Browse Source

Fix 'required_images_exists' method

Since Docker images names depend on used registry address
(Docker hub or some private one), tests can't just compare
pre-set names with actually deployed images. Use regular
expressions for that.

Change-Id: I4fb9ae3da33d668bd5729ff15cbac0234c7f9485
Artem Panchenko 2 years ago
parent
commit
124140caf2

+ 30
- 0
fuel_ccp_tests/helpers/post_install_k8s_checks.py View File

@@ -12,8 +12,15 @@
12 12
 #    License for the specific language governing permissions and limitations
13 13
 #    under the License.
14 14
 
15
+import re
16
+
15 17
 from devops.helpers import helpers
16 18
 
19
+from fuel_ccp_tests import logger
20
+
21
+
22
+LOG = logger.logger
23
+
17 24
 
18 25
 def check_calico_network(remote, k8sclient):
19 26
     dns_pod = [
@@ -31,3 +38,26 @@ def check_calico_network(remote, k8sclient):
31 38
     calico_options = remote.execute(
32 39
         'calicoctl pool show --ipv4')['stdout'][3].split('|')[2].strip()
33 40
     assert calico_options == options
41
+
42
+
43
+def required_images_exists(node_name, underlay, required_images):
44
+    """Check if there are all base containers on node
45
+
46
+    :param node_name: string
47
+    :param underlay: fuel_ccp_tests.managers.UnderlaySSHManager
48
+    :param required_images: list
49
+    """
50
+    cmd = "docker ps --no-trunc --format '{{.Image}}'"
51
+    result = underlay.sudo_check_call(cmd, node_name=node_name)
52
+    images = set([x.strip() for x in result['stdout']])
53
+    LOG.debug('Containers on node "{0}" use images: '
54
+              '{1}'.format(node_name, images))
55
+    # Image name could contain unpredictable Docker registry name
56
+    # (host:port), e.g. example.net:5000/hyperkube-amd64:v1.4.1
57
+    # Use regex to check that image (base name) is used by some container
58
+    assert all(
59
+        any(re.match('^([\w.-]+(:\d+)?/)?'  # Host:port (optional)
60
+                     '{0}:\S+$'  # image name + ":" + image tag
61
+                     .format(required_image), image)
62
+            for image in images)
63
+        for required_image in required_images)

+ 5
- 14
fuel_ccp_tests/tests/system/base_test.py View File

@@ -13,6 +13,8 @@
13 13
 #    under the License.
14 14
 
15 15
 from fuel_ccp_tests import logger
16
+from fuel_ccp_tests.helpers import post_install_k8s_checks
17
+
16 18
 
17 19
 LOG = logger.logger
18 20
 LOG.addHandler(logger.console)
@@ -30,19 +32,6 @@ class SystemBaseTest(object):
30 32
         for node_name in underlay.node_names():
31 33
             underlay.sudo_check_call(cmd, node_name=node_name)
32 34
 
33
-    def required_images_exists(self, node_name, underlay, required_images):
34
-        """Check if there are all base containers on node
35
-
36
-        :param node_name: string
37
-        :param underlay: fuel_ccp_tests.managers.UnderlaySSHManager
38
-        :param required_images: list
39
-        """
40
-        cmd = "docker ps --no-trunc --format '{{.Image}}'"
41
-        result = underlay.sudo_check_call(cmd, node_name=node_name)
42
-        images = [x.split(":")[0] for x in result['stdout']]
43
-        assert set(required_images) < set(images),\
44
-            "Running containers check failed on node '{}'".format(node_name)
45
-
46 35
     def check_list_required_images(self, underlay, required_images):
47 36
         """Check running containers on each node
48 37
 
@@ -51,7 +40,9 @@ class SystemBaseTest(object):
51 40
         """
52 41
         LOG.info("Check that required containers exist")
53 42
         for node_name in underlay.node_names():
54
-            self.required_images_exists(node_name, underlay, required_images)
43
+            post_install_k8s_checks.required_images_exists(node_name,
44
+                                                           underlay,
45
+                                                           required_images)
55 46
 
56 47
     def check_number_kube_nodes(self, underlay, k8sclient):
57 48
         """Check number of slaves"""

+ 56
- 0
fuel_ccp_tests/tests/unit/test_system_funcs.py View File

@@ -0,0 +1,56 @@
1
+#    Copyright 2016 Mirantis, Inc.
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+import pytest
16
+
17
+from fuel_ccp_tests.helpers import post_install_k8s_checks as funcs
18
+
19
+test_images1 = [
20
+    "artifactory.example.net:5000/hyperkube-amd64:v1.4.1-test_100",
21
+    "andyshinn/dnsmasq:2.72",
22
+    "artifactory.example.net:5001/calico/node:v0.20.0-mcp-7b31adc",
23
+    "artifactory.example.net:5001/calico/ctl:v0.20.0-mcp-7b31adc",
24
+    "artifactory.example.net:5000/hyperkube-amd64:v1.4.1-test_100",
25
+]
26
+
27
+test_images2 = [
28
+    "andyshinn/dnsmasq:2.72",
29
+    "gcr.io/google_containers/pause-amd64:3.0",
30
+    "quay.io/coreos/etcd:v3.0.1",
31
+]
32
+
33
+required_images = [
34
+    "andyshinn/dnsmasq",
35
+    "calico/node",
36
+    "hyperkube-amd64",
37
+]
38
+
39
+
40
+class MockUnderlay(object):
41
+    def __init__(self, images):
42
+        self.images = images
43
+
44
+    def sudo_check_call(self, *args, **kwargs):
45
+        return {'stdout': self.images}
46
+
47
+
48
+@pytest.mark.unit_tests
49
+def test_required_images_exists():
50
+    funcs.required_images_exists(node_name='master',
51
+                                 underlay=MockUnderlay(test_images1),
52
+                                 required_images=required_images)
53
+    with pytest.raises(AssertionError):
54
+        funcs.required_images_exists(node_name='master',
55
+                                     underlay=MockUnderlay(test_images2),
56
+                                     required_images=required_images)

Loading…
Cancel
Save