pulp_2_tests.tests.rpm.api_v2.utils

Location: Pulp 2 TestsTestspulp_2_tests.tests.rpm.api_v2.utils

Utility functions for RPM API tests.

class pulp_2_tests.tests.rpm.api_v2.utils.DisableSELinuxMixin

Bases: object

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.)

Parameters:
  • cfg – 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.
Returns:

Nothing.

class pulp_2_tests.tests.rpm.api_v2.utils.TemporaryUserMixin

Bases: object

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.
make_user(cfg)

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

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

Parameters:cfg – 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 – Information about the host being targeted.
Returns:The path to the private key on disk, as a string.
pulp_2_tests.tests.rpm.api_v2.utils.gen_consumer()

Create a semi-random dict for use in creating a consumer.

pulp_2_tests.tests.rpm.api_v2.utils.gen_distributor(**kwargs)

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

pulp_2_tests.tests.rpm.api_v2.utils.gen_repo(**kwargs)

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

pulp_2_tests.tests.rpm.api_v2.utils.gen_repo_group(**kwargs)

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

pulp_2_tests.tests.rpm.api_v2.utils.get_dists_by_type_id(cfg, repo)

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

Parameters:
  • cfg – Information about a Pulp host.
  • repo_href – A dict of information about a repository.
Returns:

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

pulp_2_tests.tests.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.

Parameters:
  • cfg – Information about a Pulp host.
  • distributor – A dict of information about a repository distributor.
  • type – The type of file to fetch from a repository’s repodata/ directory. Valid values might be “updateinfo” or “group”.
  • response_handler – The callback function used by pulp_smash.api.Client after downloading the repomd.xml file. Defaults to xml_handler(). Use pulp_smash.api.safe_handler if you want the raw response.
  • repomd_xml – A repomd.xml file as an ElementTree. If not given, get_repodata_repomd_xml() is consulted.
Returns:

Whatever is dictated by response_handler.

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

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

Parameters:
  • cfg – Information about a Pulp host.
  • distributor – A dict of information about a repository distributor.
  • response_handler – The callback function used by pulp_smash.api.Client after downloading the repomd.xml file. Defaults to xml_handler(). Use pulp_smash.api.safe_handler if you want the raw response.
Returns:

Whatever is dictated by response_handler.

pulp_2_tests.tests.rpm.api_v2.utils.get_rpm_names_versions(cfg, repo)

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

Parameters:
  • cfg – Information about a Pulp app.
  • repo – A dict of information about a repository.
Returns:

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_2_tests.tests.rpm.api_v2.utils.get_rpm_published_path(cfg, repo, rpm_name)

Return the absolute path to pulp_2_tests.constants.RPM.

pulp_2_tests.tests.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)
Parameters:
  • cfg – 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.
Returns:

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

pulp_2_tests.tests.rpm.api_v2.utils.get_xml_content_from_fixture(fixture_path, data_type)

Return the required xml content from the given fixture_path.

This method should be called when an xml object of the following is data_type are required.

  • group
  • filelists
  • updateinfo
  • group_gz
  • modules
  • primary
  • other

This function should be called only when the data of type xml is required. These data_type are present in repodata/repomd.xml file. The function parses the repomd.xml file, gathers the location of the data_type object, downloads the file and handles it using the xml_handler and finally returns xml.etree.Element of the root node.

Parameters:
  • fixture_path – Url path containing the fixtures.
  • data_type – The required xml file content that needs to be downloaded.
Returns:

An``xml.etree.Element`` object of the requested xml_file.

pulp_2_tests.tests.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.

Parameters:
  • cfg – Information about a Pulp host.
  • boolean – Either True or False.
Returns:

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

pulp_2_tests.tests.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.

Note:

  • 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.