Generic Utilities

Collection of functions that did not fit anywhere else.

async zaza.utilities.generic.check_call(cmd)

Asynchronous function to check a subprocess call.

Parameters

cmd (List[str]) – Command to execute

Returns

None

Return type

None

Raises

subprocess.CalledProcessError if returncode !=0

async zaza.utilities.generic.check_output(cmd)

Asynchronous function to run a subprocess and get the output.

Note, as the code raises an Exception on returncode != 0, ‘Code’ in the dictionary will always be ‘0’. This is included for compatability reasons.

Parameters

cmd (List[str]) – Command to execute

Returns

{‘Code’: ‘’, ‘Stderr’: ‘’, ‘Stdout’: ‘’}

Return type

dict

Raises

subprocess.CalledProcessError if returncode !=0

zaza.utilities.generic.dict_to_yaml(dict_data)

Return YAML from dictionary.

Parameters

dict_data (dict) – Dictionary data

Returns

YAML dump

Return type

string

zaza.utilities.generic.do_release_upgrade(unit_name)

Run do-release-upgrade noninteractive.

Parameters

unit_name (str) – Unit Name

Returns

None

Return type

None

zaza.utilities.generic.get_network_config(net_topology, ignore_env_vars=False, net_topology_file='network.yaml')

Get network info from environment.

Get network info from network.yaml, override the values if specific environment variables are set for the undercloud.

This function may be used when running network configuration from CLI to pass in network configuration settings from a YAML file.

Parameters
  • net_topology (string) – Network topology name from network.yaml

  • ignore_env_vars (bool) – Ignore enviroment variables or not

Returns

Dictionary of network configuration

Return type

dict

zaza.utilities.generic.get_pkg_version(application, pkg)

Return package version.

Parameters
  • application (string) – Application name

  • pkg (string) – Package name

Returns

List of package version

Return type

list

zaza.utilities.generic.get_process_id_list(unit_name, process_name, expect_success=True, pgrep_full=False)

Get a list of process ID(s).

Get a list of process ID(s) from a single sentry juju unit for a single process name.

Parameters
  • unit_name – Amulet sentry instance (juju unit)

  • process_name – Process name

  • expect_success – If False, expect the PID to be missing, raise if it is present.

  • pgrep_full (bool) – Should pgrep be used rather than pidof to identify a service.

Returns

List of process IDs

Raises

zaza_exceptions.ProcessIdsFailed

zaza.utilities.generic.get_undercloud_env_vars()

Get environment specific undercloud network configuration settings.

Get environment specific undercloud network configuration settings from environment variables.

For each testing substrate, specific undercloud network configuration settings should be exported into the environment to enable testing on that substrate.

Note: Overcloud settings should be declared by the test caller and should not be overridden here.

Return a dictionary compatible with zaza.openstack.configure.network functions’ expected key structure.

Example exported environment variables: export default_gateway=”172.17.107.1” export external_net_cidr=”172.17.107.0/24” export external_dns=”10.5.0.2” export start_floating_ip=”172.17.107.200” export end_floating_ip=”172.17.107.249”

Example o-c-t & uosci non-standard environment variables: export NET_ID=”a705dd0f-5571-4818-8c30-4132cc494668” export GATEWAY=”172.17.107.1” export CIDR_EXT=”172.17.107.0/24” export NAMESERVER=”10.5.0.2” export FIP_RANGE=”172.17.107.200:172.17.107.249”

Returns

Network environment variables

Return type

dict

zaza.utilities.generic.get_unit_process_ids(unit_processes, expect_success=True)

Get unit process ID(s).

Construct a dict containing unit sentries, process names, and process IDs.

Parameters
  • unit_processes – A dictionary of unit names to list of process names.

  • expect_success – if False expect the processes to not be running, raise if they are.

Returns

Dictionary of unit names to dictionary of process names to PIDs.

Raises

zaza_exceptions.ProcessIdsFailed

zaza.utilities.generic.get_yaml_config(config_file)

Return configuration from YAML file.

Parameters

config_file (string) – Configuration file name

Returns

Dictionary of configuration

Return type

dict

zaza.utilities.generic.reboot(unit_name)

Reboot unit.

Parameters

unit_name (str) – Unit Name

