satellite_populate package

Submodules

satellite_populate.api module

Implements API populator using Nailgun

class satellite_populate.api.APIPopulator(data, verbose=None, mode=None, config=None)[source]

Bases: satellite_populate.base.BasePopulator

Populates system using API/Nailgun

action_create(rendered_action_data, action_data, search, model, silent_errors)[source]

Creates new entity if does not exists or get existing entity and return Entity object

action_delete(rendered_action_data, action_data, search, model, silent_errors)[source]

Deletes an existing entity

action_update(rendered_action_data, action_data, search, model, silent_errors)[source]

Updates an existing entity

add_and_log_error(action_data, rendered_action_data, search, e=None)[source]

Add to validation errors and outputs error

populate(rendered_action_data, action_data, search, action)[source]

Populates the System using Nailgun based on value provided in action argument gets the proper CRUD method to execute dynamically

validate(rendered_action_data, action_data, search, action)[source]

Based on action fields or using action_data[‘search_query’] searches the system and validates the existence of all entities

satellite_populate.assertion_operators module

Implement basic assertions to be used in assertion action

satellite_populate.assertion_operators.eq(value, other)[source]

Equal

satellite_populate.assertion_operators.gt(value, other)[source]

Greater than

satellite_populate.assertion_operators.gte(value, other)[source]

Greater than or equal

satellite_populate.assertion_operators.identity(value, other)[source]

Identity check using ID

satellite_populate.assertion_operators.lt(value, other)[source]

Lower than

satellite_populate.assertion_operators.lte(value, other)[source]

Lower than or equal

satellite_populate.assertion_operators.ne(value, other)[source]

Not equal

satellite_populate.base module

Base module for satellite_populate reads the YAML definition and perform all the rendering and basic actions.

class satellite_populate.base.BasePopulator(data, verbose=None, mode=None, config=None)[source]

Bases: object

Base class for API and CLI populators

action_assertion(rendered_action_data, action_data)[source]

Run assert operations

action_echo(rendered_action_data, action_data)[source]

After message is echoed to log, check if needs print

action_register(rendered_action_data, action_data)[source]

Register arbitrary items to the registry

action_unregister(rendered_action_data, action_data)[source]

Remove data from registry

add_modules_to_context()[source]

Add modules dynamically to render context

add_rendered_action(action_data, rendered_action_data)[source]

Add rendered action to be written in validation file

add_to_registry(action_data, result, append=True)[source]

Add objects to the internal registry

build_raw_query(data, action_data)[source]

Builds nailgun raw_query for search

Build search data and returns a dict containing elements

  • data Dictionary of parsed rendered_action_data to be used to i nstantiate an object to searched without raw_query.
  • options if search_options are specified it is passed to .search(**options)
  • searchable Returns boolean True if model inherits from EntitySearchMixin, else alternative search must be implemented.

if search_query is available in action_data it will be used instead of rendered_action_data.

build_search_options(data, action_data)[source]

Builds nailgun options for search raw_query: Some API endpoints demands a raw_query, so build it as in example: {‘query’: {‘search’:’name=name,label=label,id=28’}}

force_raw: Returns a boolean if action_data.force_raw is explicitly specified

config

Return config dynamically because it can be overwritten by user in datafile or by custom populator

crud_actions

Return a list of crud_actions, actions that gets data and perform nailgun crud operations so custom populators can overwrite this list to add new crud actions.

execute(mode=None)[source]

Iterates the entities property described in YAML file and parses its values, variables and substitutions depending on mode execute populate or validate

from_factory(action_data, context)[source]

Generates random content using fauxfactory

from_read(action_data, context)[source]

Gets fields and perform a read to return Entity object used when ‘from_read’ directive is used in YAML file

Gets fields and perform a search to return Entity object used when ‘from_search’ directive is used in YAML file

get_search_result(model, search, unique=False, silent_errors=False)[source]

Perform a search

load_raw_search_rules()[source]

Reads default search rules then update first with custom populator defined rules and then user defined in datafile.

populate(rendered_action_data, raw_entity, search_query, action)[source]

Should be implemented in sub classes

populate_modelname(rendered_action_data, action_data, search_query, action)[source]

Example on how to implement custom populate methods e.g: def populate_organization This method should take care of all validations and errors.

raw_search_rules

Subclasses of custom populators can extend this rules

render(action_data, action)[source]

Takes an entity description and strips ‘data’ out to perform single rendering and also handle repetitions defined in with_items

render_action_data(data, context)[source]

