ceph.ceph module

This module implements the required foundation data structures for testing.

class ceph.ceph.Ceph(name, node_list=None)

Bases: object

DEFAULT_RHCS_VERSION = '4.3'
property ansible_config
property ceph_demon_stat

Retrieves expected numbers for demons of each role :returns: Ceph demon stats :rtype: dict

property ceph_stable_release

Retrieve ceph stable realease based on ansible config (jewel, luminous, etc.) :returns: Ceph stable release :rtype: str

check_health(rhbuild, cluster_name=None, client=None, timeout=300)

Check if ceph is in healthy state

Parameters
  • rhbuild (str) – rhcs build version

  • client (CephObject) – ceph object with ceph-common and ceph-keyring

  • timeout (int) – max time to check if cluster is not healthy within timeout period - return 1

Returns

return 0 when ceph is in healthy state, else 1

Return type

int

create_rbd_pool(k_and_m, cluster_name=None)

Generate pools for later testing use :param k_and_m: ec-pool-k-m settings :type k_and_m: bool

distribute_all_yml()

Distributes ansible all.yml config across all installers

generate_ansible_inventory(device_to_add=None, mixed_lvm_confs=None, filestore=False)

Generate ansible inventory file content for given cluster :param device_to_add: To add new osd to the cluster, default None :type device_to_add: str :param mixed_lvm_confs: To configure multiple mixed lvm configs, default None :type mixed_lvm_confs: str :param filestore: True for filestore usage, dafault False :type filestore: bool

Returns

inventory

Return type

str

static generate_repository_file(base_url, repos, cloud_type='openstack')

Generate rhel repository file for given repos :param base_url: rhel compose url :type base_url: str :param repos: repos behind compose/ to process :type repos: list

Returns

repository file content

Return type

str

get_ansible_config()

Get Ansible config settings for all.yml :returns: Ansible config :rtype: dict

get_ceph_demons(role=None)

Get Ceph demons list :returns: list of CephDemon :rtype: list

get_ceph_object(role, order_id=0)

Returns single ceph object.

If order id is provided returns that occurrence from results list, otherwise returns first occurrence

Parameters
  • role (str) – Ceph object’s role

  • order_id (int) – order number of the ceph object

Returns

ceph object

Return type

CephObject

get_ceph_objects(role=None)

Get Ceph Object by role.

Returns all objects if role is not defined. Ceph object can be Ceph demon, client, installer or generic entity. Pool role is never assigned to Ceph object and means that node has no Ceph objects

Parameters

role (str) – Ceph object’s role as str

Returns

ceph objects

Return type

list

get_cluster_networks() str

Returns a comma separated list of cluster networks.

static get_iso_file_url(base_url)

Returns iso url for given compose link

Parameters

base_url (str) – rhel compose

Returns

iso file url

Return type

str

get_metadata_list(role, client=None)

Returns metadata for demons of specified role :param role: ceph demon role :type role: str :param client: Client with keyring and ceph-common :type client: CephObject

Returns

metadata as json object representation

Return type

list

get_node_by_hostname(hostname)

Returns Ceph node by it’s hostname :param hostname: hostname :type hostname: str

get_nodes(role=None, ignore=None)

Get node(s) by role. Return all nodes if role is not defined :param role: node’s role. Takes precedence over ignore :type role: str, RolesContainer :param ignore: node’s role to ignore from the list :type ignore: str, RolesContainer

Returns

nodes

Return type

list

get_nodes_in_location(location: str) list

Return the list of nodes found in the location.

get_osd_by_id(osd_id, client=None)
Parameters
  • osd_id

  • client

Return type

CephDemon

get_osd_container_name_by_id(osd_id, client=None)
Parameters
  • osd_id

  • client

Returns:

get_osd_data_partition(osd_id, client=None)

Returns data partition by given osd id :param osd_id: osd id :type osd_id: int :param client: client, optional :type client: CephObject

Returns

data path

Return type

str

get_osd_data_partition_path(osd_id, client=None)

Returns data partition path by given osd id :param osd_id: osd id :type osd_id: int :param client: client, optional :type client: CephObject

Returns

data partition path

Return type

str

get_osd_device(osd_id, client=None)
Parameters
  • osd_id

  • client

Returns:

get_osd_devices(node)

Get osd devices list :param node: Ceph node with osd demon :type node: CephNode

Returns

devices

Return type

list

get_osd_metadata(osd_id, client=None)

Returns metadata for osd by given id

Parameters
  • osd_id (int) – osd id

  • client (CephObject) – Client with keyring and ceph-common

Returns

osd metadata

Return type

metadata (Dict)

Example:

