From 9a58794a04f8f94c5b04b93b39e5544eb75b5a8e Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Fri, 24 Apr 2015 14:15:37 +0530 Subject: [PATCH] CLOUDSTACK-8394: Use custom decorator to skip test case Signed-off-by: Gaurav Aradhye This closes #190 --- test/integration/smoke/test_snapshots.py | 54 +++++++++++-------- .../marvin/marvin/lib/decoratorGenerators.py | 34 ++++++++++++ 2 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 tools/marvin/marvin/lib/decoratorGenerators.py diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py index 2df17782e76..d230c6765bf 100644 --- a/test/integration/smoke/test_snapshots.py +++ b/test/integration/smoke/test_snapshots.py @@ -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,34 +44,39 @@ 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 - template = get_template( + cls._cleanup = [] + if not cls.hypervisorNotSupported: + template = get_template( cls.apiclient, cls.zone.id, cls.services["ostype"] ) - if template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] - cls.services["domainid"] = cls.domain.id - cls.services["server_without_disk"]["zoneid"] = cls.zone.id - cls.services["templates"]["ostypeid"] = template.ostypeid - cls.services["zoneid"] = cls.zone.id + cls.services["domainid"] = cls.domain.id + cls.services["server_without_disk"]["zoneid"] = cls.zone.id + cls.services["templates"]["ostypeid"] = template.ostypeid + cls.services["zoneid"] = cls.zone.id - # Create VMs, NAT Rules etc - cls.account = Account.create( + # Create VMs, NAT Rules etc + cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - cls.service_offering = ServiceOffering.create( + cls._cleanup.append(cls.account) + cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"] ) - cls.virtual_machine = cls.virtual_machine_with_disk = \ + cls._cleanup.append(cls.service_offering) + cls.virtual_machine = cls.virtual_machine_with_disk = \ VirtualMachine.create( cls.apiclient, cls.services["server_without_disk"], @@ -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), diff --git a/tools/marvin/marvin/lib/decoratorGenerators.py b/tools/marvin/marvin/lib/decoratorGenerators.py new file mode 100644 index 00000000000..8bc43b84354 --- /dev/null +++ b/tools/marvin/marvin/lib/decoratorGenerators.py @@ -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