cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject [3/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary
Date Wed, 07 May 2014 13:30:47 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_netscaler_nw_off.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_netscaler_nw_off.py b/test/integration/component/test_netscaler_nw_off.py
index d3f1f9e..af53eb7 100644
--- a/test/integration/component/test_netscaler_nw_off.py
+++ b/test/integration/component/test_netscaler_nw_off.py
@@ -18,15 +18,32 @@
 """ P1 tests for multiple netscaler instances
 """
 #Import Local Modules
-import marvin
 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.sshClient import SshClient
-import datetime
+from marvin.cloudstackTestCase import cloudstackTestCase
+#from marvin.cloudstackAPI import *
+from marvin.lib.utils import (cleanup_resources)
+from marvin.lib.base import (NATRule,
+                             LoadBalancerRule,
+                             FireWallRule,
+                             PublicIPAddress,
+                             VirtualMachine,
+                             Network,
+                             Account,
+                             NetScaler,
+                             PhysicalNetwork,
+                             NetworkServiceProvider,
+                             NetworkOffering,
+                             Vpn,
+                             Zone,
+                             ServiceOffering,
+                             Configurations
+                                )
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               add_netscaler,
+                        )
+import time
 
 
 class Services:
@@ -540,7 +557,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
             netscaler_provider = nw_service_providers[0]
 
         if netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=netscaler_provider.id,
                                           state='Enabled'
@@ -767,7 +784,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
 
         with self.assertRaises(Exception):
             # Spawn an instance in that network
