def change_os(vm_obj):
    vm_uuid = vm_obj.get_vm().uuid
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm_obj.get_vm())
    last_ps_uuid = test_lib.lib_get_root_volume(
        vm_obj.get_vm()).primaryStorageUuid
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate",
                                        cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    image_uuid = random.choice(res_ops.query_resource(res_ops.IMAGE,
                                                      cond)).uuid
    vm_ops.change_vm_image(vm_uuid, image_uuid)
    vm_obj.start()
    vm_obj.update()
    # check whether the vm is running successfully
    test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300)
    # check whether the network config has changed
    l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm_obj.get_vm())
    if l3network_uuid_after != last_l3network_uuid:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    # check whether primarystorage has changed
    ps_uuid_after = test_lib.lib_get_root_volume(
        vm_obj.get_vm()).primaryStorageUuid
    if ps_uuid_after != last_ps_uuid:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')
def test():
   test_util.test_dsc('Test Change VM Image In Multihosts Env')
   global vm
   image = test_lib.lib_get_image_by_name("centos")
   vm = test_stub.create_vm(image_uuid=image.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_uuid = vm.get_vm().uuid
   host_ops.change_host_state(host_uuid = last_host_uuid, state = 'disable')
   vm_ops.stop_vm(vm_uuid)
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success.
   if ps.type != 'LocalStorage':
      vm_ops.change_vm_image(vm_uuid,image_uuid)
      vm_ops.start_vm(vm_uuid)
      #check whether the network config has changed
      l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
      if l3network_uuid_after != last_l3network_uuid:
         test_util.test_fail('Change VM Image Failed.The Network config has changed.')
      #check whether primarystorage has changed
      primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
      if primarystorage_uuid_after != last_primarystorage_uuid:
         test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
      vm.destroy()
      test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success')
   #Disable vm's host.If ps is local storage,the operation of changing vm image will fail.  
   else:
      try:
         vm_ops.change_vm_image(vm_uuid, image_uuid)
      except:
         test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success')
   test_util.test_fail('Test Change VM Image In Multihosts Env Success Failed')
def test():
    ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
    ceph_ps = [ps for ps in ps_inv if ps.type == 'Ceph']
    if not ceph_ps:
        test_util.test_skip('Skip test as there is not Ceph primary storage')
    
    flavor = case_flavor[os.getenv('CASE_FLAVOR')]
    
    if flavor['shared_vm']:
        multi_ps.create_vm(image_name="ttylinux", ps_type="SharedBlock")
    else:
        multi_ps.create_vm(image_name="ttylinux", ps_type="Ceph")
    multi_ps.create_data_volume(vms=multi_ps.vm, ps_type='SharedBlock')
    multi_ps.create_data_volume(vms= multi_ps.vm, ps_type='Ceph')

    vm = multi_ps.vm[0]
    last_data_volumes_uuids = []
    last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
    vm.stop()

    if flavor['imagestore_bs']:
        image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test", bs_type="ImageStoreBackupStorage").uuid
    else:
        image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test", bs_type="Ceph").uuid
    vm_ops.change_vm_image(vm.get_vm().uuid, image_uuid)
    vm.start()
    vm.update()

    #check whether the vm is running successfully
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1200):
        test_util.test_fail('VM:%s is not startup in 1200 seconds.' % vm.get_vm().uuid)
    #check whether data volumes attached to the vm has changed
    now_data_volumes_uuids = []
    now_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in now_data_volumes:
        now_data_volumes_uuids.append(data_volume.uuid)
    if set(last_data_volumes_uuids) != set(now_data_volumes_uuids):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    now_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if now_l3network_uuid != last_l3network_uuid:
        test_util.test_fail('Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    now_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
    if now_primarystorage_uuid != last_primarystorage_uuid:
        test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

    test_util.test_pass('Change Vm Image Test Success')
def test():
    import uuid
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    global vm
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    test_util.test_dsc('Test change vm image with quota limited')
    test_account_uuid = test_account.uuid
    #set normal account's storage capacity as 4G
    acc_ops.update_quota(test_account.uuid, "volume.capacity", "4294967296")
    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    test_stub.share_admin_resource([test_account_uuid])

    vm = test_stub.create_vm(session_uuid=test_account_session)
    vm.check()
    image_option = test_util.ImageOption()
    image_option.set_name('8G')
    image_option.set_format('qcow2')
    image_option.set_url(
        "http://172.20.1.15:7480/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2"
    )
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)
    new_image.add_root_volume_template()

    test_stub.share_admin_resource([test_account_uuid])
    vm.stop(session_uuid=test_account_session)
    image_uuid = test_lib.lib_get_image_by_name("8G").uuid
    try:
        vm_ops.change_vm_image(vm.get_vm().uuid,
                               image_uuid,
                               session_uuid=test_account_session)
    except:
        acc_ops.delete_account(test_account_uuid)
        img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
        test_util.test_pass(
            'Change Vm Image With Limited Storage Quota Test Success ')
    test_util.test_fail('Overstep the limit of storage capacity')
