toxiccommon package

Submodules

toxiccommon.client module

class toxiccommon.client.HoleClient(requester, *args, hole_token=None, **kwargs)[source]

Bases: BaseToxicClient, LoggerMixin

Client for the master’s hole.

async connect2stream(body)[source]

Connects the client to the master’s hole stream.

async get_response()[source]

Reads data from the server and raises and exception in case of error

async request2server(action, body)[source]

Performs a request to a hole server.

Parameters:
  • action – The action to perform on the server.

  • body – The body of the request, with the actions parameters.

settings = None
async toxiccommon.client.get_hole_client(requester, host, port, hole_token=None, **kwargs)[source]

toxiccommon.coordination module

class toxiccommon.coordination.Lock(path)[source]

Bases: LoggerMixin

async acquire_read(timeout=None)[source]
async acquire_write(timeout=None)[source]
class toxiccommon.coordination.LockContext(lock, timeout=None)[source]

Bases: object

async acquire()[source]
class toxiccommon.coordination.ToxicZKClient[source]

Bases: LoggerMixin

async get_lock(path)[source]
settings = None

toxiccommon.exceptions module

exception toxiccommon.exceptions.AlreadyExists[source]

Bases: Exception

exception toxiccommon.exceptions.BadResetPasswordToken[source]

Bases: Exception

exception toxiccommon.exceptions.BadSettingsType[source]

Bases: Exception

exception toxiccommon.exceptions.NotEnoughPerms[source]

Bases: Exception

exception toxiccommon.exceptions.RepositoryDoesNotExist[source]

Bases: Exception

exception toxiccommon.exceptions.UserDoesNotExist[source]

Bases: Exception

toxiccommon.exchange module

class toxiccommon.exchange.AmqpConnection(**conn_kwargs)[source]

Bases: LoggerMixin

A connection for a broker. We can have many channels over one connection.

async connect(**conn_kwargs)[source]

Connects to the Rabbitmq server.

Parameters:

conn_kwargs – Named arguments passed to asyncamqp.connect()

async disconnect()[source]

Disconnects from the Rabbitmq server.

property reconn_lock
async reconnect()[source]
class toxiccommon.exchange.Consumer(channel, queue, consumer_tag, nowait=False, timeout=0)[source]

Bases: Consumer, LoggerMixin

async fetch_message(cancel_on_timeout=True)[source]
class toxiccommon.exchange.Exchange(name, connection, exchange_type, durable=False, bind_publisher=True, exclusive_consumer_queue=False)[source]

Bases: LoggerMixin

A simple abstraction for an amqp exchange.

async bind(routing_key, queue_name=None, channel=None)[source]

Binds the queue to the exchange.

Parameters:
  • routing_key – Routing key to bind the queue.

  • queue_name – The name of the queue to be bound. If not self.queue_name will be used.

  • channel – Optional channel to use in the communication. A new one will be used.

async consume(wait_message=True, timeout=0, routing_key='', no_ack=False)[source]

Consumes a message from a Rabbitmq queue.

Parameters:
  • wait_message – Should we wait for new messages in the queue?

  • timeout – Timeout for waiting messages.

  • no_ack – Indicates if we should send a ack response to the server. The ack must be sent by the consumer.

async declare(queue_name=None)[source]

Declares the exchange and queue.

Parameters:

queue_name – The name for the queue to be declared. If None, self.queue_name will be used.

async get_queue_size(queue_name=None)[source]
is_declared(queue_name=None)[source]
async publish(message, routing_key='')[source]

Publishes a message to a Rabbitmq exchange

Parameters:
  • message – The message that will be published in the exchange. Must be something that can be serialized into a json.

  • routing_key – The routing key to publish the message.

async queue_delete(queue_name=None)[source]

Deletes a queue. If not queue_name, self.queue_name will be used.

Parameters:

queue_name – The name of the queue to be deleted.

async unbind(routing_key, channel=None)[source]
class toxiccommon.exchange.JsonAckMessage(*args, **kwargs)[source]

Bases: Message

async acknowledge()[source]
async reject(requeue=True)[source]

toxiccommon.exchanges module

async toxiccommon.exchanges.declare()[source]

toxiccommon.interfaces module

Module with base models that are populated using a remote api.

class toxiccommon.interfaces.BaseHoleInterface(requester, ordered_kwargs)[source]

Bases: BaseInterface

async classmethod get_client(requester)[source]

Returns a client connected to master.

class toxiccommon.interfaces.BaseInterface(requester, ordered_kwargs)[source]

Bases: object

references = {}
settings = None
to_dict(dtformat=None, tzname=None)[source]

Transforms a model into a dict.

Parameters:
  • dtformat – Format for datetimes.

  • tzname – A timezone name.

to_json(*args, **kwargs)[source]

Transforms a model into a json.

Parameters:
  • args – Positional arguments passed to to_dict().

  • kwargs – Named arguments passed to to_dict().

class toxiccommon.interfaces.BuildInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod get(requester, uuid)[source]

Returns information about abuild. :param uuid: The uuid of the build.

