pulp_smash.config

Location: Pulp SmashAPI Documentationpulp_smash.config

Tools for managing information about test systems.

Pulp Smash needs to know what servers it can talk to and how to talk to those systems. For example, it needs to know the protocol, hostname and port of a Pulp server (e.g. ‘https://example.com:250‘) and how to authenticate with that server. pulp_smash.config.PulpSmashConfig eases the task of managing that information.

pulp_smash.config.AMQP_SERVICES = {'rabbitmq', 'qpidd'}

Set of expected amqp services.

pulp_smash.config.OPTIONAL_ROLES = {'pulp cli', 'squid'}

Set of roles that can be present or not on a Pulp deployment.

class pulp_smash.config.PulpSmashConfig(pulp_auth=None, pulp_version=None, systems=None)

Information about a Pulp deployment.

This object stores a set of information about a Pulp deployment and its systems. A typical usage of this object is as follows:

>>> import requests
>>> from pulp_smash.config import PulpSmashConfig
>>> cfg = PulpSmashConfig(
...     pulp_auth=('username', 'password'),
...     pulp_version='2.12.2',
...     systems=[
...         PulpSystem(
...             hostname='pulp.example.com',
...             roles={
...                 'amqp broker': {'service': 'qpidd'},
...                 'api': {
...                     'scheme': 'https',
...                     'verify': False,  # Disable SSL verification
...                 },
...                 'mongod': {},
...                 'pulp cli': {},
...                 'pulp celerybeat': {},
...                 'pulp resource manager': {},
...                 'pulp workers': {},
...                 'shell': {
...                     'transport': 'ssh',
...                 },
...             },
...         )
...     ]
... )
>>> response = requests.post(
...     cfg.base_url + '/pulp/api/v2/actions/login/',
...     **cfg.get_requests_kwargs()
... )

All methods dealing with files obey the XDG Base Directory Specification. Please read the specification for insight into the logic of those methods.

In addition, the file-facing methods respect the PULP_SMASH_CONFIG_FILE environment variable. By default, the methods work with a file named settings.json, but the environment variable overrides that default. If set, the environment variable should be a file name like settings2.json (or a relative path), not an absolute path.

Parameters:
  • pulp_auth – A two-tuple. Credentials to use when communicating with the server. For example: ('username', 'password').
  • pulp_version – A string, such as ‘1.2’ or ‘0.8.rc3’. Defaults to ‘1!0’ (epoch 1, version 0). Must be compatible with the packaging library’s packaging.version.Version class.
  • systems – A list of pulp_smash.config.PulpSystem. Mapping every system on a given Pulp deployment.
base_url

Map old config base_url to the system with api role.

cli_transport

Map old config cli_transport to the system with shell role.

default_config_file_path

Build the default config file path.

get_base_url(pulp_system=None)

Generate the base URL for a given pulp_sytem.

If pulp_system is None then the first system found with the api role will be chosen.

get_config_file_path()

Get the config file path.

Raises:pulp_smash.exceptions.ConfigFileNotFoundError – If configuration file cannot be found.
get_requests_kwargs(pulp_system=None)

Get kwargs for use by the Requests functions.

This method returns a dict of attributes that can be unpacked and used as kwargs via the ** operator. For example:

>>> cfg = PulpSmashConfig().read()
>>> requests.get(cfg.base_url + '…', **cfg.get_requests_kwargs())

This method is useful because client code may not know which attributes should be passed from a PulpSmashConfig object to Requests. Consider that the example above could also be written like this:

>>> cfg = PulpSmashConfig().get()
>>> requests.get(
...     cfg.base_url + '…',
...     auth=tuple(cfg.pulp_auth),
...     verify=cfg.get_systems('api')[0].roles['api']['verify'],
... )

But this latter approach is more fragile. The user must remember to get a system with api role to check for the verify config, then convert pulp_auth config to a tuple, and it will require maintenance if cfg gains or loses attributes.

get_systems(role)

Return a list of systems fulfilling the given role.

Parameters:role – The role to filter the available systems, see pulp_smash.config.ROLES for more information.
read(xdg_config_file=None, xdg_config_dir=None)

Read a configuration file.

Parameters:
  • xdg_config_file – A string. The name of the file to manipulate.
  • xdg_config_dir – A string. The XDG configuration directory in which the configuration file resides.
Returns:

A new pulp_smash.config.PulpSmashConfig object. The current object is not modified by this method.

Return type:

PulpSmashConfig

Raises:

warnings.DecprecationWarning if the configuration file uses the old format instead of the new system with roles based format.

static services_for_roles(roles)

Return the services based on the roles.

verify

Map old config verify to the system with api role.

version

Map old config version to the pulp_version.

class pulp_smash.config.PulpSystem(hostname, roles)
hostname

Alias for field number 0

roles

Alias for field number 1

pulp_smash.config.REQUIRED_ROLES = {'pulp resource manager', 'pulp celerybeat', 'api', 'amqp broker', 'shell', 'pulp workers', 'mongod'}

Set of roles that are required on a Pulp deployment.

pulp_smash.config.ROLES = {'pulp resource manager', 'pulp celerybeat', 'shell', 'mongod', 'api', 'amqp broker', 'pulp workers', 'pulp cli', 'squid'}

Set of all available roles on a Pulp deployment.

pulp_smash.config.convert_old_config(config_dict)

Convert the old configuration dict representation to the new format.

pulp_smash.config.get_config()

Return a copy of the global PulpSmashConfig object.

This method makes use of a cache. If the cache is empty, the configuration file is parsed and the cache is populated. Otherwise, a copy of the cached configuration object is returned.

Returns:A copy of the global server configuration object.
Return type:pulp_smash.config.PulpSmashConfig
pulp_smash.config.validate_config(config_dict)

Validate the config file schema.

Parameters:config_dict – A dictionary returned by json.load or json.loads after reading the config file.
Raises:pulp_smash.exceptions.ConfigValidationError – If the any validation error is found.