{
   "id": 8,
   "arch": "x86_64",
   "back_addr": "172.16.115.29:6801/1672",
   "back_iface": "eth0",
   "backend_filestore_dev_node": "vdd",
   "backend_filestore_partition_path": "/dev/vdd1",
   "ceph_version": "ceph version 12.2.5-42.el7cp
                    (82d52d7efa6edec70f6a0fc306f40b89265535fb) luminous
                    (stable)",
   "cpu": "Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz",
   "default_device_class": "hdd",
   "distro": "rhel",
   "distro_description": "Red Hat Enterprise Linux",
   "distro_version": "7.5",
   "filestore_backend": "xfs",
   "filestore_f_type": "0x58465342",
   "front_addr": "172.16.115.29:6800/1672",
   "front_iface": "eth0",
   "hb_back_addr": "172.16.115.29:6802/1672",
   "hb_front_addr": "172.16.115.29:6803/1672",
   "hostname": "ceph-shmohan-1537910194970-node2-osd",
   "journal_rotational": "1",
   "kernel_description": "#1 SMP Wed Mar 21 18:14:51 EDT 2018",
   "kernel_version": "3.10.0-862.el7.x86_64",
   "mem_swap_kb": "0",
   "mem_total_kb": "3880928",
   "os": "Linux",
   "osd_data": "/var/lib/ceph/osd/ceph-8",
   "osd_journal": "/var/lib/ceph/osd/ceph-8/journal",
   "osd_objectstore": "filestore",
   "rotational": "1"
}
static get_osd_service_name(osd_id, client=None)

Return the service name of the OSD daemon.

Parameters
  • osd_id

  • client

Returns:

get_public_networks() str

Returns a comma separated list of public networks.

osd_check(client, cluster_name=None, rhbuild=None)

Check OSD status :param client: client node to get OSD details :param rhbuild: ceph build version

Returns

0 - Successful 1 - failure

refresh_ansible_config_from_all_yml(installer=None)

Refreshes ansible config based on installer all.yml content :param installer: Ceph installer. Will use first available installer

if omitted

property rhcs_version

Get rhcs version, will return DEFAULT_RHCS_VERSION if not set :returns: rhcs version of given cluster :rtype: LooseVersion

set_ansible_config(ansible_config)

Set ansible config for all.yml :param ansible_config: Ceph Ansible all.yml config :type ansible_config: dict

setup_ceph_firewall()

Open required ports on nodes based on relevant ceph demons types

setup_insecure_registry()

Update all ceph demons nodes to allow insecure registry use

setup_osd_devices(devices, node)

Sets osd devices on a node :param devices: list of devices (/dev/vdb, /dev/vdc) :type devices: list :param node: Ceph node :type node: CephNode

setup_packages(base_url, hotfix_repo, installer_url, ubuntu_repo, build=None, cloud_type='openstack', exclude_ansible=False)

Setup packages required for ceph-ansible istallation :param base_url: rhel compose url :type base_url: str :param hotfix_repo: hotfix repo to use with priority :type hotfix_repo: str :param installer_url: installer url :type installer_url: str :param ubuntu_repo: deb repo url :type ubuntu_repo: str :param build: ansible_config.build or rhbuild cli argument :type build: str :param cloud_type: IaaS provider - defaults to OpenStack. :type cloud_type: str :param exclude_ansible: Excludes the ansible package from being upgraded :type exclude_ansible: bool

setup_ssh_keys()

Generate and distribute ssh keys within cluster

class ceph.ceph.CephClient(role, node)

Bases: CephObject

class ceph.ceph.CephDemon(role, node)

Bases: CephObject

ceph_demon_by_container_name(container_name)
property container_name
property container_prefix
exec_command(cmd, **kw)

Proxy to node’s exec_command with wrapper to run commands inside the container for containerized demons.

Parameters
  • cmd (str) – command to execute

  • **kw – options

Returns

node’s exec_command resut

class ceph.ceph.CephInstaller(role, node)

Bases: CephObject

add_iscsi_settings(test_data)

Add iscsi config to iscsigws.yml :param test_data: test data dict

append_to_all_yml(content)

Adds content to all.yml :param content: all.yml config as yml string :type content: str

enable_ceph_mgr_restful()

Enable restful service from MGR module with self-signed certificate. :returns: user credentials for restful calls :rtype: user_cred

get_all_yml()

Returns all.yml content :returns: all.yml content :rtype: dict

get_installed_ceph_versions()

Returns installed ceph versions :returns: ceph vsersions :rtype: str

install_ceph_ansible(rhbuild, **kw)

Installs ceph-ansible

read_inventory_file()

Read inventory file from ansible node :returns: inventory file data :rtype: out

setup_ansible_site_yml(build, containerized)

Create site.yml from sample for RPM or Image based deployment.

Parameters
  • build (string) – RHCS build

  • containerized (bool) – use site-container.yml.sample if True else site.yml.sample

write_inventory_file(inventory_config, file_name='hosts')

Write inventory to hosts file for ansible use. Old file will be overwritten :param inventory_config: inventory config compatible with ceph-ansible :type inventory_config: str :param file_name: custom inventory file name. (default : “hosts”) :type file_name: str

class ceph.ceph.CephNode(**kw)

Bases: object

class LvmConfig

Bases: object

data_lv = 'data-lv%s'
db_lv = 'db-lv%s'
lv_name = 'lv%s'
size = '{}%FREE'
vg_name = 'vg%s'
wal_lv = 'wal-lv%s'
chk_lvm_exists()
configure_firewall()

Configures firewall based on the package manager

connect()

