cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject [2/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary
Date Wed, 07 May 2014 14:52:26 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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/ff1c4bee/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


Mime
View raw message