Browse Source

Merge "Update a daemonset using updateStrategy type: RollingUpdate"

Jenkins 2 years ago
parent
commit
f5ffd8653c
1 changed files with 98 additions and 4 deletions
  1. 98
    4
      fuel_ccp_tests/tests/system/test_daemonsets.py

+ 98
- 4
fuel_ccp_tests/tests/system/test_daemonsets.py View File

@@ -30,6 +30,9 @@ class TestDaemonsetsUpdates():
30 30
     to_nginx_image = 'nginx:1.11'
31 31
 
32 32
     def get_nginx_spec(self):
33
+        """Create specification for DaemonSet with Nginx containers
34
+            :return: nested dict
35
+        """
33 36
         return {
34 37
             'apiVersion': 'extensions/v1beta1',
35 38
             'kind': 'DaemonSet',
@@ -56,23 +59,37 @@ class TestDaemonsetsUpdates():
56 59
         }
57 60
 
58 61
     def get_nginx_pods(self, k8sclient):
62
+        """Return the nginx pods
63
+            :param: k8sclient: kubernetes api client
64
+            :return: list of pods with nginx containers
65
+        """
59 66
         spec = self.get_nginx_spec()
60 67
         return [x for x in k8sclient.pods.list()
61 68
                 if spec['metadata']['name'] in x.name]
62 69
 
63 70
     def get_nginx_ds(self, k8sclient):
71
+        """Return the nginx DaemonSets
72
+            :param k8sclient: kubernetes api client
73
+            :return: list of DaemonSets with pods with nginx containers
74
+        """
64 75
         spec = self.get_nginx_spec()
65 76
         return [x for x in k8sclient.daemonsets.list()
66 77
                 if spec['metadata']['name'] in x.name]
67 78
 
68 79
     def wait_nginx_pods_ready(self, k8sclient):
69
-        """Wait until the nginx pods are ready"""
80
+        """Wait until the nginx pods are ready
81
+            :param: k8sclient: kubernetes api client
82
+            :return: None
83
+        """
70 84
         nginx_pods = self.get_nginx_pods(k8sclient)
71 85
         for pod in nginx_pods:
72 86
             pod.wait_running(timeout=60)
73 87
 
74 88
     def delete_nginx_pods(self, k8sclient):
75
-        """Delete the nginx pods"""
89
+        """Delete the nginx pods
90
+            :param: k8sclient: kubernetes api client
91
+            :return: None
92
+        """
76 93
         nginx_pods = self.get_nginx_pods(k8sclient)
77 94
         for pod in nginx_pods:
78 95
             k8sclient.pods.delete(body=pod.spec, name=pod.name)
@@ -80,6 +97,11 @@ class TestDaemonsetsUpdates():
80 97
                 x.name for x in self.get_nginx_pods(k8sclient)])
81 98
 
82 99
     def check_nginx_pods_image(self, k8sclient, nginx_image):
100
+        """Check nginx pods image version
101
+            :param: k8sclient: kubernetes api client,
102
+            :param: nginx_image: version of nginx_image to compare
103
+            :return: None
104
+        """
83 105
         nginx_pods = self.get_nginx_pods(k8sclient)
84 106
         for pod in nginx_pods:
85 107
             pod_image = pod.status.container_statuses[0].image
@@ -88,6 +110,11 @@ class TestDaemonsetsUpdates():
88 110
                 .format(pod.name, pod_image, nginx_image))
89 111
 
90 112
     def check_nginx_ds_image(self, k8sclient, nginx_image):
113
+        """Check nginx DaemonSets version
114
+            :param: k8sclient: kubernetes api client,
115
+            :param: nginx_image: version of nginx_image to compare
116
+            :return: None
117
+        """
91 118
         nginx_daemonsets = self.get_nginx_ds(k8sclient)
92 119
         for nginx_ds in nginx_daemonsets:
93 120
             nginx_ds_image = nginx_ds.spec.template.spec.containers[0].image
@@ -98,8 +125,7 @@ class TestDaemonsetsUpdates():
98 125
     @pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
99 126
     @pytest.mark.fail_snapshot
100 127
     @pytest.mark.snapshot_needed
101
-    def test_daemonset_rollingupdate_noop(self, underlay, k8scluster, config,
102
-                                          show_step):
128
+    def test_daemonset_rollingupdate_noop(self, k8scluster, show_step):
103 129
         """Update a daemonset using updateStrategy type: Noop
104 130
 
105 131
         Scenario:
@@ -176,3 +202,71 @@ class TestDaemonsetsUpdates():
176 202
         show_step(10)
177 203
         # Pods should have the new image version
178 204
         self.check_nginx_pods_image(k8sclient, self.to_nginx_image)
205
+
206
+    @pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
207
+    @pytest.mark.fail_snapshot
208
+    @pytest.mark.snapshot_needed
209
+    def test_daemonset_rollingupdate(self, k8scluster, show_step):
210
+        """Update a daemonset using updateStrategy type: RollingUpdate
211
+
212
+        Scenario:
213
+            1. Deploy k8s using fuel-ccp-installer
214
+            2. Create a DaemonSet for nginx with image version 1_10 and
215
+               update strategy RollingUpdate
216
+            3. Wait until nginx pods are created and become 'ready'
217
+            4. Check that the image version in the nginx pods is 1_10
218
+               Check that the image version in the nginx daemonset is 1_10
219
+            5. Change nginx image version to 1_11 using YAML
220
+            6. Wait for 10 seconds (needs to check that there were
221
+               no auto updates of the nginx pods)
222
+            7. Check that the image version in the nginx daemonset
223
+               is updated to 1_11
224
+               Wait for ~120 sec that the image version in the nginx pods
225
+               is changed to 1_11
226
+
227
+        Duration: 3000 seconds
228
+        """
229
+
230
+        # STEP #1
231
+        show_step(1)
232
+        k8sclient = k8scluster.api
233
+        assert k8sclient.nodes.list() is not None, "Can not get nodes list"
234
+
235
+        # STEP #2
236
+        show_step(2)
237
+        nginx_spec = self.get_nginx_spec()
238
+        nginx_spec['spec']['template']['spec']['containers'][0][
239
+            'image'] = self.from_nginx_image
240
+        k8sclient.daemonsets.create(body=nginx_spec)
241
+
242
+        # STEP #3
243
+        show_step(3)
244
+        time.sleep(3)
245
+        self.wait_nginx_pods_ready(k8sclient)
246
+
247
+        # STEP #4
248
+        show_step(4)
249
+        self.check_nginx_pods_image(k8sclient, self.from_nginx_image)
250
+        self.check_nginx_ds_image(k8sclient, self.from_nginx_image)
251
+
252
+        # STEP #5
253
+        show_step(5)
254
+        nginx_spec['spec']['template']['spec']['containers'][0][
255
+            'image'] = self.to_nginx_image
256
+        k8sclient.daemonsets.update(body=nginx_spec,
257
+                                    name=nginx_spec['metadata']['name'])
258
+
259
+        # STEP #6
260
+        show_step(6)
261
+        time.sleep(10)
262
+
263
+        # STEP #7
264
+        show_step(7)
265
+        # DaemonSet should have new image version
266
+        self.check_nginx_ds_image(k8sclient, self.to_nginx_image)
267
+        # Pods should have new image version
268
+        helpers.wait_pass(
269
+            lambda: self.check_nginx_pods_image(
270
+                k8sclient,
271
+                self.to_nginx_image),
272
+            timeout=2 * 60)

Loading…
Cancel
Save