def tearDownClass(cls): try: zoneList = Zone.list(cls.apiclient, id=cls.zone.id) if zoneList[0].allocationstate == DISABLED: cmd = updateZone.updateZoneCmd() cmd.id = zoneList[0].id cmd.allocationstate = ENABLED cls.apiclient.updateZone(cmd) cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e)
def test_01_zones(self): """Check the status of zones""" # Validate the following # 1. List zones # 2. Check allocation state is "enabled" or not zones = Zone.list(self.apiclient, id=self.zone.id, listall=True) self.assertEqual(isinstance(zones, list), True, "Check if listZones returns a valid response") for zone in zones: self.assertEqual(zone.allocationstate, 'Enabled', "Zone allocation state should be enabled") return
def test_nuage_vpc_network_multizone(self): """ Test basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones """ # Repeat the tests in the above testcase "test_nuage_vpc_network" on multiple zones self.debug("Testing basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones...") zones = Zone.list(self.api_client) if len(zones) == 1: self.skipTest("There is only one Zone configured: skipping test") for zone in zones: self.debug("Zone - %s" % zone.name) self.setUpClass(zone=zone) self.test_nuage_vpc_network()
def test_nuage_vpc_network_multizone(self): """ Test basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones """ # Repeat the tests in the above testcase "test_nuage_vpc_network" on multiple zones self.debug( "Testing basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones..." ) zones = Zone.list(self.api_client) if len(zones) == 1: self.skipTest("There is only one Zone configured: skipping test") for zone in zones: self.debug("Zone - %s" % zone.name) self.setUpClass(zone=zone) self.test_nuage_vpc_network()
def test_04_list_zones_with_no_params(self): """ Test list zones """ zonesavailable = 0 listallzones = Zone.list(self.user_api_client) self.assertEqual(isinstance(listallzones, list), True, "Check list zones response returns a valid list") for zone1 in listallzones: if zone1.allocationstate == "Enabled": zonesavailable = zonesavailable + 1 if zonesavailable < 1: self.fail("Check if zones are listed") return
def test_04_list_zones_with_no_params(self): """ Test list zones """ zonesavailable=0 listallzones=Zone.list(self.user_api_client) self.assertEqual( isinstance(listallzones, list), True, "Check list zones response returns a valid list" ) for zone1 in listallzones: if zone1.allocationstate=="Enabled": zonesavailable=zonesavailable+1 if zonesavailable<1: self.fail("Check if zones are listed") return
def test_01_zones(self): """Check the status of zones""" # Validate the following # 1. List zones # 2. Check allocation state is "enabled" or not zones = Zone.list( self.apiclient, id=self.zone.id, listall=True ) self.assertEqual( isinstance(zones, list), True, "Check if listZones returns a valid response" ) for zone in zones: self.assertEqual( zone.allocationstate, 'Enabled', "Zone allocation state should be enabled" ) return
def setUpClass(cls): testClient = super(TestTemplates, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls._cleanup = [] cls.services = testClient.getParsedTestDataConfig() cls.unsupportedHypervisor = False cls.hypervisor = testClient.getHypervisorInfo() if cls.hypervisor.lower() in ['lxc']: # Template creation from root volume is not supported in LXC cls.unsupportedHypervisor = True return # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cls.zones = Zone.list(cls.apiclient) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") cls.disk_offering = DiskOffering.create(cls.apiclient, cls.services["disk_offering"]) template = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"]) if template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services[ "ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["zoneid"] = cls.zone.id cls.services["template_2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid cls.account = Account.create(cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id) cls.user = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"]) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"]) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) list_volume = Volume.list(cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True) try: cls.volume = list_volume[0] except Exception as e: raise Exception( "Exception: Unable to find root volume foe VM: %s - %s" % (cls.virtual_machine.id, e)) #Create templates for Edit, Delete & update permissions testcases cls.template_1 = Template.create(cls.apiclient, cls.services["template"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid) cls.template_2 = Template.create(cls.apiclient, cls.services["template_2"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid) cls._cleanup = [ cls.service_offering, cls.disk_offering, cls.account, cls.user ]
def test_04_copy_template(self): """ @Desc: Test to copy Template from one zone to another @steps: Step1: Listing Zones available for a user Step2: Verifying if the zones listed are greater than 1. If Yes continuing. If not halting the test. Step3: Listing all the templates for a user in zone1 Step4: Verifying that no templates are listed Step5: Listing all the templates for a user in zone2 Step6: Verifying that no templates are listed Step7: Creating a Template in zone 1 Step8: Listing all the Templates again for a user in zone1 Step9: Verifying that list size is 1 Step10: Listing all the templates for a user in zone2 Step11: Verifying that no templates are listed Step12: Copying the template created in step7 from zone1 to zone2 Step13: Listing all the templates for a user in zone2 Step14: Verifying that list size is 1 Step15: Listing all the Templates for a user in zone1 Step16: Verifying that list size is 1 """ # Listing Zones available for a user zones_list = Zone.list( self.userapiclient, available=True ) status = validateList(zones_list) self.assertEquals( PASS, status[0], "Failed to list Zones" ) if not len(zones_list) > 1: raise unittest.SkipTest("Not enough zones exist to copy template") else: # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone1, "Templates listed for newly created User in Zone1" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone2, "Templates listed for newly created User in Zone2" ) self.services["privatetemplate"][ "ostype"] = self.services["ostype"] # Listing Hypervisors in Zone 1 hypervisor_list = Hypervisor.list( self.apiClient, zoneid=zones_list[0].id ) status = validateList(zones_list) self.assertEquals( PASS, status[0], "Failed to list Hypervisors in Zone 1" ) # Creating aTemplate in Zone 1 template_created = Template.register( self.userapiclient, self.services["privatetemplate"], zones_list[0].id, hypervisor=hypervisor_list[0].name ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_templates_zone1) self.assertEquals( PASS, status[0], "Templates creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone1), "Failed to create a Template" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no Templates are listed self.assertIsNone( list_templates_zone2, "Templates listed for newly created User in Zone2" ) # Verifying the state of the template to be ready. If not waiting # for state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail( "Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Copying the Template from Zone1 to Zone2 copied_template = template_created.copy( self.userapiclient, sourcezoneid=template_created.zoneid, destzoneid=zones_list[1].id ) self.assertIsNotNone( copied_template, "Copying Template from Zone1 to Zone2 failed" ) # Listing all the Templates for a User in Zone 1 list_templates_zone1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_templates_zone1) self.assertEquals( PASS, status[0], "Templates creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone1), "Failed to create a Template" ) # Listing all the Templates for a User in Zone 2 list_templates_zone2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], zoneid=zones_list[1].id ) status = validateList(list_templates_zone2) self.assertEquals( PASS, status[0], "Template failed to copy into Zone2" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_zone2), "Template failed to copy into Zone2" ) self.assertNotEquals( "Connection refused", list_templates_zone2[0].status, "Failed to copy Template" ) self.assertEquals( True, list_templates_zone2[0].isready, "Failed to copy Template" ) del self.services["privatetemplate"]["ostype"] return
tc_run_logger = log_obj.getLogger() else: print "\n=== Log Creation Failed. Please Check ===" exit(1) obj_tc_client = CSTestClient(cfg.mgtSvr[0], cfg.dbSvr, logger=tc_run_logger) if obj_tc_client and obj_tc_client.createTestClient() == FAILED: print "\n=== TestClient Creation Failed ===" exit(1) if (options.input) and (os.path.isfile(options.input)): apiClient = obj_tc_client.getApiClient() tmp_dict = {} zones = Zone.list(apiClient) if zones: for zone in zones: print "zone name={}, id={}".format(zone.name, zone.id) if zone.allocationstate == 'Enabled': print "Disable zone" zoneCmd = updateZone.updateZoneCmd() zoneCmd.id = zone.id zoneCmd.allocationstate = 'Disabled' apiClient.updateZone(zoneCmd) ssvms = list_ssvms(apiClient) if ssvms: for ssvm in ssvms: print "ssvm name={}, id={}".format(ssvm.name, ssvm.id) print "Destroy SSVM"
def test_04_copy_iso(self): """ @Desc: Test to copy ISO from one zone to another @steps: Step1: Listing Zones available for a user Step2: Verifying if the zones listed are greater than 1. If Yes continuing. If not halting the test. Step3: Listing all the ISO's for a user in zone1 Step4: Verifying that no ISO's are listed Step5: Listing all the ISO's for a user in zone2 Step6: Verifying that no ISO's are listed Step7: Creating an ISO in zone 1 Step8: Listing all the ISO's again for a user in zone1 Step9: Verifying that list size is 1 Step10: Listing all the ISO's for a user in zone2 Step11: Verifying that no ISO's are listed Step12: Copying the ISO created in step7 from zone1 to zone2 Step13: Listing all the ISO's for a user in zone2 Step14: Verifying that list size is 1 Step15: Listing all the ISO's for a user in zone1 Step16: Verifying that list size is 1 """ # Listing Zones available for a user zones_list = Zone.list( self.userapiclient, available=True ) status = validateList(zones_list) self.assertEquals( PASS, status[0], "Failed to list Zones" ) if not len(zones_list) > 1: self.skipTest("Enough zones doesnot exists to copy iso") else: # Listing all the ISO's for a User in Zone 1 list_isos_zone1 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[0].id ) # Verifying that no ISO's are listed self.assertIsNone( list_isos_zone1, "ISO's listed for newly created User in Zone1" ) # Listing all the ISO's for a User in Zone 2 list_isos_zone2 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no ISO's are listed self.assertIsNone( list_isos_zone2, "ISO's listed for newly created User in Zone2" ) self.services["iso"]["zoneid"] = zones_list[0].id # Creating an ISO in Zone 1 iso_created = Iso.create( self.userapiclient, self.services["iso"] ) self.assertIsNotNone( iso_created, "ISO creation failed" ) self.cleanup.append(iso_created) # Listing all the ISO's for a User in Zone 1 list_isos_zone1 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_isos_zone1) self.assertEquals( PASS, status[0], "ISO creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_isos_zone1), "Failed to create a Template" ) # Listing all the ISO's for a User in Zone 2 list_isos_zone2 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[1].id ) # Verifying that no ISO's are listed self.assertIsNone( list_isos_zone2, "ISO's listed for newly created User in Zone2" ) # Verifying the state of the ISO to be ready. If not waiting for state to become ready iso_ready = False count = 0 while iso_ready is False: list_iso = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], id=iso_created.id ) status = validateList(list_iso) self.assertEquals( PASS, status[0], "Failed to list ISO by Id" ) if list_iso[0].isready is True: iso_ready = True elif (str(list_iso[0].status) == "Error"): self.fail("Created ISO is in Errored state") break elif count > 10: self.fail("Timed out before ISO came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Copying the ISO from Zone1 to Zone2 copied_iso = Iso.copy( self.userapiclient, iso_created.id, sourcezoneid=iso_created.zoneid, destzoneid=zones_list[1].id ) self.assertIsNotNone( copied_iso, "Copying ISO from Zone1 to Zone2 failed" ) # Listing all the ISO's for a User in Zone 1 list_isos_zone1 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[0].id ) status = validateList(list_isos_zone1) self.assertEquals( PASS, status[0], "ISO creation failed in Zone1" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_isos_zone1), "Failed to create a Template" ) # Listing all the ISO's for a User in Zone 2 list_isos_zone2 = Iso.list( self.userapiclient, listall=self.services["listall"], isofilter=self.services["templatefilter"], zoneid=zones_list[1].id ) status = validateList(list_isos_zone2) self.assertEquals( PASS, status[0], "ISO failed to copy into Zone2" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_isos_zone2), "ISO failed to copy into Zone2" ) self.assertNotEquals( "Connection refused", list_isos_zone2[0].status, "Failed to copy ISO" ) self.assertEquals( True, list_isos_zone2[0].isready, "Failed to copy ISO" ) del self.services["iso"]["zoneid"] return
def setUpClass(cls): testClient = super(TestTemplates, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls._cleanup = [] cls.services = testClient.getParsedTestDataConfig() cls.unsupportedHypervisor = False cls.hypervisor = testClient.getHypervisorInfo() if cls.hypervisor.lower() in ['lxc']: # Template creation from root volume is not supported in LXC cls.unsupportedHypervisor = True return # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cls.zones = Zone.list(cls.apiclient) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") cls.disk_offering = DiskOffering.create( cls.apiclient, cls.services["disk_offering"] ) template = get_template( cls.apiclient, cls.zone.id, cls.services["ostype"] ) if template == FAILED: assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["zoneid"] = cls.zone.id cls.services["template_2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid cls.account = Account.create( cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) cls.user = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) list_volume = Volume.list( cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True ) try: cls.volume = list_volume[0] except Exception as e: raise Exception( "Exception: Unable to find root volume foe VM: %s - %s" % (cls.virtual_machine.id, e)) #Create templates for Edit, Delete & update permissions testcases cls.template_1 = Template.create( cls.apiclient, cls.services["template"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid ) cls.template_2 = Template.create( cls.apiclient, cls.services["template_2"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid ) cls._cleanup = [ cls.service_offering, cls.disk_offering, cls.account, cls.user ]
def test_01_disable_enable_zone(self): """disable enable zone 1. Disable zone and verify following things: For admin user: 1. Should be create to start/stop exsiting vms 2. Should be create to deploy new vm, snapshot,volume, template,iso in the same zone For Non-admin user: 1. Should be create to start/stop exsiting vms 2. Should not be create to deploy new vm, snapshot,volume, template,iso in the same zone 2. Enable the above disabled zone and verify that: -All users should be create to deploy new vm, snapshot,volume,template,iso in the same zone 3. Try to delete the zone and it should fail with error message: -"The zone is not deletable because there are servers running in this zone" """ # Step 1 vm_user = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id ) vm_root = VirtualMachine.create( self.apiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id ) cmd = updateZone.updateZoneCmd() cmd.id = self.zone.id cmd.allocationstate = DISABLED self.apiclient.updateZone(cmd) zoneList = Zone.list(self.apiclient, id=self.zone.id) self.assertEqual(zoneList[0].allocationstate, DISABLED, "Check if the zone is in disabled state" ) # Both user and admin vms shoul be running self.assertEqual(vm_user.state, RUNNING, "Verify that the user vm is running") self.assertEqual(vm_root.state, RUNNING, "Verify that the admin vm is running") vm_root.stop(self.apiclient) vm_user.stop(self.apiclient) root_state = self.dbclient.execute( "select state from vm_instance where name='%s'" % vm_root.name)[0][0] user_state = self.dbclient.execute( "select state from vm_instance where name='%s'" % vm_user.name)[0][0] self.assertEqual(root_state, STOPPED, "verify that vm is Stopped") self.assertEqual(user_state, STOPPED, "verify that vm is stopped") root_volume = list_volumes( self.userapiclient, virtualmachineid=vm_root.id, type='ROOT', listall=True ) snap = Snapshot.create( self.apiclient, root_volume[0].id) self.assertNotEqual(snap, None, "Verify that admin should be \ able to create snapshot") snapshots = list_snapshots( self.apiclient, volumeid=root_volume[0].id, listall=True) template_from_snapshot = Template.create_from_snapshot( self.apiclient, snapshots[0], self.testdata["privatetemplate"]) self.assertNotEqual( template_from_snapshot, None, "Verify that admin should be able to create template" ) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.testdata["privatetemplate"]["url"] = builtin_info[0] self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1] self.testdata["privatetemplate"]["format"] = builtin_info[2] template_regis = Template.register( self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) self.assertNotEqual( template_regis, None, "Check if template gets created" ) self.assertNotEqual( template_from_snapshot, None, "Check if template gets created" ) data_volume = Volume.create( self.apiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.assertNotEqual( data_volume, None, "Check if volume gets created" ) ISO = Iso.create( self.apiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) self.assertNotEqual( ISO, None, "Check if volume gets created" ) # non-admin user should fail to create vm, snap, temp etc with self.assertRaises(Exception): VirtualMachine.create(self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id ) root_volume = list_volumes( self.userapiclient, virtualmachineid=vm_user.id, type='ROOT', listall=True ) with self.assertRaises(Exception): snap = Snapshot.create( self.userapiclient, root_volume[0].id) with self.assertRaises(Exception): Template.register( self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) with self.assertRaises(Exception): Volume.create( self.userapiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) with self.assertRaises(Exception): ISO = Iso.create( self.userapiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) # Step 2 cmd.allocationstate = ENABLED self.apiclient.updateZone(cmd) # After enabling the zone all users should be able to add new VM, # volume, template and iso root_vm_new = VirtualMachine.create( self.apiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id ) self.assertNotEqual(root_vm_new, None, "Verify that admin should create new VM") snap = Snapshot.create( self.apiclient, root_volume[0].id) self.assertNotEqual(snap, None, "Verify that admin should snashot") snapshots = list_snapshots( self.apiclient, volumeid=root_volume[0].id, listall=True) template_from_snapshot = Template.create_from_snapshot( self.apiclient, snapshots[0], self.testdata["privatetemplate"]) self.assertNotEqual( template_from_snapshot, None, "Check if template gets created" ) template_regis = Template.register( self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) self.assertNotEqual( template_regis, None, "Check if template gets created" ) self.assertNotEqual( template_from_snapshot, None, "Check if template gets created" ) data_volume = Volume.create( self.apiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.assertNotEqual( data_volume, None, "Check if volume gets created" ) ISO = Iso.create( self.apiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) self.assertNotEqual( ISO, None, "Check if volume gets created" ) root_vm_new.delete(self.apiclient) # Non root user user_vm_new = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id ) self.assertNotEqual(user_vm_new, None, "Verify that admin should create new VM") snap = Snapshot.create( self.userapiclient, root_volume[0].id) self.assertNotEqual(snap, None, "Verify that admin should snashot") snapshots = list_snapshots( self.userapiclient, volumeid=root_volume[0].id, listall=True) template_regis = Template.register( self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) self.assertNotEqual( template_regis, None, "Check if template gets created" ) self.assertNotEqual( template_from_snapshot, None, "Check if template gets created" ) data_volume = Volume.create( self.userapiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.assertNotEqual( data_volume, None, "Check if volume gets created" ) ISO = Iso.create( self.userapiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) self.assertNotEqual( ISO, None, "Check if volume gets created" ) user_vm_new.delete(self.apiclient) # Step 3 # Deletion of zone should fail if vm,volume is present on the zone with self.assertRaises(Exception): self.zone.delete(self.apiclient) return
def test_01_disable_enable_zone(self): """disable enable zone 1. Disable zone and verify following things: For admin user: 1. Should be create to start/stop exsiting vms 2. Should be create to deploy new vm, snapshot,volume, template,iso in the same zone For Non-admin user: 1. Should be create to start/stop exsiting vms 2. Should not be create to deploy new vm, snapshot,volume, template,iso in the same zone 2. Enable the above disabled zone and verify that: -All users should be create to deploy new vm, snapshot,volume,template,iso in the same zone 3. Try to delete the zone and it should fail with error message: -"The zone is not deletable because there are servers running in this zone" """ # Step 1 vm_user = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) vm_root = VirtualMachine.create( self.apiclient, self.testdata["small"], templateid=self.template.id, accountid=self.admin_account.name, domainid=self.admin_account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) cmd = updateZone.updateZoneCmd() cmd.id = self.zone.id cmd.allocationstate = DISABLED self.apiclient.updateZone(cmd) zoneList = Zone.list(self.apiclient, id=self.zone.id) self.assertEqual(zoneList[0].allocationstate, DISABLED, "Check if the zone is in disabled state") # Both user and admin vms shoul be running self.assertEqual(vm_user.state.lower(), "running", "Verify that the user vm is running") self.assertEqual(vm_root.state.lower(), "running", "Verify that the admin vm is running") vm_root.stop(self.apiclient) vm_user.stop(self.apiclient) root_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_root.name)[0][0] user_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_user.name)[0][0] self.assertEqual(root_state.lower(), "stopped", "verify that vm is Stopped") self.assertEqual(user_state.lower(), "stopped", "verify that vm is stopped") root_volume = list_volumes(self.apiclient, virtualmachineid=vm_root.id, type="ROOT", listall=True) self.assertEqual(validateList(root_volume)[0], PASS, "list volume is empty for vmid %s" % vm_root.id) root_vm_new = VirtualMachine.create( self.apiclient, self.testdata["small"], templateid=self.template.id, accountid=self.admin_account.name, domainid=self.admin_account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) self.assertEqual(root_vm_new.state.lower(), "running", "Verify that admin should create new VM") if self.snapshotSupported: Snapshot.create(self.apiclient, root_volume[0].id) snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True) self.assertEqual( validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id ) Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.testdata["privatetemplate"]["url"] = builtin_info[0] self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1] self.testdata["privatetemplate"]["format"] = builtin_info[2] """ //commenting it for now will uncomment once expected behaviour is known Template.register( self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) """ Volume.create( self.apiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.admin_account.name, domainid=self.admin_account.domainid, diskofferingid=self.disk_offering.id, ) """ //commenting it for now will uncomment once expected behaviour is known Iso.create( self.apiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.admin_account.name, domainid=self.admin_account.domainid, ) """ # non-admin user should fail to create vm, snap, temp etc with self.assertRaises(Exception): VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) root_volume = list_volumes(self.userapiclient, virtualmachineid=vm_user.id, type="ROOT", listall=True) self.assertEqual(validateList(root_volume)[0], PASS, "list volume is empty for vmid id %s" % vm_user.id) if self.snapshotSupported: with self.assertRaises(Exception): Snapshot.create(self.userapiclient, root_volume[0].id) with self.assertRaises(Exception): Template.register(self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) with self.assertRaises(Exception): Volume.create( self.userapiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, ) with self.assertRaises(Exception): Iso.create( self.userapiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) # Step 2 cmd.allocationstate = ENABLED self.apiclient.updateZone(cmd) # After enabling the zone all users should be able to add new VM, # volume, template and iso root_vm_new = VirtualMachine.create( self.apiclient, self.testdata["small"], templateid=self.template.id, accountid=self.admin_account.name, domainid=self.admin_account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) self.assertEqual(root_vm_new.state.lower(), "running", "Verify that admin should create new VM") if self.snapshotSupported: Snapshot.create(self.apiclient, root_volume[0].id) snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True) self.assertEqual( validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id ) Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"]) Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) Volume.create( self.apiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.admin_account.name, domainid=self.admin_account.domainid, diskofferingid=self.disk_offering.id, ) Iso.create( self.apiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.admin_account.name, domainid=self.admin_account.domainid, ) # Non root user user_vm_new = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, zoneid=self.zone.id, ) self.assertEqual(user_vm_new.state.lower(), "running", "Verify that admin should create new VM") if self.snapshotSupported: Snapshot.create(self.userapiclient, root_volume[0].id) snapshots = list_snapshots(self.userapiclient, volumeid=root_volume[0].id, listall=True) self.assertEqual( validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id ) Template.register(self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id) Volume.create( self.userapiclient, self.testdata["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, ) Iso.create( self.userapiclient, self.testdata["iso2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, ) # Step 3 # Deletion of zone should fail if vm,volume is present on the zone with self.assertRaises(Exception): self.zone.delete(self.apiclient) return