Beispiel #5
0
def test():
    test_util.test_dsc('Test Change VM Image In Multihosts Env')
    global vm
    image = test_lib.lib_get_image_by_name("centos")
    vm = test_stub.create_vm(image_uuid=image.uuid)
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    last_primarystorage_uuid = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid
    image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
    vm_uuid = vm.get_vm().uuid
    host_ops.change_host_state(host_uuid=last_host_uuid, state='disable')
    vm_ops.stop_vm(vm_uuid)
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success.
    if ps.type != 'LocalStorage':
        vm_ops.change_vm_image(vm_uuid, image_uuid)
        vm_ops.start_vm(vm_uuid)
        #check whether the network config has changed
        l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
        if l3network_uuid_after != last_l3network_uuid:
            test_util.test_fail(
                'Change VM Image Failed.The Network config has changed.')
        #check whether primarystorage has changed
        primarystorage_uuid_after = test_lib.lib_get_root_volume(
            vm.get_vm()).primaryStorageUuid
        if primarystorage_uuid_after != last_primarystorage_uuid:
            test_util.test_fail(
                'Change VM Image Failed.Primarystorage has changed.')
        vm.destroy()
        test_util.test_pass(
            'Change Vm Image Test Success In Multihosts Env Success')
    #Disable vm's host.If ps is local storage,the operation of changing vm image will fail.
    else:
        try:
            vm_ops.change_vm_image(vm_uuid, image_uuid)
        except:
            test_util.test_pass(
                'Change Vm Image Test Success In Multihosts Env Success')
    test_util.test_fail(
        'Test Change VM Image In Multihosts Env Success Failed')
def change_os(vm_obj):
    vm_uuid = vm_obj.get_vm().uuid
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm_obj.get_vm())
    last_ps_uuid = test_lib.lib_get_root_volume(vm_obj.get_vm()).primaryStorageUuid
    cond = res_ops.gen_query_conditions("system", '=', "false")
    cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond)
    cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond)
    image_uuid = random.choice(res_ops.query_resource(res_ops.IMAGE, cond)).uuid
    vm_ops.change_vm_image(vm_uuid, image_uuid)
    vm_obj.start()
    vm_obj.update()
    # check whether the vm is running successfully
    test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300)
    # check whether the network config has changed
    l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm_obj.get_vm())
    if l3network_uuid_after != last_l3network_uuid:
        test_util.test_fail('Change VM Image Failed.The Network config has changed.')
    # check whether primarystorage has changed
    ps_uuid_after = test_lib.lib_get_root_volume(vm_obj.get_vm()).primaryStorageUuid
    if ps_uuid_after != last_ps_uuid:
        test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
