diff --git a/tools/testClient/testcase/BVT-tests/base.py b/tools/testClient/testcase/BVT-tests/base.py index 04b934d91e1..97a05ca3c5a 100644 --- a/tools/testClient/testcase/BVT-tests/base.py +++ b/tools/testClient/testcase/BVT-tests/base.py @@ -3,13 +3,15 @@ # Copyright (c) 2012 Citrix. All rights reserved. # -""" Base class for all Cloudstack resources - Virtual machine, Volume, Snapshot etc +""" Base class for all Cloudstack resources + -Virtual machine, Volume, Snapshot etc """ from utils import is_server_ssh_ready, random_gen from cloudstackAPI import * #Import System modules import time +import hashlib class Account: """ Account Life Cycle """ @@ -17,14 +19,18 @@ class Account: self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, admin=False): + def create(cls, apiclient, services, admin = False): cmd = createAccount.createAccountCmd() #0 - User, 1 - Root Admin cmd.accounttype = int(admin) cmd.email = services["email"] cmd.firstname = services["firstname"] cmd.lastname = services["lastname"] - cmd.password = services["password"] + + # Password Encoding + mdf = hashlib.md5() + mdf.update(services["password"]) + cmd.password = mdf.hexdigest() cmd.username = services["username"] account = apiclient.createAccount(cmd) @@ -35,6 +41,7 @@ class Account: cmd.id = self.account.id apiclient.deleteAccount(cmd) + class VirtualMachine: """Manage virtual machine lifecycle """ @@ -48,7 +55,7 @@ class VirtualMachine: self.ipaddress = self.nic[0].ipaddress @classmethod - def create(cls, apiclient, services, templateid=None, accountid=None, networkids = None): + def create(cls, apiclient, services, templateid = None, accountid = None, networkids = None): cmd = deployVirtualMachine.deployVirtualMachineCmd() cmd.serviceofferingid = services["serviceoffering"] cmd.zoneid = services["zoneid"] @@ -56,10 +63,19 @@ class VirtualMachine: cmd.account = accountid or services["account"] cmd.domainid = services["domainid"] + # List Networks for that user + command = listNetworks.listNetworksCmd() + command.zoneid = services["zoneid"] + command.account = accountid or services["account"] + command.domainid = services["domainid"] + network = apiclient.listNetworks(command) + if networkids: cmd.networkids = networkids elif "networkids" in services: cmd.networkids = services["networkids"] + elif network: #If user already has source NAT created, then use that + cmd.networkids = network[0].id if templateid: cmd.templateid = templateid @@ -70,7 +86,7 @@ class VirtualMachine: cmd.diskofferingid = services["diskoffering"] return VirtualMachine(apiclient.deployVirtualMachine(cmd).__dict__, services) - def get_ssh_client(self, ipaddress = None, reconnect=False): + def get_ssh_client(self, ipaddress = None, reconnect = False): if ipaddress != None: self.ipaddress = ipaddress if reconnect: @@ -88,22 +104,6 @@ class VirtualMachine: ) return self.ssh_client - def create_nat_rule(self, apiclient, services): - cmd = createPortForwardingRule.createPortForwardingRuleCmd() - cmd.ipaddressid = services["ipaddressid"] - cmd.privateport = services["privateport"] - cmd.publicport = services["publicport"] - cmd.protocol = services["protocol"] - cmd.virtualmachineid = self.id - return apiclient.createPortForwardingRule(cmd) - - - def delete_nat_rule(self, apiclient, nat_rule): - cmd = deletePortForwardingRule.deletePortForwardingRuleCmd() - cmd.id = nat_rule.id - apiclient.deletePortForwardingRule(cmd) - return - def delete(self, apiclient): cmd = destroyVirtualMachine.destroyVirtualMachineCmd() cmd.id = self.id @@ -134,7 +134,7 @@ class Volume: cmd.diskofferingid = services["volumeoffering"] cmd.zoneid = services["zoneid"] cmd.account = services["account"] - cmd.domainid= services["domainid"] + cmd.domainid = services["domainid"] return Volume(apiclient.createVolume(cmd).__dict__) @classmethod @@ -145,10 +145,9 @@ class Volume: cmd.size = services["customdisksize"] cmd.zoneid = services["zoneid"] cmd.account = services["account"] - cmd.domainid= services["domainid"] + cmd.domainid = services["domainid"] return Volume(apiclient.createVolume(cmd).__dict__) - @classmethod def create_from_snapshot(cls, apiclient, snapshot_id, services): cmd = createVolume.createVolumeCmd() @@ -165,6 +164,7 @@ class Volume: cmd.id = self.id apiclient.deleteVolume(cmd) + class Snapshot: """Manage Snapshot Lifecycle """ @@ -182,6 +182,7 @@ class Snapshot: cmd.id = self.id apiclient.deleteSnapshot(cmd) + class Template: """Manage template life cycle""" @@ -190,7 +191,6 @@ class Template: @classmethod def create(cls, apiclient, volume, services): - #Create template from Virtual machine and Volume ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] @@ -217,7 +217,6 @@ class Template: @classmethod def create_from_snapshot(cls, apiclient, snapshot, services): - #Create template from Virtual machine and Snapshot ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] @@ -240,7 +239,6 @@ class Iso: @classmethod def create(cls, apiclient, services): - #Create ISO from URL cmd = registerIso.registerIsoCmd() cmd.displaytext = services["displaytext"] @@ -248,13 +246,16 @@ class Iso: cmd.ostypeid = services["ostypeid"] cmd.url = services["url"] cmd.zoneid = services["zoneid"] - cmd.isextractable = services["isextractable"] - cmd.isfeatured = services["isfeatured"] - cmd.ispublic = services["ispublic"] + if "isextractable" in services: + cmd.isextractable = services["isextractable"] + if "isfeatured" in services: + cmd.isfeatured = services["isfeatured"] + if "ispublic" in services: + cmd.ispublic = services["ispublic"] + return Iso(apiclient.createTemplate(cmd)[0].__dict__) def delete(self, apiclient): - cmd = deleteIso.deleteIsoCmd() cmd.id = self.id apiclient.deleteIso(cmd) @@ -265,7 +266,7 @@ class Iso: while True: time.sleep(120) - cmd= listIsos.listIsosCmd() + cmd = listIsos.listIsosCmd() cmd.id = self.id response = apiclient.listIsos(cmd)[0] # Check whether download is in progress (for Ex: 10% Downloaded) @@ -284,7 +285,7 @@ class PublicIPAddress: self.__dict__.update(items) @classmethod - def create(cls, apiclient, accountid, zoneid = None, domainid = None): + def create(cls, apiclient, accountid, zoneid = None, domainid = None, services = None): cmd = associateIpAddress.associateIpAddressCmd() cmd.account = accountid cmd.zoneid = zoneid or services["zoneid"] @@ -297,6 +298,7 @@ class PublicIPAddress: apiclient.disassociateIpAddress(cmd) return + class NATRule: """Manage NAT rule""" @@ -304,23 +306,31 @@ class NATRule: self.__dict__.update(items) @classmethod - def create(cls, apiclient, virtual_machine, services, ipaddressid=None): + def create(cls, apiclient, virtual_machine, services, ipaddressid = None): cmd = createPortForwardingRule.createPortForwardingRuleCmd() - cmd.ipaddressid = ipaddressid or services["ipaddressid"] + + if ipaddressid: + cmd.ipaddressid = ipaddressid + elif "ipaddressid" in services: + cmd.ipaddressid = services["ipaddressid"] + else: # If IP Address ID is not specified then assign new IP + public_ip = PublicIPAddress.create(apiclient, virtual_machine.account, virtual_machine.zoneid, virtual_machine.domainid, services) + cmd.ipaddressid = public_ip.ipaddress.id + cmd.privateport = services["privateport"] cmd.publicport = services["publicport"] cmd.protocol = services["protocol"] cmd.virtualmachineid = virtual_machine.id return NATRule(apiclient.createPortForwardingRule(cmd).__dict__) - def delete(self, apiclient): cmd = deletePortForwardingRule.deletePortForwardingRuleCmd() cmd.id = self.id apiclient.deletePortForwardingRule(cmd) return + class ServiceOffering: """Manage service offerings cycle""" @@ -332,13 +342,12 @@ class ServiceOffering: cmd = createServiceOffering.createServiceOfferingCmd() cmd.cpunumber = services["cpunumber"] - cmd.cpuspeed = services["cpuspeed"] + cmd.cpuspeed = services["cpuspeed"] cmd.displaytext = services["displaytext"] - cmd.memory = services["memory"] + cmd.memory = services["memory"] cmd.name = services["name"] return ServiceOffering(apiclient.createServiceOffering(cmd).__dict__) - def delete(self, apiclient): cmd = deleteServiceOffering.deleteServiceOfferingCmd() @@ -356,13 +365,12 @@ class DiskOffering: @classmethod def create(cls, apiclient, services): - cmd =createDiskOffering.createDiskOfferingCmd() + cmd = createDiskOffering.createDiskOfferingCmd() cmd.displaytext = services["displaytext"] cmd.name = services["name"] - cmd.disksize=services["disksize"] + cmd.disksize = services["disksize"] return DiskOffering(apiclient.createDiskOffering(cmd).__dict__) - def delete(self, apiclient): cmd = deleteDiskOffering.deleteDiskOfferingCmd() @@ -370,6 +378,7 @@ class DiskOffering: apiclient.deleteDiskOffering(cmd) return + class SnapshotPolicy: """Manage snapshot policies""" @@ -387,7 +396,6 @@ class SnapshotPolicy: cmd.volumeid = volumeid return SnapshotPolicy(apiclient.createSnapshotPolicy(cmd).__dict__) - def delete(self, apiclient): cmd = deleteSnapshotPolicies.deleteSnapshotPoliciesCmd() @@ -395,6 +403,7 @@ class SnapshotPolicy: apiclient.deleteSnapshotPolicies(cmd) return + class LoadBalancerRule: """Manage Load Balancer rule""" @@ -402,7 +411,7 @@ class LoadBalancerRule: self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, ipaddressid, accountid=None): + def create(cls, apiclient, services, ipaddressid, accountid = None): cmd = createLoadBalancerRule.createLoadBalancerRuleCmd() cmd.publicipid = ipaddressid or services["ipaddressid"] cmd.account = accountid or services["account"] @@ -414,7 +423,7 @@ class LoadBalancerRule: def delete(self, apiclient): cmd = deleteLoadBalancerRule.deleteLoadBalancerRuleCmd() - cmd.id = self.id + cmd.id = self.id apiclient.deleteLoadBalancerRule(cmd) return @@ -431,6 +440,7 @@ class LoadBalancerRule: self.apiclient.removeFromLoadBalancerRule(cmd) return + class Cluster: """Manage Cluster life cycle""" @@ -459,10 +469,11 @@ class Cluster: def delete(self, apiclient): cmd = deleteCluster.deleteClusterCmd() - cmd.id = self.id + cmd.id = self.id apiclient.deleteCluster(cmd) return + class Host: """Manage Host life cycle""" @@ -486,7 +497,7 @@ class Host: if "password" in services: cmd.password = services["password"] - return Host(apiclient.addHost(cmd).__dict__) + return Host(apiclient.addHost(cmd)[0].__dict__) def delete(self, apiclient): # Host must be in maintenance mode before deletion @@ -496,10 +507,11 @@ class Host: time.sleep(60) cmd = deleteHost.deleteHostCmd() - cmd.id = self.id + cmd.id = self.id apiclient.deleteHost(cmd) return + class StoragePool: """Manage Storage pools""" @@ -521,10 +533,10 @@ class StoragePool: def delete(self, apiclient): # Storage pool must be in maintenance mode before deletion cmd = enableStorageMaintenance.enableStorageMaintenanceCmd() - cmd.id = self.id + cmd.id = self.id apiclient.enableStorageMaintenance(cmd) time.sleep(60) cmd = deleteStoragePool.deleteStoragePoolCmd() - cmd.id = self.id + cmd.id = self.id apiclient.deleteStoragePool(cmd) return diff --git a/tools/testClient/testcase/BVT-tests/settings.py b/tools/testClient/testcase/BVT-tests/settings.py index 19e2a5c4030..7635348a31b 100644 --- a/tools/testClient/testcase/BVT-tests/settings.py +++ b/tools/testClient/testcase/BVT-tests/settings.py @@ -4,554 +4,3 @@ # """Test Information Services """ - -TEST_VM_LIFE_CYCLE_SERVICES = { - "small" : - { - "template" : 256, - "zoneid" : 1, - "serviceoffering" : 27, - "diskoffering" : 3, - "displayname" : "testserver", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":3, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - }, - "medium" : - { - "template" : 256, - "zoneid" : 1, - "serviceoffering" : 27, - "displayname" : "testserver", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":3, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - }, - "service_offerings" : - { "small" : - { - "id": 40, - "cpunumber" : 1, - "cpuspeed" : 500, - "memory" : 524288 - }, - "medium" : - { - "id" : 39, - "cpunumber" : 1, - "cpuspeed" : 1000, - "memory" : 1048576 - } - }, - "iso": - { - "displaytext" : "Test ISO type", - "name": "testISO", - "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", - "zoneid" : 1, - "isextractable": True, - "isfeatured":True, - "ispublic": True, - "ostypeid":12, - "mode":'HTTP_DOWNLOAD', - "ostypeid":12, - }, - "diskdevice": '/dev/xvdd', - "mount_dir": "/mnt/tmp", - "hostid": 1, - } - -TEST_SNAPSHOT_SERVICES = { - "server_with_disk" : - { - "template" : 256, - "zoneid" : 1, - "serviceoffering" : 27, - "diskoffering" : 3, - "displayname" : "testserver", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":3, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - }, - - "server_without_disk" : - { - "template" : 256, - "zoneid" : 1, - "serviceoffering" : 27, - "displayname" : "testserver", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":3, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - }, - - "recurring_snapshot" : - { - "intervaltype" : 'HOURLY', - "maxsnaps" : 2, - "schedule" : 1, - "timezone" : 'US/Arizona', - }, - - "templates" : - { - "displaytext": 'Test template snapshot', - "name" : 'template_from_snapshot_3', - "ostypeid" : 12, - "templatefilter" : 'self', - }, - "small_instance": - { - "zoneid": 1, - "serviceofferingid": 2, - }, - "diskdevice" : "/dev/xvda", - "offerings" : 1, - "template" : 256, - "zoneid" : 1, - "diskoffering" : 3, - "diskname" : "TestDiskServ", - "size" : 1, #GBs - "account":'admin', - "domainid":1, - "mount_dir": "/mnt/tmp", - "sub_dir":"test", - "sub_lvl_dir1": "test1", - "sub_lvl_dir2": "test2", - "random_data" : "random.data", - - } - -TEST_VOLUME_SERVICES = { - "volume_offerings" : { - 0: { - "offerings" : 1, - "volumeoffering" : 3, - "diskname" : "TestDiskServ", - "zoneid" : 1, - "diskofferingid": 3, - "account":'admin', - "domainid":1, - }, - 1: { - "offerings" : 1, - "volumeoffering" : 4, - "diskname" : "TestDiskServ", - "zoneid" : 1, - "diskofferingid": 3, - }, - 2: { - "offerings" : 1, - "volumeoffering" : 5, - "diskname" : "TestDiskServ", - "zoneid" : 1, - "diskofferingid": 3, - }, - }, - "customdiskofferingid":41, - "customdisksize" : 2, #GBs - "serviceoffering" : 27, - "template" : 256, - "zoneid" : 1, - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "diskname" : "TestDiskServ", - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":3, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - "diskdevice" : "/dev/sda", - } - -TEST_SERVICE_OFFERING = { - "off_1" : - { - "name":"Service Offering 1", - "displaytext" : "Service Offering 1", - "cpunumber":1, - "cpuspeed": 200, - "memory": 200, - }, - - "off_2" : - { - "name":"Service Offering 2", - "displaytext" : "Service Offering 2", - "cpunumber":1, - "cpuspeed": 200, - "memory": 200, - } - } - -TEST_DISK_OFFERING = { - "off_1" : - { - "name":"Disk offering 1", - "displaytext" : "Disk offering 1", - "disksize": 1 - }, - - "off_2" : - { - "name":"Disk offering 2", - "displaytext" : "Disk offering 2", - "disksize": 1 - } - } -TEST_TEMPLATE_SERVICES ={ - "virtual_machine" : - { - "template" : 256, - "zoneid" : 1, - "serviceoffering" : 27, - "displayname" : "testVM", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "networkids":205, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":9, - "privateport":22, - "publicport":22, - "ipaddress":'69.41.185.229', - "protocol":'TCP', - }, - "volume": - { - "offerings" : 1, - "volumeoffering" : 3, - "diskname" : "TestVolumeTemplate", - "zoneid" : 1, - "diskofferingid": 3, - }, - "template_1": - { - "displaytext": "Test Template Type 1", - "name": "testTemplate", - "ostypeid":12, - "isfeatured" : False, - "ispublic" : False, - "isextractable":False, - }, - "template_2": - { - "displaytext": "Test Template Type 2", - "name": "testTemplate", - "ostypeid":12, - "isfeatured" : True, - "ispublic" :True, - "isextractable":True, - "mode": "HTTP_DOWNLOAD", - "zoneid":1, - }, - "templatefilter": 'self', - "destzoneid": 2, - "sourcezoneid": 1, - "isfeatured" : True, - "ispublic" : True, - "isextractable":False, - "bootable":True, - "passwordenabled":True, - "ostypeid":15, - "account":'bhavin333', - "domainid":1, - } - -TEST_ISO_SERVICES = { - "iso_1": - { - "displaytext" : "Test ISO type 1", - "name": "testISOType_1", - "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", - "zoneid" : 1, - "isextractable": True, - "isfeatured":True, - "ispublic": True, - "ostypeid":12, - }, - "iso_2": - { - "displaytext" : "Test ISO type 2", - "name": "testISOType_2", - "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", - "zoneid" : 1, - "isextractable": True, - "isfeatured":True, - "ispublic": True, - "ostypeid":12, - "mode":'HTTP_DOWNLOAD', - "ostypeid":12, - }, - "destzoneid": 2, - "sourcezoneid": 1, - "isfeatured" : True, - "ispublic" : True, - "isextractable":True, - "bootable":True, - "passwordenabled":True, - "ostypeid":15, - "account":'bhavin333', - "domainid":1, - } - -TEST_NETWORK_SERVICES = { - "admin_account" : "admin", - "user_account" : "gaurav_cl4", - "zoneid" : 1, - "domainid" : 1, - "account" : { - "email" : "test@test.com", - "firstname" : "Test", - "lastname" : "User", - "username" : "testuser1", - "password" : "fr3sca", - "zoneid" : 1, - "networkofferingid" : 6, - }, - "server" : - { - "template" : 206, - "zoneid" : 1, - "serviceoffering" : 1, - "diskoffering" : 3, - "displayname" : "testserver", - "username" : "root", - "password" : "password", - "ssh_port" : 22, - "hypervisor":'XenServer', - "account":'admin', - "domainid":1, - "ipaddressid":10, - "privateport":22, - "publicport":22, - "ipaddress":'192.168.100.250', - "protocol":'TCP', - }, - "natrule" : - { - "privateport" : 22, - "publicport" : 22, - "protocol" : "TCP" - }, - "lbrule" : - { - "name" : "SSH", - "alg" : "roundrobin", - "privateport" : 80, - "publicport" : 80, - } - - - } - -TEST_SSVM_SERVICES = { - "ssvm": { - "id": 1, - "zoneid": 1, - "publicport": 22, - "username":'root', - "password" : 'fr3sca', - }, - "cpvm": { - "id": 2, - "zoneid": 1, - "publicport": 22, - "username":'root', - "password" : 'fr3sca', - "mgmtserverIP": '192.168.100.154' - }, - "host": { - "username":'root', - "password" : 'fr3sca', - "publicport": 22, - }, - } - -TEST_HOSTS_SERVICES = { - "clusters":{ - 0 : { - "clustername": "Xen Cluster", - "clustertype":"CloudManaged", - "hypervisor": "XenServer", - "zoneid": 1, - "podid":1, - }, - 1 : { - # TODO - "clustername": "KVM Cluster", - "clustertype":"CloudManaged", - "hypervisor": "KVM", - "zoneid": 1, - "podid":1, - }, - 2 : { - "hypervisor": 'VMware', - "clustertype": 'ExternalManaged', - "zoneid": 1, - "podid": 1, - "username": 'administrator', - "password": 'fr3sca', - "url":'http://192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', - "clustername": '192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', - }, - }, - "hosts" :{ - "xenserver" : { - "zoneid": 1, - "podid": 1, - "clusterid":16, - "hypervisor":'XenServer', - "clustertype": 'ExternalManaged', - "url": 'http://192.168.100.210', - "username" : "administrator", - "password" : "fr3sca", - }, - "kvm" : { - "zoneid": 1, - "podid": 1, - "clusterid":16, - "hypervisor":'KVM', - "clustertype": 'ExternalManaged', - "url": 'http://192.168.100.203', - "username" : "administrator", - "password" : "fr3sca", - }, - "vmware" : { - "zoneid": 1, - "podid": 1, - "clusterid":16, - "hypervisor":'VMware', - "clustertype": 'ExternalManaged', - "url": 'http://192.168.100.203', - "username" : "administrator", - "password" : "fr3sca", - }, - } - } -TEST_PRIMARY_STORAGE_SERVICES = { - - "nfs":{ - 0 : { - "url": "nfs://192.168.100.131/Primary", - #Format: File_System_Type/Location/Path - "name": "Primary XEN", - "podid" : 1, - "clusterid" : 1, #XEN Cluster - "zoneid" : 1, - }, - 1 : { - "url": "nfs://192.168.100.131/export", - "name": "Primary KVM", - "podid" : 2, - "clusterid" : 1, #KVM Cluster - "zoneid" : 1, - }, - 2 : { - "url": "nfs://192.168.100.131/Primary", - "name": "Primary VMWare", - "podid" : 1, - "clusterid" : 33, #VMWare Cluster - "zoneid" : 1, - }, - }, - "iscsi":{ - 0 : { - "url": "iscsi://192.168.100.21/export", - "name": "Primary XEN", - "podid" : 2, - "clusterid" : 1, #XEN Cluster - "zoneid" : 1, - # TODO : lun no., iqn no. - }, - 1 : { - "url": "iscsi://192.168.100.21/export", - "name": "Primary KVM", - "podid" : 2, - "clusterid" : 1, #KVM Cluster - "zoneid" : 1, - # TODO : lun no., iqn no. - }, - }, - } - -TEST_SEC_STORAGE_SERVICES = { - "storage": { - "zoneid":1, - "url": "nfs://192.168.100.131/SecondaryStorage" - #Format: File_System_Type/Location/Path - } - } - -TEST_ROUTER_SERVICES = { - "virtual_machine" : - { - "template" : 206, - "zoneid" : 1, - "serviceoffering" : 1, - "displayname" : "testserver", - "username" : "root", - "password" : "fr3sca", - "ssh_port" : 22, - "hypervisor":'XenServer', - "domainid":1, - "ipaddressid":10, - "privateport":22, - "publicport":22, - "ipaddress":'192.168.100.250', - "protocol":'TCP', - }, - "account" : { - "email" : "test@test.com", - "firstname" : "Test", - "lastname" : "User", - "username" : "testuser1", - "password" : "fr3sca", - "zoneid" : 1, - "networkofferingid" : 6, - }, - "sleep_time": 300, - } \ No newline at end of file diff --git a/tools/testClient/testcase/BVT-tests/test_disk_offerings.py b/tools/testClient/testcase/BVT-tests/test_disk_offerings.py index 4e3ab56d735..d380d61e4ec 100644 --- a/tools/testClient/testcase/BVT-tests/test_disk_offerings.py +++ b/tools/testClient/testcase/BVT-tests/test_disk_offerings.py @@ -8,15 +8,31 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * from utils import * from base import * -services = TEST_DISK_OFFERING +class Services: + """Test Disk offerings Services + """ + + def __init__(self): + self.services = { + "off_1": { + "name": "Disk offering 1", + "displaytext": "Disk offering 1", + "disksize": 1 # in GB + }, + "off_2": { + "name": "Disk offering 2", + "displaytext": "Disk offering 2", + "disksize": 1 # in GB + } + } class TestCreateDiskOffering(cloudstackTestCase): def setUp(self): + self.services = Services().services self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] @@ -29,17 +45,17 @@ class TestCreateDiskOffering(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_create_disk_offering(self): """Test to create disk offering""" # Validate the following: - # 1. createDiskOfferings should return a valid information for newly created offering + # 1. createDiskOfferings should return valid info for new offering # 2. The Cloud Database contains the valid information - disk_offering = DiskOffering.create(self.apiclient, services["off_1"]) + disk_offering = DiskOffering.create(self.apiclient, self.services["off_1"]) self.cleanup.append(disk_offering) cmd = listDiskOfferings.listDiskOfferingsCmd() @@ -55,19 +71,19 @@ class TestCreateDiskOffering(cloudstackTestCase): self.assertEqual( disk_response.displaytext, - services["off_1"]["displaytext"], + self.services["off_1"]["displaytext"], "Check server id in createServiceOffering" ) self.assertEqual( disk_response.name, - services["off_1"]["name"], + self.services["off_1"]["name"], "Check name in createServiceOffering" ) #Verify the database entries for new disk offering qresultset = self.dbclient.execute( "select display_text, id from disk_offering where id = %s;" - %disk_offering.id + % disk_offering.id ) self.assertNotEqual( @@ -80,7 +96,7 @@ class TestCreateDiskOffering(cloudstackTestCase): self.assertEqual( qresult[0], - services["off_1"]["displaytext"], + self.services["off_1"]["displaytext"], "Compare display text with database record" ) self.assertEqual( @@ -106,23 +122,25 @@ class TestDiskOfferings(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @classmethod def setUpClass(cls): + cls.services = Services().services cls.api_client = fetch_api_client() - cls.disk_offering_1 = DiskOffering.create(cls.api_client, services["off_1"]) - cls.disk_offering_2 = DiskOffering.create(cls.api_client, services["off_2"]) + cls.disk_offering_1 = DiskOffering.create(cls.api_client, cls.services["off_1"]) + cls.disk_offering_2 = DiskOffering.create(cls.api_client, cls.services["off_2"]) + cls._cleanup = [cls.disk_offering_1] return @classmethod def tearDownClass(cls): try: cls.api_client = fetch_api_client() - cls.disk_offering_1.delete(cls.api_client) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_02_edit_disk_offering(self): @@ -136,7 +154,7 @@ class TestDiskOfferings(cloudstackTestCase): random_name = random_gen() cmd = updateDiskOffering.updateDiskOfferingCmd() - cmd.id= self.disk_offering_1.id + cmd.id = self.disk_offering_1.id cmd.displaytext = random_displaytext cmd.name = random_name @@ -168,7 +186,7 @@ class TestDiskOfferings(cloudstackTestCase): #Verify database entries for updated disk offerings qresultset = self.dbclient.execute( "select display_text, id from disk_offering where id = %s;" - %self.disk_offering_1.id + % self.disk_offering_1.id ) self.assertNotEqual( @@ -198,7 +216,6 @@ class TestDiskOfferings(cloudstackTestCase): # Validate the following: # 1. deleteDiskOffering should return a valid information for newly created offering - cmd = deleteDiskOffering.deleteDiskOfferingCmd() cmd.id = self.disk_offering_2.id self.apiclient.deleteDiskOffering(cmd) @@ -226,4 +243,3 @@ class TestDiskOfferings(cloudstackTestCase): ) return - diff --git a/tools/testClient/testcase/BVT-tests/test_hosts.py b/tools/testClient/testcase/BVT-tests/test_hosts.py index 2d48c7b03f1..70a4bd19efd 100644 --- a/tools/testClient/testcase/BVT-tests/test_hosts.py +++ b/tools/testClient/testcase/BVT-tests/test_hosts.py @@ -7,14 +7,79 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * from utils import * from base import * #Import System modules import time -services = TEST_HOSTS_SERVICES +class Services: + """Test Hosts & Clusters Services + """ + + def __init__(self): + self.services = { + "clusters": { + 0: { + "clustername": "Xen Cluster", + "clustertype": "ExternalManaged", # CloudManaged or ExternalManaged" + "hypervisor": "XenServer", # Hypervisor type + "zoneid": 3, + "podid": 3, + }, + 1: { + "clustername": "KVM Cluster", + "clustertype": "CloudManaged", # CloudManaged or ExternalManaged" + "hypervisor": "KVM", # Hypervisor type + "zoneid": 3, + "podid": 3, + }, + 2: { + "hypervisor": 'VMware', # Hypervisor type + "clustertype": 'ExternalManaged', # CloudManaged or ExternalManaged" + "zoneid": 3, + "podid": 3, + "username": 'administrator', + "password": 'fr3sca', + "url": 'http://192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', + # Format: http:// vCenter Host / Datacenter / Cluster + "clustername": '192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', + # Format: http:// IP_Address / Datacenter / Cluster + }, + }, + "hosts": { + "xenserver": { #Must be name of corresponding Hypervisor type in cluster in small letters + "zoneid": 3, + "podid": 3, + "clusterid": 16, + "hypervisor": 'XenServer', # Hypervisor type + "clustertype": 'ExternalManaged', # CloudManaged or ExternalManaged" + "url": 'http://192.168.100.210', + "username": "administrator", + "password": "fr3sca", + }, + "kvm": { + "zoneid": 3, + "podid": 3, + "clusterid": 35, + "hypervisor": 'KVM', # Hypervisor type + "clustertype": 'CloudManaged', # CloudManaged or ExternalManaged" + "url": 'http://192.168.100.212', + "username": "root", + "password": "fr3sca", + }, + "vmware": { + "zoneid": 3, + "podid": 3, + "clusterid": 16, + "hypervisor": 'VMware', # Hypervisor type + "clustertype": 'ExternalManaged', # CloudManaged or ExternalManaged" + "url": 'http://192.168.100.203', + "username": "administrator", + "password": "fr3sca", + }, + } + } class TestHosts(cloudstackTestCase): @@ -22,6 +87,7 @@ class TestHosts(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() + self.services = Services().services self.cleanup = [] return @@ -32,7 +98,7 @@ class TestHosts(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_clusters(self): @@ -45,7 +111,7 @@ class TestHosts(cloudstackTestCase): # 3. Verify that the host is added successfully and in Up state with listHosts API response #Create clusters with Hypervisor type XEN/KVM/VWare - for k,v in services["clusters"].items(): + for k, v in self.services["clusters"].items(): cluster = Cluster.create(self.apiclient, v) self.assertEqual( @@ -62,14 +128,14 @@ class TestHosts(cloudstackTestCase): #If host is externally managed host is already added with cluster cmd = listHosts.listHostsCmd() cmd.clusterid = cluster.id - response = apiclient.listHosts(cmd) + response = self.apiclient.listHosts(cmd) - if not len(response): + if not response: hypervisor_type = str(cluster.hypervisortype.lower()) host = Host.create( self.apiclient, cluster, - services["hosts"][hypervisor_type] + self.services["hosts"][hypervisor_type] ) #Cleanup Host & Cluster @@ -113,6 +179,6 @@ class TestHosts(cloudstackTestCase): self.assertEqual( cluster_response.hypervisortype, cluster.hypervisortype, - "Check hypervisor type with list clusters response is " + v["hypervisor"] + " or not" + "Check hypervisor type with list clusters response is " + v["hypervisor"] + " or not" ) - return \ No newline at end of file + return diff --git a/tools/testClient/testcase/BVT-tests/test_iso.py b/tools/testClient/testcase/BVT-tests/test_iso.py index 082f193ef55..0e5890596bc 100644 --- a/tools/testClient/testcase/BVT-tests/test_iso.py +++ b/tools/testClient/testcase/BVT-tests/test_iso.py @@ -7,8 +7,6 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * -import remoteSSHClient from utils import * from base import * import urllib @@ -16,11 +14,55 @@ from random import random #Import System modules import time -services = TEST_ISO_SERVICES +class Services: + """Test ISO Services + """ + + def __init__(self): + self.services = { + "iso_1": + { + "displaytext": "Test ISO type 1", + "name": "testISOType_1", + "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", + # Source URL where ISO is located + "zoneid": 1, + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostypeid": 12, + }, + "iso_2": + { + "displaytext": "Test ISO type 2", + "name": "testISOType_2", + "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", + # Source URL where ISO is located + "zoneid": 1, + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostypeid": 12, + "mode": 'HTTP_DOWNLOAD', + # Used in Extract template, value must be HTTP_DOWNLOAD + "ostypeid": 12, + }, + "destzoneid": 2, # Copy ISO from one zone to another (Destination Zone) + "sourcezoneid": 1, # Copy ISO from one zone to another (Source Zone) + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "bootable": True, # For edit template + "passwordenabled": True, + "ostypeid": 15, + "account": 'bhavin333', # Normal user, no admin rights + "domainid": 1, + } class TestCreateIso(cloudstackTestCase): def setUp(self): + self.services = Services().services self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] @@ -34,7 +76,7 @@ class TestCreateIso(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -47,7 +89,7 @@ class TestCreateIso(cloudstackTestCase): # 2. UI should show the newly added ISO # 3. listIsos API should show the newly added ISO - iso = Iso.create(self.apiclient, services["iso_2"]) + iso = Iso.create(self.apiclient, self.services["iso_2"]) iso.download(self.apiclient) self.cleanup.append(iso) @@ -65,28 +107,28 @@ class TestCreateIso(cloudstackTestCase): self.assertEqual( iso_response.displaytext, - services["iso_2"]["displaytext"], + self.services["iso_2"]["displaytext"], "Check display text of newly created ISO" ) self.assertEqual( iso_response.name, - services["iso_2"]["name"], + self.services["iso_2"]["name"], "Check name of newly created ISO" ) self.assertEqual( iso_response.zoneid, - services["iso_2"]["zoneid"], + self.services["iso_2"]["zoneid"], "Check zone ID of newly created ISO" ) #Verify the database entry for ISO self.debug( "select name, display_text from vm_template where id = %s and format='ISO';" - %iso.id + % iso.id ) qresultset = self.dbclient.execute( "select name, display_text from vm_template where id = %s and format='ISO';" - %iso.id + % iso.id ) self.assertNotEqual( @@ -99,13 +141,13 @@ class TestCreateIso(cloudstackTestCase): self.assertEqual( qresult[0], - services["iso_2"]["name"], + self.services["iso_2"]["name"], "Compare ISO name with database record" ) self.assertEqual( qresult[1], - services["iso_2"]["displaytext"], + self.services["iso_2"]["displaytext"], "Compare ISO display text with database record" ) return @@ -114,10 +156,11 @@ class TestISO(cloudstackTestCase): @classmethod def setUpClass(cls): + cls.services = Services().services cls.api_client = fetch_api_client() - cls.iso_1 = Iso.create(cls.api_client, services["iso_1"]) + cls.iso_1 = Iso.create(cls.api_client, cls.services["iso_1"]) cls.iso_1.download(cls.api_client) - cls.iso_2 = Iso.create(cls.api_client, services["iso_2"]) + cls.iso_2 = Iso.create(cls.api_client, cls.services["iso_2"]) cls.iso_2.download(cls.api_client) return @@ -128,7 +171,7 @@ class TestISO(cloudstackTestCase): cls.iso_2.delete(cls.api_client) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -144,7 +187,7 @@ class TestISO(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -165,9 +208,9 @@ class TestISO(cloudstackTestCase): cmd.id = self.iso_1.id cmd.displaytext = new_displayText cmd.name = new_name - cmd.bootable = services["bootable"] - cmd.passwordenabled = services["passwordenabled"] - cmd.ostypeid = services["ostypeid"] + cmd.bootable = self.services["bootable"] + cmd.passwordenabled = self.services["passwordenabled"] + cmd.ostypeid = self.services["ostypeid"] self.apiclient.updateIso(cmd) @@ -195,24 +238,24 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( iso_response.bootable, - services["bootable"], + self.services["bootable"], "Check if image is bootable of updated ISO" ) self.assertEqual( iso_response.ostypeid, - services["ostypeid"], + self.services["ostypeid"], "Check OSTypeID of updated ISO" ) #Verify database entry for updateIso self.debug( "select name, display_text, bootable, guest_os_id from vm_template where id = %s and format='ISO';" - %self.iso_1.id + % self.iso_1.id ) qresultset = self.dbclient.execute( "select name, display_text, bootable, guest_os_id from vm_template where id = %s and format='ISO';" - %self.iso_1.id + % self.iso_1.id ) self.assertNotEqual( @@ -236,13 +279,13 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( qresult[2], - int(services["bootable"]), + int(self.services["bootable"]), "Compare template enable_password field with database record" ) self.assertEqual( qresult[3], - services["ostypeid"], + self.services["ostypeid"], "Compare template guest OS ID with database record" ) return @@ -267,11 +310,11 @@ class TestISO(cloudstackTestCase): #Verify whether database entry is deleted or not self.debug( "select name, display_text from vm_template where id = %s and format='ISO';" - %self.iso_1.id + % self.iso_1.id ) qresultset = self.dbclient.execute( "select name, display_text from vm_template where id = %s and format='ISO';" - %self.iso_1.id + % self.iso_1.id ) self.assertEqual( @@ -291,8 +334,8 @@ class TestISO(cloudstackTestCase): cmd = extractIso.extractIsoCmd() cmd.id = self.iso_2.id - cmd.mode = services["iso_2"]["mode"] - cmd.zoneid = services["iso_2"]["zoneid"] + cmd.mode = self.services["iso_2"]["mode"] + cmd.zoneid = self.services["iso_2"]["zoneid"] list_extract_response = self.apiclient.extractIso(cmd) #Format URL to ASCII to retrieve response code @@ -307,12 +350,12 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( list_extract_response.extractMode, - services["iso_2"]["mode"], + self.services["iso_2"]["mode"], "Check mode of extraction" ) self.assertEqual( list_extract_response.zoneid, - services["iso_2"]["zoneid"], + self.services["iso_2"]["zoneid"], "Check zone ID of extraction" ) self.assertEqual( @@ -332,16 +375,16 @@ class TestISO(cloudstackTestCase): cmd = updateIsoPermissions.updateIsoPermissionsCmd() cmd.id = self.iso_2.id #Update ISO permissions - cmd.isfeatured = services["isfeatured"] - cmd.ispublic = services["ispublic"] - cmd.isextractable = services["isextractable"] + cmd.isfeatured = self.services["isfeatured"] + cmd.ispublic = self.services["ispublic"] + cmd.isextractable = self.services["isextractable"] self.apiclient.updateIsoPermissions(cmd) #Verify ListIsos have updated permissions for the ISO for normal user cmd = listIsos.listIsosCmd() cmd.id = self.iso_2.id - cmd.account = services["account"] - cmd.domainid = services["domainid"] + cmd.account = self.services["account"] + cmd.domainid = self.services["domainid"] list_iso_response = self.apiclient.listIsos(cmd) iso_response = list_iso_response[0] @@ -353,24 +396,24 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( iso_response.ispublic, - services["ispublic"], + self.services["ispublic"], "Check ispublic permission of ISO" ) self.assertEqual( iso_response.isfeatured, - services["isfeatured"], + self.services["isfeatured"], "Check isfeatured permission of ISO" ) #Verify database entry for updated ISO permissions self.debug( "select public, featured, extractable from vm_template where id = %s and format='ISO';" - %self.iso_2.id + % self.iso_2.id ) qresultset = self.dbclient.execute( "select public, featured, extractable from vm_template where id = %s and format='ISO';" - %self.iso_2.id + % self.iso_2.id ) self.assertNotEqual( @@ -383,18 +426,18 @@ class TestISO(cloudstackTestCase): self.assertEqual( qresult[0], - int(services["ispublic"]), + int(self.services["ispublic"]), "Compare ispublic permission with database record" ) self.assertEqual( qresult[1], - int(services["isfeatured"]), + int(self.services["isfeatured"]), "Compare isfeatured permission with database record" ) self.assertEqual( qresult[2], - int(services["isextractable"]), + int(self.services["isextractable"]), "Compare extractable permission with database record" ) return @@ -407,8 +450,8 @@ class TestISO(cloudstackTestCase): cmd = copyIso.copyIsoCmd() cmd.id = self.iso_2.id - cmd.destzoneid = services["destzoneid"] - cmd.sourcezoneid = services["sourcezoneid"] + cmd.destzoneid = self.services["destzoneid"] + cmd.sourcezoneid = self.services["sourcezoneid"] self.apiclient.copyIso(cmd) #Verify ISO is copied to another zone using ListIsos @@ -430,7 +473,7 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( iso_response.zoneid, - services["destzoneid"], + self.services["destzoneid"], "Check zone ID of the copied ISO" ) return diff --git a/tools/testClient/testcase/BVT-tests/test_network.py b/tools/testClient/testcase/BVT-tests/test_network.py index 57f637d8121..16f18577e70 100644 --- a/tools/testClient/testcase/BVT-tests/test_network.py +++ b/tools/testClient/testcase/BVT-tests/test_network.py @@ -8,19 +8,67 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * import remoteSSHClient from utils import * from base import * #Import System modules import time -services = TEST_NETWORK_SERVICES +class Services: + """Test Network Services + """ + + def __init__(self): + self.services = { + "admin_account": "admin", + "user_account": "testuser", + "zoneid": 1, + "domainid": 1, + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "testuser", + "password": "fr3sca", + "zoneid": 1, + }, + "server": + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "diskoffering": 3, + "displayname": "testserver", + "username": "root", + "password": "fr3sca", + "hypervisor": 'XenServer', + "account": 'testuser', + "domainid": 1, + "ipaddressid": 4, # IP Address ID of Public IP, If not specified new public IP + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "natrule": + { + "privateport": 22, + "publicport": 22, + "protocol": "TCP" + }, + "lbrule": + { + "name": "SSH", + "alg": "roundrobin", # Algorithm used for load balancing + "privateport": 80, + "publicport": 80, + } + } class TestPublicIP(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services def test_public_ip_admin_account(self): """Test for Associate/Disassociate public IP address for admin account""" @@ -31,9 +79,9 @@ class TestPublicIP(cloudstackTestCase): ip_address = PublicIPAddress.create( self.apiclient, - services["admin_account"], - services["zoneid"], - services["domainid"] + self.services["admin_account"], + self.services["zoneid"], + self.services["domainid"] ) cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.id = ip_address.ipaddress.id @@ -78,9 +126,9 @@ class TestPublicIP(cloudstackTestCase): ip_address = PublicIPAddress.create( self.apiclient, - services["user_account"], - services["zoneid"], - services["domainid"] + self.services["user_account"], + self.services["zoneid"], + self.services["domainid"] ) cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.id = ip_address.ipaddress.id @@ -119,12 +167,13 @@ class TestPortForwarding(cloudstackTestCase): def setUpClass(cls): cls.api_client = fetch_api_client() + cls.services = Services().services #Create an account, network, VM and IP addresses - cls.account = Account.create(cls.api_client, services["account"], admin=True) + cls.account = Account.create(cls.api_client, cls.services["account"], admin = True) cls.virtual_machine = VirtualMachine.create( cls.api_client, - services["server"], - accountid=cls.account.account.name, + cls.services["server"], + accountid = cls.account.account.name, ) cls._cleanup = [cls.virtual_machine, cls.account] @@ -152,11 +201,11 @@ class TestPortForwarding(cloudstackTestCase): cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] src_nat_ip_addr = self.apiclient.listPublicIpAddresses(cmd)[0] #Create NAT rule - nat_rule = NATRule.create(self.apiclient, self.virtual_machine, services["natrule"], src_nat_ip_addr.id) + nat_rule = NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule"], src_nat_ip_addr.id) time.sleep(60) cmd = listPortForwardingRules.listPortForwardingRulesCmd() @@ -177,7 +226,7 @@ class TestPortForwarding(cloudstackTestCase): try: self.virtual_machine.get_ssh_client(src_nat_ip_addr.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.virtual_machine.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress, e)) nat_rule.delete(self.apiclient) time.sleep(60) @@ -208,13 +257,18 @@ class TestPortForwarding(cloudstackTestCase): #1. listPortForwardingRules should not return the deleted rule anymore #2. attempt to do ssh should now fail - ip_address = PublicIPAddress.create(self.apiclient, self.account.account.name) + ip_address = PublicIPAddress.create( + self.apiclient, + self.account.account.name, + self.services["zoneid"], + self.services["domainid"] + ) self.clean_up.append(ip_address) #Create NAT rule nat_rule = NATRule.create( self.apiclient, self.virtual_machine, - services["natrule"], + self.services["natrule"], ip_address.ipaddress.id ) time.sleep(60) @@ -241,7 +295,7 @@ class TestPortForwarding(cloudstackTestCase): try: self.virtual_machine.get_ssh_client(public_ip = ip_address.ipaddress.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.virtual_machine.ipaddress.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress.ipaddress, e)) nat_rule.delete(apiclient) time.sleep(60) @@ -266,29 +320,31 @@ class TestPortForwarding(cloudstackTestCase): ) return + class TestLoadBalancingRule(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = fetch_api_client() + cls.services = Services().services #Create an account, network, VM and IP addresses - cls.account = Account.create(cls.api_client, services["account"], admin=True) + cls.account = Account.create(cls.api_client, cls.services["account"], admin = True) cls.vm_1 = VirtualMachine.create( cls.api_client, - services["server"], - accountid=cls.account.account.name, + cls.services["server"], + accountid = cls.account.account.name, ) cls.vm_2 = VirtualMachine.create( cls.api_client, - services["server"], - accountid=cls.account.account.name, + cls.services["server"], + accountid = cls.account.account.name, ) cls.non_src_nat_ip = PublicIPAddress.create( cls.api_client, cls.account.account.name, - services["zoneid"], - services["domainid"] + cls.services["zoneid"], + cls.services["domainid"] ) cls._cleanup = [cls.vm_1, cls.vm_2, cls.non_src_nat_ip, cls.account] @@ -316,13 +372,13 @@ class TestLoadBalancingRule(cloudstackTestCase): cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] src_nat_ip_addr = self.apiclient.listPublicIpAddresses(cmd)[0] #Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( self.apiclient, - services["lbrule"], + self.services["lbrule"], src_nat_ip_addr.id, accountid = self.account.account.name ) @@ -370,7 +426,7 @@ class TestLoadBalancingRule(cloudstackTestCase): ssh_1 = remoteSSHClient.remoteSSHClient( src_nat_ip_addr.ipaddress, - services['lbrule']["publicport"], + self.services['natrule']["publicport"], self.vm_1.username, self.vm_1.password ) @@ -380,7 +436,7 @@ class TestLoadBalancingRule(cloudstackTestCase): time.sleep(20) ssh_2 = remoteSSHClient.remoteSSHClient( src_nat_ip_addr.ipaddress, - services['lbrule']["publicport"], + self.services['natrule']["publicport"], self.vm_1.username, self.vm_1.password ) @@ -411,7 +467,7 @@ class TestLoadBalancingRule(cloudstackTestCase): #Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( self.apiclient, - services["lbrule"], + self.services["lbrule"], self.non_src_nat_ip.ipaddress.id, accountid = self.account.account.name ) @@ -458,7 +514,7 @@ class TestLoadBalancingRule(cloudstackTestCase): ssh_1 = remoteSSHClient.remoteSSHClient( self.non_src_nat_ip.ipaddress.ipaddress, - services['lbrule']["publicport"], + self.services['natrule']["publicport"], self.vm_1.username, self.vm_1.password ) @@ -468,7 +524,7 @@ class TestLoadBalancingRule(cloudstackTestCase): time.sleep(20) ssh_2 = remoteSSHClient.remoteSSHClient( self.non_src_nat_ip.ipaddress.ipaddress, - services['lbrule']["publicport"], + self.services['natrule']["publicport"], self.vm_1.username, self.vm_1.password ) @@ -488,29 +544,30 @@ class TestLoadBalancingRule(cloudstackTestCase): ssh_1.execute("hostname")[0] return + class TestRebootRouter(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services #Create an account, network, VM and IP addresses - self.account = Account.create(self.apiclient, services["account"], admin=True) + self.account = Account.create(self.apiclient, self.services["account"], admin = True) self.vm_1 = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) - src_nat_ip_addr = self.account.public_ip.ipaddress lb_rule = LoadBalancerRule.create( self.apiclient, - services["lbrule"], + self.services["lbrule"], src_nat_ip_addr.id, self.account.account.name ) lb_rule.assign(self.apiclient, [self.vm_1]) - #nat_rule = NATRule.create(self.apiclient, self.vm_1, services["natrule"], src_nat_ip_addr.id) - self.cleanup = [self.vm_1, lb_rule, account] + #nat_rule = NATRule.create(self.apiclient, self.vm_1, self.services["natrule"], src_nat_ip_addr.id) + self.cleanup = [self.vm_1, lb_rule, self.account] return def test_reboot_router(self): @@ -535,53 +592,56 @@ class TestRebootRouter(cloudstackTestCase): cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] src_nat_ip_addr = self.apiclient.listPublicIpAddresses(cmd)[0] #we should be able to SSH after successful reboot try: remoteSSHClient.remoteSSHClient( src_nat_ip_addr.ipaddress, - services["natrule"]["publicport"], + self.services["natrule"]["publicport"], self.vm_1.username, self.vm_1.password ) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.vm_1.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.vm_1.ipaddress, e)) return def tearDown(self): cleanup_resources(self.apiclient, self.cleanup) return + class TestAssignRemoveLB(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services #Create VMs, accounts - self.account = Account.create(self.apiclient, services["account"], admin=True) + self.account = Account.create(self.apiclient, self.services["account"], admin = True) self.vm_1 = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) self.vm_2 = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) self.vm_3 = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) - self.cleanup = [self.vm_1, self.vm_2, self.vm_3] + self.cleanup = [self.vm_1, self.vm_2, self.vm_3, self.account] return + def test_assign_and_removal_elb(self): """Test for assign & removing load balancing rule""" @@ -592,12 +652,12 @@ class TestAssignRemoveLB(cloudstackTestCase): cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] self.non_src_nat_ip = self.apiclient.listPublicIpAddresses(cmd)[0] lb_rule = LoadBalancerRule.create( self.apiclient, - services["lbrule"], + self.services["lbrule"], self.non_src_nat_ip.id, self.account.account.name ) @@ -606,20 +666,20 @@ class TestAssignRemoveLB(cloudstackTestCase): #Create SSH client for each VM ssh_1 = remoteSSHClient.remoteSSHClient( self.non_src_nat_ip.ipaddress, - services["natrule"]["publicport"], + self.services["natrule"]["publicport"], self.vm_1.username, self.vm_1.password ) ssh_2 = remoteSSHClient.remoteSSHClient( self.non_src_nat_ip.ipaddress, - services["natrule"]["publicport"], + self.services["natrule"]["publicport"], self.vm_2.username, self.vm_2.password ) ssh_3 = remoteSSHClient.remoteSSHClient( self.non_src_nat_ip.ipaddress, - services["natrule"]["publicport"], + self.services["natrule"]["publicport"], self.vm_3.username, self.vm_3.password ) @@ -651,38 +711,40 @@ class TestAssignRemoveLB(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) return + class TestReleaseIP(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services #Create an account, network, VM, Port forwarding rule, LB rules and IP addresses - self.account = Account.create(self.apiclient, services["account"], admin=True) + self.account = Account.create(self.apiclient, self.services["account"], admin = True) self.virtual_machine = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) self.ip_address = PublicIPAddress.create( self.apiclient, self.account.account.name, - services["zoneid"], + self.services["zoneid"], self.account.account.domainid ) cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] self.ip_addr = self.apiclient.listPublicIpAddresses(cmd)[0] - self.nat_rule = NATRule.create(self.apiclient, self.virtual_machine, services["natrule"], self.ip_addr.id) - self.lb_rule = LoadBalancerRule.create(self.apiclient, services["lbrule"], self.ip_addr.id, accountid = self.account.account.name) - self.cleanup = [self.virtual_machine, self.account] + self.nat_rule = NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule"], self.ip_addr.id) + self.lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], self.ip_addr.id, accountid = self.account.account.name) + self.cleanup = [self.virtual_machine, self.account] return def teardown(self): - cleanup_resources(self.apiclient,self.cleanup) + cleanup_resources(self.apiclient, self.cleanup) def test_releaseIP(self): """Test for Associate/Disassociate public IP address""" @@ -726,7 +788,7 @@ class TestReleaseIP(cloudstackTestCase): with self.assertRaises(Exception): ssh_2 = remoteSSHClient.remoteSSHClient( self.ip_addr.ipaddress, - services["natrule"]["publicport"], + self.services["natrule"]["publicport"], self.virtual_machine.username, self.virtual_machine.password ) @@ -738,27 +800,28 @@ class TestDeleteAccount(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services #Create an account, network, VM and IP addresses - self.account = Account.create(self.apiclient, services["account"], admin=True) + self.account = Account.create(self.apiclient, self.services["account"], admin = True) self.vm_1 = VirtualMachine.create( self.apiclient, - services["server"], - accountid=self.account.account.name, + self.services["server"], + accountid = self.account.account.name, ) cmd = listPublicIpAddresses.listPublicIpAddressesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] src_nat_ip_addr = self.apiclient.listPublicIpAddresses(cmd)[0] self.lb_rule = LoadBalancerRule.create( self.apiclient, - services["lbrule"], + self.services["lbrule"], src_nat_ip_addr.id, self.account.account.name ) self.lb_rule.assign(self.apiclient, [self.vm_1]) - self.nat_rule = NATRule.create(self.apiclient, self.vm_1, services["natrule"], src_nat_ip_addr.id) + self.nat_rule = NATRule.create(self.apiclient, self.vm_1, self.services["natrule"], src_nat_ip_addr.id) self.cleanup = [] return @@ -776,7 +839,7 @@ class TestDeleteAccount(cloudstackTestCase): # ListLoadBalancerRules should not list associated rules with deleted account cmd = listLoadBalancerRules.listLoadBalancerRulesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] # Unable to find account testuser1 in domain 1 : Exception with self.assertRaises(Exception): self.apiclient.listLoadBalancerRules(cmd) @@ -784,7 +847,7 @@ class TestDeleteAccount(cloudstackTestCase): # ListPortForwardingRules should not list associated rules with deleted account cmd = listPortForwardingRules.listPortForwardingRulesCmd() cmd.account = self.account.account.name - cmd.domainid = services["server"]["domainid"] + cmd.domainid = self.services["server"]["domainid"] with self.assertRaises(Exception): self.apiclient.listPortForwardingRules(cmd) diff --git a/tools/testClient/testcase/BVT-tests/test_primary_storage.py b/tools/testClient/testcase/BVT-tests/test_primary_storage.py index 6dd1bf84ce0..099e40bd60d 100644 --- a/tools/testClient/testcase/BVT-tests/test_primary_storage.py +++ b/tools/testClient/testcase/BVT-tests/test_primary_storage.py @@ -7,21 +7,72 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * -import remoteSSHClient from utils import * from base import * #Import System modules import time -services = TEST_PRIMARY_STORAGE_SERVICES +class Services: + """Test Primary storage Services + """ + + def __init__(self): + self.services = { + "nfs": { + 0: { + "url": "nfs://192.168.100.131/Primary", + # Format: File_System_Type/Location/Path + "name": "Primary XEN", + "podid": 3, + "clusterid": 1, # XEN Cluster + "zoneid": 3, + "hypervisor": 'XEN', + }, + 1: { + "url": "nfs://192.168.100.131/Primary", + "name": "Primary KVM", + "podid": 3, + "clusterid": 40, # KVM Cluster + "zoneid": 3, + "hypervisor": 'KVM', + }, + 2: { + "url": "nfs://192.168.100.131/Primary", + "name": "Primary VMWare", + "podid": 3, + "clusterid": 33, # VMWare Cluster + "zoneid": 3, + "hypervisor": 'VMWare', + }, + }, + "iscsi": { + 0: { + "url": "iscsi://192.168.100.21/iqn.2012-01.localdomain.clo-cstack-cos6:iser/1", + # Format : iscsi : // IP Address/ IQN number/ LUN # + "name": "Primary iSCSI", + "podid": 1, + "clusterid": 1, # XEN Cluster + "zoneid": 1, + "hypervisor": 'XEN', + }, + 1: { + "url": "iscsi://192.168.100.21/export", + "name": "Primary KVM", + "podid": 3, + "clusterid": 1, # KVM Cluster + "zoneid": 3, + "hypervisor": 'KVM', + }, + }, + } class TestPrimaryStorageServices(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.services = Services().services self.cleanup = [] return @@ -31,7 +82,7 @@ class TestPrimaryStorageServices(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_primary_storage(self): @@ -44,7 +95,7 @@ class TestPrimaryStorageServices(cloudstackTestCase): # 3. verify that the host is added successfully and in Up state with listHosts api response #Create NFS storage pools with on XEN/KVM/VMWare clusters - for k,v in services["nfs"].items(): + for k, v in self.services["nfs"].items(): #Host should be present before adding primary storage cmd = listHosts.listHostsCmd() @@ -99,7 +150,7 @@ class TestPrimaryStorageServices(cloudstackTestCase): self.cleanup = [] # Create iSCSI storage pools with on XEN/KVM clusters - for k,v in services["iscsi"].items(): + for k, v in self.services["iscsi"].items(): storage = StoragePool.create(self.apiclient, v) self.cleanup.append(storage) @@ -135,4 +186,4 @@ class TestPrimaryStorageServices(cloudstackTestCase): # Call cleanup for reusing primary storage cleanup_resources(self.apiclient, self.cleanup) self.cleanup = [] - return \ No newline at end of file + return diff --git a/tools/testClient/testcase/BVT-tests/test_routers.py b/tools/testClient/testcase/BVT-tests/test_routers.py index 36730db7297..7a978209fc9 100644 --- a/tools/testClient/testcase/BVT-tests/test_routers.py +++ b/tools/testClient/testcase/BVT-tests/test_routers.py @@ -7,7 +7,6 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * import remoteSSHClient from utils import * from base import * @@ -15,7 +14,38 @@ from base import * #Import System modules import time -services = TEST_ROUTER_SERVICES +class Services: + """Test router Services + """ + + def __init__(self): + self.services = { + "virtual_machine": + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "displayname": "testserver", + "username": "root", + "password": "fr3sca", + "ssh_port": 22, + "hypervisor": 'XenServer', + "domainid": 1, + "ipaddressid": 4, # IP Address ID of Public IP, If not specified new public IP + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "testuser", + "password": "fr3sca", + "zoneid": 1, + }, + "sleep_time": 300, + } class TestRouterServices(cloudstackTestCase): @@ -24,12 +54,13 @@ class TestRouterServices(cloudstackTestCase): cls.api_client = fetch_api_client() + cls.services = Services().services #Create an account, network, VM and IP addresses - cls.account = Account.create(cls.api_client, services["account"]) + cls.account = Account.create(cls.api_client, cls.services["account"]) cls.vm_1 = VirtualMachine.create( cls.api_client, - services["virtual_machine"], - accountid=cls.account.account.name, + cls.services["virtual_machine"], + accountid = cls.account.account.name, ) cls.cleanup = [cls.vm_1, cls.account] @@ -43,7 +74,7 @@ class TestRouterServices(cloudstackTestCase): cleanup_resources(cls.api_client, cls.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def setUp(self): @@ -67,35 +98,35 @@ class TestRouterServices(cloudstackTestCase): 0, "Check list router response" ) - for i in range(len(list_router_response)): + for router in list_router_response: self.assertEqual( - list_router_response[i].state, + router.state, 'Running', "Check list router response for router state" ) cmd = listZones.listZonesCmd() - cmd.zoneid = list_router_response[i].zoneid + cmd.zoneid = router.zoneid zone = self.apiclient.listZones(cmd)[0] self.assertEqual( - list_router_response[i].dns1, + router.dns1, zone.dns1, "Compare DNS1 of router and zone" ) self.assertEqual( - list_router_response[i].dns2, + router.dns2, zone.dns2, "Compare DNS2 of router and zone" ) self.assertEqual( - hasattr(list_router_response[i],'guestipaddress'), + hasattr(router, 'guestipaddress'), True, "Check whether router has guest IP field" ) self.assertEqual( - hasattr(list_router_response[i],'linklocalip'), + hasattr(router, 'linklocalip'), True, "Check whether router has link local IP field" ) @@ -112,7 +143,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] list_router_response = self.apiclient.listRouters(cmd) self.assertNotEqual( @@ -120,46 +151,46 @@ class TestRouterServices(cloudstackTestCase): 0, "Check list router response" ) - for i in range(len(list_router_response)): + for router in list_router_response: self.assertEqual( - list_router_response[i].state, + router.state, 'Running', "Check list router response for router state" ) cmd = listZones.listZonesCmd() - cmd.zoneid = list_router_response[i].zoneid + cmd.zoneid = router.zoneid zone = self.apiclient.listZones(cmd)[0] self.assertEqual( - list_router_response[i].dns1, + router.dns1, zone.dns1, "Compare DNS1 of router and zone" ) self.assertEqual( - list_router_response[i].dns2, + router.dns2, zone.dns2, "Compare DNS2 of router and zone" ) self.assertEqual( - hasattr(list_router_response[i],'guestipaddress'), + hasattr(router, 'guestipaddress'), True, "Check whether router has guest IP field" ) self.assertEqual( - hasattr(list_router_response[i],'linklocalip'), + hasattr(router, 'linklocalip'), True, "Check whether router has link local IP field" ) #Fetch corresponding ip ranges information from listVlanIpRanges cmd = listVlanIpRanges.listVlanIpRangesCmd() - cmd.id = list_ssvm_response[i].zoneid + cmd.id = router.zoneid ipranges_response = self.apiclient.listVlanIpRanges(cmd)[0] self.assertEqual( - list_router_response[i].gateway, + router.gateway, ipranges_response.gateway, "Check gateway with that of corresponding IP range" ) @@ -174,7 +205,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] #Stop the router @@ -205,7 +236,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] #Start the router @@ -236,7 +267,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] public_ip = router.publicip @@ -265,7 +296,7 @@ class TestRouterServices(cloudstackTestCase): ) return - def test_05_network_gc(self): + def test_06_network_gc(self): """Test network GC """ @@ -277,7 +308,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listVirtualMachines.listVirtualMachinesCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] list_vms = self.apiclient.listVirtualMachines(cmd) self.assertNotEqual( @@ -286,10 +317,10 @@ class TestRouterServices(cloudstackTestCase): "Check length of list VM response" ) - for i in range(len(list_vms)): + for vm in list_vms: # Stop all virtual machines associated with that account cmd = stopVirtualMachine.stopVirtualMachineCmd() - cmd.id = list_vms[i].id + cmd.id = vm.id self.apiclient.stopVirtualMachine(cmd) # Wait for network.gc.interval @@ -297,12 +328,12 @@ class TestRouterServices(cloudstackTestCase): cmd.name = 'network.gc.interval' response = self.apiclient.listConfigurations(cmd)[0] - time.sleep(int(response.value)) + time.sleep(int(response.value) * 2) #Check status of network router cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] self.assertEqual( @@ -312,7 +343,7 @@ class TestRouterServices(cloudstackTestCase): ) return - def test_06_router_internal_basic(self): + def test_07_router_internal_basic(self): """Test router internal basic zone """ # Validate the following @@ -322,7 +353,7 @@ class TestRouterServices(cloudstackTestCase): # Find router associated with user account cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] cmd = listHosts.listHostsCmd() @@ -334,9 +365,9 @@ class TestRouterServices(cloudstackTestCase): #SSH to the machine ssh = remoteSSHClient.remoteSSHClient( host.ipaddress, - services['virtual_machine']["publicport"], - services['virtual_machine']["username"], - services['virtual_machine']["password"] + self.services['virtual_machine']["publicport"], + self.services['virtual_machine']["username"], + self.services['virtual_machine']["password"] ) ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -p 3922 %s " % router.linklocalip @@ -359,7 +390,7 @@ class TestRouterServices(cloudstackTestCase): ) return - def test_07_router_internal_adv(self): + def test_08_router_internal_adv(self): """Test router internal advanced zone """ # Validate the following @@ -370,7 +401,7 @@ class TestRouterServices(cloudstackTestCase): # Find router associated with user account cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] cmd = listHosts.listHostsCmd() @@ -382,9 +413,9 @@ class TestRouterServices(cloudstackTestCase): #SSH to the machine ssh = remoteSSHClient.remoteSSHClient( host.ipaddress, - services['virtual_machine']["publicport"], - services['virtual_machine']["username"], - services['virtual_machine']["password"] + self.services['virtual_machine']["publicport"], + self.services['virtual_machine']["username"], + self.services['virtual_machine']["password"] ) ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -p 3922 %s " % router.linklocalip @@ -424,7 +455,7 @@ class TestRouterServices(cloudstackTestCase): ) return - def test_08_restart_network_cleanup(self): + def test_09_restart_network_cleanup(self): """Test restart network """ @@ -435,7 +466,7 @@ class TestRouterServices(cloudstackTestCase): # Find router associated with user account cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] #Store old values before restart @@ -443,7 +474,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listNetworks.listNetworksCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] network = self.apiclient.listNetworks(cmd)[0] cmd = restartNetwork.restartNetworkCmd() @@ -454,7 +485,7 @@ class TestRouterServices(cloudstackTestCase): # Get router details after restart cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] self.assertNotEqual( @@ -464,7 +495,7 @@ class TestRouterServices(cloudstackTestCase): ) return - def test_08_restart_network_wo_cleanup(self): + def test_10_restart_network_wo_cleanup(self): """Test restart network without cleanup """ @@ -474,7 +505,7 @@ class TestRouterServices(cloudstackTestCase): cmd = listNetworks.listNetworksCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] network = self.apiclient.listNetworks(cmd)[0] cmd = restartNetwork.restartNetworkCmd() @@ -485,7 +516,7 @@ class TestRouterServices(cloudstackTestCase): # Get router details after restart cmd = listRouters.listRoutersCmd() cmd.account = self.account.account.name - cmd.domainid = services["virtual_machine"]["domainid"] + cmd.domainid = self.services["virtual_machine"]["domainid"] router = self.apiclient.listRouters(cmd)[0] cmd = listHosts.listHostsCmd() @@ -497,9 +528,9 @@ class TestRouterServices(cloudstackTestCase): #SSH to the machine ssh = remoteSSHClient.remoteSSHClient( host.ipaddress, - services['virtual_machine']["publicport"], - services['virtual_machine']["username"], - services['virtual_machine']["password"] + self.services['virtual_machine']["publicport"], + self.services['virtual_machine']["username"], + self.services['virtual_machine']["password"] ) ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -p 3922 %s uptime" % router.linklocalip @@ -534,4 +565,4 @@ class TestRouterServices(cloudstackTestCase): 'sec,', "Check uptime is in seconds" ) - return \ No newline at end of file + return diff --git a/tools/testClient/testcase/BVT-tests/test_secondary_storage.py b/tools/testClient/testcase/BVT-tests/test_secondary_storage.py index d130487164a..aa158faa380 100644 --- a/tools/testClient/testcase/BVT-tests/test_secondary_storage.py +++ b/tools/testClient/testcase/BVT-tests/test_secondary_storage.py @@ -7,15 +7,47 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * -import remoteSSHClient from utils import * from base import * #Import System modules import time -services = TEST_SEC_STORAGE_SERVICES +class Services: + """Test secondary storage Services + """ + + def __init__(self): + self.services = { + "storage": { + "zoneid": 3, + "podid": 3, + "url": "nfs://192.168.100.131/SecStorage" + # Format: File_System_Type/Location/Path + }, + "hypervisors": { + 0: { + "hypervisor": "XenServer", + "zoneid": 3, + "podid": 3, + "templatefilter": "self", + }, + 1: { + "hypervisor": "KVM", + "zoneid": 3, + "podid": 3, + "templatefilter": "self", + }, + 2: { + "hypervisor": "VMWare", + "zoneid": 3, + "podid": 3, + "templatefilter": "self", + }, + }, + "sleep": 180, + "timeout": 5, + } class TestSecStorageServices(cloudstackTestCase): @@ -23,15 +55,15 @@ class TestSecStorageServices(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.cleanup = [] + self.services = Services().services return def tearDown(self): try: #Clean up, terminate the created templates cleanup_resources(self.apiclient, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_add_sec_storage(self): @@ -43,13 +75,13 @@ class TestSecStorageServices(cloudstackTestCase): # 2. Verify with listHosts and type secondarystorage cmd = addSecondaryStorage.addSecondaryStorageCmd() - cmd.zoneid = services["storage"]["zoneid"] - cmd.url = services["storage"]["url"] + cmd.zoneid = self.services["storage"]["zoneid"] + cmd.url = self.services["storage"]["url"] sec_storage = self.apiclient.addSecondaryStorage(cmd) self.assertEqual( sec_storage.zoneid, - services["storage"]["zoneid"], + self.services["storage"]["zoneid"], "Check zoneid where sec storage is added" ) @@ -88,6 +120,8 @@ class TestSecStorageServices(cloudstackTestCase): cmd = listHosts.listHostsCmd() cmd.type = 'Routing' + cmd.zoneid = self.services["storage"]["zoneid"] + cmd.podid = self.services["storage"]["podid"] list_hosts_response = self.apiclient.listHosts(cmd) # ListHosts has all 'routing' hosts in UP state self.assertNotEqual( @@ -95,11 +129,9 @@ class TestSecStorageServices(cloudstackTestCase): 0, "Check list host response" ) - for i in range(len(list_hosts_response)): - - host_response = list_hosts_response[i] + for host in list_hosts_response: self.assertEqual( - host_response.state, + host.state, 'Up', "Check state of routing hosts is Up or not" ) @@ -107,6 +139,8 @@ class TestSecStorageServices(cloudstackTestCase): # ListStoragePools shows all primary storage pools in UP state cmd = listStoragePools.listStoragePoolsCmd() cmd.name = 'Primary' + cmd.zoneid = self.services["storage"]["zoneid"] + cmd.podid = self.services["storage"]["podid"] list_storage_response = self.apiclient.listStoragePools(cmd) self.assertNotEqual( @@ -115,10 +149,9 @@ class TestSecStorageServices(cloudstackTestCase): "Check list storage pools response" ) - for i in range(len(list_hosts_response)): - storage_response = list_storage_response[i] + for primary_storage in list_hosts_response: self.assertEqual( - storage_response.state, + primary_storage.state, 'Up', "Check state of primary storage pools is Up or not" ) @@ -126,7 +159,17 @@ class TestSecStorageServices(cloudstackTestCase): # Secondary storage is added successfully cmd = listHosts.listHostsCmd() cmd.type = 'SecondaryStorage' - list_hosts_response = self.apiclient.listHosts(cmd) + cmd.zoneid = self.services["storage"]["zoneid"] + + timeout = self.services["timeout"] + while True: + list_hosts_response = self.apiclient.listHosts(cmd) + if not list_hosts_response: + # Sleep to ensure Secondary storage is Up + time.sleep(int(self.services["sleep"])) + timeout = timeout - 1 + elif timeout == 0 or list_hosts_response: + break self.assertNotEqual( len(list_hosts_response), @@ -141,11 +184,87 @@ class TestSecStorageServices(cloudstackTestCase): 'Up', "Check state of secondary storage" ) + + cmd = listSystemVms.listSystemVmsCmd() + cmd.systemvmtype = 'secondarystoragevm' + cmd.zoneid = self.services["storage"]["zoneid"] + cmd.podid = self.services["storage"]["podid"] + + timeout = self.services["timeout"] + + while True: + list_ssvm_response = self.apiclient.listSystemVms(cmd) + if not list_ssvm_response: + # Sleep to ensure SSVMs are Up and Running + time.sleep(int(self.services["sleep"])) + timeout = timeout - 1 + elif timeout == 0 or list_ssvm_response: + break + + #Verify SSVM response + self.assertNotEqual( + len(list_ssvm_response), + 0, + "Check list System VMs response" + ) + + for ssvm in list_ssvm_response: + self.assertEqual( + ssvm.state, + 'Running', + "Check whether state of SSVM is running" + ) return def test_03_sys_template_ready(self): """Test system templates are ready """ - # TODO - return \ No newline at end of file + # Validate the following + # If SSVM is in UP state and running + # 1. wait for listTemplates to show all builtin templates downloaded for all added hypervisors and in “Ready” state" + + for k, v in self.services["hypervisors"].items(): + + cmd = listTemplates.listTemplatesCmd() + cmd.hypervisor = v["hypervisor"] + cmd.zoneid = v["zoneid"] + cmd.templatefilter = v["templatefilter"] + list_templates = self.apiclient.listTemplates(cmd) + + # Ensure all BUILTIN templates are downloaded + templateid = None + for template in list_templates: + if template.templatetype == "BUILTIN": + templateid = template.id + + cmd = listTemplates.listTemplatesCmd() + cmd.id = templateid + cmd.templatefilter = v["templatefilter"] + cmd.zoneid = v["zoneid"] + + while True and (templateid != None): + + template = self.apiclient.listTemplates(cmd)[0] + # If template is ready, + # template.status = Download Complete + # Downloading - x% Downloaded + # Error - Any other string + + if template.status == 'Download Complete' : + break + elif 'Downloaded' not in template.status.split(): + raise Exception + elif 'Downloaded' in template.status.split(): + time.sleep(120) + + #Ensuring the template is in ready state + time.sleep(30) + template = self.apiclient.listTemplates(cmd)[0] + + self.assertEqual( + template.isready, + True, + "Check whether state of template is ready or not" + ) + return diff --git a/tools/testClient/testcase/BVT-tests/test_service_offerings.py b/tools/testClient/testcase/BVT-tests/test_service_offerings.py index 0a69946bdb3..038704e84ab 100644 --- a/tools/testClient/testcase/BVT-tests/test_service_offerings.py +++ b/tools/testClient/testcase/BVT-tests/test_service_offerings.py @@ -8,11 +8,34 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * from utils import * from base import * -services = TEST_SERVICE_OFFERING + +class Services: + """Test Service offerings Services + """ + + def __init__(self): + self.services = { + "off_1": + { + "name": "Service Offering 1", + "displaytext": "Service Offering 1", + "cpunumber": 1, + "cpuspeed": 200, # MHz + "memory": 200, # in MBs + }, + + "off_2": + { + "name": "Service Offering 2", + "displaytext": "Service Offering 2", + "cpunumber": 1, + "cpuspeed": 200, # MHz + "memory": 200, # in MBs + } + } class TestCreateServiceOffering(cloudstackTestCase): @@ -20,6 +43,7 @@ class TestCreateServiceOffering(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] + self.services = Services().services def tearDown(self): try: @@ -28,7 +52,7 @@ class TestCreateServiceOffering(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -39,7 +63,7 @@ class TestCreateServiceOffering(cloudstackTestCase): # 1. createServiceOfferings should return a valid information for newly created offering # 2. The Cloud Database contains the valid information - service_offering = ServiceOffering.create(self.apiclient, services["off_1"]) + service_offering = ServiceOffering.create(self.apiclient, self.services["off_1"]) self.cleanup.append(service_offering) cmd = listServiceOfferings.listServiceOfferingsCmd() @@ -55,27 +79,27 @@ class TestCreateServiceOffering(cloudstackTestCase): self.assertEqual( list_service_response[0].cpunumber, - services["off_1"]["cpunumber"], + self.services["off_1"]["cpunumber"], "Check server id in createServiceOffering" ) self.assertEqual( list_service_response[0].cpuspeed, - services["off_1"]["cpuspeed"], + self.services["off_1"]["cpuspeed"], "Check cpuspeed in createServiceOffering" ) self.assertEqual( list_service_response[0].displaytext, - services["off_1"]["displaytext"], + self.services["off_1"]["displaytext"], "Check server displaytext in createServiceOfferings" ) self.assertEqual( list_service_response[0].memory, - services["off_1"]["memory"], + self.services["off_1"]["memory"], "Check memory in createServiceOffering" ) self.assertEqual( list_service_response[0].name, - services["off_1"]["name"], + self.services["off_1"]["name"], "Check name in createServiceOffering" ) #Verify the service offerings with database records @@ -94,17 +118,17 @@ class TestCreateServiceOffering(cloudstackTestCase): self.assertEqual( qresult[0], - services["off_1"]["cpunumber"], + self.services["off_1"]["cpunumber"], "Check number of CPUs allocated to service offering in the database" ) self.assertEqual( qresult[1], - services["off_1"]["cpuspeed"], + self.services["off_1"]["cpuspeed"], "Check number of CPUs allocated to service offering in the database" ) self.assertEqual( qresult[2], - services["off_1"]["memory"], + self.services["off_1"]["memory"], "Check number of CPUs allocated to service offering in the database" ) return @@ -125,26 +149,28 @@ class TestServiceOfferings(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @classmethod def setUpClass(cls): - + cls.services = Services().services cls.api_client = fetch_api_client() - cls.service_offering_1 = ServiceOffering.create(cls.api_client, services["off_1"]) - cls.service_offering_2 = ServiceOffering.create(cls.api_client, services["off_2"]) + cls.service_offering_1 = ServiceOffering.create(cls.api_client, cls.services["off_1"]) + cls.service_offering_2 = ServiceOffering.create(cls.api_client, cls.services["off_2"]) + cls._cleanup = [cls.service_offering_1] return @classmethod def tearDownClass(cls): try: cls.api_client = fetch_api_client() - cls.service_offering_1.delete(cls.api_client) + #Clean up, terminate the created templates + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_02_edit_service_offering(self): @@ -160,7 +186,7 @@ class TestServiceOfferings(cloudstackTestCase): cmd = updateServiceOffering.updateServiceOfferingCmd() #Add parameters for API call - cmd.id= self.service_offering_1.id + cmd.id = self.service_offering_1.id cmd.displaytext = random_displaytext cmd.name = random_name self.apiclient.updateServiceOffering(cmd) diff --git a/tools/testClient/testcase/BVT-tests/test_snapshots.py b/tools/testClient/testcase/BVT-tests/test_snapshots.py index 06126fe7ca2..9e850302e0b 100644 --- a/tools/testClient/testcase/BVT-tests/test_snapshots.py +++ b/tools/testClient/testcase/BVT-tests/test_snapshots.py @@ -7,32 +7,117 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * from utils import * from base import * +import remoteSSHClient -services = TEST_SNAPSHOT_SERVICES +class Services: + """Test Snapshots Services + """ + + def __init__(self): + self.services = { + "server_with_disk": + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "diskoffering": 3, # Optional, if specified data disk will be allocated to VM + "displayname": "testserver", + "username": "root", + "password": "fr3sca", + "ssh_port": 22, + "hypervisor": 'XenServer', + "account": 'testuser', + "domainid": 1, + "ipaddressid": 4, # IP Address ID of Public IP, If not specified new public IP + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + + "server_without_disk": + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "displayname": "testserver", + "username": "root", + "password": "fr3sca", + "ssh_port": 22, + "hypervisor": 'XenServer', + "account": 'testuser', + "domainid": 1, + "ipaddressid": 4, # IP Address ID of Public IP, If not specified new public IP + "privateport": 22, # For NAT rule creation + "publicport": 22, + "protocol": 'TCP', + }, + + "recurring_snapshot": + { + "intervaltype": 'HOURLY', # Frequency of snapshots + "maxsnaps": 2, # Should be min 2 + "schedule": 1, + "timezone": 'US/Arizona', + # Timezone Formats - http://cloud.mindtouch.us/CloudStack_Documentation/Developer's_Guide%3A_CloudStack + }, + + "templates": + { + "displaytext": 'Test template snapshot', + "name": 'template_from_snapshot_3', + "ostypeid": 12, + "templatefilter": 'self', + }, + "small_instance": + { + "zoneid": 1, + "serviceofferingid": 1, + }, + "diskdevice": "/dev/xvda", + "offerings": 1, + "template": 206, + "zoneid": 1, + "diskoffering": 3, + "diskname": "TestDiskServ", + "size": 1, # GBs + "account": 'testuser', + "domainid": 1, + "mount_dir": "/mnt/tmp", + "sub_dir": "test", + "sub_lvl_dir1": "test1", + "sub_lvl_dir2": "test2", + "random_data": "random.data", + "exportpath": 'SecondaryStorage', + "sec_storage": '192.168.100.131', + "mgmt_server_ip": '192.168.100.154', + "username": "root", + "password": "fr3sca", + "ssh_port": 22, + } class TestSnapshots(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = fetch_api_client() - cls.virtual_machine = cls.virtual_machine_with_disk =\ - VirtualMachine.create(cls.api_client, services["server_with_disk"]) - cls.virtual_machine_without_disk =\ - VirtualMachine.create(cls.api_client, services["server_without_disk"]) - cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, services["server_with_disk"]) + cls.services = Services().services + cls.virtual_machine = cls.virtual_machine_with_disk = \ + VirtualMachine.create(cls.api_client, cls.services["server_with_disk"]) + cls.virtual_machine_without_disk = \ + VirtualMachine.create(cls.api_client, cls.services["server_without_disk"]) + cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, cls.services["server_with_disk"]) + cls._cleanup = [cls.virtual_machine, cls.virtual_machine_without_disk, cls.nat_rule] return @classmethod def tearDownClass(cls): try: - cls.virtual_machine.delete(cls.api_client) - cls.virtual_machine_without_disk.delete(cls.api_client) - cls.nat_rule.delete(cls.api_client) + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def setUp(self): @@ -46,17 +131,24 @@ class TestSnapshots(cloudstackTestCase): #Clean up, terminate the created instance, volumes and snapshots cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_snapshot_root_disk(self): """Test Snapshot Root Disk """ + + # Validate the following + # 1.listSnapshots should list the snapshot that was created. + # 2.verify that secondary storage NFS share contains the reqd volume under /secondary/snapshots/$volumeid/$snapshot_uuid + # 3.verify backup_snap_id was non null in the `snapshots` table + cmd = listVolumes.listVolumesCmd() cmd.virtualmachineid = self.virtual_machine_with_disk.id cmd.type = 'ROOT' volumes = self.apiclient.listVolumes(cmd) snapshot = Snapshot.create(self.apiclient, volumes[0].id) + self.cleanup.append(snapshot) cmd = listSnapshots.listSnapshotsCmd() cmd.id = snapshot.id @@ -68,8 +160,8 @@ class TestSnapshots(cloudstackTestCase): snapshot.id, "Check resource id in list resources call" ) - self.debug("select backup_snap_id from snapshots where id = %s;" % snapshot.id) - qresultset = self.dbclient.execute("select backup_snap_id from snapshots where id = %s;" % snapshot.id) + self.debug("select backup_snap_id, account_id, volume_id, path from snapshots where id = %s;" % snapshot.id) + qresultset = self.dbclient.execute("select backup_snap_id, account_id, volume_id, path from snapshots where id = %s;" % snapshot.id) self.assertNotEqual( len(qresultset), 0, @@ -83,6 +175,28 @@ class TestSnapshots(cloudstackTestCase): 'NULL', "Check if backup_snap_id is not null" ) + + # Login to management server to check snapshot present on sec disk + ssh_client = remoteSSHClient.remoteSSHClient( + self.services["mgmt_server_ip"], + self.services["ssh_port"], + self.services["username"], + self.services["password"] + ) + + cmds = [ "mkdir -p %s" % self.services["mount_dir"], + "mount %s:/%s %s" % (self.services["sec_storage"], self.services["exportpath"], self.services["mount_dir"]), + "ls %s/snapshots/%s/%s" % (self.services["mount_dir"], qresult[1], qresult[2]), + ] + + for c in cmds: + result = ssh_client.execute(c) + + self.assertEqual( + result[0], + str(qresult[3]) + ".vhd", + "Check snapshot UUID in secondary storage and database" + ) return def test_02_snapshot_data_disk(self): @@ -105,8 +219,8 @@ class TestSnapshots(cloudstackTestCase): snapshot.id, "Check resource id in list resources call" ) - self.debug("select backup_snap_id from snapshots where id = %s;" % snapshot.id) - qresultset = self.dbclient.execute("select backup_snap_id from snapshots where id = %s;" % snapshot.id) + self.debug("select backup_snap_id, account_id, volume_id, path from snapshots where id = %s;" % 6)#snapshot.id + qresultset = self.dbclient.execute("select backup_snap_id, account_id, volume_id, backup_snap_id from snapshots where id = %s;" % 6) # snapshot.id self.assertNotEqual( len(qresultset), 0, @@ -120,6 +234,27 @@ class TestSnapshots(cloudstackTestCase): 'NULL', "Check if backup_snap_id is not null" ) + + # Login to management server to check snapshot present on sec disk + ssh_client = remoteSSHClient.remoteSSHClient( + self.services["mgmt_server_ip"], + self.services["ssh_port"], + self.services["username"], + self.services["password"] + ) + + cmds = [ "mkdir -p %s" % self.services["mount_dir"], + "mount %s:/%s %s" % (self.services["sec_storage"], self.services["exportpath"], self.services["mount_dir"]), + "ls %s/snapshots/%s/%s" % (self.services["mount_dir"], qresult[1], qresult[2]), + ] + for c in cmds: + result = ssh_client.execute(c) + + self.assertEqual( + result[0], + str(qresult[3]) + ".vhd", + "Check snapshot UUID in sec storage and database" + ) return def test_03_volume_from_snapshot(self): @@ -132,28 +267,33 @@ class TestSnapshots(cloudstackTestCase): #5. Compare data random_data_0 = random_gen(100) random_data_1 = random_gen(100) - ssh_client = self.virtual_machine.get_ssh_client(services["server_with_disk"]["ipaddress"]) + + cmd = listPublicIpAddresses.listPublicIpAddressesCmd() + cmd.id = self.services["server_with_disk"]["ipaddressid"] + public_ip = self.apiclient.listPublicIpAddresses(cmd)[0] + + ssh_client = self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress) #Format partition using ext3 - format_volume_to_ext3(ssh_client, services["diskdevice"]) - cmds = [ "mkdir -p %s" % services["mount_dir"], - "mount %s1 %s" %(services["diskdevice"], services["mount_dir"]), - "pushd %s" % services["mount_dir"], - "mkdir -p %s/{%s,%s} " %( - services["sub_dir"], - services["sub_lvl_dir1"], - services["sub_lvl_dir2"] + format_volume_to_ext3(ssh_client, self.services["diskdevice"]) + cmds = [ "mkdir -p %s" % self.services["mount_dir"], + "mount %s1 %s" % (self.services["diskdevice"], self.services["mount_dir"]), + "pushd %s" % self.services["mount_dir"], + "mkdir -p %s/{%s,%s} " % ( + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["sub_lvl_dir2"] ), - "echo %s > %s/%s/%s" %( - random_data_0, - services["sub_dir"], - services["sub_lvl_dir1"], - services["random_data"] + "echo %s > %s/%s/%s" % ( + random_data_0, + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["random_data"] ), - "echo %s > %s/%s/%s" %( + "echo %s > %s/%s/%s" % ( random_data_1, - services["sub_dir"], - services["sub_lvl_dir2"], - services["random_data"] + self.services["sub_dir"], + self.services["sub_lvl_dir2"], + self.services["random_data"] ) ] for c in cmds: @@ -168,7 +308,7 @@ class TestSnapshots(cloudstackTestCase): snapshot = Snapshot.create(self.apiclient, volume.id) self.cleanup.append(snapshot) #Create volume from snapshot - volume = Volume.create_from_snapshot(self.apiclient, snapshot.id, services) + volume = Volume.create_from_snapshot(self.apiclient, snapshot.id, self.services) self.cleanup.append(volume) cmd = listVolumes.listVolumesCmd() cmd.id = volume.id @@ -189,30 +329,34 @@ class TestSnapshots(cloudstackTestCase): cmd = attachVolume.attachVolumeCmd() cmd.id = volume.id cmd.virtualmachineid = new_virtual_machine.id - volume = self.apiclient.attachVolume(cmd) + + cmd = listPublicIpAddresses.listPublicIpAddressesCmd() + cmd.id = self.services["server_without_disk"]["ipaddressid"] + public_ip = self.apiclient.listPublicIpAddresses(cmd)[0] + #Login to VM to verify test directories and files - ssh = new_virtual_machine.get_ssh_client(services["server_without_disk"]["ipaddress"]) + ssh = new_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) cmds = [ - "mkdir %s" %services["mount_dir"], - "mount %s1 %s" %(services["diskdevice"], services["mount_dir"]) + "mkdir %s" % self.services["mount_dir"], + "mount %s1 %s" % (self.services["diskdevice"], self.services["mount_dir"]) ] for c in cmds: self.debug(ssh.execute(c)) - returned_data_0 = ssh.execute("cat %s/%s/%s" %( - services["sub_dir"], - services["sub_lvl_dir1"], - services["random_data"] + returned_data_0 = ssh.execute("cat %s/%s/%s" % ( + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["random_data"] ) ) - returned_data_1 = ssh.execute("cat %s/%s/%s" %( - services["sub_dir"], - services["sub_lvl_dir2"], - services["random_data"] - ) ) + returned_data_1 = ssh.execute("cat %s/%s/%s" % ( + self.services["sub_dir"], + self.services["sub_lvl_dir2"], + self.services["random_data"] + )) #Verify returned data self.assertEqual( random_data_0, @@ -242,7 +386,7 @@ class TestSnapshots(cloudstackTestCase): cmd.id = list_volumes[0].id list_snapshots = self.apiclient.listSnapshots(cmd) - snapshot = Snapshot.create(self.apiclient,list_volumes[0].id) + snapshot = Snapshot.create(self.apiclient, list_volumes[0].id) snapshot.delete(self.apiclient) #Sleep to ensure all database records are updated time.sleep(60) @@ -263,12 +407,12 @@ class TestSnapshots(cloudstackTestCase): cmd.virtualmachineid = self.virtual_machine_with_disk.id cmd.type = 'ROOT' volume = self.apiclient.listVolumes(cmd) - recurring_snapshot = SnapshotPolicy.create(self.apiclient, volume[0].id, services["recurring_snapshot"]) + recurring_snapshot = SnapshotPolicy.create(self.apiclient, volume[0].id, self.services["recurring_snapshot"]) self.cleanup.append(recurring_snapshot) #ListSnapshotPolicy should return newly created policy cmd = listSnapshotPolicies.listSnapshotPoliciesCmd() cmd.id = recurring_snapshot.id - cmd.volumeid=volume[0].id + cmd.volumeid = volume[0].id list_snapshots_policy = self.apiclient.listSnapshotPolicies(cmd) self.assertNotEqual(list_snapshots_policy, None, "Check if result exists in list item call") @@ -280,19 +424,19 @@ class TestSnapshots(cloudstackTestCase): ) self.assertEqual( snapshots_policy.maxsnaps, - services["recurring_snapshot"]["maxsnaps"], + self.services["recurring_snapshot"]["maxsnaps"], "Check interval type in list resources call" ) #Sleep for (maxsnaps+1) hours to verify only maxsnaps snapshots are retained - time.sleep(((services["recurring_snapshot"]["maxsnaps"])+1)*3600) + time.sleep(((self.services["recurring_snapshot"]["maxsnaps"]) + 1) * 3600) cmd = listSnapshots.listSnapshotsCmd() - cmd.volumeid=volume.id - cmd.intervaltype = services["recurring_snapshot"]["intervaltype"] + cmd.volumeid = volume.id + cmd.intervaltype = self.services["recurring_snapshot"]["intervaltype"] cmd.snapshottype = 'RECURRING' list_snapshots = self.apiclient.listSnapshots(cmd) self.assertEqual( len(list_snapshots), - services["recurring_snapshot"]["maxsnaps"], + self.services["recurring_snapshot"]["maxsnaps"], "Check maximum number of recurring snapshots retained" ) return @@ -308,12 +452,12 @@ class TestSnapshots(cloudstackTestCase): cmd.virtualmachineid = self.virtual_machine_with_disk.id cmd.type = 'DATADISK' volume = self.apiclient.listVolumes(cmd) - recurring_snapshot = SnapshotPolicy.create(self.apiclient, volume[0].id, services["recurring_snapshot"]) + recurring_snapshot = SnapshotPolicy.create(self.apiclient, volume[0].id, self.services["recurring_snapshot"]) self.cleanup.append(recurring_snapshot) #ListSnapshotPolicy should return newly created policy cmd = listSnapshotPolicies.listSnapshotPoliciesCmd() cmd.id = recurring_snapshot.id - cmd.volumeid=volume[0].id + cmd.volumeid = volume[0].id list_snapshots_policy = self.apiclient.listSnapshotPolicies(cmd) self.assertNotEqual(list_snapshots_policy, None, "Check if result exists in list item call") @@ -325,23 +469,23 @@ class TestSnapshots(cloudstackTestCase): ) self.assertEqual( snapshots_policy.maxsnaps, - services["recurring_snapshot"]["maxsnaps"], + self.services["recurring_snapshot"]["maxsnaps"], "Check interval type in list resources call" ) #Sleep for (maxsnaps+1) hours to verify only maxsnaps snapshots are retained - time.sleep(((services["recurring_snapshot"]["maxsnaps"])+1)*3600) + time.sleep(((self.services["recurring_snapshot"]["maxsnaps"]) + 1) * 3600) cmd = listSnapshots.listSnapshotsCmd() - cmd.volumeid=volume.id - cmd.intervaltype = services["recurring_snapshot"]["intervaltype"] + cmd.volumeid = volume.id + cmd.intervaltype = self.services["recurring_snapshot"]["intervaltype"] cmd.snapshottype = 'RECURRING' list_snapshots = self.apiclient.listSnapshots(cmd) self.assertEqual( len(list_snapshots), - services["recurring_snapshot"]["maxsnaps"], + self.services["recurring_snapshot"]["maxsnaps"], "Check maximum number of recurring snapshots retained" ) return @@ -360,28 +504,32 @@ class TestSnapshots(cloudstackTestCase): random_data_0 = random_gen(100) random_data_1 = random_gen(100) - #Login to virtual machine - ssh_client = self.virtual_machine.get_ssh_client(services["server_with_disk"]["ipaddress"]) + cmd = listPublicIpAddresses.listPublicIpAddressesCmd() + cmd.id = self.services["server_with_disk"]["ipaddressid"] + public_ip = self.apiclient.listPublicIpAddresses(cmd)[0] - cmds = [ "mkdir -p %s" % services["mount_dir"], - "mount %s1 %s" %(services["diskdevice"], services["mount_dir"]), - "pushd %s" % services["mount_dir"], - "mkdir -p %s/{%s,%s} " %( - services["sub_dir"], - services["sub_lvl_dir1"], - services["sub_lvl_dir2"] + #Login to virtual machine + ssh_client = self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress) + + cmds = [ "mkdir -p %s" % self.services["mount_dir"], + "mount %s1 %s" % (self.services["diskdevice"], self.services["mount_dir"]), + "pushd %s" % self.services["mount_dir"], + "mkdir -p %s/{%s,%s} " % ( + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["sub_lvl_dir2"] ), - "echo %s > %s/%s/%s" %( + "echo %s > %s/%s/%s" % ( random_data_0, - services["sub_dir"], - services["sub_lvl_dir1"], - services["random_data"] + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["random_data"] ), - "echo %s > %s/%s/%s" %( + "echo %s > %s/%s/%s" % ( random_data_1, - services["sub_dir"], - services["sub_lvl_dir2"], - services["random_data"] + self.services["sub_dir"], + self.services["sub_lvl_dir2"], + self.services["random_data"] ) ] @@ -397,11 +545,11 @@ class TestSnapshots(cloudstackTestCase): self.cleanup.append(snapshot) # Generate template from the snapshot - template = Template.create_from_snapshot(self.apiclient, snapshot, services["templates"]) + template = Template.create_from_snapshot(self.apiclient, snapshot, self.services["templates"]) cmd = listTemplates.listTemplatesCmd() - cmd.templatefilter = services["templates"]["templatefilter"] - cmd.id= template.id + cmd.templatefilter = self.services["templates"]["templatefilter"] + cmd.id = template.id list_templates = self.apiclient.listTemplates(cmd) self.assertNotEqual(list_templates, None, "Check if result exists in list item call") @@ -413,32 +561,37 @@ class TestSnapshots(cloudstackTestCase): ) # Deploy new virtual machine using template - new_virtual_machine = VirtualMachine.create( + new_virtual_machine = VirtualMachine.create( self.apiclient, - services["server_without_disk"], + self.services["server_without_disk"], template.id ) self.cleanup.append(new_virtual_machine) + + cmd = listPublicIpAddresses.listPublicIpAddressesCmd() + cmd.id = self.services["server_without_disk"]["ipaddressid"] + public_ip = self.apiclient.listPublicIpAddresses(cmd)[0] + #Login to VM & mount directory - ssh = new_virtual_machine.get_ssh_client(services["server_without_disk"]["ipaddress"]) + ssh = new_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) cmds = [ - "mkdir %s" %services["mount_dir"], - "mount %s1 %s" %(services["diskdevice"], services["mount_dir"]) + "mkdir %s" % self.services["mount_dir"], + "mount %s1 %s" % (self.services["diskdevice"], self.services["mount_dir"]) ] for c in cmds: ssh.execute(c) - returned_data_0 = ssh.execute("cat %s/%s/%s" %( - services["sub_dir"], - services["sub_lvl_dir1"], - services["random_data"] - ) ) - returned_data_1 = ssh.execute("cat %s/%s/%s" %( - services["sub_dir"], - services["sub_lvl_dir2"], - services["random_data"] - ) ) + returned_data_0 = ssh.execute("cat %s/%s/%s" % ( + self.services["sub_dir"], + self.services["sub_lvl_dir1"], + self.services["random_data"] + )) + returned_data_1 = ssh.execute("cat %s/%s/%s" % ( + self.services["sub_dir"], + self.services["sub_lvl_dir2"], + self.services["random_data"] + )) #Verify returned data self.assertEqual(random_data_0, returned_data_0[0], "Verify newly attached volume contents with existing one") self.assertEqual(random_data_1, returned_data_1[0], "Verify newly attached volume contents with existing one") diff --git a/tools/testClient/testcase/BVT-tests/test_ssvm.py b/tools/testClient/testcase/BVT-tests/test_ssvm.py index 9754fb6876a..b28607dbe27 100644 --- a/tools/testClient/testcase/BVT-tests/test_ssvm.py +++ b/tools/testClient/testcase/BVT-tests/test_ssvm.py @@ -7,7 +7,6 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * import remoteSSHClient from utils import * from base import * @@ -16,7 +15,27 @@ import telnetlib #Import System modules import time -services = TEST_SSVM_SERVICES +class Services: + """Test SSVM Services + """ + + def __init__(self): + self.services = { + "ssvm": { + "id": 1, # SSVM ID in particular zone + "zoneid": 1, + }, + "cpvm": { + "id": 2, # CPVM ID in particular zone + "zoneid": 1, + "mgmtserverIP": '192.168.100.154' # For Telnet + }, + "host": { + "username": 'root', # Credentials for SSH + "password": 'fr3sca', + "publicport": 22, + }, + } class TestSSVMs(cloudstackTestCase): @@ -24,6 +43,7 @@ class TestSSVMs(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.cleanup = [] + self.services = Services().services return def tearDown(self): @@ -32,7 +52,7 @@ class TestSSVMs(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return def test_01_list_sec_storage_vm(self): @@ -66,56 +86,56 @@ class TestSSVMs(cloudstackTestCase): "Check number of SSVMs with number of zones" ) #For each secondary storage VM check private IP, public IP, link local IP and DNS - for i in range(len(list_ssvm_response)): + for ssvm in list_ssvm_response: self.assertEqual( - list_ssvm_response[i].state, + ssvm.state, 'Running', "Check whether state of SSVM is running" ) self.assertEqual( - hasattr(list_ssvm_response[i],'privateip'), + hasattr(ssvm, 'privateip'), True, "Check whether SSVM has private IP field" ) self.assertEqual( - hasattr(list_ssvm_response[i],'linklocalip'), + hasattr(ssvm, 'linklocalip'), True, "Check whether SSVM has link local IP field" ) self.assertEqual( - hasattr(list_ssvm_response[i],'publicip'), + hasattr(ssvm, 'publicip'), True, "Check whether SSVM has public IP field" ) #Fetch corresponding ip ranges information from listVlanIpRanges cmd = listVlanIpRanges.listVlanIpRangesCmd() - cmd.id = list_ssvm_response[i].zoneid + cmd.id = ssvm.zoneid ipranges_response = self.apiclient.listVlanIpRanges(cmd)[0] self.assertEqual( - list_ssvm_response[i].gateway, + ssvm.gateway, ipranges_response.gateway, "Check gateway with that of corresponding ip range" ) #Fetch corresponding zone information from listZones cmd = listZones.listZonesCmd() - cmd.id = list_ssvm_response[i].zoneid + cmd.id = ssvm.zoneid zone_response = self.apiclient.listZones(cmd)[0] self.assertEqual( - list_ssvm_response[i].dns1, + ssvm.dns1, zone_response.dns1, "Check DNS1 with that of corresponding zone" ) self.assertEqual( - list_ssvm_response[i].dns2, + ssvm.dns2, zone_response.dns2, "Check DNS2 with that of corresponding zone" ) @@ -152,55 +172,55 @@ class TestSSVMs(cloudstackTestCase): "Check number of CPVMs with number of zones" ) #For each CPVM check private IP, public IP, link local IP and DNS - for i in range(len(list_cpvm_response)): + for cpvm in list_cpvm_response: self.assertEqual( - list_cpvm_response[i].state, + cpvm.state, 'Running', "Check whether state of CPVM is running" ) self.assertEqual( - hasattr(list_cpvm_response[i],'privateip'), + hasattr(cpvm, 'privateip'), True, "Check whether CPVM has private IP field" ) self.assertEqual( - hasattr(list_cpvm_response[i],'linklocalip'), + hasattr(cpvm, 'linklocalip'), True, "Check whether CPVM has link local IP field" ) self.assertEqual( - hasattr(list_cpvm_response[i],'publicip'), + hasattr(cpvm, 'publicip'), True, "Check whether CPVM has public IP field" ) #Fetch corresponding ip ranges information from listVlanIpRanges cmd = listVlanIpRanges.listVlanIpRangesCmd() - cmd.id = list_ssvm_response[i].zoneid + cmd.id = cpvm.zoneid ipranges_response = self.apiclient.listVlanIpRanges(cmd)[0] self.assertEqual( - list_cpvm_response[i].gateway, + cpvm.gateway, ipranges_response.gateway, "Check gateway with that of corresponding ip range" ) #Fetch corresponding zone information from listZones cmd = listZones.listZonesCmd() - cmd.id = list_cpvm_response[i].zoneid + cmd.id = cpvm.zoneid zone_response = self.apiclient.listZones(cmd)[0] self.assertEqual( - list_cpvm_response[i].dns1, + cpvm.dns1, zone_response.dns1, "Check DNS1 with that of corresponding zone" ) self.assertEqual( - list_cpvm_response[i].dns2, + cpvm.dns2, zone_response.dns2, "Check DNS2 with that of corresponding zone" ) @@ -216,7 +236,7 @@ class TestSSVMs(cloudstackTestCase): # 4. If no process is running/multiple process are running then the test is a failure cmd = listHosts.listHostsCmd() - cmd.zoneid = services["ssvm"]["zoneid"] + cmd.zoneid = self.services["ssvm"]["zoneid"] cmd.type = 'Routing' cmd.state = 'Up' host = self.apiclient.listHosts(cmd)[0] @@ -230,9 +250,9 @@ class TestSSVMs(cloudstackTestCase): #SSH to the machine ssh = remoteSSHClient.remoteSSHClient( host.ipaddress, - services['host']["publicport"], - services['host']["username"], - services['host']["password"] + self.services['host']["publicport"], + self.services['host']["username"], + self.services['host']["password"] ) timeout = 5 @@ -289,7 +309,7 @@ class TestSSVMs(cloudstackTestCase): # 3. Service cloud status should report cloud agent status to be running cmd = listHosts.listHostsCmd() - cmd.zoneid = services["cpvm"]["zoneid"] + cmd.zoneid = self.services["cpvm"]["zoneid"] cmd.type = 'Routing' cmd.state = 'Up' host = self.apiclient.listHosts(cmd)[0] @@ -300,19 +320,19 @@ class TestSSVMs(cloudstackTestCase): cpvm = self.apiclient.listSystemVms(cmd)[0] with assertNotRaises(Exception): - telnet = telnetlib.Telnet( services["cpvm"]["mgmtserverIP"] , '8250') + telnet = telnetlib.Telnet(self.services["cpvm"]["mgmtserverIP"] , '8250') self.debug("Cheking cloud process status") #SSH to the machine ssh = remoteSSHClient.remoteSSHClient( host.ipaddress, - services['host']["publicport"], - services['host']["username"], - services['host']["password"] + self.services['host']["publicport"], + self.services['host']["username"], + self.services['host']["password"] ) timeout = 5 # Check status of cloud service - ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -p 3922 %s " % cpvm.linklocalip + ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -p 3922 %s " % cpvm.linklocalip c = ssh_command + "service cloud status" while True: @@ -344,14 +364,14 @@ class TestSSVMs(cloudstackTestCase): # 3. If either of the two above steps fail the test is a failure cmd = stopSystemVm.stopSystemVmCmd() - cmd.id = services["ssvm"]["id"] + cmd.id = self.services["ssvm"]["id"] cmd.systemvmtype = 'secondarystoragevm' self.apiclient.stopSystemVm(cmd) #Sleep to ensure that SSVM is properly restarted time.sleep(90) cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["ssvm"]["id"] + cmd.id = self.services["ssvm"]["id"] list_ssvm_response = self.apiclient.listSystemVms(cmd) ssvm_response = list_ssvm_response[0] @@ -375,12 +395,12 @@ class TestSSVMs(cloudstackTestCase): # 3. If either of the two above steps fail the test is a failure cmd = stopSystemVm.stopSystemVmCmd() - cmd.id = services["cpvm"]["id"] + cmd.id = self.services["cpvm"]["id"] cmd.systemvmtype = 'consoleproxy' self.apiclient.stopSystemVm(cmd) cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["cpvm"]["id"] + cmd.id = self.services["cpvm"]["id"] timeout = 10 while True : @@ -414,7 +434,7 @@ class TestSSVMs(cloudstackTestCase): # 3. The cloud process should still be running within the SSVM cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["ssvm"]["id"] + cmd.id = self.services["ssvm"]["id"] cmd.systemvmtype = 'secondarystoragevm' ssvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -423,13 +443,13 @@ class TestSSVMs(cloudstackTestCase): old_private_ip = ssvm_response.privateip cmd = rebootSystemVm.rebootSystemVmCmd() - cmd.id = services["ssvm"]["id"] + cmd.id = self.services["ssvm"]["id"] self.apiclient.rebootSystemVm(cmd) #Sleep to ensure that SSVM is properly stopped/started time.sleep(60) cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["ssvm"]["id"] + cmd.id = self.services["ssvm"]["id"] ssvm_response = self.apiclient.listSystemVms(cmd)[0] self.assertEqual( @@ -462,7 +482,7 @@ class TestSSVMs(cloudstackTestCase): # 3. the cloud process should still be running within the CPVM cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["cpvm"]["id"] + cmd.id = self.services["cpvm"]["id"] cmd.systemvmtype = 'consoleproxy' cpvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -471,14 +491,14 @@ class TestSSVMs(cloudstackTestCase): old_private_ip = cpvm_response.privateip cmd = rebootSystemVm.rebootSystemVmCmd() - cmd.id = services["cpvm"]["id"] + cmd.id = self.services["cpvm"]["id"] self.apiclient.rebootSystemVm(cmd) #Sleep to ensure that SSVM is properly stopped/started time.sleep(60) cmd = listSystemVms.listSystemVmsCmd() - cmd.id = services["cpvm"]["id"] + cmd.id = self.services["cpvm"]["id"] cpvm_response = self.apiclient.listSystemVms(cmd)[0] self.assertEqual( @@ -513,7 +533,7 @@ class TestSSVMs(cloudstackTestCase): # 4. cloud process within SSVM must be up and running cmd = listSystemVms.listSystemVmsCmd() - cmd.zoneid = services["ssvm"]["zoneid"] + cmd.zoneid = self.services["ssvm"]["zoneid"] cmd.systemvmtype = 'secondarystoragevm' ssvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -527,7 +547,7 @@ class TestSSVMs(cloudstackTestCase): time.sleep(60) cmd = listSystemVms.listSystemVmsCmd() - cmd.zoneid = services["ssvm"]["zoneid"] + cmd.zoneid = self.services["ssvm"]["zoneid"] cmd.systemvmtype = 'secondarystoragevm' ssvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -538,19 +558,19 @@ class TestSSVMs(cloudstackTestCase): "Check SSVM new name with name of destroyed SSVM" ) self.assertEqual( - hasattr(ssvm_response,'privateip'), + hasattr(ssvm_response, 'privateip'), True, "Check whether SSVM has private IP field" ) self.assertEqual( - hasattr(ssvm_response,'linklocalip'), + hasattr(ssvm_response, 'linklocalip'), True, "Check whether SSVM has link local IP field" ) self.assertEqual( - hasattr(ssvm_response,'publicip'), + hasattr(ssvm_response, 'publicip'), True, "Check whether SSVM has public IP field" ) @@ -569,7 +589,7 @@ class TestSSVMs(cloudstackTestCase): # 4. cloud process within CPVM must be up and running cmd = listSystemVms.listSystemVmsCmd() - cmd.zoneid = services["cpvm"]["zoneid"] + cmd.zoneid = self.services["cpvm"]["zoneid"] cmd.systemvmtype = 'consoleproxy' cpvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -583,7 +603,7 @@ class TestSSVMs(cloudstackTestCase): time.sleep(60) cmd = listSystemVms.listSystemVmsCmd() - cmd.zoneid = services["cpvm"]["zoneid"] + cmd.zoneid = self.services["cpvm"]["zoneid"] cmd.systemvmtype = 'consoleproxy' cpvm_response = self.apiclient.listSystemVms(cmd)[0] @@ -594,22 +614,22 @@ class TestSSVMs(cloudstackTestCase): "Check SSVM new name with name of destroyed CPVM" ) self.assertEqual( - hasattr(cpvm_response,'privateip'), + hasattr(cpvm_response, 'privateip'), True, "Check whether CPVM has private IP field" ) self.assertEqual( - hasattr(cpvm_response,'linklocalip'), + hasattr(cpvm_response, 'linklocalip'), True, "Check whether CPVM has link local IP field" ) self.assertEqual( - hasattr(cpvm_response,'publicip'), + hasattr(cpvm_response, 'publicip'), True, "Check whether CPVM has public IP field" ) #Call to verify cloud process is running self.test_04_cpvm_internals() - return \ No newline at end of file + return diff --git a/tools/testClient/testcase/BVT-tests/test_templates.py b/tools/testClient/testcase/BVT-tests/test_templates.py index d3d9dcf7140..e364813f112 100644 --- a/tools/testClient/testcase/BVT-tests/test_templates.py +++ b/tools/testClient/testcase/BVT-tests/test_templates.py @@ -7,8 +7,6 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * -import remoteSSHClient from utils import * from base import * import urllib @@ -16,8 +14,60 @@ from random import random #Import System modules import time +class Services: + """Test Templates Services + """ -services = TEST_TEMPLATE_SERVICES + def __init__(self): + self.services = { + "virtual_machine": + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "displayname": "testVM", + "hypervisor": 'XenServer', + "account": 'admin', # Account for which VM should be created + "domainid": 1, + "protocol": 'TCP', + }, + "volume": + { + "offerings": 1, + "volumeoffering": 3, + "diskname": "TestVolumeTemplate", + "zoneid": 1, + "diskofferingid": 3, + }, + "template_1": + { + "displaytext": "Test Template Type 1", + "name": "testTemplate", + "ostypeid": 12, + }, + "template_2": + { + "displaytext": "Test Template Type 2", + "name": "testTemplate", + "ostypeid": 12, + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "mode": "HTTP_DOWNLOAD", + "zoneid": 1, + }, + "templatefilter": 'self', + "destzoneid": 2, # For Copy template (Destination zone) + "sourcezoneid": 1, # For Copy template (Source zone) + "isfeatured": True, + "ispublic": True, + "isextractable": False, + "bootable": True, + "passwordenabled": True, + "ostypeid": 15, + "account": 'testuser', # Normal user + "domainid": 1, + } class TestCreateTemplate(cloudstackTestCase): @@ -35,17 +85,17 @@ class TestCreateTemplate(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @classmethod def setUpClass(cls): - + cls.services = Services().services cls.api_client = fetch_api_client() #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.api_client, - services["virtual_machine"] + cls.services["virtual_machine"] ) #Stop virtual machine @@ -60,6 +110,7 @@ class TestCreateTemplate(cloudstackTestCase): cmd.type = 'ROOT' list_volume = cls.api_client.listVolumes(cmd) cls.volume = list_volume[0] + cls._cleanup = [cls.virtual_machine] return @classmethod @@ -67,10 +118,10 @@ class TestCreateTemplate(cloudstackTestCase): try: cls.api_client = fetch_api_client() #Cleanup resources used - cls.virtual_machine.delete(cls.api_client) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -84,11 +135,11 @@ class TestCreateTemplate(cloudstackTestCase): # 3. ListTemplates API should show the newly added template #Create template from Virtual machine and Volume ID - template = Template.create(self.apiclient, self.volume, services["template_1"]) + template = Template.create(self.apiclient, self.volume, self.services["template_1"]) self.cleanup.append(template) cmd = listTemplates.listTemplatesCmd() - cmd.templatefilter = services["templatefilter"] + cmd.templatefilter = self.services["templatefilter"] cmd.id = template.id list_template_response = self.apiclient.listTemplates(cmd) @@ -102,29 +153,30 @@ class TestCreateTemplate(cloudstackTestCase): self.assertEqual( template_response.displaytext, - services["template_1"]["displaytext"], + self.services["template_1"]["displaytext"], "Check display text of newly created template" ) + name = template_response.name self.assertEqual( - template_response.name, - services["template_1"]["name"], + name.count(self.services["template_1"]["name"]), + 1, "Check name of newly created template" ) self.assertEqual( template_response.ostypeid, - services["template_1"]["ostypeid"], + self.services["template_1"]["ostypeid"], "Check osTypeID of newly created template" ) #Verify the database entry for template self.debug( "select name, display_text, guest_os_id from vm_template where id = %s;" - %template.id + % template.id ) qresultset = self.dbclient.execute( "select name, display_text, guest_os_id from vm_template where id = %s;" - %template.id + % template.id ) self.assertNotEqual( @@ -135,21 +187,22 @@ class TestCreateTemplate(cloudstackTestCase): qresult = qresultset[0] + name = qresult[0] self.assertEqual( - qresult[0], - services["template_1"]["name"], + name.count(self.services["template_1"]["name"]), + 1, "Compare template name with database record" ) self.assertEqual( qresult[1], - services["template_1"]["displaytext"], + self.services["template_1"]["displaytext"], "Compare template display text with database record" ) self.assertEqual( qresult[2], - services["template_1"]["ostypeid"], + self.services["template_1"]["ostypeid"], "Compare template osTypeID with database record" ) return @@ -159,11 +212,12 @@ class TestTemplates(cloudstackTestCase): @classmethod def setUpClass(cls): + cls.services = Services().services cls.api_client = fetch_api_client() #create virtual machines cls.virtual_machine = VirtualMachine.create( cls.api_client, - services["virtual_machine"] + cls.services["virtual_machine"] ) #Stop virtual machine @@ -180,20 +234,19 @@ class TestTemplates(cloudstackTestCase): cls.volume = list_volume[0] #Create templates for Edit, Delete & update permissions testcases - cls.template_1 = Template.create(cls.api_client, cls.volume, services["template_1"]) - cls.template_2 = Template.create(cls.api_client, cls.volume, services["template_2"]) + cls.template_1 = Template.create(cls.api_client, cls.volume, cls.services["template_1"]) + cls.template_2 = Template.create(cls.api_client, cls.volume, cls.services["template_2"]) + cls._cleanup = [cls.template_2, cls.virtual_machine] @classmethod def tearDownClass(cls): try: cls.api_client = fetch_api_client() - #Cleanup created resources such as templates and VMs - cls.template_2.delete(cls.api_client) - cls.virtual_machine.delete(cls.api_client) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -212,7 +265,7 @@ class TestTemplates(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -232,15 +285,15 @@ class TestTemplates(cloudstackTestCase): cmd.id = self.template_1.id cmd.displaytext = new_displayText cmd.name = new_name - cmd.bootable = services["bootable"] - cmd.passwordenabled = services["passwordenabled"] - cmd.ostypeid = services["ostypeid"] + cmd.bootable = self.services["bootable"] + cmd.passwordenabled = self.services["passwordenabled"] + cmd.ostypeid = self.services["ostypeid"] self.apiclient.updateTemplate(cmd) # Verify template response for updated attributes cmd = listTemplates.listTemplatesCmd() - cmd.templatefilter = services["templatefilter"] + cmd.templatefilter = self.services["templatefilter"] cmd.id = self.template_1.id list_template_response = self.apiclient.listTemplates(cmd) @@ -264,23 +317,23 @@ class TestTemplates(cloudstackTestCase): ) self.assertEqual( str(template_response.passwordenabled).lower(), - str(services["passwordenabled"]).lower(), + str(self.services["passwordenabled"]).lower(), "Check passwordenabled field of updated template" ) self.assertEqual( template_response.ostypeid, - services["ostypeid"], + self.services["ostypeid"], "Check OSTypeID of updated template" ) # Verify database entry for updated template attributes self.debug( "select name, display_text, bootable, enable_password, guest_os_id from vm_template where id = %s;" - %self.template_1.id + % self.template_1.id ) qresultset = self.dbclient.execute( "select name, display_text, bootable, enable_password, guest_os_id from vm_template where id = %s;" - %self.template_1.id + % self.template_1.id ) self.assertNotEqual( @@ -304,17 +357,17 @@ class TestTemplates(cloudstackTestCase): ) self.assertEqual( qresult[2], - int(services["bootable"]), + int(self.services["bootable"]), "Compare template enable_password field with database record" ) self.assertEqual( qresult[3], - int(services["passwordenabled"]), + int(self.services["passwordenabled"]), "Compare template display text with database record" ) self.assertEqual( qresult[4], - services["ostypeid"], + self.services["ostypeid"], "Compare template guest OS ID with database record" ) return @@ -330,7 +383,7 @@ class TestTemplates(cloudstackTestCase): self.template_1.delete(self.apiclient) cmd = listTemplates.listTemplatesCmd() - cmd.templatefilter = services["templatefilter"] + cmd.templatefilter = self.services["templatefilter"] cmd.id = self.template_1.id list_template_response = self.apiclient.listTemplates(cmd) @@ -340,12 +393,12 @@ class TestTemplates(cloudstackTestCase): # Verify database entry is removed for deleted template self.debug( "select name, display_text from vm_template where id = %s;" - %self.template_1.id + % self.template_1.id ) qresultset = self.dbclient.execute( "select name, display_text from vm_template where id = %s;" - %self.template_1.id + % self.template_1.id ) self.assertEqual( @@ -366,8 +419,8 @@ class TestTemplates(cloudstackTestCase): cmd = extractTemplate.extractTemplateCmd() cmd.id = self.template_2.id - cmd.mode = services["template_2"]["mode"] - cmd.zoneid = services["template_2"]["zoneid"] + cmd.mode = self.services["template_2"]["mode"] + cmd.zoneid = self.services["template_2"]["zoneid"] list_extract_response = self.apiclient.extractTemplate(cmd) # Format URL to ASCII to retrieve response code @@ -382,12 +435,12 @@ class TestTemplates(cloudstackTestCase): ) self.assertEqual( list_extract_response.extractMode, - services["template_2"]["mode"], + self.services["template_2"]["mode"], "Check mode of extraction" ) self.assertEqual( list_extract_response.zoneid, - services["template_2"]["zoneid"], + self.services["template_2"]["zoneid"], "Check zone ID of extraction" ) self.assertEqual( @@ -407,16 +460,16 @@ class TestTemplates(cloudstackTestCase): cmd = updateTemplatePermissions.updateTemplatePermissionsCmd() # Update template permissions cmd.id = self.template_2.id - cmd.isfeatured = services["isfeatured"] - cmd.ispublic = services["ispublic"] - cmd.isextractable =services["isextractable"] + cmd.isfeatured = self.services["isfeatured"] + cmd.ispublic = self.services["ispublic"] + cmd.isextractable = self.services["isextractable"] self.apiclient.updateTemplatePermissions(cmd) cmd = listTemplates.listTemplatesCmd() cmd.id = self.template_2.id - cmd.account = services["account"] - cmd.domainid = services["domainid"] + cmd.account = self.services["account"] + cmd.domainid = self.services["domainid"] cmd.templatefilter = 'featured' list_template_response = self.apiclient.listTemplates(cmd) @@ -443,11 +496,11 @@ class TestTemplates(cloudstackTestCase): # Verify database entries for updated permissions self.debug( "select public, featured, extractable from vm_template where id = %s;" - %self.template_2.id + % self.template_2.id ) qresultset = self.dbclient.execute( "select public, featured, extractable from vm_template where id = %s;" - %self.template_2.id + % self.template_2.id ) self.assertNotEqual( @@ -460,18 +513,18 @@ class TestTemplates(cloudstackTestCase): self.assertEqual( qresult[0], - int(services["ispublic"]), + int(self.services["ispublic"]), "Compare public permission with database record" ) self.assertEqual( qresult[1], - int(services["isfeatured"]), + int(self.services["isfeatured"]), "Compare featured permission with database record" ) self.assertEqual( qresult[2], - int(services["isextractable"]), + int(self.services["isextractable"]), "Compare extractable permission with database record" ) return @@ -484,14 +537,14 @@ class TestTemplates(cloudstackTestCase): cmd = copyTemplate.copyTemplateCmd() cmd.id = self.template_2.id - cmd.destzoneid = services["destzoneid"] - cmd.sourcezoneid = services["sourcezoneid"] + cmd.destzoneid = self.services["destzoneid"] + cmd.sourcezoneid = self.services["sourcezoneid"] self.apiclient.copyTemplate(cmd) # Verify template is copied to another zone using ListTemplates cmd = listTemplates.listTemplatesCmd() cmd.id = self.template_2.id - cmd.templatefilter = services["templatefilter"] + cmd.templatefilter = self.services["templatefilter"] list_template_response = self.apiclient.listTemplates(cmd) template_response = list_template_response[0] @@ -507,7 +560,7 @@ class TestTemplates(cloudstackTestCase): ) self.assertEqual( template_response.zoneid, - services["destzoneid"], + self.services["destzoneid"], "Check zone ID of the copied template" ) return @@ -520,8 +573,8 @@ class TestTemplates(cloudstackTestCase): cmd = listTemplates.listTemplatesCmd() cmd.templatefilter = 'featured' - cmd.account = services["account"] - cmd.domainid = services["domainid"] + cmd.account = self.services["account"] + cmd.domainid = self.services["domainid"] list_template_response = self.apiclient.listTemplates(cmd) @@ -531,9 +584,9 @@ class TestTemplates(cloudstackTestCase): "Check template available in List Templates" ) #Template response should list all 'public' templates - for k in range(len(list_template_response)): + for template in list_template_response: self.assertEqual( - list_template_response[k].ispublic, + template.ispublic, True, "ListTemplates should list only public templates" ) @@ -547,8 +600,8 @@ class TestTemplates(cloudstackTestCase): cmd = listTemplates.listTemplatesCmd() cmd.templatefilter = 'featured' - cmd.account = services["account"] - cmd.domainid = services["domainid"] + cmd.account = self.services["account"] + cmd.domainid = self.services["domainid"] list_template_response = self.apiclient.listTemplates(cmd) @@ -558,9 +611,9 @@ class TestTemplates(cloudstackTestCase): "Check template available in List Templates" ) - for k in range(len(list_template_response)): + for template in list_template_response: self.assertNotEqual( - list_template_response[k].templatetype, + template.templatetype, 'SYSTEM', "ListTemplates should not list any system templates" ) diff --git a/tools/testClient/testcase/BVT-tests/test_vm_life_cycle.py b/tools/testClient/testcase/BVT-tests/test_vm_life_cycle.py index a1351ff4b18..bdc1362a5e0 100644 --- a/tools/testClient/testcase/BVT-tests/test_vm_life_cycle.py +++ b/tools/testClient/testcase/BVT-tests/test_vm_life_cycle.py @@ -8,26 +8,99 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * import remoteSSHClient from utils import * from base import * #Import System modules import time +class Services: + """Test VM Life Cycle Services + """ -services = TEST_VM_LIFE_CYCLE_SERVICES + def __init__(self): + self.services = { + "small": # Create a small virtual machine instance with disk offering + { + "template": 256, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 43, + "diskoffering": 3, # Optional, if specified data disk will be allocated to VM + "displayname": "testserver", + "username": "root", # VM creds for SSH + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "account": 'testuser', # Account for which VM should be created + "domainid": 1, + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "medium": # Create a medium virtual machine instance + { + "template": 206, # Template used for VM creation + "zoneid": 1, + "serviceoffering": 1, + "displayname": "testserver", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "account": 'testuser', + "domainid": 1, + "ipaddressid": 4, + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "service_offerings": + { + "small": + { + "id": 40, + # Small service offering ID to for change VM service offering from medium to small + "cpunumber": 1, + "cpuspeed": 500, + "memory": 524288 + }, + "medium": + { + "id": 39, + # Medium service offering ID to for change VM service offering from small to medium + "cpunumber": 1, + "cpuspeed": 1000, + "memory": 1048576 + } + }, + "iso": # ISO settings for Attach/Detach ISO tests + { + "displaytext": "Test ISO type", + "name": "testISO", + "url": "http://iso.linuxquestions.org/download/504/1819/http/gd4.tuwien.ac.at/dsl-4.4.10.iso", + # Source URL where ISO is located + "zoneid": 1, + "ostypeid": 12, + "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO + }, + "diskdevice": '/dev/xvdd', + "mount_dir": "/mnt/tmp", + "hostid": 1, + } class TestDeployVM(cloudstackTestCase): def setUp(self): + self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.cleanup = [] - self.virtual_machine = VirtualMachine.create(self.apiclient, services["small"]) + + # Create VMs, NAT Rules etc + self.services = Services().services + self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["small"]) self.cleanup.append(self.virtual_machine) - self.nat_rule = NATRule.create(self.apiclient, self.virtual_machine, services["small"]) + self.nat_rule = NATRule.create(self.apiclient, self.virtual_machine, self.services["small"]) self.cleanup.append(self.nat_rule) def test_deploy_vm(self): @@ -38,17 +111,19 @@ class TestDeployVM(cloudstackTestCase): # 1. Virtual Machine is accessible via SSH # 2. listVirtualMachines returns accurate information # 3. The Cloud Database contains the valid information + ipaddress = self.virtual_machine.ipaddress - self.debug("Verify SSH Access for virtual machine: %s" %self.virtual_machine.id) + self.debug("Verify SSH Access for virtual machine: %s" % self.virtual_machine.id) + try: - self.virtual_machine.get_ssh_client(services["small"]["ipaddress"]) + self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.virtual_machine.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress, e)) cmd = listVirtualMachines.listVirtualMachinesCmd() cmd.id = self.virtual_machine.id list_vm_response = self.apiclient.listVirtualMachines(cmd) - self.debug("Verify listVirtualMachines response for virtual machine: %s" %self.virtual_machine.id) + self.debug("Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id) vm_response = list_vm_response[0] self.assertNotEqual( @@ -70,10 +145,10 @@ class TestDeployVM(cloudstackTestCase): "Check virtual machine displayname in listVirtualMachines" ) - self.debug("Verify the database entry for virtual machine: %s" %self.virtual_machine.id) + self.debug("Verify the database entry for virtual machine: %s" % self.virtual_machine.id) - self.debug("select id, state, private_ip_address from vm_instance where id = %s;" %self.virtual_machine.id) - qresultset = self.dbclient.execute("select id, state, private_ip_address from vm_instance where id = %s;" %self.virtual_machine.id) + self.debug("select id, state, private_ip_address from vm_instance where id = %s;" % self.virtual_machine.id) + qresultset = self.dbclient.execute("select id, state, private_ip_address from vm_instance where id = %s;" % self.virtual_machine.id) self.assertNotEqual( len(qresultset), @@ -104,7 +179,7 @@ class TestDeployVM(cloudstackTestCase): try: cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - self.debug("Warning! Exception in tearDown: %s" %e) + self.debug("Warning! Exception in tearDown: %s" % e) class TestVMLifeCycle(cloudstackTestCase): @@ -112,26 +187,27 @@ class TestVMLifeCycle(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = fetch_api_client() - + cls.services = self.services().services #create small and large virtual machines cls.small_virtual_machine = VirtualMachine.create( cls.api_client, - TEST_VM_LIFE_CYCLE_SERVICES["small"] + cls.services["small"] ) cls.medium_virtual_machine = VirtualMachine.create( cls.api_client, - TEST_VM_LIFE_CYCLE_SERVICES["medium"] + cls.services["medium"] ) cls.virtual_machine = VirtualMachine.create( cls.api_client, - TEST_VM_LIFE_CYCLE_SERVICES["small"] + cls.services["small"] ) - cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, services["small"]) + cls.nat_rule = NATRule.create(cls.api_client, cls.small_virtual_machine, cls.services["small"]) + cls._cleanup = [cls.nat_rule, cls.medium_virtual_machine, cls.virtual_machine, ] @classmethod def tearDownClass(cls): cls.api_client = fetch_api_client() - cls.nat_rule.delete(cls.api_client) + cleanup_resources(cls.api_client, cls._cleanup) return def setUp(self): @@ -140,7 +216,6 @@ class TestVMLifeCycle(cloudstackTestCase): self.cleanup = [] def tearDown(self): - self.dbclient.close() #Clean up, terminate the created ISOs cleanup_resources(self.apiclient, self.cleanup) return @@ -153,7 +228,7 @@ class TestVMLifeCycle(cloudstackTestCase): self.api_client.stopVirtualMachine(cmd) #Wait before server has be successfully stopped - self.debug("Verify SSH Access for virtual machine: %s,%s" %(self.small_virtual_machine.id, self.small_virtual_machine.ipaddress)) + self.debug("Verify SSH Access for virtual machine: %s,%s" % (self.small_virtual_machine.id, self.small_virtual_machine.ipaddress)) time.sleep(30) with self.assertRaises(Exception): remoteSSHClient.remoteSSHClient( @@ -178,10 +253,10 @@ class TestVMLifeCycle(cloudstackTestCase): "Check virtual machine is in stopped state" ) - self.debug("Verify the database entry for virtual machine: %s" %self.small_virtual_machine.id) + self.debug("Verify the database entry for virtual machine: %s" % self.small_virtual_machine.id) - self.debug("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) + self.debug("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) self.assertNotEqual( len(qresultset), @@ -206,32 +281,35 @@ class TestVMLifeCycle(cloudstackTestCase): cmd.id = self.small_virtual_machine.id self.apiclient.startVirtualMachine(cmd) + time.sleep(30) + cmd = listVirtualMachines.listVirtualMachinesCmd() cmd.id = self.small_virtual_machine.id - list_vm_response = self.apiclient.listVirtualMachines(cmd) + self.assertNotEqual( len(list_vm_response), 0, "Check VM avaliable in List Virtual Machines" ) - self.debug("Verify listVirtualMachines response for virtual machine: %s" %self.small_virtual_machine.id) + self.debug("Verify listVirtualMachines response for virtual machine: %s" % self.small_virtual_machine.id) self.assertEqual( list_vm_response[0].state, "Running", "Check virtual machine is in running state" ) - self.debug("Verify SSH Access for virtual machine: %s" %self.small_virtual_machine.id) - try: - self.small_virtual_machine.get_ssh_client(services["small"]["ipaddress"]) - except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.small_virtual_machine.ipaddress, e)) + self.debug("Verify SSH Access for virtual machine: %s" % self.small_virtual_machine.id) - self.debug("Verify the database entry for virtual machine: %s" %self.small_virtual_machine.id) - self.debug("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) + try: + self.small_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % (self.small_virtual_machine.ipaddress, e)) + + self.debug("Verify the database entry for virtual machine: %s" % self.small_virtual_machine.id) + self.debug("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) self.assertNotEqual( len(qresultset), 0, @@ -266,11 +344,12 @@ class TestVMLifeCycle(cloudstackTestCase): ) - self.debug("Verify SSH Access for virtual machine: %s" %self.small_virtual_machine.id) + self.debug("Verify SSH Access for virtual machine: %s" % self.small_virtual_machine.id) + try: - self.small_virtual_machine.get_ssh_client(services["small"]["ipaddress"]) + self.small_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.small_virtual_machine.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.small_virtual_machine.ipaddress, e)) self.assertEqual( @@ -292,7 +371,7 @@ class TestVMLifeCycle(cloudstackTestCase): time.sleep(60) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.small_virtual_machine.id - cmd.serviceofferingid = services["service_offerings"]["medium"]["id"] + cmd.serviceofferingid = self.services["service_offerings"]["medium"]["id"] self.apiclient.changeServiceForVirtualMachine(cmd) @@ -301,9 +380,9 @@ class TestVMLifeCycle(cloudstackTestCase): self.apiclient.startVirtualMachine(cmd) try: - ssh = self.small_virtual_machine.get_ssh_client(services["small"]["ipaddress"]) + ssh = self.small_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.small_virtual_machine.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.small_virtual_machine.ipaddress, e)) cpuinfo = ssh.execute("cat /proc/cpuinfo") @@ -318,18 +397,18 @@ class TestVMLifeCycle(cloudstackTestCase): self.assertEqual( cpu_cnt, - services["service_offerings"]["medium"]["cpunumber"], + self.services["service_offerings"]["medium"]["cpunumber"], "Check CPU Count for medium offering" ) self.assertEqual( cpu_speed, - services["service_offerings"]["medium"]["cpuspeed"], + self.services["service_offerings"]["medium"]["cpuspeed"], "Check CPU Speed for medium offering" ) self.assertEqual( total_mem, - services["service_offerings"]["medium"]["memory"], + self.services["service_offerings"]["medium"]["memory"], "Check Memory(kb) for medium offering" ) @@ -344,7 +423,7 @@ class TestVMLifeCycle(cloudstackTestCase): time.sleep(60) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.medium_virtual_machine.id - cmd.serviceofferingid = services["service_offerings"]["small"]["id"] + cmd.serviceofferingid = self.services["service_offerings"]["small"]["id"] self.apiclient.changeServiceForVirtualMachine(cmd) @@ -353,9 +432,9 @@ class TestVMLifeCycle(cloudstackTestCase): self.apiclient.startVirtualMachine(cmd) try: - ssh = self.medium_virtual_machine.get_ssh_client(services["medium"]["ipaddress"]) + ssh = self.medium_virtual_machine.get_ssh_client(self.nat_rule.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" %(self.medium_virtual_machine.ipaddress, e)) + self.fail("SSH Access failed for %s: %s" % (self.medium_virtual_machine.ipaddress, e)) cpuinfo = ssh.execute("cat /proc/cpuinfo") @@ -370,18 +449,18 @@ class TestVMLifeCycle(cloudstackTestCase): self.assertEqual( cpu_cnt, - services["service_offerings"]["small"]["cpunumber"], + self.services["service_offerings"]["small"]["cpunumber"], "Check CPU Count for small offering" ) self.assertEqual( cpu_speed, - services["service_offerings"]["small"]["cpuspeed"], + self.services["service_offerings"]["small"]["cpuspeed"], "Check CPU Speed for small offering" ) self.assertEqual( total_mem, - services["service_offerings"]["small"]["memory"], + self.services["service_offerings"]["small"]["memory"], "Check Memory(kb) for small offering" ) @@ -393,7 +472,7 @@ class TestVMLifeCycle(cloudstackTestCase): cmd.id = self.small_virtual_machine.id self.apiclient.destroyVirtualMachine(cmd) - self.debug("Verify SSH Access for virtual machine: %s" %self.small_virtual_machine.id) + self.debug("Verify SSH Access for virtual machine: %s" % self.small_virtual_machine.id) with self.assertRaises(Exception): remoteSSHClient.remoteSSHClient( self.small_virtual_machine.ipaddress, @@ -418,10 +497,10 @@ class TestVMLifeCycle(cloudstackTestCase): "Check virtual machine is in destroyed state" ) - self.debug("Verify the database entry for virtual machine: %s" %self.small_virtual_machine.id) + self.debug("Verify the database entry for virtual machine: %s" % self.small_virtual_machine.id) - self.debug("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) + self.debug("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) self.assertNotEqual( len(qresultset), 0, @@ -466,9 +545,9 @@ class TestVMLifeCycle(cloudstackTestCase): "Check virtual machine is in Stopped state" ) - self.debug("Verify the database entry for virtual machine: %s" %self.small_virtual_machine.id) - self.debug("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) + self.debug("Verify the database entry for virtual machine: %s" % self.small_virtual_machine.id) + self.debug("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) self.assertNotEqual( len(qresultset), 0, @@ -488,7 +567,7 @@ class TestVMLifeCycle(cloudstackTestCase): """Test migrate VM """ cmd = migrateVirtualMachine.migrateVirtualMachineCmd() - cmd.hostid = services["hostid"] + cmd.hostid = self.services["hostid"] cmd.virtualmachineid = self.small_virtual_machine.id self.apiclient.migrateVirtualMachine(cmd) @@ -512,7 +591,7 @@ class TestVMLifeCycle(cloudstackTestCase): self.assertEqual( vm_response.hostid, - services["hostid"], + self.services["hostid"], "Check destination hostID of migrated VM" ) return @@ -529,7 +608,7 @@ class TestVMLifeCycle(cloudstackTestCase): cmd.name = 'expunge.delay' response = self.apiclient.listConfigurations(cmd)[0] - time.sleep(int(response.value)) + time.sleep(int(response.value) + 10) cmd = listVirtualMachines.listVirtualMachinesCmd() cmd.id = self.small_virtual_machine.id @@ -541,9 +620,9 @@ class TestVMLifeCycle(cloudstackTestCase): "Check Expunged virtual machine is listVirtualMachines" ) - self.debug("Verify the database entry for virtual machine: %s" %self.small_virtual_machine.id) - self.debug("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" %self.small_virtual_machine.id) + self.debug("Verify the database entry for virtual machine: %s" % self.small_virtual_machine.id) + self.debug("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select state from vm_instance where id = %s;" % self.small_virtual_machine.id) self.assertNotEqual( len(qresultset), 0, @@ -557,8 +636,8 @@ class TestVMLifeCycle(cloudstackTestCase): "Check virtual machine state in VM_INSTANCES table" ) - self.debug("select instance_id from nics where instance_id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select instance_id from nics where instance_id = %s;" %self.small_virtual_machine.id) + self.debug("select instance_id from nics where instance_id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select instance_id from nics where instance_id = %s;" % self.small_virtual_machine.id) qresult = qresultset[0] self.assertEqual( @@ -568,8 +647,8 @@ class TestVMLifeCycle(cloudstackTestCase): ) - self.debug("select instance_id from volumes where instance_id = %s;" %self.small_virtual_machine.id) - qresultset = self.dbclient.execute("select instance_id from volumes where instance_id = %s;" %self.small_virtual_machine.id) + self.debug("select instance_id from volumes where instance_id = %s;" % self.small_virtual_machine.id) + qresultset = self.dbclient.execute("select instance_id from volumes where instance_id = %s;" % self.small_virtual_machine.id) qresult = qresultset[0] self.assertEqual( @@ -590,7 +669,7 @@ class TestVMLifeCycle(cloudstackTestCase): # 5. Detach ISO #6. Check the device is properly detached by logging into VM - iso = Iso.create(self.apiclient, services["iso"]) + iso = Iso.create(self.apiclient, self.services["iso"]) self.cleanup.append(iso) iso.download(self.apiclient) @@ -600,17 +679,17 @@ class TestVMLifeCycle(cloudstackTestCase): cmd.virtualmachineid = self.virtual_machine.id self.apiclient.attachIso(cmd) - ssh_client = self.virtual_machine.get_ssh_client(services["small"]["ipaddress"]) + ssh_client = self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress) - cmds = [ "mkdir -p %s" %services["mount_dir"], - "mount -rt iso9660 %s %s" %(services["diskdevice"], services["mount_dir"]), + cmds = [ "mkdir -p %s" % self.services["mount_dir"], + "mount -rt iso9660 %s %s" % (self.services["diskdevice"], self.services["mount_dir"]), ] for c in cmds: res = ssh_client.execute(c) self.assertEqual(res, [], "Check mount is successful or not") - c = "fdisk -l|grep %s|head -1" % services["diskdevice"] + c = "fdisk -l|grep %s|head -1" % self.services["diskdevice"] res = ssh_client.execute(c) #Disk /dev/xvdd: 4393 MB, 4393723904 bytes actual_disk_size = res[0].split()[4] @@ -618,7 +697,7 @@ class TestVMLifeCycle(cloudstackTestCase): self.assertEqual(str(iso.size), actual_disk_size, "Check size of the attached ISO") #Unmount ISO - command = "umount %s" % services["diskdevice"] + command = "umount %s" % self.services["diskdevice"] ssh_client.execute(command) #Detach from VM @@ -627,7 +706,7 @@ class TestVMLifeCycle(cloudstackTestCase): self.apiclient.detachIso(cmd) res = ssh_client.execute(c) - result = services["diskdevice"] in res[0].split() + result = self.services["diskdevice"] in res[0].split() self.assertEqual(result, False, "Check if ISO is detached from virtual machine") - return \ No newline at end of file + return diff --git a/tools/testClient/testcase/BVT-tests/test_volumes.py b/tools/testClient/testcase/BVT-tests/test_volumes.py index db4478cffe5..6c5306fa99e 100644 --- a/tools/testClient/testcase/BVT-tests/test_volumes.py +++ b/tools/testClient/testcase/BVT-tests/test_volumes.py @@ -7,41 +7,100 @@ #Import Local Modules from cloudstackTestCase import * from cloudstackAPI import * -from settings import * from utils import * from base import * +import remoteSSHClient #Import System modules import os import urllib2 import time import tempfile -services = TEST_VOLUME_SERVICES +class Services: + """Test Volume Services + """ + + def __init__(self): + self.services = { + "volume_offerings": { + 0: { + "offerings": 1, + "volumeoffering": 3, + "diskname": "TestDiskServ", + "zoneid": 1, + "diskofferingid": 3, + "account": 'testuser', # Account for which volume offering is created + "domainid": 1, + }, + 1: { + "offerings": 1, + "volumeoffering": 4, + "diskname": "TestDiskServ", + "zoneid": 1, + "diskofferingid": 3, + "account": 'testuser', + "domainid": 1, + }, + 2: { + "offerings": 1, + "volumeoffering": 5, + "diskname": "TestDiskServ", + "zoneid": 1, + "diskofferingid": 3, + "account": 'testuser', + "domainid": 1, + }, + }, + "customdiskofferingid": 16, #Custom disk offering should be availale + "customdisksize": 2, # GBs + "volumeoffering": 3, + "serviceoffering": 1, + "template": 206, + "zoneid": 1, + "username": "root", # Creds for SSH to VM + "password": "fr3sca", + "ssh_port": 22, + "diskname": "TestDiskServ", + "hypervisor": 'XenServer', + "account": 'testuser', # Account for VM instance + "domainid": 1, + "ipaddressid": 4, + # Optional, If not given Public IP will be assigned for that account before NAT rule creation + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + "diskdevice": "/dev/sda", + } class TestCreateVolume(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = fetch_api_client() - cls.virtual_machine = VirtualMachine.create(cls.api_client, services) - cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, services) + cls.services = Services().services + cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services) + cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, cls.services) + cls._cleanup = [cls.nat_rule, cls.virtual_machine] def setUp(self): self.apiClient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.cleanup= [] + self.cleanup = [] def test_01_create_volume(self): """Test Volume creation for all Disk Offerings (incl. custom) """ self.volumes = [] - for k,v in services["volume_offerings"].items(): + for k, v in self.services["volume_offerings"].items(): volume = Volume.create(self.apiClient, v) self.volumes.append(volume) self.cleanup.append(volume) - self.volumes.append(Volume.create_custom_disk(self.apiClient, services)) + volume = Volume.create_custom_disk(self.apiClient, self.services) + self.volumes.append(volume) + self.cleanup.append(volume) + #Attach a volume with different disk offerings and check the memory allocated to each of them for volume in self.volumes: cmd = listVolumes.listVolumesCmd() @@ -49,24 +108,24 @@ class TestCreateVolume(cloudstackTestCase): list_volume_response = self.apiClient.listVolumes(cmd) self.assertNotEqual(list_volume_response, None, "Check if volume exists in ListVolumes") - qresultset = self.dbclient.execute("select id from volumes where id = %s" %volume.id) + qresultset = self.dbclient.execute("select id from volumes where id = %s" % volume.id) self.assertNotEqual(len(qresultset), 0, "Check if volume exists in Database") - attached_volume = self.virtual_machine.attach_volume(self.apiClient,volume) - ssh = self.virtual_machine.get_ssh_client(services["ipaddress"]) + attached_volume = self.virtual_machine.attach_volume(self.apiClient, volume) - ssh.execute("shutdown -r now") + ssh = self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress) + + ssh.execute("reboot") #Sleep to ensure the machine is rebooted properly time.sleep(120) - - ssh = self.virtual_machine.get_ssh_client(services["ipaddress"], True) - c = "fdisk -l|grep %s|head -1" % services["diskdevice"] + ssh = self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress, reconnect = True) + c = "fdisk -l|grep %s|head -1" % self.services["diskdevice"] res = ssh.execute(c) #Disk /dev/sda: 21.5 GB, 21474836480 bytes actual_disk_size = res[0].split()[4] self.assertEqual(str(list_volume_response[0].size), actual_disk_size, "Check if promised disk size actually available") - self.virtual_machine.detach_volume(self.apiClient,volume) + self.virtual_machine.detach_volume(self.apiClient, volume) def tearDown(self): #Clean up, terminate the created templates @@ -76,26 +135,28 @@ class TestCreateVolume(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.nat_rule.delete(cls.api_client) - cls.virtual_machine.delete(cls.api_client) + cls.api_client = fetch_api_client() + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) class TestVolumes(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = fetch_api_client() - cls.virtual_machine = VirtualMachine.create(cls.api_client, services) - cls.volume = Volume.create(cls.api_client, services) + cls.services = Services().services + cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services) + cls.nat_rule = NATRule.create(cls.api_client, cls.virtual_machine, cls.services) + cls.volume = Volume.create(cls.api_client, self.services) + cls._cleanup = [cls.nat_rule, cls.virtual_machine, cls.volume] @classmethod def tearDownClass(cls): try: - cls.virtual_machine.delete(cls.api_client) - cls.volume.delete(cls.api_client) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" %e) + raise Exception("Warning: Exception during cleanup : %s" % e) def setUp(self): self.apiClient = self.testClient.getApiClient() @@ -104,7 +165,7 @@ class TestVolumes(cloudstackTestCase): def test_02_attach_volume(self): """Attach a created Volume to a Running VM """ - self.virtual_machine.attach_volume(self.volume) + self.virtual_machine.attach_volume(self.apiClient, self.volume) #Sleep to ensure the current state will reflected in other calls time.sleep(60) @@ -116,15 +177,19 @@ class TestVolumes(cloudstackTestCase): volume = list_volume_response[0] self.assertNotEqual(volume.virtualmachineid, None, "Check if volume state (attached) is reflected") - qresultset = self.dbclient.execute("select instance_id, device_id from volumes where id = %s" %self.volume.id) + qresultset = self.dbclient.execute("select instance_id, device_id from volumes where id = %s" % self.volume.id) self.assertNotEqual(len(qresultset), 0, "Check if volume exists in Database") qresult = qresultset[0] self.assertEqual(qresult[0], self.virtual_machine.id, "Check if volume is assc. with virtual machine in Database") #self.assertEqual(qresult[1], 0, "Check if device is valid in the database") + cmd = listPublicIpAddresses.listPublicIpAddressesCmd() + cmd.id = self.services["ipaddressid"] + public_ip = self.apiclient.listPublicIpAddresses(cmd)[0] + #Format the attached volume to a known fs - format_volume_to_ext3(self.virtual_machine.get_ssh_client(services["ipaddress"])) + format_volume_to_ext3(self.virtual_machine.get_ssh_client(self.nat_rule.ipaddress)) def test_03_download_attached_volume(self): """Download a Volume attached to a VM @@ -133,7 +198,7 @@ class TestVolumes(cloudstackTestCase): cmd = extractVolume.extractVolumeCmd() cmd.id = self.volume.id cmd.mode = "HTTP_DOWNLOAD" - cmd.zoneid = services["zoneid"] + cmd.zoneid = self.services["zoneid"] #A proper exception should be raised; downloading attach VM is not allowed with self.assertRaises(Exception): self.apiClient.deleteVolume(cmd) @@ -152,7 +217,7 @@ class TestVolumes(cloudstackTestCase): def test_05_detach_volume(self): """Detach a Volume attached to a VM """ - self.virtual_machine.detach_volume(self.virtual_machine) + self.virtual_machine.detach_volume(self.apiClient, self.virtual_machine) #Sleep to ensure the current state will reflected in other calls time.sleep(60) cmd = listVolumes.listVolumesCmd() @@ -163,7 +228,7 @@ class TestVolumes(cloudstackTestCase): volume = list_volume_response[0] self.assertEqual(volume.virtualmachineid, None, "Check if volume state (detached) is reflected") - qresultset = self.dbclient.execute("select instance_id, device_id from volumes where id = %s" %self.volume.id) + qresultset = self.dbclient.execute("select instance_id, device_id from volumes where id = %s" % self.volume.id) self.assertNotEqual(len(qresultset), 0, "Check if volume exists in Database") qresult = qresultset[0] @@ -178,7 +243,7 @@ class TestVolumes(cloudstackTestCase): cmd = extractVolume.extractVolumeCmd() cmd.id = self.volume.id cmd.mode = "HTTP_DOWNLOAD" - cmd.zoneid = services["zoneid"] + cmd.zoneid = self.services["zoneid"] extract_vol = self.apiClient.extractVolume(cmd) #Attempt to download the volume and save contents locally @@ -192,7 +257,7 @@ class TestVolumes(cloudstackTestCase): except Exception as e: print e - self.fail("Extract Volume Failed with invalid URL %s (vol id: %s)" %(extract_vol.url, self.volume.id)) + self.fail("Extract Volume Failed with invalid URL %s (vol id: %s)" % (extract_vol.url, self.volume.id)) def test_07_delete_detached_volume(self): """Delete a Volume unattached to an VM diff --git a/tools/testClient/testcase/BVT-tests/utils.py b/tools/testClient/testcase/BVT-tests/utils.py index e4b20dcfa3b..ce8bea15240 100644 --- a/tools/testClient/testcase/BVT-tests/utils.py +++ b/tools/testClient/testcase/BVT-tests/utils.py @@ -16,7 +16,7 @@ import logging import string import random -def random_gen(size=6, chars=string.ascii_uppercase + string.digits): +def random_gen(size = 6, chars = string.ascii_uppercase + string.digits): """Generate Random Strings of variable length""" return ''.join(random.choice(chars) for x in range(size)) @@ -25,7 +25,7 @@ def cleanup_resources(api_client, resources): for obj in resources: obj.delete(api_client) -def is_server_ssh_ready(ipaddress, port, username, password, retries=50): +def is_server_ssh_ready(ipaddress, port, username, password, retries = 50): """Return ssh handle else wait till sshd is running""" loop_cnt = retries while True: @@ -45,21 +45,21 @@ def is_server_ssh_ready(ipaddress, port, username, password, retries=50): return ssh -def format_volume_to_ext3(ssh_client, device="/dev/sda" ): +def format_volume_to_ext3(ssh_client, device = "/dev/sda"): """Format attached storage to ext3 fs""" cmds = [ - "echo -e 'n\np\n1\n\n\nw' | fdisk %s" %device, - "mkfs.ext3 %s1" %device, + "echo -e 'n\np\n1\n\n\nw' | fdisk %s" % device, + "mkfs.ext3 %s1" % device, ] for c in cmds: ssh_client.execute(c) -def fetch_api_client(config_file='datacenterCfg'): +def fetch_api_client(config_file = 'datacenterCfg'): """Fetch the Cloudstack API Client""" config = configGenerator.get_setup_config(config_file) mgt = config.mgtSvr[0] testClientLogger = logging.getLogger("testClient") - asyncTimeout=3600 + asyncTimeout = 3600 return cloudstackAPIClient.CloudStackAPIClient( cloudstackConnection.cloudConnection( mgt.mgtSvrIp,