Skip to content

Commit bede34d

Browse files
author
Gaurav Aradhye
committed
CLOUDSTACK-8394: Skip test cases through setUp() instead of setUpClass()
Signed-off-by: Gaurav Aradhye <gaurav.aradhye@clogeny.com> This closes apache#203
1 parent 0436560 commit bede34d

7 files changed

Lines changed: 86 additions & 48 deletions

File tree

test/integration/smoke/test_deploy_vgpu_enabled_vm.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Test from the Marvin - Testing in Python wiki
1919

2020
# All tests inherit from cloudstackTestCase
21-
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
21+
from marvin.cloudstackTestCase import cloudstackTestCase
2222

2323
# Import Integration Libraries
2424

@@ -49,15 +49,19 @@ def setUpClass(self):
4949
testClient = super(TestDeployvGPUenabledVM, self).getClsTestClient()
5050
self.apiclient = testClient.getApiClient()
5151
self.testdata = self.testClient.getParsedTestDataConfig()
52+
self._cleanup = []
53+
self.unsupportedHypervisor = False
54+
self.noSuitableHost = False
5255
# Need to add check whether zone containing the xen hypervisor or not
5356
# as well
5457
hosts = list_hosts(
5558
self.apiclient,
5659
hypervisor="XenServer"
5760
)
5861
if hosts is None:
59-
raise unittest.SkipTest(
60-
"There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response")
62+
# GPU feature is supported only on XenServer.Check listhosts response
63+
self.unsupportedHypervisor = True
64+
return
6165
else:
6266
gpuhosts = 0
6367
for ghost in hosts:
@@ -79,8 +83,9 @@ def setUpClass(self):
7983
else:
8084
continue
8185
if gpuhosts == 0:
82-
raise unittest.SkipTest(
83-
"No XenServer available with GPU Drivers installed")
86+
# No XenServer available with GPU Drivers installed
87+
self.noSuitableHost = True
88+
return
8489

8590
self.domain = get_domain(self.apiclient)
8691
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
@@ -90,13 +95,14 @@ def setUpClass(self):
9095
self.testdata["account"],
9196
domainid=self.domain.id
9297
)
93-
self._cleanup = [
94-
self.account
95-
]
98+
self._cleanup.append(self.account)
9699

