You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by gi...@apache.org on 2014/05/07 15:30:45 UTC

[1/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary

Repository: cloudstack
Updated Branches:
  refs/heads/master d4f167032 -> 247c79669


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/smoke/test_templates.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py
index 4865ee3..c7594bb 100644
--- a/test/integration/smoke/test_templates.py
+++ b/test/integration/smoke/test_templates.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,19 +17,28 @@
 """ BVT tests for Templates ISO
 """
 #Import Local Modules
-import marvin
 from marvin.codes import FAILED
-from marvin.cloudstackTestCase import *
-from marvin.cloudstackAPI import *
-from marvin.sshClient import SshClient
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.cloudstackAPI import (updateTemplate,
+                                  extractTemplate,
+                                  listZones,
+                                  updateTemplatePermissions,
+                                  deleteTemplate,
+                                  copyTemplate)
+from marvin.lib.utils import random_gen, cleanup_resources
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             VirtualMachine,
+                             DiskOffering,
+                             Template,
+                             Volume)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template)
 from nose.plugins.attrib import attr
 import urllib
-from random import random
 #Import System modules
-import datetime
+import time
 
 _multiprocess_shared_ = True
 
@@ -62,38 +71,43 @@ class TestCreateTemplate(cloudstackTestCase):
         cls.domain = get_domain(cls.apiclient)
         cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.services['mode'] = cls.zone.networktype
