Пример #1
0
def test():
    global test_obj_dict
    global vol_num
    global volume
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()
    for i in range(vol_num):
        volume_list.append(test_stub.create_volume())
        test_obj_dict.add_volume(volume_list[i])

    additional_vol = test_stub.create_volume()
    test_obj_dict.add_volume(additional_vol)

    for i in range(vol_num):
        volume_list[i].check()
    time.sleep(60)

    test_util.test_dsc('Test attach/detach 24 volumes operations.')
    for i in range(vol_num):
        volume_list[i].attach(vm)

    for i in range(vol_num):
        volume_list[i].check()

    for i in range(vol_num):
        volume_list[i].detach()
        volume_list[i].check()

    test_util.test_dsc('Redo attach/detach 24 volumes operations.')

    for i in range(vol_num):
        volume_list[i].attach(vm)
        volume_list[i].check()

    test_util.test_dsc('Try to attach the 25th data volume.')
    try:
        additional_vol.attach(vm)
    except:
        test_util.test_logger(
            'Catch expected exception: try to attach the 25th data [volume:] %s to [vm:] %s fail.'
            % (additional_vol.volume.uuid, vm.vm.uuid))

        for i in range(vol_num):
            volume_list[i].detach()
            volume_list[i].check()

        for i in range(vol_num):
            volume_list[i].delete()
            volume_list[i].check()

        vm.destroy()
        test_util.test_pass('Create Multi Data Volumes for VM Test Success')
        return True

    test_util.test_fail(
        'Fail: could attached the 25th data [volume:] %s to [vm:] %s .' %
        (additional_vol.volume.uuid, vm.vm.uuid))
    return False
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.")
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
    global vol_num
    global volume
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()
    for i in range(vol_num):
        volume_list.append(test_stub.create_volume())
        test_obj_dict.add_volume(volume_list[i])

    additional_vol = test_stub.create_volume()
    test_obj_dict.add_volume(additional_vol)

    for i in range(vol_num):
        volume_list[i].check()
    time.sleep(60)

    test_util.test_dsc('Test attach/detach 20 volumes operations.')
    for i in range(vol_num):
        volume_list[i].attach(vm)

    for i in range(vol_num):
        volume_list[i].check()

    for i in range(vol_num):
        volume_list[i].detach()
        volume_list[i].check()

    test_util.test_dsc('Redo attach/detach 20 volumes operations.')

    for i in range(vol_num):
        volume_list[i].attach(vm)
        volume_list[i].check()

    test_util.test_dsc('Try to attach the 21th data volume.')
    try:
        additional_vol.attach(vm)
    except:
        test_util.test_logger('Catch expected exception: try to attach the 21th data [volume:] %s to [vm:] %s fail.' % (additional_vol.volume.uuid, vm.vm.uuid))
        
        for i in range(vol_num):
            volume_list[i].detach()
            volume_list[i].check()

        for i in range(vol_num):
            volume_list[i].delete()
            volume_list[i].check()

        vm.destroy()
        test_util.test_pass('Create Multi Data Volumes for VM Test Success')
        return True

    test_util.test_fail('Fail: could attached the 21th data [volume:] %s to [vm:] %s .' % (additional_vol.volume.uuid, vm.vm.uuid))
    return False
def test():
    global test_obj_dict
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    volume.attach(vm)
    volume.check()

    vm.stop()
    volume2 = test_stub.create_volume()
    test_obj_dict.add_volume(volume2)
    volume2.check()

    volume2.attach(vm)
    volume2.check()

    volume2.detach()
    volume2.check()

    volume2.attach(vm)
    volume2.check()
        
    vm.start()
    vm.check()
    time.sleep(60)

    volume.check()
    volume2.check()

    volume.detach()
    volume.check()
    volume2.check()

    volume.delete()
    volume.check()
    volume2.check()

    vm.destroy()
    volume2.check()

    volume2.delete()
    volume2.check()
        
    test_util.test_pass('Create Data Volume for stopped VM Test Success')
Пример #6
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."
    )
def test():
    global test_obj_dict
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    volume.attach(vm)
    volume.check()

    vm.stop()
    volume2 = test_stub.create_volume()
    test_obj_dict.add_volume(volume2)
    volume2.check()

    volume2.attach(vm)
    volume2.check()

    volume2.detach()
    volume2.check()

    volume2.attach(vm)
    volume2.check()
        
    vm.start()
    vm.check()

    volume.check()
    volume2.check()

    volume.detach()
    volume.check()
    volume2.check()

    volume.delete()
    volume.check()
    volume2.check()

    vm.destroy()
    volume2.check()

    volume2.delete()
    volume2.check()
        
    test_util.test_pass('Create Data Volume for stopped VM Test Success')