def test():
   import uuid
   account_name = uuid.uuid1().get_hex()
   account_pass = uuid.uuid1().get_hex()
   account_pass = hashlib.sha512(account_name).hexdigest()
   test_account = acc_ops.create_normal_account(account_name,account_pass)
   global vm
   bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
   bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
   if not bss:
      test_util.test_skip("not find available backup storage. Skip test")

   test_util.test_dsc('Test change vm image with quota limited')
   test_account_uuid = test_account.uuid
   #set normal account's storage capacity as 4G
   acc_ops.update_quota(test_account.uuid,"volume.capacity","4294967296")
   test_account_session = acc_ops.login_by_account(account_name,account_pass)
   test_stub.share_admin_resource([test_account_uuid])

   vm = test_stub.create_vm(session_uuid = test_account_session)
   vm.check()
   image_option = test_util.ImageOption()
   image_option.set_name('8G')
   image_option.set_format('qcow2')
   image_option.set_url(os.environ.get('imageServer')+"/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2")
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   new_image = zstack_image_header.ZstackTestImage()
   new_image.set_creation_option(image_option)
   new_image.add_root_volume_template()

   test_stub.share_admin_resource([test_account_uuid])
   vm.stop(session_uuid = test_account_session)
   image_uuid = test_lib.lib_get_image_by_name("8G").uuid
   try:
      vm_ops.change_vm_image(vm.get_vm().uuid,image_uuid,session_uuid = test_account_session)
   except:
      acc_ops.delete_account(test_account_uuid)
      img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
      test_util.test_pass('Change Vm Image With Limited Storage Quota Test Success ')
   test_util.test_fail('Overstep the limit of storage capacity')
Beispiel #8
0
def test():
   test_util.test_dsc('Test Change VM Image Function')
   global vm
   image_uuid = test_lib.lib_get_image_by_name("centos").uuid
   vm = test_stub.create_vm(image_uuid = image_uuid)
   vm_uuid = vm.get_vm().uuid
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   imagelist = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
   for image in imagelist.inventories:
      #check whether the image is an iso
      if image.format == "iso" or image.url.endswith('.iso') or image.mediaType == 'ISO':
         test_util.test_fail("iso cannot be chose.")
      #check whether the image is a vr image
      if image.system == "true":
         test_util.test_fail("vr image cannot be chose.")
   #test change vm image when vm is running	 
   try:
      vm_ops.change_vm_image(vm_uuid,image_uuid)
   except:
      vm.destroy()
      vm.expunge()
      test_util.test_pass('Neg Test Change VM Image Function Success')
   test_util.test_fail('Neg Test Change VM Image Function Failed')
def stopped_vm_operations(vm,bss):
   
   vm_uuid = vm.get_vm().uuid
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_ops.stop_vm(vm_uuid)
   #Change vm's instanceoffering
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)
   
   #Change vm's status
   ha_ops.set_vm_instance_ha_level(vm_uuid,'neverstop')
   vm_ops.stop_vm(vm_uuid)
   ha_ops.del_vm_instance_ha_level(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   if ps.type != 'LocalStorage':
      target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
      if target_host_uuid != None:
         vm_ops.start_vm_with_target_host(vm_uuid,target_host_uuid)
   #vm_ops.stop_vm(vm_uuid)
   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.reinit_vm(vm_uuid)

   #clone
   vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart')

   #migrate
   vm_ops.start_vm(vm_uuid)
   candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   migrate_host_uuids = []
   if candidate_hosts != None:
      for host in candidate_hosts.inventories:
         migrate_host_uuids.append(host.uuid)
      if ps.type == 'LocalStorage':
         vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
         #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])		
         vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
         test_util.test_logger('migrate vm success')
   
   #resize root volume
   vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
   vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
   set_size = 1024*1024*1024*5
   vol_ops.resize_volume(vol_uuid, set_size)
   vm.update()
   vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
   if set_size != vol_size_after:
      test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)
   test_util.test_logger('resize vm success')
   
   #storage migrate
         
   #change vm image
   image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
   image_uuids = []
   for image in image_list.inventories:
      image_uuids.append(image.uuid)
   vm_ops.change_vm_image(vm_uuid,image_uuids[0])
   vm.update()
   
   #update vm nic mac
   nic_uuid = vm.get_vm().vmNics[0].uuid
   mac = 'fa:4c:ee:9a:76:00'
   vm_ops.update_vm_nic_mac(nic_uuid,mac)

   #set/del static ip
   l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
   vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip)
   vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)
  
   #snapshot operations
   sp_option = test_util.SnapshotOption()
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   sp_option.set_volume_uuid(root_volume_uuid)
   sp = vol_ops.create_snapshot(sp_option)
   vol_ops.use_snapshot(sp.uuid)
   vol_ops.delete_snapshot(sp.uuid)

   common_operations(vm,bss,'stopped')
   vm.destroy()
   vm.expunge()