-        cls.disk_offering = DiskOffering.create(
+
+        cls._cleanup = []
+        try:
+            cls.disk_offering = DiskOffering.create(
                                     cls.apiclient,
                                     cls.services["disk_offering"]
                                     )
-        template = get_template(
+            cls._cleanup.append(cls.disk_offering)
+            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"]
-
-        cls.services["template"]["ostypeid"] = template.ostypeid
-        cls.services["template_2"]["ostypeid"] = template.ostypeid
-        cls.services["ostypeid"] = template.ostypeid
-
-        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
-        cls.services["volume"]["diskoffering"] = cls.disk_offering.id
-        cls.services["volume"]["zoneid"] = cls.zone.id
-        cls.services["sourcezoneid"] = cls.zone.id
-
-        cls.account = Account.create(
+            if template == FAILED:
+                assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
+            cls.services["template"]["ostypeid"] = template.ostypeid
+            cls.services["template_2"]["ostypeid"] = template.ostypeid
+            cls.services["ostypeid"] = template.ostypeid
+
+            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+            cls.services["volume"]["diskoffering"] = cls.disk_offering.id
+            cls.services["volume"]["zoneid"] = cls.zone.id
+            cls.services["sourcezoneid"] = cls.zone.id
+            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"]
                                             )
-        #create virtual machine
-        cls.virtual_machine = VirtualMachine.create(
+            cls._cleanup.append(cls.service_offering)
+            #create virtual machine
+            cls.virtual_machine = VirtualMachine.create(
                                     cls.apiclient,
                                     cls.services["virtual_machine"],
                                     templateid=template.id,
@@ -102,47 +116,20 @@ class TestCreateTemplate(cloudstackTestCase):
                                     serviceofferingid=cls.service_offering.id,
                                     mode=cls.services["mode"]
                                     )
+            #Stop virtual machine
+            cls.virtual_machine.stop(cls.apiclient)
 
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.apiclient)
-
-        # 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.apiclient,
-                                            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) in change service offering" %
-                                                                        vm.id)
-
-            timeout = timeout - 1
-
-        list_volume = list_volumes(
+            list_volume = Volume.list(
                                    cls.apiclient,
                                    virtualmachineid=cls.virtual_machine.id,
                                    type='ROOT',
                                    listall=True
                                    )
 
-        cls.volume = list_volume[0]
-        cls._cleanup = [
-                        cls.account,
-                        cls.service_offering,
-                        cls.disk_offering,
-                        ]
+            cls.volume = list_volume[0]
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
         return
 
     @classmethod
@@ -180,7 +167,7 @@ class TestCreateTemplate(cloudstackTestCase):
 
         self.debug("Created template with ID: %s" % template.id)
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["templatefilter"],
@@ -289,31 +276,7 @@ class TestTemplates(cloudstackTestCase):
         #Stop virtual machine
         cls.virtual_machine.stop(cls.apiclient)
 
-        # 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.apiclient,
-                                            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) in change service offering" %
-                                                                        vm.id)
-
-            timeout = timeout - 1
-
-        list_volume = list_volumes(
+        list_volume = Volume.list(
                                    cls.apiclient,
                                    virtualmachineid=cls.virtual_machine.id,
                                    type='ROOT',
@@ -323,8 +286,8 @@ class TestTemplates(cloudstackTestCase):
             cls.volume = list_volume[0]
         except Exception as e:
             raise Exception(
-                "Exception: Unable to find root volume foe VM: %s" %
-                                                    cls.virtual_machine.id)
+                "Exception: Unable to find root volume foe VM: %s - %s" %
+                 (cls.virtual_machine.id, e))
 
         #Create templates for Edit, Delete & update permissions testcases
         cls.template_1 = Template.create(
@@ -407,7 +370,7 @@ class TestTemplates(cloudstackTestCase):
         timeout = self.services["timeout"]
         while True:
             # Verify template response for updated attributes
-            list_template_response = list_templates(
+            list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["templatefilter"],
@@ -473,7 +436,7 @@ class TestTemplates(cloudstackTestCase):
 
         self.template_1.delete(self.apiclient)
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["templatefilter"],
@@ -560,7 +523,7 @@ class TestTemplates(cloudstackTestCase):
         cmd.isextractable = self.services["isextractable"]
         self.apiclient.updateTemplatePermissions(cmd)
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter='featured',
                                     id=self.template_2.id,
@@ -617,7 +580,7 @@ class TestTemplates(cloudstackTestCase):
         self.apiclient.copyTemplate(cmd)
 
         # Verify template is copied to another zone using ListTemplates
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["templatefilter"],
@@ -651,7 +614,7 @@ class TestTemplates(cloudstackTestCase):
         timeout = self.services["timeout"]
         while True:
             time.sleep(self.services["sleep"])
-            list_template_response = list_templates(
+            list_template_response = Template.list(
                                         self.apiclient,
                                         templatefilter=\
                                         self.services["templatefilter"],
@@ -691,7 +654,7 @@ class TestTemplates(cloudstackTestCase):
         # Validate the following
         # 1. ListTemplates should show only 'public' templates for normal user
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter='featured',
                                     account=self.user.name,
@@ -723,7 +686,7 @@ class TestTemplates(cloudstackTestCase):
         # Validate the following
         # 1. ListTemplates should not show 'SYSTEM' templates for normal user
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter='featured',
                                     account=self.user.name,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/smoke/test_vm_life_cycle.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py
index f114ec9..62a807d 100644
--- a/test/integration/smoke/test_vm_life_cycle.py
+++ b/test/integration/smoke/test_vm_life_cycle.py
@@ -18,12 +18,24 @@
 """
 #Import Local Modules
 from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.codes import FAILED
-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.cloudstackAPI import (recoverVirtualMachine,
+                                  destroyVirtualMachine,
+                                  attachIso,
+                                  detachIso)
+from marvin.lib.utils import (cleanup_resources,
+                              validateList,
+                              get_hypervisor_type)
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             VirtualMachine,
+                             Host,
+                             Iso,
+                             Router,
+                             Configurations)
+from marvin.lib.common import (get_domain,
+                                get_zone,
+                                get_template)
+from marvin.codes import FAILED, PASS
 from nose.plugins.attrib import attr
 #Import System modules
 import time
@@ -110,7 +122,7 @@ class TestDeployVM(cloudstackTestCase):
         # Validate the following:
         # 1. Virtual Machine is accessible via SSH
         # 2. listVirtualMachines returns accurate information
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -159,7 +171,7 @@ class TestDeployVM(cloudstackTestCase):
         3. Has a linklocalip, publicip and a guestip
         @return:
         """
-        routers = list_routers(self.apiclient, account=self.account.name)
+        routers = Router.list(self.apiclient, account=self.account.name)
         self.assertTrue(len(routers) > 0, msg = "No virtual router found")
         router = routers[0]
 
@@ -181,7 +193,7 @@ class TestDeployVM(cloudstackTestCase):
         2. is in the account the VM was deployed in
         @return:
         """
-        routers = list_routers(self.apiclient, account=self.account.name)
+        routers = Router.list(self.apiclient, account=self.account.name)
         self.assertTrue(len(routers) > 0, msg = "No virtual router found")
         router = routers[0]
 
@@ -301,31 +313,10 @@ class TestVMLifeCycle(cloudstackTestCase):
         # 1. Should Not be able to login to the VM.
         # 2. listVM command should return
         #    this VM.State of this VM should be ""Stopped"".
-
-        self.debug("Stopping VM - ID: %s" % self.virtual_machine.id)
-        self.small_virtual_machine.stop(self.apiclient)
-
-        list_vm_response = list_virtual_machines(
-                                            self.apiclient,
-                                            id=self.small_virtual_machine.id
-                                            )
-
-        self.assertEqual(
-                            isinstance(list_vm_response, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        self.assertNotEqual(
-                            len(list_vm_response),
-                            0,
-                            "Check VM available in List Virtual Machines"
-                        )
-
-        self.assertEqual(
-                            list_vm_response[0].state,
-                            "Stopped",
-                            "Check virtual machine is in stopped state"
-                        )
+        try:
+            self.small_virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
         return
 
     @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"])
@@ -339,7 +330,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         self.debug("Starting VM - ID: %s" % self.virtual_machine.id)
         self.small_virtual_machine.start(self.apiclient)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.small_virtual_machine.id
                                             )
@@ -379,7 +370,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         self.debug("Rebooting VM - ID: %s" % self.virtual_machine.id)
         self.small_virtual_machine.reboot(self.apiclient)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.small_virtual_machine.id
                                             )
@@ -416,7 +407,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         self.debug("Destroy VM - ID: %s" % self.small_virtual_machine.id)
         self.small_virtual_machine.delete(self.apiclient)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.small_virtual_machine.id
                                             )
@@ -456,7 +447,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         cmd.id = self.small_virtual_machine.id
         self.apiclient.recoverVirtualMachine(cmd)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.small_virtual_machine.id
                                             )
@@ -540,7 +531,7 @@ class TestVMLifeCycle(cloudstackTestCase):
 
         self.vm_to_migrate.migrate(self.apiclient, migrate_host.id)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.vm_to_migrate.id
                                             )
@@ -580,7 +571,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         cmd.id = self.small_virtual_machine.id
         self.apiclient.destroyVirtualMachine(cmd)
 
-        config = list_configurations(
+        config = Configurations.list(
                                      self.apiclient,
                                      name='expunge.delay'
                                      )
@@ -590,14 +581,14 @@ class TestVMLifeCycle(cloudstackTestCase):
 
         #VM should be destroyed unless expunge thread hasn't run
         #Wait for two cycles of the expunge thread
-        config = list_configurations(
+        config = Configurations.list(
                                      self.apiclient,
                                      name='expunge.interval'
                                      )
         expunge_cycle = int(config[0].value)
         wait_time = expunge_cycle * 2
         while wait_time >= 0:
-            list_vm_response = list_virtual_machines(
+            list_vm_response = VirtualMachine.list(
                                                 self.apiclient,
                                                 id=self.small_virtual_machine.id
                                                 )
@@ -657,7 +648,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         except Exception as e:
             self.fail("SSH failed for virtual machine: %s - %s" %
                                 (self.virtual_machine.ipaddress, e))
-        
+
         mount_dir = "/mnt/tmp"
         cmds = "mkdir -p %s" % mount_dir
         self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest")
@@ -676,7 +667,7 @@ class TestVMLifeCycle(cloudstackTestCase):
         self.debug("Found a mount point at %s with size %s" % (res, size))
 
         # Get ISO size
-        iso_response = list_isos(
+        iso_response = Iso.list(
                                  self.apiclient,
                                  id=iso.id
                                  )

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/smoke/test_volumes.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py
index 7f5c4f3..5908e2b 100644
--- a/test/integration/smoke/test_volumes.py
+++ b/test/integration/smoke/test_volumes.py
@@ -17,15 +17,25 @@
 """ BVT tests for Volumes
 """
 #Import Local Modules
-from marvin.cloudstackTestCase import *
-from marvin.cloudstackException import *
-from marvin.cloudstackAPI import *
-from marvin.sshClient import SshClient
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
+from marvin.cloudstackTestCase import cloudstackTestCase
+#from marvin.cloudstackException import *
+from marvin.cloudstackAPI import (deleteVolume,
+                                  extractVolume,
+                                  resizeVolume)
+#from marvin.sshClient import SshClient
+from marvin.lib.utils import (cleanup_resources,
+                              format_volume_to_ext3)
+from marvin.lib.base import (ServiceOffering,
+                             VirtualMachine,
+                             Account,
+                             Volume,
+                             Host,
+                             DiskOffering)
+from marvin.lib.common import (get_domain,
+                                get_zone,
+                                get_template)
 from marvin.lib.utils import checkVolumeSize
-from marvin.codes import SUCCESS
+from marvin.codes import SUCCESS, FAILED
 from nose.plugins.attrib import attr
 #Import System modules
 import os
@@ -149,10 +159,9 @@ class TestCreateVolume(cloudstackTestCase):
         #Attach a volume with different disk offerings
         #and check the memory allocated to each of them
         for volume in self.volumes:
-            list_volume_response = list_volumes(
-                                                self.apiClient,
-                                                id=volume.id
-                                                )
+            list_volume_response = Volume.list(
+                                               self.apiClient,
+                                               id=volume.id)
             self.assertEqual(
                             isinstance(list_volume_response, list),
                             True,
@@ -186,7 +195,7 @@ class TestCreateVolume(cloudstackTestCase):
                 time.sleep(self.services["sleep"])
 
                 # Ensure that VM is in running state
-                list_vm_response = list_virtual_machines(
+                list_vm_response = VirtualMachine.list(
                                             self.apiClient,
                                             id=self.virtual_machine.id
                                             )
@@ -337,7 +346,7 @@ class TestVolumes(cloudstackTestCase):
                                                     ))
         self.virtual_machine.attach_volume(self.apiClient, self.volume)
         self.attached = True
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                                 self.apiClient,
                                                 id=self.volume.id
                                                 )
@@ -429,7 +438,7 @@ class TestVolumes(cloudstackTestCase):
         self.attached = False
         #Sleep to ensure the current state will reflected in other calls
         time.sleep(self.services["sleep"])
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                                 self.apiClient,
                                                 id=self.volume.id
                                                 )
@@ -501,7 +510,7 @@ class TestVolumes(cloudstackTestCase):
         cmd.diskofferingid = self.services['resizeddiskofferingid']
         success            = False
         try:
-            response = self.apiClient.resizeVolume(cmd)
+            self.apiClient.resizeVolume(cmd)
         except Exception as ex:
             #print str(ex)
             if "invalid" in str(ex):
@@ -516,7 +525,7 @@ class TestVolumes(cloudstackTestCase):
         cmd.diskofferingid = "invalid id"
         success            = False
         try:
-            response = self.apiClient.resizeVolume(cmd)
+            self.apiClient.resizeVolume(cmd)
         except Exception as ex:
             if "invalid" in str(ex):
                 success = True
@@ -527,7 +536,7 @@ class TestVolumes(cloudstackTestCase):
 
         # try to resize a root disk with a disk offering, root can only be resized by size=
         # get root vol from created vm
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiClient,
                                             virtualmachineid=self.virtual_machine.id,
                                             type='ROOT',
@@ -540,7 +549,7 @@ class TestVolumes(cloudstackTestCase):
         cmd.diskofferingid = self.services['diskofferingid']
         success            = False
         try:
-            response = self.apiClient.resizeVolume(cmd)
+            self.apiClient.resizeVolume(cmd)
         except Exception as ex:
             if "Can only resize Data volumes" in str(ex):
                 success = True
@@ -548,7 +557,7 @@ class TestVolumes(cloudstackTestCase):
                 success,
                 True,
                 "ResizeVolume - verify root disks cannot be resized by disk offering id")
-            
+
         # Ok, now let's try and resize a volume that is not custom.
         cmd.id             = self.volume.id
         cmd.diskofferingid = self.services['diskofferingid']
@@ -578,7 +587,7 @@ class TestVolumes(cloudstackTestCase):
         count = 0
         success = True
         while count < 10:
-            list_volume_response = list_volumes(
+            list_volume_response = Volume.list(
                                                 self.apiClient,
                                                 id=self.volume.id,
                                                 type='DATADISK'
@@ -637,7 +646,7 @@ class TestVolumes(cloudstackTestCase):
         count = 0
         success = False
         while count < 3:
-            list_volume_response = list_volumes(
+            list_volume_response = Volume.list(
                                                 self.apiClient,
                                                 id=self.volume.id,
                                                 type='DATADISK'
@@ -661,7 +670,7 @@ class TestVolumes(cloudstackTestCase):
         self.debug("Resize Root for : %s" % self.virtual_machine.id)
 
         # get root vol from created vm
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiClient,
                                             virtualmachineid=self.virtual_machine.id,
                                             type='ROOT',
@@ -679,7 +688,7 @@ class TestVolumes(cloudstackTestCase):
         count = 0
         success = False
         while count < 3:
-            list_volume_response = list_volumes(
+            list_volume_response = Volume.list(
                                                 self.apiClient,
                                                 id=rootvolume.id
                                                 )
@@ -732,7 +741,7 @@ class TestVolumes(cloudstackTestCase):
         cmd.id = self.volume_1.id
         self.apiClient.deleteVolume(cmd)
 
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiClient,
                                             id=self.volume_1.id,
                                             type='DATADISK'


[3/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary

Posted by gi...@apache.org.
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:


[4/4] git commit: updated refs/heads/master to 247c796

Posted by gi...@apache.org.
CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/247c7966
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/247c7966
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/247c7966

Branch: refs/heads/master
Commit: 247c7966938e27ca67bd2f1075d4211ab11b97bf
Parents: d4f1670
Author: Girish Shilamkar <gi...@clogeny.com>
Authored: Wed Apr 30 03:40:40 2014 -0400
Committer: Gaurav Aradhye <ga...@clogeny.com>
Committed: Wed May 7 02:43:10 2014 -0400

----------------------------------------------------------------------
 .../component/test_add_remove_network.py        |  26 +-
 test/integration/component/test_blocker_bugs.py |  40 ++-
 .../component/test_custom_hostname.py           |  17 +-
 .../component/test_dynamic_compute_offering.py  | 241 ++++++--------
 test/integration/component/test_egress_rules.py |  30 +-
 test/integration/component/test_escalations.py  | 269 +++++++---------
 .../component/test_netscaler_configs.py         |  88 ++---
 test/integration/component/test_netscaler_lb.py |  81 ++---
 .../component/test_netscaler_nw_off.py          | 150 ++++-----
 .../component/test_network_offering.py          |  31 +-
 .../component/test_persistent_networks.py       |  55 ++--
 .../component/test_project_resources.py         | 103 +++---
 .../integration/component/test_project_usage.py | 109 ++++---
 .../component/test_redundant_router_cleanups.py |  39 +--
 .../component/test_reset_ssh_keypair.py         | 222 +++++--------
 .../component/test_resource_limits.py           | 168 +++++-----
 .../component/test_security_groups.py           |  68 ++--
 test/integration/component/test_stopped_vm.py   | 104 +++---
 test/integration/component/test_tags.py         | 183 +++++------
 test/integration/component/test_templates.py    | 134 ++++----
 test/integration/component/test_usage.py        | 131 ++++----
 test/integration/component/test_volumes.py      | 319 ++++++++-----------
 test/integration/component/test_vpc_network.py  |   4 -
 .../component/test_vpc_vm_life_cycle.py         |  48 +--
 .../integration/smoke/test_service_offerings.py |  22 +-
 test/integration/smoke/test_templates.py        | 159 ++++-----
 test/integration/smoke/test_vm_life_cycle.py    |  79 ++---
 test/integration/smoke/test_volumes.py          |  59 ++--
 28 files changed, 1350 insertions(+), 1629 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_add_remove_network.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_add_remove_network.py b/test/integration/component/test_add_remove_network.py
index 3e0e78b..c17293d 100644
--- a/test/integration/component/test_add_remove_network.py
+++ b/test/integration/component/test_add_remove_network.py
@@ -347,14 +347,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
         # Validate the following:
         # 1. New nic is generated for the added network
 
-        self.debug("Stopping Virtual Machine: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
-
-        vm_list = list_virtual_machines(self.apiclient,id=self.virtual_machine.id)
-        vm_list_validation_result = validateList(vm_list)
-        self.assertEqual(vm_list_validation_result[0], PASS, "vm list validation failed due to %s" %
-			 vm_list_validation_result[2])
-        self.assertTrue(vm_list[0].state == 'Stopped', "Failed to stop VM, the state is %s" % vm_list[0].state)
+        try:
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
 
         network = None #The network which we are adding to the vm
         if value == "isolated":
@@ -451,16 +447,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
         # Validate the following:
         # 1. Adding VPC to vm should fail
 
-        self.debug("Stopping Virtual Machine: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
-
-        vm_list = list_virtual_machines(self.apiclient,id=self.virtual_machine.id)
-        #validation vm list
-        vm_list_validation_result = validateList(vm_list)
-        self.assertEqual(vm_list_validation_result[0], PASS, "vm list validation failed due to %s" %
-			 vm_list_validation_result[2])
-
-        self.assertTrue(vm_list[0].state == 'Stopped', "Failed to stop VM, the state is %s" % vm_list[0].state)
+        try:
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop virtual machine: %s" % e)
 
         self.addNetworkToVm(self.isolated_network, self.virtual_machine)
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_blocker_bugs.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_blocker_bugs.py b/test/integration/component/test_blocker_bugs.py
index ba2602c..ba15b18 100644
--- a/test/integration/component/test_blocker_bugs.py
+++ b/test/integration/component/test_blocker_bugs.py
@@ -28,7 +28,7 @@ from marvin.lib.base import (Snapshot,
                              StaticNATRule,
                              FireWallRule,
                              Volume)
-from marvin.lib.utils import cleanup_resources
+from marvin.lib.utils import cleanup_resources, validateList
 from marvin.lib.common import (get_zone,
                                get_domain,
                                get_template,
@@ -36,8 +36,9 @@ from marvin.lib.common import (get_zone,
                                get_builtin_template_info)
 
 #Import Local Modules
-from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
 from marvin.cloudstackAPI import restartNetwork
+from marvin.codes import PASS
 import time
 
 
@@ -744,20 +745,24 @@ class TestTemplates(cloudstackTestCase):
                             cls.services["ostype"]
                             )
         cls.services["virtual_machine"]["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._cleanup.append(cls.account)
 
-        cls.services["account"] = cls.account.name
-        cls.service_offering = ServiceOffering.create(
+            cls.services["account"] = cls.account.name
+            cls.service_offering = ServiceOffering.create(
                                             cls.api_client,
                                             cls.services["service_offering"],
                                         )
+            cls._cleanup.append(cls.service_offering)
 
-        # create virtual machine
-        cls.virtual_machine = VirtualMachine.create(
+            # create virtual machine
+            cls.virtual_machine = VirtualMachine.create(
                                     cls.api_client,
                                     cls.services["virtual_machine"],
                                     templateid=template.id,
@@ -765,27 +770,20 @@ class TestTemplates(cloudstackTestCase):
                                     domainid=cls.account.domainid,
                                     serviceofferingid=cls.service_offering.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 = Volume.list(
+            listvolumes = Volume.list(
                                    cls.api_client,
                                    virtualmachineid=cls.virtual_machine.id,
                                    type='ROOT',
                                    listall=True
                                    )
-        try:
-            if isinstance(list_volume, list):
-                cls.volume = list_volume[0]
+            assert validateList(listvolumes)[0] == PASS, "volumes list is empty"
+            cls.volume = listvolumes[0]
         except Exception as e:
-            raise Exception("Warning: Exception during setup : %s" % e)
-
-        cls._cleanup = [
-                        cls.service_offering,
-                        cls.account,
-                        ]
+            cls.tearDownClass()
+            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
 
     @classmethod
     def tearDownClass(cls):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_custom_hostname.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_custom_hostname.py b/test/integration/component/test_custom_hostname.py
index 7eeda49..637be86 100644
--- a/test/integration/component/test_custom_hostname.py
+++ b/test/integration/component/test_custom_hostname.py
@@ -17,12 +17,19 @@
 """ P1 tests for user provide hostname cases
 """
 #Import Local Modules
-import marvin
+
 from nose.plugins.attrib import attr
-from marvin.cloudstackTestCase 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,
+                              random_gen)
+from marvin.lib.base import (ServiceOffering,
+                             Configurations,
+                             VirtualMachine,
+                             Account)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               is_config_suitable)
 
 
 class Services:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_dynamic_compute_offering.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_dynamic_compute_offering.py b/test/integration/component/test_dynamic_compute_offering.py
index 8cb6eb1..3939777 100644
--- a/test/integration/component/test_dynamic_compute_offering.py
+++ b/test/integration/component/test_dynamic_compute_offering.py
@@ -24,12 +24,22 @@
     Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+Compute+Offering+FS
 """
 from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
+from marvin.lib.utils import (cleanup_resources,
+                              validateList,
+                              random_gen)
+from marvin.lib.base import (Account,
+                             VirtualMachine,
+                             ServiceOffering,
+                             Resources,
+                             AffinityGroup,
+                             Host)
+from marvin.lib.common import (get_zone,
+                               get_domain,
+                               get_template,
+                               verifyComputeOfferingCreation)
 
 from nose.plugins.attrib import attr
-from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT
+from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT, FAILED
 from ddt import ddt, data
 
 @ddt
@@ -460,27 +470,6 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
             raise Exception("Warning: Exception during cleanup : %s" % e)
         return
 
-    def stopVM(self, vm):
-        """Stop VM and verify that it is indeed in stopped state"""
-        try:
-            vm.stop(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to stop VM: %s" % e)
-
-        retriesCount = 10
-        while True:
-            vmlist = VirtualMachine.list(self.apiclient, id=vm.id)
-            if str(vmlist[0].state).lower() == "stopped":
-                break
-            elif retriesCount == 0:
-                self.fail("Failed to stop VM even after 10 minutes")
-            else:
-                retriesCount -= 1
-                time.sleep(60)
-                continue
-        # End while
-        return
-
     @data(ADMIN_ACCOUNT, USER_ACCOUNT)
     @attr(tags=["basic","advanced"])
     def test_change_so_stopped_vm_static_to_static(self, value):
@@ -500,46 +489,43 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
         if value == USER_ACCOUNT:
             isadmin=False
 
-        # Create Account
-        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
-        apiclient = self.testClient.getUserApiClient(
+        try:
+            # Create Account
+            self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
+            self.cleanup.append(self.account)
+            apiclient = self.testClient.getUserApiClient(
                                     UserName=self.account.name,
                                     DomainName=self.account.domain)
-        self.cleanup.append(self.account)
 
-        # Create static service offerings (Second offering should have
-        # one of the custom values greater than 1st one, scaling down is not allowed
-        self.services["service_offering"]["cpunumber"] = "2"
-        self.services["service_offering"]["cpuspeed"] = "256"
-        self.services["service_offering"]["memory"] = "128"
+            # Create static service offerings (Second offering should have
+            # one of the custom values greater than 1st one, scaling down is not allowed
+            self.services["service_offering"]["cpunumber"] = "2"
+            self.services["service_offering"]["cpuspeed"] = "256"
+            self.services["service_offering"]["memory"] = "128"
 
-        serviceOffering_static_1 = ServiceOffering.create(self.apiclient,
+            serviceOffering_static_1 = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.services["service_offering"]["cpunumber"] = "4"
+            self.services["service_offering"]["cpunumber"] = "4"
 
-        serviceOffering_static_2 = ServiceOffering.create(self.apiclient,
+            serviceOffering_static_2 = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.cleanup_co.append(serviceOffering_static_1)
-        self.cleanup_co.append(serviceOffering_static_2)
+            self.cleanup_co.append(serviceOffering_static_1)
+            self.cleanup_co.append(serviceOffering_static_2)
 
-        # Deploy VM
-        try:
+            # Deploy VM
             virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
                 serviceofferingid=serviceOffering_static_1.id,
                 accountid=self.account.name,domainid=self.account.domainid)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
 
-        # Stop VM and verify it is in stopped state
-        self.stopVM(virtualMachine)
+            # Stop VM
+            virtualMachine.stop(apiclient)
 
-        # Scale VM to new static service offering
-        try:
+            # Scale VM to new static service offering
             virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static_2.id)
         except Exception as e:
-            self.fail("Failure while changing service offering: %s" % e)
+            self.fail("Exception occured: %s" % e)
         return
 
     @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@@ -565,69 +551,59 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
         if value == USER_ACCOUNT:
             isadmin=False
 
-        # Create Account and api client
-        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
-        apiclient = self.testClient.getUserApiClient(
+        try:
+            # Create Account and api client
+            self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
+            apiclient = self.testClient.getUserApiClient(
                                     UserName=self.account.name,
                                     DomainName=self.account.domain)
-        self.cleanup.append(self.account)
+            self.cleanup.append(self.account)
 
-        # Create static and dynamic service offerings
-        self.services["service_offering"]["cpunumber"] = "2"
-        self.services["service_offering"]["cpuspeed"] = "256"
-        self.services["service_offering"]["memory"] = "128"
+            # Create static and dynamic service offerings
+            self.services["service_offering"]["cpunumber"] = "2"
+            self.services["service_offering"]["cpuspeed"] = "256"
+            self.services["service_offering"]["memory"] = "128"
 
-        serviceOffering_static = ServiceOffering.create(self.apiclient,
+            serviceOffering_static = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
 
-        self.services["service_offering"]["cpunumber"] = ""
-        self.services["service_offering"]["cpuspeed"] = ""
-        self.services["service_offering"]["memory"] = ""
+            self.services["service_offering"]["cpunumber"] = ""
+            self.services["service_offering"]["cpuspeed"] = ""
+            self.services["service_offering"]["memory"] = ""
 
-        serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
+            serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.cleanup_co.append(serviceOffering_static)
-        self.cleanup_co.append(serviceOffering_dynamic)
+            self.cleanup_co.append(serviceOffering_static)
+            self.cleanup_co.append(serviceOffering_dynamic)
 
-        # Deploy VM with static service offering
-        try:
+            # Deploy VM with static service offering
             virtualMachine_1 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
                 serviceofferingid=serviceOffering_static.id,
                 accountid=self.account.name,domainid=self.account.domainid)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
 
-        # Stop VM and verify it is in stopped state
-        self.stopVM(virtualMachine_1)
+            # Stop VM
+            virtualMachine_1.stop(apiclient)
 
-        # Scale VM to dynamic service offering proving all custom values
-        try:
+            # Scale VM to dynamic service offering proving all custom values
             virtualMachine_1.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id,
                                  customcpunumber=4, customcpuspeed=256, custommemory=128)
-        except Exception as e:
-            self.fail("Failure while changing service offering: %s" % e)
 
-        # Deploy VM with static service offering
-        try:
+            # Deploy VM with static service offering
             virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
                 serviceofferingid=serviceOffering_static.id,
                 accountid=self.account.name,domainid=self.account.domainid)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
 
-        # Stop VM and verify it is in stopped state
-        self.stopVM(virtualMachine_2)
+            # Stop VM
+            virtualMachine_2.stop(apiclient)
+        except Exception as e:
+            self.fail("Exception occuered: %s" % e)
 
-        # Scale VM to dynamic service offering proving only custom cpu number
-        try:
+            # Scale VM to dynamic service offering proving only custom cpu number
+        with self.assertRaises(Exception):
             virtualMachine_2.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id,
                                  customcpunumber=4)
-            self.fail("Changing service offering with incomplete data should have failed, it succeded")
-        except Exception as e:
-            self.debug("Failure while changing service offering as expected: %s" % e)
-
         return
 
     @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@@ -649,48 +625,45 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
         if value == USER_ACCOUNT:
             isadmin=False
 
-        # Create account and api client
-        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
-        apiclient = self.testClient.getUserApiClient(
+        try:
+            # Create account and api client
+            self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
+            apiclient = self.testClient.getUserApiClient(
                                     UserName=self.account.name,
                                     DomainName=self.account.domain)
-        self.cleanup.append(self.account)
+            self.cleanup.append(self.account)
 
-        # Create dynamic and static service offering
-        self.services["service_offering"]["cpunumber"] = ""
-        self.services["service_offering"]["cpuspeed"] = ""
-        self.services["service_offering"]["memory"] = ""
+            # Create dynamic and static service offering
+            self.services["service_offering"]["cpunumber"] = ""
+            self.services["service_offering"]["cpuspeed"] = ""
+            self.services["service_offering"]["memory"] = ""
 
-        serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
+            serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.services["service_offering"]["cpunumber"] = "4"
-        self.services["service_offering"]["cpuspeed"] = "256"
-        self.services["service_offering"]["memory"] = "128"
+            self.services["service_offering"]["cpunumber"] = "4"
+            self.services["service_offering"]["cpuspeed"] = "256"
+            self.services["service_offering"]["memory"] = "128"
 
-        serviceOffering_static = ServiceOffering.create(self.apiclient,
+            serviceOffering_static = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.cleanup_co.append(serviceOffering_static)
-        self.cleanup_co.append(serviceOffering_dynamic)
+            self.cleanup_co.append(serviceOffering_static)
+            self.cleanup_co.append(serviceOffering_dynamic)
 
-        # Deploy VM with dynamic service offering
-        try:
+            # Deploy VM with dynamic service offering
             virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
                 serviceofferingid=serviceOffering_dynamic.id,
                 accountid=self.account.name,domainid=self.account.domainid,
                 customcpunumber=2, customcpuspeed=256, custommemory=128)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
 
-        # Stop VM and verify that it is in stopped state
-        self.stopVM(virtualMachine)
+            # Stop VM and verify that it is in stopped state
+            virtualMachine.stop(apiclient)
 
-        # Scale VM to static service offering
-        try:
+            # Scale VM to static service offering
             virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static.id)
         except Exception as e:
-            self.fail("Failure while changing service offering: %s" % e)
+            self.fail("Exception occured: %s" % e)
         return
 
     @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@@ -717,62 +690,52 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
         if value == USER_ACCOUNT:
             isadmin=False
 
-        # Create Account
-        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
-        apiclient = self.testClient.getUserApiClient(
+        try:
+            # Create Account
+            self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
+            apiclient = self.testClient.getUserApiClient(
                                     UserName=self.account.name,
                                     DomainName=self.account.domain)
-        self.cleanup.append(self.account)
+            self.cleanup.append(self.account)
 
-        # Create dynamic service offerings
-        self.services["service_offering"]["cpunumber"] = ""
-        self.services["service_offering"]["cpuspeed"] = ""
-        self.services["service_offering"]["memory"] = ""
+            # Create dynamic service offerings
+            self.services["service_offering"]["cpunumber"] = ""
+            self.services["service_offering"]["cpuspeed"] = ""
+            self.services["service_offering"]["memory"] = ""
 
-        serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient,
+            serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient,
+            serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient,
                                                  self.services["service_offering"])
 
-        self.cleanup_co.append(serviceOffering_dynamic_1)
-        self.cleanup_co.append(serviceOffering_dynamic_2)
+            self.cleanup_co.append(serviceOffering_dynamic_1)
+            self.cleanup_co.append(serviceOffering_dynamic_2)
 
-        # Deploy VM with dynamic service offering
-        try:
+            # Deploy VM with dynamic service offering
             virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
                 serviceofferingid=serviceOffering_dynamic_1.id,
                 accountid=self.account.name,domainid=self.account.domainid,
                 customcpunumber=2, customcpuspeed=256, custommemory=128)
-        except Exception as e:
-            self.fail("vm creation failed: %s" % e)
 
-        # Stop VM and verify that it is in stopped state
-        self.stopVM(virtualMachine)
+            # Stop VM
+            virtualMachine.stop(apiclient)
 
-        # Scale VM with same dynamic service offering
-        try:
+            # Scale VM with same dynamic service offering
             virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id,
                                  customcpunumber=4, customcpuspeed=512, custommemory=256)
-        except Exception as e:
-            self.fail("Failure while changing service offering: %s" % e)
 
-        # Scale VM with other dynamic service offering
-        try:
+            # Scale VM with other dynamic service offering
             virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_2.id,
                                  customcpunumber=4, customcpuspeed=512, custommemory=256)
         except Exception as e:
-            self.fail("Failure while changing service offering: %s" % e)
+            self.fail("Exception occured: %s" % e)
 
         # Scale VM with dynamic service offering proving custom value
         # only for cpu number
-        try:
+        with self.assertRaises(Exception):
             virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id,
                                  customcpunumber=4)
-            self.fail("Changing service offering should have failed, it succeded")
-        except Exception as e:
-            self.debug("Failure while changing service offering: %s" % e)
-
         return
 
     @data(ADMIN_ACCOUNT, USER_ACCOUNT)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_egress_rules.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_egress_rules.py b/test/integration/component/test_egress_rules.py
index f0b98e4..0f05c07 100644
--- a/test/integration/component/test_egress_rules.py
+++ b/test/integration/component/test_egress_rules.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
@@ -1901,27 +1901,11 @@ class TestStartStopVMWithEgressRule(cloudstackTestCase):
                           "Check egress rule created properly"
                     )
 
