示例#1
0
def get_cluster_reuse(session_credentials):
    """
    Returns Gluster *trusted storage pool* (aka cluster) as identified by
    ``cluster_member`` machine (specified in usmqe config file).

    Returned cluster can be used for further testing.
    Function uses Tendrl API(clusters). In case there
    is need to identify cluster directly by storage
    tools this function should be split.
    """
    LOGGER = pytest.get_logger("cluster_reuse")
    id_hostname = CONF.config["usmqe"]["cluster_member"]
    api = TendrlApi(auth=session_credentials)

    retry_num = 12
    for i in range(retry_num):
        clusters = []
        for cluster in api.get_cluster_list():
            node_fqdn_list = cluster2node_fqdn_list(cluster)
            if id_hostname in node_fqdn_list:
                clusters.append(cluster)
                msg = "cluster member {} found in cluster {}"
            else:
                msg = "cluster member {} not found in cluster {}"
            LOGGER.debug(msg.format(id_hostname, node_fqdn_list))
        if len(clusters) == 1:
            cluster = clusters[0]
            LOGGER.info("using cluster: {}".format(
                cluster2node_fqdn_list(cluster)))
            return cluster
        else:
            LOGGER.warning(
                "unexpected number (!= 1) of clusters found: {}".format(
                    len(clusters)))
        # wait a bit before retrying again
        if i != retry_num - 1:
            LOGGER.info("retrying search for a cluster")
            time.sleep(5)

    raise Exception("There is no cluster which includes node"
                    " with FQDN == {}.".format(id_hostname))
示例#2
0
import attr
import pytest
from wait_for import wait_for

from usmqe.web.application.entities import BaseCollection, BaseEntity
from usmqe.web.application.implementations.web_ui import ViaWebUI

LOGGER = pytest.get_logger('events', module=True)


@attr.s
class BaseEvent(BaseEntity):
    """
    Base Event object. Can be either Cluster Event or Task Event.
    """
    event_id = attr.ib()
    description = attr.ib()
    date = attr.ib()


@attr.s
class Event(BaseEvent):
    """
    Event object is an item of a Cluster's EventsCollection.
    """
    cluster_name = attr.ib()


@attr.s
class EventsCollection(BaseCollection):
    ENTITY = Event
示例#3
0
# -*- coding: utf-8 -*-
import pytest
import time

from usmqe.usmscheduler import Scheduler
import usmqe.usmssh as usmssh
from usmqe.usmqeconfig import UsmConfig

LOGGER = pytest.get_logger('scheduler', module=True)


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")
示例#4
0
import pytest

# initialize usmqe logging module
LOGGER = pytest.get_logger("pytests_test")
pytest.set_logger(LOGGER)

# NOTE beware any usmqe import has to be after LOGGER is initialized not before
#      all import lines must have NOQA flag to be ignored by flake,
#        because all imports have to be at the begginning of the file
#      other possibility is to have imports where they are really needed
from usmqe.api.tendrlapi.common import login, logout  # NOQA flake8
from usmqe.api.tendrlapi import user as tendrlapi_user  # NOQA flake8


def get_name(fname):
    """
    Generate test name from method name.

    Parameters:
        fname (string): function name with parametrized arguments
                        e.g. "Test <Function 'test_my_method[1-my_arg-42]'>"
    """
    # take only function name with its parameters
    import re
    fname = re.sub(".*'(?P<name>.*)'.*", '\g<name>', fname)
    # remove 'test_' from the beginning and
    # replace all underscores with spaces
    return fname[5:].replace('_', ' ')


@pytest.fixture(scope="session", autouse=True)
示例#5
0
"""
Tendrl REST API for ceph.
"""
import pytest
import requests
from usmqe.api.tendrlapi.common import TendrlApi
from usmqe.usmqeconfig import UsmConfig

LOGGER = pytest.get_logger("tendrlapi_ceph", module=True)
CONF = UsmConfig()