connect to ceph instance using paramiko ssh protocol eg: self.connect() - setup tcp keepalive to max retries for active connection - set up hostname and shortname as attributes for tests to query

create_ceph_object(role)

Create ceph object on the node :param role: ceph object role :type role: str

Returns

created ceph object

Return type

CephObject|CephDemon

create_lvm(devices, num=None, check_lvm=True)

Creates lvm volumes and returns device list suitable for ansible config :param devices: list of devices :param num: number to concatenate with pv,vg and lv names :param check_lvm: To check if lvm exists is optional, by default checking is enabled

Returns (list): lvm volumes list

property distro_info
exec_command(**kw)

execute a command on the vm.

kw

execute command configuration

Type

Dict

check_ec

False will run the command and not wait for exit code

Example:

eg: self.exec_cmd(cmd='uptime')
or
self.exec_cmd(cmd='background_cmd', check_ec=False)

kw:
    check_ec: False will run the command and not wait for exit code
generate_id_rsa()

generate id_rsa key files for the new vm node

get_allocated_volumes()
get_ceph_demons(role=None)

Get Ceph demons list.

Only active (those which will be part of the cluster) demons are shown.

Returns

list of CephDemon

Return type

list

get_ceph_objects(role=None)

Get Ceph objects list on the node :param role: Ceph object role :type role: str

Returns

ceph objects

Return type

list

get_free_volumes()
install_lvm_util()

Installs lvm util

long_running(**kw)

Method to execute long running command.

Parameters

**kw – execute command configuration

Returns

exit status

Return type

ec

multiple_lvm_scenarios(devices, scenario)

Create lvm volumes based on the provided scenario and return dict, suitable for ansible config.

Parameters
  • devices (list) – device list

  • scenario (func) – osd scenario to be generated

Returns (dict): generated osd scenario

obtain_root_permissions(path)

Transfer ownership of root to current user for the path given. Recursive. :param path: file path :type path: str

open_firewall_port(port, protocol)

Opens firewall port on the node

Parameters
  • port (str|int|list) – port(s) to be enabled

  • protocol (str) – protocol

reconnect()

Re-establish the connections.

remote_file(**kw)

Return contents of the remote file.

remove_ceph_object(ceph_object)

Removes ceph object form the node :param ceph_object: ceph object to remove :type ceph_object: CephObject

property role
search_ethernet_interface(ceph_node_list)

Search interface on the given node which allows every node in the cluster accesible by it’s shortname.

Parameters

ceph_node_list (list) – lsit of CephNode

Returns

retturns None if no suitable interface found

Return type

eth_interface (str)

set_eth_interface(eth_interface)

set the eth interface

set_internal_ip()

set the internal ip of the vm which differs from floating ip

setup_deb_cdn_repos(build)

Setup cdn repositories for deb systems :param build: rhcs version :type build: str|LooseVersion

setup_deb_repos(deb_repo)

Setup repositories for deb system :param deb_repo: deb (Ubuntu) repository link :type deb_repo: str

setup_rhceph_cdn_repos(build, distro_ver)

Setup cdn repositories for rhel systems :param build: rhcs version :type build: str :param distro_ver: os distro version from /etc/os-release

setup_rhceph_repos(base_url, installer_url=None, cloud_type='openstack')

Setup repositories for rhel :param base_url: compose url for rhel :type base_url: str :param installer_url: installer repos url :type installer_url: str

class ceph.ceph.CephObject(role, node)

Bases: object

property distro_info
exec_command(cmd, **kw)

Proxy to node’s exec_command :param cmd: command to execute :type cmd: str :param **kw: options

Returns

node’s exec_command result

property pkg_type
remote_file(**kw)

Proxy to node’s write file :param **kw: options

Returns

node’s remote_file result

class ceph.ceph.CephObjectFactory(node)

Bases: object

CLIENT_ROLES = ['client']
DEMON_ROLES = ['mon', 'osd', 'mgr', 'rgw', 'mds', 'nfs', 'grafana']
create_ceph_object(role)

Create an appropriate Ceph object by role :param role: role string

Returns: Ceph object based on role

class ceph.ceph.CephOsd(node, device=None)

Bases: CephDemon

property container_name
property is_active
exception ceph.ceph.CommandFailed

Bases: Exception

class ceph.ceph.NodeVolume(status, path=None)

Bases: object

ALLOCATED = 'allocated'
FREE = 'free'
exception ceph.ceph.ResourceNotFoundError

Bases: Exception

class ceph.ceph.RolesContainer(role='pool')

Bases: object

Container for single or multiple node roles.

Can be used as iterable or with equality ‘==’ operator to check if role is present for the node. Note that ‘==’ operator will behave the same way as ‘in’ operator i.e. check that value is present in the role list.

append(object)
clear()
equals(other)
extend(iterable)
remove(object)
update_role(roles_list)
class ceph.ceph.SSHConnectionManager(ip_address, username, password, look_for_keys=False, private_key_file_path='', outage_timeout=600)

Bases: object

property client
get_client()
get_transport()
property transport
exception ceph.ceph.SocketTimeoutException

Bases: Exception