-        # Stop virtual machine
-        self.debug("Stopping virtual machine: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
-
-        vms = VirtualMachine.list(
-                                  self.apiclient,
-                                  id=self.virtual_machine.id,
-                                  listall=True
-                                  )
-        self.assertEqual(
-                         isinstance(vms, list),
-                         True,
-                         "List VM should return a valid list"
-                         )
-        vm = vms[0]
-        self.assertEqual(
-                         vm.state,
-                         "Stopped",
-                         "VM state should be stopped"
-                         )
-        self.debug("VM: %s state: %s" % (vm.id, vm.state))
+        try:
+            # Stop virtual machine
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop instance: %s" % e)
 
         # Start virtual machine
         self.debug("Starting virtual machine: %s" % self.virtual_machine.id)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_escalations.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_escalations.py b/test/integration/component/test_escalations.py
index c07cf97..ed00b32 100644
--- a/test/integration/component/test_escalations.py
+++ b/test/integration/component/test_escalations.py
@@ -16,23 +16,47 @@
 # under the License.
 
 #Import Local Modules
-from marvin.cloudstackTestCase import *
-from marvin.cloudstackException import *
-from marvin.cloudstackAPI import *
-from marvin.sshClient import SshClient
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
-from marvin.lib.utils import checkVolumeSize
-from marvin.codes import SUCCESS
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.cloudstackAPI import (createVolume,
+                                  createTemplate)
+from marvin.lib.base import (Volume,
+                             Iso,
+                             VirtualMachine,
+                             Template,
+                             Snapshot,
+                             SecurityGroup,
+                             Account,
+                             Zone,
+                             Network,
+                             NetworkOffering,
+                             DiskOffering,
+                             ServiceOffering,
+                             VmSnapshot,
+                             SnapshotPolicy,
+                             SSHKeyPair,
+                             Resources,
+                             Configurations,
+                             VpnCustomerGateway,
+                             Hypervisor,
+                             VpcOffering,
+                             VPC,
+                             NetworkACL)
+from marvin.lib.common import (get_zone,
+                               get_domain,
+                               get_template,
+                               list_os_types)
+from marvin.lib.utils import (validateList,
+                              cleanup_resources,
+                              random_gen)
+from marvin.codes import (PASS, FAIL, EMPTY_LIST)
 from nose.plugins.attrib import attr
-from time import sleep
+import time
 
 class TestVolumes(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-       
+
         cls.testClient = super(TestVolumes, cls).getClsTestClient()
         cls.api_client = cls.testClient.getApiClient()
         cls.services = cls.testClient.getParsedTestDataConfig()
@@ -112,9 +136,9 @@ class TestVolumes(cloudstackTestCase):
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
 
-   
+
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @summary: Function to verify expected and actual values
         Step1: Initializing return flag to True
         Step1: Verifying length of expected and actual dictionaries is matching.
@@ -2142,7 +2166,7 @@ class TestListInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "selfservice"])
     def test_04_list_Destroyed_vm(self):
-        """  
+        """
         @Desc: Test List Destroyed VM's
         @Steps:
         Step1: Listing all the Destroyed VMs for a user
@@ -2250,7 +2274,7 @@ class TestListInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "selfservice"])
     def test_05_list_vm_by_id(self):
-        """  
+        """
         @Desc: Test List VM by Id
         @Steps:
         Step1: Listing all the VMs for a user
@@ -2352,7 +2376,7 @@ class TestListInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "selfservice"])
     def test_06_list_vm_by_name(self):
-        """  
+        """
         @Desc: Test List VM's by Name
         @Steps:
         Step1: Listing all the VMs for a user
@@ -2394,7 +2418,7 @@ class TestListInstances(cloudstackTestCase):
                                  )
             self.cleanup.append(vm_created)
             vms.update({i: vm_created})
-  
+
         # Listing all the VM's for a User
         list_vms_after = VirtualMachine.list(
                                              self.userapiclient,
@@ -3198,22 +3222,6 @@ class TestListInstances(cloudstackTestCase):
                         self.userapiclient,
                         forced=True
                         )
-        # Listing VM details
-        list_vm = VirtualMachine.list(
-                                      self.userapiclient,
-                                      id=vm_created.id
-                                     )
-        status = validateList(list_vm)
-        self.assertEquals(
-                          PASS,
-                          status[0],
-                          "Listing of VM failed"
-                          )
-        self.assertEquals(
-                          "Stopped",
-                          list_vm[0].state,
-                          "Stopped VM is not in stopped state"
-                          )
         # Listing all the SSH Key pairs
         list_keypairs_before = SSHKeyPair.list(
                                                self.userapiclient
@@ -3284,7 +3292,7 @@ class TestListInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "provisioning"])
     def test_12_vm_nics(self):
-        """  
+        """
         @Desc: Test to verify Nics for a VM
         @Steps:
         Step1: Deploying a VM
@@ -3293,7 +3301,7 @@ class TestListInstances(cloudstackTestCase):
         Step4: Creating 1 network
         Step5: Listing all the networks again
         Step6: Verifying that the list size is 2
-        Step7: Verifying that VM deployed in step1 has only 1 nic 
+        Step7: Verifying that VM deployed in step1 has only 1 nic
                 and it is same as network listed in step3
         Step8: Adding the networks created in step4 to VM deployed in step1
         Step9: Verifying that VM deployed in step1 has 2 nics