references = {'builder': <class 'toxiccommon.interfaces.BuilderInterface'>, 'steps': <class 'toxiccommon.interfaces.StepInterface'>}
to_dict(*args, **kwargs)[source]

Converts a build object in to a dictionary.

Parameters:
  • args – Positional arguments passed to to_dict().

  • kwargs – Named arguments passed to to_dict().

class toxiccommon.interfaces.BuildSetInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod get(requester, buildset_id)[source]

Returns an instance of BuildSetInterface.

Parameters:

buildset_id – The id of the buildset to get.

async classmethod list(requester, repo_name_or_id=None, summary=True, branch=None)[source]

Lists buildsets. If repo_name_or_id only builds of this repsitory will be listed.

Parameters:
  • repo_name – Name of a repository.

  • summary – If True, no builds information will be returned.

  • branch – List buildsets for this branch. If None list buildsets from all branches.

references = {'builds': <class 'toxiccommon.interfaces.BuildInterface'>, 'repository': <class 'toxiccommon.interfaces.RepositoryInterface'>}
to_dict(*args, **kwargs)[source]

Returns a dictionary based in a BuildSet object.

Parameters:
  • args – Positional arguments passed to to_dict().

  • kwargs – Named arguments passed to to_dict().

class toxiccommon.interfaces.BuilderInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod list(requester, **kwargs)[source]

Lists builders already used.

class toxiccommon.interfaces.NotificationInterface(ordered_kwargs)[source]

Bases: BaseInterface

Integration with the notifications api.

classmethod api_token()[source]
classmethod api_url()[source]
async classmethod disable(repo_id, notif_name)[source]

Disables a notification for a given repository.

Parameters:
  • repo_id – The id of the repository to enable the notification.

  • notif_name – The name of the notification.

async classmethod enable(repo_id, notif_name, **config)[source]

Enables a notification for a given repository.

Parameters:
  • repo_id – The id of the repository to enable the notification.

  • notif_name – The name of the notification.

  • config – A dictionary with the config values for the notification.

async classmethod list(obj_id=None)[source]

Lists all the notifications available.

Parameters:

obj_id – The of of an repository. If not None, the notifications will return the values of the configuration for that repository.

async classmethod update(repo_id, notif_name, **config)[source]

Updates a notification for a given repository.

Parameters:
  • repo_id – The id of the repository to enable the notification.

  • notif_name – The name of the notification.

  • config – A dictionary with the new config values for the notification.

class toxiccommon.interfaces.RepositoryInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

Interface for a repository.

async classmethod add(requester, name, url, owner, vcs_type, update_seconds=300, slaves=None, parallel_builds=None, schedule_poller=True, branches=None, external_id=None, external_full_name=None, fetch_url=None, envvars=None)[source]

Adds a new repository.

Parameters:
  • requester – The user who is requesting the operation.

  • name – Repository’s name.

  • url – Repository’s url.

  • owner – The repository owner

  • vcs_type – VCS type used on the repository.

  • update_seconds – Interval to update the repository code.

  • slaves – List with slave names for this reporitory.

  • schedule_poller – Should this repository be scheduled for polling? If this repository comes from an integration (with github, gitlab, etc…) this should be False.

  • branches – A list of branches configuration that trigger builds.

  • external_id – The id of the repository in an external service.

  • external_full_name – The full name in an external service.

  • fetch_url – If the repository uses a differente url to fetch code (ie: it has an auth token url) this is the fetch_url.

  • envvars – Environment variables that will be used in every build in this repository.

Params parallel_builds:

How many paralles builds this repository executes. If None, there is no limit.

async add_branch(branch_name, notify_only_latest)[source]

Adds a branch config to a repositoiry.

Parameters:
  • branch_name – The name of the branch.

  • notify_only_latest – If we should create builds for all revisions or only for the lastest one.

async add_envvars(**envvars)[source]

Adds environment variables to use in the builds of this repository.

Parameters:

envvars – Environment variables in the format {var: val, …}

async add_or_update_secret(key, value)[source]

Adds a new secret to be used in builds. Note that secrets are not used in builds from external sources.

async add_slave(slave)[source]

Adds a slave to the repository.

Parameters:

slave – A Slave instance.

async cancel_build(build_uuid)[source]

Cancels a build from the repository.

Parameters:

build_uuid – The uuid of the build.

async delete()[source]

Delete a repository.

async disable()[source]

Disables this repository.

async enable()[source]

Enables this repository.

async classmethod get(requester, **kwargs)[source]

Returns a repository.

Parameters:
  • requester – The user who is requesting the operation.

  • kwargs – kwargs to get the repository.

async get_secrets()[source]

Returns the secrets owned from the repository

async classmethod list(requester, **kwargs)[source]

Lists all repositories.

Parameters:

requester – The user who is requesting the operation.

async list_branches()[source]

Lists the branches known by this repositor.

references = {'last_buildset': 'toxiccommon.interfaces.BuildSetInterface', 'slaves': <class 'toxiccommon.interfaces.SlaveInterface'>}
async remove_branch(branch_name)[source]