def test():
   test_util.test_dsc('Test Change VM Image Function')
   global vm
   #set overProvisioning.primaryStorage's value as 10
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid
   image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids)
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   vm_ops.stop_vm(vm_uuid)
   vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0]
   vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   #change vm image
   image_uuid = test_lib.lib_get_image_by_name("windows").uuid
   vm_ops.change_vm_image(vm_uuid,image_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the windows vm is running successfully
   vm_ip = vm.get_vm().vmNics[0].ip
   if not test_lib.lib_wait_target_up(vm_ip,'23',1200):
      test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != last_l3network_uuid:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   #check whether the linux vm is running successfully
   vm_ops.stop_vm(vm_uuid)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_ops.change_vm_image(vm_uuid,image_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)

   if not test_lib.lib_wait_target_up(vm_ip,'22',120):
      test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_linux = []
   data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_linux:
      data_volumes_after_uuids_linux.append(data_volume.uuid)
   if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != l3network_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after_linux != primarystorage_uuid_after:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   test_util.test_pass('Change Vm Image Test Success')
def test():
   test_util.test_dsc('Test Change VM Image Function')
   #set overProvisioning.primaryStorage's value as 10
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   global vm
   bs_cond = res_ops.gen_query_conditions("status","=","Connected")
   bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
   if not bss:
      test_util.test_skip("not find available backup storage.Skip test")
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   #create vm with 3 data volumes
   vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids)
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   vm_ops.stop_vm(vm_uuid)
   image_option = test_util.ImageOption()
   image_option.set_name('windows_for_test')
   image_option.set_format('qcow2')
   image_option.set_mediaType('RootVolumeTemplate')
   image_option.set_platform('windows')
   #image_option.set_url('http://172.20.1.16:7480/diskimages/windows-telnet.qcow2')
   image_option.set_url(os.environ.get('windowsImageUrl'))
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   image_option.set_timeout(1800*1000)
   new_image = zstack_image_header.ZstackTestImage()
   new_image.set_creation_option(image_option)
   new_image.add_root_volume_template()

   image_windows_uuid = test_lib.lib_get_image_by_name("windows_for_test").uuid
   vm_ops.change_vm_image(vm_uuid,image_windows_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   vm_ip = vm.get_vm().vmNics[0].ip
   #check whether the windows vm is running successfully
   if not test_lib.lib_wait_target_up(vm_ip,'23',1200):
      test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != last_l3network_uuid:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
   #check whether the linux vm is running successfully
   image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_ops.stop_vm(vm_uuid)
   vm_ops.change_vm_image(vm_uuid,image_linux_uuid)
   vm_ops.start_vm(vm_uuid)
   if not test_lib.lib_wait_target_up(vm_ip,'22',180):
      test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_linux = []
   data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_linux:
      data_volumes_after_uuids_linux.append(data_volume.uuid)
   if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != l3network_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != primarystorage_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')


   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   vm.expunge()
   img_ops.delete_image(image_windows_uuid)
   img_ops.expunge_image(image_windows_uuid)
   test_util.test_pass('Change Vm Image Test Success')
def stopped_vm_operations(vm, bss):

    vm_uuid = vm.get_vm().uuid
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    vm_ops.stop_vm(vm_uuid)
    #Change vm's instanceoffering
    vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024)

    #Change vm's status
    ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop')
    vm_ops.stop_vm(vm_uuid)
    ha_ops.del_vm_instance_ha_level(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    if ps.type != 'LocalStorage':
        target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
        if target_host_uuid != None:
            vm_ops.start_vm_with_target_host(vm_uuid, target_host_uuid)
    #vm_ops.stop_vm(vm_uuid)
    vm_ops.destroy_vm(vm_uuid)
    vm_ops.recover_vm(vm_uuid)
    vm_ops.reinit_vm(vm_uuid)

    #clone
    vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart')

    #migrate
    vm_ops.start_vm(vm_uuid)
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    migrate_host_uuids = []
    if candidate_hosts != None:
        for host in candidate_hosts.inventories:
            migrate_host_uuids.append(host.uuid)
        if ps.type == 'LocalStorage':
            vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
            #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
            vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
            test_util.test_logger('migrate vm success')

    #resize root volume
    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_volume(vol_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' %
                            vol_size_after)
    test_util.test_logger('resize vm success')

    #storage migrate

    #change vm image
    image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
    image_uuids = []
    for image in image_list.inventories:
        image_uuids.append(image.uuid)
    vm_ops.change_vm_image(vm_uuid, image_uuids[0])
    vm.update()

    #update vm nic mac
    nic_uuid = vm.get_vm().vmNics[0].uuid
    mac = 'fa:4c:ee:9a:76:00'
    vm_ops.update_vm_nic_mac(nic_uuid, mac)

    #set/del static ip
    l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
    vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid,
                               vm.get_vm().vmNics[0].ip)
    vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)

    #snapshot operations
    sp_option = test_util.SnapshotOption()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    sp_option.set_volume_uuid(root_volume_uuid)
    sp = vol_ops.create_snapshot(sp_option)
    vol_ops.use_snapshot(sp.uuid)
    vol_ops.delete_snapshot(sp.uuid)

    common_operations(vm, bss, 'stopped')
    vm.destroy()
    vm.expunge()