Gets a single action_data and perform inplace template rendering or reference evaluation depending on directive being used.

render_assertion_data(action_data, rendered_action_data)[source]

Render items on assertion data

resolve_result(data, from_where, k, v, result)[source]

Used in from_search and from_object to get specific attribute from object e.g: name. Or to invoke a method when attr is a dictionary of parameters.

set_gpgkey()[source]

Set gpgkey

validate(rendered_action_data, raw_entity, search_query, action)[source]

Should be implemented in sub classes

validate_modelname(rendered_action_data, action_data, search_query, action)[source]

Example on how to implement custom validate methods e.g:: def validate_organization This method should take care of all validations and errors.

satellite_populate.cli module

To be implemented: a populator using CLI

satellite_populate.commands module

This module contains commands to interact with satellite populator and validator.

Commands included:

satellite-populate

A command to populate the system based in an YAML file describing the entities:

$ satellite-populate file.yaml -h myhost.com -o /tmp/validation.yaml

validate

A command to validate the system based in an validation file generated by the populate or a YAML file with mode: validation:

$ satellite-populate /tmp/validation.yaml

Use $ satellite-populate --help for more info

satellite_populate.commands.configure()[source]

Read satellite-populate settings file.

satellite_populate.commands.execute_populate(datafile, verbose, output, mode, scheme, port, hostname, username, password, report=True, enable_output=True)[source]

Populate using the data described in datafile:

satellite_populate.constants module

Default base config values

satellite_populate.decorators module

decorators for populate feature

satellite_populate.decorators.populate_with(data, context_name=None, context_wrapper=<function default_context_wrapper>, **extra_options)[source]

To be used in test cases as a decorator

Having a data_file like:

actions:
  - model: Organization
    register: organization_1
    data:
      name: My Org

Then you can use in decorators:

@populate_with('file.yaml')
def test_case_(self):
    'My Org exists in system test anything here'

And getting the populated entities inside the test_case:

@populate_with('file.yaml', context_name='my_context')
def test_case_(self, my_context=None):
    assert my_context.organization_1.name == 'My Org'

You can also set a customized context wrapper to the context_wrapper argument:

def my_custom_context_wrapper(result):
    # create an object using result
    my_context = MyResultContext(result)
    return my_context

@populate_with('file.yaml', context_name='my_context',
               content_wrapper=my_custom_context_wrapper)
def test_case_(self, my_context=None):
    # assert with some expression using my_context object returned
    # my_custom_context_wrapper
    assert some_expression

NOTE:

That is important that ``context_name`` argument always be declared
using either a default value ``my_context=None`` or handle in
``**kwargs`` Otherwise ``py.test`` may try to use this as a fixture
 placeholder.

if context_wrapper is set to None, my_context will be the pure
unmodified result of populate function.

satellite_populate.main module

Point of entry for populate and validate used in scripts

satellite_populate.main.default_context_wrapper(result)[source]

Takes the result of populator and keeps only useful data e.g. in decorators context.registered_name, context.config.verbose and context.vars.admin_username will all be available.

satellite_populate.main.get_populator(data, **kwargs)[source]

Gets an instance of populator dynamically

satellite_populate.main.load_data(datafile)[source]

Loads YAML file as a dictionary

satellite_populate.main.populate(data, **kwargs)[source]

Loads and execute populator in populate mode

satellite_populate.main.save_rendered_data(result, filepath)[source]

Save the result of rendering in a new file to be used for validation

satellite_populate.main.setup_yaml()[source]

Set YAML to use OrderedDict http://stackoverflow.com/a/8661021

satellite_populate.utils module

class satellite_populate.utils.SmartDict(*args, **kwargs)[source]

Bases: dict

A Dict which is accessible via attribute dot notation

copy()[source]
satellite_populate.utils.format_result(result)[source]

format result to show in logs

satellite_populate.utils.import_from_string(import_name, *args, **kwars)[source]

Try import string and then try builtins

satellite_populate.utils.remove_keys(data, *args, **kwargs)[source]

remove keys from dictionary d = {‘item’: 1, ‘other’: 2, ‘keep’: 3} remove_keys(d, ‘item’, ‘other’) d -> {‘keep’: 3} deep = True returns a deep copy of data.

satellite_populate.utils.remove_nones(data)[source]

remove nones from data

satellite_populate.utils.set_logger(verbose)[source]

Set logger verbosity used when client is called with -vvvvv

Module contents

This package contains tools to populate and validate the system