def list_packages(reponame): """ This helper function returns list of all rpm packages in given repository. """ # try to get baseurl of repository directly from usmqe config file, # which is even more TERRIBLE HACK, but I can't help it as pytest.config is # not available during of fixture arguments ... # TODO: we may want to reconsider design of usmqe configuration usm_config = UsmConfig() # if repo is not defined in config file, we have no packages to check ... if ("usmqe" in usm_config.config and "rpm_repo" in usm_config.config["usmqe"] and reponame2confname[reponame] in usm_config.config["usmqe"]["rpm_repo"]): baseurl = usm_config.config["usmqe"]["rpm_repo"][ reponame2confname[reponame]]["baseurl"] else: return [] # list all package names from given repo cmd = [ "repoquery", "--repofrompath={},{}".format(reponame, baseurl), "--repoid={}".format(reponame), "--all", "--qf='%{name}'", ] stdout = subprocess.check_output(cmd) rpm_name_list = stdout.decode('utf-8').replace("'", "").split("\n") # account for edge case of stdout2list conversion if len(rpm_name_list) >= 1 and len(rpm_name_list[-1]) == 0: rpm_name_list.pop() return rpm_name_list
def test_inventory_groups_exists(): CONF = UsmConfig() gd = CONF.inventory.get_groups_dict() assert "gluster_servers" in gd assert "usm_nodes" in gd assert "usm_server" in gd assert "usm_client" in gd
def test_inventory_get_hosts_gluster_is_node(): CONF = UsmConfig() gd = CONF.inventory.get_groups_dict() example_server = "example-usm1-gl1.usmqe.tendrl.org" assert example_server in gd["usm_nodes"] assert example_server in gd["gluster_servers"] assert gd["usm_nodes"] == gd["gluster_servers"]
def test_scheduler_workflow(): conf = UsmConfig() nodes = conf.inventory.get_groups_dict()["gluster_servers"] scheduler = Scheduler(nodes) scheduler.run_at("echo '1' > /tmp/test_task") jobs = scheduler.jobs() LOGGER.info("Jobs: {}".format(jobs)) assert len(jobs) == len(nodes) time.sleep(70) for node in nodes: SSH = usmssh.get_ssh() _, message, _ = SSH[node].run("cat /tmp/test_task") assert message.decode("utf-8").rstrip("\n") == "1" # teardown SSH[node].run("rm -f /tmp/test_task")
def main(): ap = argparse.ArgumentParser(description="Find Tendrl provisioner node(s).") ap.add_argument("-v", dest="verbose", action="store_true", help="set LOGGER to DEBUG level") args = ap.parse_args() if args.verbose: LOGGER.setLevel("DEBUG") else: LOGGER.setLevel("INFO") LOGGER.debug("loading UsmConfig") conf = UsmConfig() LOGGER.info("url of etcd: %s", conf.config["usmqe"]["etcd_api_url"]) provisioner_nodes = get_nodes_by_tag("provisioner") LOGGER.info("found %d provisioner node(s)", len(provisioner_nodes)) for node_name in provisioner_nodes: LOGGER.info(node_name)
import glob import os import pathlib import subprocess import tempfile import textwrap import urllib import pytest import requests from usmqe.usmqeconfig import UsmConfig from packagelist import list_packages from packagelist import reponame2confname CONF = UsmConfig() @pytest.fixture(scope="module") def chroot_dir(tendrl_repos): """ Create chroot enviroment for rpm installation test. """ tmpdirname = tempfile.mkdtemp() # create minimal directory tree os.makedirs(os.path.join(tmpdirname, "var/lib/rpm")) os.makedirs(os.path.join(tmpdirname, "etc/yum.repos.d")) os.makedirs(os.path.join(tmpdirname, "tmp")) # expected paths for gpg keys of rpm repositories repo_keys = [ os.path.join(tmpdirname, "etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7"),
def test_inventory_get_hosts(): CONF = UsmConfig() gd = CONF.inventory.get_groups_dict() example_server = "example-usm1-gl1.usmqe.tendrl.org" assert len(gd["usm_nodes"]) == 6 assert len(gd["usm_server"]) == 1
#!/usr/bin/env python3 from collections.abc import Iterable from os import pardir, path, environ import subprocess import sys from usmqe.usmqeconfig import UsmConfig conf = UsmConfig() # This serves as predefined pytest plugin configuration. # There can be added new options required by pytest plugins. # Prefered way to execute this script is to call pytest_cli.py from terminal # instead of pytest command. params = { "ansible_playbook_directory": path.abspath(path.join(path.dirname(__file__), pardir, "usmqe-setup")), "ansible_playbook_inventory": conf.config["inventory_file"] } # `ansible_playbook_inventory` option is preprocessed # todo(fbalak): add inventory file concatenation or something # now is used first inventory file in UsmConfig if params['ansible_playbook_inventory'] is not None: if (not isinstance(params['ansible_playbook_inventory'], str) and isinstance(params['ansible_playbook_inventory'], Iterable)): params['ansible_playbook_inventory'] = params[ 'ansible_playbook_inventory'][0]