Beispiel #13
0
def test():
   test_util.test_dsc('Test Change VM Image Function')
   #set overProvisioning.primaryStorage's value as 10
   primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
   for ps in primary_storage_list:
       if ps.type == "SharedBlock":
           test_util.test_skip('SharedBlock primary storage does not support overProvision')
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   global vm
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork3").uuid
   image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-nxs",disk_offering_uuids = disk_offering_uuids)
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid

   ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid)
   avail_cap = ps.availableCapacity
   total_cap = ps.totalCapacity

   vm_ops.stop_vm(vm_uuid)
   vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0]
   vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_ops.change_vm_image(vm_uuid,image_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   #if vr.state == 'Stopped':
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the vm is running successfully
   if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120):
      test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if set(l3network_uuid_after) != set(last_l3network_uuid):
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after)
   avail_cap1 = ps.availableCapacity
   total_cap1 = ps.totalCapacity

   if total_cap != total_cap1:
      test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap,total_cap1))
   if avail_cap <= avail_cap1:
      test_util.test_fail('Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap,avail_cap1))

   vm_ops.stop_vm(vm_uuid)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid
   vm_ops.change_vm_image(vm_uuid,image_tiny_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   #if vr.state == 'Stopped':
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the vm is running successfully
   if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120):
      test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_tiny = []
   data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_tiny:
      data_volumes_after_uuids_tiny.append(data_volume.uuid)
   if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if set(l3network_uuid_after_tiny) != set(l3network_uuid_after_tiny):
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != primarystorage_uuid_after_tiny:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after_tiny)
   avail_cap2 = ps.availableCapacity
   total_cap2 = ps.totalCapacity

   if total_cap2 != total_cap1:
      test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap1,total_cap2))
   if avail_cap2 <= avail_cap1:
      test_util.test_fail('Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap1,avail_cap2))


   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   test_util.test_pass('Change Vm Image Test Success')
def test():
   test_util.test_dsc('Test Change VM Image Function')
   primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
   for ps in primary_storage_list:
       if ps.type == "SharedBlock":
           test_util.test_skip('SharedBlock primary storage does not support overProvision')
   global vm
   #set overProvisioning.primaryStorage's value as 10
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid
   image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   #choose the ps which availableCapacity >= 105G
   cond = res_ops.gen_query_conditions('availableCapacity', '>=', '112742891520')
   ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid
   system_tag = "primaryStorageUuidForDataVolume::%s" % ps_uuid
   vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids,system_tags=[system_tag])
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   vm_ops.stop_vm(vm_uuid)
   vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0]
   vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   #change vm image
   image_uuid = test_lib.lib_get_image_by_name("windows").uuid
   vm_ops.change_vm_image(vm_uuid,image_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the windows vm is running successfully
   vm_ip = vm.get_vm().vmNics[0].ip
   if not test_lib.lib_wait_target_up(vm_ip,'23',1200):
      test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != last_l3network_uuid:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   #check whether the linux vm is running successfully
   vm_ops.stop_vm(vm_uuid)
   #stop vm's vr
   vm_ops.stop_vm(vr.uuid)
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_ops.change_vm_image(vm_uuid,image_uuid)
   #check whether vr's status is running
   if vr.applianceVmType == 'vrouter':
      if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240):
         test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid)
      time.sleep(20)
   else:
      vm_ops.start_vm(vr.uuid)
      vm_ops.reconnect_vr(vr.uuid)
   vm_ops.start_vm(vm_uuid)

   if not test_lib.lib_wait_target_up(vm_ip,'22',180):
      test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_linux = []
   data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_linux:
      data_volumes_after_uuids_linux.append(data_volume.uuid)
   if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != l3network_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after_linux != primarystorage_uuid_after:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   test_util.test_pass('Change Vm Image Test Success')