Returns

None

Return type

None

zaza.utilities.generic.run_via_ssh(unit_name, cmd)

Run command on unit via ssh.

For executing commands on units when the juju agent is down.

Parameters
  • unit_name – Unit Name

  • cmd (str) – Command to execute on remote unit

Returns

None

Return type

None

zaza.utilities.generic.series_upgrade(unit_name, machine_num, from_series='trusty', to_series='xenial', origin='openstack-origin', files=None, workaround_script=None)

Perform series upgrade on a unit.

Parameters
  • unit_name (str) – Unit Name

  • machine_num (str) – Machine number

  • from_series (str) – The series from which to upgrade

  • to_series (str) – The series to which to upgrade

  • origin (str) – The configuration setting variable name for changing origin source. (openstack-origin or source)

  • files (list) – Workaround files to scp to unit under upgrade

  • workaround_script (str) – Workaround script to run during series upgrade

Returns

None

Return type

None

zaza.utilities.generic.series_upgrade_application(application, pause_non_leader_primary=True, pause_non_leader_subordinate=True, from_series='trusty', to_series='xenial', origin='openstack-origin', completed_machines=[], files=None, workaround_script=None)

Series upgrade application.

Wrap all the functionality to handle series upgrade for a given application. Including pausing non-leader units.

Parameters
  • application (str) – Name of application to upgrade series

  • pause_non_leader_primary (bool) – Whether the non-leader applications should be paused

  • pause_non_leader_subordinate (bool) – Whether the non-leader subordinate hacluster applications should be paused

  • from_series (str) – The series from which to upgrade

  • to_series (str) – The series to which to upgrade

  • origin (str) – The configuration setting variable name for changing origin source. (openstack-origin or source)

  • completed_machines (list) – List of completed machines which do no longer require series upgrade.

  • files (list) – Workaround files to scp to unit under upgrade

  • workaround_script (str) – Workaround script to run during series upgrade

Returns

None

Return type

None

zaza.utilities.generic.series_upgrade_non_leaders_first(application, from_series='trusty', to_series='xenial', completed_machines=[])

Series upgrade non leaders first.

Wrap all the functionality to handle series upgrade for charms which must have non leaders upgraded first.

Parameters
  • application (str) – Name of application to upgrade series

  • from_series (str) – The series from which to upgrade

  • to_series (str) – The series to which to upgrade

  • completed_machines (list) – List of completed machines which do no longer require series upgrade.

Returns

None

Return type

None

zaza.utilities.generic.set_dpkg_non_interactive_on_unit(unit_name, apt_conf_d='/etc/apt/apt.conf.d/50unattended-upgrades')

Set dpkg options on unit.

Parameters
  • unit_name (str) – Unit Name

  • apt_conf_d (str) – Apt.conf file to update

zaza.utilities.generic.set_origin(application, origin='openstack-origin', pocket='distro')

Set the configuration option for origin source.

Parameters
  • application (str) – Name of application to upgrade series

  • origin (str) – The configuration setting variable name for changing origin source. (openstack-origin or source)

  • pocket (str) – Origin source cloud pocket. i.e. ‘distro’ or ‘cloud:xenial-newton’

Returns

None

Return type

None

zaza.utilities.generic.validate_unit_process_ids(expected, actual)

Validate process id quantities for services on units.

Returns

True if the PIDs are validated, raises an exception if it is not the case.

Raises

zaza_exceptions.UnitCountMismatch

Raises

zaza_exceptions.UnitNotFound

Raises

zaza_exceptions.ProcessNameCountMismatch

Raises

zaza_exceptions.ProcessNameMismatch

Raises

zaza_exceptions.PIDCountMismatch

zaza.utilities.generic.wrap_do_release_upgrade(unit_name, from_series='trusty', to_series='xenial', files=None, workaround_script=None)

Wrap do release upgrade.

In a production environment this step would be run administratively. For testing purposes we need this automated.

Parameters
  • unit_name (str) – Unit Name

  • from_series (str) – The series from which to upgrade

  • to_series (str) – The series to which to upgrade

  • files (list) – Workaround files to scp to unit under upgrade

  • workaround_script (str) – Workaround script to run during series upgrade

Returns

None

Return type

None