コード例 #1
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = 'L3-%s' % os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1):
        network_pattern1 = 'L3-%s' % os.environ['portgroup0']

    disk_offering1 = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('largeDiskOfferingName'))

    vm = test_stub.create_vm_in_vcenter(vm_name='test_for_sync_volume_size_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
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid)
    volume_creation_option.set_name('test_for_sync_volume_size_volume')
    volume_creation_option.set_primary_storage_uuid(ps_uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    #SyncVolumeSize
    vol_ops.sync_volume_size(volume.get_volume().uuid)
    volume.attach(vm)
    volume.check()
    vol_ops.sync_volume_size(volume.get_volume().uuid)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Test sync volume size in vcenter passed.")
def test():
    global test_obj_dict

    #enable vmware vmotion
    SI = vct_ops.connect_vcenter(os.environ['vcenter'])
    content = SI.RetrieveContent()
    hosts = vct_ops.get_host(content)
    for host in hosts:
        vct_ops.enable_vmotion(host)

    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']
    ova_image_name = os.environ['vcenterDefaultmplate']
    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 = 'migrate_vm', image_name = ova_image_name, l3_name = network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm')
    else:
        test_util.test_dsc('Migrate vm to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm.vm.uuid, host_uuid)
        vm.update()
        vm.check()
        #check whether the specified host is effective
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm.vm).name
        #check the consistency of the migration in zstack and vmware
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm.vm.name)
        test_util.test_dsc('vm in suspended state does not allow migration')
        vm.suspend()
        candidate_host = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories
        assert candidate_host == []
        
    #create vm with disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name = 'migrate_vm_with_disk', image_name = ova_image_name, l3_name = network_pattern, disk_offering_uuids = [disk_offering.uuid])
    vm1.check()
    test_obj_dict.add_vm(vm1)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm1.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm with disk')
    else:
        test_util.test_dsc('Migrate vm with disk to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm1.vm.uuid, host_uuid)
        vm1.update()
        vm1.check()
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm1.vm).name
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm1.vm.name)
   
    #cleanup 
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Migrate vm 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.")
コード例 #4
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = 'L3-%s'%os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1):
        network_pattern1 = 'L3-%s'%os.environ['portgroup0']

    disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName'))

    vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_volume_size_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
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid)
    volume_creation_option.set_name('test_for_sync_volume_size_volume')
    volume_creation_option.set_primary_storage_uuid(ps_uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    #SyncVolumeSize
    vol_ops.sync_volume_size(volume.get_volume().uuid)
    volume.attach(vm)
    volume.check()
    vol_ops.sync_volume_size(volume.get_volume().uuid)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Test sync volume size in vcenter passed.")
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')
コード例 #6
0
def test():
    global test_obj_dict

    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']

    ova_image_name = os.environ['vcenterDefaultmplate']
    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-create', image_name = ova_image_name, l3_name = network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid
    ps1_uuid = None
    for ps in res_ops.query_resource(res_ops.VCENTER_PRIMARY_STORAGE):
        if ps.uuid != ps_uuid:
            ps1_uuid = ps.uuid
            break

    test_util.test_dsc('Create volume 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_creation_option.set_primary_storage_uuid(ps_uuid)
    volume_creation_option.set_name('vcenter_volume_ps')
    volume_ps = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume_ps)
    volume_ps.check()
    if ps1_uuid:
        volume_creation_option.set_primary_storage_uuid(ps1_uuid)
        volume_creation_option.set_name('vcenter_volume_ps1')
        volume_ps1 = test_stub.create_volume(volume_creation_option)
        test_obj_dict.add_volume(volume_ps1)
        volume_ps1.check()
    
    test_util.test_dsc('Attach volume and check')
    volume.attach(vm)
    volume.check()
    volume_ps.attach(vm)
    volume_ps.check()
    
    if vct_ops.get_datastore_type(os.environ['vcenter']) == 'local' and ps1_uuid != None:
        try:
            volume_ps1.attach(vm)
        except:
            test_util.test_logger('test for volume_ps1 pass')
        else:
            test_util.test_fail('volume_ps1 should not attach to vm')

    
    #cleanup 
    test_lib.lib_error_cleanup(test_obj_dict)
    
    test_util.test_pass("Attach data volumes to vm test passed.")
コード例 #7
0
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')
コード例 #8
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = 'L3-%s'%os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1):
        network_pattern1 = 'L3-%s'%os.environ['portgroup0']
    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_for_instantiated_vm', image_name = ova_image_name, l3_name = network_pattern1)
    test_obj_dict.add_vm(vm)
    ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid
    vm.check()

    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_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()

    test_util.test_dsc('Attach volumes and check')
    volume.attach(vm)
    volume.check()
    vm.stop()
    volume1.attach(vm)
    if volume.volume.installPath == "vcenter://empty" or volume1.volume.installPath != "vcenter://empty":
        test_util.test_fail("check data volumes fail")
    vm.start()
    test_util.test_logger(test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid))
    db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid)
    if db_volume1.installPath == "vcenter://empty":
        test_util.test_fail("check data volumes fail")
    
    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Test data volume will be instantiated at vm startup in vcenter 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
    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.")
