Exemplo n.º 1
0
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 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.")
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')
Exemplo n.º 5
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')
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_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.")
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.")