common Package

common Package

This package contains some functions, which are likely to be shared between modules.

When decide to put a function here?:

  • When it’s enough universal to be used with multiple modules
  • It can’t be parameter for py.test
common.audrey_service_path = '/var/audrey/tooling/user'
Variables:audrey_service_path – Where are all Audrey services from XML located

beaker Module

common.beaker.list_tests(inputfile)[source]

Returns Beaker tasks list

Returns:Beaker tasks list
Return type:list

elf Module

common.elf.fortify_find_dangerous(filename)[source]

Finds potentially dangerous func-calls in desired file

Parameters:filename (str) – File to check
Returns:list of the potentially dangerous func-calls
Return type:str
common.elf.is_elf(filename)[source]

Checks whether file is ELF executable

Parameters:filename (str) – file name to check
Returns:Whether file is ELF executable
common.elf.readelf(filename)[source]

Returns content of the readelf --all call.

Parameters:filename (str) – File to check
Returns:Content of the ELF analysis
Return type:str

katello Module

common.katello.poll_task_state(server, port, task_uuid, login, password)[source]

This function returns state of task with given UUID. Useful when polling certain task if finished or not.

Parameters:
  • server (str) – Katello server to poll on.
  • port (str) – Katello port to poll on.
  • task_uuid (str) – Checked task’s unique ID
  • password (str) – Login password into Katello server
  • package (str) – Package to install into system
Returns:

Reported task state

Return type:

str

common.katello.query_remote_install(server, port, uuid, login, password, package)[source]

This function installs package into guest system via Katello request. Basically, it tells Katello “Hey, Katello, install these packages into machine with that UUID”

Parameters:
  • server (str) – Remote Katello server
  • port (str) – Remote Katello port
  • uuid (str) – Target machine UUID
  • login (str) – Login name into Katello server
  • password (str) – Login password into Katello server
  • package (str) – Package to install into system
Raises :

pytest.Failed

common.katello.system_group_add_system(server, port, org, uuid, login, password, group_id)[source]

This function adds a system to a specified system group

Parameters:
  • server (str) – Remote Katello server
  • port (str) – Remote Katello port
  • org (str) – Katello organization
  • uuid (str) – Target machine UUID
  • login (str) – Login name into Katello server
  • password (str) – Login password into Katello server
  • group_id (str) – Id of the system group to create
Raises :

pytest.Failed

common.katello.system_group_create(server, port, org, login, password, group_name)[source]

This function creates a system group via a katello API request.

Parameters:
  • server (str) – Remote Katello server
  • port (str) – Remote Katello port
  • org (str) – Katello organization
  • login (str) – Login name into Katello server
  • password (str) – Login password into Katello server
  • group_name (str) – Name of the system group to create
Raises :

pytest.Failed

common.katello.system_group_query(server, port, org, login, password, query_name=None)[source]

net Module

exception common.net.DownloadException[source]

Bases: exceptions.Exception

common.net.download_file(url, target_file_name, bulletproof=False)[source]

Downloads file from desired URL. Can be specified as bulletproof, if downloading from Gitweb-site

Parameters:
  • url (str) – URL where to download from
  • target_file_name (str) – Target file name
  • bulletproof (bool) – Whether it has to check if it didn’t download garbage or not
common.net.list_opened_files(pid)[source]

This function lists opened files of certain process specified by PID

Parameters:pid (int) – PID of the process
common.net.make_auth_request(url, login, password)[source]

Creates request with basic HTTP authentication

Parameters:
  • url (str) – URL to use for request
  • login (str) – Login name
  • password (str) – Login password
Returns:

Basic HTTP authenticated request

Return type:

urllib2.Request

common.net.service_bound_localhost(service)[source]

This function checks whether certain service is bound only to localhost.

Parameters:service (str) – Service name
Returns:True when it’s bound only to localhost, otherwise False
Return type:bool

rpm Module

exception common.rpm.RPMPackageFailure[source]

Bases: exceptions.Exception

exception common.rpm.RPMScriptletFailure[source]

Bases: exceptions.Exception

common.rpm.RPM_PROBLEMS_MESSAGES = {'S': 'size', '5': 'MD5 checksum', 'D': 'major and minor numbers', 'G': 'group', 'U': 'owner', 'M': 'mode', 'L': 'symbolic link contents', 'T': 'modification time'}