class TendrlApiCeph(TendrlApi):
    """ Ceph methods for Tendrl REST API.
    """
    def import_cluster(self, nodes, asserts_in=None):
        """ Import Ceph cluster.

        Args:
            nodes (list): node list of cluster which will be imported
            asserts_in (dict): assert values for this call and this method
        """
        return super().import_cluster(nodes, "ceph", asserts_in)

    def create_pool(self,
                    cluster,
                    name,
                    pg_num,
                    min_size,
                    size,
                    pool_type=None,
示例#6
0
import attr
import pytest
from navmazing import NavigateToAttribute
from wait_for import wait_for

from usmqe.web import tools
from usmqe.web.application.entities import BaseCollection, BaseEntity
from usmqe.web.application.implementations.web_ui import TendrlNavigateStep, ViaWebUI
from usmqe.web.application.views.grafana import GrafanaBrickDashboard
from usmqe.web.application.views.brick import HostBricksView
from usmqe.web.application.views.brick import VolumeBricksView

LOGGER = pytest.get_logger('bricks', module=True)


@attr.s
class Brick(BaseEntity):
    """
    Base Brick object for bricks that are part of HostBricksCollection or VolumeBricksCollection.
    """
    brick_path = attr.ib()
    hostname = attr.ib()
    volume_name = attr.ib()
    utilization = attr.ib()
    disk_device_path = attr.ib()
    port = attr.ib()
    cluster_name = attr.ib()

    def get_values_from_dashboard(self):
        """
        Click Dashboard button, read the selected data from Grafana dashboard,
示例#7
0
"""
REST API test suite - Ceph pool
"""
import pytest

from usmqe.api.tendrlapi import cephapi
from usmqe.ceph import ceph_cluster

LOGGER = pytest.get_logger('test_pool', module=True)
"""@pylatest default
Setup
=====
There is Ceph cluster where pools can be managed.
"""
"""@pylatest default
Teardown
========
"""

# TODO create negative test case generator
# http://doc.pytest.org/en/latest/parametrize.html#basic-pytest-generate-tests-example


def test_create_pool_invalid(valid_cluster_id, invalid_pool_name,
                             invalid_pg_num, invalid_minsize, invalid_size,
                             valid_session_credentials):
    """@pylatest api/ceph.create_pool_invalid
        API-ceph: create_pool
        ******************************

        :authors:
示例#8
0
"""
tendrl REST API.
"""

import json
import requests
import pytest
from usmqe.api.tendrlapi.common import TendrlApi

LOGGER = pytest.get_logger("tendrlapi.user", module=True)
USERDATA_KEYS = {'email', 'name', 'role', 'username', 'email_notifications'}


class ApiUser(TendrlApi):
    """ Main class for interact with REST API - user.
    """
    def get_users(self, asserts_in=None):
        """ Get users.

        Name:        "GET_users",
        Method:      "GET",
        Pattern:     "users",

        Args:
            asserts_in: assert values for this call and this method
        """
        pattern = "users"
        request = requests.get(
            pytest.config.getini("usm_api_url") + pattern,
            auth=self._auth)
        self.print_req_info(request)
示例#9
0
import pytest
import time
import datetime

from usmqe.usmqeconfig import UsmConfig
from usmqe import usmssh, usmmail
from usmqe.api.tendrlapi import user as tendrlapi_user

LOGGER = pytest.get_logger('ui_user_testing', module=True)
CONF = UsmConfig()


@pytest.mark.author("*****@*****.**")
@pytest.mark.parametrize("receive_alerts", [False, True])
@pytest.mark.happypath
@pytest.mark.ansible_playbook_setup('test_setup.smtp.yml')
@pytest.mark.ansible_playbook_setup('test_setup.snmp.yml')
@pytest.mark.ansible_playbook_teardown('test_teardown.smtp.yml')
@pytest.mark.ansible_playbook_teardown('test_teardown.snmp.yml')
def test_alerting_settings(application, receive_alerts,
                           valid_normal_user_data):
    """
    Create normal user with email notifications switched on or off.
    Check that alerts appear in the mailbox according to notification settings.
    """
    """
    :step:
      Change admin's email to avoid collision.
    :result:
      Admin's email is changed
    """
"""
REST API test suite - Grafana dashboard cluster-dashboard
"""

import pytest
from usmqe.api.grafanaapi import grafanaapi
from usmqe.api.graphiteapi import graphiteapi
from usmqe.gluster.gluster import GlusterCommon


LOGGER = pytest.get_logger('cluster_dashboard', module=True)
"""@pylatest default
Setup
=====

Prepare USM cluster accordingly to documentation.
``GRAFANA`` for this file stands for Grafana API url used by tested Tendrl
server.
``GRAPHITE`` for this file stands for Graphite API url used by tested Tendrl
server.

"""

"""@pylatest default
Teardown
========
"""


def test_layout():
    """@pylatest grafana/layout
示例#11
0
import pytest

from usmqe.web import tools

LOGGER = pytest.get_logger('hosts', module=True)


@pytest.mark.testready
@pytest.mark.author("*****@*****.**")
@pytest.mark.happypath
def test_host_attributes(application, managed_cluster):
    """
    Test that all hosts are listed on cluster's Hosts page.
    Check all common host attributes
    """
    """
    :step:
      Log in to Web UI and get the cluster identified by cluster_member.
      Get the list of its hosts.
    :result:
      Host objects are initiated and their attributes are read from the page
    """
    clusters = application.collections.clusters.get_clusters()
    test_cluster = tools.choose_cluster(clusters,
                                        managed_cluster["cluster_id"],
                                        managed_cluster["short_name"])
    assert test_cluster.managed == "Yes"
    hosts = test_cluster.hosts.get_hosts()
    """
    :step:
       Compare the set of hostnames in UI to set of nodes in API
示例#12
0
"""
REST API test suite - Grafana dashboard host-dashboard
"""

import pytest
import time
from usmqe.api.grafanaapi import grafanaapi
from usmqe.api.graphiteapi import graphiteapi
from usmqe.usmqeconfig import UsmConfig


LOGGER = pytest.get_logger('host_dashboard', module=True)
CONF = UsmConfig()


@pytest.mark.testready
@pytest.mark.author("*****@*****.**")
def test_host_dashboard_layout():
    """
    Check that layout of dashboard is according to specification:
    ``https://github.com/Tendrl/specifications/issues/222``
    """
    grafana = grafanaapi.GrafanaApi()

    """
    :step:
      Send **GET** request to:
      ``GRAFANA/dashboards/db/host-dashboard`` and get layout structure.
      Compare structure of panels and rows as defined in specification:
      ``https://github.com/Tendrl/specifications/issues/222``
    :result:
示例#13
0
    # ...use SSH connection in any module...
    # and close all open ssh connections at the end
    ssh = usmssh.get_ssh()
    ssh.finish()

    # ...use SSH in any module
    SSH = usmssh.get_ssh()
    SSH["host.example.com"].run("ls -l")
"""

import os

import plumbum
import pytest

LOGGER = pytest.get_logger("ssh", module=True)
KEYFILE = "~/.ssh/id_rsa"
__SSH = None


def get_ssh():
    """
    Return SSH object.
    """
    # pylint: disable=W0603
    global __SSH
    if not __SSH:
        __SSH = SSHConnections()
    return __SSH

示例#14
0
"""
SkyRing REST API.
"""

import json

import requests
import pytest

from usmqe.api.skyringapi import skyringapi

LOGGER = pytest.get_logger("skyringapi.user", module=True)


class ApiUser(skyringapi.ApiCommon):
    """ Main class for interact with REST API - user.
    """
    def users(self, asserts_in=None):
        """ Get users.

        Name:        "GET_users",
        Method:      "GET",
        Pattern:     "users",

        Args:
            asserts_in: assert values for this call and this method
        """
        asserts = ApiUser.default_asserts.copy()
        asserts.update({
            "users": ["admin"],
            })
示例#15
0
"""
Library for direct access to gluster commands.

.. moduleauthor:: [email protected]
"""

import pytest

import usmqe.usmssh


LOGGER = pytest.get_logger('usmgluster.commands', module=True)
SSH = usmqe.usmssh.get_ssh()


class GlusterCommand(object):
    """
    gluster commands class
    """

    def __init__(self):
        """
        Run gluster command.
        """
        self._format_str = '--xml'
        self._timeout = 3
        self._base_command = 'gluster'

    def cmd(self, command):
        """
        Prepare gluster command.
示例#16
0
import pytest
from usmqe.api.tendrlapi import glusterapi

LOGGER = pytest.get_logger('grafana_conftest', module=True)


@pytest.fixture
def up_gluster_nodes(valid_session_credentials):
    """
    Generate valid host info from GetNodeList api call related to tendrl/nodes
    for hosts that are UP.
    """
    api = glusterapi.TendrlApiGluster(auth=valid_session_credentials)
    cluster_list = api.get_nodes()
    return [x for x in cluster_list["nodes"]
            if "tendrl/node" in x["tags"] and x["status"] == "UP"]
示例#17
0
# -*- coding: utf8 -*-
"""
REST API test suite - user
"""

import json
import pytest
from usmqe.api.tendrlapi import user as tendrlapi_user
from usmqe.api.tendrlapi.common import login, logout

LOGGER = pytest.get_logger('user_test', module=True)
"""@pylatest default
Setup
=====

Prepare USM cluster accordingly to documentation.

Further mentioned ``APIURL`` points to: ``http://USMSERVER/api/1.0``.
"""
"""@pylatest default
Teardown
========
"""


@pytest.mark.happypath
@pytest.mark.testready
def test_user_get(valid_session_credentials, valid_new_normal_user):
    """@pylatest api/user.get
    API-users: get user
    *******************
示例#18
0
import pytest
import os.path
from usmqe.api.tendrlapi import glusterapi
from usmqe.usmqeconfig import UsmConfig

LOGGER = pytest.get_logger('gluster_conftest', module=True)
CONF = UsmConfig()


@pytest.fixture
def valid_nodes(valid_session_credentials):
    """
    Generate valid host info from GetNodeList api call related to tendrl/nodes
    """
    api = glusterapi.TendrlApiGluster(auth=valid_session_credentials)
    cluster_list = api.get_nodes()
    return [
        x for x in cluster_list["nodes"]
        if "tendrl/node" in x["tags"] and x["status"] == "UP"
    ]


@pytest.fixture(params=[None, "0000000000000000"])
def invalid_cluster_id(request):
    """
    Generate invalid cluster id.
    """
    return request.param


@pytest.fixture(params=[None, "0000000000000000"])
示例#19
0
"""
Library for direct access to ceph commands.

.. moduleauthor:: [email protected]
.. moduleauthor:: [email protected]
"""

import pytest

from usmqe.usmqeconfig import UsmConfig
import usmqe.usmssh

LOGGER = pytest.get_logger('usmceph.commands', module=True)
SSH = usmqe.usmssh.get_ssh()
CONF = UsmConfig()


class CephCommand(object):
    """
    ceph commands class
    """
    def __init__(self):
        """
        Run ceph command.
        """
        self._format = 'json'
        self._timeout = 3
        self._base_command = 'ceph'

    def cmd(self, command):
        """
示例#20
0
"""
Description: Simple tests for log in on tendrl UI

Author: ltrilety
"""

import pytest
from selenium.webdriver.common.keys import Keys

from webstr.selenium.ui.support import WaitForWebstrPage
from usmqe.web.tendrl.loginpage import pages as loginpage
from usmqe.web.tendrl.landing_page.pages import get_landing_page
from usmqe.web.tendrl.landing_page.models import LOCATION
from usmqe.web.tendrl.auxiliary.pages import UpperMenu

LOGGER = pytest.get_logger('login_test', module=True)


def test_positive_login(testcase_set, log_out):
    """@usmid web/login_positive
    Login as valid user.
    """
    loginpage_inst = loginpage.LoginPage(testcase_set.driver,
                                         pytest.config.getini("usm_web_url"))
    LOGGER.debug("Fill valid credentials and log in")
    loginpage_inst.login_user(pytest.config.getini("usm_username"),
                              pytest.config.getini("usm_password"))
    page_inst = get_landing_page(testcase_set.driver)
    # Following check is extra, could be removed
    pytest.check(
        page_inst.is_present,
示例#21
0
import pytest
import re
from string import Template
import time
from usmqe.usmqeconfig import UsmConfig
import usmqe.usmmail
import usmqe.usmssh

LOGGER = pytest.get_logger('usmqe_alerting', module=True)
CONF = UsmConfig()


class Alerting(object):
    """
    Class for alert lookup. Supports alerts from SNMP, SMTP and tendrl api.
    For api lookup there have to run `usmqe_alerts_logger` service on api
    server. This can be installled by `test_setup.alerts_logger.yml` from
    usmqe-setup repository.
    """
    def __init__(self,
                 user="******",
                 client=None,
                 server=None,
                 msg_templates=None,
                 divergence=15.0):
        """
        Args:
            user (str): Tendrl user that receives alerts.
            client (str): Machine address with SNMP and SMTP client.
            server (str): Machine where Tendrl runs.
            msg_templates (dict): Tendrl messages can be overwritten but for
示例#22
0
"""
Tendrl REST API for gluster.
"""

import requests
import pytest
from usmqe.api.tendrlapi.common import TendrlApi

LOGGER = pytest.get_logger("glusterapi", module=True)


class TendrlApiGluster(TendrlApi):
    """ Gluster methods for Tendrl REST API.
    """
    def create_cluster(self,
                       name,
                       cluster_id,
                       nodes,
                       network,
                       conf_overrides=None,
                       asserts_in=None):
        """ Create Gluster cluster.

        Args:
            name (str): name of cluster
            cluster_id (str): id of cluster
            nodes (list): list of dictionaries containing node identification
                          and node role
            network (str): ip address and mask in prefix format of network with nodes
            conf_overrides (dict): dictionary containing special settings related
                        to specific sds type.
示例#23
0
"""
Grafana REST API.
"""

import json
import requests
import pytest
from difflib import Differ
from usmqe.api.base import ApiBase
from usmqe.usmqeconfig import UsmConfig

LOGGER = pytest.get_logger("grafanaapi", module=True)
CONF = UsmConfig()


class GrafanaApi(ApiBase):
    """ Common methods for grafana REST API.
    """
    def get_dashboards(self):
        """Get list of slugs that identify dashboards in Grafana.
        For more information about ``slugs`` refer to:
        ``http://docs.grafana.org/http_api/dashboard/#get-dashboard-by-slug``
        """
        pattern = "search"
        response = requests.get(CONF.config["usmqe"]["grafana_api_url"] +
                                pattern)
        self.check_response(response)
        return [
            dashboard["uri"].split("/")[1] for dashboard in response.json()
            if dashboard["type"] == "dash-db"
        ]
示例#24
0
"""
Graphite REST API.
"""

import requests
import pytest
from usmqe.api.base import ApiBase
from usmqe.usmqeconfig import UsmConfig

LOGGER = pytest.get_logger("graphiteapi", module=True)
CONF = UsmConfig()


class GraphiteApi(ApiBase):
    """ Common methods for graphite REST API.
    """
    def get_datapoints(self, target, from_date=None, until_date=None):
        """ Get required datapoints of provided Graphite target. If there
        are no datapoints then return empty list.
        Datapoints are in format:
        ``[[value, epoch-time], [value, epoch-time], ...]``
        Datetime format used by Graphite API is described on:
        ``https://graphite-api.readthedocs.io/en/latest/api.html#from-until``

        Args:
            target: id of Graphite metric.
            from_date: datetime string from which date are records shown
            until_date: datetime string to which date are records shown
        """
        pattern = "render/?target={}&format=json".format(target)
        if from_date:
示例#25
0
"""
etcd REST API.
"""

import json
import time
import requests
import pytest
from usmqe.api.base import ApiBase

LOGGER = pytest.get_logger("etcdapi", module=True)


class EtcdApi(ApiBase):
    """ Common methods for etcd REST API.
    """

    # TODO status, defaul finish, +issue parameter
    def wait_for_job_status(self,
                            job_id,
                            max_count=30,
                            status="finished",
                            issue=None):
        """ Repeatedly check if status of job with provided id is in reqquired state.

        Args:
            job_id: id provided by api request
            max_count: maximum of iterations
            status: expected status of job that is checked
            issue: pytest issue message (usually github issue link)
        """
示例#26
0
"""
REST API test suite - ceph cluster import

"""
from json.decoder import JSONDecodeError
import pytest

from usmqe.api.tendrlapi import cephapi

LOGGER = pytest.get_logger('test_cluster', module=True)
"""@pylatest default
Setup
=====
"""
"""@pylatest default
Teardown
========

"""
"""@pylatest api/ceph.cluster_import
API-ceph: cluster_import
***************************

.. test_metadata:: author [email protected]

Description
===========

Positive import Ceph cluster.

"""
示例#27
0
import attr
import pytest
from navmazing import NavigateToAttribute
from wait_for import wait_for

from usmqe.web.application.entities import BaseCollection, BaseEntity
from usmqe.web.application.implementations.web_ui import ViaWebUI
from usmqe.web.application.entities.events import TaskEventsCollection
from usmqe.web.application.implementations.web_ui import TendrlNavigateStep
from usmqe.web.application.views.task import TaskEventsView

LOGGER = pytest.get_logger('volumes', module=True)


@attr.s
class Task(BaseEntity):
    """
    Task object is an item of a Cluster's TasksCollection.
    Each task has its collection of Events.
    """
    task_id = attr.ib()
    task_name = attr.ib()
    submitted_date = attr.ib()
    status = attr.ib()
    changed_date = attr.ib()
    cluster_name = attr.ib()

    _collections = {'task_events': TaskEventsCollection}

    @property
    def task_events(self):
示例#28
0
"""
tendrl REST API.
"""

import requests
import pytest
from usmqe.api.tendrlapi.common import TendrlApi

LOGGER = pytest.get_logger("tendrlapi.notifications", module=True)


class ApiNotifications(TendrlApi):
    """ Main class for interact with REST API - notifications.
    """
    def get_notifications(self, asserts_in=None):
        """ Get notifications.

        Name:        "GET_notifications",
        Method:      "GET",
        Pattern:     "notifications",

        Args:
            asserts_in: assert values for this call and this method
        """
        pattern = "notifications"
        request = requests.get(pytest.config.getini("usm_api_url") + pattern,
                               auth=self._auth)
        self.print_req_info(request)
        self.check_response(request, asserts_in)
        return request.json(encoding='unicode')
示例#29
0
"""
REST API test suite - gluster cluster
"""
import pytest
import time

from usmqe.api.graphiteapi import graphiteapi
from usmqe.api.tendrlapi import glusterapi

LOGGER = pytest.get_logger('cluster_test', module=True)
"""@pylatest default
Setup
=====
"""
"""@pylatest default
Teardown
========
"""
"""@pylatest api/gluster.cluster_import
API-gluster: cluster_import
***************************

.. test_metadata:: author [email protected]

Description
===========

Positive import gluster cluster.
"""

示例#30
0
# -*- coding: utf8 -*-

import pytest
import subprocess

from packagelist import list_packages


LOGGER = pytest.get_logger(__name__, module=True)


@pytest.mark.parametrize("rpm_name", list_packages('tendrl-core'))
def test_yum_install(chroot_dir, rpm_name):
    """
    Try to install and uninstall rpm package via yum in CentOS 7 chroot.
    """
    cmd = [
        "sudo",
        "yum", "--installroot=%s" % chroot_dir, "-y", "install", rpm_name]
    # running yum install
    LOGGER.info(" ".join(cmd))
    cp = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    LOGGER.debug("STDOUT: %s", cp.stdout)
    if len(cp.stderr) > 0:
        LOGGER.warning("STDERR: %s", cp.stderr)
    else:
        LOGGER.debug("STDERR: %s", cp.stderr)
    check_msg = "return code of 'yum install {}' should be 0 indicating no errors"
    pytest.check(cp.returncode == 0, msg=check_msg.format(rpm_name))
    # check after installation
    cmd = ["rpm", "-q", rpm_name, "--root", chroot_dir]