Removes a branch config from a repository.

Parameters:

branch_name – The name of the branch.

async remove_slave(slave)[source]

Removes a slave from the repository.

Parameters:

slave – A Slave instance.

async replace_envvars(**envvars)[source]

Replaces environment variables of this repository.

Parameters:

envvars – Environment variables in the format {var: val, …}

async replace_secrets(**secrets)[source]

Replace the secrets of a repository

async request_code_update(repo_branches=None, external=None)[source]

Request the code update of the repository.

Parameters:
  • repo_branches

    A dictionary with information about the branches to be updated. If no repo_branches all branches in the repo config will be updated.

    The dictionary has the following format.

    {'branch-name': {'notify_only_latest': True}}
    

  • external – If we should update code from an external (not the origin) repository, external is the information about this remote repo.

async rm_envvars(**envvars)[source]

Removes environment variables from this repository.

Parameters:

envvars – Environment variables in the format {var: val, …}

async rm_secret(key)[source]

Removes a secret from the repository

async start_build(branch, builder_name_or_id=None, named_tree=None)[source]

Starts a (some) build(s) for a repository.

Parameters:
  • branch – The name of the branch.

  • builder_name_or_id – The name of the builder that will execute the build

  • named_tree – The named_tree that will be builded. If no named_tree the last one will be used.

to_dict(*args, **kwargs)[source]

Transforms a repository into a dictionary.

Parameters:
  • args – Positional arguments passed to to_dict().

  • kwargs – Named arguments passed to to_dict().

async update(**kwargs)[source]

Updates a repository

class toxiccommon.interfaces.SlaveInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod add(requester, name, port, token, owner, use_ssl=True, validate_cert=True, on_demand=False, host=None, instance_type=None, instance_confs=None)[source]

Adds a new slave.

Parameters:
  • name – Slave name.

  • host – Slave host.

  • port – Slave port.

  • token – Authentication token.

  • owner – The slave owner

  • use_ssl – Indicates if the slave uses a ssl connection.

  • on_demand – Does this slave have an on-demand instance?

  • instance_type – Type of the on-demand instance.

  • instance_confs – Configuration parameters for the on-demand instance.

Pram validate_cert:

Should the slave certificate be validated?

async delete()[source]

Delete a slave.

async classmethod get(requester, **kwargs)[source]

Returns a slave.

Parameters:
  • requester – The user who is requesting the operation.

  • kwargs – kwargs to get the slave.

async classmethod list(requester)[source]

Lists all slaves.

Parameters:

requester – The user who is requesting the operation.

async update(**kwargs)[source]

Updates a slave

class toxiccommon.interfaces.StepInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod get(requester, uuid)[source]

Returns information about a step. :param uuid: The uuid of the step.

class toxiccommon.interfaces.UserInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

A user created in the master

async classmethod add(email, username, password, allowed_actions)[source]
async classmethod authenticate(username_or_email, password)[source]
async classmethod change_password(requester, old_password, new_password)[source]
async classmethod change_password_with_token(token, password)[source]

Changes the user password using a token. The token was generated when request_password_reset was called and a link with the token was sent to the user email.

async delete()[source]
async classmethod exists(**kwargs)[source]

Checks if a user with some given information exists.

Parameters:

kwargs – Named arguments to match the user

async classmethod get(**kwargs)[source]

Returns a user.

Parameters:
  • requester – The user who is requesting the operation.

  • kwargs – kwargs to get the user.

async classmethod request_password_reset(email, reset_link)[source]

Request the reset of the user’s password. Sends an email with a link to reset the password.

class toxiccommon.interfaces.WaterfallInterface(requester, ordered_kwargs)[source]

Bases: BaseHoleInterface

async classmethod get(requester, repo_name_or_id, branch=None)[source]

Returns an instance of WaterfallInterface.

Parameters:
  • buildset_id – The name or id of a repository

  • branch – A branch name to filter the waterfall

references = {'builders': <class 'toxiccommon.interfaces.BuilderInterface'>, 'buildsets': <class 'toxiccommon.interfaces.BuildSetInterface'>}
to_dict(*args, **kwargs)[source]

Returns a dictionary based in a WaterfallInterface object.

Parameters:
  • args – Positional arguments passed to to_dict().

  • kwargs – Named arguments passed to to_dict().

toxiccommon.utils module

toxiccommon.utils.format_datetime(dt, dtformat, tzname=None)[source]

Formats a datetime object according to the timezone and format specified in the config file.

Parameters:
  • dt – A datetime object.

  • dtformat – The format for the datetime.

  • tzname – A timezone name.

toxiccommon.utils.get_hole_client_settings(settings)[source]

Returns the settings that must be used by the hole client

toxiccommon.utils.is_datetime(dtstr)[source]

Checks if a string is a formated datetime. The format expected for the datetime string is: ‘%a %b %d %H:%M:%S %Y %z’

Module contents

async toxiccommon.common_setup(settings)[source]