robottelo.virtwho_utils

Utility module to handle the virtwho configure UI/CLI/API testing

Module Contents

Functions

_parse_entry(entry)

Parse the string and return json format

get_system(system_type)

Return a dict account for ssh connect.

get_guest_info(hypervisor_type)

Return the guest_name, guest_uuid

runcmd(cmd, system=None, timeout=600, output_format='base')

Return the retcode and stdout.

register_system(system, activation_key=None, org='Default_Organization', env='Library')

Return True if the system is registered to satellite successfully.

virtwho_cleanup()

Before running test cases, need to clean the environment.

get_virtwho_status()

Return the status of virt-who service, it will help us to know

get_configure_id(name)

Return the configure id by hammer.

get_configure_command(config_id, org=DEFAULT_ORG)

Return the deploy command line based on configure id.

get_configure_file(config_id)

Return the configuration file full name in /etc/virt-who.d

get_configure_option(option, filename)

Return the option’s value for the specific file.

_get_hypervisor_mapping(logs, hypervisor_type)

Analysing rhsm.log and get to know: what is the hypervisor_name

deploy_validation(hypervisor_type)

Checkout the deploy result

deploy_configure_by_command(command, hypervisor_type, debug=False, org='Default_Organization')

Deploy and run virt-who servcie by the hammer command.

deploy_configure_by_script(script_content, hypervisor_type, debug=False)

Deploy and run virt-who service by the shell script.

restart_virtwho_service()

Do the following:

update_configure_option(option, value, config_file)

Update option in virt-who config file

delete_configure_option(option, config_file)

Delete option in virt-who config file

add_configure_option(option, value, config_file)

Add option to virt-who config file

hypervisor_json_create(hypervisors, guests)

Create a hypervisor guest json data. For example:

create_fake_hypervisor_content(org_label, hypervisors, guests)

Post the fake hypervisor content to satellite server

get_hypervisor_info(hypervisor_type)

Get the hypervisor_name and guest_name from rhsm.log.

virtwho_package_locked()

Uninstall virt-who package and lock the foreman-maintain packages.

create_http_proxy(name=None, url=None, type='https')

Creat a new http-proxy with attributes.

Attributes

VIRTWHO_SYSCONFIG

virtwho

robottelo.virtwho_utils.VIRTWHO_SYSCONFIG = /etc/sysconfig/virt-who
robottelo.virtwho_utils.virtwho
exception robottelo.virtwho_utils.VirtWhoError

Bases: Exception

Exception raised for failed virtwho operations

robottelo.virtwho_utils._parse_entry(entry)

Parse the string and return json format

robottelo.virtwho_utils.get_system(system_type)

Return a dict account for ssh connect.

Parameters

system_type (str) – The type of the system, should be one of (‘satellite’, ‘esx’, ‘xen’, ‘hyperv’, ‘rhevm’, ‘libvirt’, ‘kubevirt’).

Raises

VirtWhoError: If wrong system_type specified.

robottelo.virtwho_utils.get_guest_info(hypervisor_type)

Return the guest_name, guest_uuid

robottelo.virtwho_utils.runcmd(cmd, system=None, timeout=600, output_format='base')

Return the retcode and stdout.

Parameters
  • cmd (str) – The command line will be executed in the target system.

  • system (dict) – the system account which ssh will connect to, it will connect to the satellite host if the system is None.

  • timeout (int) – Time to wait for establish the connection.

  • output_format (str) – base|json|csv|list

robottelo.virtwho_utils.register_system(system, activation_key=None, org='Default_Organization', env='Library')

Return True if the system is registered to satellite successfully.

Parameters
  • system (dict) – system account used by ssh to connect and register.

  • activation_key (str) – the activation key will be used to register.

  • org (str) – Which organization will be used to register.

  • env (str) – Which environment will be used to register.

Raises

VirtWhoError: If failed to register the system.

robottelo.virtwho_utils.virtwho_cleanup()

Before running test cases, need to clean the environment. Do the following: 1. stop virt-who service. 2. kill all the virt-who pid 3. clean rhsm.log message, make sure there is no old message exist. 4. clean all the configure files in /etc/virt-who.d/

robottelo.virtwho_utils.get_virtwho_status()

Return the status of virt-who service, it will help us to know the virt-who configuration file is deployed or not.

robottelo.virtwho_utils.get_configure_id(name)

Return the configure id by hammer. :param str name: the configure name you have created. :raises: VirtWhoError: If failed to get the configure info by hammer.

