robottelo.api.utils

Module containing convenience functions for working with the API.

Module Contents

Classes

templateupdate

Context Manager to unlock lock template for updating

Functions

call_entity_method_with_timeout(entity_callable, timeout=300, **kwargs)

Call Entity callable with a custom timeout

enable_rhrepo_and_fetchid(basearch, org_id, product, repo, reposet, releasever)

Enable a RedHat Repository and fetches it’s Id.

promote(content_view_version, environment_id, force=False)

Call content_view_version.promote(…).

upload_manifest(organization_id, manifest)

Call nailgun.entities.Subscription.upload.

publish_puppet_module(puppet_modules, repo_url, organization_id=None)

Creates puppet repo, sync it via provided url and publish using

delete_puppet_class(puppetclass_name, puppet_module=None, proxy_hostname=None, environment_name=None)

Removes puppet class entity and uninstall puppet module from Capsule if

create_sync_custom_repo(org_id=None, product_name=None, repo_name=None, repo_url=None, repo_type=None, repo_unprotected=True, docker_upstream_name=None)

Create product/repo, sync it and returns repo_id

enable_sync_redhat_repo(rh_repo, org_id, timeout=1500)

Enable the RedHat repo, sync it and returns repo_id

cv_publish_promote(name=None, env_name=None, repo_id=None, org_id=None)

Create, publish and promote CV to selected environment

one_to_one_names(name)

Generate the names Satellite might use for a one to one field.

one_to_many_names(name)

Generate the names Satellite might use for a one to many field.

configure_provisioning(org=None, loc=None, compute=False, os=None)

Create and configure org, loc, product, repo, cv, env. Update proxy,

create_role_permissions(role, permissions_types_names, search=None)

Create role permissions found in dict permissions_types_names.

wait_for_tasks(search_query, search_rate=1, max_tries=10, poll_rate=None, poll_timeout=None)

Search for tasks by specified search query and poll them to ensure that

wait_for_syncplan_tasks(repo_backend_id=None, timeout=10, repo_name=None)

Search the pulp tasks and identify repositories sync tasks with

wait_for_errata_applicability_task(host_id, from_when, search_rate=1, max_tries=10, poll_rate=None, poll_timeout=15)

Search the generate applicability task for given host and make sure it finishes

create_discovered_host(name=None, ip_address=None, mac_address=None, options=None)

Creates a discovered host.

update_vm_host_location(vm_client, location_id)

Update vm client host location.

check_create_os_with_title(os_title)

Check if the OS is present, if not create the required OS

attach_custom_product_subscription(prod_name=None, host_name=None)

Attach custom product subscription to client host

update_provisioning_template(name=None, old=None, new=None)

Update provisioning template content

apply_package_filter(content_view, repo, package, inclusion=True)

Apply package filter on content view

create_org_admin_role(orgs, locs, name=None)

Helper function to create org admin role for particular

create_org_admin_user(orgs, locs)

Helper function to create an Org Admin user by assigning org admin role and assign

skip_yum_update_during_provisioning(template=None, reverse=False)

Hides the yum update command with echo text

set_hammer_api_timeout(timeout=-1, reverse=False)

Set hammer API request timeout on Satellite

update_rhsso_settings_in_satellite(revert=False)

Update or Revert the RH-SSO settings in satellite

robottelo.api.utils.call_entity_method_with_timeout(entity_callable, timeout=300, **kwargs)

Call Entity callable with a custom timeout

:param entity_callable, the entity method object to call :param timeout: the time to wait for the method call to finish :param kwargs: the kwargs to pass to the entity callable

Usage:
call_entity_method_with_timeout(

entities.Repository(id=repo_id).sync, timeout=1500)

robottelo.api.utils.enable_rhrepo_and_fetchid(basearch, org_id, product, repo, reposet, releasever)

Enable a RedHat Repository and fetches it’s Id.

Parameters
  • org_id (str) – The organization Id.

  • product (str) – The product name in which repository exists.

  • reposet (str) – The reposet name in which repository exists.

  • repo (str) – The repository name who’s Id is to be fetched.

  • basearch (str) – The architecture of the repository.

  • optional releasever (str) – The releasever of the repository.

Returns

Returns the repository Id.

Return type

str

robottelo.api.utils.promote(content_view_version, environment_id, force=False)

Call content_view_version.promote(…).

Parameters
  • content_view_version – A nailgun.entities.ContentViewVersion object.

  • environment_id – An environment ID.

  • force – Whether to force the promotion or not. Only needed if promoting to a lifecycle environment that is not the next in order of sequence.

Returns

