pulp_smash.config

Location: Pulp SmashAPI Documentationpulp_smash.config

Tools for managing information about hosts under test.

Pulp Smash needs to know about the Pulp application under test and the hosts that comprise that application. For example, it might need to know which username and password to use when communicating with a Pulp application, or it might need to know which host is hosting the squid service, if any. This module eases the task of managing that information.

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

The set of services that can fulfill the amqp broker role.

pulp_smash.config.CONFIG_JSON_SCHEMA = {'additionalProperties': False, 'definitions': {'host': {'required': ['hostname', 'roles'], 'type': 'object', 'additionalProperties': False, 'properties': {'roles': {'required': ['shell'], 'type': 'object', 'additionalProperties': False, 'properties': {'pulp cli': {'type': 'object'}, 'mongod': {'type': 'object'}, 'amqp broker': {'required': ['service'], 'type': 'object', 'properties': {'service': {'enum': ['rabbitmq', 'qpidd'], 'type': 'string'}}}, 'pulp celerybeat': {'type': 'object'}, 'squid': {'type': 'object'}, 'shell': {'type': 'object', 'properties': {'transport': {'enum': ['local', 'ssh'], 'type': 'string'}}}, 'pulp resource manager': {'type': 'object'}, 'api': {'required': ['scheme'], 'type': 'object', 'properties': {'scheme': {'enum': ['http', 'https'], 'type': 'string'}, 'verify': {'type': ['boolean', 'string']}, 'port': {'maximum': 65535, 'type': 'integer', 'minimum': 0}}}, 'pulp workers': {'type': 'object'}}}, 'hostname': {'type': 'string', 'format': 'hostname'}}}}, 'properties': {'pulp': {'required': ['auth', 'version'], 'type': 'object', 'additionalProperties': False, 'properties': {'selinux enabled': {'type': 'boolean'}, 'auth': {'type': 'array', 'maxItems': 2, 'minItems': 2}, 'version': {'type': 'string'}}}, 'hosts': {'type': 'array', 'minItems': 1, 'items': {'$ref': '#/definitions/host'}}}, 'required': ['pulp', 'hosts'], 'type': 'object'}

The schema for Pulp Smash’s configuration file.

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

Additional roles that can be present in a Pulp application.

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

Alias for field number 0

roles

Alias for field number 1

class pulp_smash.config.PulpSmashConfig(pulp_auth, pulp_version, pulp_selinux_enabled, *, hosts)

Information about a Pulp application.

This object stores information about Pulp application and its constituent hosts. A single Pulp application may have its services spread across several hosts. For example, one host might run Qpid, another might run MongoDB, and so on. Here’s how to model a multi-host deployment where Apache runs on one host, and the remaining components run on another host:

>>> import requests
>>> from pulp_smash.config import PulpSmashConfig
>>> cfg = PulpSmashConfig(
...     pulp_auth=('username', 'password'),
...     pulp_version='2.12.2',
...     pulp_selinux_enabled=True,
...     hosts=[
...         PulpHost(
...             hostname='pulp1.example.com',
...             roles={'api': {'scheme': 'https'}},
...         ),
...         PulpHost(
...             hostname='pulp.example.com',
...             roles={
...                 'amqp broker': {'service': 'qpidd'},
...                 'mongod': {},
...                 'pulp celerybeat': {},
...                 'pulp resource manager': {},
...                 'pulp workers': {},
...                 'shell': {'transport': 'ssh'},
...             },
...         )
...     ]
... )

In the simplest case, all of the services that comprise a Pulp applicaiton run on a single host. Here’s an example of how this object might model a single-host deployment:

>>> import requests
>>> from pulp_smash.config import PulpSmashConfig
>>> cfg = PulpSmashConfig(
...     pulp_auth=('username', 'password'),
...     pulp_version='2.12.2',
...     pulp_selinux_enabled=True,
...     hosts=[
...         PulpHost(
...             hostname='pulp.example.com',
...             roles={
...                 'amqp broker': {'service': 'qpidd'},
...                 'api': {'scheme': 'https'},
...                 'mongod': {},
...                 'pulp cli': {},
...                 'pulp celerybeat': {},
...                 'pulp resource manager': {},
...                 'pulp workers': {},
...                 'shell': {'transport': 'ssh'},
...             },
...         )
...     ]
... )

In the simplest case, Pulp Smash’s configuration file resides at ~/.config/pulp_smash/settings.json. However, there are several ways to alter this path. Pulp Smash obeys the XDG Base Directory Specification. In addition, Pulp Smash responds to the PULP_SMASH_CONFIG_FILE environment variable. This variable is a relative path, and it defaults to settings.json.

Configuration files contain JSON data structured in a way that resembles what is accepted by this class’s constructor. For exact details on the structure of configuration files, see pulp_smash.config.CONFIG_JSON_SCHEMA.

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’. If you are unsure what to pass, consider passing ‘1!0’ (epoch 1, version 0). Must be compatible with the packaging library’s packaging.version.Version class.
  • pulp_selinux_enabled – A boolean. Determines whether selinux tests are enabled.
  • hosts – A list of the hosts comprising a Pulp application. Each element of the list should be a pulp_smash.config.PulpHost object.
get_base_url(pulp_host=None)

Generate the base URL for a given pulp_host.

Parameters:pulp_host (pulp_smash.config.PulpHost) – One of the hosts that comprises a Pulp application. Defaults to the first host with the api role.
get_hosts(role)

Return a list of hosts fulfilling the given role.

Parameters:role – The role to filter the available hosts, see pulp_smash.config.ROLES for more information.
classmethod get_load_path(xdg_subdir=None, config_file=None)

Return the path to where a configuration file may be loaded from.

Search each of the $XDG_CONFIG_DIRS for a file named $xdg_subdir/$config_file.

Parameters:
  • xdg_subdir – A string. The directory to append to each of the $XDG_CONFIG_DIRS. Defaults to 'pulp_smash'.
  • config_file – A string. The name of the settings file. Typically defaults to 'settings.json'.
Returns:

A string. The path to a configuration file, if one is found.

Raises:

pulp_smash.exceptions.ConfigFileNotFoundError – If no configuration file is found.

get_requests_kwargs(pulp_host=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.load()
>>> requests.get(cfg.get_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.load()
>>> requests.get(
...     cfg.get_base_url() + '…',
...     auth=tuple(cfg.pulp_auth),
...     verify=cfg.get_hosts('api')[0].roles['api']['verify'],
... )

But this latter approach is more fragile. The user must remember to get a host 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.

classmethod get_save_path()

Return a path to where a configuration file may be saved.

Create parent directories if they don’t exist.

static get_services(roles)

Translate role names to init system service names.

classmethod load(xdg_subdir=None, config_file=None)

Load a configuration file from disk.

Parameters:
Returns:

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

Return type:

PulpSmashConfig

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

The set of roles that must be present in a functional Pulp application.

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

The set of all roles that may be present in a Pulp application.

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 an in-memory configuration file.

Given an in-memory configuration file, verify its sanity by validating it against a schema and performing several semantic checks.

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