cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject [1/4] CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary
Date Wed, 07 May 2014 13:30:45 GMT
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'


Mime
View raw message