def test(): global test_obj_dict volumes = [] ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern = 'L3-%s'%os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern): network_pattern = 'L3-%s'%os.environ['portgroup0'] disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) #create vm with disk vm = test_stub.create_vm_in_vcenter(vm_name = 'vm_2', image_name = ova_image_name, l3_name = network_pattern, disk_offering_uuids = [disk_offering.uuid, disk_offering.uuid] ) test_obj_dict.add_vm(vm) vm.check() vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vm = vct_ops.get_vm(content, name = 'vm_2')[0] vct_ops.delete_virtual_disk(vm, 2) vct_ops.delete_virtual_disk(vm, 2) vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) allvolumes = vct_ops.lib_get_vm_by_name('vm_2').allVolumes assert len(allvolumes) == 1 for volume in allvolumes: if volume.type == 'Data': volumes.append(volume.installPath) assert set(volumes) == set([]) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("sync after detaching disk from vm in vmware test passed.")
def test(): global vc_cluster vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() datacenter_name = os.environ.get('vcdatacenterName') datacenter = vct_ops.get_datacenter(content, datacenter_name)[0] #create vcenter cluster vc_cluster = vct_ops.create_cluster(datacenter) #create vcenter host host_name = os.environ.get('hostName3') managementIp = deploy_operations.get_host_from_scenario_file( host_name, test_lib.all_scenario_config, test_lib.scenario_file, test_lib.deploy_config) vc_host = vct_ops.add_host(vc_cluster, managementIp) #sync vcenter vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) assert vc_cluster.name == vct_ops.lib_get_vcenter_cluster_by_name( vc_cluster.name).name assert managementIp == vct_ops.lib_get_vcenter_host_by_ip( managementIp).name assert vct_ops.lib_get_vcenter_host_by_ip( managementIp).hypervisorType == "ESX" vct_ops.remove_cluster(vc_cluster) test_util.test_pass( 'Sync vcenter after creating new vcenter cluster and add host to the cluster successfully' )
def test(): global portgroup global vswitch vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vc_cluster = vct_ops.get_cluster(content)[0] #add host to vcenter cluster host_name = os.environ.get('hostName4') managementIp = deploy_operations.get_host_from_scenario_file(host_name, test_lib.all_scenario_config, test_lib.scenario_file,test_lib.deploy_config) vc_host = vct_ops.add_host(vc_cluster, managementIp) #add vswitch and portgroup vswitch1 = vct_ops.add_vswitch(vc_host, 'vSwitch1') vswitch.append('vSwitch1') for port_group in ['port_group0', 'port_group1', 'port_group2', 'port_group3']: vct_ops.add_portgroup(vc_host, 'vSwitch0', port_group) portgroup.append(port_group) #sync vcenter vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) #check assert managementIp == vct_ops.lib_get_vcenter_host_by_ip(managementIp).name assert vct_ops.lib_get_vcenter_host_by_ip(managementIp).hypervisorType == "ESX" assert 'port_group0' == vct_ops.lib_get_vcenter_l2_by_name('port_group0').name assert "L3-" + 'port_group0' == vct_ops.lib_get_vcenter_l3_by_name("L3-" +'port_group0' ).name vct_ops.remove_portgroup(vc_host, 'port_group0') portgroup.remove('port_group0') for port_group in portgroup: assert vct_ops.lib_get_vcenter_l2_by_name(port_group) == None vct_ops.add_portgroup(vc_host, 'vSwitch1', 'port_group0',0) vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) assert vct_ops.lib_get_vcenter_l2_by_name('port_group0') == None #cleanup vct_ops.remove_vswitch(vc_host,'vSwitch1') for name in portgroup: vct_ops.remove_portgroup(vc_host, name) vct_ops.remove_host(vc_host) #recover the test environment vc_origin_host = vct_ops.get_host(content)[0] #delete the virtualrouter network corresponding portgroups vct_ops.remove_portgroup(vc_origin_host, name=os.environ['l2vCenterPublicNetworkName']) vct_ops.remove_portgroup(vc_origin_host, name=os.environ['l2vCenterNoVlanNetworkName']) vct_ops.sync_vcenter(vcenter_uuid) #recover virtualrouter network deploy_operations.add_vcenter_l2l3_network(test_lib.all_scenario_config, test_lib.scenario_file,test_lib.deploy_config, acc_ops.login_as_admin()) deploy_operations.add_vcenter_vrouter(test_lib.all_scenario_config, test_lib.scenario_file,test_lib.deploy_config, acc_ops.login_as_admin()) vct_ops.sync_vcenter(vcenter_uuid) test_util.test_pass('Sync vcenter after adding host to vcenter cluster and add portgroup successfully')
def test(): global portgroup global vswitch vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vc_cluster = vct_ops.get_cluster(content)[0] #add host to vcenter cluster host_name = os.environ.get('hostName4') managementIp = deploy_operations.get_host_from_scenario_file(host_name, test_lib.all_scenario_config, test_lib.scenario_file,test_lib.deploy_config) vc_host = vct_ops.add_host(vc_cluster, managementIp) #add vswitch and portgroup vswitch1 = vct_ops.add_vswitch(vc_host, 'vSwitch1') vswitch.append('vSwitch1') for port_group in ['port_group0', 'port_group1', 'port_group2', 'port_group3']: vct_ops.add_portgroup(vc_host, 'vSwitch0', port_group) portgroup.append(port_group) #sync vcenter vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) #check assert managementIp == vct_ops.lib_get_vcenter_host_by_ip(managementIp).name assert vct_ops.lib_get_vcenter_host_by_ip(managementIp).hypervisorType == "ESX" assert 'port_group0' == vct_ops.lib_get_vcenter_l2_by_name('port_group0').name assert "L3-" + 'port_group0' == vct_ops.lib_get_vcenter_l3_by_name("L3-" +'port_group0' ).name vct_ops.remove_portgroup(vc_host, 'port_group0') portgroup.remove('port_group0') for port_group in portgroup: assert vct_ops.lib_get_vcenter_l2_by_name(port_group) == None vct_ops.add_portgroup(vc_host, 'vSwitch1', 'port_group0',0) vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) assert vct_ops.lib_get_vcenter_l2_by_name('port_group0') == None #cleanup vct_ops.remove_vswitch(vc_host,'vSwitch1') for name in portgroup: vct_ops.remove_portgroup(vc_host, name) test_util.test_pass('Sync vcenter after adding host to vcenter cluster and add portgroup successfully')
def test(): global vm volumes = [] ova_image_name = os.environ['vcenterDefaultmplate'] if os.environ['dportgroup']: network_pattern = os.environ['dportgroup'] network_pattern = 'L3-%s' % network_pattern else: network_pattern = os.environ['portgroup0'] network_pattern = 'L3-%s' % network_pattern disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) #create vm vm = test_stub.create_vm_in_vcenter(vm_name='vm_1', image_name=ova_image_name, l3_name=network_pattern) vm.check() vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vm = vct_ops.get_vm(content, name='vm_1')[0] #add 2 disks to vcenter vm disk1 = vct_ops.add_disk(vm, 2) disk2 = vct_ops.add_disk(vm, 5) disk_file = vct_ops.get_data_volume_attach_to_vm(vm) #sync vcenter vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) allvolumes = vct_ops.lib_get_vm_by_name('vm_1').allVolumes assert len(allvolumes) == 3 for volume in allvolumes: if volume.type == 'Data': volumes.append(volume.installPath) assert set(volumes) ^ set(disk_file) == set([]) #cleanup vct_ops.destroy_vm(vm) vct_ops.sync_vcenter(vcenter_uuid) test_util.test_pass("sync after adding disk to vm in vmware test passed.")
def test(): global test_obj_dict volumes = [] ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern = 'L3-%s' % os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern): network_pattern = 'L3-%s' % os.environ['portgroup0'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) #create vm with disk vm = test_stub.create_vm_in_vcenter( vm_name='vm_2', image_name=ova_image_name, l3_name=network_pattern, disk_offering_uuids=[disk_offering.uuid, disk_offering.uuid]) test_obj_dict.add_vm(vm) vm.check() vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vm = vct_ops.get_vm(content, name='vm_2')[0] vct_ops.delete_virtual_disk(vm, 2) vct_ops.delete_virtual_disk(vm, 2) vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) allvolumes = vct_ops.lib_get_vm_by_name('vm_2').allVolumes assert len(allvolumes) == 1 for volume in allvolumes: if volume.type == 'Data': volumes.append(volume.installPath) assert set(volumes) == set([]) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass( "sync after detaching disk from vm in vmware test passed.")
def test(): global vm volumes = [] ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern = 'L3-%s'%os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern): network_pattern = 'L3-%s'%os.environ['portgroup0'] disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) #create vm vm = test_stub.create_vm_in_vcenter(vm_name = 'vm_1', image_name = ova_image_name, l3_name = network_pattern) vm.check() vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vm = vct_ops.get_vm(content, name = 'vm_1')[0] #add 2 disks to vcenter vm disk1 = vct_ops.add_disk(vm, 2) disk2 = vct_ops.add_disk(vm, 5) disk_file = vct_ops.get_data_volume_attach_to_vm(vm) #sync vcenter vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) allvolumes = vct_ops.lib_get_vm_by_name('vm_1').allVolumes assert len(allvolumes) == 3 for volume in allvolumes: if volume.type == 'Data': volumes.append(volume.installPath) assert set(volumes) ^ set(disk_file) == set([]) #cleanup vct_ops.destroy_vm(vm) vct_ops.sync_vcenter(vcenter_uuid) test_util.test_pass("sync after adding disk to vm in vmware test passed.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name='test_volume_after_sync_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume.detach() volume.check() volume1.attach(vm) volume1.check() volume1.delete() volume1.check() test_util.test_dsc('Sync vcenter') vc_name = os.environ['vcenter'] vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc_name).uuid test_util.test_logger(vcenter_uuid) vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) test_util.test_dsc('check volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume.status != 'Ready' or db_volume1.status != 'Deleted': test_util.test_fail( "check data volumes fail after synchronizing vcenter") #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() volume_installPath = vc_ps.url.split( '//')[1] + db_volume.installPath.split('[' + vc_ps.name + ']')[1].lstrip() test_util.test_logger(volume_installPath) cmd = 'rm -f %s' % volume_installPath vchost_user = os.environ['vchostUser'] vchost_password = os.environ['vchostpwd'] result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user, vchost_password, cmd, 180) atexit.register(connect.Disconnect, SI) test_util.test_dsc('Sync vcenter') vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume: test_util.test_fail( "check data volumes fail after synchronizing vcenter") #cleanup vm.destroy() vm.expunge() volume1.expunge() test_util.test_pass("Test sync volume in vcenter passed.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name = 'test_volume_after_sync_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) volume.check() volume.detach() volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume1.attach(vm) volume1.check() volume1.delete() volume1.check() test_util.test_dsc('Sync vcenter') vcenter_uuid = vct_ops.lib_get_vcenter_by_name(os.environ['vcenter']).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) test_util.test_dsc('check volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume.status != 'Ready' or db_volume1.status != 'Deleted': test_util.test_fail("check data volumes fail after synchronizing vcenter") #delete volume file volume_installPath = vc_ps.url.split('//')[1] + db_volume.installPath.split('[' + vc_ps.name + ']')[1].lstrip() test_util.test_logger(volume_installPath) cmd = 'rm -f %s' %volume_installPath vchost_user = os.environ['vchostUser'] vchost_password = os.environ['vchostpwd'] result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user, vchost_password, cmd, 180) test_util.test_dsc('Sync vcenter') vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume: test_util.test_fail("check data volumes fail after synchronizing vcenter") #cleanup vm.destroy() vm.expunge() volume1.expunge() test_util.test_pass("Test sync volume in vcenter passed.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and attach volume') vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_vcenter_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('vcenter3_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) test_util.test_logger(volume.target_vm.state) volume.check() test_util.test_dsc('Destroy vm and its attached data volume both') vm.destroy() volume.delete() vm.check() volume.check() test_util.test_dsc('Check in vcenter after destroying vm and its attached data volume both in zstack') #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() vc_vm = vm_checker.get_obj(content, [vim.VirtualMachine], name='test_for_sync_vcenter_vm') test_util.test_logger(vc_vm.summary.runtime.powerState) if not (vc_vm.summary.runtime.powerState == 'poweredOff'): test_util.test_fail("Vm should stop in vcenter") atexit.register(connect.Disconnect, SI) test_util.test_dsc('Sync vcenter') vc_name = os.environ['vcenter'] vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc_name).uuid test_util.test_logger(vcenter_uuid) vct_ops.sync_vcenter(vcenter_uuid) #After synchronization, wait for the database update time.sleep(5) test_util.test_dsc('check vm and volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) test_util.test_logger(db_volume.status) if db_volume.status != 'Deleted': test_util.test_fail("check data volume fail") db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Destroyed': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.recover() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Stopped' and len(db_vm.allVolumes) == 1 and db_vm.allVolumes[0].type == 'Root' and db_vm.allVolumes[0].status == 'Ready': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.destroy() vm.expunge() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) if test_lib.lib_get_vm_by_uuid(vm.vm.uuid): test_util.test_fail("check vm fail: vm has been expunged") #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() vc_vm = vm_checker.get_obj(content, [vim.VirtualMachine], name='test_for_sync_vcenter_vm') if not isinstance(vc_vm, list): test_util.test_fail("check vm fail: vm has been expunged.") volume.expunge() test_util.test_pass("Sync vcenter test passed after destroying vm and its attached data volume both.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name='test_volume_after_sync_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) volume.check() volume.detach() volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume1.attach(vm) volume1.check() volume1.delete() volume1.check() test_util.test_dsc('Sync vcenter') vcenter_uuid = vct_ops.lib_get_vcenter_by_name(os.environ['vcenter']).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) test_util.test_dsc('check volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume.status != 'Ready' or db_volume1.status != 'Deleted': test_util.test_fail( "check data volumes fail after synchronizing vcenter") #delete volume file volume_installPath = vc_ps.url.split( '//')[1] + db_volume.installPath.split('[' + vc_ps.name + ']')[1].lstrip() test_util.test_logger(volume_installPath) cmd = 'rm -f %s' % volume_installPath vchost_user = os.environ['vchostUser'] vchost_password = os.environ['vchostpwd'] result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user, vchost_password, cmd, 180) test_util.test_dsc('Sync vcenter') vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume: test_util.test_fail( "check data volumes fail after synchronizing vcenter") #cleanup vm.destroy() vm.expunge() volume1.expunge() test_util.test_pass("Test sync volume in vcenter passed.")
def check_deployed_vcenter(deploy_config, scenario_config=None, scenario_file=None): vc_name = os.environ.get('vcenter') vslist = {} if xmlobject.has_element(deploy_config, 'vcenter.datacenters.datacenter'): assert deploy_config.vcenter.name_ == vc_ops.lib_get_vcenter_by_name( vc_name).name for datacenter in xmlobject.safe_list( deploy_config.vcenter.datacenters.datacenter): dportgroup_list = [] if xmlobject.has_element(datacenter, 'dswitch'): for dswitch in xmlobject.safe_list(datacenter.dswitch): for dportgroup in xmlobject.safe_list( dswitch.dportgroups.dportgroup): dportgroup_list.append(dportgroup.name_) for cluster in xmlobject.safe_list(datacenter.clusters.cluster): sign = None assert cluster.name_ == vc_ops.lib_get_vcenter_cluster_by_name( cluster.name_).name for host in xmlobject.safe_list(cluster.hosts.host): vslist[host.name_] = {'vSwitch0': ['VM Network.0']} managementIp = dep_ops.get_host_from_scenario_file( host.name_, scenario_config, scenario_file, deploy_config) assert managementIp == vc_ops.lib_get_vcenter_host_by_ip( managementIp).name assert vc_ops.lib_get_vcenter_host_by_ip( managementIp).hypervisorType == "ESX" if xmlobject.has_element(host, "iScsiStorage.vmfsdatastore"): assert host.iScsiStorage.vmfsdatastore.name_ == vc_ops.lib_get_vcenter_primary_storage_by_name( host.iScsiStorage.vmfsdatastore.name_).name assert vc_ops.lib_get_vcenter_primary_storage_by_name( host.iScsiStorage.vmfsdatastore.name_ ).type == "VCenter" assert host.iScsiStorage.vmfsdatastore.name_ == vc_ops.lib_get_vcenter_backup_storage_by_name( host.iScsiStorage.vmfsdatastore.name_).name assert vc_ops.lib_get_vcenter_backup_storage_by_name( host.iScsiStorage.vmfsdatastore.name_ ).type == "VCenter" if xmlobject.has_element(host, "vswitchs"): for vswitch in xmlobject.safe_list(host.vswitchs.vswitch): if vswitch.name_ == "vSwitch0": for port_group in xmlobject.safe_list( vswitch.portgroup): vslist[host.name_]['vSwitch0'].append( port_group.text_ + '.' + port_group.vlanId_) else: vslist[host.name_][vswitch.name_] = [] for port_group in xmlobject.safe_list( vswitch.portgroup): vslist[host.name_][vswitch.name_].append( port_group.text_ + '.' + port_group.vlanId_) if xmlobject.has_element(host, "dswitchRef"): sign = 1 for vm in xmlobject.safe_list(host.vms.vm): assert vm.name_ == vc_ops.lib_get_vm_by_name(vm.name_).name assert vc_ops.lib_get_vm_by_name( vm.name_).hypervisorType == "ESX" assert vc_ops.lib_get_vm_by_name( vm.name_).state == "Running" if xmlobject.has_element(cluster, "templates"): for template in xmlobject.safe_list( cluster.templates.template): templ_name = template.path_ tp_name = templ_name.split('/')[-1].split('.')[0] assert tp_name == vc_ops.lib_get_root_image_by_name( tp_name).name for dportgroup_name in dportgroup_list: if sign: assert dportgroup_name == vc_ops.lib_get_vcenter_l2_by_name( dportgroup_name).name assert "L3-" + dportgroup_name == vc_ops.lib_get_vcenter_l3_by_name( "L3-" + dportgroup_name).name cluster_list = vc_ops.lib_get_vcenter_l2_by_name( dportgroup_name).attachedClusterUuids if vc_ops.lib_get_vcenter_cluster_by_name( cluster.name_).uuid not in cluster_list: test_util.test_fail("dpg not sync success") else: if vc_ops.lib_get_vcenter_l2_by_name(dportgroup_name): cluster_list = vc_ops.lib_get_vcenter_l2_by_nam( dportgroup_name).attachedClusterUuids if vc_ops.lib_get_vcenter_cluster_by_name( cluster.name_).uuid in cluster_list: test_util.test_fail("dpg not sync success") else: assert vc_ops.lib_get_vcenter_l2_by_name( dportgroup_name) == None assert vc_ops.lib_get_vcenter_l3_by_name( "L3-" + dportgroup_name) == None pg_list, vlan_list, non_pg_list, non_vlan_list = get_pgs(vslist) for pg in pg_list: assert pg == vc_ops.lib_get_vcenter_l2_by_name(pg).name assert "L3-" + pg == vc_ops.lib_get_vcenter_l3_by_name("L3-" + pg).name cluster_list = vc_ops.lib_get_vcenter_l2_by_name( pg).attachedClusterUuids if vc_ops.lib_get_vcenter_cluster_by_name( cluster.name_).uuid not in cluster_list: test_util.test_fail("pg not sync success") for non_pg in non_pg_list: if vc_ops.lib_get_vcenter_l2_by_name(non_pg): cluster_list = vc_ops.lib_get_vcenter_l2_by_name( non_pg).attachedClusterUuids if vc_ops.lib_get_vcenter_cluster_by_name( cluster.name_).uuid in cluster_list: test_util.test_fail("pg not sync success") else: assert vc_ops.lib_get_vcenter_l2_by_name(non_pg) == None assert vc_ops.lib_get_vcenter_l3_by_name("L3-" + non_pg) == None
def check_deployed_vcenter(deploy_config, scenario_config = None, scenario_file = None): vc_name = os.environ.get('vcenter') vslist = {} if xmlobject.has_element(deploy_config, 'vcenter.datacenters.datacenter'): assert deploy_config.vcenter.name_ == vc_ops.lib_get_vcenter_by_name(vc_name).name for datacenter in xmlobject.safe_list(deploy_config.vcenter.datacenters.datacenter): dportgroup_list = [] if xmlobject.has_element(datacenter, 'dswitch'): for dswitch in xmlobject.safe_list(datacenter.dswitch): for dportgroup in xmlobject.safe_list(dswitch.dportgroups.dportgroup): dportgroup_list.append(dportgroup.name_) for cluster in xmlobject.safe_list(datacenter.clusters.cluster): sign = None assert cluster.name_ == vc_ops.lib_get_vcenter_cluster_by_name(cluster.name_).name cluster_uuid = vc_ops.lib_get_vcenter_cluster_by_name(cluster.name_).uuid for host in xmlobject.safe_list(cluster.hosts.host): vslist[host.name_] = {'vSwitch0':['VM Network.0']} managementIp = dep_ops.get_host_from_scenario_file(host.name_, scenario_config, scenario_file, deploy_config) assert managementIp == vc_ops.lib_get_vcenter_host_by_ip(managementIp).name assert vc_ops.lib_get_vcenter_host_by_ip(managementIp).hypervisorType == "ESX" if xmlobject.has_element(host, "iScsiStorage.vmfsdatastore"): assert host.iScsiStorage.vmfsdatastore.name_ == vc_ops.lib_get_vcenter_primary_storage_by_name(host.iScsiStorage.vmfsdatastore.name_).name assert vc_ops.lib_get_vcenter_primary_storage_by_name(host.iScsiStorage.vmfsdatastore.name_).type == "VCenter" assert host.iScsiStorage.vmfsdatastore.name_ == vc_ops.lib_get_vcenter_backup_storage_by_name(host.iScsiStorage.vmfsdatastore.name_).name assert vc_ops.lib_get_vcenter_backup_storage_by_name(host.iScsiStorage.vmfsdatastore.name_).type == "VCenter" if xmlobject.has_element(host, "vswitchs"): for vswitch in xmlobject.safe_list(host.vswitchs.vswitch): if vswitch.name_ == "vSwitch0": for port_group in xmlobject.safe_list(vswitch.portgroup): vslist[host.name_]['vSwitch0'].append(port_group.text_ + '.' + port_group.vlanId_) else: vslist[host.name_][vswitch.name_] = [] for port_group in xmlobject.safe_list(vswitch.portgroup): vslist[host.name_][vswitch.name_].append(port_group.text_ + '.' + port_group.vlanId_) if xmlobject.has_element(host, "dswitchRef"): sign = 1 for vm in xmlobject.safe_list(host.vms.vm): assert vc_ops.lib_get_vm_by_name(vm.name_) == None if xmlobject.has_element(cluster, "templates"): for template in xmlobject.safe_list(cluster.templates.template): templ_name = template.path_ tp_name = templ_name.split('/')[-1].split('.')[0] assert tp_name == vc_ops.lib_get_root_image_by_name(tp_name).name for dportgroup_name in dportgroup_list: if sign: l2 = vc_ops.lib_get_vcenter_l2_by_name_and_cluster(dportgroup_name, cluster_uuid) assert dportgroup_name == l2.name assert "L3-" + dportgroup_name == vc_ops.lib_get_vcenter_l3_by_name_and_l2("L3-" + dportgroup_name, l2.uuid).name pg_vlan_list, non_pg_vlan_list = get_pgs(vslist) for pg_vlan in pg_vlan_list: pg = pg_vlan.split('.')[0] vlan = pg_vlan.split('.')[1] l2 = vc_ops.lib_get_vcenter_l2_by_name_and_cluster(pg, cluster_uuid) assert pg == l2.name if l2.vlan: assert vlan == str(l2.vlan) assert "L3-" + pg == vc_ops.lib_get_vcenter_l3_by_name_and_l2("L3-" + pg, l2.uuid).name for non_pg_vlan in non_pg_vlan_list: non_pg = non_pg_vlan.split('.')[0] assert vc_ops.lib_get_vcenter_l2_by_name_and_cluster(non_pg, cluster_uuid) == None
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and attach volume') vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_vcenter_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('vcenter3_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) test_util.test_logger(volume.target_vm.state) volume.check() test_util.test_dsc('Destroy vm and its attached data volume both') vm.destroy() volume.delete() vm.check() volume.check() test_util.test_dsc('Sync vcenter') vc = os.environ.get('vcenter') vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc).uuid vct_ops.sync_vcenter(vcenter_uuid) #After synchronization, wait for the database update time.sleep(5) test_util.test_dsc('check vm and volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume.status != 'Deleted': test_util.test_fail("check data volume fail") db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Destroyed': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.recover() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Stopped' and len(db_vm.allVolumes) == 1 and db_vm.allVolumes[0].type == 'Root' and db_vm.allVolumes[0].status == 'Ready': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.destroy() vm.expunge() #check in vcenter SI = vct_ops.connect_vcenter(vc) content = SI.RetrieveContent() vc_vm = vct_ops.get_vm(content, name='test_for_sync_vcenter_vm')[0] if vc_vm.name == 'test_for_sync_vcenter_vm' : test_util.test_fail("check vm fail: vm has been expunged.") vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) if test_lib.lib_get_vm_by_uuid(vm.vm.uuid): test_util.test_fail("check vm fail: vm has been expunged") volume.expunge() test_util.test_pass("Sync vcenter test passed after destroying vm and its attached data volume both.")