mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-8394: Use custom decorator to skip test case
Signed-off-by: Gaurav Aradhye <gaurav.aradhye@clogeny.com> This closes #190
This commit is contained in:
parent
23f4c022c2
commit
9a58794a04
@ -17,11 +17,19 @@
|
||||
|
||||
from marvin.codes import FAILED
|
||||
from nose.plugins.attrib import attr
|
||||
from marvin.cloudstackTestCase import *
|
||||
from marvin.cloudstackAPI import *
|
||||
from marvin.lib.utils import *
|
||||
from marvin.lib.base import *
|
||||
from marvin.lib.common import *
|
||||
from marvin.cloudstackTestCase import cloudstackTestCase
|
||||
from marvin.lib.utils import (cleanup_resources,
|
||||
is_snapshot_on_nfs)
|
||||
from marvin.lib.base import (VirtualMachine,
|
||||
Account,
|
||||
ServiceOffering,
|
||||
Snapshot)
|
||||
from marvin.lib.common import (get_domain,
|
||||
get_template,
|
||||
get_zone,
|
||||
list_volumes,
|
||||
list_snapshots)
|
||||
from marvin.lib.decoratorGenerators import skipTestIf
|
||||
|
||||
class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
|
||||
@ -36,10 +44,13 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
|
||||
cls.services['mode'] = cls.zone.networktype
|
||||
|
||||
cls.hypervisorNotSupported = False
|
||||
cls.hypervisor = cls.testClient.getHypervisorInfo()
|
||||
if cls.hypervisor.lower() in ['hyperv', 'lxc']:
|
||||
raise unittest.SkipTest("Snapshots not supported on Hyper-V or LXC")
|
||||
cls.hypervisorNotSupported = True
|
||||
|
||||
cls._cleanup = []
|
||||
if not cls.hypervisorNotSupported:
|
||||
template = get_template(
|
||||
cls.apiclient,
|
||||
cls.zone.id,
|
||||
@ -59,10 +70,12 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls._cleanup.append(cls.account)
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.services["service_offerings"]
|
||||
)
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
cls.virtual_machine = cls.virtual_machine_with_disk = \
|
||||
VirtualMachine.create(
|
||||
cls.apiclient,
|
||||
@ -73,10 +86,6 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
serviceofferingid=cls.service_offering.id,
|
||||
mode=cls.services["mode"]
|
||||
)
|
||||
cls._cleanup = [
|
||||
cls.service_offering,
|
||||
cls.account,
|
||||
]
|
||||
return
|
||||
|
||||
@classmethod
|
||||
@ -102,6 +111,7 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
@skipTestIf("hypervisorNotSupported")
|
||||
@attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="true")
|
||||
def test_01_snapshot_root_disk(self):
|
||||
"""Test Snapshot Root Disk
|
||||
@ -166,8 +176,6 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
qresult = qresultset[0]
|
||||
|
||||
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
|
||||
account_id = qresult[1]
|
||||
volume_id = qresult[2]
|
||||
|
||||
self.assertNotEqual(
|
||||
str(snapshot_uuid),
|
||||
|
||||
34
tools/marvin/marvin/lib/decoratorGenerators.py
Normal file
34
tools/marvin/marvin/lib/decoratorGenerators.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Custom decorator generators used across test cases
|
||||
"""
|
||||
|
||||
from functools import wraps
|
||||
|
||||
def skipTestIf(attribute):
|
||||
def decorator(test):
|
||||
@wraps(test)
|
||||
def test_wrapper(self, *args, **kwargs):
|
||||
if hasattr(self, attribute):
|
||||
if getattr(self, attribute):
|
||||
self.skipTest("Skipping test: Reason - %s" % attribute)
|
||||
else:
|
||||
return test(self, *args, **kwargs)
|
||||
else:
|
||||
return test(self, *args, **kwargs)
|
||||
return test_wrapper
|
||||
return decorator
|
||||
Loading…
x
Reference in New Issue
Block a user