Contains messages reported by RPM tests for each problem

common.rpm.check_for_errors(text)[source]

This function checks for errors in text and returns text unchanged

Parameters:text (str) – text to be checked
Returns:text
Return type:str
common.rpm.e(package)[source]

Performs a ‘rpm -e’ command

Parameters:package (str) – Package to be removed
common.rpm.keys_import(keydir='/etc/pki/rpm-gpg')[source]

This function imports all keys in directory ‘/etc/pki/rpm-gpg’ by default

common.rpm.package_build_host(package)[source]

Returns build host of the package.

Parameters:package (str) – Package to check
Returns:Build host of the package
Return type:str
common.rpm.package_installed(package)[source]

Returns whether is package installed or not

Parameters:package (str) – Package name
Returns:True when package is installed, otherwise False
Return type:bool
common.rpm.package_problems(package)[source]

This functions returns reported problems with package

Parameters:package (str) – Package to check
Returns:STDOUT of rpm -V
Return type:str
common.rpm.q(package, qf=None)[source]

Performs a ‘rpm -q’ command with optional –qf parameter

Parameters:
  • package (str) – Package to query
  • qf (str) – --qf parameter value
Returns:

Package informations

Return type:

str

common.rpm.qa(qf=None)[source]

Performs a ‘rpm -qa’ command with optional –qf parameter

Parameters:qf (str) – --qf parameter value
Returns:Package informations
Return type:str
common.rpm.ql(package)[source]

Performs a ‘rpm -ql’ command

Parameters:package (str) – Package to be listed
common.rpm.signature_lines(package_lines)[source]

Returns lines with signature informations of package

Parameters:package_lines (list[str]) – rpm –verify output for the package
Returns:List of lines speaking about signatures
Return type:list(str)
common.rpm.verify_package_files(package)[source]

Verifies package in RPM database.

