From d281c46d94357becfe3a9ed326d9d3fdfbc4863e Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Thu, 4 Feb 2021 19:32:00 +0530 Subject: [PATCH] marvin: fix test failures when changing service offering of a VM --- .../smoke/test_service_offerings.py | 17 +++++++++++++ test/integration/smoke/test_vm_snapshots.py | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 0e7f068a2774..0ee055ad0f41 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -502,6 +502,23 @@ def test_04_change_offering_small(self): self.skipTest("Skipping this test for {} due to bug CS-38153".format(self.hypervisor)) try: self.medium_virtual_machine.stop(self.apiclient) + timeout = self.services["timeout"] + while True: + time.sleep(self.services["sleep"]) + # Ensure that VM is in stopped state + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.medium_virtual_machine.id + ) + if isinstance(list_vm_response, list): + vm = list_vm_response[0] + if vm.state == 'Stopped': + self.debug("VM state: %s" % vm.state) + break + if timeout == 0: + raise Exception( + "Failed to stop VM (ID: %s) in change service offering" % vm.id) + timeout = timeout - 1 except Exception as e: self.fail("Failed to stop VM: %s" % e) diff --git a/test/integration/smoke/test_vm_snapshots.py b/test/integration/smoke/test_vm_snapshots.py index a6803b80edaf..ce63ed4aa635 100644 --- a/test/integration/smoke/test_vm_snapshots.py +++ b/test/integration/smoke/test_vm_snapshots.py @@ -454,6 +454,30 @@ def test_change_service_offering_for_vm_with_snapshots(self): self.debug("Stopping VM - ID: %s" % virtual_machine.id) try: virtual_machine.stop(self.apiclient) + timeout = self.services["timeout"] + + while True: + time.sleep(self.services["sleep"]) + + # Ensure that VM is in stopped state + list_vm_response = list_virtual_machines( + self.apiclient, + id=virtual_machine.id + ) + + if isinstance(list_vm_response, list): + + vm = list_vm_response[0] + if vm.state == 'Stopped': + self.debug("VM state: %s" % vm.state) + break + + if timeout == 0: + raise Exception( + "Failed to stop VM (ID: %s) in change service offering" % vm.id) + + timeout = timeout - 1 + except Exception as e: self.fail("Failed to stop VM: %s" % e)