def test():
    test_util.test_dsc('Test Change VM Image Function')
    #set overProvisioning.primaryStorage's value as 10
    con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage',
                                 10)
    global vm
    bs_cond = res_ops.gen_query_conditions("status", "=", "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage.Skip test")
    test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T")
    disk_offering_uuids = [
        test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,
        test_lib.lib_get_disk_offering_by_name("root-disk").uuid,
        test_lib.lib_get_disk_offering_by_name("1T").uuid
    ]
    #create vm with 3 data volumes
    vm = test_stub.create_vm(image_name="ttylinux",
                             vm_name="test-vm",
                             disk_offering_uuids=disk_offering_uuids)
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_uuid = vm.get_vm().uuid
    last_data_volumes_uuids = []
    last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    last_primarystorage_uuid = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    vm_ops.stop_vm(vm_uuid)
    image_option = test_util.ImageOption()
    image_option.set_name('windows_for_test')
    image_option.set_format('qcow2')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_platform('windows')
    image_option.set_url(
        'http://172.20.1.16:7480/diskimages/windows-telnet.qcow2')
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(1800 * 1000)
    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)
    new_image.add_root_volume_template()

    image_windows_uuid = test_lib.lib_get_image_by_name(
        "windows_for_test").uuid
    vm_ops.change_vm_image(vm_uuid, image_windows_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.update()
    vm_ip = vm.get_vm().vmNics[0].ip
    #check whether the windows vm is running successfully
    if not test_lib.lib_wait_target_up(vm_ip, '23', 1200):
        test_util.test_fail(
            'vm:%s is not startup in 1200 seconds.Fail to reboot it.' %
            vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids = []
    data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after:
        data_volumes_after_uuids.append(data_volume.uuid)
    if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after != last_l3network_uuid:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after != last_primarystorage_uuid:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')
    #check whether the linux vm is running successfully
    image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
    vm_ops.stop_vm(vm_uuid)
    vm_ops.change_vm_image(vm_uuid, image_linux_uuid)
    vm_ops.start_vm(vm_uuid)
    if not test_lib.lib_wait_target_up(vm_ip, '22', 120):
        test_util.test_fail(
            'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids_linux = []
    data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after_linux:
        data_volumes_after_uuids_linux.append(data_volume.uuid)
    if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after != l3network_uuid_after_linux:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after != primarystorage_uuid_after_linux:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')

    test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
    vm.expunge()
    img_ops.delete_image(image_windows_uuid)
    img_ops.expunge_image(image_windows_uuid)
    test_util.test_pass('Change Vm Image Test Success')
Beispiel #16
0
def test():
    test_util.test_dsc('Test Change VM Image Function')
    #set overProvisioning.primaryStorage's value as 10
    con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage',
                                 10)
    global vm
    test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T")
    disk_offering_uuids = [
        test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,
        test_lib.lib_get_disk_offering_by_name("root-disk").uuid,
        test_lib.lib_get_disk_offering_by_name("1T").uuid
    ]
    vm = test_stub.create_vm(image_name="ttylinux",
                             vm_name="test-vm",
                             disk_offering_uuids=disk_offering_uuids)
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_uuid = vm.get_vm().uuid
    last_data_volumes_uuids = []
    last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    last_primarystorage_uuid = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid

    ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid)
    avail_cap = ps.availableCapacity
    total_cap = ps.totalCapacity

    vm_ops.stop_vm(vm_uuid)
    image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
    vm_ops.change_vm_image(vm_uuid, image_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.update()
    #check whether the vm is running successfully
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120):
        test_util.test_fail(
            'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids = []
    data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after:
        data_volumes_after_uuids.append(data_volume.uuid)
    if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after != last_l3network_uuid:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after != last_primarystorage_uuid:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')

    ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after)
    avail_cap1 = ps.availableCapacity
    total_cap1 = ps.totalCapacity

    if total_cap != total_cap1:
        test_util.test_fail(
            'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s'
            % (image_uuid, total_cap, total_cap1))
    if avail_cap <= avail_cap1:
        test_util.test_fail(
            'Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s'
            % (image_uuid, avail_cap, avail_cap1))

    vm_ops.stop_vm(vm_uuid)
    image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid
    vm_ops.change_vm_image(vm_uuid, image_tiny_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.update()
    #check whether the vm is running successfully
    if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120):
        test_util.test_fail(
            'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids_tiny = []
    data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after_tiny:
        data_volumes_after_uuids_tiny.append(data_volume.uuid)
    if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after_tiny != l3network_uuid_after:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after_tiny != primarystorage_uuid_after:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')

    ps = test_lib.lib_get_primary_storage_by_uuid(
        primarystorage_uuid_after_tiny)
    avail_cap2 = ps.availableCapacity
    total_cap2 = ps.totalCapacity

    if total_cap2 != total_cap1:
        test_util.test_fail(
            'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s'
            % (image_uuid, total_cap1, total_cap2))
    if avail_cap2 <= avail_cap1:
        test_util.test_fail(
            'Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s'
            % (image_uuid, avail_cap1, avail_cap2))

    test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
    vm.expunge()
    test_util.test_pass('Change Vm Image Test Success')
 def change_vm_image(self, image_uuid, session_uuid = None):
     vm_ops.change_vm_image(self.vm.uuid, image_uuid, session_uuid)
def test():
   test_util.test_dsc('Test Change VM Image Function')
   #set overProvisioning.primaryStorage's value as 10
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   global vm
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids)
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid

   ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid)
   avail_cap = ps.availableCapacity
   total_cap = ps.totalCapacity

   vm_ops.stop_vm(vm_uuid)
   image = test_lib.lib_get_image_by_name("image_for_sg_test")
   image_uuid = image.uuid
   image_tiny = test_lib.lib_get_image_by_name("ttylinux")
   image_tiny_uuid = image_tiny.uuid
   change_size = (image.size-image_tiny.size)/10

   vm_ops.change_vm_image(vm_uuid,image_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the vm is running successfully
   if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',180):
      test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != last_l3network_uuid:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
   
   ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after)
   avail_cap1 = ps.availableCapacity
   total_cap1 = ps.totalCapacity

   if total_cap != total_cap1:
      test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap,total_cap1))
   if not (avail_cap1-1) <= (avail_cap - change_size) <= (avail_cap1+1):
      test_util.test_fail('Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap,avail_cap1))

   vm_ops.stop_vm(vm_uuid)
   image_tiny_uuid = image_tiny.uuid
   vm_ops.change_vm_image(vm_uuid,image_tiny_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   #check whether the vm is running successfully
   if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',180):
      test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_tiny = []
   data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_tiny:
      data_volumes_after_uuids_tiny.append(data_volume.uuid)
   if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after_tiny != l3network_uuid_after:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after_tiny != primarystorage_uuid_after:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')

   ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after_tiny)
   avail_cap2 = ps.availableCapacity
   total_cap2 = ps.totalCapacity

   if total_cap2 != total_cap1:
      test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_tiny_uuid,total_cap1,total_cap2))
   if not (change_size-1)<=(avail_cap2 - avail_cap1)<= (change_size+1):
      test_util.test_fail('Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_tiny_uuid,avail_cap1,avail_cap2))



   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   vm.expunge()
   test_util.test_pass('Change Vm Image Test Success')