Skip to content

Commit 29cc73f

Browse files
committed
cleanup vm life cycle test file
1 parent a303c7c commit 29cc73f

10 files changed

+1615
-1355
lines changed

Diff for: test/integration/smoke/test_deploy_vm.py

+264
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
""" BVT tests for Virtual Machine Life Cycle
18+
"""
19+
# Import Local Modules
20+
from marvin.cloudstackTestCase import cloudstackTestCase
21+
from marvin.cloudstackAPI import (recoverVirtualMachine,
22+
destroyVirtualMachine,
23+
attachIso,
24+
detachIso,
25+
provisionCertificate,
26+
updateConfiguration,
27+
migrateVirtualMachine,
28+
migrateVirtualMachineWithVolume,
29+
listNics,
30+
listVolumes)
31+
from marvin.lib.utils import *
32+
33+
from marvin.lib.base import (Account,
34+
ServiceOffering,
35+
VirtualMachine,
36+
Host,
37+
Iso,
38+
Router,
39+
Configurations,
40+
StoragePool,
41+
Volume,
42+
DiskOffering,
43+
NetworkOffering,
44+
Network)
45+
from marvin.lib.common import (get_domain,
46+
get_zone,
47+
get_suitable_test_template,
48+
get_test_ovf_templates,
49+
list_hosts,
50+
get_vm_vapp_configs)
51+
from marvin.codes import FAILED, PASS
52+
from nose.plugins.attrib import attr
53+
from marvin.lib.decoratorGenerators import skipTestIf
54+
# Import System modules
55+
import time
56+
import json
57+
from operator import itemgetter
58+
59+
_multiprocess_shared_ = True
60+
61+
class TestDeployVM(cloudstackTestCase):
62+
63+
@classmethod
64+
def setUpClass(cls):
65+
testClient = super(TestDeployVM, cls).getClsTestClient()
66+
cls.apiclient = testClient.getApiClient()
67+
cls.services = testClient.getParsedTestDataConfig()
68+
69+
# Get Zone, Domain and templates
70+
cls.domain = get_domain(cls.apiclient)
71+
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
72+
cls.services['mode'] = cls.zone.networktype
73+
cls.hypervisor = testClient.getHypervisorInfo()
74+
75+
# If local storage is enabled, alter the offerings to use localstorage
76+
# this step is needed for devcloud
77+
if cls.zone.localstorageenabled == True:
78+
cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
79+
cls.services["service_offerings"]["small"]["storagetype"] = 'local'
80+
cls.services["service_offerings"]["medium"]["storagetype"] = 'local'
81+
82+
template = get_suitable_test_template(
83+
cls.apiclient,
84+
cls.zone.id,
85+
cls.services["ostype"],
86+
cls.hypervisor
87+
)
88+
if template == FAILED:
89+
assert False, "get_suitable_test_template() failed to return template with description %s" % cls.services["ostype"]
90+
91+
# Set Zones and disk offerings
92+
cls.services["small"]["zoneid"] = cls.zone.id
93+
cls.services["small"]["template"] = template.id
94+
95+
cls.services["iso1"]["zoneid"] = cls.zone.id
96+
97+
cls._cleanup = []
98+
99+
cls.account = Account.create(
100+
cls.apiclient,
101+
cls.services["account"],
102+
domainid=cls.domain.id
103+
)
104+
cls._cleanup.append(cls.account)
105+
cls.debug(cls.account.id)
106+
107+
cls.service_offering = ServiceOffering.create(
108+
cls.apiclient,
109+
cls.services["service_offerings"]["tiny"]
110+
)
111+
cls._cleanup.append(cls.service_offering)
112+
113+
cls.virtual_machine = VirtualMachine.create(
114+
cls.apiclient,
115+
cls.services["small"],
116+
accountid=cls.account.name,
117+
domainid=cls.account.domainid,
118+
serviceofferingid=cls.service_offering.id,
119+
mode=cls.services['mode']
120+
)
121+
cls._cleanup.append(cls.virtual_machine)
122+
123+
@classmethod
124+
def tearDownClass(cls):
125+
super(TestDeployVM, cls).tearDownClass()
126+
127+
def setUp(self):
128+
self.apiclient = self.testClient.getApiClient()
129+
self.dbclient = self.testClient.getDbConnection()
130+
self.cleanup = []
131+
132+
def tearDown(self):
133+
super(TestDeployVM, self).tearDown()
134+
135+
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
136+
def test_deploy_vm(self):
137+
"""Test Deploy Virtual Machine
138+
"""
139+
# Validate the following:
140+
# 1. Virtual Machine is accessible via SSH
141+
# 2. listVirtualMachines returns accurate information
142+
list_vm_response = VirtualMachine.list(
143+
self.apiclient,
144+
id=self.virtual_machine.id
145+
)
146+
147+
self.debug(
148+
"Verify listVirtualMachines response for virtual machine: %s" \
149+
% self.virtual_machine.id
150+
)
151+
self.assertEqual(
152+
isinstance(list_vm_response, list),
153+
True,
154+
"Check list response returns a valid list"
155+
)
156+
self.assertNotEqual(
157+
len(list_vm_response),
158+
0,
159+
"Check VM available in List Virtual Machines"
160+
)
161+
vm_response = list_vm_response[0]
162+
self.assertEqual(
163+
164+
vm_response.id,
165+
self.virtual_machine.id,
166+
"Check virtual machine id in listVirtualMachines"
167+
)
168+
self.assertEqual(
169+
vm_response.name,
170+
self.virtual_machine.name,
171+
"Check virtual machine name in listVirtualMachines"
172+
)
173+
self.assertEqual(
174+
vm_response.state,
175+
'Running',
176+
msg="VM is not in Running state"
177+
)
178+
return
179+
180+
@attr(tags=["advanced"], required_hardware="false")
181+
def test_advZoneVirtualRouter(self):
182+
# TODO: SIMENH: duplicate test, remove it
183+
"""
184+
Test advanced zone virtual router
185+
1. Is Running
186+
2. is in the account the VM was deployed in
187+
3. Has a linklocalip, publicip and a guestip
188+
@return:
189+
"""
190+
routers = Router.list(self.apiclient, account=self.account.name)
191+
self.assertTrue(len(routers) > 0, msg="No virtual router found")
192+
router = routers[0]
193+
194+
self.assertEqual(router.state, 'Running', msg="Router is not in running state")
195+
self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account")
196+
197+
# Has linklocal, public and guest ips
198+
self.assertIsNotNone(router.linklocalip, msg="Router has no linklocal ip")
199+
self.assertIsNotNone(router.publicip, msg="Router has no public ip")
200+
self.assertIsNotNone(router.guestipaddress, msg="Router has no guest ip")
201+
202+
@attr(mode=["basic"], required_hardware="false")
203+
def test_basicZoneVirtualRouter(self):
204+
# TODO: SIMENH: duplicate test, remove it
205+
"""
206+
Tests for basic zone virtual router
207+
1. Is Running
208+
2. is in the account the VM was deployed in
209+
@return:
210+
"""
211+
routers = Router.list(self.apiclient, account=self.account.name)
212+
self.assertTrue(len(routers) > 0, msg="No virtual router found")
213+
router = routers[0]
214+
215+
self.assertEqual(router.state, 'Running', msg="Router is not in running state")
216+
self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account")
217+
218+
@attr(tags=['advanced', 'basic', 'sg'], required_hardware="false")
219+
def test_deploy_vm_multiple(self):
220+
"""Test Multiple Deploy Virtual Machine
221+
222+
# Validate the following:
223+
# 1. deploy 2 virtual machines
224+
# 2. listVirtualMachines using 'ids' parameter returns accurate information
225+
"""
226+
account = Account.create(
227+
self.apiclient,
228+
self.services["account"],
229+
domainid=self.domain.id
230+
)
231+
self.cleanup.append(account)
232+
233+
virtual_machine1 = VirtualMachine.create(
234+
self.apiclient,
235+
self.services["small"],
236+
accountid=account.name,
237+
domainid=account.domainid,
238+
serviceofferingid=self.service_offering.id
239+
)
240+
self.cleanup.append(virtual_machine1)
241+
virtual_machine2 = VirtualMachine.create(
242+
self.apiclient,
243+
self.services["small"],
244+
accountid=account.name,
245+
domainid=account.domainid,
246+
serviceofferingid=self.service_offering.id
247+
)
248+
self.cleanup.append(virtual_machine2)
249+
250+
list_vms = VirtualMachine.list(self.apiclient, ids=[virtual_machine1.id, virtual_machine2.id], listAll=True)
251+
self.debug(
252+
"Verify listVirtualMachines response for virtual machines: %s, %s" % (
253+
virtual_machine1.id, virtual_machine2.id)
254+
)
255+
self.assertEqual(
256+
isinstance(list_vms, list),
257+
True,
258+
"List VM response was not a valid list"
259+
)
260+
self.assertEqual(
261+
len(list_vms),
262+
2,
263+
"List VM response was empty, expected 2 VMs"
264+
)

