def _compose_nics(vifs, net_ids, image_id, guest_os): nics = [] glance_vif = None if isinstance(vifs, str): vifs = (vifs,) for i in range(len(vifs)): vif_model = vifs[i] nic = {'net-id': net_ids[i]} if vif_model in ('e1000', 'rt18139'): glance_vif = vif_model elif vif_model != 'virtio': nic['vif-model'] = vif_model nics.append(nic) if glance_vif: glance_helper.set_image(image=image_id, hw_vif_model=glance_vif, new_name='{}_{}'.format(guest_os, glance_vif)) return nics
def test_update_image_name(create_image_for_metrics): """ Test for Update image name """ global second_update # This workaround is needed because it seems that the output is not a string, but a list # and needs to be converted to a string created_at = glance_helper.get_image_values(create_image_for_metrics, "created_at") # Set temporary image name test_image_name = glance_helper.set_image( image=create_image_for_metrics, new_name=cirros_params['image_name_tmp'])[1] # ToDo: modify glance_helper.set_image to add imageID as an output test_image_name = test_image_name.replace("Image ", "") test_image_name = test_image_name.replace(" is successfully modified", "") first_update = glance_helper.get_image_values(test_image_name, "updated_at") assert created_at != first_update, "date of first update should be different" \ " than date of creation time" # Check temporary image name image_exists = glance_helper.image_exists( image=cirros_params['image_name_tmp'], image_val="Name") assert image_exists is True, "Image name has not been changed to {}"\ .format(cirros_params['image_name_tmp']) # Set original image name test_image_name = glance_helper.set_image( image=create_image_for_metrics, new_name=cirros_params['image_name'])[1] # ToDo: modify glance_helper.set_image to add imageID as an output test_image_name = test_image_name.replace("Image ", "") test_image_name = test_image_name.replace(" is successfully modified", "") second_update = glance_helper.get_image_values(test_image_name, "updated_at") assert first_update != second_update, "date of second update should be different" \ "than date of first update" # Check image name is back to original name image_exists = glance_helper.image_exists( image=cirros_params['image_name'], image_val="Name") assert image_exists is True, "Image name has not been changed back to {}".\ format(cirros_params['image_name'])
def test_update_image_disk_ram_size(create_image_for_metrics): """ Test for Update image disk and RAM size """ # Set min disk size test_image_name = glance_helper.set_image( image=create_image_for_metrics, min_disk=10)[1] # ToDo: modify glance_helper.set_image to add imageID as an output test_image_name = test_image_name.replace("Image ", "") test_image_name = test_image_name.replace(" is successfully modified", "") third_update = glance_helper.get_image_values(test_image_name, "updated_at") assert second_update != third_update, "date of third update should be different" \ "than date of second update" # Set min ram size test_image_name = glance_helper.set_image( image=create_image_for_metrics, min_ram=20)[1] # ToDo: modify glance_helper.set_image to add imageID as an output test_image_name = test_image_name.replace("Image ", "") test_image_name = test_image_name.replace(" is successfully modified", "") forth_update = glance_helper.get_image_values(test_image_name, "updated_at") assert third_update != forth_update, "date of forth update should be different " \ "than date of third update"
def test_interface_attach_detach_max_vnics(guest_os, if_attach_arg, vifs, check_avs_pattern, base_vm): """ Sample test case for interface attach/detach to maximum vnics Setups: - Boot a base vm with mgmt net and internal0-net1 (module) Test Steps: - Boot a vm with only mgmt interface - Attach an vifs to vm with given if_attach_arg and vif_model - Bring up the interface from vm - ping between base_vm and vm_under_test over mgmt & tenant network - Perform VM action - Cold migrate, live migrate, pause resume, suspend resume - Verify ping between base_vm and vm_under_test over mgmt & tenant network after vm operation - detach all the tenant interface - Repeat attach/detach after performing each vm action Teardown: - Delete created vm, volume, port (if any) (func) - Delete base vm, volume (module) """ if guest_os == 'vxworks' and not system_helper.is_avs(): skip('e1000 vif unsupported by OVS') base_vm_id, mgmt_nic, tenant_nic, internal_net_id, tenant_net_id, mgmt_net_id = base_vm glance_vif = None if not (if_attach_arg == 'port_id' and system_helper.is_avs()): for vif in vifs: if vif[0] in ('e1000', 'rtl8139'): glance_vif = vif[0] break LOG.tc_step("Get/Create {} glance image".format(guest_os)) cleanup = None if (not glance_vif and re.search( GuestImages.TIS_GUEST_PATTERN, guest_os)) else 'function' image_id = glance_helper.get_guest_image( guest_os=guest_os, cleanup=cleanup, use_existing=False if cleanup else True) if glance_vif: glance_helper.set_image(image_id, hw_vif_model=glance_vif, new_name='{}_{}'.format(guest_os, glance_vif)) LOG.tc_step("Create a flavor with 2 vcpus") flavor_id = nova_helper.create_flavor(vcpus=1, guest_os=guest_os, cleanup='function')[1] LOG.tc_step("Create a volume from {} image".format(guest_os)) code, vol_id = cinder_helper.create_volume(name='vol-' + guest_os, source_id=image_id, fail_ok=True, guest_image=guest_os, cleanup='function') assert 0 == code, "Issue occurred when creating volume" source_id = vol_id LOG.tc_step("Boot a vm with mgmt nic only") vm_under_test = vm_helper.boot_vm(name='if_attach_tenant', nics=[mgmt_nic], source_id=source_id, flavor=flavor_id, guest_os=guest_os, cleanup='function')[1] prev_port_count = 1 for vm_actions in [['live_migrate'], ['cold_migrate'], ['pause', 'unpause'], ['suspend', 'resume'], ['stop', 'start']]: tenant_port_ids = [] if 'vxworks' not in guest_os: LOG.tc_step( "Attach specified vnics to the VM before {} and bring up interfaces" .format(vm_actions)) expt_vnics = 1 for vif in vifs: vif_model, vif_count = vif expt_vnics += vif_count LOG.info("iter {}".format(vif_count)) for i in range(vif_count): if if_attach_arg == 'port_id': vif_model = vif_model if system_helper.is_avs( ) else None port = network_helper.create_port( net_id=tenant_net_id, wrs_vif=vif_model, cleanup='function', name='attach_{}_{}'.format(vif_model, i))[1] kwargs = {'port_id': port} else: kwargs = {'net_id': tenant_net_id} tenant_port_id = vm_helper.attach_interface( vm_under_test, **kwargs)[1] tenant_port_ids.append(tenant_port_id) LOG.info( "Attached new vnics to the VM {}".format(tenant_port_ids)) vm_ports_count = len( network_helper.get_ports(server=vm_under_test)) LOG.info("vnics attached to VM: {}".format(vm_ports_count)) assert vm_ports_count == expt_vnics, "vnics attached is not equal to max number." LOG.info( "Bring up all the attached new vifs {} on tenant net from vm". format(vifs)) _bring_up_attached_interface(vm_under_test, ports=tenant_port_ids, guest_os=guest_os, base_vm=base_vm_id) if expt_vnics == 16: LOG.tc_step( "Verify no more vnic can be attached after reaching upper limit 16" ) res = vm_helper.attach_interface(vm_under_test, net_id=tenant_net_id, fail_ok=True)[0] assert res == 1, "vnics attach exceed maximum limit" if vm_actions[0] == 'auto_recover': LOG.tc_step( "Set vm to error state and wait for auto recovery complete, then verify ping from " "base vm over management and data networks") vm_helper.set_vm_state(vm_id=vm_under_test, error_state=True, fail_ok=False) vm_helper.wait_for_vm_values(vm_id=vm_under_test, status=VMStatus.ACTIVE, fail_ok=True, timeout=600) # if 'vxworks' not in guest_os: # _bring_up_attached_interface(vm_under_test, guest_os=guest_os, num=new_vnics) else: LOG.tc_step("Perform following action(s) on vm {}: {}".format( vm_under_test, vm_actions)) for action in vm_actions: vm_helper.perform_action_on_vm(vm_under_test, action=action) if action == 'cold_migrate' or action == 'start': LOG.tc_step( "Bring up all the attached tenant interface from vm after {}" .format(vm_actions)) # if 'vxworks' not in guest_os: # _bring_up_attached_interface(vm_under_test, guest_os=guest_os, num=new_vnics) vm_helper.wait_for_vm_pingable_from_natbox(vm_under_test) if 'vxworks' not in guest_os: LOG.tc_step( "Verify ping from base_vm to vm_under_test over management networks still works " "after {}".format(vm_actions)) vm_helper.ping_vms_from_vm(to_vms=vm_under_test, from_vm=base_vm_id, net_types=['mgmt', 'data'], retry=10) LOG.tc_step("Detach all attached interface {} after {}".format( tenant_port_ids, vm_actions)) for tenant_port_id in tenant_port_ids: vm_helper.detach_interface(vm_id=vm_under_test, port_id=tenant_port_id, cleanup_route=True) vm_ports_count = len( network_helper.get_ports(server=vm_under_test)) assert prev_port_count == vm_ports_count, "VM ports still listed after interface-detach" res = vm_helper.ping_vms_from_vm(to_vms=base_vm_id, from_vm=vm_under_test, fail_ok=True, net_types=['data'], retry=0)[0] assert not res, "Detached interface still works"
def test_boot_vm_mem_page_size(self, flavor_2g, flavor_mem_page_size, image_mempage, image_mem_page_size): """ Test boot vm with various memory page size setting in flavor and image. Args: flavor_2g (tuple): flavor id of a flavor with ram set to 2G, hosts configured and storage_backing flavor_mem_page_size (str): memory page size extra spec value to set in flavor image_mempage (str): image id for tis image image_mem_page_size (str): memory page metadata value to set in image Setup: - Create a flavor with 2G RAM (module) - Get image id of tis image (module) Test Steps: - Set/Unset flavor memory page size extra spec with given value ( unset if None is given) - Set/Unset image memory page size metadata with given value ( unset if None if given) - Attempt to boot a vm with above flavor and image - Verify boot result based on the mem page size values in the flavor and image Teardown: - Delete vm if booted - Delete created flavor (module) """ skip_4k_for_ovs(image_mem_page_size) flavor_id, hosts, storage_backing = flavor_2g if image_mem_page_size is None: glance_helper.unset_image(image_mempage, properties=ImageMetadata.MEM_PAGE_SIZE) expt_code = 0 else: glance_helper.set_image( image=image_mempage, properties={ImageMetadata.MEM_PAGE_SIZE: image_mem_page_size}) if flavor_mem_page_size is None: expt_code = 4 elif flavor_mem_page_size.lower() in ['any', 'large']: expt_code = 0 else: expt_code = 0 if flavor_mem_page_size.lower() == \ image_mem_page_size.lower() else 4 LOG.tc_step("Attempt to boot a vm with flavor_mem_page_size: {}, and " "image_mem_page_size: {}. And check return " "code is {}.".format(flavor_mem_page_size, image_mem_page_size, expt_code)) actual_code, vm_id, msg = vm_helper.boot_vm(name='mem_page_size', flavor=flavor_id, source='image', source_id=image_mempage, fail_ok=True, avail_zone='stxauto', cleanup='function') assert expt_code == actual_code, "Expect boot vm to return {}; " \ "Actual result: {} with msg: " \ "{}".format(expt_code, actual_code, msg) if expt_code != 0: assert re.search( NovaCLIOutput.VM_BOOT_REJECT_MEM_PAGE_SIZE_FORBIDDEN, msg) else: assert vm_helper.get_vm_host(vm_id) in hosts, \ "VM is not booted on hosts in stxauto zone" LOG.tc_step("Ensure VM is pingable from NatBox") vm_helper.wait_for_vm_pingable_from_natbox(vm_id)
def image_with_vif_multiq(): img_id = glance_helper.create_image(name='vif_multq', cleanup='function')[1] glance_helper.set_image(image=img_id, properties={'hw_vif_multiqueue_enabled': True}) return img_id