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.")
コード例 #2
0
def test():
    global vcenter_uuid, vm

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    ova_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']


    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid = inv.uuid

    if vcenter_uuid == None:
        test_util.test_fail("vcenter_uuid is None")

    vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-create-test', image_name = ova_image_name, l3_name = network_pattern1)
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    vct_ops.delete_vcenter(vcenter_uuid)
    test_util.test_pass("Creating vm of vcenter test passed.")
コード例 #3
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.")
コード例 #4
0
def test():

    l3_vr_network = os.environ['l3vCenterNoVlanNetworkName']
    image_name = os.environ['image_dhcp_name']

    vm = test_stub.create_vm_in_vcenter(vm_name='stop_vm',
                                        image_name=image_name,
                                        l3_name=l3_vr_network)
    test_obj_dict.add_vm(vm)
    vm.stop()
    vm.check()

    clone_vm = vm.clone(['clone_stop_vm'])[0]
    test_obj_dict.add_vm(clone_vm)
    clone_vm.stop()
    clone_vm.check()

    names = []
    for i in range(3):
        names.append('clone_stop_vm' + str(i + 1))

    clone_vms = clone_vm.clone(names)

    for _vm in clone_vms:
        _vm.check()
        test_obj_dict.add_vm(_vm)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass("test vcenter clone stop vm pass")
コード例 #5
0
def test():

  l3_vr_network = os.environ['l3vCenterNoVlanNetworkName']
  image_name = os.environ['image_dhcp_name']

  vm = test_stub.create_vm_in_vcenter(vm_name='vm', image_name = image_name, l3_name=l3_vr_network)
  test_obj_dict.add_vm(vm)
  vm.check()
  
  clone_vm = vm.clone(['clone_vm'])[0]
  test_obj_dict.add_vm(clone_vm)
  clone_vm.check()

  names = []
  for i in range(3):
    names.append('clone' + str(i+1))

  clone_vms = clone_vm.clone(names)

  for _vm in clone_vms:
    _vm.check()
    test_obj_dict.add_vm(_vm)

  test_lib.lib_error_cleanup(test_obj_dict)
  test_util.test_pass("test vcenter clone vm pass")
コード例 #6
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.")
コード例 #7
0
def test():
    global vcenter_uuid, vm

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    ova_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid = inv.uuid

    if vcenter_uuid == None:
        test_util.test_fail("vcenter_uuid is None")

    vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1)
    vm.check()

    vm.stop()
    vm.check()

    vm.start()
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    vct_ops.delete_vcenter(vcenter_uuid)
    test_util.test_pass("vm start and stop of vcenter 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.")
コード例 #9
0
def test():
    global test_obj_dict

    cond = res_ops.gen_query_conditions('name', '=', 'newdatastore')
    ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid
    cond = res_ops.gen_query_conditions('name', '=', 'newdatastore (1)')
    ps1_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid

    centos_image_name = os.environ['image_dhcp_name']
    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-create',
                                        image_name=centos_image_name,
                                        l3_name=network_pattern)
    vm.check()

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

    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.")
コード例 #10
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.")
コード例 #11
0
def test():
    global vcenter_uuid, vm

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    ova_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid = inv.uuid

    if vcenter_uuid == None:
        test_util.test_fail("vcenter_uuid is None")

    #this test suppose user has already deployed a cluster with more than 2 hosts included,
    #the vm is created in one of the host, then start the vm with another host uuid,
    #which leads vm migration triggering.
    vm = test_stub.create_vm_in_vcenter(vm_name='vm-start-stop-test',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern1)
    vm.check()

    vm.stop()
    vm.check()

    vm_host_uuid = test_lib.lib_get_vm_host(vm.get_vm()).uuid

    host_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    host_uuids = res_ops.query_resource_fields(res_ops.HOST,
                                               host_cond,
                                               None,
                                               fields=['uuid'])
    for host_uuid in host_uuids:
        if host_uuid != vm_host_uuid:
            another_host_uuid = host_uuid
            break

    test_stub.start_vm_with_host_uuid(vm.get_vm(), vm_host_uuid)
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    vct_ops.delete_vcenter(vcenter_uuid)
    test_util.test_pass("vm start and stop of vcenter test passed.")