Checks output of the rpm -Vvv and looks for files, which have some problems (see http://www.rpm.org/max-rpm/s1-rpm-verify-output.html) When using RHEL5, $? is ignored.
Parameters:package (str) – Package to check
Returns:Bool whether verification succeeded
Return type:bool
common.rpm.verify_package_signed(package)[source]

Verifies package in RPM database.

Checks for signature.
Parameters:package (str) – Package to check
Returns:Bool whether verification of signature succeeded
Return type:bool
common.rpm.wrong_files_lines(package_lines)[source]

Returns lines with problem files

Parameters:package_lines (list[str]) – rpm –verify output for the package
Returns:List of lines speaking about wrong something about files
Return type:list(str)

selinux Module

common.selinux.getenforce()[source]

Returns enforcing mode of SElinux

Returns:Enforcing mode of SELinux
Return type:str
common.selinux.setenforce(mode)[source]

Sets enforcing mode of SElinux

Parameters:
  • mode – Enforcing mode from [Permissive, Enforcing]
  • typestr
Raises :

AssertionError

shell Module

class common.shell.Run(stdout, stderr, stdin, rc, command, shell=False)[source]

Bases: object

New class for running shell commands. To run a command, use the Run.command(...) class method. Result contains stdout, stderr, rc and run command: self.stdout, self.stderr, self.rc, self.command. Result is usable in if, if the $?=0, if evaluates as True.

Run.bash() runs bash script provides as a parameter.

AssertRC(rc=0)[source]

Assert used for testing on certain RC values

Raises :AssertionError
classmethod bash(script_body, stdin=None)[source]

Uses Run.command(...) to open bash shell and feed it with script from string script_body.

Returns:Run() instance with resulting data
classmethod command(command, stdin=None, shell=False)[source]

Runs specified command.

The command can be fed with data on stdin with parameter stdin. The command can also be treated as a shell command with parameter shell. Please refer to subprocess.Popen on how does this stuff work

Returns:Run() instance with resulting data
rerun()[source]

Performs a new run of the command which produced this result

Returns:Instance of Run() class
common.shell.command(command)[source]

DEPRECATED, PLEASE DO NOT USE IN THE NEW CODE!!!!!

Function used for calling shell commands rather than invoking programs.

Parameters:command (str) – Command to be launched
Returns:tuple of STDOUT and RC of the command
Raises :AssertionError
common.shell.command_stderr(command)[source]

DEPRECATED, PLEASE DO NOT USE IN THE NEW CODE!!!!!

Function used for calling shell commands rather than invoking programs. It also returns stderr output, so it’s basically the same as the preceeding function, just return tuple extended

Parameters:command (str) – Command to be launched
Returns:tuple of STDOUT and RC of the command
Raises :AssertionError
common.shell.copy(source, destination)[source]
common.shell.exists_in_path(file, actual_directory)[source]

This function looks whether a file exists in system PATH or actual directory.

Parameters:
  • file (str) – File to look for
  • actual_directory (str) – Actual directory we are in
Returns:

File existence True or False

Return type:

bool

common.shell.mkdir(directory)[source]
common.shell.run(cmd, errorcode=0)[source]

DEPRECATED, PLEASE DO NOT USE IN THE NEW CODE!!!!!

This function runs desired command and checks whether it has failed or not

Parameters:
  • cmd (str or list (shlex-splitted)) – Command to be run
  • errorcode (int, list, None) – Desired error code of the program. Defaults to 0 (all ok). If set to None, error code won’t be checked. If it is list, then it checks whether program ended with errorcode specified in list and returns the error code
Returns:

STDOUT of called process

Return type:

str, int

Raises :

AssertionError

tools Module

common.tools.append_file(target, fromf, strip_sep=False)[source]

This function appends one file to another. It’s possible to strip the content from blank characters at beginning and end + separate the contents by

Parameters:
  • target (str) – Target file
  • target – Source file
  • strip_sep (bool) – Whether to strip the contents and separate new file by
Returns:

None

Return type:

None

common.tools.filename_from_url(url)[source]

Extracts the filename from given URL

Parameters:url (str) – URL to be used for extraction
Returns:File name from URL
Return type:str
common.tools.s_format(s, dct)[source]

Does the dict-format of string. Python-version-proof.

Parameters:
  • s (str) – Formatting string
  • dct (dict) – Replacing dictionary
Returns:

Formatted string.

Return type:

str

yum Module

common.yum.check_update(package_name)[source]

Using the ‘yum check-update <package>’ command, determines whether an update is available for the provided package.

Parameters:package_name (str) – Name of the package to be checked for update (eg. katello-all)
Raises :AssertionError
common.yum.get_yum_variable(key)[source]

???

common.yum.groupinstall(group)[source]

Does the ‘yum groupinstall <package>’ command.

Parameters:package_name (str) – Name of the group to install (eg. katello-all)
Raises :AssertionError
common.yum.grouplist()[source]

Does the ‘yum grouplist’ command.

Raises :AssertionError
common.yum.install(package_name)[source]

Does the ‘yum install <package>’ command.

Parameters:package_name (str) – Name of the package to install (eg. katello-all)
Raises :AssertionError
common.yum.remove(package_name)[source]

Does the ‘yum remove <package>’ command.

Parameters:package_name (str) – Name of the package to be removed (eg. katello-all)
Raises :AssertionError
common.yum.repolist()[source]

Does the ‘yum repolist’ command.

Raises :AssertionError
common.yum.search(package_name)[source]

Does the ‘yum search <package>’ command.

Parameters:package_name (str) – Name of the package to install (eg. katello-all)
Raises :AssertionError
common.yum.set_yum_variable(key, value)[source]

???

common.yum.update()[source]

Does the ‘yum update’ command.

Raises :AssertionError
common.yum.update_config(repo_file, enabled=True)[source]

Enables or disables all sections in Yum config files

Parameters:
  • repo_file (str) – Config file, which should be processed
  • enabled (bool) – Whether to enable or disable
common.yum.update_plugin(plugin_conf, enabled=True)[source]

Enables or disables all sections in Yum plugin config files

Parameters:
  • repo_file (str) – Config file, which should be processed
  • enabled (bool) – Whether to enable or disable
common.yum.update_repo(repo_file, enabled=True)[source]

Enables or disables all sections in Yum repository files

Parameters:
  • repo_file (str) – Repo file, which should be processed
  • enabled (bool) – Whether to enable or disable