Пример #8
0
def test():
    global test_obj_dict

    test_util.test_dsc("Create test vm and check")
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc("Create volume and check")
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

    test_util.test_dsc("Attach volume and check")
    volume.attach(vm)
    volume.check()

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

    test_util.test_dsc("Delete volume and check")
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    vm.destroy()
    vm.check()

    test_util.test_pass("Create Data Volume for VM Test Success")
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.")
Пример #10
0
def test():
    global test_obj_dict

    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

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

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

    test_util.test_dsc('Delete volume and check')
    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)

    vm.destroy()
    vm.check()

    test_util.test_pass('Create Data Volume for VM Test Success')
def test():
    global test_obj_dict
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)
    volume.check()
        
    test_util.test_dsc('Reboot vm and check volume again.')
    vm.reboot()
    vm.check()
    volume.check()

    volume.detach()
    volume.check()

    volume.delete()
    volume.check()
    test_obj_dict.rm_volume(volume)
        
    vm.destroy()
    test_util.test_pass('Create Data Volume for VM Test Success')
Пример #12
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():
    '''
    Test Description:
        Test add volume with negative test. 
    Resource required:
        2 test VMs with additional 1*10M data volume.
 
    '''
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

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

    test_util.test_dsc('Doing negative test. Try to reattach same volume to vm again.')
    try:
        volume.attach(vm)
    except:
        test_util.test_logger('Catch expected exception. [volume:] %s can not be attached to [vm:] %s twice.' % (volume.volume.uuid, vm.vm.uuid))
        test_util.test_dsc('Doing negative test. Try to delete an attached data volume.')
        vm2 = test_stub.create_vm()
        test_obj_dict.add_vm(vm2)
        test_util.test_dsc('Doing negative test. Try to attach an attached volume to 2nd vm.')
        try:
            volume.attach(vm2)
        except:
            test_util.test_logger('Catch expected exception. [volume:] %s can not be attached to another [vm:] %s, as it is already attached to [vm:] %s.' % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
            volume.check()
            try:
                volume.delete()
            except:
                test_util.test_fail('Catch wrong logic: [volume:] %s can not be deleted, when it is assigned to [vm:] %s' % (volume.volume.uuid, vm.vm.uuid))
            test_obj_dict.rm_volume(volume)
            vm.destroy()
            test_obj_dict.rm_vm(vm)
            vm2.destroy()
            test_obj_dict.rm_vm(vm2)
            volume.check()
            test_util.test_pass('Data Volume Negative Test Success')
            return True
        
        test_util.test_fail('Catch wrong logic: [volume:] %s is attached to [vm:] %s again, although it is already attached to [vm:] %s .' % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
    test_util.test_fail('Catch wrong logic: [volume:] %s is attached to [vm:] %s twice.' % (volume.volume.uuid, vm.vm.uuid))
Пример #14
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.")
Пример #15
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.")
Пример #16
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.")
Пример #18
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.")
def test():
    global test_obj_dict

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = os.environ['l3vCenterNoVlanNetworkName']
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('largeDiskOfferingName'))
    test_util.test_dsc('Create vm and check')
    vm = test_stub.create_vm_in_vcenter(vm_name='test_volume_after_sync_vm',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern1)
    test_obj_dict.add_vm(vm)
    vm.check()
    ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid
    vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid)
    vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp

    test_util.test_dsc('Create volumes and check')
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_name('vcenter_volume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)
    volume.check()
    volume.detach()
    volume.check()

    volume_creation_option.set_name('vcenter_volume1')
    volume_creation_option.set_primary_storage_uuid(ps_uuid)
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    volume1.check()
    volume1.attach(vm)
    volume1.check()
    volume1.delete()
    volume1.check()

    test_util.test_dsc('Sync vcenter')
    vcenter_uuid = vct_ops.lib_get_vcenter_by_name(os.environ['vcenter']).uuid
    vct_ops.sync_vcenter(vcenter_uuid)
    time.sleep(5)

    test_util.test_dsc('check volumes after synchronizing vcenter')
    db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid)
    db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid)
    if db_volume.status != 'Ready' or db_volume1.status != 'Deleted':
        test_util.test_fail(
            "check data volumes fail after synchronizing vcenter")

    #delete volume file
    volume_installPath = vc_ps.url.split(
        '//')[1] + db_volume.installPath.split('[' + vc_ps.name +
                                               ']')[1].lstrip()
    test_util.test_logger(volume_installPath)
    cmd = 'rm -f %s' % volume_installPath
    vchost_user = os.environ['vchostUser']
    vchost_password = os.environ['vchostpwd']
    result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user,
                                          vchost_password, cmd, 180)

    test_util.test_dsc('Sync vcenter')
    vct_ops.sync_vcenter(vcenter_uuid)
    time.sleep(5)
    db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid)
    if db_volume:
        test_util.test_fail(
            "check data volumes fail after synchronizing vcenter")

    #cleanup
    vm.destroy()
    vm.expunge()
    volume1.expunge()

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

    ova_image_name = os.environ['vcenterDefaultmplate']
    network_pattern1 = '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

    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():
    '''
    Test Description:
        Test add volume with negative test. 
    Resource required:
        2 test VMs with additional 1*10M data volume.
 
    '''
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vm()
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Create volume and check')
    volume = test_stub.create_volume()
    test_obj_dict.add_volume(volume)
    volume.check()

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

    test_util.test_dsc(
        'Doing negative test. Try to reattach same volume to vm again.')
    try:
        volume.attach(vm)
    except:
        test_util.test_logger(
            'Catch expected exception. [volume:] %s can not be attached to [vm:] %s twice.'
            % (volume.volume.uuid, vm.vm.uuid))
        test_util.test_dsc(
            'Doing negative test. Try to delete an attached data volume.')
        vm2 = test_stub.create_vm()
        test_obj_dict.add_vm(vm2)
        test_util.test_dsc(
            'Doing negative test. Try to attach an attached volume to 2nd vm.')
        try:
            volume.attach(vm2)
        except:
            test_util.test_logger(
                'Catch expected exception. [volume:] %s can not be attached to another [vm:] %s, as it is already attached to [vm:] %s.'
                % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
            volume.check()
            try:
                volume.delete()
            except:
                test_util.test_fail(
                    'Catch wrong logic: [volume:] %s can not be deleted, when it is assigned to [vm:] %s'
                    % (volume.volume.uuid, vm.vm.uuid))
            test_obj_dict.rm_volume(volume)
            vm.destroy()
            test_obj_dict.rm_vm(vm)
            vm2.destroy()
            test_obj_dict.rm_vm(vm2)
            volume.check()
            test_util.test_pass('Data Volume Negative Test Success')
            return True

        test_util.test_fail(
            'Catch wrong logic: [volume:] %s is attached to [vm:] %s again, although it is already attached to [vm:] %s .'
            % (volume.volume.uuid, vm2.vm.uuid, vm.vm.uuid))
    test_util.test_fail(
        'Catch wrong logic: [volume:] %s is attached to [vm:] %s twice.' %
        (volume.volume.uuid, vm.vm.uuid))
def test():
    global vm
    vm = test_stub.create_vm()
    test_util.test_logger('Create VM Success')

    volume = test_stub.create_volume()
    test_util.test_logger('Create volume Success')

    volume.attach(vm)
    test_util.test_logger('attach volume Success')

    zone_uuid = vm.get_vm().zoneUuid
    bs_uuid_list = test_lib.lib_get_backup_storage_uuid_list_by_zone(zone_uuid)

    vol_template = test_stub.create_data_volume_template_from_volume(volume.get_volume().uuid, bs_uuid_list, "vol_temp_for_volume")
    
    imageUrl = test_stub.export_image_from_backup_storage(vol_template.uuid, bs_uuid_list[0])

    vol = test_stub.create_data_volume_from_template(vol_template.uuid, volume.get_volume().primaryStorageUuid, "vol_from_template", vm.get_vm().hostUuid)
    vol_uuid = vol.uuid
    test_util.test_logger('create volume from volume template Success')

    test_stub.delete_volume_image(vol_template.uuid)

    ps = test_lib.lib_get_primary_storage_by_uuid(volume.get_volume().primaryStorageUuid)

    if ps.type == 'LocalStorage':
         for host in test_stub.get_local_storage_volume_migratable_hosts(vol_uuid):
             test_stub.migrate_local_storage_volume(vol_uuid, host.uuid)
         test_stub.migrate_local_storage_volume(vol_uuid, vm.get_vm().hostUuid)


    test_lib.lib_attach_volume(vol_uuid, vm.get_vm().uuid)
    test_lib.lib_detach_volume(vol_uuid)

    test_stub.expunge_image(vol_template.uuid)

    if ps.type == 'LocalStorage':
         for host in test_stub.get_local_storage_volume_migratable_hosts(vol_uuid):
             test_stub.migrate_local_storage_volume(vol_uuid, host.uuid)

         test_stub.migrate_local_storage_volume(vol_uuid, vm.get_vm().hostUuid)
    test_lib.lib_attach_volume(vol_uuid, vm.get_vm().uuid)
    test_lib.lib_detach_volume(vol_uuid)
    test_stub.delete_volume(vol_uuid)

    test_stub.recover_volume(vol_uuid)
    if ps.type == 'LocalStorage':
         for host in test_stub.get_local_storage_volume_migratable_hosts(vol_uuid):
             test_stub.migrate_local_storage_volume(vol_uuid, host.uuid)

         test_stub.migrate_local_storage_volume(vol_uuid, vm.get_vm().hostUuid)
    
    test_lib.lib_attach_volume(vol_uuid, vm.get_vm().uuid)
    test_lib.lib_detach_volume(vol_uuid)
    vol_template = test_stub.create_data_volume_template_from_volume(volume.get_volume().uuid, bs_uuid_list, "vol_temp_for_volume")
    test_stub.delete_volume(vol_uuid)
    test_stub.expunge_volume(vol_uuid)

    #create volume again
    vol = test_stub.create_data_volume_from_template(vol_template.uuid, volume.get_volume().primaryStorageUuid, "vol_from_template", vm.get_vm().hostUuid)
    vol_uuid = vol.uuid
    test_util.test_logger('create volume from volume template Success')
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

    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.")