robottelo.virtwho_utils.get_configure_command(config_id, org=DEFAULT_ORG)

Return the deploy command line based on configure id. :param str config_id: the unique id of the configure file you have created. :param str org: the satellite organization name.

robottelo.virtwho_utils.get_configure_file(config_id)

Return the configuration file full name in /etc/virt-who.d :param str config_id: the unique id of the configuration file you have created.

robottelo.virtwho_utils.get_configure_option(option, filename)

Return the option’s value for the specific file.

Parameters
  • option (str) – the option name in the configuration file

  • filename (str) – the configuration file, it could be: /etc/sysconfig/virt-who /etc/virt-who.d/virt-who-config-{}.conf

Raises

VirtWhoError: If this option name not in the file.

robottelo.virtwho_utils._get_hypervisor_mapping(logs, hypervisor_type)

Analysing rhsm.log and get to know: what is the hypervisor_name for the specific guest. :param str logs: the output of rhsm.log. :param str hypervisor_type: esx, libvirt, rhevm, xen, libvirt, kubevirt :raises: VirtWhoError: If hypervisor_name is None. :return: hypervisor_name and guest_name

robottelo.virtwho_utils.deploy_validation(hypervisor_type)

Checkout the deploy result :param str hypervisor_type: esx, libvirt, rhevm, xen, libvirt, kubevirt :raises: VirtWhoError: If failed to start virt-who servcie. :ruturn: hypervisor_name and guest_name

robottelo.virtwho_utils.deploy_configure_by_command(command, hypervisor_type, debug=False, org='Default_Organization')

Deploy and run virt-who servcie by the hammer command.

Parameters
  • command (str) – get the command by UI/CLI/API, it should be like: hammer virt-who-config deploy –id 1 –organization-id 1

  • hypervisor_type (str) – esx, libvirt, rhevm, xen, libvirt, kubevirt

  • debug (bool) – if VIRTWHO_DEBUG=1, this option should be True.

  • org (str) – Organization Label

robottelo.virtwho_utils.deploy_configure_by_script(script_content, hypervisor_type, debug=False)

Deploy and run virt-who service by the shell script. :param str script_content: get the script by UI or API. :param str hypervisor_type: esx, libvirt, rhevm, xen, libvirt, kubevirt :param bool debug: if VIRTWHO_DEBUG=1, this option should be True.

robottelo.virtwho_utils.restart_virtwho_service()

Do the following: 1. remove rhsm.log to ensure there are no old messages. 2. restart virt-who service via systemctl command

robottelo.virtwho_utils.update_configure_option(option, value, config_file)

Update option in virt-who config file :param option: the option you want to update :param value: set the option to the value :param config_file: path of virt-who config file

robottelo.virtwho_utils.delete_configure_option(option, config_file)

Delete option in virt-who config file :param option: the option you want to delete :param config_file: path of virt-who config file

robottelo.virtwho_utils.add_configure_option(option, value, config_file)

Add option to virt-who config file :param option: the option you want to add :param value: the value of the option :param config_file: path of virt-who config file

robottelo.virtwho_utils.hypervisor_json_create(hypervisors, guests)

Create a hypervisor guest json data. For example: {‘hypervisors’: [{‘hypervisorId’: ‘820b5143-3885-4dba-9358-4ce8c30d934e’, ‘guests’: [{‘guestId’: ‘afb91b1f-8438-46f5-bc67-d7ab328ef782’, ‘state’: 1, ‘attributes’: {‘active’: 1, ‘virtWhoType’: ‘esx’}}]}]} :param hypervisors: how many hypervisors will be created :param guests: how many guests will be created

robottelo.virtwho_utils.create_fake_hypervisor_content(org_label, hypervisors, guests)

Post the fake hypervisor content to satellite server :param hypervisors: how many hypervisors will be created :param guests: how many guests will be created :param org_label: the label of the Organization :return data: the hypervisor content

robottelo.virtwho_utils.get_hypervisor_info(hypervisor_type)

Get the hypervisor_name and guest_name from rhsm.log.

robottelo.virtwho_utils.virtwho_package_locked()

Uninstall virt-who package and lock the foreman-maintain packages.

robottelo.virtwho_utils.create_http_proxy(name=None, url=None, type='https')

Creat a new http-proxy with attributes. :param name: Name of the proxy :param url: URL of the proxy including schema (https://proxy.example.com:8080) :param type: https or http :return: