pulp_smash.pulp2.utils¶
Location: Pulp Smash → API Documentation → pulp_smash.pulp2.utils
Utility functions for Pulp 2 tests.
-
class
pulp_smash.pulp2.utils.
BaseAPICrudTestCase
(*args, **kwargs)¶ Bases:
unittest.case.TestCase
A parent class for API CRUD test cases.
create_body()
andupdate_body()
should be overridden by concrete child classes. The bodies of these two methods are encoded to JSON and used as the bodies of HTTP requests for creating and updating a repository, respectively. Be careful to return appropriate data when overriding these methods: the varioustest*
methods assume the repository is fairly simple.Relevant Pulp documentation:
- Create
- http://docs.pulpproject.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#create-a-repository
- Read
- http://docs.pulpproject.org/en/latest/dev-guide/integration/rest-api/repo/retrieval.html#retrieve-a-single-repository
- Update
- http://docs.pulpproject.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#update-a-repository
- Delete
- http://docs.pulpproject.org/en/latest/dev-guide/integration/rest-api/repo/cud.html#delete-a-repository
-
static
create_body
()¶ Return a dict for creating a repository. Should be overridden.
Raises: NotImplementedError
if not implemented by a child class.
-
classmethod
setUpClass
()¶ Create, update, read and delete a repository.
-
test_create
()¶ Assert the created repository has all requested attributes.
Walk through each of the attributes returned by
create_body()
and verify the attribute is present in the repository.NOTE: Any attribute whose name starts with
importer
ordistributor
is not verified.
-
test_importer_config
()¶ Validate the
config
attribute of each importer.
-
test_importer_type_id
()¶ Validate the repo importer’s
importer_type_id
attribute.
-
test_number_importers
()¶ Assert the repository has one importer.
-
test_read
()¶ Assert the repo update response has the requested changes.
-
test_status_codes
()¶ Assert each response has a correct status code.
-
test_update
()¶ Assert the repo update response has the requested changes.
-
static
update_body
()¶ Return a dict for updating a repository. Should be overridden.
Raises: NotImplementedError
if not implemented by a child class.
-
class
pulp_smash.pulp2.utils.
BaseAPITestCase
(*args, **kwargs)¶ Bases:
unittest.case.TestCase
A class with behaviour that is of use in many API test cases.
This test case provides set-up and tear-down behaviour that is common to many API test cases.
Warning
Avoid using BaseAPITestCase. Its design encourages fragile clean-up logic, and it slows down tests by unnecessarily deleting orphans. Try using the addCleanup instance method instead, and only delete orphans as needed.
-
classmethod
setUpClass
()¶ Provide a server config and an iterable of resources to delete.
The following class attributes are created this method:
cfg
- A
pulp_smash.config.PulpSmashConfig
object. resources
- A set object. If a child class creates some resources that should be deleted when the test is complete, the child class should add that resource’s href to this set.
-
classmethod
tearDownClass
()¶ Delete all resources named by
resources
.
-
classmethod
-
class
pulp_smash.pulp2.utils.
DuplicateUploadsMixin
¶ Bases:
object
A mixin that adds tests for the “duplicate upload” test cases.
Consider the following procedure:
- Create a new feed-less repository of any content unit type.
- Upload a content unit into the repository.
- Upload the same content unit into the same repository.
The second upload should silently fail for all Pulp releases in the 2.x series. See:
This mixin adds tests for this case. Child classes should do the following:
- Create a repository. Content units will be uploaded into this repository.
- Create a class or instance attribute named
upload_import_unit_args
. It should be an iterable whose contents match the signature ofupload_import_unit()
.
-
test_01_first_upload
()¶ Upload a content unit to a repository.
-
test_02_second_upload
()¶ Upload the same content unit to the same repository.
-
pulp_smash.pulp2.utils.
get_broker
(cfg)¶ Build an object for managing the target system’s AMQP broker.
Talk to the host named by
cfg
and use simple heuristics to determine which AMQP broker is installed. If Qpid or RabbitMQ appear to be installed, return the name of that service. Otherwise, raise an exception.Parameters: cfg (pulp_smash.config.PulpSmashConfig) – Information about the system on which an AMQP broker exists. Returns: A string such as ‘qpidd’ or ‘rabbitmq’. Raises: pulp_smash.exceptions.NoKnownBrokerError – If unable to find any AMQP brokers on the target system.
-
pulp_smash.pulp2.utils.
get_unit_types
()¶ Tell which unit types are supported by the target Pulp server.
Each Pulp plugin adds one (or more?) content unit types to Pulp, and each content unit type has a unique identifier. For example, the Python plugin [1] adds the Python content unit type [2], and Python content units have an ID of
python_package
. This function queries the server and returns those unit type IDs.Returns: A set of content unit type IDs. For example: {'ostree', 'python_package'}
.[1] http://docs.pulpproject.org/plugins/pulp_python/ [2] http://docs.pulpproject.org/plugins/pulp_python/reference/python-type.html
-
pulp_smash.pulp2.utils.
publish_repo
(cfg, repo, json=None)¶ Publish a repository.
Parameters: - cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
- repo – A dict of detailed information about the repository to be published.
- json – Data to be encoded as JSON and sent as the request body.
Defaults to
{'id': repo['distributors'][0]['id']}
.
Raises: ValueError
whenjson
is not passed, andrepo
does not have exactly one distributor.Returns: The server’s reponse. Call
.json()
on the response to get a call report.
-
pulp_smash.pulp2.utils.
pulp_admin_login
(cfg)¶ Execute
pulp-admin login
.Parameters: cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp server being targeted. Returns: The completed process. Return type: pulp_smash.cli.CompletedProcess
-
pulp_smash.pulp2.utils.
require_issue_3159
(exc)¶ Skip tests if Fedora 27 is under test and Pulp #3159 is open.
Parameters: exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.
-
pulp_smash.pulp2.utils.
require_issue_3687
(exc)¶ Skip tests if Fedora 27 is under test and Pulp #3687 is open.
Parameters: exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.
-
pulp_smash.pulp2.utils.
require_pulp_2
(exc)¶ Skip tests if Pulp 2 isn’t under test.
Parameters: exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.
-
pulp_smash.pulp2.utils.
require_unit_types
(required_unit_types, exc)¶ Skip tests if one or more unit types aren’t supported.
Parameters: - required_unit_types – A set of unit types IDs, e.g.
{'ostree'}
. - exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.
- required_unit_types – A set of unit types IDs, e.g.
-
pulp_smash.pulp2.utils.
reset_pulp
(cfg)¶ Stop Pulp, reset its database, remove certain files, and start it.
Parameters: cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp server being targeted. Returns: Nothing.
-
pulp_smash.pulp2.utils.
reset_squid
(cfg)¶ Stop Squid, reset its cache directory, and restart it.
Parameters: cfg (pulp_smash.config.PulpSmashConfig) – Information about a Pulp host. Returns: Nothing.
-
pulp_smash.pulp2.utils.
search_units
(cfg, repo, criteria=None, response_handler=None)¶ Find content units in a
repo
.Parameters: - cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
- repo – A dict of detailed information about the repository.
- criteria – A dict of criteria to pass in the search body. Defaults to an empty dict.
- response_handler – The callback function used by
pulp_smash.api.Client
after searching. Defaults topulp_smash.api.json_handler()
.
Returns: Whatever is dictated by
response_handler
.
-
pulp_smash.pulp2.utils.
sync_repo
(cfg, repo)¶ Sync a repository.
Parameters: - cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
- repo – A dict of detailed information about the repository to be synced.
Returns: The server’s reponse. Call
.json()
on the response to get a call report.
-
pulp_smash.pulp2.utils.
upload_import_erratum
(cfg, erratum, repo)¶ Upload an erratum to a Pulp server and import it into a repository.
For most content types, use
upload_import_unit()
.Parameters: - cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp server being targeted.
- erratum – A dict, with keys such as “id,” “status,” “issued,” and “references.”
- repo – A dict. The repository into which
erratum
be imported.
Returns: The call report returned when importing the erratum.
-
pulp_smash.pulp2.utils.
upload_import_unit
(cfg, unit, import_params, repo)¶ Upload a content unit to a Pulp server and import it into a repository.
This procedure only works for some unit types, such as
rpm
orpython_package
. Others, likepackage_group
, require an alternate procedure. The procedure encapsulated by this function is as follows:- Create an upload request.
- Upload the content unit to Pulp, in small chunks.
- Import the uploaded content unit into a repository.
- Delete the upload request.
The default set of parameters sent to Pulp during step 3 are:
{'unit_key': {}, 'upload_id': '…'}
The actual parameters required by Pulp depending on the circumstances, and the parameters sent to Pulp may be customized via the
import_params
argument. For example, if uploading a Python content unit,import_params
should be the following:{'unit_key': {'filename': '…'}, 'unit_type_id': 'python_package'}
This would result in the following upload parameters being used:
{ 'unit_key': {'filename': '…'}, 'unit_type_id': 'python_package', 'upload_id': '…', }
Parameters: - cfg (pulp_smash.config.PulpSmashConfig) – Information about a Pulp host.
- unit – The unit to be uploaded and imported, as a binary blob.
- import_params – A dict of parameters to be merged into the default set of import parameters during step 3.
- repo – A dict of information about the target repository.
Returns: The call report returned when importing the unit.