pulp_smash.config¶
Location: Pulp Smash → API Documentation → pulp_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.
JSON_CONFIG_SCHEMA
= {'anyOf': [{'additionalProperties': False, 'required': ['pulp', 'hosts'], 'type': 'object', 'properties': {'hosts': {'type': 'array', 'minItems': 1, 'items': {'$ref': '#/definitions/pulp 2 host'}}, 'pulp': {'$ref': '#/definitions/pulp'}, 'general': {'$ref': '#/definitions/general'}, 'custom': {'$ref': '#/definitions/custom'}}}, {'additionalProperties': False, 'required': ['pulp', 'hosts'], 'type': 'object', 'properties': {'hosts': {'type': 'array', 'minItems': 1, 'items': {'$ref': '#/definitions/pulp 3 host'}}, 'pulp': {'$ref': '#/definitions/pulp'}, 'general': {'$ref': '#/definitions/general'}, 'custom': {'$ref': '#/definitions/custom'}}}], 'definitions': {'amqp broker role': {'properties': {'service': {'enum': ['qpidd', 'rabbitmq'], 'type': 'string'}}, 'required': ['service'], 'type': 'object'}, 'custom': {'type': 'object'}, 'general': {'additionalProperties': False, 'properties': {'timeout': {'maximum': 1800, 'mininum': 1, 'type': 'number'}}, 'required': ['timeout'], 'type': 'object'}, 'mongod role': {'type': 'object'}, 'pulp': {'additionalProperties': False, 'properties': {'auth': {'maxItems': 2, 'minItems': 2, 'type': 'array'}, 'selinux enabled': {'type': 'boolean'}, 'version': {'type': 'string'}}, 'required': ['auth', 'version'], 'type': 'object'}, 'pulp 2 api role': {'properties': {'port': {'maximum': 65535, 'minimum': 0, 'type': 'integer'}, 'scheme': {'enum': ['http', 'https'], 'type': 'string'}, 'service': {'type': 'string'}, 'verify': {'type': ['boolean', 'string']}}, 'required': ['scheme'], 'type': 'object'}, 'pulp 2 host': {'additionalProperties': False, 'properties': {'hostname': {'format': 'hostname', 'type': 'string'}, 'roles': {'additionalProperties': False, 'properties': {'amqp broker': {'$ref': '#/definitions/amqp broker role'}, 'api': {'$ref': '#/definitions/pulp 2 api role'}, 'mongod': {'$ref': '#/definitions/mongod role'}, 'pulp celerybeat': {'$ref': '#/definitions/pulp celerybeat role'}, 'pulp cli': {'$ref': '#/definitions/pulp cli role'}, 'pulp resource manager': {'$ref': '#/definitions/pulp resource manager role'}, 'pulp workers': {'$ref': '#/definitions/pulp workers role'}, 'shell': {'$ref': '#/definitions/shell role'}, 'squid': {'$ref': '#/definitions/squid role'}}, 'required': ['shell'], 'type': 'object'}}, 'required': ['hostname', 'roles'], 'type': 'object'}, 'pulp 3 api role': {'properties': {'port': {'maximum': 65535, 'minimum': 0, 'type': 'integer'}, 'scheme': {'enum': ['http', 'https'], 'type': 'string'}, 'service': {'type': 'string'}, 'verify': {'type': ['boolean', 'string']}}, 'required': ['scheme', 'service'], 'type': 'object'}, 'pulp 3 content role': {'properties': {'port': {'maximum': 65535, 'minimum': 0, 'type': 'integer'}, 'scheme': {'enum': ['http', 'https'], 'type': 'string'}, 'service': {'type': 'string'}, 'verify': {'type': ['boolean', 'string']}}, 'required': ['scheme'], 'type': 'object'}, 'pulp 3 host': {'additionalProperties': False, 'properties': {'hostname': {'format': 'hostname', 'type': 'string'}, 'roles': {'additionalProperties': False, 'properties': {'api': {'$ref': '#/definitions/pulp 3 api role'}, 'content': {'$ref': '#/definitions/pulp 3 content role'}, 'pulp resource manager': {'$ref': '#/definitions/pulp resource manager role'}, 'pulp workers': {'$ref': '#/definitions/pulp workers role'}, 'redis': {'$ref': '#/definitions/redis role'}, 'shell': {'$ref': '#/definitions/shell role'}}, 'required': ['shell'], 'type': 'object'}}, 'required': ['hostname', 'roles'], 'type': 'object'}, 'pulp celerybeat role': {'type': 'object'}, 'pulp cli role': {'type': 'object'}, 'pulp resource manager role': {'type': 'object'}, 'pulp workers role': {'type': 'object'}, 'redis role': {'type': 'object'}, 'shell role': {'properties': {'transport': {'enum': ['local', 'ssh'], 'type': 'string'}}, 'type': 'object'}, 'squid role': {'type': 'object'}}, 'title': 'Pulp Smash configuration file'}¶ The schema for Pulp Smash’s configuration file.
-
pulp_smash.config.
P2_AMQP_SERVICES
= {'qpidd', 'rabbitmq'}¶ The set of services that can fulfill the
amqp broker
role.
-
pulp_smash.config.
P2_OPTIONAL_ROLES
= {'custom', 'pulp cli', 'squid'}¶ Additional roles that can be present in a Pulp 2 application.
-
pulp_smash.config.
P2_REQUIRED_ROLES
= {'amqp broker', 'api', 'mongod', 'pulp celerybeat', 'pulp resource manager', 'pulp workers', 'shell'}¶ The set of roles that must be present in a functional Pulp 2 application.
-
pulp_smash.config.
P2_ROLES
= {'amqp broker', 'api', 'custom', 'mongod', 'pulp celerybeat', 'pulp cli', 'pulp resource manager', 'pulp workers', 'shell', 'squid'}¶ The set of all roles that can be present in a Pulp 2 application.
-
pulp_smash.config.
P3_OPTIONAL_ROLES
= {'content', 'custom'}¶ Additional roles that can be present in a Pulp 3 application.
-
pulp_smash.config.
P3_REQUIRED_ROLES
= {'api', 'pulp resource manager', 'pulp workers', 'redis', 'shell'}¶ The set of roles that must be present in a functional Pulp 3 application.
-
pulp_smash.config.
P3_ROLES
= {'api', 'content', 'custom', 'pulp resource manager', 'pulp workers', 'redis', 'shell'}¶ The set of all roles that can be present in a Pulp 3 application.
-
class
pulp_smash.config.
PulpHost
(hostname, roles)¶ Bases:
tuple
-
hostname
¶ Alias for field number 0
-
roles
¶ Alias for field number 1
-
-
class
pulp_smash.config.
PulpSmashConfig
(pulp_auth, pulp_version, pulp_selinux_enabled, timeout, *, hosts, custom=None)¶ Bases:
object
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 thePULP_SMASH_CONFIG_FILE
environment variable. This variable is a relative path, and it defaults tosettings.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.JSON_CONFIG_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, role='api')¶ 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 given role.
- role – The host role. Defaults to
api
.
-
get_bindings_config
()¶ Return bindings settings.
-
get_content_host
()¶ Return content host if defined else returns api host.
-
get_content_host_base_url
()¶ Return content host url if defined else returns api base url.
-
get_fixtures_url
()¶ Return fixtures URL.
-
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.P2_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.
- xdg_subdir – A string. The directory to append to each of the
-
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 ifcfg
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.
Sample usage:
>>> from pulp_smash import config >>> host = config.PulpHost('example.com', { ... 'amqp broker': {'service': 'qpidd'}, ... 'pulp celerybeat': {}, ... }) >>> services = config.PulpSmashConfig.get_services(host.roles) >>> services == {'pulp_celerybeat', 'qpidd'} True
Parameters: roles – The roles
attribute of apulp_smash.config.PulpHost
.Returns: A set. The services that back the named roles.
-
classmethod
load
(xdg_subdir=None, config_file=None)¶ Load a configuration file from disk.
Parameters: - xdg_subdir – Passed to
get_load_path()
. - config_file – Passed to
get_load_path()
.
Returns: A new
pulp_smash.config.PulpSmashConfig
object. The current object is not modified by this method.Return type: - xdg_subdir – Passed to
- pulp_auth – A two-tuple. Credentials to use when communicating with
the server. For example:
-
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 a config against
pulp_smash.config.JSON_CONFIG_SCHEMA
.Parameters: config_dict – A dict, such as one returned by calling json.load
on a configuration file, or one generated by the user-facing CLI.Returns: Nothing. Raises: pulp_smash.exceptions.ConfigValidationError – If the any validation error is found.