@@ -3465,7 +3473,6 @@ class TestListInstances(cloudstackTestCase):
                 default_nic = vm_nics_after[i]
             else:
                 non_default_nic = vm_nics_after[i]
-     
         self.assertEquals(
                           1,
                           default_count,
@@ -3513,7 +3520,7 @@ class TestListInstances(cloudstackTestCase):
                 default_nic = vm_nics_after[i]
             else:
                 non_default_nic = vm_nics_after[i]
-     
+
         self.assertEquals(
                           1,
                           default_count,
@@ -3566,7 +3573,7 @@ class TestInstances(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestInstances, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -3587,13 +3594,13 @@ class TestInstances(cloudstackTestCase):
                 cls.storagetype = 'shared'
                 cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared'
                 cls.services["disk_offering"]["storagetype"] = 'shared'
-   
+
             cls.services['mode'] = cls.zone.networktype
             cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo()
             cls.services["virtual_machine"]["zoneid"] = cls.zone.id
             cls.services["virtual_machine"]["template"] = cls.template.id
             cls.services["custom_volume"]["zoneid"] = cls.zone.id
-   
+
             # Creating Disk offering, Service Offering and Account
             cls.disk_offering = DiskOffering.create(
                                                     cls.api_client,
@@ -3648,7 +3655,7 @@ class TestInstances(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -3660,10 +3667,10 @@ class TestInstances(cloudstackTestCase):
         Step4: returning the return flag after all the values are verified
         """
         return_flag = True
-   
+
         if len(expected_vals) != len(actual_vals):
             return False
-   
+
         keys = expected_vals.keys()
         for i in range(0, len(expected_vals)):
             exp_val = expected_vals[keys[i]]
@@ -3680,8 +3687,8 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_13_attach_detach_iso(self):
-        """  
-        @Desc: Test Attach ISO to VM and Detach ISO from VM. 
+        """
+        @Desc: Test Attach ISO to VM and Detach ISO from VM.
         @Steps:
         Step1: Listing all the VMs for a user
         Step2: Verifying that the size of the list is 0
@@ -3808,15 +3815,15 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_14_vm_snapshot_pagination(self):
-        """  
-        @Desc: Test VM Snapshots pagination. 
+        """
+        @Desc: Test VM Snapshots pagination.
         @Steps:
         Step1: Deploying a VM
         Step2: Listing all the Snapshots of the VM deployed in Step 1
         Step3: Verifying that the list size is 0
         Step4: Creating (pagesize + 1) number of Snapshots for the VM
         Step5: Listing all the Snapshots of the VM deployed in Step 1
-        Step6: Verifying that the list size is (pagesize + 1) 
+        Step6: Verifying that the list size is (pagesize + 1)
         Step7: Listing all the VM snapshots in Page 1 with page size
         Step8: Verifying that size of the list is same as page size
         Step9: Listing all the VM snapshots in Page 2 with page size
@@ -3965,8 +3972,8 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_15_revert_vm_to_snapshot(self):
-        """  
-        @Desc: Test Revert VM to Snapshot functionality. 
+        """
+        @Desc: Test Revert VM to Snapshot functionality.
         @Steps:
         Step1: Deploying a VM
         Step2: Listing all the Snapshots of the VM deployed in Step 1
@@ -4064,14 +4071,14 @@ class TestInstances(cloudstackTestCase):
                           len(list_snapshots_after),
                           "Count of VM Snapshots is not matching"
                           )
-        # Verifying that only 1 snapshot is having current flag set to true 
+        # Verifying that only 1 snapshot is having current flag set to true
         # and that snapshot is the latest snapshot created (snapshot2)
         current_count = 0
         for i in range(0, len(list_snapshots_after)):
             if(list_snapshots_after[i].current is True):
                 current_count = current_count + 1
                 current_snapshot = list_snapshots_after[i]
-  
+
         self.assertEquals(
                           1,
                           current_count,
@@ -4104,7 +4111,7 @@ class TestInstances(cloudstackTestCase):
                           len(list_snapshots_after),
                           "Count of VM Snapshots is not matching"
                           )
-        # Verifying that only 1 snapshot is having current flag set to true 
+        # Verifying that only 1 snapshot is having current flag set to true
         # and that snapshot is snapshot1
         current_count = 0
         for i in range(0, len(list_snapshots_after)):
@@ -4125,7 +4132,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "selfservice"])
     def test_16_list_vm_volumes_pagination(self):
-        """  
+        """
         @Desc: Test to verify pagination of Volumes for a VM
         @Steps:
         Step1: Deploying a VM
@@ -4218,7 +4225,7 @@ class TestInstances(cloudstackTestCase):
                                      self.userapiclient,
                                      volume_created
                                      )
-  
+
         # List all the volumes for the VM again
         list_volumes_after = Volume.list(
                                           self.userapiclient,
@@ -4299,7 +4306,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_17_running_vm_scaleup(self):
-        """  
+        """
         @Desc: Test to verify change service for Running VM
         @Steps:
         Step1: Checking if dynamic scaling of virtual machines is enabled in zone and template.
@@ -4437,7 +4444,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_18_stopped_vm_change_service(self):
-        """  
+        """
         @Desc: Test to verify change service for Stopped VM
         @Steps:
         Step1: Deploying a VM
@@ -4504,22 +4511,6 @@ class TestInstances(cloudstackTestCase):
                         self.userapiclient,
                         forced=True
                         )
-        # Listing VM details
-        list_vm = VirtualMachine.list(
-                                      self.userapiclient,
-                                      id=vm_created.id
-                                     )
-        status = validateList(list_vms_after)
-        self.assertEquals(
-                          PASS,
-                          status[0],
-                          "Listing of VM failed"
-                          )
-        self.assertEquals(
-                          "Stopped",
-                          list_vm[0].state,
-                          "Stopped VM is not in stopped state"
-                          )
         # Listing all the service offerings
         service_offerings_list = ServiceOffering.list(
                                                       self.userapiclient,
@@ -4573,7 +4564,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_19_create_reset_vm_sshkey(self):
-        """  
+        """
         @Desc: Test to verify creation and reset of SSH Key for VM
         @Steps:
         Step1: Deploying a VM
@@ -4629,22 +4620,6 @@ class TestInstances(cloudstackTestCase):
                         self.userapiclient,
                         forced=True
                         )
-        # Listing VM details
-        list_vm = VirtualMachine.list(
-                                      self.userapiclient,
-                                      id=vm_created.id
-                                     )
-        status = validateList(list_vm)
-        self.assertEquals(
-                          PASS,
-                          status[0],
-                          "Listing of VM failed"
-                          )
-        self.assertEquals(
-                          "Stopped",
-                          list_vm[0].state,
-                          "Stopped VM is not in stopped state"
-                          )
         # Listing all the SSH Key pairs
         list_keypairs_before = SSHKeyPair.list(
                                                self.userapiclient
@@ -4652,7 +4627,7 @@ class TestInstances(cloudstackTestCase):
         list_keypairs_before_size = 0
         if list_keypairs_before is not None:
             list_keypairs_before_size = len(list_keypairs_before)
-  
+
         # Creating a new Key pair
         new_keypair = SSHKeyPair.create(
                                         self.userapiclient,
@@ -4716,7 +4691,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "selfservice"])
     def test_20_update_vm_displayname_group(self):
-        """  
+        """
         @Desc: Test to verify Update VM details
         @Steps:
         Step1: List all the VM's for a user
@@ -4817,7 +4792,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_21_restore_vm(self):
-        """  
+        """
         @Desc: Test to verify Restore VM
         @Steps:
         Step1: List all the VM's for a user
@@ -4904,7 +4879,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["advanced", "selfservice"])
     def test_22_deploy_vm_multiple_networks(self):
-        """  
+        """
         @Desc: Test to verify deploy VM with multiple networks
         @Steps:
         Step1: List all the networks for user
@@ -4924,7 +4899,7 @@ class TestInstances(cloudstackTestCase):
         networks_list_size = 0
         if networks_list_before is not None:
             networks_list_size = len(networks_list_before)
-     
+
         # Listing Network Offerings
         network_offerings_list = NetworkOffering.list(
                                                       self.apiClient,
@@ -4956,7 +4931,7 @@ class TestInstances(cloudstackTestCase):
                                  )
             self.cleanup.append(network)
             networks_list_size = networks_list_size + 1
- 
+
         # Listing the networks again
         networks_list_after = Network.list(
                                            self.userapiclient,
@@ -5036,7 +5011,7 @@ class TestInstances(cloudstackTestCase):
 
     @attr(tags=["basic", "provisioning"])
     def test_23_deploy_vm_multiple_securitygroups(self):
-        """  
+        """
         @Desc: Test to verify deploy VM with multiple Security Groups
         @Steps:
         Step1: List all the security groups for user
@@ -5057,7 +5032,7 @@ class TestInstances(cloudstackTestCase):
         security_groups_list_size = 0
         if security_groups_list is not None:
             security_groups_list_size = len(security_groups_list)
-     
+
         while security_groups_list_size < 2:
             # Creating a security group
             security_group = SecurityGroup.create(
@@ -5072,7 +5047,7 @@ class TestInstances(cloudstackTestCase):
                                  )
             self.cleanup.append(security_group)
             security_groups_list_size = security_groups_list_size + 1
-     
+
         # Listing the networks again
         security_groups_list = SecurityGroup.list(
                                                   self.userapiclient,
@@ -5142,7 +5117,7 @@ class TestInstances(cloudstackTestCase):
                 (vm_securitygroups[i].id != security_groups_list[1].id)):
                 vm_securitygroups_flag = False
                 break
-     
+
         self.assertEquals(
                           True,
                           vm_securitygroups_flag,
@@ -5155,7 +5130,7 @@ class TestSnapshots(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestSnapshots, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -5175,7 +5150,7 @@ class TestSnapshots(cloudstackTestCase):
                 cls.storagetype = 'shared'
                 cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared'
                 cls.services["disk_offering"]["storagetype"] = 'shared'
-    
+
             cls.services['mode'] = cls.zone.networktype
             cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo()
             cls.services["virtual_machine"]["zoneid"] = cls.zone.id
@@ -5235,7 +5210,7 @@ class TestSnapshots(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -5267,7 +5242,7 @@ class TestSnapshots(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_01_list_volume_snapshots_pagination(self):
-        """  
+        """
         @Desc: Test to List Volume Snapshots pagination
         @steps:
         Step1: Listing all the volume snapshots for a user
@@ -5399,7 +5374,7 @@ class TestSnapshots(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_02_list_volume_snapshots_byid(self):
-        """  
+        """
         @Desc: Test to List Volume Snapshots by Id
         @Steps:
         Step1: Listing all the volume snapshots for a user
@@ -5517,7 +5492,7 @@ class TestSnapshots(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_03_list_vm_snapshots_pagination(self):
-        """  
+        """
         @Desc: Test to List VM Snapshots pagination
         @Steps:
         Step1: Listing all the VM snapshots for a user
@@ -5653,7 +5628,7 @@ class TestSnapshots(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_04_list_vm_snapshots_byid(self):
-        """  
+        """
         @summary: Test to List VM Snapshots by Id
 
         Step1: Listing all the VM snapshots for a user
@@ -5749,7 +5724,7 @@ class TestSecurityGroups(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestSecurityGroups, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -5796,7 +5771,7 @@ class TestSecurityGroups(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -5828,11 +5803,11 @@ class TestSecurityGroups(cloudstackTestCase):
 
     @attr(tags=["basic", "provisioning"])
     def test_01_list_securitygroups_pagination(self):
-        """  
+        """
         @Desc: Test to List Security Groups pagination
         @steps:
         Step1: Listing all the Security Groups for a user
-        Step2: Verifying that list size is 1 
+        Step2: Verifying that list size is 1
         Step3: Creating (page size) number of Security Groups
         Step4: Listing all the Security Groups again for a user
         Step5: Verifying that list size is (page size + 1)
@@ -5953,11 +5928,11 @@ class TestSecurityGroups(cloudstackTestCase):
 
     @attr(tags=["basic", "provisioning"])
     def test_02_securitygroups_authorize_revoke_ingress(self):
-        """  
+        """
         @Desc: Test to Authorize and Revoke Ingress for Security Group
         @steps:
         Step1: Listing all the Security Groups for a user
-        Step2: Verifying that list size is 1 
+        Step2: Verifying that list size is 1
         Step3: Creating a Security Groups
         Step4: Listing all the Security Groups again for a user
         Step5: Verifying that list size is 2
@@ -6117,11 +6092,11 @@ class TestSecurityGroups(cloudstackTestCase):
 
     @attr(tags=["basic", "provisioning"])
     def test_03_securitygroups_authorize_revoke_egress(self):
-        """  
+        """
         @Desc: Test to Authorize and Revoke Egress for Security Group
         @steps:
         Step1: Listing all the Security Groups for a user
-        Step2: Verifying that list size is 1 
+        Step2: Verifying that list size is 1
         Step3: Creating a Security Groups
         Step4: Listing all the Security Groups again for a user
         Step5: Verifying that list size is 2
@@ -6284,7 +6259,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestVpnCustomerGateways, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -6331,7 +6306,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -6363,7 +6338,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_01_list_vpncustomergateways_pagination(self):
-        """  
+        """
         @Desc: Test to List VPN Customer Gateways pagination
         @steps:
         Step1: Listing all the VPN Customer Gateways for a user
@@ -6483,7 +6458,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_02_update_vpncustomergateways(self):
-        """  
+        """
         @Desc: Test to update VPN Customer Gateways pagination
         @steps:
         Step1: Listing all the VPN Customer Gateways for a user
@@ -6613,7 +6588,7 @@ class TestTemplates(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestTemplates, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -6661,7 +6636,7 @@ class TestTemplates(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -6693,7 +6668,7 @@ class TestTemplates(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_01_list_templates_pagination(self):
-        """  
+        """
         @Desc: Test to List Templates pagination
         @steps:
         Step1: Listing all the Templates for a user
@@ -6706,8 +6681,8 @@ class TestTemplates(cloudstackTestCase):
         Step8: Listing all the Templates in page2
         Step9: Verifying that list size is 1
         Step10: Listing the template by Id
-        Step11: Verifying if the template is downloaded and ready. 
-                If yes the continuing 
+        Step11: Verifying if the template is downloaded and ready.
+                If yes the continuing
                 If not waiting and checking for template to be ready till timeout
         Step12: Deleting the Template present in page 2
         Step13: Listing all the Templates in page2
@@ -6853,7 +6828,7 @@ class TestTemplates(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_02_download_template(self):
-        """  
+        """
         @Desc: Test to Download Template
         @steps:
         Step1: Listing all the Templates for a user
@@ -6861,8 +6836,8 @@ class TestTemplates(cloudstackTestCase):
         Step3: Creating a Templates
         Step4: Listing all the Templates again for a user
         Step5: Verifying that list size is 1
-        Step6: Verifying if the template is in ready state. 
-                If yes the continuing 
+        Step6: Verifying if the template is in ready state.
+                If yes the continuing
                 If not waiting and checking for template to be ready till timeout
         Step7: Downloading the template (Extract)
         Step8: Verifying that Template is downloaded
@@ -6974,7 +6949,7 @@ class TestTemplates(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_03_edit_template_details(self):
-        """  
+        """
         @Desc: Test to Edit Template name, displaytext, OSType
         @steps:
         Step1: Listing all the Templates for a user
@@ -6982,8 +6957,8 @@ class TestTemplates(cloudstackTestCase):
         Step3: Creating a Templates
         Step4: Listing all the Templates again for a user
         Step5: Verifying that list size is 1
-        Step6: Verifying if the template is in ready state. 
-                If yes the continuing 
+        Step6: Verifying if the template is in ready state.
+                If yes the continuing
                 If not waiting and checking for template to be ready till timeout
         Step7: Editing the template name
         Step8: Verifying that Template name is edited
@@ -7160,7 +7135,7 @@ class TestTemplates(cloudstackTestCase):
             if ostype_list[i].id != template_created.ostypeid:
                 newostypeid = ostype_list[i].id
                 break
- 
+
         edited_template = Template.update(
                                           template_created,
                                           self.userapiclient,
@@ -7290,7 +7265,7 @@ class TestTemplates(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_04_copy_template(self):
-        """  
+        """
         @Desc: Test to copy Template from one zone to another
         @steps:
         Step1: Listing Zones available for a user
@@ -7504,7 +7479,7 @@ class TestIsos(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []        
+            cls._cleanup = []
             cls.testClient = super(TestIsos, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -7552,7 +7527,7 @@ class TestIsos(cloudstackTestCase):
         return
 
     def __verify_values(self, expected_vals, actual_vals):
-        """  
+        """
         @Desc: Function to verify expected and actual values
         @Steps:
         Step1: Initializing return flag to True
@@ -7584,7 +7559,7 @@ class TestIsos(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_01_list_isos_pagination(self):
-        """  
+        """
         @Desc: Test to List ISO's pagination
         @steps:
         Step1: Listing all the ISO's for a user
@@ -7597,8 +7572,8 @@ class TestIsos(cloudstackTestCase):
         Step8: Listing all the ISO's in page2
         Step9: Verifying that list size is 1
         Step10: Listing the ISO's by Id
-        Step11: Verifying if the ISO is downloaded and ready. 
-                If yes the continuing 
+        Step11: Verifying if the ISO is downloaded and ready.
+                If yes the continuing
                 If not waiting and checking for iso to be ready till timeout
         Step12: Deleting the ISO present in page 2
         Step13: Listing all the ISO's in page2
@@ -7738,7 +7713,7 @@ class TestIsos(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_02_download_iso(self):
-        """  
+        """
         @Desc: Test to Download ISO
         @steps:
         Step1: Listing all the ISO's for a user
@@ -7746,8 +7721,8 @@ class TestIsos(cloudstackTestCase):
         Step3: Creating an ISO
         Step4: Listing all the ISO's again for a user
         Step5: Verifying that list size is 1
-        Step6: Verifying if the ISO is in ready state. 
-                If yes the continuing 
+        Step6: Verifying if the ISO is in ready state.
+                If yes the continuing
                 If not waiting and checking for template to be ready till timeout
         Step7: Downloading the ISO (Extract)
         Step8: Verifying the details of downloaded ISO
@@ -7853,7 +7828,7 @@ class TestIsos(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_03_edit_iso_details(self):
-        """  
+        """
         @Desc: Test to Edit ISO name, displaytext, OSType
         @steps:
         Step1: Listing all the ISO's for a user
@@ -7861,8 +7836,8 @@ class TestIsos(cloudstackTestCase):
         Step3: Creating an ISO
         Step4: Listing all the ISO's again for a user
         Step5: Verifying that list size is 1
-        Step6: Verifying if the ISO is in ready state. 
-                If yes the continuing 
+        Step6: Verifying if the ISO is in ready state.
+                If yes the continuing
                 If not waiting and checking for template to be ready till timeout
         Step7: Editing the ISO's name, displaytext
         Step8: Verifying that ISO name and displaytext are edited
@@ -7990,7 +7965,7 @@ class TestIsos(cloudstackTestCase):
             if ostype_list[i].id != iso_created.ostypeid:
                 newostypeid = ostype_list[i].id
                 break
-   
+
         edited_iso = Iso.update(
                                 iso_created,
                                 self.userapiclient,
@@ -8037,7 +8012,7 @@ class TestIsos(cloudstackTestCase):
 
     @attr(tags=["advanced", "basic", "provisioning"])
     def test_04_copy_iso(self):
-        """  
+        """
         @Desc: Test to copy ISO from one zone to another
         @steps:
         Step1: Listing Zones available for a user
@@ -8234,7 +8209,7 @@ class TestNetworks(cloudstackTestCase):
     @classmethod
     def setUpClass(cls):
         try:
-            cls._cleanup = []      
+            cls._cleanup = []
             cls.testClient = super(TestNetworks, cls).getClsTestClient()
             cls.api_client = cls.testClient.getApiClient()
             cls.services = cls.testClient.getParsedTestDataConfig()
@@ -9646,4 +9621,4 @@ class TestNetworks(cloudstackTestCase):
                                            networkid=network_created.id
                                            )
         self.assertIsNone(list_network_acl, "ACL list is not empty for newly created network")
-        return
\ No newline at end of file
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_netscaler_configs.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_netscaler_configs.py b/test/integration/component/test_netscaler_configs.py
index 592b351..6d85609 100644
--- a/test/integration/component/test_netscaler_configs.py
+++ b/test/integration/component/test_netscaler_configs.py
@@ -18,15 +18,28 @@
 """ P1 tests for netscaler configurations
 """
 #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,
+                              random_gen)
+from marvin.lib.base import (VirtualMachine,
+                             NetworkServiceProvider,
+                             PublicIPAddress,
+                             Account,
+                             Network,
+                             NetScaler,
+                             LoadBalancerRule,
+                             NetworkOffering,
+                             ServiceOffering,
+                             PhysicalNetwork,
+                             Configurations)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               add_netscaler)
 from marvin.sshClient import SshClient
-import datetime
+import time
 
 
 class Services:
@@ -559,7 +572,7 @@ class TestNetScalerDedicated(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'
@@ -621,11 +634,11 @@ class TestNetScalerDedicated(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'
                                     )
@@ -781,7 +794,7 @@ class TestNetScalerShared(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'
@@ -839,11 +852,11 @@ class TestNetScalerShared(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'
                                     )
@@ -1023,7 +1036,7 @@ class TestNetScalerCustomCapacity(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'
@@ -1087,11 +1100,11 @@ class TestNetScalerCustomCapacity(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'
                                     )
@@ -1244,7 +1257,7 @@ class TestNetScalerCustomCapacity(cloudstackTestCase):
         self.debug("Deploying VM in account: %s" % self.account_3.name)
         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,
@@ -1295,7 +1308,7 @@ class TestNetScalerNoCapacity(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'
@@ -1359,11 +1372,11 @@ class TestNetScalerNoCapacity(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'
                                     )
@@ -1517,7 +1530,7 @@ class TestNetScalerNoCapacity(cloudstackTestCase):
         self.debug("Deploying VM in account: %s" % self.account_3.name)
         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,
@@ -1568,7 +1581,7 @@ class TestGuestNetworkWithNetScaler(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'
@@ -1626,11 +1639,11 @@ class TestGuestNetworkWithNetScaler(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'
                                     )
@@ -2030,11 +2043,11 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase):
         self.debug("Account: %s is deleted!" % self.account_1.name)
 
         self.debug("Waiting for network.gc.interval & network.gc.wait..")
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-        wait = list_configurations(
+        wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -2223,15 +2236,18 @@ class TestGuestNetworkShutDown(cloudstackTestCase):
             "Stopping all the VM instances for the account: %s" %
                                                     self.account.name)
 
-        self.vm_1.stop(self.apiclient)
-        self.vm_2.stop(self.apiclient)
+        try:
+            self.vm_1.stop(self.apiclient)
+            self.vm_2.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop instance: %s" % e)
 
         self.debug("Sleep for network.gc.interval + network.gc.wait")
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.interval'
                                     )
-        wait = list_configurations(
+        wait = Configurations.list(
                                     self.apiclient,
                                     name='network.gc.wait'
                                     )
@@ -2529,7 +2545,7 @@ class TestServiceProvider(cloudstackTestCase):
             cls.netscaler_provider = nw_service_providers[0]
 
         if cls.netscaler_provider.state != 'Enabled':
-            response = NetworkServiceProvider.update(
+            NetworkServiceProvider.update(
                                           cls.api_client,
                                           id=cls.netscaler_provider.id,
                                           state='Enabled'
@@ -2586,11 +2602,11 @@ class TestServiceProvider(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'
                                     )
@@ -2843,7 +2859,7 @@ class TestDeleteNetscaler(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'
@@ -2901,11 +2917,11 @@ class TestDeleteNetscaler(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'
                                     )

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_netscaler_lb.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py
index 732f0f9..4c99aa3 100644
--- a/test/integration/component/test_netscaler_lb.py
+++ b/test/integration/component/test_netscaler_lb.py
@@ -18,15 +18,27 @@
 """ P1 tests for netscaler load balancing
 """
 #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 migrateVirtualMachine
+from marvin.lib.utils import (cleanup_resources,
+                              random_gen)
+from marvin.lib.base import (Account,
+                             VirtualMachine,
+                             PublicIPAddress,
+                             LoadBalancerRule,
+                             ServiceOffering,
+                             NetworkOffering,
+                             Host,
+                             Network,
+                             NATRule,
+                             Configurations)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               add_netscaler)
 from marvin.sshClient import SshClient
-import datetime
+import time
 
 
 class Services:
@@ -209,11 +221,11 @@ class TestLbSourceNat(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'
                                     )
@@ -418,11 +430,11 @@ class TestLbOnIpWithPf(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'
                                     )
@@ -630,11 +642,11 @@ class TestPfOnIpWithLb(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'
                                     )
@@ -771,7 +783,7 @@ class TestPfOnIpWithLb(cloudstackTestCase):
         with self.assertRaises(Exception):
             NATRule.create(
                          self.apiclient,
-                         virtual_machine,
+                         virtual_machine_1,
                          self.services["natrule"],
                          ipaddressid=ip_with_lb_rule.ipaddress.id
                       )
@@ -843,11 +855,11 @@ class TestLbOnNonSourceNat(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'
                                     )
@@ -1059,11 +1071,11 @@ class TestAddMultipleVmsLb(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'
                                     )
@@ -1338,11 +1350,11 @@ class TestMultipleLbRules(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'
                                     )
@@ -1656,11 +1668,11 @@ class TestMultipleLbRulesSameIp(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'
                                     )
@@ -2246,7 +2258,7 @@ class TestDeleteCreateLBRule(cloudstackTestCase):
 
         self.debug("Create a new LB rule with different public port")
         self.services["lbrule"]["publicport"] = 23
-        lb_rule = LoadBalancerRule.create(
+        LoadBalancerRule.create(
                                     self.apiclient,
                                     self.services["lbrule"],
                                     ipaddressid=self.public_ip.ipaddress.id,
@@ -2462,18 +2474,11 @@ class TestVmWithLb(cloudstackTestCase):
         # 4. In netscaler, LB rules for this VM  still remain configured.But
         #    it will be marked as being down
 
-        self.debug("Adding instances: %s, %s to LB rule: %s" % (
-                                                        self.vm_1.name,
-                                                        self.vm_2.name,
-                                                        self.lb_rule_1.name))
-        self.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2])
-        self.debug("Assigned instances: %s, %s to LB rule: %s" % (
-                                                        self.vm_1.name,
-                                                        self.vm_2.name,
-                                                        self.lb_rule_1.name))
-        self.debug("Stopping VM instance: %s" % self.vm_2.name)
-        self.vm_2.stop(self.apiclient)
-        self.debug("Stopped VM: %s" % self.vm_2.name)
+        try:
+            self.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2])
+            self.vm_2.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
 
         try:
             self.debug(
@@ -2642,7 +2647,7 @@ class TestVmWithLb(cloudstackTestCase):
         cmd.virtualmachineid = self.vm_2.id
         self.apiclient.migrateVirtualMachine(cmd)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                             self.apiclient,
                                             id=self.vm_2.id
                                             )
@@ -2852,11 +2857,11 @@ class TestVmWithLb(cloudstackTestCase):
             self.fail("Exception occured during SSH: %s - %s" % (
                                         self.public_ip_1.ipaddress.ipaddress,
                                         e))
-        delay = list_configurations(
+        delay = Configurations.list(
                                     self.apiclient,
                                     name='expunge.delay'
                                     )
-        wait = list_configurations(
+        wait = Configurations.list(
                                     self.apiclient,
                                     name='expunge.interval'
                                     )


[2/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary

Posted by gi...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_stopped_vm.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_stopped_vm.py b/test/integration/component/test_stopped_vm.py
index 6c77679..04dd859 100644
--- a/test/integration/component/test_stopped_vm.py
+++ b/test/integration/component/test_stopped_vm.py
@@ -18,13 +18,27 @@
 """ P1 for stopped Virtual Maschine life cycle
 """
 #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,
+                             VirtualMachine,
+                             ServiceOffering,
+                             Volume,
+                             Router,
+                             DiskOffering,
+                             Host,
+                             Iso,
+                             Cluster,
+                             StoragePool,
+                             Configurations,
+                             Template)
+from marvin.lib.common import (get_zone,
+                               get_domain,
+                               get_template,
+                               get_builtin_template_info,
+                               update_resource_limit)
 #Import System modules
 import time
 
@@ -194,7 +208,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -245,7 +259,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -297,7 +311,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -340,17 +354,17 @@ class TestDeployVM(cloudstackTestCase):
             )
         self.debug("Instance destroyed..waiting till expunge interval")
 
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='expunge.interval'
                                     )
-        delay = list_configurations(
+        delay = Configurations.list(
                                     self.apiclient,
                                     name='expunge.delay'
                                     )
         # Sleep to ensure that all resources are deleted
         time.sleep((int(interval[0].value) + int(delay[0].value)))
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -387,7 +401,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -425,7 +439,7 @@ class TestDeployVM(cloudstackTestCase):
         try:
             self.virtual_machine.attach_volume(self.apiclient, volume)
         except Exception as e:
-            self.fail("Attach volume failed!")
+            self.fail("Attach volume failed with Exception: %s" % e)
         return
 
     @attr(tags=["advanced", "eip", "advancedns", "basic", "sg", "selfservice"])
@@ -452,7 +466,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -528,7 +542,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -566,7 +580,7 @@ class TestDeployVM(cloudstackTestCase):
         try:
             self.virtual_machine.attach_volume(self.apiclient, volume)
         except Exception as e:
-            self.fail("Attach volume failed!")
+            self.fail("Attach volume failed with Exception: %s" % e)
 
         self.debug("Detaching the disk: %s" % volume.name)
         self.virtual_machine.detach_volume(self.apiclient, volume)
@@ -611,7 +625,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -702,7 +716,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine_1.id
                                                  )
@@ -738,7 +752,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine_2.id
                                                  )
@@ -868,7 +882,7 @@ class TestDeployVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -889,28 +903,10 @@ class TestDeployVM(cloudstackTestCase):
                             "Running",
                             "VM should be in Running state after deployment"
                         )
-        self.debug("Stopping instance: %s" % self.virtual_machine.name)
-        self.virtual_machine.stop(self.apiclient)
-        self.debug("Instance is stopped!")
-        self.debug(
-                "Verify listVirtualMachines response for virtual machine: %s" \
-                % self.virtual_machine.id
-            )
-        list_vm_response = list_virtual_machines(
-                                                 self.apiclient,
-                                                 id=self.virtual_machine.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 should be in Stopped state after stoping vm"
-                        )
+        try:
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("failed to stop instance: %s" % e)
         volumes = Volume.list(
                               self.apiclient,
                               virtualmachineid=self.virtual_machine.id,
@@ -1047,7 +1043,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -1112,7 +1108,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -1161,7 +1157,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -1278,7 +1274,7 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine_1.id
                                                  )
@@ -1328,7 +1324,7 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine_2.id
                                                  )
@@ -1375,11 +1371,11 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
         self.virtual_machine_2.delete(self.apiclient)
         self.debug("Instance destroyed..waiting till expunge interval")
 
-        interval = list_configurations(
+        interval = Configurations.list(
                                     self.apiclient,
                                     name='expunge.interval'
                                     )
-        delay = list_configurations(
+        delay = Configurations.list(
                                     self.apiclient,
                                     name='expunge.delay'
                                     )
@@ -1518,8 +1514,8 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
                             )
 
         builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
-        self.services["template"]["url"] = builtin_info[0] 
-        self.services["template"]["hypervisor"] = builtin_info[1]     
+        self.services["template"]["url"] = builtin_info[0]
+        self.services["template"]["hypervisor"] = builtin_info[1]
         self.services["template"]["format"] = builtin_info[2]
 
         # Register new template
@@ -1578,7 +1574,7 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
 
         self.debug("Deployed instance in account: %s" %
                                                     self.account.name)
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )
@@ -1605,7 +1601,7 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
         self.virtual_machine.start(self.apiclient)
         self.debug("Started the instance: %s" % self.virtual_machine.name)
 
-        list_vm_response = list_virtual_machines(
+        list_vm_response = VirtualMachine.list(
                                                  self.apiclient,
                                                  id=self.virtual_machine.id
                                                  )

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_tags.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py
index d6b43d9..fbe6436 100644
--- a/test/integration/component/test_tags.py
+++ b/test/integration/component/test_tags.py
@@ -17,15 +17,31 @@
 """ P1 tests for tags
 """
 #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.lib.utils import cleanup_resources
+from marvin.lib.base import (Tag,
+                             Account,
+                             VirtualMachine,
+                             Iso,
+                             Volume,
+                             Network,
+                             Host,
+                             DiskOffering,
+                             NATRule,
+                             PublicIPAddress,
+                             FireWallRule,
+                             LoadBalancerRule,
+                             Vpn,
+                             Template,
+                             Snapshot,
+                             ServiceOffering,
+                             Project)
+from marvin.lib.common import (get_zone,
+                               get_domain,
+                               get_template)
+from marvin.codes import FAILED
+import time
 
 class Services:
     """Test tags Services
@@ -924,14 +940,14 @@ class TestResourceTags(cloudstackTestCase):
         # 1. Create a tag on template/ISO using createTags API
         # 2. Delete above created tag using deleteTags API
 
-        self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
-        #Stop virtual machine
-        self.vm_1.stop(self.apiclient)
+        try:
+            self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
+            #Stop virtual machine
+            self.vm_1.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
 
         timeout = self.services["timeout"]
-        #Wait before server has be successfully stopped
-        time.sleep(self.services["sleep"])
-
         while True:
             list_volume = Volume.list(
                                    self.apiclient,
@@ -990,11 +1006,11 @@ class TestResourceTags(cloudstackTestCase):
                          'CentOS',
                          'The tag should have original value'
                          )
-      
-        templates = Template.list(
+
+        Template.list(
                   self.apiclient,
                   templatefilter=\
-                  self.services["template"]["templatefilter"],  
+                  self.services["template"]["templatefilter"],
                   listall=True,
                   key='OS',
                   value='CentOS'
@@ -1044,10 +1060,8 @@ class TestResourceTags(cloudstackTestCase):
                          )
         self.debug("ISO created with ID: %s" % iso.id)
 
-        list_iso_response = list_isos(
-                                      self.apiclient,
-                                      id=iso.id
-                                      )
+        list_iso_response = Iso.list(self.apiclient,
+                                     id=iso.id)
         self.assertEqual(
                          isinstance(list_iso_response, list),
                          True,
@@ -1225,12 +1239,10 @@ class TestResourceTags(cloudstackTestCase):
         self.debug("Creating snapshot on ROOT volume for VM: %s " %
                                                             self.vm_1.name)
         # Get the Root disk of VM
-        volumes = list_volumes(
-                               self.apiclient,
-                               virtualmachineid=self.vm_1.id,
-                               type='ROOT',
-                               listall=True
-                              )
+        volumes = Volume.list(self.apiclient,
+                              virtualmachineid=self.vm_1.id,
+                              type='ROOT',
+                              listall=True)
         volume = volumes[0]
 
         # Create a snapshot from the ROOTDISK
@@ -1238,10 +1250,8 @@ class TestResourceTags(cloudstackTestCase):
         self.debug("Snapshot created: ID - %s" % snapshot.id)
         self.cleanup.append(snapshot)
 
-        snapshots = list_snapshots(
-                                   self.apiclient,
-                                   id=snapshot.id
-                                   )
+        snapshots = Snapshot.list(self.apiclient,
+                                  id=snapshot.id)
         self.assertEqual(
                          isinstance(snapshots, list),
                          True,
@@ -1275,13 +1285,10 @@ class TestResourceTags(cloudstackTestCase):
                          'manual',
                          'The tag should have original value'
                          )
-        
-        snapshots = list_snapshots(
-                                   self.apiclient,
-                                   listall=True,
-                                   key='type',
-                                   value='manual'
-                                   )
+        snapshots = Snapshot.list(self.apiclient,
+                                  listall=True,
+                                  key='type',
+                                  value='manual')
         self.assertEqual(
                          isinstance(snapshots, list),
                          True,
@@ -1563,21 +1570,16 @@ class TestResourceTags(cloudstackTestCase):
                          'India',
                          'The tag should have original value'
                          )
-        self.debug("Creating the same tag with caps for user VM")
-        
         try:
-            tag_2 = Tag.create(
-                     self.apiclient,
-                     resourceIds=self.vm_1.id,
-                     resourceType='userVM',
-                     tags={'REGION': 'INDIA'}
-                )
+            Tag.create(self.apiclient,
+                       resourceIds=self.vm_1.id,
+                       resourceType='userVM',
+                       tags={'REGION': 'INDIA'})
         except Exception as e:
             pass
         else:
             assert("Creating same tag in upper case succeeded")
 
-        self.debug("Deleting the created tag..")
         try:
             tag_1.delete(
                        self.apiclient,
@@ -1785,14 +1787,14 @@ class TestResourceTags(cloudstackTestCase):
                             domainid=self.domain.id
                             )
         self.cleanup.append(user_account)
-        
+
         other_user_account = Account.create(
                             self.apiclient,
                             self.services["other_user"],
                             domainid=self.domain.id
                             )
         self.cleanup.append(other_user_account)
-    
+
         iso = Iso.create(
                          self.apiclient,
                          self.services["iso"],
@@ -1801,10 +1803,8 @@ class TestResourceTags(cloudstackTestCase):
                          )
         self.debug("ISO created with ID: %s" % iso.id)
 
-        list_iso_response = list_isos(
-                                      self.apiclient,
-                                      id=iso.id
-                                      )
+        list_iso_response = Iso.list(self.apiclient,
+                                     id=iso.id)
         self.assertEqual(
                             isinstance(list_iso_response, list),
                             True,
@@ -1828,8 +1828,6 @@ class TestResourceTags(cloudstackTestCase):
                         domainid=user_account.domainid,
                         key='region',
                         )
-    
-        self.debug("Verify listTag API using user account")
         self.assertEqual(
                          isinstance(tags, list),
                          True,
@@ -1877,33 +1875,25 @@ class TestResourceTags(cloudstackTestCase):
                             domainid=self.domain.id
                             )
         self.cleanup.append(user_account)
-        
+
         iso = Iso.create(
                          self.apiclient,
                          self.services["iso"],
                          account=user_account.name,
                          domainid=user_account.domainid
                          )
-        self.debug("ISO created with ID: %s" % iso.id)
 
-        list_iso_response = list_isos(
-                                      self.apiclient,
-                                      id=iso.id
-                                      )
+        list_iso_response = Iso.list(self.apiclient,
+                                     id=iso.id)
         self.assertEqual(
                          isinstance(list_iso_response, list),
                          True,
                          "Check list response returns a valid list"
                          )
-
-        self.debug("Creating a tag for the ISO")
-        tag = Tag.create(
-                         self.apiclient,
-                         resourceIds=iso.id,
-                         resourceType='ISO',
-                         tags={'region': 'India'}
-                         )
-        self.debug("Tag created: %s" % tag.__dict__)
+        Tag.create(self.apiclient,
+                   resourceIds=iso.id,
+                   resourceType='ISO',
+                   tags={'region': 'India'})
 
         tags = Tag.list(
                         self.apiclient,
@@ -1913,8 +1903,6 @@ class TestResourceTags(cloudstackTestCase):
                         domainid=user_account.domainid,
                         key='region',
                         )
-    
-        self.debug("Verify listTag API using user account")
         self.assertEqual(
                          isinstance(tags, list),
                          True,
@@ -2200,47 +2188,21 @@ class TestResourceTags(cloudstackTestCase):
     def test_21_create_tag_stopped_vm(self):
         "Test creation of tag on stopped vm."
 
-        self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
-        #Stop virtual machine
-        self.vm_1.stop(self.apiclient)
-    
-        timeout = self.services["timeout"]
-        #Wait before server has be successfully stopped
-        time.sleep(self.services["sleep"])
-
-        list_vm_response = list_virtual_machines(
-                                                 self.apiclient,
-                                                 id=self.vm_1.id
-                                                 )
-
-        self.debug(
-                "Verify listVirtualMachines response for virtual machine: %s" \
-                % self.vm_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 should be in stopped state after deployment"
-                         )
+        try:
+            self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
+            #Stop virtual machine
+            self.vm_1.stop(self.apiclient)
 
-        self.debug("Creating a tag for user VM")
-        tag = Tag.create(
+            self.debug("Creating a tag for user VM")
+            tag = Tag.create(
                          self.apiclient,
                          resourceIds=self.vm_1.id,
                          resourceType='userVM',
                          tags={'region': 'India'}
                          )
-        self.debug("Tag created: %s" % tag.__dict__)
+            self.debug("Tag created: %s" % tag.__dict__)
 
-        tags = Tag.list(
+            tags = Tag.list(
                         self.apiclient,
                         listall=True,
                         resourceType='userVM',
@@ -2249,20 +2211,19 @@ class TestResourceTags(cloudstackTestCase):
                         key='region',
                         value='India'
                         )
-        self.assertEqual(
+            self.assertEqual(
                          isinstance(tags, list),
                          True,
                          "List tags should not return empty response"
                          )
 
-        self.assertEqual(
+            self.assertEqual(
                          tags[0].value,
                          "India",
                          "Tag created with incorrect value"
                          )
 
-        self.debug("Deleting the created tag..")
-        try:
+            self.debug("Deleting the created tag..")
             tag.delete(
                        self.apiclient,
                        resourceIds=self.vm_1.id,
@@ -2270,7 +2231,7 @@ class TestResourceTags(cloudstackTestCase):
                        tags={'region': 'India'}
                        )
         except Exception as e:
-            self.fail("Failed to delete the tag - %s" % e)
+            self.fail("Exception occured - %s" % e)
         return
 
     @attr(tags=["advanced", "basic", "selfservice"])

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_templates.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py
index 98b1cbc..1985264 100644
--- a/test/integration/component/test_templates.py
+++ b/test/integration/component/test_templates.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,15 +17,20 @@
 """ P1 tests for Templates
 """
 #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 urllib
-from random import random
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.cloudstackAPI import listZones
+from marvin.lib.utils import (cleanup_resources)
+from marvin.lib.base import (Account,
+                             Template,
+                             ServiceOffering,
+                             VirtualMachine,
+                             Snapshot,
+                             Volume)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               get_builtin_template_info)
 #Import System modules
 import time
 
@@ -201,14 +206,13 @@ class TestCreateTemplate(cloudstackTestCase):
         time.sleep(self.services["sleep"])
         timeout = self.services["timeout"]
         while True:
-            list_template_response = list_templates(
-                                    self.apiclient,
-                                    templatefilter='all',
-                                    id=template.id,
-                                    zoneid=self.zone.id,
-                                    account=self.account.name,
-                                    domainid=self.account.domainid
-                                    )
+            list_template_response = Template.list(
+                                            self.apiclient,
+                                            templatefilter='all',
+                                            id=template.id,
+                                            zoneid=self.zone.id,
+                                            account=self.account.name,
+                                            domainid=self.account.domainid)
             if isinstance(list_template_response, list):
                 break
             elif timeout == 0:
@@ -247,12 +251,10 @@ class TestCreateTemplate(cloudstackTestCase):
                                     mode=self.services["mode"]
                                     )
         self.debug("creating an instance with template ID: %s" % template.id)
-        vm_response = list_virtual_machines(
-                                        self.apiclient,
-                                        id=virtual_machine.id,
-                                        account=self.account.name,
-                                        domainid=self.account.domainid
-                                        )
+        vm_response = VirtualMachine.list(self.apiclient,
+                                          id=virtual_machine.id,
+                                          account=self.account.name,
+                                          domainid=self.account.domainid)
         self.assertEqual(
                              isinstance(vm_response, list),
                              True,
@@ -300,20 +302,24 @@ class TestTemplates(cloudstackTestCase):
                             cls.services["ostype"]
                             )
         cls.services["virtual_machine"]["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._cleanup.append(cls.account)
 
-        cls.services["account"] = cls.account.name
-        cls.service_offering = ServiceOffering.create(
+            cls.services["account"] = cls.account.name
+            cls.service_offering = ServiceOffering.create(
                                             cls.api_client,
                                             cls.services["service_offering"]
                                         )
+            cls._cleanup.append(cls.service_offering)
 
-        # create virtual machine
-        cls.virtual_machine = VirtualMachine.create(
+            # create virtual machine
+            cls.virtual_machine = VirtualMachine.create(
                                     cls.api_client,
                                     cls.services["virtual_machine"],
                                     templateid=template.id,
@@ -321,40 +327,36 @@ class TestTemplates(cloudstackTestCase):
                                     domainid=cls.account.domainid,
                                     serviceofferingid=cls.service_offering.id,
                                     )
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.api_client)
+            #Stop virtual machine
+            cls.virtual_machine.stop(cls.api_client)
 
-        timeout = cls.services["timeout"]
-        #Wait before server has be successfully stopped
-        time.sleep(cls.services["sleep"])
+            timeout = cls.services["timeout"]
 
-        while True:
-            list_volume = list_volumes(
-                                   cls.api_client,
-                                   virtualmachineid=cls.virtual_machine.id,
-                                   type='ROOT',
-                                   listall=True
-                                   )
-            if isinstance(list_volume, list):
-                break
-            elif timeout == 0:
-                raise Exception("List volumes failed.")
+            while True:
+                list_volume = Volume.list(
+                                cls.api_client,
+                                virtualmachineid=cls.virtual_machine.id,
+                                type='ROOT',
+                                listall=True)
+                if isinstance(list_volume, list):
+                    break
+                elif timeout == 0:
+                    raise Exception("List volumes failed.")
 
-            time.sleep(5)
-            timeout = timeout - 1
+                time.sleep(5)
+                timeout = timeout - 1
 
-        cls.volume = list_volume[0]
+            cls.volume = list_volume[0]
 
-        #Create template from volume
-        cls.template = Template.create(
+            #Create template from volume
+            cls.template = Template.create(
                                          cls.api_client,
                                          cls.services["template"],
                                          cls.volume.id
                                          )
-        cls._cleanup = [
-                        cls.service_offering,
-                        cls.account,
-                        ]
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Failure in setUpClass: %s" % e)
 
     @classmethod
     def tearDownClass(cls):
@@ -405,12 +407,11 @@ class TestTemplates(cloudstackTestCase):
 
         self.debug("creating an instance with template ID: %s" % self.template.id)
         self.cleanup.append(virtual_machine)
-        vm_response = list_virtual_machines(
-                                        self.apiclient,
-                                        id=virtual_machine.id,
-                                        account=self.account.name,
-                                        domainid=self.account.domainid
-                                        )
+        vm_response = VirtualMachine.list(
+                            self.apiclient,
+                            id=virtual_machine.id,
+                            account=self.account.name,
+                            domainid=self.account.domainid)
         #Verify VM response to check whether VM deployment was successful
         self.assertNotEqual(
                             len(vm_response),
@@ -435,13 +436,12 @@ class TestTemplates(cloudstackTestCase):
         # 2. Delete the created template and again verify list template response
 
         # Verify template response for updated attributes
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["template"]["templatefilter"],
                                     id=self.template.id,
-                                    zoneid=self.zone.id
-                                    )
+                                    zoneid=self.zone.id)
         self.assertEqual(
                         isinstance(list_template_response, list),
                         True,
@@ -467,7 +467,7 @@ class TestTemplates(cloudstackTestCase):
         self.template.delete(self.apiclient)
         self.debug("Delete template: %s successful" % self.template)
 
-        list_template_response = list_templates(
+        list_template_response = Template.list(
                                     self.apiclient,
                                     templatefilter=\
                                     self.services["template"]["templatefilter"],
@@ -493,7 +493,7 @@ class TestTemplates(cloudstackTestCase):
         # 4. Deploy Virtual machine using this template
         # 5. VM should be in running state
 
-        volumes = list_volumes(
+        volumes = Volume.list(
                         self.apiclient,
                         virtualmachineid=self.virtual_machine.id,
                         type='ROOT',
@@ -518,7 +518,7 @@ class TestTemplates(cloudstackTestCase):
                                     )
         self.cleanup.append(template)
         # Verify created template
-        templates = list_templates(
+        templates = Template.list(
                                 self.apiclient,
                                 templatefilter=\
                                 self.services["template"]["templatefilter"],
@@ -547,7 +547,7 @@ class TestTemplates(cloudstackTestCase):
                                     )
         self.cleanup.append(virtual_machine)
 
-        vm_response = list_virtual_machines(
+        vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=virtual_machine.id,
                                         account=self.account.name,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_usage.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_usage.py b/test/integration/component/test_usage.py
index eb92011..03823be 100644
--- a/test/integration/component/test_usage.py
+++ b/test/integration/component/test_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,27 @@
 """ 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 (Account,
+                             ServiceOffering,
+                             NATRule,
+                             VirtualMachine,
+                             Snapshot,
+                             Iso,
+                             ImageStore,
+                             LoadBalancerRule,
+                             PublicIPAddress,
+                             DiskOffering,
+                             Template,
+                             VpnUser,
+                             Vpn,
+                             Volume)
+from marvin.lib.common import (get_zone,
+                               get_domain,
+                               get_template)
 
 class Services:
     """Test Snapshots Services
@@ -193,14 +204,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 instance: %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 destroy VM: %s" % e)
 
         # Fetch account ID from account_uuid
         self.debug("select id from account where uuid = '%s';" \
@@ -536,16 +552,18 @@ class TestVolumeUsage(cloudstackTestCase):
         # 4. Destroy the Data disk. Volume.delete event is generated for data
         #    disk of the destroyed VM
 
-        # Stop VM
-        self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
+        try:
+            # Stop VM
+            self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
+            self.virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop instance: %s" % e)
 
-        volume_response = list_volumes(
-                                    self.apiclient,
-                                    virtualmachineid=self.virtual_machine.id,
-                                    type='DATADISK',
-                                    listall=True
-                                    )
+        volume_response = Volume.list(
+                                self.apiclient,
+                                virtualmachineid=self.virtual_machine.id,
+                                type='DATADISK',
+                                listall=True)
         self.assertEqual(
                          isinstance(volume_response, list),
                          True,
@@ -643,19 +661,22 @@ class TestTemplateUsage(cloudstackTestCase):
                             cls.services["ostype"]
                             )
         cls.services["server"]["zoneid"] = cls.zone.id
-        cls.account = Account.create(
+        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.service_offering = ServiceOffering.create(
+            cls.service_offering = ServiceOffering.create(
                                             cls.api_client,
                                             cls.services["service_offering"]
                                             )
-        #create virtual machine
-        cls.virtual_machine = VirtualMachine.create(
+            cls._cleanup.append(cls.service_offering)
+            #create virtual machine
+            cls.virtual_machine = VirtualMachine.create(
                                     cls.api_client,
                                     cls.services["server"],
                                     templateid=template.id,
@@ -665,24 +686,21 @@ class TestTemplateUsage(cloudstackTestCase):
                                     mode=cls.services["mode"]
                                     )
 
-        #Stop virtual machine
-        cls.virtual_machine.stop(cls.api_client)
-
-        #Wait before server has be successfully stopped
-        time.sleep(30)
-        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("List Volumes failed!")
-        cls._cleanup = [
-                        cls.account,
-                        ]
+            #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("List Volumes failed!")
+        except Exception as e:
+            cls.tearDownClass()
+            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
         return
 
     @classmethod
@@ -1180,20 +1198,17 @@ class TestSnapshotUsage(cloudstackTestCase):
         # 3. Delete the account
 
         # Get the Root disk of VM
-        volumes = list_volumes(
-                            self.apiclient,
-                            virtualmachineid=self.virtual_machine.id,
-                            type='ROOT',
-                            listall=True
-                            )
+        volumes = Volume.list(
+                    self.apiclient,
+                    virtualmachineid=self.virtual_machine.id,
+                    type='ROOT',
+                    listall=True)
         self.assertEqual(
                          isinstance(volumes, list),
                          True,
                          "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_volumes.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_volumes.py b/test/integration/component/test_volumes.py
index a310472..b5b08e2 100644
--- a/test/integration/component/test_volumes.py
+++ b/test/integration/component/test_volumes.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,11 +18,24 @@
 """
 #Import Local Modules
 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 (listHypervisorCapabilities,
+                                  attachIso,
+                                  deleteVolume)
+from marvin.lib.utils import cleanup_resources
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             VirtualMachine,
+                             Volume,
+                             Host,
+                             Iso,
+                             Configurations,
+                             DiskOffering,
+                             Domain)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               get_pod)
 #Import System modules
 import time
 
@@ -186,9 +199,9 @@ class TestAttachVolume(cloudstackTestCase):
         # 5. Start The VM. Start VM should be successful
 
         # Create 5 volumes and attach to VM
-        for i in range(self.max_data_volumes):
-            self.debug(i)
-            volume = Volume.create(
+        try:
+            for i in range(self.max_data_volumes):
+                volume = Volume.create(
                                    self.apiclient,
                                    self.services["volume"],
                                    zoneid=self.zone.id,
@@ -196,134 +209,99 @@ class TestAttachVolume(cloudstackTestCase):
                                    domainid=self.account.domainid,
                                    diskofferingid=self.disk_offering.id
                                    )
-            self.debug("Created volume: %s for account: %s" % (
-                                                volume.id,
-                                                self.account.name
-                                                ))
-            # Check List Volume response for newly created volume
-            list_volume_response = list_volumes(
+                # Check List Volume response for newly created volume
+                list_volume_response = Volume.list(
                                                 self.apiclient,
                                                 id=volume.id
                                                 )
-            self.assertNotEqual(
+                self.assertNotEqual(
                                 list_volume_response,
                                 None,
                                 "Check if volume exists in ListVolumes"
                                 )
-            # Attach volume to VM
-            self.virtual_machine.attach_volume(
+                # Attach volume to VM
+                self.virtual_machine.attach_volume(
                                                 self.apiclient,
                                                 volume
                                                 )
-            self.debug("Attach volume: %s to VM: %s" % (
-                                                volume.id,
-                                                self.virtual_machine.id
-                                                ))
-        # Check all volumes attached to same VM
-        list_volume_response = list_volumes(
+            # Check all volumes attached to same VM
+            list_volume_response = Volume.list(
                                     self.apiclient,
                                     virtualmachineid=self.virtual_machine.id,
                                     type='DATADISK',
                                     listall=True
                                     )
-        self.assertNotEqual(
-            list_volume_response,
-            None,
-            "Check if volume exists in ListVolumes"
-        )
-        self.assertEqual(
-            isinstance(list_volume_response, list),
-            True,
-            "Check list volumes response for valid list"
-        )
-        self.assertEqual(
-            len(list_volume_response),
-            self.max_data_volumes,
-            "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes)
-        )
-        self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
-        # Reboot VM
-        self.virtual_machine.reboot(self.apiclient)
-
-        vm_response = list_virtual_machines(
+            self.assertNotEqual(
+                list_volume_response,
+                None,
+                "Check if volume exists in ListVolumes")
+            self.assertEqual(
+                isinstance(list_volume_response, list),
+                True,
+                "Check list volumes response for valid list")
+            self.assertEqual(
+                len(list_volume_response),
+                self.max_data_volumes,
+                "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes))
+            self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
+            # Reboot VM
+            self.virtual_machine.reboot(self.apiclient)
+
+            vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=self.virtual_machine.id,
                                         )
-        #Verify VM response to check whether VM deployment was successful
-        self.assertNotEqual(
+            #Verify VM response to check whether VM deployment was successful
+            self.assertNotEqual(
                             len(vm_response),
                             0,
                             "Check VMs available in List VMs response"
                         )
-        self.assertEqual(
+            self.assertEqual(
                                 isinstance(vm_response, list),
                                 True,
                                 "Check list VM response for valid list"
                         )
-        vm = vm_response[0]
-        self.assertEqual(
+            vm = vm_response[0]
+            self.assertEqual(
                             vm.state,
                             'Running',
                             "Check the state of VM"
                         )
 
-        self.debug("Stopping the VM: %s" % self.virtual_machine.id)
-        # Stop VM
-        self.virtual_machine.stop(self.apiclient)
+            # Stop VM
+            self.virtual_machine.stop(self.apiclient)
 
-        vm_response = list_virtual_machines(
-                                        self.apiclient,
-                                        id=self.virtual_machine.id,
-                                        )
-        self.assertEqual(
-                                isinstance(vm_response, list),
-                                True,
-                                "Check list VM response for valid list"
-                        )
+            # Start VM
+            self.virtual_machine.start(self.apiclient)
+            # Sleep to ensure that VM is in ready state
+            time.sleep(self.services["sleep"])
 
-        #Verify VM response to check whether VM deployment was successful
-        self.assertNotEqual(
-                            len(vm_response),
-                            0,
-                            "Check VMs available in List VMs response"
-                        )
-
-        vm = vm_response[0]
-        self.assertEqual(
-                            vm.state,
-                            'Stopped',
-                            "Check the state of VM"
-                        )
-
-        self.debug("Starting the VM: %s" % self.virtual_machine.id)
-        # Start VM
-        self.virtual_machine.start(self.apiclient)
-        # Sleep to ensure that VM is in ready state
-        time.sleep(self.services["sleep"])
-
-        vm_response = list_virtual_machines(
+            vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=self.virtual_machine.id,
                                         )
-        self.assertEqual(
+            self.assertEqual(
                                 isinstance(vm_response, list),
                                 True,
                                 "Check list VM response for valid list"
                         )
 
-        #Verify VM response to check whether VM deployment was successful
-        self.assertNotEqual(
+            #Verify VM response to check whether VM deployment was successful
+            self.assertNotEqual(
                             len(vm_response),
                             0,
                             "Check VMs available in List VMs response"
                         )
 
-        vm = vm_response[0]
-        self.assertEqual(
+            vm = vm_response[0]
+            self.assertEqual(
                             vm.state,
                             'Running',
                             "Check the state of VM"
                         )
+        except Exception as e:
+            self.fail("Exception occured: %s" % e)
         return
 
     @attr(tags = ["advanced", "advancedns"])
@@ -349,7 +327,7 @@ class TestAttachVolume(cloudstackTestCase):
                                                 self.account.name
                                                 ))
         # Check List Volume response for newly created volume
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiclient,
                                             id=volume.id
                                             )
@@ -476,10 +454,11 @@ class TestAttachDetachVolume(cloudstackTestCase):
         # 5. Stop the VM. Stop VM should be successful
         # 6. Start The VM. Start VM should be successful
 
-        volumes = []
-        # Create 5 volumes and attach to VM
-        for i in range(self.max_data_volumes):
-            volume = Volume.create(
+        try:
+            volumes = []
+            # Create 5 volumes and attach to VM
+            for i in range(self.max_data_volumes):
+                volume = Volume.create(
                                    self.apiclient,
                                    self.services["volume"],
                                    zoneid=self.zone.id,
@@ -487,155 +466,117 @@ class TestAttachDetachVolume(cloudstackTestCase):
                                    domainid=self.account.domainid,
                                    diskofferingid=self.disk_offering.id
                                    )
-            self.debug("Created volume: %s for account: %s" % (
-                                                volume.id,
-                                                self.account.name
-                                                ))
-            self.cleanup.append(volume)
-            volumes.append(volume)
+                self.cleanup.append(volume)
+                volumes.append(volume)
 
-            # Check List Volume response for newly created volume
-            list_volume_response = list_volumes(
+                # Check List Volume response for newly created volume
+                list_volume_response = Volume.list(
                                                 self.apiclient,
                                                 id=volume.id
                                                 )
-            self.assertNotEqual(
-                list_volume_response,
-                None,
-                "Check if volume exists in ListVolumes"
-            )
-            self.assertEqual(
-                isinstance(list_volume_response, list),
-                True,
-                "Check list volumes response for valid list"
-            )
-            self.debug("Attach volume: %s to VM: %s" % (
-                                                volume.id,
-                                                self.virtual_machine.id
-                                                ))
-            # Attach volume to VM
-            self.virtual_machine.attach_volume(
+                self.assertNotEqual(
+                    list_volume_response,
+                    None,
+                    "Check if volume exists in ListVolumes")
+                self.assertEqual(
+                    isinstance(list_volume_response, list),
+                    True,
+                    "Check list volumes response for valid list")
+                # Attach volume to VM
+                self.virtual_machine.attach_volume(
                                                 self.apiclient,
                                                 volume
                                                 )
 
-        # Check all volumes attached to same VM
-        list_volume_response = list_volumes(
+            # Check all volumes attached to same VM
+            list_volume_response = Volume.list(
                                     self.apiclient,
                                     virtualmachineid=self.virtual_machine.id,
                                     type='DATADISK',
                                     listall=True
                                     )
-        self.assertNotEqual(
+            self.assertNotEqual(
                                 list_volume_response,
                                 None,
                                 "Check if volume exists in ListVolumes"
                                 )
-        self.assertEqual(
+            self.assertEqual(
                                 isinstance(list_volume_response, list),
                                 True,
                                 "Check list volumes response for valid list"
                         )
-        self.assertEqual(
-            len(list_volume_response),
-            self.max_data_volumes,
-            "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes)
-        )
+            self.assertEqual(
+                len(list_volume_response),
+                self.max_data_volumes,
+                "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes)
+            )
 
-        # Detach all volumes from VM
-        for volume in volumes:
-            self.debug("Detach volume: %s to VM: %s" % (
-                                                volume.id,
-                                                self.virtual_machine.id
-                                                ))
-            self.virtual_machine.detach_volume(
+            # Detach all volumes from VM
+            for volume in volumes:
+                self.virtual_machine.detach_volume(
                                                 self.apiclient,
                                                 volume
                                             )
-        # Reboot VM
-        self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
-        self.virtual_machine.reboot(self.apiclient)
-        # Sleep to ensure that VM is in ready state
-        time.sleep(self.services["sleep"])
+            # Reboot VM
+            self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
+            self.virtual_machine.reboot(self.apiclient)
+            # Sleep to ensure that VM is in ready state
+            time.sleep(self.services["sleep"])
 
-        vm_response = list_virtual_machines(
+            vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=self.virtual_machine.id,
                                         )
-        #Verify VM response to check whether VM deployment was successful
-        self.assertEqual(
+            #Verify VM response to check whether VM deployment was successful
+            self.assertEqual(
                                 isinstance(vm_response, list),
                                 True,
                                 "Check list VM response for valid list"
                         )
 
-        self.assertNotEqual(
+            self.assertNotEqual(
                             len(vm_response),
                             0,
                             "Check VMs available in List VMs response"
                         )
-        vm = vm_response[0]
-        self.assertEqual(
+            vm = vm_response[0]
+            self.assertEqual(
                             vm.state,
                             'Running',
                             "Check the state of VM"
                         )
 
-        # Stop VM
-        self.debug("Stopping the VM: %s" % self.virtual_machine.id)
-        self.virtual_machine.stop(self.apiclient)
-        # Sleep to ensure that VM is in ready state
-        time.sleep(self.services["sleep"])
-
-        vm_response = list_virtual_machines(
-                                        self.apiclient,
-                                        id=self.virtual_machine.id,
-                                        )
-        #Verify VM response to check whether VM deployment was successful
-        self.assertEqual(
-                                isinstance(vm_response, list),
-                                True,
-                                "Check list VM response for valid list"
-                        )
-        self.assertNotEqual(
-                            len(vm_response),
-                            0,
-                            "Check VMs available in List VMs response"
-                        )
-        vm = vm_response[0]
-        self.assertEqual(
-                            vm.state,
-                            'Stopped',
-                            "Check the state of VM"
-                        )
+            # Stop VM
+            self.virtual_machine.stop(self.apiclient)
 
-        # Start VM
-        self.debug("Starting the VM: %s" % self.virtual_machine.id)
-        self.virtual_machine.start(self.apiclient)
-        # Sleep to ensure that VM is in ready state
-        time.sleep(self.services["sleep"])
+            # Start VM
+            self.virtual_machine.start(self.apiclient)
+            # Sleep to ensure that VM is in ready state
+            time.sleep(self.services["sleep"])
 
-        vm_response = list_virtual_machines(
+            vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=self.virtual_machine.id,
                                         )
-        #Verify VM response to check whether VM deployment was successful
-        self.assertEqual(
+            #Verify VM response to check whether VM deployment was successful
+            self.assertEqual(
                                 isinstance(vm_response, list),
                                 True,
                                 "Check list VM response for valid list"
                         )
-        self.assertNotEqual(
+            self.assertNotEqual(
                             len(vm_response),
                             0,
                             "Check VMs available in List VMs response"
                         )
-        vm = vm_response[0]
-        self.assertEqual(
+            vm = vm_response[0]
+            self.assertEqual(
                             vm.state,
                             'Running',
                             "Check the state of VM"
                         )
+        except Exception as e:
+            self.fail("Exception occuered: %s" % e)
         return
 
 
@@ -754,7 +695,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
                                                 self.account.name
                                                 ))
             # Check List Volume response for newly created volume
-            list_volume_response = list_volumes(
+            list_volume_response = Volume.list(
                                                 self.apiclient,
                                                 id=volume.id
                                                 )
@@ -775,7 +716,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
                                                 )
 
         # Check all volumes attached to same VM
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                     self.apiclient,
                                     virtualmachineid=self.virtual_machine.id,
                                     type='DATADISK',
@@ -826,7 +767,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
         self.apiclient.attachIso(cmd)
 
         # Verify ISO is attached to VM
-        vm_response = list_virtual_machines(
+        vm_response = VirtualMachine.list(
                                         self.apiclient,
                                         id=self.virtual_machine.id,
                                         )
@@ -941,7 +882,7 @@ class TestVolumes(cloudstackTestCase):
         #    response before volume attach (to VM)
 
         # Check the list volumes response for vmname and virtualmachineid
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                                 self.apiclient,
                                                 id=self.volume.id
                                                 )
@@ -982,7 +923,7 @@ class TestVolumes(cloudstackTestCase):
         self.virtual_machine.attach_volume(self.apiclient, self.volume)
 
         # Check all volumes attached to same VM
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                     self.apiclient,
                                     virtualmachineid=self.virtual_machine.id,
                                     type='DATADISK',
@@ -1030,7 +971,7 @@ class TestVolumes(cloudstackTestCase):
         #Sleep to ensure the current state will reflected in other calls
         time.sleep(self.services["sleep"])
 
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiclient,
                                             id=self.volume.id
                                             )
@@ -1074,7 +1015,7 @@ class TestVolumes(cloudstackTestCase):
         #Sleep to ensure the current state will reflected in other calls
         time.sleep(self.services["sleep"])
 
-        list_volume_response = list_volumes(
+        list_volume_response = Volume.list(
                                             self.apiclient,
                                             id=self.volume.id,
                                             )

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_vpc_network.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_network.py b/test/integration/component/test_vpc_network.py
index 2924b72..a449948 100644
--- a/test/integration/component/test_vpc_network.py
+++ b/test/integration/component/test_vpc_network.py
@@ -1933,8 +1933,6 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
         except Exception as e:
             self.fail("Failed to stop VMs, %s" % e)
 
-        wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
-
         # When all Vms ain network are stopped, network state changes from Implemented --> Shutdown --> Allocated
         # We can't update the network when it is in Shutodown state, hence we should wait for the state to change to
         # Allocated and then update the network
@@ -2108,8 +2106,6 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
         except Exception as e:
             self.fail("Failed to stop VMs, %s" % e)
 
-        wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
-
         self.debug("Upgrading network offering to support PF services")
         with self.assertRaises(Exception):
             network_1.update(

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/component/test_vpc_vm_life_cycle.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_vm_life_cycle.py b/test/integration/component/test_vpc_vm_life_cycle.py
index 95f46d0..fd995cd 100644
--- a/test/integration/component/test_vpc_vm_life_cycle.py
+++ b/test/integration/component/test_vpc_vm_life_cycle.py
@@ -19,7 +19,7 @@
 """
 #Import Local Modules
 from nose.plugins.attrib import attr
-from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.cloudstackTestCase import cloudstackTestCase
 from marvin.lib.utils import cleanup_resources, validateList
 from marvin.lib.base import (VirtualMachine,
                                          NATRule,
@@ -1256,24 +1256,6 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
         except Exception as e:
             self.fail("Failed to stop the virtual instances, %s" % e)
 
-        self.debug("Check if the instance is in stopped state?")
-        vms = VirtualMachine.list(
-                                  self.apiclient,
-                                  id=self.vm_2.id,
-                                  listall=True
-                                  )
-        self.assertEqual(
-                         isinstance(vms, list),
-                         True,
-                         "List virtual machines should return a valid list"
-                         )
-        vm = vms[0]
-        self.assertEqual(
-                         vm.state,
-                         "Stopped",
-                         "Virtual machine should be in stopped state"
-                         )
-
         self.debug("Validating if network rules are coonfigured properly?")
         self.validate_network_rules()
         return
@@ -3099,35 +3081,7 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
                                                 self.account.name)
         try:
             self.vm_1.stop(self.apiclient)
-
-            list_vm_response = list_virtual_machines(
-                                                 self.apiclient,
-                                                 id=self.vm_1.id
-                                                 )
-
-            vm_response = list_vm_response[0]
-
-            self.assertEqual(
-                    vm_response.state,
-                    'Stopped',
-                    "VM state should be stopped"
-                    )
-
             self.vm_2.stop(self.apiclient)
-
-            list_vm_response = list_virtual_machines(
-                                                 self.apiclient,
-                                                 id=self.vm_2.id
-                                                 )
-
-            vm_response = list_vm_response[0]
-
-            self.assertEqual(
-                    vm_response.state,
-                    'Stopped',
-                    "VM state should be stopped"
-                    )
-
         except Exception as e:
             self.fail("Failed to stop the virtual instances, %s" % e)
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/247c7966/test/integration/smoke/test_service_offerings.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py
index 3c91859..980e110 100644
--- a/test/integration/smoke/test_service_offerings.py
+++ b/test/integration/smoke/test_service_offerings.py
@@ -85,7 +85,6 @@ class TestCreateServiceOffering(cloudstackTestCase):
             0,
             "Check Service offering is created"
         )
-        service_response = list_service_response[0]
 
         self.assertEqual(
             list_service_response[0].cpunumber,
@@ -293,23 +292,10 @@ class TestServiceOfferings(cloudstackTestCase):
         # 2. Using  listVM command verify that this Vm
         #    has Small service offering Id.
 
-        self.debug("Stopping VM - ID: %s" % self.medium_virtual_machine.id)
-        self.medium_virtual_machine.stop(self.apiclient)
-        # Ensure that VM is in stopped state
-        list_vm_response = list_virtual_machines(
-            self.apiclient,
-            id=self.medium_virtual_machine.id
-        )
-        if isinstance(list_vm_response, list):
-            vm = list_vm_response[0]
-            if vm.state == 'Stopped':
-                self.debug("VM state: %s" % vm.state)
-            else:
-                raise Exception(
-                    "Failed to stop VM (ID: %s) in change service offering" % vm.id)
-
-        self.debug("Change Service offering VM - ID: %s" %
-                   self.medium_virtual_machine.id)
+        try:
+            self.medium_virtual_machine.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
 
         cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd()
         cmd.id = self.medium_virtual_machine.id