Diff for: test/integration/smoke/test_hostha_kvm.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def setUp(self):
7979
self.apiclient,
8080
self.services["service_offerings"]["hasmall"]
8181
)
82+
self.cleanup = [self.service_offering]
8283

8384
self.template = get_test_template(
8485
self.apiclient,
@@ -87,7 +88,6 @@ def setUp(self):
8788
)
8889

8990
self.configureAndDisableHostHa()
90-
self.cleanup = [self.service_offering]
9191

9292
def updateConfiguration(self, name, value):
9393
cmd = updateConfiguration.updateConfigurationCmd()
@@ -116,9 +116,10 @@ def tearDown(self):
116116
self.dbclient.execute("delete from mshost where runid=%s" % self.getFakeMsRunId())
117117
self.dbclient.execute("delete from cluster_details where name='outOfBandManagementEnabled'")
118118
self.dbclient.execute("delete from data_center_details where name='outOfBandManagementEnabled'")
119-
cleanup_resources(self.apiclient, self.cleanup)
120119
except Exception as e:
121120
raise Exception("Warning: Exception during cleanup : %s" % e)
121+
finally:
122+
super(TestHAKVM, self).tearDown()
122123

123124
def getHostHaEnableCmd(self):
124125
cmd = enableHAForHost.enableHAForHostCmd()
@@ -292,7 +293,6 @@ def test_hostha_enable_ha_when_host_in_maintenance(self):
292293
# Enable HA
293294
self.configureAndEnableHostHa()
294295

295-
296296
# Prepare for maintenance Host
297297
self.setHostToMaintanance(self.host.id)
298298

@@ -341,7 +341,6 @@ def test_remove_ha_provider_not_possible(self):
341341
"""
342342
self.logger.debug("Starting test_remove_ha_provider_not_possible")
343343

344-
345344
# Enable HA
346345
self.apiclient.configureHAForHost(self.getHostHaConfigCmd())
347346
cmd = self.getHostHaEnableCmd()
@@ -393,7 +392,6 @@ def test_hostha_kvm_host_degraded(self):
393392
self.startAgent()
394393
self.waitUntilHostInState("Available")
395394

396-
397395
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="true")
398396
def test_hostha_kvm_host_recovering(self):
399397
"""
@@ -581,7 +579,6 @@ def getIpmiServerIp(self):
581579
return s.getsockname()[0]
582580

583581
def get_non_configured_ha_host(self):
584-
585582
response = list_hosts(
586583
self.apiclient,
587584
type='Routing'

0 commit comments

Comments
 (0)