Browse Source

Merge "Rollout multiple times a daemonset using --revision key"

Jenkins 2 years ago
parent
commit
2e7445e92b
1 changed files with 179 additions and 0 deletions
  1. 179
    0
      fuel_ccp_tests/tests/system/test_daemonsets.py

+ 179
- 0
fuel_ccp_tests/tests/system/test_daemonsets.py View File

@@ -28,6 +28,7 @@ class TestDaemonsetsUpdates():
28 28
 
29 29
     from_nginx_image = 'nginx:1.10'
30 30
     to_nginx_image = 'nginx:1.11'
31
+    to_nginx_image_1_12 = 'nginx:1.12'
31 32
 
32 33
     def get_nginx_spec(self):
33 34
         """Create specification for DaemonSet with Nginx containers
@@ -122,6 +123,19 @@ class TestDaemonsetsUpdates():
122 123
                 "DaemonSet {0} has image {1} while expected {2}"
123 124
                 .format(nginx_ds.name, nginx_ds_image, nginx_image))
124 125
 
126
+    def check_nginx_revision_image(self, config, underlay,
127
+                                   revision, nginx_image):
128
+        cmd = "kubectl rollout history daemonset/nginx " \
129
+              "--revision {} | grep Image".format(revision)
130
+        nginx_revision_image = underlay.check_call(cmd,
131
+                                                   host=config
132
+                                                   )['stdout_str'].replace(
133
+            '\t', '').split(
134
+            ":", 1)[1]
135
+        assert nginx_revision_image == nginx_image, (
136
+            "revision {0} has image {1} while expected {2}".format(
137
+                revision, nginx_revision_image, nginx_image))
138
+
125 139
     @pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
126 140
     @pytest.mark.fail_snapshot
127 141
     @pytest.mark.snapshot_needed
@@ -471,3 +485,168 @@ class TestDaemonsetsUpdates():
471 485
                 self.from_nginx_image),
472 486
             timeout=2 * 60
473 487
         )
488
+
489
+    @pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
490
+    @pytest.mark.fail_snapshot
491
+    @pytest.mark.snapshot_needed
492
+    def test_daemonset_multirollout_rollingupdate_revision(self,
493
+                                                           config,
494
+                                                           k8scluster,
495
+                                                           show_step,
496
+                                                           underlay):
497
+        """Rollout a daemonset using updateStrategy type: RollingUpdate and
498
+            --to-revision argument
499
+
500
+        Scenario:
501
+            1. Deploy k8s using fuel-ccp-installer
502
+            2. Create a DaemonSet for nginx with image version 1_10 and
503
+               update strategy RollingUpdate
504
+            3. Wait until nginx pods are created and become 'ready'
505
+            4. Check that the image version in the nginx pods is 1_10
506
+               Check that the image version in the nginx daemonset is 1_10
507
+            5. Change nginx image version to 1_11 using YAML
508
+            6. Check that the image version in the nginx daemonset
509
+               is updated to 1_11
510
+               Wait for ~120 sec that the image version in the nginx pods
511
+               is changed to 1_11
512
+            7. Change nginx image version to 1_12 using YAML
513
+            8. Check that the image version in the nginx daemonset
514
+                is updated to 1_12.
515
+               Wait for ~120 sec that the image version in the nginx pods
516
+               is changed to 1_12 .
517
+            9. Get the revision #1 and check that there are the image
518
+               version 1_10
519
+            10. Get the revision #2 and check that there are the image
520
+                version 1_11
521
+            11. Get the revision #3 and check that there are the image
522
+                version 1_12
523
+            12. Rollback the nginx daemonset to revision #1:
524
+                kubectl rollout undo daemonset/nginx --to-revision=1
525
+            13. Check that the image version in the nginx daemonset
526
+                is updated to 1_10
527
+                Wait for ~120 sec that the image version in the nginx pods
528
+                is changed to 1_10
529
+            14. Rollback the nginx daemonset:
530
+                kubectl rollout undo daemonset/nginx
531
+            15. Check that the image version in the nginx daemonset
532
+                is updated to 1_12
533
+                Wait for ~120 sec that the image version in the nginx pods
534
+                is changed to 1_12
535
+
536
+        Duration: 3000 seconds
537
+        """
538
+
539
+        # STEP #1
540
+        show_step(1)
541
+        k8sclient = k8scluster.api
542
+        assert k8sclient.nodes.list() is not None, "Can not get nodes list"
543
+
544
+        # STEP #2
545
+        show_step(2)
546
+        nginx_spec = self.get_nginx_spec()
547
+        nginx_spec['spec']['template']['spec']['containers'][0][
548
+            'image'] = self.from_nginx_image
549
+        k8sclient.daemonsets.create(body=nginx_spec)
550
+
551
+        # STEP #3
552
+        show_step(3)
553
+        time.sleep(3)
554
+        self.wait_nginx_pods_ready(k8sclient)
555
+
556
+        # STEP #4
557
+        show_step(4)
558
+        self.check_nginx_pods_image(k8sclient, self.from_nginx_image)
559
+        self.check_nginx_ds_image(k8sclient, self.from_nginx_image)
560
+
561
+        # STEP #5
562
+        show_step(5)
563
+        nginx_spec['spec']['template']['spec']['containers'][0][
564
+            'image'] = self.to_nginx_image
565
+        k8sclient.daemonsets.update(body=nginx_spec,
566
+                                    name=nginx_spec['metadata']['name'])
567
+
568
+        # STEP #6
569
+        show_step(6)
570
+
571
+        # DaemonSet should have new image version
572
+        self.check_nginx_ds_image(k8sclient, self.to_nginx_image)
573
+        # Pods should have new image version
574
+        helpers.wait_pass(
575
+            lambda: self.check_nginx_pods_image(
576
+                k8sclient,
577
+                self.to_nginx_image),
578
+            timeout=2 * 60)
579
+
580
+        # STEP #7
581
+        show_step(7)
582
+        nginx_spec['spec']['template']['spec']['containers'][0][
583
+            'image'] = self.to_nginx_image_1_12
584
+        k8sclient.daemonsets.update(body=nginx_spec,
585
+                                    name=nginx_spec['metadata']['name'])
586
+
587
+        # STEP #8
588
+        show_step(8)
589
+
590
+        # DaemonSet should have new image version
591
+        self.check_nginx_ds_image(k8sclient, self.to_nginx_image_1_12)
592
+        # Pods should have new image version
593
+        helpers.wait_pass(
594
+            lambda: self.check_nginx_pods_image(
595
+                k8sclient,
596
+                self.to_nginx_image_1_12),
597
+            timeout=2 * 60)
598
+
599
+        # STEP #9
600
+        show_step(9)
601
+        self.check_nginx_revision_image(config=config.k8s.kube_host,
602
+                                        underlay=underlay,
603
+                                        revision="1",
604
+                                        nginx_image=self.from_nginx_image)
605
+
606
+        # STEP #10
607
+        show_step(10)
608
+        self.check_nginx_revision_image(config=config.k8s.kube_host,
609
+                                        underlay=underlay,
610
+                                        revision="2",
611
+                                        nginx_image=self.to_nginx_image)
612
+
613
+        # STEP #11
614
+        show_step(11)
615
+        self.check_nginx_revision_image(config=config.k8s.kube_host,
616
+                                        underlay=underlay,
617
+                                        revision="3",
618
+                                        nginx_image=self.to_nginx_image_1_12)
619
+
620
+        # STEP #12
621
+        show_step(12)
622
+        cmd = "kubectl rollout undo daemonset/nginx --to-revision=1"
623
+        underlay.check_call(cmd,
624
+                            host=config.k8s.kube_host)
625
+
626
+        # STEP #13
627
+        show_step(13)
628
+        self.check_nginx_ds_image(k8sclient, self.to_nginx_image)
629
+        # Pods should have old image version
630
+        helpers.wait_pass(
631
+            lambda: self.check_nginx_pods_image(
632
+                k8sclient,
633
+                self.from_nginx_image),
634
+            timeout=2 * 60
635
+        )
636
+
637
+        # STEP #14
638
+        show_step(14)
639
+        cmd = "kubectl rollout undo daemonset/nginx"
640
+        underlay.check_call(cmd,
641
+                            host=config.k8s.kube_host)
642
+
643
+        # STEP #15
644
+        show_step(15)
645
+        self.check_nginx_ds_image(k8sclient, self.from_nginx_image)
646
+        # Pods should have new image version
647
+        helpers.wait_pass(
648
+            lambda: self.check_nginx_pods_image(
649
+                k8sclient,
650
+                self.to_nginx_image_1_12),
651
+            timeout=2 * 60
652
+        )

Loading…
Cancel
Save