-            virtual_machine_3 = VirtualMachine.create(
+            VirtualMachine.create(
                                   self.apiclient,
                                   self.services["virtual_machine"],
                                   accountid=self.account_3.name,
@@ -955,7 +972,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
 
         with self.assertRaises(Exception):
             # Spawn an instance in that network
-            virtual_machine_5 = VirtualMachine.create(
+            VirtualMachine.create(
                                   self.apiclient,
                                   self.services["virtual_machine"],
                                   accountid=self.account_5.name,
@@ -983,14 +1000,10 @@ class TestNetScalerSharedMode(cloudstackTestCase):
         self.account_4.delete(self.apiclient)
         self.debug("Account: %s is deleted" % self.account_4.name)
 
-        interval = list_configurations(
-                                    self.apiclient,
-                                    name='network.gc.interval'
-                                    )
-        wait = list_configurations(
-                                    self.apiclient,
-                                    name='network.gc.wait'
-                                    )
+        interval = Configurations.list(self.apiclient,
+                                       name='network.gc.interval')
+        wait = Configurations.list(self.apiclient,
+                                   name='network.gc.wait')
         self.debug("Sleeping for: network.gc.interval + network.gc.wait")
         # Sleep to ensure that all resources are deleted
         time.sleep(int(interval[0].value) + int(wait[0].value))
@@ -1084,7 +1097,7 @@ class TestNwOffDedicatedNetscaler(cloudstackTestCase):
             netscaler_provider = nw_service_providers[0]
 
         if netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=netscaler_provider.id,
                                           state='Enabled'
@@ -1135,11 +1148,11 @@ class TestNwOffDedicatedNetscaler(cloudstackTestCase):
             self.debug("Cleaning up the resources")
             #Clean up, terminate the created network offerings
             cleanup_resources(self.apiclient, self.cleanup)
-            interval = list_configurations(
+            interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-            wait = list_configurations(
+            wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -1256,7 +1269,7 @@ class TestNwOffNetscaler(cloudstackTestCase):
             netscaler_provider = nw_service_providers[0]
 
         if netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=netscaler_provider.id,
                                           state='Enabled'
@@ -1326,11 +1339,11 @@ class TestNwOffNetscaler(cloudstackTestCase):
             self.debug("Cleaning up the resources")
             #Clean up, terminate the created network offerings
             cleanup_resources(self.apiclient, self.cleanup)
-            interval = list_configurations(
+            interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-            wait = list_configurations(
+            wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -1386,14 +1399,13 @@ class TestNwOffNetscaler(cloudstackTestCase):
                                     zoneid=self.zone.id
                                     )
         self.debug("Deploying VM in account: %s" % self.account_1.name)
-        virtual_machine = VirtualMachine.create(
-                                  self.apiclient,
-                                  self.services["virtual_machine"],
-                                  accountid=self.account_1.name,
-                                  domainid=self.account_1.domainid,
-                                  serviceofferingid=self.service_offering.id,
-                                  networkids=[str(self.network.id)]
-                                  )
+        VirtualMachine.create(
+                              self.apiclient,
+                              self.services["virtual_machine"],
+                              accountid=self.account_1.name,
+                              domainid=self.account_1.domainid,
+                              serviceofferingid=self.service_offering.id,
+                              networkids=[str(self.network.id)])
         # Creating network using the network offering created
         self.debug("Creating different network with network offering: %s" %
                                                     self.network_offering.id)
@@ -1421,14 +1433,12 @@ class TestNwOffNetscaler(cloudstackTestCase):
         self.debug("Deleting account: %s" % self.account_1.name)
         self.account_1.delete(self.apiclient)
         self.debug("Account: %s deleted!" % self.account_1.name)
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-        wait = list_configurations(
-                                    self.apiclient,
-                                    name='network.gc.wait'
-                                    )
+        wait = Configurations.list(self.apiclient,
+                                   name='network.gc.wait')
         self.debug("Sleeping for: network.gc.interval + network.gc.wait")
         # Sleep to ensure that all resources are deleted
         time.sleep(int(interval[0].value) + int(wait[0].value))
@@ -1564,7 +1574,7 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
             netscaler_provider = nw_service_providers[0]
 
         if netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=netscaler_provider.id,
                                           state='Enabled'
@@ -1634,11 +1644,11 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
             self.debug("Cleaning up the resources")
             #Clean up, terminate the created network offerings
             cleanup_resources(self.apiclient, self.cleanup)
-            interval = list_configurations(
+            interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-            wait = list_configurations(
+            wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -1823,29 +1833,6 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
                             self.account_1.name)
         virtual_machine_1.stop(self.apiclient)
 
-        list_vm_response = VirtualMachine.list(
-                                        self.apiclient,
-                                        id=virtual_machine_1.id
-                                        )
-
-        self.debug(
-                "Verify listVirtualMachines response for virtual machine: %s" \
-                % virtual_machine_1.id
-            )
-
-        self.assertEqual(
-                            isinstance(list_vm_response, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        vm_response = list_vm_response[0]
-
-        self.assertEqual(
-                            vm_response.state,
-                            "Stopped",
-                            "VM state should be running after deployment"
-                        )
-        self.debug("All Vms are in stopped state")
         self.debug("Upgrading the network: %s" % self.network_1.id)
         self.network_1.update(
                             self.apiclient,
@@ -1917,7 +1904,7 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
             "Creating LB rule for IP address: %s with round robin algo" %
                                                 public_ip.ipaddress.ipaddress)
 
-            lb_rule = LoadBalancerRule.create(
+            LoadBalancerRule.create(
                                     self.apiclient,
                                     self.services["lbrule"],
                                     ipaddressid=public_ip.ipaddress.id,
@@ -1978,7 +1965,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
             netscaler_provider = nw_service_providers[0]
 
         if netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=netscaler_provider.id,
                                           state='Enabled'
@@ -2048,11 +2035,11 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
             self.debug("Cleaning up the resources")
             #Clean up, terminate the created network offerings
             cleanup_resources(self.apiclient, self.cleanup)
-            interval = list_configurations(
+            interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-            wait = list_configurations(
+            wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -2227,29 +2214,6 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
         self.debug("Stopping all VMs in account: %s" % self.account_3.name)
         virtual_machine_3.stop(self.apiclient)
 
-        list_vm_response = VirtualMachine.list(
-                                        self.apiclient,
-                                        id=virtual_machine_3.id
-                                        )
-
-        self.debug(
-                "Verify listVirtualMachines response for virtual machine: %s" \
-                % virtual_machine_3.id
-            )
-
-        self.assertEqual(
-                            isinstance(list_vm_response, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        vm_response = list_vm_response[0]
-
-        self.assertEqual(
-                            vm_response.state,
-                            "Stopped",
-                            "VM state should be stopped"
-                        )
-        self.debug("All user VMs stopped")
         self.debug("Upgrading the network: %s" % self.network_3.id)
         self.network_3.update(
                             self.apiclient,
@@ -2318,7 +2282,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
             "Creating LB rule for IP address: %s with round robin algo" %
                                                 public_ip.ipaddress.ipaddress)
 
-            lb_rule = LoadBalancerRule.create(
+            LoadBalancerRule.create(
                                     self.apiclient,
                                     self.services["lbrule"],
                                     ipaddressid=public_ip.ipaddress.id,
@@ -2936,7 +2900,7 @@ class TestNOWithNetscaler(cloudstackTestCase):
         # User should be able to enable VPN on source NAT
         self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress)
         # Assign VPN to source NAT
-        vpn = Vpn.create(
+        Vpn.create(
                         self.apiclient,
                         src_nat.id,
                         account=self.account.name,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_network_offering.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py
index b0b6906..f2251ff8 100644
--- a/test/integration/component/test_network_offering.py
+++ b/test/integration/component/test_network_offering.py
@@ -18,14 +18,23 @@
 """ P1 tests for network offering
 """
 #Import Local Modules
-import marvin
 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 *
-import datetime
+from marvin.cloudstackTestCase import cloudstackTestCase
+#from marvin.cloudstackAPI import *
+from marvin.lib.utils import (cleanup_resources)
+from marvin.lib.base import (VirtualMachine,
+                             Account,
+                             Network,
+                             LoadBalancerRule,
+                             PublicIPAddress,
+                             FireWallRule,
+                             NATRule,
+                             Vpn,
+                             ServiceOffering,
+                             NetworkOffering)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template)
 
 
 class Services:
@@ -700,7 +709,7 @@ class TestNOVirtualRouter(cloudstackTestCase):
         # User should be able to enable VPN on source NAT
         self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress)
         # Assign VPN to source NAT
-        vpn = Vpn.create(
+        Vpn.create(
                         self.apiclient,
                         src_nat.id,
                         account=self.account.name,
@@ -942,7 +951,7 @@ class TestNetworkUpgrade(cloudstackTestCase):
 
         # Assign VPN to source NAT
         self.debug("Enabling VPN on source NAT")
-        vpn = Vpn.create(
+        Vpn.create(
                         self.apiclient,
                         src_nat.id,
                         account=self.account.name,
@@ -1142,7 +1151,7 @@ class TestNetworkUpgrade(cloudstackTestCase):
 
         # Assign VPN to source NAT
         self.debug("Enabling VPN on source NAT")
-        vpn = Vpn.create(
+        Vpn.create(
                         self.apiclient,
                         src_nat.id,
                         account=self.account.name,
@@ -1262,7 +1271,7 @@ class TestNOWithOnlySourceNAT(cloudstackTestCase):
 
         self.debug("Deploying VM in account: %s on the network %s" % (self.account.name, self.network.id))
         # Spawn an instance in that network
-        virtual_machine = VirtualMachine.create(
+        VirtualMachine.create(
             self.apiclient,
             self.services["virtual_machine"],
             accountid=self.account.name,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_persistent_networks.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_persistent_networks.py b/test/integration/component/test_persistent_networks.py
index deb0d6e..4261abe 100644
--- a/test/integration/component/test_persistent_networks.py
+++ b/test/integration/component/test_persistent_networks.py
@@ -15,11 +15,32 @@
 # specific language governing permissions and limitations
 # under the License.
 """ Tests for Persistent Networks without running VMs feature"""
-from marvin.cloudstackException import CloudstackAPIException
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
-import netaddr
+from marvin.lib.utils import (cleanup_resources,
+                              validateList,
+                              get_hypervisor_type)
+from marvin.lib.base import (Account,
+                             VPC,
+                             VirtualMachine,
+                             LoadBalancerRule,
+                             Network,
+                             Domain,
+                             Router,
+                             NetworkACL,
+                             PublicIPAddress,
+                             VpcOffering,
+                             ServiceOffering,
+                             Project,
+                             NetworkOffering,
+                             NATRule,
+                             FireWallRule,
+                             Host,
+                             StaticNATRule)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               verifyNetworkState,
+                               add_netscaler,
+                               wait_for_cleanup)
 from nose.plugins.attrib import attr
 from marvin.codes import PASS, FAIL, FAILED
 from marvin.sshClient import SshClient
@@ -1051,24 +1072,20 @@ class TestAssignVirtualMachine(cloudstackTestCase):
                                                     networkids=[network.id],
                                                     serviceofferingid=self.service_offering.id,
                                                     accountid=account_1.name,domainid=self.domain.id)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
-
-        virtual_machine.stop(self.apiclient)
 
-        vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id)
-        self.assertEqual(validateList(vms)[0], PASS, "vm list validation failed, vm list is %s" % vms)
-        self.assertEqual(str(vms[0].state).lower(), "stopped", "vm state should be stopped, it is %s" % vms[0].state)
+            virtual_machine.stop(self.apiclient)
 
-        # Assign virtual machine to different account
-        virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
+            # Assign virtual machine to different account
+            virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
 
-        # Start VM
-        virtual_machine.start(self.apiclient)
+            # Start VM
+            virtual_machine.start(self.apiclient)
 
-        # Verify that new network is created in other account
-        networks = Network.list(self.apiclient, account=account_2.name, domainid = account_2.domainid)
-        self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+            # Verify that new network is created in other account
+            networks = Network.list(self.apiclient, account=account_2.name, domainid = account_2.domainid)
+            self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         return
 
 @ddt

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_project_resources.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_project_resources.py b/test/integration/component/test_project_resources.py
index 8f81cf9..4f61cb0 100644
--- a/test/integration/component/test_project_resources.py
+++ b/test/integration/component/test_project_resources.py
@@ -5,9 +5,9 @@
 # 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
@@ -18,7 +18,7 @@
 """
 #Import Local Modules
 from nose.plugins.attrib import attr
-from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.cloudstackTestCase import cloudstackTestCase
 from marvin.lib.base import (VirtualMachine,
                                          Account,
                                          Project,
@@ -458,7 +458,6 @@ class TestNetwork(cloudstackTestCase):
                          True,
                          "Check for the valid network list response"
                          )
-        network_response = networks[0]
 
         self.debug("Deploying VM with network: %s" % network.id)
 
@@ -631,53 +630,56 @@ class TestTemplates(cloudstackTestCase):
         # 3. Verify that template created in project can be used in project
         #    without any restrictions
 
-        self.debug("Deploying VM for with public template: %s" %
+        try:
+            self.debug("Deploying VM for with public template: %s" %
                                                         self.template.id)
-        virtual_machine_1 = VirtualMachine.create(
+            virtual_machine_1 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=self.template.id,
                                 serviceofferingid=self.service_offering.id,
                                 projectid=self.project.id
                                 )
-        self.cleanup.append(virtual_machine_1)
-        # Verify VM state
-        self.assertEqual(
+            self.cleanup.append(virtual_machine_1)
+            # Verify VM state
+            self.assertEqual(
                             virtual_machine_1.state,
                             'Running',
                             "Check VM state is Running or not"
                         )
-        virtual_machine_1.stop(self.apiclient)
-        # Get the Root disk of VM
-        volumes = list_volumes(
+            virtual_machine_1.stop(self.apiclient)
+            # Get the Root disk of VM
+            volumes = list_volumes(
                             self.apiclient,
                             projectid=self.project.id,
                             type='ROOT',
                             listall=True
                             )
-        self.assertEqual(
+            self.assertEqual(
                         isinstance(volumes, list),
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
+            volume = volumes[0]
 
-        self.debug("Creating template from volume: %s" % volume.id)
-        # Create a template from the ROOTDISK
-        template_1 = Template.create(
+            self.debug("Creating template from volume: %s" % volume.id)
+            # Create a template from the ROOTDISK
+            template_1 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
                             projectid=self.project.id
                             )
 
-        self.cleanup.append(template_1)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_1)
+            # Verify Template state
+            self.assertEqual(
                             template_1.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         return
 
     @attr(tags=["advanced", "basic", "sg", "eip", "advancedns", "selfservice"])
@@ -690,83 +692,83 @@ class TestTemplates(cloudstackTestCase):
         #    be granted to the Project (use API 'updateTemplatePermissions'
         #    with project id to achieve that).
 
-        self.debug("Deploying VM for with public template: %s" %
+        try:
+            self.debug("Deploying VM for with public template: %s" %
                                                         self.template.id)
-        virtual_machine_1 = VirtualMachine.create(
+            virtual_machine_1 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=self.template.id,
                                 serviceofferingid=self.service_offering.id,
                                 projectid=self.project.id
                                 )
-        self.cleanup.append(virtual_machine_1)
-        # Verify VM state
-        self.assertEqual(
-                            virtual_machine_1.state,
-                            'Running',
-                            "Check VM state is Running or not"
-                        )
-        self.debug("Stopping the VM: %s" % virtual_machine_1.id)
-        virtual_machine_1.stop(self.apiclient)
-        # Get the Root disk of VM
-        volumes = list_volumes(
+            self.cleanup.append(virtual_machine_1)
+            # Verify VM state
+            self.assertEqual(virtual_machine_1.state,
+                         'Running',
+                         "Check VM state is Running or not")
+            virtual_machine_1.stop(self.apiclient)
+            # Get the Root disk of VM
+            volumes = list_volumes(
                             self.apiclient,
                             projectid=self.project.id,
                             type='ROOT',
                             listall=True
                             )
-        self.assertEqual(
+            self.assertEqual(
                         isinstance(volumes, list),
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
+            volume = volumes[0]
 
-        self.debug("Creating template from volume: %s" % volume.id)
-        # Create a template from the ROOTDISK
-        template_1 = Template.create(
+            self.debug("Creating template from volume: %s" % volume.id)
+            # Create a template from the ROOTDISK
+            template_1 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
                             projectid=self.project.id
                             )
 
-        self.cleanup.append(template_1)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_1)
+            # Verify Template state
+            self.assertEqual(
                             template_1.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
 
-        # Update template permissions to grant permission to project
-        self.debug(
-          "Updating template permissions:%s to grant access to project: %s" % (
+            # Update template permissions to grant permission to project
+            self.debug(
+                        "Updating template permissions:%s to grant access to project: %s" % (
                                                             template_1.id,
                                                             self.project.id
                                                         ))
 
-        template_1.updatePermissions(
+            template_1.updatePermissions(
                                      self.apiclient,
                                      op='add',
                                      projectids=self.project.id
                                      )
-        self.debug("Deploying VM for with privileged template: %s" %
+            self.debug("Deploying VM for with privileged template: %s" %
                                                         self.template.id)
-        virtual_machine_2 = VirtualMachine.create(
+            virtual_machine_2 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=template_1.id,
                                 serviceofferingid=self.service_offering.id,
                                 projectid=self.project.id
                                 )
-        self.cleanup.append(virtual_machine_2)
-        # Verify VM state
-        self.assertEqual(
+            self.cleanup.append(virtual_machine_2)
+            # Verify VM state
+            self.assertEqual(
                             virtual_machine_2.state,
                             'Running',
                             "Check VM state is Running or not"
                         )
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         return
 
 
@@ -882,7 +884,6 @@ class TestSnapshots(cloudstackTestCase):
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
 
         self.debug("Creating snapshot from volume: %s" % volumes[0].id)
         # Create a snapshot from the ROOTDISK

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_project_usage.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_project_usage.py b/test/integration/component/test_project_usage.py
index 16ca8c1..5e0dda5 100644
--- a/test/integration/component/test_project_usage.py
+++ b/test/integration/component/test_project_usage.py
@@ -5,9 +5,9 @@
 # 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
@@ -17,16 +17,29 @@
 """ P1 tests for Snapshots
 """
 #Import Local Modules
-import marvin
 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.sshClient import SshClient
-import datetime
-
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.cloudstackAPI import deleteVolume
+from marvin.lib.utils import (cleanup_resources)
+from marvin.lib.base import (Project,
+                             VirtualMachine,
+                             Account,
+                             Network,
+                             PublicIPAddress,
+                             NATRule,
+                             ServiceOffering,
+                             Vpn,
+                             VpnUser,
+                             Snapshot,
+                             ImageStore,
+                             DiskOffering,
+                             LoadBalancerRule,
+                             Template,
+                             Iso)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               list_volumes)
 
 class Services:
     """Test Snapshots Services
@@ -204,14 +217,19 @@ class TestVmUsage(cloudstackTestCase):
         #    VM.Destroy and volume .delete Event for the created account
         # 4. Delete the account
 
-        self.debug("Stopping the VM: %s" % self.virtual_machine.id)
-        # Stop the VM
-        self.virtual_machine.stop(self.apiclient)
+        try:
+            self.debug("Stopping the VM: %s" % self.virtual_machine.id)
+            # Stop the VM
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
 
-        time.sleep(self.services["sleep"])
-        # Destroy the VM
-        self.debug("Destroying the VM: %s" % self.virtual_machine.id)
-        self.virtual_machine.delete(self.apiclient)
+        try:
+            # Destroy the VM
+            self.debug("Destroying the VM: %s" % self.virtual_machine.id)
+            self.virtual_machine.delete(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to delete VM: %s" % e)
 
         # Fetch project account ID from project UUID
         self.debug(
@@ -574,7 +592,10 @@ class TestVolumeUsage(cloudstackTestCase):
 
         # Stop VM
         self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
+        try:
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
 
         volume_response = list_volumes(
                                     self.apiclient,
@@ -594,7 +615,10 @@ class TestVolumeUsage(cloudstackTestCase):
                                                  data_volume.id,
                                                  self.virtual_machine.id
                                                  ))
-        self.virtual_machine.detach_volume(self.apiclient, data_volume)
+        try:
+            self.virtual_machine.detach_volume(self.apiclient, data_volume)
+        except Exception as e:
+            self.fail("Failed to detach volume: %s" % e)
 
         # Delete Data disk
         self.debug("Delete volume ID: %s" % data_volume.id)
@@ -680,26 +704,28 @@ class TestTemplateUsage(cloudstackTestCase):
                             cls.services["ostype"]
                             )
         cls.services["server"]["zoneid"] = cls.zone.id
-        cls.account = Account.create(
+        cls._cleanup = []
+        try:
+            cls.account = Account.create(
                             cls.api_client,
                             cls.services["account"],
                             domainid=cls.domain.id
                             )
-        cls.services["account"] = cls.account.name
+            cls._cleanup.append(cls.account)
+            cls.services["account"] = cls.account.name
 
-        cls.project = Project.create(
+            cls.project = Project.create(
                                  cls.api_client,
                                  cls.services["project"],
                                  account=cls.account.name,
                                  domainid=cls.account.domainid
                                  )
-
-        cls.service_offering = ServiceOffering.create(
+            cls._cleanup.append(cls.account)
+            cls.service_offering = ServiceOffering.create(
                                             cls.api_client,
-                                            cls.services["service_offering"]
-                                            )
-        #create virtual machine
-        cls.virtual_machine = VirtualMachine.create(
+                                            cls.services["service_offering"])
+            #create virtual machine
+            cls.virtual_machine = VirtualMachine.create(
                                     cls.api_client,
                                     cls.services["server"],
                                     templateid=template.id,
@@ -707,25 +733,22 @@ class TestTemplateUsage(cloudstackTestCase):
                                     projectid=cls.project.id
                                     )
 
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.api_client)
+            #Stop virtual machine
+            cls.virtual_machine.stop(cls.api_client)
 
-        #Wait before server has be successfully stopped
-        time.sleep(30)
-        list_volume = list_volumes(
+            list_volume = list_volumes(
                                    cls.api_client,
                                    projectid=cls.project.id,
                                    type='ROOT',
                                    listall=True
                                    )
-        if isinstance(list_volume, list):
-            cls.volume = list_volume[0]
-        else:
-            raise Exception("List Volumes failed!")
-        cls._cleanup = [
-                        cls.project,
-                        cls.account,
-                        ]
+            if isinstance(list_volume, list):
+                cls.volume = list_volume[0]
+            else:
+                raise Exception("List Volumes failed!")
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Failed during setUpClass: %s" % e)
         return
 
     @classmethod
@@ -1271,8 +1294,6 @@ class TestSnapshotUsage(cloudstackTestCase):
                          "Check if list volumes return a valid data"
                         )
 
-        volume = volumes[0]
-
         # Create a snapshot from the ROOTDISK
         self.debug("Creating snapshot from volume: %s" % volumes[0].id)
         snapshot = Snapshot.create(self.apiclient, volumes[0].id)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_redundant_router_cleanups.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_redundant_router_cleanups.py b/test/integration/component/test_redundant_router_cleanups.py
index 2220d51..444fa3a 100644
--- a/test/integration/component/test_redundant_router_cleanups.py
+++ b/test/integration/component/test_redundant_router_cleanups.py
@@ -5,9 +5,9 @@
 # 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
@@ -16,13 +16,22 @@
 # under the License.
 
 from nose.plugins.attrib import attr
-from marvin.lib.base import *
-from marvin.lib.utils import *
-from marvin.lib.common import *
+from marvin.lib.base import (Account,
+                             Network,
+                             ServiceOffering,
+                             NetworkOffering,
+                             VirtualMachine,
+                             Router,
+                             Configurations)
+from marvin.lib.utils import cleanup_resources
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template)
 
 #Import Local Modules
 from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.cloudstackAPI import *
+from marvin.cloudstackAPI import startRouter
+import time
 
 class Services:
     """Test Services for customer defects
@@ -304,13 +313,6 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
                     "Length of the list router should be 2 (Backup & master)"
                     )
 
-        if routers[0].redundantstate == 'MASTER':
-            master_router = routers[0]
-            backup_router = routers[1]
-        else:
-            master_router = routers[1]
-            backup_router = routers[0]
-
         self.debug("restarting network with cleanup=False")
         try:
             network.restart(self.apiclient, cleanup=False)
@@ -445,13 +447,6 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
                     "Length of the list router should be 2 (Backup & master)"
                     )
 
-        if routers[0].redundantstate == 'MASTER':
-            master_router = routers[0]
-            backup_router = routers[1]
-        else:
-            master_router = routers[1]
-            backup_router = routers[0]
-
         self.debug("restarting network with cleanup=True")
         try:
             network.restart(self.apiclient, cleanup=True)
@@ -597,12 +592,12 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
             self.fail("Failed to stop guest Vm: %s - %s" %
                                             (virtual_machine.name, e))
 
-        interval = list_configurations(
+        interval = Configurations(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
         delay = int(interval[0].value)
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_reset_ssh_keypair.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_reset_ssh_keypair.py b/test/integration/component/test_reset_ssh_keypair.py
index 307e8dc..d0ddb18 100644
--- a/test/integration/component/test_reset_ssh_keypair.py
+++ b/test/integration/component/test_reset_ssh_keypair.py
@@ -24,12 +24,11 @@ from marvin.lib.base import (VirtualMachine,
                                          Account,
                                          Template,
                                          ServiceOffering,
-                                         EgressFireWallRule)
+                                         EgressFireWallRule,
+                                         Volume)
 from marvin.lib.common import (get_domain,
                                            get_zone,
-                                           get_template,
-                                           list_virtual_machines,
-                                           list_volumes)
+                                           get_template)
 from marvin.lib.utils import (cleanup_resources,
                                           random_gen,
                                           validateList)
@@ -136,118 +135,93 @@ class TestResetSSHKeypair(cloudstackTestCase):
         cls.services["virtual_machine"]["zoneid"] = cls.zone.id
         cls.services["virtual_machine"]["template"] = template.id
 
-        # Create VMs, NAT Rules etc
-        cls.account = Account.create(
-            cls.api_client,
-            cls.services["account"],
-            domainid=domain.id
-        )
-
-        cls.service_offering = ServiceOffering.create(
-            cls.api_client,
-            cls.services["service_offering"]
-        )
-
-        cls.virtual_machine = VirtualMachine.create(
-            cls.api_client,
-            cls.services["virtual_machine"],
-            accountid=cls.account.name,
-            domainid=cls.account.domainid,
-            serviceofferingid=cls.service_offering.id,
-            mode=cls.services["mode"]
-        )
-
-        networkid = cls.virtual_machine.nic[0].networkid
-
-        # create egress rule to allow wget of my cloud-set-guest-password script
-        if cls.zone.networktype.lower() == 'advanced':
-            EgressFireWallRule.create(cls.api_client,
+        cls._cleanup = []
+        try:
+            # Create VMs, NAT Rules etc
+            cls.account = Account.create(
+                                cls.api_client,
+                                cls.services["account"],
+                                domainid=domain.id)
+            cls._cleanup.append(cls.account)
+
+            cls.service_offering = ServiceOffering.create(
+                                        cls.api_client,
+                                        cls.services["service_offering"])
+            cls._cleanup.append(cls.service_offering)
+
+            cls.virtual_machine = VirtualMachine.create(
+                                    cls.api_client,
+                                    cls.services["virtual_machine"],
+                                    accountid=cls.account.name,
+                                    domainid=cls.account.domainid,
+                                    serviceofferingid=cls.service_offering.id,
+                                    mode=cls.services["mode"])
+
+            networkid = cls.virtual_machine.nic[0].networkid
+
+            # create egress rule to allow wget of my cloud-set-guest-password script
+            if cls.zone.networktype.lower() == 'advanced':
+                EgressFireWallRule.create(cls.api_client,
                                   networkid=networkid,
                                   protocol=cls.services["egress"]["protocol"],
                                   startport=cls.services["egress"]["startport"],
                                   endport=cls.services["egress"]["endport"],
                                   cidrlist=cls.services["egress"]["cidrlist"])
 
-        cls.virtual_machine.password = cls.services["virtual_machine"]["password"]
-        ssh = cls.virtual_machine.get_ssh_client()
-
-        # below steps are required to get the new password from VR(reset password)
-        # http://cloudstack.org/dl/cloud-set-guest-password
-        # Copy this file to /etc/init.d
-        # chmod +x /etc/init.d/cloud-set-guest-password
-        # chkconfig --add cloud-set-guest-password
-        # similar steps to get SSH key from web so as to make it ssh enabled
-
-        cmds = [
-            "cd /etc/init.d;wget http://people.apache.org/~tsp/cloud-set-guest-password",
-            "chmod +x /etc/init.d/cloud-set-guest-password",
-            "chkconfig --add cloud-set-guest-password",
-            "cd /etc/init.d;wget http://downloads.sourceforge.net/project/cloudstack/SSH%20Key%20Gen%20Script/" + \
-            "cloud-set-guest-sshkey.in?r=http%3A%2F%2Fsourceforge" + \
-            ".net%2Fprojects%2Fcloudstack%2Ffiles%2FSSH%2520Key%2520Gen%2520Script%2F&ts=1331225219&use_mirror=iweb",
-            "chmod +x /etc/init.d/cloud-set-guest-sshkey.in",
-            "chkconfig --add cloud-set-guest-sshkey.in"
-            ]
-        for c in cmds:
-            result = ssh.execute(c)
-
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.api_client)
-
-        # Poll listVM to ensure VM is stopped properly
-        timeout = cls.services["timeout"]
-        while True:
-            time.sleep(cls.services["sleep"])
-
-            # Ensure that VM is in stopped state
-            list_vm_response = list_virtual_machines(
-                cls.api_client,
-                id=cls.virtual_machine.id
-            )
-
-            if isinstance(list_vm_response, list):
-
-                vm = list_vm_response[0]
-                if vm.state == 'Stopped':
-                    break
-
-            if timeout == 0:
+            cls.virtual_machine.password = cls.services["virtual_machine"]["password"]
+            ssh = cls.virtual_machine.get_ssh_client()
+
+            # below steps are required to get the new password from VR(reset password)
+            # http://cloudstack.org/dl/cloud-set-guest-password
+            # Copy this file to /etc/init.d
+            # chmod +x /etc/init.d/cloud-set-guest-password
+            # chkconfig --add cloud-set-guest-password
+            # similar steps to get SSH key from web so as to make it ssh enabled
+
+            cmds = [
+                "cd /etc/init.d;wget http://people.apache.org/~tsp/cloud-set-guest-password",
+                "chmod +x /etc/init.d/cloud-set-guest-password",
+                "chkconfig --add cloud-set-guest-password",
+                "cd /etc/init.d;wget http://downloads.sourceforge.net/project/cloudstack/SSH%20Key%20Gen%20Script/" + \
+                "cloud-set-guest-sshkey.in?r=http%3A%2F%2Fsourceforge" + \
+                ".net%2Fprojects%2Fcloudstack%2Ffiles%2FSSH%2520Key%2520Gen%2520Script%2F&ts=1331225219&use_mirror=iweb",
+                "chmod +x /etc/init.d/cloud-set-guest-sshkey.in",
+                "chkconfig --add cloud-set-guest-sshkey.in"
+                ]
+            for c in cmds:
+                ssh.execute(c)
+
+            #Stop virtual machine
+            cls.virtual_machine.stop(cls.api_client)
+
+            list_volume = Volume.list(
+                            cls.api_client,
+                            virtualmachineid=cls.virtual_machine.id,
+                            type='ROOT',
+                            listall=True)
+
+            if isinstance(list_volume, list):
+                cls.volume = list_volume[0]
+            else:
                 raise Exception(
-                    "Failed to stop VM (ID: %s) " %
-                    vm.id)
-
-            timeout = timeout - 1
-
-        list_volume = list_volumes(
-            cls.api_client,
-            virtualmachineid=cls.virtual_machine.id,
-            type='ROOT',
-            listall=True
-        )
-        if isinstance(list_volume, list):
-            cls.volume = list_volume[0]
-        else:
-            raise Exception(
                 "Exception: Unable to find root volume for VM: %s" %
                 cls.virtual_machine.id)
 
-        cls.services["template"]["ostype"] = cls.services["ostype"]
-        #Create templates for Edit, Delete & update permissions testcases
-        cls.pw_ssh_enabled_template = Template.create(
-            cls.api_client,
-            cls.services["template"],
-            cls.volume.id,
-            account=cls.account.name,
-            domainid=cls.account.domainid
-        )
-        # Delete the VM - No longer needed
-        cls.virtual_machine.delete(cls.api_client)
-
-        cls._cleanup = [
-                        cls.service_offering,
-                        cls.pw_ssh_enabled_template,
-                        cls.account
-                       ]
+            cls.services["template"]["ostype"] = cls.services["ostype"]
+            #Create templates for Edit, Delete & update permissions testcases
+            cls.pw_ssh_enabled_template = Template.create(
+                cls.api_client,
+                cls.services["template"],
+                cls.volume.id,
+                account=cls.account.name,
+                domainid=cls.account.domainid
+            )
+            cls._cleanup.append(cls.pw_ssh_enabled_template)
+            # Delete the VM - No longer needed
+            cls.virtual_machine.delete(cls.api_client)
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
 
     @classmethod
     def tearDownClass(cls):
@@ -1026,36 +1000,16 @@ class TestResetSSHKeyUserRights(cloudstackTestCase):
             "chkconfig --add cloud-set-guest-sshkey.in"
             ]
         for c in cmds:
-            result = ssh.execute(c)
-
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.api_client)
+            ssh.execute(c)
 
-        # Poll listVM to ensure VM is stopped properly
-        timeout = cls.services["timeout"]
-        while True:
-            time.sleep(cls.services["sleep"])
-
-            # Ensure that VM is in stopped state
-            list_vm_response = list_virtual_machines(
-                cls.api_client,
-                id=cls.virtual_machine.id
-            )
-
-            if isinstance(list_vm_response, list):
-
-                vm = list_vm_response[0]
-                if vm.state == 'Stopped':
-                    break
-
-            if timeout == 0:
-                raise Exception(
-                    "Failed to stop VM (ID: %s) " %
-                    vm.id)
-
-            timeout = timeout - 1
+        try:
+            #Stop virtual machine
+            cls.virtual_machine.stop(cls.api_client)
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
 
-        list_volume = list_volumes(
+        list_volume = Volume.list(
             cls.api_client,
             virtualmachineid=cls.virtual_machine.id,
             type='ROOT',

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_resource_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_resource_limits.py b/test/integration/component/test_resource_limits.py
index 09d9658..9f9cdfa 100644
--- a/test/integration/component/test_resource_limits.py
+++ b/test/integration/component/test_resource_limits.py
@@ -5,9 +5,9 @@
 # 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
@@ -747,11 +747,12 @@ class TestResourceLimitsAccount(cloudstackTestCase):
         # 3. Try to create 2 templates in account 2. Verify account 2 should be
         #    able to create template without any error
 
-        self.debug(
-            "Updating template resource limit for account: %s" %
+        try:
+            self.debug(
+                       "Updating template resource limit for account: %s" %
                                                 self.account_1.name)
-        # Set usage_vm=1 for Account 1
-        update_resource_limit(
+            # Set usage_vm=1 for Account 1
+            update_resource_limit(
                               self.apiclient,
                               4, # Template
                               account=self.account_1.name,
@@ -759,10 +760,10 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                               max=1
                               )
 
-        self.debug(
-            "Updating volume resource limit for account: %s" %
+            self.debug(
+                "Updating volume resource limit for account: %s" %
                                                 self.account_1.name)
-        virtual_machine_1 = VirtualMachine.create(
+            virtual_machine_1 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=self.template.id,
@@ -770,19 +771,19 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                                 domainid=self.account_1.domainid,
                                 serviceofferingid=self.service_offering.id
                                 )
-        self.cleanup.append(virtual_machine_1)
-        # Verify VM state
-        self.assertEqual(
+            self.cleanup.append(virtual_machine_1)
+            # Verify VM state
+            self.assertEqual(
                             virtual_machine_1.state,
                             'Running',
                             "Check VM state is Running or not"
                         )
 
-        self.debug(
-            "Deploying virtual machine for account: %s" %
+            self.debug(
+                "Deploying virtual machine for account: %s" %
                                                 self.account_2.name)
-        # Create VM for second account
-        virtual_machine_2 = VirtualMachine.create(
+            # Create VM for second account
+            virtual_machine_2 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=self.template.id,
@@ -790,33 +791,33 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                                 domainid=self.account_2.domainid,
                                 serviceofferingid=self.service_offering.id
                                 )
-        self.cleanup.append(virtual_machine_2)
-        # Verify VM state
-        self.assertEqual(
+            self.cleanup.append(virtual_machine_2)
+            # Verify VM state
+            self.assertEqual(
                             virtual_machine_2.state,
                             'Running',
                             "Check VM state is Running or not"
                         )
 
-        virtual_machine_1.stop(self.apiclient)
-        # Get the Root disk of VM
-        volumes = list_volumes(
+            virtual_machine_1.stop(self.apiclient)
+            # Get the Root disk of VM
+            volumes = list_volumes(
                             self.apiclient,
                             virtualmachineid=virtual_machine_1.id,
                             type='ROOT',
                             listall=True
                             )
-        self.assertEqual(
+            self.assertEqual(
                         isinstance(volumes, list),
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
+            volume = volumes[0]
 
-        self.debug(
-            "Creating template from volume: %s" % volume.id)
-        # Create a template from the ROOTDISK (Account 1)
-        template_1 = Template.create(
+            self.debug(
+                "Creating template from volume: %s" % volume.id)
+            # Create a template from the ROOTDISK (Account 1)
+            template_1 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
@@ -824,14 +825,15 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                             domainid=self.account_1.domainid,
                             )
 
-        self.cleanup.append(template_1)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_1)
+            # Verify Template state
+            self.assertEqual(
                             template_1.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
-
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         # Exception should be raised for second snapshot (account_1)
         with self.assertRaises(Exception):
             Template.create(
@@ -841,25 +843,27 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                             account=self.account_1.name,
                             domainid=self.account_1.domainid,
                             )
-        virtual_machine_2.stop(self.apiclient)
-        # Get the Root disk of VM
-        volumes = list_volumes(
+
+        try:
+            virtual_machine_2.stop(self.apiclient)
+            # Get the Root disk of VM
+            volumes = list_volumes(
                             self.apiclient,
                             virtualmachineid=virtual_machine_2.id,
                             type='ROOT',
                             listall=True
                             )
-        self.assertEqual(
+            self.assertEqual(
                         isinstance(volumes, list),
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
+            volume = volumes[0]
 
-        self.debug(
-            "Creating template from volume: %s" % volume.id)
-        # Create a snapshot from the ROOTDISK (Account 1)
-        template_2 = Template.create(
+            self.debug(
+                "Creating template from volume: %s" % volume.id)
+            # Create a snapshot from the ROOTDISK (Account 1)
+            template_2 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
@@ -867,17 +871,17 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                             domainid=self.account_2.domainid,
                             )
 
-        self.cleanup.append(template_2)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_2)
+            # Verify Template state
+            self.assertEqual(
                             template_2.isready,
                             True,
                             "Check Template is in ready state or not"
-                        )
-        self.debug(
-            "Creating template from volume: %s" % volume.id)
-        # Create a second volume from the ROOTDISK (Account 2)
-        template_3 = Template.create(
+                            )
+            self.debug(
+                "Creating template from volume: %s" % volume.id)
+            # Create a second volume from the ROOTDISK (Account 2)
+            template_3 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
@@ -885,13 +889,15 @@ class TestResourceLimitsAccount(cloudstackTestCase):
                             domainid=self.account_2.domainid,
                             )
 
-        self.cleanup.append(template_3)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_3)
+            # Verify Template state
+            self.assertEqual(
                             template_3.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         return
 
 
@@ -1256,27 +1262,23 @@ class TestResourceLimitsDomain(cloudstackTestCase):
         # 4. Try create 3rd template in the domain. It should give the user an
         #    appropriate error and an alert should be generated.
 
-        # Set usage_vm=1 for Account 1
-        update_resource_limit(
+        try:
+            # Set usage_vm=1 for Account 1
+            update_resource_limit(
                               self.apiclient,
                               2, # Volume
                               domainid=self.account.domainid,
                               max=5
                               )
 
-        self.debug(
-            "Updating template resource limits for domain: %s" %
-                                        self.account.domainid)
-        # Set usage_vm=1 for Account 1
-        update_resource_limit(
+            # Set usage_vm=1 for Account 1
+            update_resource_limit(
                               self.apiclient,
                               4, # Template
                               domainid=self.account.domainid,
                               max=2
                               )
-
-        self.debug("Deploying VM for account: %s" % self.account.name)
-        virtual_machine_1 = VirtualMachine.create(
+            virtual_machine_1 = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["server"],
                                 templateid=self.template.id,
@@ -1284,31 +1286,31 @@ class TestResourceLimitsDomain(cloudstackTestCase):
                                 domainid=self.account.domainid,
                                 serviceofferingid=self.service_offering.id
                                 )
-        self.cleanup.append(virtual_machine_1)
-        # Verify VM state
-        self.assertEqual(
+            self.cleanup.append(virtual_machine_1)
+            # Verify VM state
+            self.assertEqual(
                             virtual_machine_1.state,
                             'Running',
                             "Check VM state is Running or not"
                         )
-        virtual_machine_1.stop(self.apiclient)
-        # Get the Root disk of VM
-        volumes = list_volumes(
+            virtual_machine_1.stop(self.apiclient)
+            # Get the Root disk of VM
+            volumes = list_volumes(
                             self.apiclient,
                             virtualmachineid=virtual_machine_1.id,
                             type='ROOT',
                             listall=True
                             )
-        self.assertEqual(
+            self.assertEqual(
                         isinstance(volumes, list),
                         True,
                         "Check for list volume response return valid data"
                         )
-        volume = volumes[0]
+            volume = volumes[0]
 
-        self.debug("Creating template from volume: %s" % volume.id)
-        # Create a template from the ROOTDISK
-        template_1 = Template.create(
+            self.debug("Creating template from volume: %s" % volume.id)
+            # Create a template from the ROOTDISK
+            template_1 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
@@ -1316,16 +1318,16 @@ class TestResourceLimitsDomain(cloudstackTestCase):
                             domainid=self.account.domainid,
                             )
 
-        self.cleanup.append(template_1)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_1)
+            # Verify Template state
+            self.assertEqual(
                             template_1.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
-        self.debug("Creating template from volume: %s" % volume.id)
-        # Create a template from the ROOTDISK
-        template_2 = Template.create(
+            self.debug("Creating template from volume: %s" % volume.id)
+            # Create a template from the ROOTDISK
+            template_2 = Template.create(
                             self.apiclient,
                             self.services["template"],
                             volumeid=volume.id,
@@ -1333,13 +1335,15 @@ class TestResourceLimitsDomain(cloudstackTestCase):
                             domainid=self.account.domainid,
                             )
 
-        self.cleanup.append(template_2)
-        # Verify Template state
-        self.assertEqual(
+            self.cleanup.append(template_2)
+            # Verify Template state
+            self.assertEqual(
                             template_2.isready,
                             True,
                             "Check Template is in ready state or not"
                         )
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
 
         # Exception should be raised for second template
         with self.assertRaises(Exception):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_security_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_security_groups.py b/test/integration/component/test_security_groups.py
index f5c4727..6343613 100644
--- a/test/integration/component/test_security_groups.py
+++ b/test/integration/component/test_security_groups.py
@@ -18,13 +18,21 @@
 """ P1 for Security groups
 """
 #Import Local Modules
-import marvin
 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.cloudstackAPI import *
+from marvin.lib.utils import cleanup_resources
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             VirtualMachine,
+                             SecurityGroup,
+                             Router,
+                             Host,
+                             Configurations)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               get_process_status)
 from marvin.sshClient import SshClient
 
 #Import System modules
@@ -186,7 +194,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
         self.debug("Deployed VM with ID: %s" % self.virtual_machine.id)
         self.cleanup.append(self.virtual_machine)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -225,7 +233,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
                    "Verify list routers response for account: %s" \
                    % self.account.name
                    )
-        routers = list_routers(
+        routers = Router.list(
                                self.apiclient,
                                zoneid=self.zone.id,
                                listall=True
@@ -300,7 +308,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
         self.debug("Deployed VM with ID: %s" % self.virtual_machine.id)
         self.cleanup.append(self.virtual_machine)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -362,12 +370,12 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
         # SSH Attempt to VM should fail
         with self.assertRaises(Exception):
             self.debug("SSH into VM: %s" % self.virtual_machine.ssh_ip)
-            ssh = SshClient(
-                                    self.virtual_machine.ssh_ip,
-                                    self.virtual_machine.ssh_port,
-                                    self.virtual_machine.username,
-                                    self.virtual_machine.password
-                                    )
+            SshClient(
+                      self.virtual_machine.ssh_ip,
+                      self.virtual_machine.ssh_port,
+                      self.virtual_machine.username,
+                      self.virtual_machine.password
+                      )
         return
 
 
@@ -651,7 +659,7 @@ class TestRevokeIngressRule(cloudstackTestCase):
         self.debug("Revoking ingress rule for sec group ID: %s for ssh access"
                                                             % security_group.id)
         # Revoke Security group to SSH to VM
-        result = security_group.revoke(
+        security_group.revoke(
                                 self.apiclient,
                                 id=ssh_rule["ruleid"]
                                 )
@@ -752,7 +760,7 @@ class TestDhcpOnlyRouter(cloudstackTestCase):
         #2. The only service supported by this router should be dhcp
 
         # Find router associated with user account
-        list_router_response = list_routers(
+        list_router_response = Router.list(
                                     self.apiclient,
                                     zoneid=self.zone.id,
                                     listall=True
@@ -764,7 +772,7 @@ class TestDhcpOnlyRouter(cloudstackTestCase):
                         )
         router = list_router_response[0]
 
-        hosts = list_hosts(
+        hosts = Host.list(
                            self.apiclient,
                            zoneid=router.zoneid,
                            type='Routing',
@@ -886,7 +894,7 @@ class TestdeployVMWithUserData(cloudstackTestCase):
         #    router for this VM
 
         # Find router associated with user account
-        list_router_response = list_routers(
+        list_router_response = Router.list(
                                     self.apiclient,
                                     zoneid=self.zone.id,
                                     listall=True
@@ -1201,7 +1209,7 @@ class TestDeleteSecurityGroup(cloudstackTestCase):
         # Destroy the VM
         self.virtual_machine.delete(self.apiclient)
 
-        config = list_configurations(
+        config = Configurations.list(
                                      self.apiclient,
                                      name='expunge.delay'
                                      )
@@ -1220,8 +1228,8 @@ class TestDeleteSecurityGroup(cloudstackTestCase):
             self.debug("Deleting Security Group: %s" % security_group.id)
             security_group.delete(self.apiclient)
         except Exception as e:
-            self.fail("Failed to delete security group - ID: %s" \
-                      % security_group.id
+            self.fail("Failed to delete security group - ID: %s: %s" \
+                      % (security_group.id, e)
                       )
         return
 
@@ -1639,15 +1647,13 @@ class TestIngressRule(cloudstackTestCase):
                       % ingress_rule["id"]
                       )
 
-        self.virtual_machine.stop(self.apiclient)
-
-        # Sleep to ensure that VM is in stopped state
-        time.sleep(self.services["sleep"])
-
-        self.virtual_machine.start(self.apiclient)
-
-        # Sleep to ensure that VM is in running state
-        time.sleep(self.services["sleep"])
+        try:
+            self.virtual_machine.stop(self.apiclient)
+            self.virtual_machine.start(self.apiclient)
+            # Sleep to ensure that VM is in running state
+            time.sleep(self.services["sleep"])
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
 
         # SSH should be allowed on 22 port after restart
         try:


Mime
View raw message