Location: Pulp SmashAPI Documentationpulp_smash.tests.pulp2.rpm.api_v2.utils

Utility functions for RPM API tests.

class pulp_smash.tests.pulp2.rpm.api_v2.utils.DisableSELinuxMixin

A mixin providing the ability to temporarily disable SELinux.

maybe_disable_selinux(cfg, pulp_issue_id)

Disable SELinux if appropriate.

If the given Pulp issue is unresolved, and if SELinux is installed and enforcing on the target Pulp system, then disable SELinux and schedule it to be re-enabled. (Method addCleanup is used for the schedule.)

  • cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp deployment being targeted.
  • pulp_issue_id – The (integer) ID of a Pulp issue. If the referenced issue is fixed in the Pulp system under test, this method immediately returns.


class pulp_smash.tests.pulp2.rpm.api_v2.utils.TemporaryUserMixin

A mixin providing the ability to create a temporary user.

A typical usage of this mixin is as follows:

ssh_user, priv_key = self.make_user(cfg)
ssh_identity_file = self.write_private_key(cfg, priv_key)

This mixin requires that the unittest.TestCase class from the standard library be a parent class.

static delete_user(cfg, username)

Delete a user.

The Pulp rsync distributor has a habit of leaving (idle?) SSH sessions open even after publishing a repository. When executed, this function will:

  1. Poll the process list until all processes belonging to username have died, or raise a unittest.SkipTest exception if the time limit is exceeded.
  2. Delete username.

Create a user account with a home directory and an SSH keypair.

In addition, schedule the user for deletion with self.addCleanup.

Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about the host being targeted.
Returns:A (username, private_key) tuple.
write_private_key(cfg, private_key)

Write the given private key to a file on disk.

Ensure that the file is owned by user “apache” and has permissions of 600. In addition, schedule the key for deletion with self.addCleanup.

Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about the host being targeted.
Returns:The path to the private key on disk, as a string.

Return a semi-random dict for use in creating a YUM distributor.


Return a semi-random dict for use in creating an RPM repository.


Return a semi-random dict for use in creating a RPM repository group.

pulp_smash.tests.pulp2.rpm.api_v2.utils.get_dists_by_type_id(cfg, repo)

Return the named repository’s distributors, keyed by their type IDs.


A dict in the form {'type_id': {distributor_info}}.

pulp_smash.tests.pulp2.rpm.api_v2.utils.get_repodata(cfg, distributor, type_, response_handler=None, repomd_xml=None)

Download a file of the given type_ from a repodata/ directory.


Whatever is dictated by response_handler.

pulp_smash.tests.pulp2.rpm.api_v2.utils.get_repodata_repomd_xml(cfg, distributor, response_handler=None)

Download the given repository’s repodata/repomd.xml file.


Whatever is dictated by response_handler.

pulp_smash.tests.pulp2.rpm.api_v2.utils.get_rpm_names_versions(cfg, repo)

Get a dict of a repository’s RPMs and their versions.


The name and versions of each package in the repository, with the versions sorted in ascending order. For example: {'walrus': ['0.71', '5.21']}.

pulp_smash.tests.pulp2.rpm.api_v2.utils.get_unit(cfg, distributor, unit_name, primary_xml=None)

Download a file from a published repository.

A typical invocation is as follows:

>>> foo_rpm = get_unit(cfg, repo['distributors'][0], 'foo.rpm')

If multiple units are being fetched, efficiency can be improved by passing in a parsed primary.xml file:

>>> distributor = repo['distributors'][0]
>>> primary_xml = get_repodata(cfg, distributor, 'primary')
>>> foo_rpm = get_unit(cfg, distributor, 'foo.rpm', primary_xml)
>>> bar_rpm = get_unit(cfg, distributor, 'bar.rpm', primary_xml)
  • cfg (pulp_smash.config.PulpSmashConfig) – Information about a Pulp host.
  • distributor – A dict of information about a repository distributor.
  • unit_name – The name of a content unit to be fetched. For example: “bear-4.1-1.noarch.rpm”.
  • primary_xml – A primary.xml file as an ElementTree. If not given, get_repodata() is consulted.

A raw response. The unit is available as response.content.

pulp_smash.tests.pulp2.rpm.api_v2.utils.set_pulp_manage_rsync(cfg, boolean)

Set the pulp_manage_rsync SELinux policy.

If the setsebool executable is not available, return. (This is the case if SELinux isn’t installed on the system under test.) Otherwise, set the pulp_manage_rsync SELinux policy on or off, depending on the truthiness of ``boolean.

For more information on the pulp_manage_rsync SELinux policy, see ISO rsync Distributor → Configuration.


Information about the executed command, or None if no command was executed.

Return type:


pulp_smash.tests.pulp2.rpm.api_v2.utils.xml_handler(_, response)

Decode a response as if it is XML.

This API response handler is useful for fetching XML files made available by an RPM repository. When it handles a response, it will check the status code of response, decompress the response if the request URL ended in .gz, and return an xml.etree.Element instance built from the response body.


  • The entire response XML is loaded and parsed before returning, so this may be unsafe for use with large XML files.
  • The Content-Type and Content-Encoding response headers are ignored due to https://pulp.plan.io/issues/1781.