コード例 #12
0
def test():
    global test_obj_dict

    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']

    ova_image_name = os.environ['vcenterDefaultmplate']
    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-create',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid
    ps1_uuid = None
    for ps in res_ops.query_resource(res_ops.VCENTER_PRIMARY_STORAGE):
        if ps.uuid != ps_uuid:
            ps1_uuid = ps.uuid
            break

    test_util.test_dsc('Create volume 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_creation_option.set_primary_storage_uuid(ps_uuid)
    volume_creation_option.set_name('vcenter_volume_ps')
    volume_ps = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume_ps)
    volume_ps.check()
    if ps1_uuid:
        volume_creation_option.set_primary_storage_uuid(ps1_uuid)
        volume_creation_option.set_name('vcenter_volume_ps1')
        volume_ps1 = test_stub.create_volume(volume_creation_option)
        test_obj_dict.add_volume(volume_ps1)
        volume_ps1.check()

    test_util.test_dsc('Attach volume and check')
    volume.attach(vm)
    volume.check()
    volume_ps.attach(vm)
    volume_ps.check()

    if vct_ops.get_datastore_type(
            os.environ['vcenter']) == 'local' and ps1_uuid != None:
        try:
            volume_ps1.attach(vm)
        except:
            test_util.test_logger('test for volume_ps1 pass')
        else:
            test_util.test_fail('volume_ps1 should not attach to vm')

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Attach data volumes to vm test passed.")
コード例 #13
0
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
コード例 #14
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = 'L3-%s' % os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1):
        network_pattern1 = '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_with_disk',
        image_name=ova_image_name,
        l3_name=network_pattern1,
        disk_offering_uuids=[disk_offering.uuid])
    test_obj_dict.add_vm(vm)
    vm.check()

    #create vm1 without disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name='test_detached_volume_vm',
                                         image_name=ova_image_name,
                                         l3_name=network_pattern1)
    test_obj_dict.add_vm(vm1)
    vm1.check()

    test_util.test_dsc('Create 2 volumes')
    disk_offering1 = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('largeDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid)
    volume_creation_option.set_name('vcenter_datavolume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_creation_option.set_name('vcenter_datavolume1')
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    volume1.check()

    test_util.test_dsc('Attach volume to vm, volume1 to vm1')
    #mv vm checker later, to save some time.
    volume.attach(vm)
    volume.check()
    volume1.attach(vm1)
    volume1.check()

    test_util.test_dsc('Detach volume1 and attach it to vm')
    volume1.detach()
    volume1.check()
    volume1.attach(vm)
    volume1.check()

    test_util.test_dsc('Destroy vm and attach volume to vm1')
    vm.destroy()
    volume.attach(vm1)
    volume.check()
    test_util.test_dsc('Expunge vm and attach volume1 to vm1')
    vm.expunge()
    test_obj_dict.rm_vm(vm)
    volume1.attach(vm1)
    volume1.check()

    volume.detach()
    volume.check()
    volume1.delete()
    volume1.check()
    test_obj_dict.rm_volume(volume1)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Test for detached vcenter volume passed.")
コード例 #15
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = 'L3-%s'%os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1):
        network_pattern1 = '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_with_disk', image_name = ova_image_name, l3_name = network_pattern1, disk_offering_uuids = [disk_offering.uuid])
    test_obj_dict.add_vm(vm)
    vm.check()
   
    #create vm1 without disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name = 'test_detached_volume_vm', image_name = ova_image_name, l3_name = network_pattern1)
    test_obj_dict.add_vm(vm1)
    vm1.check()
    
    test_util.test_dsc('Create 2 volumes')
    disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid)
    volume_creation_option.set_name('vcenter_datavolume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_creation_option.set_name('vcenter_datavolume1')
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    volume1.check()

    test_util.test_dsc('Attach volume to vm, volume1 to vm1')
    #mv vm checker later, to save some time.
    volume.attach(vm)
    volume.check()
    volume1.attach(vm1)
    volume1.check()

    test_util.test_dsc('Detach volume1 and attach it to vm')
    volume1.detach()
    volume1.check()
    volume1.attach(vm)
    volume1.check()
 
    test_util.test_dsc('Destroy vm and attach volume to vm1')
    vm.destroy()
    volume.attach(vm1)
    volume.check()
    test_util.test_dsc('Expunge vm and attach volume1 to vm1')
    vm.expunge()
    test_obj_dict.rm_vm(vm)
    volume1.attach(vm1)
    volume1.check()

    volume.detach()
    volume.check()
    volume1.delete()
    volume1.check()
    test_obj_dict.rm_volume(volume1)
    
    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Test for detached vcenter volume passed.")
def test():
    global test_obj_dict

    #enable vmware vmotion
    SI = vct_ops.connect_vcenter(os.environ['vcenter'])
    content = SI.RetrieveContent()
    hosts = vct_ops.get_host(content)
    for host in hosts:
        vct_ops.enable_vmotion(host)

    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']
    ova_image_name = os.environ['vcenterDefaultmplate']
    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='migrate_vm',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(
        vm.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger(
            'Not find vm migration candidate hosts, skip test migrate vm')
    else:
        test_util.test_dsc('Migrate vm to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm.vm.uuid, host_uuid)
        vm.update()
        vm.check()
        #check whether the specified host is effective
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(
            vm.vm).name
        #check the consistency of the migration in zstack and vmware
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(
            content, vm.vm.name)
        test_util.test_dsc('vm in suspended state does not allow migration')
        vm.suspend()
        candidate_host = vm_ops.get_vm_migration_candidate_hosts(
            vm.vm.uuid).inventories
        assert candidate_host == []

    #create vm with disk
    vm1 = test_stub.create_vm_in_vcenter(
        vm_name='migrate_vm_with_disk',
        image_name=ova_image_name,
        l3_name=network_pattern,
        disk_offering_uuids=[disk_offering.uuid])
    vm1.check()
    test_obj_dict.add_vm(vm1)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(
        vm1.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger(
            'Not find vm migration candidate hosts, skip test migrate vm with disk'
        )
    else:
        test_util.test_dsc('Migrate vm with disk to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm1.vm.uuid, host_uuid)
        vm1.update()
        vm1.check()
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(
            vm1.vm).name
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(
            content, vm1.vm.name)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Migrate vm test passed.")