Skip to content

Commit 452fa43

Browse files
test: deploy planner and metrics smoke test VMs in the test's own network
test_vm_deployment_planner.py and the VM tests in test_metrics_api.py deploy their VMs as the admin with no network, so they land in the admin account's shared network. When that network's router is stuck, or an earlier test has left the network in Shutdown, every VM in these files fails to start and the smoke run reports failures that have nothing to do with the change under test. Create an L2 network owned by the test account and deploy into it (in advanced zones only for the metrics test, which also runs on basic zones), and wait for usage history stats to show up instead of sleeping a fixed two minutes.
1 parent 8eeccdb commit 452fa43

2 files changed

Lines changed: 72 additions & 9 deletions

File tree

test/integration/smoke/test_metrics_api.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ def setUpClass(cls):
6868
domainid=cls.domain.id
6969
)
7070
cls._cleanup.append(cls.account)
71+
cls.network = None
72+
if cls.zone.networktype.lower() == 'advanced':
73+
cls.network_offering = NetworkOffering.create(
74+
cls.apiclient,
75+
cls.services["l2-network_offering"]
76+
)
77+
cls._cleanup.append(cls.network_offering)
78+
cls.network_offering.update(cls.apiclient, state="enabled")
79+
cls.network = Network.create(
80+
cls.apiclient,
81+
cls.services["l2-network"],
82+
accountid=cls.account.name,
83+
domainid=cls.account.domainid,
84+
networkofferingid=cls.network_offering.id,
85+
zoneid=cls.zone.id
86+
)
87+
cls._cleanup.append(cls.network)
7188
cls.hypervisorNotSupported = True
7289
if cls.hypervisor.lower() != 'simulator':
7390
cls.hypervisorNotSupported = False
@@ -207,6 +224,9 @@ def run_list_vm_metrics_test(self, is_user):
207224
self.small_virtual_machine = VirtualMachine.create(
208225
apiclient,
209226
self.services["virtual_machine"],
227+
accountid=self.account.name,
228+
domainid=self.account.domainid,
229+
networkids=[self.network.id] if self.network else None,
210230
serviceofferingid=self.service_offering.id,
211231
templateid=self.template.id,
212232
zoneid=self.zone.id
@@ -466,19 +486,19 @@ def test_list_vms_metrics_history(self):
466486
self.small_virtual_machine = VirtualMachine.create(
467487
self.apiclient,
468488
self.services["virtual_machine"],
489+
accountid=self.account.name,
490+
domainid=self.account.domainid,
491+
networkids=[self.network.id] if self.network else None,
469492
serviceofferingid=self.service_offering.id,
470493
templateid=self.template.id,
471494
zoneid=self.zone.id
472495
)
473496
self.cleanup.append(self.small_virtual_machine)
474497

475-
# Wait for 2 minutes
476-
time.sleep(120)
477-
478498
cmd = listVirtualMachinesUsageHistory.listVirtualMachinesUsageHistoryCmd()
479499
cmd.id = self.small_virtual_machine.id
480500

481-
result = self.apiclient.listVirtualMachinesUsageHistory(cmd)[0]
501+
result = self.wait_for_stats(lambda: self.apiclient.listVirtualMachinesUsageHistory(cmd))
482502

483503
self.assertEqual(result.id, self.small_virtual_machine.id)
484504
self.assertTrue(hasattr(result, 'stats'))
@@ -510,6 +530,9 @@ def test_list_volumes_metrics_history(self):
510530
self.small_virtual_machine = VirtualMachine.create(
511531
self.apiclient,
512532
self.services["virtual_machine"],
533+
accountid=self.account.name,
534+
domainid=self.account.domainid,
535+
networkids=[self.network.id] if self.network else None,
513536
serviceofferingid=self.service_offering.id,
514537
templateid=self.template.id,
515538
zoneid=self.zone.id
@@ -522,17 +545,15 @@ def test_list_volumes_metrics_history(self):
522545
self.skipTest("Skipping test because volume metrics doesn't work on hypervisor\
523546
%s, %s" % (currentHost.hypervisor, currentHost.hypervisorversion))
524547

525-
# Wait for 2 minutes
526-
time.sleep(120)
527-
528548
volume = Volume.list(
529549
self.apiclient,
530-
virtualmachineid=self.small_virtual_machine.id)[0]
550+
virtualmachineid=self.small_virtual_machine.id,
551+
listall=True)[0]
531552

532553
cmd = listVolumesUsageHistory.listVolumesUsageHistoryCmd()
533554
cmd.id = volume.id
534555

535-
result = self.apiclient.listVolumesUsageHistory(cmd)[0]
556+
result = self.wait_for_stats(lambda: self.apiclient.listVolumesUsageHistory(cmd))
536557
self.assertEqual(result.id, volume.id)
537558
self.assertTrue(hasattr(result, 'stats'))
538559
self.assertTrue(type(result.stats) == list and len(result.stats) > 0)
@@ -547,6 +568,18 @@ def test_list_volumes_metrics_history(self):
547568

548569
return
549570

571+
def wait_for_stats(self, list_usage_history):
572+
def stats_collected():
573+
response = list_usage_history()
574+
if isinstance(response, list) and len(response) > 0 and \
575+
isinstance(getattr(response[0], 'stats', None), list) and len(response[0].stats) > 0:
576+
return True, response[0]
577+
return False, None
578+
579+
collected, result = wait_until(15, 20, stats_collected)
580+
self.assertTrue(collected, "No usage history stats were collected within 5 minutes")
581+
return result
582+
550583
def validate_vm_stats(self, stats):
551584
self.assertTrue(hasattr(stats, 'cpuused'))
552585
self.assertTrue(hasattr(stats, 'diskiopstotal'))

test/integration/smoke/test_vm_deployment_planner.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from marvin.cloudstackTestCase import cloudstackTestCase
2222
from marvin.lib.base import (Account,
2323
ServiceOffering,
24+
NetworkOffering,
25+
Network,
2426
Host, Pod, Cluster)
2527
from marvin.lib.common import (get_domain,
2628
get_zone,
@@ -61,10 +63,33 @@ def setUpClass(cls):
6163
cls.service_offering
6264
]
6365

66+
cls.network_offering = NetworkOffering.create(
67+
cls.apiclient,
68+
cls.services["l2-network_offering"]
69+
)
70+
cls._cleanup.append(cls.network_offering)
71+
cls.network_offering.update(cls.apiclient, state="enabled")
72+
73+
cls.network = Network.create(
74+
cls.apiclient,
75+
cls.services["l2-network"],
76+
accountid=cls.account.name,
77+
domainid=cls.account.domainid,
78+
networkofferingid=cls.network_offering.id,
79+
zoneid=cls.zone.id
80+
)
81+
cls._cleanup.append(cls.network)
82+
6483
@classmethod
6584
def tearDownClass(cls):
6685
super(TestVMDeploymentPlanner, cls).tearDownClass()
6786

87+
def set_owner(self, cmd):
88+
cmd.account = self.account.name
89+
cmd.domainid = self.account.domainid
90+
cmd.networkids = [self.network.id]
91+
return cmd
92+
6893
def deploy_vm(self, destination_id):
6994
cmd = deployVirtualMachine.deployVirtualMachineCmd()
7095
template = get_template(
@@ -75,6 +100,7 @@ def deploy_vm(self, destination_id):
75100
cmd.templateid = template.id
76101
cmd.serviceofferingid = self.service_offering.id
77102
cmd.hostid = destination_id
103+
self.set_owner(cmd)
78104
return self.apiclient.deployVirtualMachine(cmd)
79105

80106
def destroy_vm(self, vm_id):
@@ -123,6 +149,7 @@ def test_02_deploy_vm_on_specific_cluster(self):
123149
cmd.serviceofferingid = self.service_offering.id
124150
cmd.templateid = template.id
125151
cmd.clusterid = target_id
152+
self.set_owner(cmd)
126153
vm = self.apiclient.deployVirtualMachine(cmd)
127154

128155
vm_host = Host.list(self.apiclient,
@@ -160,6 +187,7 @@ def test_03_deploy_vm_on_specific_pod(self):
160187

161188
cmd.templateid = template.id
162189
cmd.podid = target_pod.id
190+
self.set_owner(cmd)
163191
vm = self.apiclient.deployVirtualMachine(cmd)
164192

165193
vm_host = Host.list(self.apiclient,
@@ -200,6 +228,7 @@ def test_04_deploy_vm_on_host_override_pod_and_cluster(self):
200228
cmd.podid = pod.id
201229
cmd.clusterid = clusters[1].id if len(clusters) > 1 else clusters[0].id
202230
cmd.hostid = host.id
231+
self.set_owner(cmd)
203232

204233
vm = self.apiclient.deployVirtualMachine(cmd)
205234

@@ -235,6 +264,7 @@ def test_05_deploy_vm_on_cluster_override_pod(self):
235264
# Add optional deployment params
236265
cmd.podid = pod.id
237266
cmd.clusterid = clusters[0].id
267+
self.set_owner(cmd)
238268

239269
vm = self.apiclient.deployVirtualMachine(cmd)
240270

0 commit comments

Comments
 (0)