robottelo.helpers

Several helper methods and functions.

Module Contents

Classes

ServerFileDownloader

Downloads file from given fileurl to local /temp dirctory.

Storage

Turns a dict into an attribute based object.

Functions

file_downloader(file_url, local_path=None, file_name=None, hostname=None)

Downloads file from given fileurl to directory specified by local_path

get_server_software()

Figure out which product distribution is installed on the server.

get_server_version()

Read Satellite version.

get_host_info(hostname=None)

Get remote host’s distribution information

get_nailgun_config(user=None)

Return a NailGun configuration file constructed from default values.

escape_search(term)

Wraps a search term in ” and escape term’s ” and characters

update_dictionary(default, updates)

Updates default dictionary with elements from

get_data_file(filename)

Returns correct path of file from data folder.

read_data_file(filename)

Read the contents of data file

install_katello_ca(hostname=None, sat_hostname=None)

Downloads and installs katello-ca rpm

remove_katello_ca(hostname=None)

Removes katello-ca rpm

md5_by_url(url, hostname=None)

Returns md5 checksum of a file, accessible via URL. Useful when you want

add_remote_execution_ssh_key(hostname, key_path=None, proxy_hostname=None, **kwargs)

Add remote execution keys to the client

get_available_capsule_port(port_pool=None)

returns a list of unused ports dedicated for fake capsules

default_url_on_new_port(oldport, newport)

Creates context where the default capsule is forwarded on a new port

get_func_name(func, test_item=None)

Given a func object return standardized name to use across project

get_services_status()

Check if core services are running

form_repo_path(org=None, lce=None, cv=None, cvv=None, prod=None, repo=None, capsule=False)

Forms unix path to the directory containing published repository in

create_repo(name, repo_fetch_url=None, packages=None, wipe_repodata=False, hostname=None)

Creates a repository from given packages and publishes it into pulp’s

repo_add_updateinfo(name, updateinfo_url=None, hostname=None)

Modify repo with contents of updateinfo.xml file.

extract_capsule_satellite_installer_command(text)

Extract satellite installer command from capsule-certs-generate command

extract_ui_token(input)

Extracts and returns the CSRF protection token from a given

get_web_session()

Logs in as admin user and returns the valid requests.Session object

host_provisioning_check(ip_addr)

Check the provisioned host status by pinging the ip of host and check

slugify_component(string, keep_hyphens=True)

Make component name a slug

download_gce_cert()

idgen(val)

The id generator function which will return string that will append to the parameterized

Attributes

LOGGER

download_server_file

robottelo.helpers.LOGGER
exception robottelo.helpers.DataFileError

Bases: Exception

Indicates any issue when reading a data file.

exception robottelo.helpers.HostInfoError

Bases: Exception

Indicates any issue when getting host info.

exception robottelo.helpers.ProvisioningCheckError

Bases: Exception

Indicates any issue when provisioning a host.

exception robottelo.helpers.InvalidArgumentError

Bases: Exception

Indicates an error when an invalid argument is received.

exception robottelo.helpers.ProxyError

Bases: Exception

Indicates an error in state of proxy

exception robottelo.helpers.DownloadFileError

Bases: Exception

Indicates an error when failure in downloading file from server.

class robottelo.helpers.ServerFileDownloader

Downloads file from given fileurl to local /temp dirctory.

__call__(self, extention, fileurl)

Downloads file from given fileurl to local /temp directory with given extention.

Parameters
  • extention (str) – The file extention with which the file to be saved in /temp directory.

  • fileurl (str) – The complete server file path from where the file will be downloaded.

Returns

Returns complete file path with name of downloaded file.

robottelo.helpers.download_server_file
robottelo.helpers.file_downloader(file_url, local_path=None, file_name=None, hostname=None)

Downloads file from given fileurl to directory specified by local_path with given file_name on host specified by hostname. Leave hostname as None to download file on the localhost.If remote directory is not specified it downloads file to /tmp/.

Parameters
  • file_url (str) – The complete server file path from where the file will be downloaded.

  • local_path (str) – Name of directory where file will be saved. If not provided file will be saved in /tmp/ directory.

  • file_name (str) – Name of the file to be saved with. If not provided filename from url will be used.

  • hostname (str) – Hostname of server where the file need to be downloaded.

Returns

Returns list containing complete file path and name of downloaded file.

robottelo.helpers.get_server_software()

Figure out which product distribution is installed on the server.

Returns

Either ‘upstream’ or ‘downstream’.

Return type

str

robottelo.helpers.get_server_version()

Read Satellite version.

Inspect server /usr/share/foreman/lib/satellite/version.rb in order to get the installed Satellite version.

Returns

Either a string containing the Satellite version or None if the version.rb file is not present.

robottelo.helpers.get_host_info(hostname=None)

Get remote host’s distribution information

Parameters

hostname (str) – Hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config.

Returns

A tuple in the form (distro, major, minor). major and minor are integers. minor can be None if not available.

robottelo.helpers.get_nailgun_config(user=None)

Return a NailGun configuration file constructed from default values.

Parameters

user – The `nailgun.entities.User` object of an user with additional passwd property/attribute

Returns

nailgun.config.ServerConfig object, populated from user parameter object else with values from robottelo.config.settings

Wraps a search term in ” and escape term’s ” and characters

robottelo.helpers.update_dictionary(default, updates)

Updates default dictionary with elements from optional dictionary.