97100
def setUp(self):
98101
self.testdata = self.testClient.getParsedTestDataConfig()["vgpu"]
99102
self.apiclient = self.testClient.getApiClient()
103+
if self.noSuitableHost or self.unsupportedHypervisor:
104+
self.skipTest("Skipping test because suitable hypervisor/host not\
105+
present")
100106

101107
# Get Zone, Domain and Default Built-in template
102108
self.domain = get_domain(self.apiclient)

test/integration/smoke/test_nic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
""" NIC tests for VM """
18-
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
18+
from marvin.cloudstackTestCase import cloudstackTestCase
1919
from marvin.lib.base import (Account,
2020
ServiceOffering,
2121
Network,
@@ -47,7 +47,7 @@ def signal_handler(signal, frame):
4747

4848
self.hypervisor = self.testClient.getHypervisorInfo()
4949
if self.hypervisor.lower() == "hyperv":
50-
raise unittest.SkipTest("Not supported on Hyper-V")
50+
self.skipTest("Not supported on Hyper-V")
5151

5252
try:
5353
self.apiclient = self.testClient.getApiClient()

test/integration/smoke/test_nic_adapter_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_vm_nic_adapter_vmxnet3(self):
125125
"""
126126

127127
if self.hypervisor.lower() not in ["vmware"]:
128-
raise unittest.SkipTest("This test case is written specifically\
128+
self.skipTest("This test case is written specifically\
129129
for Vmware hypervisor")
130130

131131
# Register a private template in the account with nic adapter vmxnet3

test/integration/smoke/test_scale_vm.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"""
1919
# Import Local Modules
2020
from marvin.codes import FAILED
21-
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
21+
from marvin.cloudstackTestCase import cloudstackTestCase
2222
from marvin.cloudstackAPI import scaleVirtualMachine
2323
from marvin.lib.utils import cleanup_resources
2424
from marvin.lib.base import (Account,
@@ -39,11 +39,12 @@ def setUpClass(cls):
3939
testClient = super(TestScaleVm, cls).getClsTestClient()
4040
cls.apiclient = testClient.getApiClient()
4141
cls.services = testClient.getParsedTestDataConfig()
42+
cls._cleanup = []
43+
cls.unsupportedHypervisor = False
4244
cls.hypervisor = cls.testClient.getHypervisorInfo()
4345
if cls.hypervisor.lower() in ('kvm', 'hyperv', 'lxc'):
44-
raise unittest.SkipTest(
45-
"ScaleVM is not supported on KVM, Hyper-V or LXC.\
46-
Hence, skipping the test")
46+
cls.unsupportedHypervisor = True
47+
return
4748

4849
# Get Zone, Domain and templates
4950
domain = get_domain(cls.apiclient)
@@ -107,6 +108,10 @@ def setUp(self):
107108
self.dbclient = self.testClient.getDbConnection()
108109
self.cleanup = []
109110

111+
if self.unsupportedHypervisor:
112+
self.skipTest("Skipping test because unsupported hypervisor\
113+
%s" % self.hypervisor)
114+
110115
def tearDown(self):
111116
# Clean up, terminate the created ISOs
112117
cleanup_resources(self.apiclient, self.cleanup)

test/integration/smoke/test_templates.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def setUp(self):
4444
self.apiclient = self.testClient.getApiClient()
4545
self.dbclient = self.testClient.getDbConnection()
4646
self.cleanup = []
47+
48+
if self.unsupportedHypervisor:
49+
self.skipTest("Skipping test because unsupported hypervisor\
50+
%s" % self.hypervisor)
4751
return
4852

4953
def tearDown(self):
@@ -59,17 +63,19 @@ def tearDown(self):
5963
def setUpClass(cls):
6064
testClient = super(TestCreateTemplate, cls).getClsTestClient()
6165
cls.apiclient = testClient.getApiClient()
66+
cls._cleanup = []
6267
cls.services = testClient.getParsedTestDataConfig()
68+
cls.unsupportedHypervisor = False
6369
cls.hypervisor = testClient.getHypervisorInfo()
6470
if cls.hypervisor.lower() in ['lxc']:
65-
raise unittest.SkipTest("Template creation from root volume is not supported in LXC")
71+
# Template creation from root volume is not supported in LXC
72+
cls.unsupportedHypervisor = True
73+
return
6674

6775
# Get Zone, Domain and templates
6876
cls.domain = get_domain(cls.apiclient)
6977
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
7078
cls.services['mode'] = cls.zone.networktype
71-
72-
cls._cleanup = []
7379
try:
7480
cls.disk_offering = DiskOffering.create(
7581
cls.apiclient,
@@ -210,10 +216,14 @@ def setUpClass(cls):
210216

211217
testClient = super(TestTemplates, cls).getClsTestClient()
212218
cls.apiclient = testClient.getApiClient()
219+
cls._cleanup = []
213220
cls.services = testClient.getParsedTestDataConfig()
221+
cls.unsupportedHypervisor = False
214222
cls.hypervisor = testClient.getHypervisorInfo()
215223
if cls.hypervisor.lower() in ['lxc']:
216-
raise unittest.SkipTest("Template creation from root volume is not supported in LXC")
224+
# Template creation from root volume is not supported in LXC
225+
cls.unsupportedHypervisor = True
226+
return
217227

218228
# Get Zone, Domain and templates
219229
cls.domain = get_domain(cls.apiclient)
@@ -325,6 +335,10 @@ def setUp(self):
325335
self.apiclient = self.testClient.getApiClient()
326336
self.dbclient = self.testClient.getDbConnection()
327337
self.cleanup = []
338+
339+
if self.unsupportedHypervisor:
340+
self.skipTest("Skipping test because unsupported hypervisor\
341+
%s" % self.hypervisor)
328342
return
329343

330344
def tearDown(self):

test/integration/smoke/test_vm_snapshots.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Import Local Modules
1919
from marvin.codes import FAILED, KVM, PASS
2020
from nose.plugins.attrib import attr
21-
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
21+
from marvin.cloudstackTestCase import cloudstackTestCase
2222
from marvin.lib.utils import random_gen, cleanup_resources, validateList
2323
from marvin.lib.base import (Account,
2424
ServiceOffering,
@@ -37,13 +37,14 @@ class TestVmSnapshot(cloudstackTestCase):
3737
@classmethod
3838
def setUpClass(cls):
3939
testClient = super(TestVmSnapshot, cls).getClsTestClient()
40-
41-
hypervisor = testClient.getHypervisorInfo()
42-
if hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"):
43-
raise unittest.SkipTest(
44-
"VM snapshot feature is not supported on KVM, Hyper-V or LXC")
45-
4640
cls.apiclient = testClient.getApiClient()
41+
cls._cleanup = []
42+
cls.unsupportedHypervisor = False
43+
cls.hypervisor = testClient.getHypervisorInfo()
44+
if cls.hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"):
45+
cls.unsupportedHypervisor = True
46+
return
47+
4748
cls.services = testClient.getParsedTestDataConfig()
4849
# Get Zone, Domain and templates
4950
cls.domain = get_domain(cls.apiclient)
@@ -69,11 +70,13 @@ def setUpClass(cls):
6970
cls.services["account"],
7071
domainid=cls.domain.id
7172
)
73+
cls._cleanup.append(cls.account)
7274

7375
cls.service_offering = ServiceOffering.create(
7476
cls.apiclient,
7577
cls.services["service_offerings"]
7678
)
79+
cls._cleanup.append(cls.service_offering)
7780
cls.virtual_machine = VirtualMachine.create(
7881
cls.apiclient,
7982
cls.services["server"],
@@ -86,10 +89,6 @@ def setUpClass(cls):
8689
cls.random_data_0 = random_gen(size=100)
8790
cls.test_dir = "/tmp"
8891
cls.random_data = "random.data"
89-
cls._cleanup = [
90-
cls.service_offering,
91-
cls.account,
92-
]
9392
return
9493

9594
@classmethod
@@ -105,6 +104,10 @@ def setUp(self):
105104
self.apiclient = self.testClient.getApiClient()
106105
self.dbclient = self.testClient.getDbConnection()
107106
self.cleanup = []
107+
108+
if self.unsupportedHypervisor:
109+
self.skipTest("Skipping test because unsupported hypervisor\
110+
%s" % self.hypervisor)
108111
return
109112

110113
def tearDown(self):
@@ -285,10 +288,11 @@ def setUpClass(cls):
285288
cls.testClient = super(TestSnapshots, cls).getClsTestClient()
286289
cls.api_client = cls.testClient.getApiClient()
287290
cls.services = cls.testClient.getParsedTestDataConfig()
291+
cls.unsupportedHypervisor = False
288292
cls.hypervisor = cls.testClient.getHypervisorInfo()
289293
if cls.hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"):
290-
raise unittest.SkipTest(
291-
"VM snapshot feature is not supported on KVM, Hyper-V or LXC")
294+
cls.unsupportedHypervisor = True
295+
return
292296
# Get Domain, Zone, Template
293297
cls.domain = get_domain(cls.api_client)
294298
cls.zone = get_zone(
@@ -335,6 +339,10 @@ def setUp(self):
335339
self.apiclient = self.testClient.getApiClient()
336340
self.cleanup = []
337341

342+
if self.unsupportedHypervisor:
343+
self.skipTest("Skipping test because unsupported\
344+
hypervisor %s" % self.hypervisor)
345+
338346
def tearDown(self):
339347
# Clean up, terminate the created resources
340348
cleanup_resources(self.apiclient, self.cleanup)

test/integration/smoke/test_volumes.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
""" BVT tests for Volumes
1818
"""
1919
#Import Local Modules
20-
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
20+
from marvin.cloudstackTestCase import cloudstackTestCase
2121
#from marvin.cloudstackException import *
2222
from marvin.cloudstackAPI import (deleteVolume,
2323
extractVolume,
@@ -57,12 +57,16 @@ def setUpClass(cls):
5757
# Get Zone, Domain and templates
5858
cls.domain = get_domain(cls.apiclient)
5959
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
60+
cls._cleanup = []
6061
cls.hypervisor = testClient.getHypervisorInfo()
6162
cls.services['mode'] = cls.zone.networktype
63+
cls.invalidStoragePoolType = False
6264
#for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
6365
if cls.hypervisor.lower() == 'lxc':
6466
if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
65-
raise unittest.SkipTest("RBD storage type is required for data volumes for LXC")
67+
# RBD storage type is required for data volumes for LXC
68+
cls.invalidStoragePoolType = True
69+
return
6670
cls.disk_offering = DiskOffering.create(
6771
cls.apiclient,
6872
cls.services["disk_offering"]
@@ -120,6 +124,10 @@ def setUp(self):
120124
self.dbclient = self.testClient.getDbConnection()
121125
self.cleanup = []
122126

127+
if self.invalidStoragePoolType:
128+
self.skipTest("Skipping test because of valid storage\
129+
pool not available")
130+
123131
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true")
124132
def test_01_create_volume(self):
125133
"""Test Volume creation for all Disk Offerings (incl. custom)
@@ -264,16 +272,19 @@ def setUpClass(cls):
264272
testClient = super(TestVolumes, cls).getClsTestClient()
265273
cls.apiclient = testClient.getApiClient()
266274
cls.services = testClient.getParsedTestDataConfig()
267-
275+
cls._cleanup = []
268276
# Get Zone, Domain and templates
269277
cls.domain = get_domain(cls.apiclient)
270278
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
271279
cls.services['mode'] = cls.zone.networktype
272280
cls.hypervisor = testClient.getHypervisorInfo()
281+
cls.invalidStoragePoolType = False
273282
#for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
274283
if cls.hypervisor.lower() == 'lxc':
275284
if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
276-
raise unittest.SkipTest("RBD storage type is required for data volumes for LXC")
285+
# RBD storage type is required for data volumes for LXC
286+
cls.invalidStoragePoolType = True
287+
return
277288
cls.disk_offering = DiskOffering.create(
278289
cls.apiclient,
279290
cls.services["disk_offering"]
@@ -321,16 +332,7 @@ def setUpClass(cls):
321332
serviceofferingid=cls.service_offering.id,
322333
mode=cls.services["mode"]
323334
)
324-
pools = StoragePool.list(cls.apiclient)
325-
# cls.assertEqual(
326-
# validateList(pools)[0],
327-
# PASS,
328-
# "storage pool list validation failed")
329-
330-
331335

332-
if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd':
333-
raise unittest.SkipTest("Snapshots not supported on Hyper-V or LXC")
334336
cls.volume = Volume.create(
335337
cls.apiclient,
336338
cls.services,
@@ -359,6 +361,10 @@ def setUp(self):
359361
self.attached = False
360362
self.cleanup = []
361363

364+
if self.invalidStoragePoolType:
365+
self.skipTest("Skipping test because valid storage pool not\
366+
available")
367+
362368
def tearDown(self):
363369
#Clean up, terminate the created volumes
364370
if self.attached:
@@ -454,7 +460,7 @@ def test_04_delete_attached_volume(self):
454460
#with self.assertRaises(Exception):
455461
with self.assertRaises(Exception):
456462
self.apiClient.deleteVolume(cmd)
457-
463+
458464
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
459465
def test_05_detach_volume(self):
460466
"""Detach a Volume attached to a VM
@@ -590,7 +596,6 @@ def test_07_resize_fail(self):
590596
cmd.id = self.volume.id
591597
cmd.diskofferingid = self.services['diskofferingid']
592598
cmd.size = 4
593-
currentSize = self.volume.size
594599

595600
self.debug(
596601
"Attaching volume (ID: %s) to VM (ID: %s)" % (
@@ -619,7 +624,7 @@ def test_07_resize_fail(self):
619624
if hosts[0].hypervisor == "XenServer":
620625
self.virtual_machine.start(self.apiClient)
621626
time.sleep(30)
622-
return
627+
return
623628

624629

625630
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true")

0 commit comments

Comments
 (0)