pgreco / rpms / cockpit

Forked from forks/areguera/rpms/cockpit 5 years ago
Clone
Blob Blame History Raw
From a3ddc1c7865b128b6a2bf3aa22876b238b0fb445 Mon Sep 17 00:00:00 2001
From: Dominik Perpeet <dperpeet@redhat.com>
Date: Tue, 20 Jun 2017 22:35:41 +0200
Subject: [PATCH 13/23] test: Update openshift tests to master

Closes #7025
Reviewed-by: Stef Walter <stefw@redhat.com>
---
 test/verify/check-openshift | 181 +++++++++++++++++++++++++++++++++++++++++---
 test/verify/kubelib.py      |   9 ++-
 2 files changed, 178 insertions(+), 12 deletions(-)

diff --git a/test/verify/check-openshift b/test/verify/check-openshift
index 5c404e5..6b2236d 100755
--- a/test/verify/check-openshift
+++ b/test/verify/check-openshift
@@ -51,7 +51,7 @@ def wait_project(machine, project):
             i = i + 1
             time.sleep(2)
 
-@skipImage("Kubernetes not packaged", "debian-8", "debian-testing", "ubuntu-1604", "fedora-i386")
+@skipImage("Kubernetes not packaged", "debian-stable", "debian-testing", "ubuntu-1604", "ubuntu-stable", "fedora-i386")
 @skipImage("No cockpit-kubernetes packaged", "continuous-atomic", "fedora-atomic", "rhel-atomic")
 class TestOpenshift(MachineCase, OpenshiftCommonTests):
     additional_machines = {
@@ -63,12 +63,13 @@ class TestOpenshift(MachineCase, OpenshiftCommonTests):
 
         self.openshift = self.machines['openshift']
         self.openshift.upload(["verify/files/mock-app-openshift.json"], "/tmp")
-        tmpfile = os.path.join(self.tmpdir, "config")
-        self.openshift.download("/root/.kube/config", tmpfile)
+        self.kubeconfig = os.path.join(self.tmpdir, "config")
+        self.openshift.download("/root/.kube/config", self.kubeconfig)
 
         m = self.machine
-        with open(tmpfile, "r") as f:
-            m.execute("mkdir -p /home/admin/.kube && cat > /home/admin/.kube/config", input=f.read())
+        m.execute("mkdir -p /home/admin/.kube")
+        m.upload([self.kubeconfig], "/home/admin/.kube/config")
+        m.execute("chown -R admin:admin /home/admin/.kube")
 
         wait_project(self.openshift, "marmalade")
 
@@ -124,7 +125,7 @@ class TestOpenshift(MachineCase, OpenshiftCommonTests):
         b.wait_present("a[href='#/volumes']")
         b.click("a[href='#/volumes']")
         b.wait_present(".pv-listing")
-        b.wait_in_text(".pv-listing", "cannot list all")
+        b.wait_in_text(".pv-listing", "cannot watch all")
         b.click("a[href='#/']")
 
         b.wait_present("#kubernetes-change-connection")
@@ -145,7 +146,7 @@ class TestOpenshift(MachineCase, OpenshiftCommonTests):
 
         # Test the saved kube config file
         m.execute("rm /home/admin/.kube/config")
-        m.upload(["verify/files/openshift.kubeconfig"], "/home/admin/.kube/config")
+        m.upload([self.kubeconfig], "/home/admin/.kube/config")
         m.execute("chown -R admin:admin /home/admin/.kube")
 
         self.login_and_go("/kubernetes")
@@ -304,7 +305,81 @@ LABEL io.projectatomic.nulecule.atomicappversion="0.1.11" \
         b.wait_present(".details-listing tbody[data-id='pods/default/helloapache'] th")
         self.assertEqual(b.text(".details-listing tbody[data-id='pods/default/helloapache'] th"), "helloapache")
 
-@skipImage("Kubernetes not packaged", "debian-8", "debian-testing", "ubuntu-1604", "fedora-i386")
+    def testReconnectChangeCert(self):
+        m = self.machine
+        b = self.browser
+
+        # Try to connect with an old and non-matching client cert
+        old_cert = ('LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUREVENDQWZXZ0F3SUJBZ0lCQnpBTkJna3Foa2'
+                    'lHOXcwQkFRc0ZBREFtTVNRd0lnWURWUVFEREJ0dmNHVnUKYzJocFpuUXRjMmxuYm1WeVFERTBPVEEy'
+                    'T0RFMk16RXdIaGNOTVRjd016STRNRFl4TXpVeVdoY05NVGt3TXpJNApNRFl4TXpVeldqQTNNUjR3SE'
+                    'FZRFZRUUtFeFZ6ZVhOMFpXMDZZMngxYzNSbGNpMWhaRzFwYm5NeEZUQVRCZ05WCkJBTVRESE41YzNS'
+                    'bGJUcGhaRzFwYmpDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUIKQU5Rel'
+                    'J5SzUzQUhmdlZnME5GTHRSSENhMTEyK3l5a0xXdG14bjAxb2JTMy85VmovQU1UdmZwNVRkUlhKNjF'
+                    'WcAo3L0N1L1pkQ3RDc1pyNnJpYVMxbUJGcmtTSkZJdmFjN2NNa3k2M0tVVXNaQmU5ZGFLdG1OMmhY'
+                    'TUt0VitESStvCjJFQVJNWlV5YTZIMzJXZUpzRGM0L1lscUR5TFAxYVR3NWNwRTJPY3dWQTdoQ1dCS'
+                    'ysyajIvZTl6RDhrYzM2R24KNG0wZWd3YWxlZ2UwTXFaUk1BbTFkenRpS3I1UWZ4MG9ZVUY3Z0JIYm'
+                    'RjM253cGZ6a3M2K1F4Tkl6V0hlRmN2WApxcXpsMGxnT2ZGeWc0VWptYzhFcTBiKy9ER3lYSGlHNXN'
+                    'vVmw1RGlVa1RKRjNrcURCZVVjZWNZaEx1VDd4emxzClk0bldYVFprc3lJMXVoZFJmS2NnbVZjQ0F3'
+                    'RUFBYU0xTURNd0RnWURWUjBQQVFIL0JBUURBZ1dnTUJNR0ExVWQKSlFRTU1Bb0dDQ3NHQVFVRkJ3T'
+                    'UNNQXdHQTFVZEV3RUIvd1FDTUFBd0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQgpBRy9rTElnQ2YwK2'
+                    '1MZ1VXcWZjS2NLN0Nmdm9PbS9qL0FUSW1MR0YvSUtvQTRCWGhqMG5EcEszeVd3ZGt4d0hZCmxxUDh'
+                    'xZ1NyQ1FaNkVoSlpMSWtjQWovTUlTUEUvSlJPa3R5TWFTMis4OGhqeGpxdUhucnZ5ODA5ZlJ5QzhF'
+                    'R2kKeVIyRzhtNGJ5MEJrOWhENkVxbDYxb21VU0MzL2ozR3lPUGNZWDJEQjZsU2h4ZlFJVEpqUWNKQ'
+                    '0oyMnNDdlBBOApVeU9EaUgrNllZSVdtVFN5a2kzazk0Q3NOZXlRbERjNzh3a1BseUdrN0p1anFIK2p'
+                    'KaURXSDQ2TXE3TTNaVVArCmowQWxhd3dtdllsRjBVZEIwdGRCenZWR21RbTRudEwwSkhVMGFqRnUy'
+                    'QTYvTjJmT3VrZWI0TDR6elBzSkJFNHIKaUUyNWRJUlAvWHRoM0tjRFYyYkxtMUk9Ci0tLS0tRU5EI'
+                    'ENFUlRJRklDQVRFLS0tLS0K')
+        old_key = ('LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBMUROSElybmNBZC'
+                   's5V0RRMFV1MUVjSnJYWGI3TEtRdGEyYkdmVFdodExmLzFXUDhBCnhPOStubE4xRmNuclZXbnY4Szc5'
+                   'bDBLMEt4bXZxdUpwTFdZRVd1UklrVWk5cHp0d3lUTHJjcFJTeGtGNzExb3EKMlkzYUZjd3ExWDRNa'
+                   'jZqWVFCRXhsVEpyb2ZmWlo0bXdOemo5aVdvUElzL1ZwUERseWtUWTV6QlVEdUVKWUVyNwphUGI5Nz'
+                   'NNUHlSemZvYWZpYlI2REJxVjZCN1F5cGxFd0NiVjNPMklxdmxCL0hTaGhRWHVBRWR0MXplZkNsL09'
+                   'TCnpyNURFMGpOWWQ0Vnk5ZXFyT1hTV0E1OFhLRGhTT1p6d1NyUnY3OE1iSmNlSWJteWhXWGtPSlNS'
+                   'TWtYZVNvTUYKNVJ4NXhpRXU1UHZIT1d4amlkWmRObVN6SWpXNkYxRjhweUNaVndJREFRQUJBb0lCQ'
+                   'UNxbjNDYlk0YWJteVBNUQpHMnlJRVhmcFNGMnAyc0QzYlYzUlhNcDhzV1hMekJBRndxdlQwTW9XME'
+                   'xSK2tIWHRBN1NJR0tYdFhMWkZSWkMrClRwSTNyYXh2c3o2eE5wNkZUbGpEaVp6UXdBcm1ZdlNaUlg'
+                   'vU0NnTFR0ZENRdEFtMDBUT2Z3UzNTb3R3K0xFK3AKMStoaDVtVlhFby9XNDRWeWYxNjNsRHAwOXBD'
+                   'K3dpS0ZEa2JHVExBdnA1bnFaMnhtZDRyNzhyMi9TZmZ2YUplZQpJSlpwbENMYzMyQkVZaE4yeDRIa'
+                   'HpqQkhOdTJwYkFXS2twUDVjWkZNS3QwSUkrRTN0UUNWMlkrYVZvNTY0TzRGCjZxMmFUUzVxMnRuaW'
+                   'VBTS9uay8zN3hkNUVoNjRpMU8vQTU2YzdoZmxkMDVQMC9PdU9OY2dsaVVYRG44cnFvOUoKdXpFQ1F'
+                   'ORUNnWUVBN0xOeWRQQlhkdEZRZ3NrWG56UlVYM3hhYWFCYU8xYnJYZzVmUnlMVm5DY2thWlRORXlE'
+                   'dAp3eURxSGRUOGtRNXNIcXZ3WDNxNXR1elZBZ3NJUlhvcTZIUGtxRWdLeFZIclhTNzY1OFhLUnR1S'
+                   'GswbE11ZkQxCnVPVVBaTTJYNVR4NXRmTmh1Zlh3dXZqTkdyN0E3ZEw4VUFiY3ZtS2VuSnF2bDNJZX'
+                   'I0cVpkdDBDZ1lFQTVZQncKZ2pNTGJRZStEUzd1QmdsOFVmdGl5YnZCbDdTSEQ4T2RWamVOdzNEZjJ'
+                   'uckltQVdLTVhNTk5GWldwbmhhc0g3Swp1bWtMQWdMNWFEWXJhaFJHN2ZwMGd0YnN0RVE5Uit2dFVp'
+                   'azMxaFNHUS83dFBENU1LaU1jcFpnazhYUXI5UnlFCkVEN285bWFvUEZibnJKbFl5VXNQY0FCN3Y1W'
+                   'FNxaVdqeFZMODI4TUNnWUVBNUhoSk1DcVVvZkZqL3ZsUFBiSnIKQmtlbmxYRGI1NDc4WEtzT3VFRW'
+                   'RZajQ5M1ZOdHB0c1A1RnF1MytDbmNQUTAxRjR1QkZzWFMwUEtUdENMU1ZTawplZjd6WktNMUVrVUN'
+                   'JODJuRFhSU3pKWTFoS3NwemdpUmhjaERWWTlFNEZYQlBTa1EyVWhVOW9RVXBZNGQ5dkRCCjdoVFJt'
+                   'VXJqd2xGa3o0K3RvczdyVmxrQ2dZRUF4RW8vY0V5aVNDV29HblI2Sm5XMGZCWUxuMGxVUWlHb3B3W'
+                   'UQKS3Z1bTUzTkNNd1p6VFByb0FIVkw1T2kzZ2ZoTWNNcHhNRkNwbHBYZXBaQTNQNnFLSS83ajZnaF'
+                   'RPYmRueG56MgpaU0JWM21kOWt1aVdGY0dldVNlQTErMHlJOFhkMXU0RjBqTk1ZM3JZQjR1NDZQbmJ'
+                   'ZNGNzYy9vbDNXNFNXVzZLCkRUcDJoS3NDZ1lCSlpMQys3Uy9zRGVqdkl0MTZ2Q3JzbDJlWlFsb1p0'
+                   'clNoVCtTb0hmR1NPRXZkMXp1NStBL3UKaVVDYyt1SHdUa1c0RVpMTEdBYkUzTG1xSllJcXNkNVpUW'
+                   'UkxWTZ1TGoyV1NGWFZYUXVLanVlTDZJdGttc1dvZgpyMHFtQU93RHdFVDFvRXlNVUJoOTJVMmhxSHR'
+                   'aamlMdkxQdDc5aUhacDNtTnlLVjc5QXY3dVE9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=')
+
+        m.execute("sed -i '/client-certificate-data:/ s/:.*$/: %s/; /client-key-data:/ s/:.*$/: %s/' /home/admin/.kube/config" % (
+            old_cert, old_key))
+        m.execute("chown -R admin:admin /home/admin/.kube")
+        self.login_and_go("/kubernetes")
+
+        b.wait_present(".curtains-ct")
+        b.wait_visible(".curtains-ct")
+        b.wait_in_text(".curtains-ct", "Couldn't connect to server")
+        b.wait_in_text(".curtains-ct", "Unauthorized")
+        b.wait_present(".curtains-ct #kubernetes-reconnect")
+
+        # now provide a good certificate, and reconnect
+        m.upload([self.kubeconfig], "/home/admin/.kube/config")
+        m.execute("chown -R admin:admin /home/admin/.kube")
+
+        b.click("#kubernetes-reconnect")
+        b.wait_present("#service-list")
+
+
+@skipImage("Kubernetes not packaged", "debian-stable", "debian-testing", "ubuntu-1604", "ubuntu-stable", "fedora-i386")
 @skipImage("No cockpit-kubernetes packaged", "continuous-atomic", "fedora-atomic", "rhel-atomic")
 class TestRegistry(MachineCase):
     additional_machines = {
@@ -325,6 +400,26 @@ class TestRegistry(MachineCase):
 
         self.browser.wait_timeout(120)
 
+    def setupDockerRegistry(self):
+        """Run a docker registry instance and populate it
+
+        The OpenShift registry can pull image streams from localhost:5555 for
+        testing.
+        """
+        # set up a docker registry with cert, as openshift registry expects https
+        self.openshift.execute("docker run -d -p 5555:5000 --name testreg "
+                               "-v /openshift.local.config/master/:/certs "
+                               "-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/master.server.crt "
+                               "-e REGISTRY_HTTP_TLS_KEY=/certs/master.server.key "
+                               "registry:2")
+        self.openshift.execute("while ! curl -s --connect-timeout 1 https://localhost:5555/; do sleep 1; done")
+        self.addCleanup(self.openshift.execute, "docker rm -f testreg")
+
+        # populate it with some images
+        self.openshift.execute("docker tag registry:5000/marmalade/juggs:latest localhost:5555/juggs:latest; "
+                               "docker tag registry:5000/marmalade/juggs:2.11 localhost:5555/juggs:2.11; "
+                               "docker push localhost:5555/juggs")
+
     def testImages(self):
         b = self.browser
         o = self.openshift
@@ -358,7 +453,7 @@ class TestRegistry(MachineCase):
         b.click(".listing-ct-head li:last-child a")
         b.wait_present(".listing-ct-body .registry-image-layers")
         b.wait_visible(".listing-ct-body .registry-image-layers")
-        b.wait_in_text(".listing-ct-body .registry-image-layers", "ADD file:")
+        b.wait_in_text(".listing-ct-body .registry-image-layers", "KiB")
 
         # Add postgres into the stream
         output = o.execute("oc get imagestream --namespace=marmalade --template='{{.spec}}' busybee")
@@ -668,7 +763,7 @@ class TestRegistry(MachineCase):
         b.wait_visible("#add_role .dropdown-menu")
         b.click("#add_role a[value='Admin']")
         b.click(".btn-primary")
-        self.assertEqual(b.text(".dialog-error"), "The member name contains invalid characters.")
+        b.wait_in_text(".dialog-error", "The member name contains invalid characters.")
 
         # but email-style user name should be accepted
         b.set_val("#add_member_name", "foo@bar.com")
@@ -690,7 +785,7 @@ class TestRegistry(MachineCase):
         b.set_val("#user_name", "bar ^ baz")
         b.set_val("#identities", "anypassword:abc123")
         b.click(".btn-primary")
-        self.assertEqual(b.text(".dialog-error"), "The name contains invalid characters")
+        b.wait_in_text(".dialog-error", "The name contains invalid characters")
 
         # email-style user name should be accepted
         b.set_val("#user_name", "bar@baz.com")
@@ -977,6 +1072,70 @@ class TestRegistry(MachineCase):
         # FIXME: known to fail for now, needs fixing in registry-image-widgets
         # b.wait_not_visible('.registry-imagestream-push')
 
+    def testImagestreamImport(self):
+        b = self.browser
+        self.setupDockerRegistry()
+
+        # Add new "alltags" image stream pulling from localhost:5555/juggs
+        self.login_and_go("/kubernetes/registry#/images/marmalade")
+        b.wait_present("a.pull-right span:contains('New image stream')")
+        b.click("a.pull-right")
+        b.wait_present("modal-dialog")
+        b.wait_val("#imagestream-modify-project-text", "marmalade")
+        b.set_val("#imagestream-modify-name", "alltags")
+        b.wait_present("#imagestream-modify-populate")
+        b.click("#imagestream-modify-populate button")
+        b.wait_visible("#imagestream-modify-populate .dropdown-menu")
+        b.click("#imagestream-modify-populate .dropdown-menu a[value='pull']")
+        b.wait_present("#imagestream-modify-pull")
+        b.wait_visible("#imagestream-modify-pull")
+        b.set_val("#imagestream-modify-pull", "localhost:5555/juggs")
+        b.click("modal-dialog div.modal-footer button.btn-primary")
+        b.wait_not_present("modal-dialog")
+
+        # new stream with both "latest" and "2.11" tags should now appear
+        b.wait_present("tr.imagestream-item th:contains('marmalade/alltags')")
+        b.wait_present('tbody[data-id="marmalade/alltags:latest"]')
+        b.wait_present('tbody[data-id="marmalade/alltags:2.11"]')
+
+        # also check with CLI
+        output = self.openshift.execute("oc get imagestream --namespace=marmalade alltags")
+        self.assertIn("localhost:5555/juggs", output)
+        self.assertIn("latest", output)
+        self.assertIn("2.11", output)
+
+        # Add new "sometags" image stream pulling only the 2.11 tag
+        b.click("a.pull-right")
+        b.wait_present("modal-dialog")
+        b.wait_val("#imagestream-modify-project-text", "marmalade")
+        b.set_val("#imagestream-modify-name", "sometags")
+        b.wait_present("#imagestream-modify-populate")
+        b.click("#imagestream-modify-populate button")
+        b.wait_visible("#imagestream-modify-populate .dropdown-menu")
+        b.click("#imagestream-modify-populate .dropdown-menu a[value='tags']")
+        b.wait_present("#imagestream-modify-tags")
+        b.wait_visible("#imagestream-modify-tags")
+        b.set_val("#imagestream-modify-pull", "localhost:5555/juggs")
+        # fields.tags is not an <input> element, type manually
+        b.click("#imagestream-modify-tags")
+        b.key_press(['2', '.', '1', '1'])
+        b.click("modal-dialog div.modal-footer button.btn-primary")
+        b.wait_not_present("modal-dialog")
+
+        # new stream with only "2.11" tags should now appear
+        b.wait_present("tr.imagestream-item th:contains('marmalade/sometags')")
+        b.go("/kubernetes/registry#/images/marmalade/sometags")
+        # EXFAIL: https://bugzilla.redhat.com/show_bug.cgi?id=1373332
+        # b.wait_present('tbody[data-id="marmalade/sometags:2.11"]')
+        self.assertFalse(b.is_present('tbody[data-id="marmalade/sometags:latest"]'))
+
+        # also check with CLI
+        output = self.openshift.execute("oc get imagestream --namespace=marmalade sometags")
+        self.assertIn("localhost:5555/juggs", output)
+        self.assertIn("2.11", output)
+        # EXFAIL: https://bugzilla.redhat.com/show_bug.cgi?id=1373332
+        # self.assertNotIn("latest", output)
+
 
 if __name__ == '__main__':
     test_main()
diff --git a/test/verify/kubelib.py b/test/verify/kubelib.py
index 1af2c44..5be8aed 100644
--- a/test/verify/kubelib.py
+++ b/test/verify/kubelib.py
@@ -47,6 +47,11 @@ class KubernetesCase(testlib.MachineCase):
 
     def start_kubernetes(self):
         self.machine.execute("systemctl start docker || journalctl -u docker")
+
+        # HACK: work around https://github.com/kubernetes/kubernetes/issues/43805 until
+        # the fix lands in Fedora 26
+        if self.machine.image == "fedora-26":
+            self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s/"$/ --cgroup-driver=systemd"/ }' /etc/kubernetes/kubelet""")
         try:
             self.machine.execute('/etc/kubernetes/start-kubernetes')
         except subprocess.CalledProcessError:
@@ -62,7 +67,9 @@ class KubernetesCase(testlib.MachineCase):
         scheme=%s
         for a in $(seq 0 $timeout); do
             if curl -o /dev/null -k -s $scheme://localhost:$port; then
-                break
+                if kubectl get all | grep -q svc/kubernetes; then
+                    break
+                fi
             fi
             sleep 0.5
         done
-- 
2.13.5