コード例 #12
0
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_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."
    )
コード例 #13
0
def test():
    global vm

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = os.environ['vcenterDefaultNetwork']



    vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-create-test', image_name = ova_image_name, l3_name = network_pattern1)
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    test_util.test_pass("Creating vm of vcenter test passed.")
コード例 #14
0
def test():
    global vm

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = os.environ['vcenterDefaultNetwork']

    vm = test_stub.create_vm_in_vcenter(vm_name='vm-create-test',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern1)
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    test_util.test_pass("Creating vm of vcenter test passed.")
コード例 #15
0
def test():
    global vcenter_uuid, vm

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    ova_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid = inv.uuid

    if vcenter_uuid == None:
        test_util.test_fail("vcenter_uuid is None")

    #this test suppose user has already deployed a cluster with more than 2 hosts included, 
    #the vm is created in one of the host, then start the vm with another host uuid, 
    #which leads vm migration triggering. 
    vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1)
    vm.check()

    vm.stop()
    vm.check()

    vm_host_uuid = test_lib.lib_get_vm_host(vm.get_vm()).uuid

    host_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    host_uuids = res_ops.query_resource_fields(res_ops.HOST, host_cond, None, fields=['uuid'])
    for host_uuid in host_uuids:
        if host_uuid != vm_host_uuid:
            another_host_uuid = host_uuid
            break

    test_stub.start_vm_with_host_uuid(vm.get_vm(), vm_host_uuid)
    vm.check()

    vm.destroy()
    vm.check()
    vm.expunge()

    vct_ops.delete_vcenter(vcenter_uuid)
    test_util.test_pass("vm start and stop of vcenter test passed.")
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

    #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.")
コード例 #20
0
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global vm_uuid

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_vm = os.environ['vcenter2_sync_vm_create_delete']
    sync_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']

    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")

    #create vm in remote and check
    test_util.test_logger("create vm for sync test")
    vm = test_stub.create_vm_in_vcenter(vm_name=sync_vm,
                                        image_name=sync_image_name,
                                        l3_name=network_pattern1)
    vm.check()

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    vm_cond = res_ops.gen_query_conditions("name", '=', sync_vm)
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE,
                                           vm_cond,
                                           None,
                                           fields=['uuid', 'state'])
    if not vm_inv:
        test_util.test_fail("not found target vm being sync")

    vm_uuid = vm_inv[0].uuid
    if not vm_uuid:
        test_util.test_fail("remote woodpecker vm uuid is null")

    vm_state = vm_inv[0].state.strip().lower()
    if vm_state != "running":
        test_util.test_fail("vcenter sync vm start failed.")

    #delete vm in remote and check
    test_util.test_logger("delete vm for sync test")
    if vm_uuid:
        vm_ops.destroy_vm(vm_uuid)
        vm_ops.expunge_vm(vm_uuid)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE,
                                           vm_cond,
                                           None,
                                           fields=['uuid', 'state'])
    if vm_inv:
        test_util.test_fail("found the expected deleted vm")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync start and stop vm test passed.")
