robottelo.vm

Utilities to create clients

Clients are virtual machines provisioned on a provisioning_server. All virtual machine images are stored on the image_dir path on the provisioning server.

Make sure to configure the clients section on the configuration file. Also make sure that the server have in place: the base images for rhel66 and rhel71, snap-guest and its dependencies and the image_dir path created.

Module Contents

Classes

VirtualMachine

Manages a virtual machine to allow client provisioning for robottelo

Attributes

logger

robottelo.vm.logger
exception robottelo.vm.VirtualMachineError

Bases: Exception

Exception raised for failed virtual machine management operations

class robottelo.vm.VirtualMachine(cpu=1, ram=512, distro=None, provisioning_server=None, image_dir=None, tag=None, hostname=None, domain=None, source_image=None, target_image=None, bridge=None, network=None)

Manages a virtual machine to allow client provisioning for robottelo

It expects that base images are created and snap-guest is setup on the provisioning server.

This also can be used as a context manager:

with VirtualMachine() as vm:
    result = vm.run('ls')
    out = result.stdout

Make sure to call destroy() to stop and clean the image on the provisioning server, otherwise the virtual machine and its image will stay on the server consuming hardware resources.

It is possible to customize the provisioning_server and image_dir as per virtual machine basis. Just set the wanted values when instantiating.

allowed_distros(self)

This is needed in construction, record it for easy reference Property instead of a class attribute to delay reading of the settings

property subscribed(self)
property domain(self)
property hostname(self)
property target_image(self)
create(self)

Creates a virtual machine on the provisioning server using snap-guest

Raises

robottelo.vm.VirtualMachineError – Whenever a virtual machine could not be executed.

destroy(self)

Destroys the virtual machine on the provisioning server

download_install_rpm(self, repo_url, package_name)

Downloads and installs custom rpm on the virtual machine.

Parameters
  • repo_url – URL to repository, where package is located.

  • package_name – Desired package name.

Returns

None.

Raises

robottelo.vm.VirtualMachineError – If package wasn’t installed.

enable_repo(self, repo, force=False)

Enables specified Red Hat repository on the virtual machine. Does nothing if capsule or satellite tools repo was passed and downstream with custom repo URLs detected (custom repos are enabled by default when registering a host).

Parameters
  • repo – Red Hat repository name.

  • force – enforce enabling command, even when custom repos are detected for satellite tools or capsule.

Returns

None.

subscription_manager_list_repos(self)
subscription_manager_status(self)
create_custom_repos(self, **kwargs)

Create custom repofiles. Each kwargs item will result in one repository file created. Where the key is the repository filename and repository name, and the value is the repository URL.

For example:

create_custom_repo(custom_repo='http://repourl.domain.com/path')

Will create a repository file named custom_repo.repo with the following contents:

[custom_repo]
name=custom_repo
baseurl=http://repourl.domain.com/path
enabled=1
gpgcheck=0
install_katello_agent(self)

Installs katello agent on the virtual machine.

Returns

None.

Raises

robottelo.vm.VirtualMachineError – If katello-ca wasn’t installed.

install_katello_host_tools(self)

Installs Katello host tools on the virtual machine

Raises

robottelo.vm.VirtualMachineError – If katello-host-tools wasn’t installed.

install_katello_ca(self)

Downloads and installs katello-ca rpm on the virtual machine.

Uses common helper install_katello_ca(hostname=None), but passes self.ip_addr instead of the hostname as we are using fake hostnames for virtual machines.

Returns

None.

Raises

robottelo.vm.VirtualMachineError – If katello-ca wasn’t installed.

install_capsule_katello_ca(self, capsule=None)

Downloads and installs katello-ca rpm on the virtual machine.

Param

str capsule: Capsule hostname

Raises

robottelo.vm.VirtualMachineError – If katello-ca wasn’t installed.

register_contenthost(self, org, activation_key=None, lce=None, consumerid=None, force=True, releasever=None, username=None, password=None, auto_attach=False)

Registers content host on foreman server using activation-key. This can be done in two ways: either by specifying organization name and activation key name or by specifying organization name and lifecycle environment name (administrator credentials for authentication will be passed automatically)

Parameters
  • activation_key – Activation key name to register content host with.

  • lce – lifecycle environment name to which register the content host.

  • consumerid – uuid of content host, register to this content host, content host has to be created before

  • org – Organization name to register content host for.

  • force – Register the content host even if it’s already registered

  • releasever – Set a release version

  • username – a user name to register the content host with

  • password – the user password

  • auto_attach – automatically attach compatible subscriptions to this system.

Returns

SSHCommandResult instance filled with the result of the registration.

remove_katello_ca(self)

Removes katello-ca rpm from the virtual machine.

Uses common helper remove_katello_ca(hostname=None), but passes self.ip_addr instead of the hostname as we are using fake hostnames for virtual machines.

Returns

None.

Raises

robottelo.vm.VirtualMachineError – If katello-ca wasn’t removed.

remove_capsule_katello_ca(self, capsule=None)

Removes katello-ca rpm and reset rhsm.conf from the virtual machine.

Param

str capsule: Capsule hostname

Raises

robottelo.vm.VirtualMachineError – If katello-ca wasn’t removed.

unregister(self)

Run subscription-manager unregister.

Returns

SSHCommandResult instance filled with the result of the unregistration.

run(self, cmd, timeout=None)

Runs a ssh command on the virtual machine

Parameters
  • cmd (str) – Command to run on the virtual machine

  • timeout (int) – Time to wait for the ssh command to finish

Returns

A robottelo.ssh.SSHCommandResult instance with the commands results

Return type

robottelo.ssh.SSHCommandResult

Raises

robottelo.vm.VirtualMachineError – If the virtual machine is not created.

get(self, remote_path, local_path=None)

Get a remote file from the virtual machine.

put(self, local_path, remote_path=None)

Put a local file to the virtual machine.

configure_rhel_repo(self, rhel_repo)

Configures specified Red Hat repository on the virtual machine.

Parameters

rhel_repo – Red Hat repository link from properties file.

Returns

None.

configure_puppet(self, rhel_repo=None, proxy_hostname=None)

Configures puppet on the virtual machine/Host. :param proxy_hostname: external capsule hostname :param rhel_repo: Red Hat repository link from properties file. :return: None.

execute_foreman_scap_client(self, policy_id=None)

Executes foreman_scap_client on the vm/clients to create security audit report.

Parameters

policy_id – The Id of the OSCAP policy.

Returns

None.

configure_rhai_client(self, activation_key, org, rhel_distro, register=True)

Configures a Red Hat Access Insights service on the system by installing the redhat-access-insights package and registering to the service.

Parameters
  • activation_key – Activation key to be used to register the system to satellite

  • org – The org to which the system is required to be registered

  • rhel_distro – rhel distribution for

  • register – Whether to register client to insights

Returns

None

set_infrastructure_type(self, infrastructure_type='physical')

Force host to appear as bare-metal or virtual machine in subscription-manager fact.

Parameters

infrastructure_type (str) – One of “physical”, “virtual”

patch_os_release_version(self, distro=DISTRO_RHEL7)

Patch VM OS release version.

This is needed by yum package manager to generate the right RH repositories urls.

__enter__(self)
__exit__(self, *exc)