Whatever nailgun.entities.ContentViewVersion.promote returns.

robottelo.api.utils.upload_manifest(organization_id, manifest)

Call nailgun.entities.Subscription.upload.

Parameters
  • organization_id – An organization ID.

  • manifest – A file object referencing a Red Hat Satellite 6 manifest.

Returns

Whatever nailgun.entities.Subscription.upload returns.

robottelo.api.utils.publish_puppet_module(puppet_modules, repo_url, organization_id=None)

Creates puppet repo, sync it via provided url and publish using Content View publishing mechanism. It makes puppet class available via Puppet Environment created by Content View and returns Content View entity.

Parameters
  • puppet_modules – List of dictionaries with module ‘author’ and module ‘name’ fields.

  • repo_url (str) – Url of the repo that can be synced using pulp: pulp repo or puppet forge.

  • organization_id – Organization id that is shared between created entities.

Returns

nailgun.entities.ContentView entity.

robottelo.api.utils.delete_puppet_class(puppetclass_name, puppet_module=None, proxy_hostname=None, environment_name=None)

Removes puppet class entity and uninstall puppet module from Capsule if puppet module name and Capsule details provided.

Parameters
  • puppetclass_name (str) – Name of the puppet class entity that should be removed.

  • puppet_module (str) – Name of the module that should be uninstalled via puppet.

  • proxy_hostname (str) – Hostname of the Capsule from which puppet module should be removed.

  • environment_name (str) – Name of environment where puppet module was imported.

robottelo.api.utils.create_sync_custom_repo(org_id=None, product_name=None, repo_name=None, repo_url=None, repo_type=None, repo_unprotected=True, docker_upstream_name=None)

Create product/repo, sync it and returns repo_id

robottelo.api.utils.enable_sync_redhat_repo(rh_repo, org_id, timeout=1500)

Enable the RedHat repo, sync it and returns repo_id

robottelo.api.utils.cv_publish_promote(name=None, env_name=None, repo_id=None, org_id=None)

Create, publish and promote CV to selected environment

robottelo.api.utils.one_to_one_names(name)

Generate the names Satellite might use for a one to one field.

Example of usage:

>>> one_to_many_names('person') == {'person_name', 'person_id'}
True
Parameters

name – A field name.

Returns

A set including both name and variations on name.

robottelo.api.utils.one_to_many_names(name)

Generate the names Satellite might use for a one to many field.

Example of usage:

>>> one_to_many_names('person') == {'person', 'person_ids', 'people'}
True
Parameters

name – A field name.

Returns

A set including both name and variations on name.

robottelo.api.utils.configure_provisioning(org=None, loc=None, compute=False, os=None)

Create and configure org, loc, product, repo, cv, env. Update proxy, domain, subnet, compute resource, provision templates and medium with previously created entities and create a hostgroup using all mentioned entities.

Parameters
  • org (str) – Default Organization that should be used in both host discovering and host provisioning procedures

  • loc (str) – Default Location that should be used in both host discovering and host provisioning procedures

  • compute (bool) – If False creates a default Libvirt compute resource

  • os (str) – Specify the os to be used while provisioning and to associate related entities to the specified os.

Returns

List of created entities that can be re-used further in provisioning or validation procedure (e.g. hostgroup or domain)

robottelo.api.utils.create_role_permissions(role, permissions_types_names, search=None)

Create role permissions found in dict permissions_types_names.

Parameters
  • role – nailgun.entities.Role

  • permissions_types_names – a dict containing resource types and permission names to add to the role.

  • search

    string that contains search criteria that should be applied to the filter

    example usage:

    permissions_types_names = {
        None: ['access_dashboard'],
        'Organization': ['view_organizations'],
        'Location': ['view_locations'],
        'Katello::KTEnvironment': [
            'view_lifecycle_environments',
            'edit_lifecycle_environments',
            'promote_or_remove_content_views_to_environments'
        ]
    }
    role = entities.Role(name='example_role_name').create()
    create_role_permissions(
        role,
        permissions_types_names,
        'name = {0}'.format(lce.name)
    )
    

robottelo.api.utils.wait_for_tasks(search_query, search_rate=1, max_tries=10, poll_rate=None, poll_timeout=None)

Search for tasks by specified search query and poll them to ensure that task has finished.

Parameters
  • search_query – Search query that will be passed to API call.

  • search_rate – Delay between searches.

  • max_tries – How many times search should be executed.

  • poll_rate – Delay between the end of one task check-up and the start of the next check-up. Parameter for nailgun.entities.ForemanTask.poll() method.

  • poll_timeout – Maximum number of seconds to wait until timing out. Parameter for nailgun.entities.ForemanTask.poll() method.