コード例 #21
0
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.")
コード例 #22
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.")
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.")
コード例 #24
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    centos_image_name = os.environ['image_dhcp_name']
    network_pattern1 = os.environ['l3vCenterNoVlanNetworkName']
    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-create-with-disk',
        image_name=centos_image_name,
        l3_name=network_pattern1,
        disk_offering_uuids=[disk_offering.uuid])
    vm.check()
    vm.destroy()
    vm.check()
    vm.expunge()
    #create vm1 without disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name='test_vcenter_vm1',
                                         image_name=ova_image_name,
                                         l3_name=network_pattern1)
    test_obj_dict.add_vm(vm1)

    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('vcenter3_volume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()

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

    test_util.test_dsc('Detach volume and check')
    volume.detach()
    volume.check()

    test_util.test_dsc('Attach volume which was detached and check')
    volume.attach(vm1)
    volume.check()

    test_util.test_dsc('Delete volume which was attached to vm and check')
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    test_util.test_dsc('Recover volume and check')
    volume.recover()
    volume.check()
    test_obj_dict.add_volume(volume)

    test_util.test_dsc(
        'Attach volume, detach volume, then delete volume and check')
    volume.attach(vm1)
    volume.check()
    volume.detach()
    volume.check()
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    volume.recover()
    volume.check()
    test_obj_dict.add_volume(volume)
    test_util.test_dsc('Expunge vm , then test volume can be expunged or not')
    volume.attach(vm1)
    volume.check()
    vm1.destroy()
    vm1.expunge()
    volume.delete()
    volume.check()
    volume.expunge()
    volume.check()
    test_obj_dict.rm_volume(volume)

    test_util.test_pass("Creating vm with disk volume of vcenter 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.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.")
コード例 #26
0
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.")
コード例 #27
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.")
コード例 #28
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    centos_image_name = os.environ['image_dhcp_name'] 
    network_pattern1 = os.environ['l3vCenterNoVlanNetworkName']
    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-create-with-disk', image_name = centos_image_name, l3_name = network_pattern1, disk_offering_uuids = [disk_offering.uuid] )
    vm.check()
    vm.destroy()
    vm.check()
    vm.expunge()
    #create vm1 without disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name = 'test_vcenter_vm1', image_name = ova_image_name, l3_name = network_pattern1)
    test_obj_dict.add_vm(vm1)
    
    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('vcenter3_volume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()

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

    test_util.test_dsc('Detach volume and check')
    volume.detach()
    volume.check()
 
    test_util.test_dsc('Attach volume which was detached and check')
    volume.attach(vm1)
    volume.check()

    test_util.test_dsc('Delete volume which was attached to vm and check')
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    test_util.test_dsc('Recover volume and check')
    volume.recover()
    volume.check()
    test_obj_dict.add_volume(volume)

    test_util.test_dsc('Attach volume, detach volume, then delete volume and check')
    volume.attach(vm1)
    volume.check()
    volume.detach()
    volume.check()
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    volume.recover()
    volume.check()
    test_obj_dict.add_volume(volume)
    test_util.test_dsc('Expunge vm , then test volume can be expunged or not')
    volume.attach(vm1)
    volume.check()
    vm1.destroy()
    vm1.expunge()
    volume.delete()
    volume.check()
    volume.expunge()
    volume.check()
    test_obj_dict.rm_volume(volume)
    
    test_util.test_pass("Creating vm with disk volume of vcenter test passed.")
コード例 #29
0
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global vm_uuid


    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_vm = os.environ['vcenter2_sync_vm_create_delete']
    sync_image_name = os.environ['vcenter2_template_exist']
    network_pattern1 = os.environ['vcenter2_network_pattern1']



    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']    


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")



    #create vm in remote and check
    test_util.test_logger("create vm for sync test")
    vm = test_stub.create_vm_in_vcenter(vm_name = sync_vm, image_name = sync_image_name, l3_name = network_pattern1)
    vm.check()

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    vm_cond = res_ops.gen_query_conditions("name", '=', sync_vm)
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])
    if not vm_inv:
        test_util.test_fail("not found target vm being sync")

    vm_uuid = vm_inv[0].uuid
    if not vm_uuid:
        test_util.test_fail("remote woodpecker vm uuid is null")

    vm_state = vm_inv[0].state.strip().lower()
    if vm_state != "running":
        test_util.test_fail("vcenter sync vm start failed.")



    #delete vm in remote and check
    test_util.test_logger("delete vm for sync test")
    if vm_uuid:
        vm_ops.destroy_vm(vm_uuid)
        vm_ops.expunge_vm(vm_uuid)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])
    if vm_inv:
        test_util.test_fail("found the expected deleted vm")




    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync start and stop vm 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.")
コード例 #31
0
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    #centos_image_name = os.environ['image_dhcp_name']
    network_pattern1 = os.environ['l3vCenterNoVlanNetworkName']
    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.")