summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-10-26 12:13:59 +0000
committerGerrit Code Review <review@openstack.org>2016-10-26 12:13:59 +0000
commitd2864ee6307aed411a73ff2ab712f83400592087 (patch)
treeba80140cb079a5d8f421b1f0ea6c5cacec6fefb0
parent3be04d12cee06f65e1a82003753f05000bbf7759 (diff)
parentdc7c1bb232a40bb9e9f833e068d1197a1f8a7a4e (diff)
Merge "Update a daemonset using updateStrategy type: Noop"
-rw-r--r--fuel_ccp_tests/managers/k8s/daemonsets.py5
-rw-r--r--fuel_ccp_tests/tests/system/test_daemonsets.py178
2 files changed, 183 insertions, 0 deletions
diff --git a/fuel_ccp_tests/managers/k8s/daemonsets.py b/fuel_ccp_tests/managers/k8s/daemonsets.py
index b98774c..f74642c 100644
--- a/fuel_ccp_tests/managers/k8s/daemonsets.py
+++ b/fuel_ccp_tests/managers/k8s/daemonsets.py
@@ -68,3 +68,8 @@ class K8sDaemonSetManager(K8sBaseManager):
68 def full_list(self, *args, **kwargs): 68 def full_list(self, *args, **kwargs):
69 lst = self._full_list(*args, **kwargs) 69 lst = self._full_list(*args, **kwargs)
70 return [self.resource_class(self, item) for item in lst.items] 70 return [self.resource_class(self, item) for item in lst.items]
71
72 def update(self, body, name, namespace=None, **kwargs):
73 namespace = namespace or self.namespace
74 return self.api.patch_namespaced_daemon_set(
75 body=body, name=name, namespace=namespace, **kwargs)
diff --git a/fuel_ccp_tests/tests/system/test_daemonsets.py b/fuel_ccp_tests/tests/system/test_daemonsets.py
new file mode 100644
index 0000000..f98ec49
--- /dev/null
+++ b/fuel_ccp_tests/tests/system/test_daemonsets.py
@@ -0,0 +1,178 @@
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 time
16
17from devops.helpers import helpers
18import pytest
19
20from fuel_ccp_tests.helpers import ext
21from fuel_ccp_tests import logger
22
23LOG = logger.logger
24
25
26class TestDaemonsetsUpdates():
27 """Test class for update DaemonSets"""
28
29 from_nginx_image = 'nginx:1.10'
30 to_nginx_image = 'nginx:1.11'
31
32 def get_nginx_spec(self):
33 return {
34 'apiVersion': 'extensions/v1beta1',
35 'kind': 'DaemonSet',
36 'metadata': {
37 'labels': {'app': 'nginx'},
38 'name': 'nginx',
39 },
40 'spec': {
41 'template': {
42 'metadata': {
43 'labels': {'app': 'nginx'},
44 'name': 'nginx-app'},
45 'spec': {
46 'containers': [
47 {'name': 'nginx-app',
48 'image': self.from_nginx_image},
49 ],
50 },
51 },
52 'updateStrategy': {
53 'type': 'RollingUpdate',
54 },
55 }
56 }
57
58 def get_nginx_pods(self, k8sclient):
59 spec = self.get_nginx_spec()
60 return [x for x in k8sclient.pods.list()
61 if spec['metadata']['name'] in x.name]
62
63 def get_nginx_ds(self, k8sclient):
64 spec = self.get_nginx_spec()
65 return [x for x in k8sclient.daemonsets.list()
66 if spec['metadata']['name'] in x.name]
67
68 def wait_nginx_pods_ready(self, k8sclient):
69 """Wait until the nginx pods are ready"""
70 nginx_pods = self.get_nginx_pods(k8sclient)
71 for pod in nginx_pods:
72 pod.wait_running(timeout=60)
73
74 def delete_nginx_pods(self, k8sclient):
75 """Delete the nginx pods"""
76 nginx_pods = self.get_nginx_pods(k8sclient)
77 for pod in nginx_pods:
78 k8sclient.pods.delete(body=pod.spec, name=pod.name)
79 helpers.wait(lambda: pod.name not in [
80 x.name for x in self.get_nginx_pods(k8sclient)])
81
82 def check_nginx_pods_image(self, k8sclient, nginx_image):
83 nginx_pods = self.get_nginx_pods(k8sclient)
84 for pod in nginx_pods:
85 pod_image = pod.status.container_statuses[0].image
86 assert pod_image == nginx_image, (
87 "Pod {0} has image {1} while expected {2}"
88 .format(pod.name, pod_image, nginx_image))
89
90 def check_nginx_ds_image(self, k8sclient, nginx_image):
91 nginx_daemonsets = self.get_nginx_ds(k8sclient)
92 for nginx_ds in nginx_daemonsets:
93 nginx_ds_image = nginx_ds.spec.template.spec.containers[0].image
94 assert nginx_ds_image == nginx_image, (
95 "DaemonSet {0} has image {1} while expected {2}"
96 .format(nginx_ds.name, nginx_ds_image, nginx_image))
97
98 @pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
99 @pytest.mark.fail_snapshot
100 @pytest.mark.snapshot_needed
101 def test_daemonset_rollingupdate_noop(self, underlay, k8scluster, config,
102 show_step):
103 """Update a daemonset using updateStrategy type: Noop
104
105 Scenario:
106 1. Deploy k8s using fuel-ccp-installer
107 2. Create a DaemonSet for nginx with image version 1_10 and
108 update strategy Noop
109 3. Wait until nginx pods are created and become 'ready'
110 4. Check that the image version in the nginx pods is 1_10
111 Check that the image version in the nginx daemonset is 1_10
112 5. Change nginx image version to 1_11 using YAML
113 6. Wait for 10 seconds (needs to check that there were
114 no auto updates of the nginx pods)
115 7. Check that the image version in the nginx pods is still 1_10
116 Check that the image version in the nginx daemonset
117 is updated to 1_11
118 8. Kill all nginx pods that are belong to the nginx daemonset
119 9. Wait until nginx pods are created and become 'ready'
120 10. Check that the image version in the nginx pods
121 is updated to 1_11
122
123 Duration: 3000 seconds
124 """
125
126 # STEP #1
127 show_step(1)
128 k8sclient = k8scluster.api
129 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
130
131 # STEP #2
132 show_step(2)
133 nginx_spec = self.get_nginx_spec()
134 nginx_spec['spec']['updateStrategy']['type'] = 'Noop'
135 nginx_spec['spec']['template']['spec']['containers'][0][
136 'image'] = self.from_nginx_image
137 k8sclient.daemonsets.create(body=nginx_spec)
138
139 # STEP #3
140 show_step(3)
141 time.sleep(3)
142 self.wait_nginx_pods_ready(k8sclient)
143
144 # STEP #4
145 show_step(4)
146 self.check_nginx_pods_image(k8sclient, self.from_nginx_image)
147 self.check_nginx_ds_image(k8sclient, self.from_nginx_image)
148
149 # STEP #5
150 show_step(5)
151 nginx_spec['spec']['template']['spec']['containers'][0][
152 'image'] = self.to_nginx_image
153 k8sclient.daemonsets.update(body=nginx_spec,
154 name=nginx_spec['metadata']['name'])
155
156 # STEP #6
157 show_step(6)
158 time.sleep(10)
159
160 # STEP #7
161 show_step(7)
162 # Pods should still have the old image version
163 self.check_nginx_pods_image(k8sclient, self.from_nginx_image)
164 # DaemonSet should have new image version
165 self.check_nginx_ds_image(k8sclient, self.to_nginx_image)
166
167 # STEP #8
168 show_step(8)
169 self.delete_nginx_pods(k8sclient)
170
171 # STEP #9
172 show_step(9)
173 self.wait_nginx_pods_ready(k8sclient)
174
175 # STEP #10
176 show_step(10)
177 # Pods should have the new image version
178 self.check_nginx_pods_image(k8sclient, self.to_nginx_image)