Returns

List of nailgun.entities.ForemanTasks entities.

Raises

AssertionError. If not tasks were found until timeout.

robottelo.api.utils.wait_for_syncplan_tasks(repo_backend_id=None, timeout=10, repo_name=None)

Search the pulp tasks and identify repositories sync tasks with specified name or backend_identifier

Parameters
  • repo_backend_id – The Backend ID for the repository to identify the repo in Pulp environment

  • timeout – Value to decided how long to check for the Sync task

  • repo_name – If repo_backend_id can not be passed, pass the repo_name

robottelo.api.utils.wait_for_errata_applicability_task(host_id, from_when, search_rate=1, max_tries=10, poll_rate=None, poll_timeout=15)

Search the generate applicability task for given host and make sure it finishes

Parameters
  • host_id (int) – Content host ID of the host where we are regenerating applicability.

  • from_when (int) – Timestamp (in UTC) to limit number of returned tasks to investigate.

  • search_rate (int) – Delay between searches.

  • max_tries (int) – How many times search should be executed.

  • poll_rate (int) – Delay between the end of one task check-up and the start of the next check-up. Parameter for nailgun.entities.ForemanTask.poll() method.

  • poll_timeout (int) – Maximum number of seconds to wait until timing out. Parameter for nailgun.entities.ForemanTask.poll() method.

Returns

Relevant errata applicability task.

Raises

AssertionError. If not tasks were found for given host until timeout.

robottelo.api.utils.create_discovered_host(name=None, ip_address=None, mac_address=None, options=None)

Creates a discovered host.

Parameters
  • name (str) – Name of discovered host.

  • ip_address (str) – A valid ip address.

  • mac_address (str) – A valid mac address.

  • options (dict) – additional facts to add to discovered host

Returns

dict of entities.DiscoveredHost facts.

robottelo.api.utils.update_vm_host_location(vm_client, location_id)

Update vm client host location.

Parameters
  • vm_client – A subscribed Virtual Machine client instance.

  • location_id – The location id to update the vm_client host with.

robottelo.api.utils.check_create_os_with_title(os_title)

Check if the OS is present, if not create the required OS

Parameters

os_title – OS title to check, and create (like: RedHat 7.5)

Returns

Created or found OS

robottelo.api.utils.attach_custom_product_subscription(prod_name=None, host_name=None)

Attach custom product subscription to client host :param str prod_name: custom product name :param str host_name: client host name

class robottelo.api.utils.templateupdate(temp)

Context Manager to unlock lock template for updating

__enter__(self)

Unlocks template for update

__exit__(self, exc_type, exc_val, exc_tb)

Locks template after update

robottelo.api.utils.update_provisioning_template(name=None, old=None, new=None)

Update provisioning template content

Parameters
  • name (str) – template provisioning name

  • old (str) – current content

  • new (str) – replace content

Return bool

True/False

robottelo.api.utils.apply_package_filter(content_view, repo, package, inclusion=True)

Apply package filter on content view

Parameters
  • content_view – entity content view

  • repo – entity repository

  • package (str) – package name to filter

  • inclusion (bool) – True/False based on include or exclude filter

:return list : list of content view versions

robottelo.api.utils.create_org_admin_role(orgs, locs, name=None)

Helper function to create org admin role for particular organizations and locations by cloning ‘Organization admin’ role.

Parameters
  • orgs (list) – The list of organizations for which the org admin is being created

  • locs (list) – The list of locations for which the org admin is being created

  • name (str) – The name of cloned Org Admin role, autogenerates if None provided

Return dict

The object of `nailgun.Role` of Org Admin role.

robottelo.api.utils.create_org_admin_user(orgs, locs)

Helper function to create an Org Admin user by assigning org admin role and assign taxonomies to Role and User

The taxonomies for role and user will be assigned based on parameters of this function

Return User

Returns the `nailgun.entities.User` object with passwd attr

robottelo.api.utils.skip_yum_update_during_provisioning(template=None, reverse=False)

Hides the yum update command with echo text

Parameters
  • template (str) – The template name where the yum update will be hidden

  • reverse (bool) – Reverses the echo text to yum update

Returns

Boolean True on success else exception

robottelo.api.utils.set_hammer_api_timeout(timeout=- 1, reverse=False)

Set hammer API request timeout on Satellite

Parameters
  • timeout (int) – request timeout in seconds

  • reverse (bool) – Reverses the request timeout

Returns

ssh.command

robottelo.api.utils.update_rhsso_settings_in_satellite(revert=False)

Update or Revert the RH-SSO settings in satellite