@param default: A python dictionary containing the minimal required arguments to create a CLI object. @param updates: A python dictionary containing attributes to overwrite on default dictionary.

@return default: The modified default python dictionary.

robottelo.helpers.get_data_file(filename)

Returns correct path of file from data folder.

robottelo.helpers.read_data_file(filename)

Read the contents of data file

robottelo.helpers.install_katello_ca(hostname=None, sat_hostname=None)

Downloads and installs katello-ca rpm

Parameters

hostname (str) – Hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config

Returns

None.

Raises

AssertionError: If katello-ca wasn’t installed.

robottelo.helpers.remove_katello_ca(hostname=None)

Removes katello-ca rpm

Parameters

hostname (str) – Hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config

Returns

None.

Raises

AssertionError: If katello-ca wasn’t removed.

robottelo.helpers.md5_by_url(url, hostname=None)

Returns md5 checksum of a file, accessible via URL. Useful when you want to calculate checksum but don’t want to deal with storing a file and removing it afterwards.

Parameters
  • url (str) – URL of a file.

  • hostname (str) – Hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config

Return str

string containing md5 checksum.

Raises

AssertionError: If non-zero return code received (file couldn’t be reached or calculation was not successful).

robottelo.helpers.add_remote_execution_ssh_key(hostname, key_path=None, proxy_hostname=None, **kwargs)

Add remote execution keys to the client

Parameters
  • proxy_hostname (str) – external capsule hostname

  • hostname (str) – The client hostname

  • key (str) – Path to a key on the satellite server

  • kwargs (dict) – directly passed to ssh.add_authorized_key

robottelo.helpers.get_available_capsule_port(port_pool=None)

returns a list of unused ports dedicated for fake capsules This calls an ss command on the server prompting for a port range. ss returns a list of ports which have a PID assigned (a list of ports which are already used). This function then substracts unavailable ports from the other ones and returns one of available ones randomly.

Parameters

port_pool – A list of ports used for fake capsules (for RHEL7+: don’t forget to set a correct selinux context before otherwise you’ll get Connection Refused error)

Returns

Random available port from interval <9091, 9190>.

Return type

int

robottelo.helpers.default_url_on_new_port(oldport, newport)

Creates context where the default capsule is forwarded on a new port

Parameters
  • oldport (int) – Port to be forwarded.

  • newport (int) – New port to be used to forward oldport.

Returns

A string containing the new capsule URL with port.

Return type

str

class robottelo.helpers.Storage(*args, **kwargs)

Turns a dict into an attribute based object.

Example:

d = {'foo': 'bar'}
d['foo'] == 'bar'
storage = Storage(d)
storage.foo == 'bar'
robottelo.helpers.get_func_name(func, test_item=None)

Given a func object return standardized name to use across project

robottelo.helpers.get_services_status()

Check if core services are running

robottelo.helpers.form_repo_path(org=None, lce=None, cv=None, cvv=None, prod=None, repo=None, capsule=False)

Forms unix path to the directory containing published repository in pulp using provided entity names. Supports both repositories in content view version and repositories in lifecycle environment. Note that either cvv or lce is required.

Parameters
  • org (str) – organization label

  • optional lce (str) – lifecycle environment label

  • cv (str) – content view label

  • optional cvv (str) – content view version, e.g. ‘1.0’

  • prod (str) – product label

  • repo (str) – repository label

  • capsule (bool) – whether the repo_path is from a capsule or not

Returns

full unix path to the specific repository

Return type

str

robottelo.helpers.create_repo(name, repo_fetch_url=None, packages=None, wipe_repodata=False, hostname=None)

Creates a repository from given packages and publishes it into pulp’s directory for web access.

Parameters
  • name (str) – repository name - name of a directory with packages

  • repo_fetch_url (str) – URL to fetch packages from

  • packages – list of packages to fetch (with extension)

  • wipe_repodata – whether to recursively delete repodata folder

  • optional hostname (str) – hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config.

Returns

URL where the repository can be accessed

Return type

str

robottelo.helpers.repo_add_updateinfo(name, updateinfo_url=None, hostname=None)

Modify repo with contents of updateinfo.xml file.

Parameters
  • name (str) – repository name

  • optional updateinfo_url (str) – URL to download updateinfo.xml file from. If not specified - updateinfo.xml from repository folder will be used instead

  • optional hostname (str) – hostname or IP address of the remote host. If None the hostname will be get from main.server.hostname config.

Returns

result of executing modifyrepo command

robottelo.helpers.extract_capsule_satellite_installer_command(text)

Extract satellite installer command from capsule-certs-generate command output

robottelo.helpers.extract_ui_token(input)

Extracts and returns the CSRF protection token from a given HTML string

robottelo.helpers.get_web_session()

Logs in as admin user and returns the valid requests.Session object

robottelo.helpers.host_provisioning_check(ip_addr)

Check the provisioned host status by pinging the ip of host and check to connect to ssh port

Parameters

ip_addr – IP address of the provisioned host

Returns

ssh command return code and stdout

robottelo.helpers.slugify_component(string, keep_hyphens=True)

Make component name a slug

Arguments:

string {str} – Component name e.g: ActivationKeys keep_hyphens {bool} – Keep hyphens or replace with underscores

Returns:

str – component slug e.g: activationkeys

robottelo.helpers.download_gce_cert()
robottelo.helpers.idgen(val)

The id generator function which will return string that will append to the parameterized test name