Skip to content

Commit acf78ab

Browse files
DaanHooglandDaan Hoogland
authored andcommitted
test: cleanup resources in test_deploy_vm_iso and code
1 parent 72b99a3 commit acf78ab

1 file changed

Lines changed: 54 additions & 38 deletions

File tree

test/integration/smoke/test_deploy_vm_iso.py

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# Import Local Modules
2121
from nose.plugins.attrib import attr
2222
from marvin.cloudstackTestCase import cloudstackTestCase
23-
from marvin.lib.utils import cleanup_resources
2423
from marvin.lib.base import (Account,
2524
VirtualMachine,
2625
ServiceOffering,
@@ -38,28 +37,28 @@ class TestDeployVMFromISO(cloudstackTestCase):
3837
def setUpClass(cls):
3938

4039
cls.testClient = super(TestDeployVMFromISO, cls).getClsTestClient()
41-
cls.api_client = cls.testClient.getApiClient()
40+
cls.apiclient = cls.testClient.getApiClient()
4241

4342
cls.testdata = cls.testClient.getParsedTestDataConfig()
4443
# Get Zone, Domain and templates
45-
cls.domain = get_domain(cls.api_client)
46-
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
44+
cls.domain = get_domain(cls.apiclient)
45+
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
4746
cls.hypervisor = cls.testClient.getHypervisorInfo()
4847

4948
cls.template = get_test_template(
50-
cls.api_client,
49+
cls.apiclient,
5150
cls.zone.id,
5251
cls.hypervisor
5352
)
5453

5554
# Create service, disk offerings etc
5655
cls.service_offering = ServiceOffering.create(
57-
cls.api_client,
56+
cls.apiclient,
5857
cls.testdata["service_offering"]
5958
)
6059

6160
cls.disk_offering = DiskOffering.create(
62-
cls.api_client,
61+
cls.apiclient,
6362
cls.testdata["disk_offering"]
6463
)
6564

@@ -69,13 +68,6 @@ def setUpClass(cls):
6968
]
7069
return
7170

72-
@classmethod
73-
def tearDownClass(cls):
74-
try:
75-
cleanup_resources(cls.api_client, cls._cleanup)
76-
except Exception as e:
77-
raise Exception("Warning: Exception during cleanup : %s" % e)
78-
7971
def setUp(self):
8072

8173
self.apiclient = self.testClient.getApiClient()
@@ -92,35 +84,24 @@ def setUp(self):
9284
self.cleanup = [self.account]
9385
return
9486

95-
def tearDown(self):
96-
try:
97-
self.debug("Cleaning up the resources")
98-
cleanup_resources(self.apiclient, self.cleanup)
99-
self.debug("Cleanup complete!")
100-
except Exception as e:
101-
self.debug("Warning! Exception in tearDown: %s" % e)
102-
10387
@attr(
10488
tags=[
10589
"advanced",
10690
"eip",
10791
"advancedns",
10892
"basic",
109-
"sg"],
110-
required_hardware="true")
93+
"sg"
94+
],
95+
required_hardware="true"
96+
)
11197
def test_deploy_vm_from_iso(self):
11298
"""Test Deploy Virtual Machine from ISO
11399
"""
114100

115101
# Validate the following:
116-
# 1. deploy VM using ISO
117-
# 2. listVM command should return the deployed VM. State of this VM
118-
# should be "Running".
119-
self.hypervisor = self.testClient.getHypervisorInfo()
120-
if self.hypervisor.lower() in ['lxc']:
121-
self.skipTest(
122-
"vm deploy from ISO feature is not supported on %s" %
123-
self.hypervisor.lower())
102+
# 1. Create an ISO
103+
# 2. Deploy a VM from the ISO
104+
# 3. VM should be in 'Running' state
124105

125106
self.iso = Iso.create(
126107
self.apiclient,
@@ -129,16 +110,29 @@ def test_deploy_vm_from_iso(self):
129110
domainid=self.account.domainid,
130111
zoneid=self.zone.id
131112
)
113+
self.cleanup.append(self.iso)
114+
115+
self.debug("ISO created with ID: %s" % self.iso.id)
116+
117+
list_iso_response = Iso.list(
118+
self.apiclient,
119+
id=self.iso.id
120+
)
121+
self.assertEqual(
122+
isinstance(list_iso_response, list),
123+
True,
124+
"Check list response returns a valid list"
125+
)
126+
132127
try:
133128
# Download the ISO
134129
self.iso.download(self.apiclient)
135130
except Exception as e:
136131
raise Exception("Exception while downloading ISO %s: %s"
137132
% (self.iso.id, e))
138133

139-
self.debug("Registered ISO: %s" % self.iso.name)
140-
self.debug("Deploying instance in the account: %s" %
141-
self.account.name)
134+
self.debug(f"Registered ISO: {self.iso.name}")
135+
self.debug(f"Deploying instance in the account: {self.account.name}")
142136
self.virtual_machine = VirtualMachine.create(
143137
self.apiclient,
144138
self.testdata["virtual_machine"],
@@ -149,9 +143,31 @@ def test_deploy_vm_from_iso(self):
149143
diskofferingid=self.disk_offering.id,
150144
hypervisor=self.hypervisor
151145
)
146+
self.cleanup.append(self.virtual_machine)
152147

153-
response = self.virtual_machine.getState(
148+
self.debug("VM created with ID: %s" % self.virtual_machine.id)
149+
150+
list_vm_response = VirtualMachine.list(
154151
self.apiclient,
155-
VirtualMachine.RUNNING)
156-
self.assertEqual(response[0], PASS, response[1])
152+
id=self.virtual_machine.id
153+
)
154+
155+
self.assertEqual(
156+
isinstance(list_vm_response, list),
157+
True,
158+
"Check list response returns a valid list"
159+
)
160+
vm_response = list_vm_response[0]
161+
162+
self.assertEqual(
163+
vm_response.state,
164+
"Running",
165+
"Check virtual machine is in running state"
166+
)
167+
168+
self.assertEqual(
169+
vm_response.isoid,
170+
self.iso.id,
171+
"Check virtual machine is booted from the ISO"
172+
)
157173
return

0 commit comments

Comments
 (0)