summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Panchenko <apanchenko@mirantis.com>2016-10-31 17:21:22 +0200
committerArtem Panchenko <apanchenko@mirantis.com>2016-10-31 17:21:22 +0200
commit124140caf225af3c774b8d62e7e410a5c420ec57 (patch)
tree3c387b77679b59093b8eec1633ebb030ecbb2f37
parenta1ac1910f54b7e6d264453947159780a8e5726d4 (diff)
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
Notes
Notes (review): Verified+1: Mirantis CCP CI <mirantis-fuel-ccp-ci@mirantis.com> Code-Review+1: Artem Grechanichenko <agrechanichenko@mirantis.com> Code-Review+2: Artem Panchenko <apanchenko@mirantis.com> Workflow+1: Artem Panchenko <apanchenko@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 01 Nov 2016 12:49:01 +0000 Reviewed-on: https://review.openstack.org/391888 Project: openstack/fuel-ccp-tests Branch: refs/heads/master
-rw-r--r--fuel_ccp_tests/helpers/post_install_k8s_checks.py30
-rw-r--r--fuel_ccp_tests/tests/system/base_test.py19
-rw-r--r--fuel_ccp_tests/tests/unit/test_system_funcs.py56
3 files changed, 91 insertions, 14 deletions
diff --git a/fuel_ccp_tests/helpers/post_install_k8s_checks.py b/fuel_ccp_tests/helpers/post_install_k8s_checks.py
index 351984c..aa9e0a4 100644
--- a/fuel_ccp_tests/helpers/post_install_k8s_checks.py
+++ b/fuel_ccp_tests/helpers/post_install_k8s_checks.py
@@ -12,8 +12,15 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import re
16
15from devops.helpers import helpers 17from devops.helpers import helpers
16 18
19from fuel_ccp_tests import logger
20
21
22LOG = logger.logger
23
17 24
18def check_calico_network(remote, k8sclient): 25def check_calico_network(remote, k8sclient):
19 dns_pod = [ 26 dns_pod = [
@@ -31,3 +38,26 @@ def check_calico_network(remote, k8sclient):
31 calico_options = remote.execute( 38 calico_options = remote.execute(
32 'calicoctl pool show --ipv4')['stdout'][3].split('|')[2].strip() 39 'calicoctl pool show --ipv4')['stdout'][3].split('|')[2].strip()
33 assert calico_options == options 40 assert calico_options == options
41
42
43def 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)
diff --git a/fuel_ccp_tests/tests/system/base_test.py b/fuel_ccp_tests/tests/system/base_test.py
index 1e93dee..75fb82d 100644
--- a/fuel_ccp_tests/tests/system/base_test.py
+++ b/fuel_ccp_tests/tests/system/base_test.py
@@ -13,6 +13,8 @@
13# under the License. 13# under the License.
14 14
15from fuel_ccp_tests import logger 15from fuel_ccp_tests import logger
16from fuel_ccp_tests.helpers import post_install_k8s_checks
17
16 18
17LOG = logger.logger 19LOG = logger.logger
18LOG.addHandler(logger.console) 20LOG.addHandler(logger.console)
@@ -30,19 +32,6 @@ class SystemBaseTest(object):
30 for node_name in underlay.node_names(): 32 for node_name in underlay.node_names():
31 underlay.sudo_check_call(cmd, node_name=node_name) 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 def check_list_required_images(self, underlay, required_images): 35 def check_list_required_images(self, underlay, required_images):
47 """Check running containers on each node 36 """Check running containers on each node
48 37
@@ -51,7 +40,9 @@ class SystemBaseTest(object):
51 """ 40 """
52 LOG.info("Check that required containers exist") 41 LOG.info("Check that required containers exist")
53 for node_name in underlay.node_names(): 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 def check_number_kube_nodes(self, underlay, k8sclient): 47 def check_number_kube_nodes(self, underlay, k8sclient):
57 """Check number of slaves""" 48 """Check number of slaves"""
diff --git a/fuel_ccp_tests/tests/unit/test_system_funcs.py b/fuel_ccp_tests/tests/unit/test_system_funcs.py
new file mode 100644
index 0000000..ba83fe8
--- /dev/null
+++ b/fuel_ccp_tests/tests/unit/test_system_funcs.py
@@ -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
15import pytest
16
17from fuel_ccp_tests.helpers import post_install_k8s_checks as funcs
18
19test_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
27test_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
33required_images = [
34 "andyshinn/dnsmasq",
35 "calico/node",
36 "hyperkube-amd64",
37]
38
39
40class 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
49def 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)