Esempio n. 1
0
from tobiko.shell import ssh
from tobiko.tripleo import undercloud

CONF = config.CONF


def has_overcloud():
    # rewrite this function
    return undercloud.has_undercloud()


def load_overcloud_rcfile():
    return undercloud.fetch_os_env(rcfile=CONF.tobiko.tripleo.overcloud_rcfile)


skip_if_missing_overcloud = tobiko.skip_unless(
    'TripleO overcloud not configured', has_overcloud)


class OvercloudKeystoneCredentialsFixture(
        keystone.EnvironKeystoneCredentialsFixture):
    def get_environ(self):
        return load_overcloud_rcfile()


def list_overcloud_nodes(**params):
    session = undercloud.undercloud_keystone_session()
    client = nova.get_nova_client(session=session)
    return nova.list_servers(client=client, **params)


def find_overcloud_node(**params):
Esempio n. 2
0
def skip_unless_osp_version(version, higher=False, lower=False):
    skip_msg = "OSP version doesn't match the requirement"
    return tobiko.skip_unless(skip_msg, verify_osp_version, version, higher,
                              lower)
Esempio n. 3
0
from tobiko.tripleo import _config


def get_tripleo_ansible_inventory():
    inventory_file = get_tripleo_ansible_inventory_file()
    with io.open(inventory_file, 'rb') as fd:
        return tobiko.load_yaml(fd)


def has_tripleo_ansible_inventory():
    inventory_file = get_tripleo_ansible_inventory_file()
    return inventory_file and os.path.isfile(inventory_file)


skip_if_missing_tripleo_ansible_inventory = \
    tobiko.skip_unless("Can't read TripleO Ansible inventory",
                       has_tripleo_ansible_inventory)


def get_tripleo_ansible_inventory_file():
    return tobiko.setup_fixture(TripleoAnsibleInventoryFixture).inventory_file


class TripleoAnsibleInventoryFixture(tobiko.SharedFixture):

    inventory_file = None

    def setup_fixture(self):
        tripleo = _config.get_tripleo_config()
        self.inventory_file = inventory_file = tobiko.tobiko_config_path(
            tripleo.inventory_file)
        if inventory_file is not None and not os.path.isfile(inventory_file):
Esempio n. 4
0
        pcs_df_query_resource_type = pcs_df.query(
            'resource_type=="{}"'.format(resource_type))
        return pcs_df_query_resource_type['resource'].unique().tolist()


def instanceha_deployed():
    """check IHA deployment
    checks for existence of the nova-evacuate resource"""
    if overcloud.has_overcloud():
        return get_overcloud_nodes_running_pcs_resource(
            resource='nova-evacuate')
    else:
        return False


skip_if_instanceha_not_delpoyed = tobiko.skip_unless('instanceha not delpoyed',
                                                     instanceha_deployed)


def fencing_deployed():
    """check fencing deployment
    checks for existence of the stonith-fence type resources"""
    ssh_client = get_random_controller_ssh_client()
    fencing_output = sh.execute(
        "sudo pcs status |grep "
        "'stonith:fence_ipmilan'",
        ssh_client=ssh_client,
        expect_exit_status=None)

    if fencing_output.exit_status == 0:
        return True
    else:
Esempio n. 5
0

def get_ping_interface(ssh_client):
    manager = tobiko.setup_fixture(PingInterfaceManager)
    interface = manager.get_ping_interface(ssh_client=ssh_client)
    tobiko.check_valid_type(interface, PingInterface)
    return interface


def has_fragment_ping_option(ssh_client=None):
    interface = get_ping_interface(ssh_client=ssh_client)
    return interface.has_fragment_option


skip_if_missing_fragment_ping_option = tobiko.skip_unless(
    "requires (don't) fragment Ping option",
    has_fragment_ping_option)


class PingInterfaceManager(tobiko.SharedFixture):

    def __init__(self):
        super(PingInterfaceManager, self).__init__()
        self.client_interfaces = {}
        self.interfaces = []
        self.default_interface = PingInterface()

    def add_ping_interface(self, interface):
        LOG.debug('Register ping interface %r', interface)
        self.interfaces.append(interface)
Esempio n. 6
0
def load_undercloud_rcfile():
    return fetch_os_env(rcfile=CONF.tobiko.tripleo.undercloud_rcfile)


class UndercloudKeystoneCredentialsFixture(
        keystone.EnvironKeystoneCredentialsFixture):
    def get_environ(self):
        return load_undercloud_rcfile()


def has_undercloud():
    host_config = undercloud_host_config()
    return bool(host_config.hostname)


skip_if_missing_undercloud = tobiko.skip_unless(
    'TripleO undercloud hostname not configured', has_undercloud)


class UndecloudHostConfig(tobiko.SharedFixture):

    host = 'undercloud-0'
    hostname = None
    port = None
    username = None
    key_filename = None

    def __init__(self, **kwargs):
        super(UndecloudHostConfig, self).__init__()
        self._connect_parameters = ssh.gather_ssh_connect_parameters(**kwargs)

    def setup_fixture(self):
Esempio n. 7
0
    return networks


def get_external_network_id():
    return tobiko.setup_fixture(ExternalNetworkStackFixture).network_id


def get_external_network():
    return tobiko.setup_fixture(ExternalNetworkStackFixture).network_details


def has_external_network():
    return tobiko.setup_fixture(ExternalNetworkStackFixture).has_network


skip_unless_has_external_network = tobiko.skip_unless(
    'External network not found', has_external_network)


def get_floating_network_id():
    return tobiko.setup_fixture(FloatingNetworkStackFixture).network_id


def get_floating_network():
    return tobiko.setup_fixture(FloatingNetworkStackFixture).network_details


def has_floating_network():
    return tobiko.setup_fixture(FloatingNetworkStackFixture).has_network


skip_unless_has_floating_network = tobiko.skip_unless(
Esempio n. 8
0
def skip_unless_has_rhel_image():
    return tobiko.skip_unless('RHEL image not found', has_rhel_image)
Esempio n. 9
0
# Copyright (c) 2020 Red Hat, Inc.
#
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
from __future__ import absolute_import

import tobiko


def has_ssh_proxy_jump():
    return bool(tobiko.tobiko_config().ssh.proxy_jump)


skip_unless_has_ssh_proxy_jump = tobiko.skip_unless(
    "SSH proxy jump not configured", has_ssh_proxy_jump)
Esempio n. 10
0
def skip_unless_has_keystone_credentials(*args, **kwargs):
    return tobiko.skip_unless('Missing Keystone credentials',
                              has_keystone_credentials, *args, **kwargs)
Esempio n. 11
0
    """
    containers = get_filtered_node_containers(node, ['logrotate.*', ])
    if not containers:
        tobiko.skip_test('No logrotate container has been found')
    else:
        container = containers[0]
    sh.execute(f'docker exec -u root {container} logrotate '
               '-f /etc/logrotate-crond.conf',
               ssh_client=node.ssh_client, sudo=True)


def has_docker():
    return get_docker_version() is not None


skip_unless_has_docker = tobiko.skip_unless(
    "requires docker on controller nodes", has_docker)


def get_docker_version():
    # use a fixture to save the result
    return tobiko.setup_fixture(
        DockerVersionFixture).docker_version


class DockerVersionFixture(tobiko.SharedFixture):

    docker_version = None

    def setup_fixture(self):
        controller = topology.find_openstack_node(group='controller')
        try:
Esempio n. 12
0
def skip_unless_has_container_runtime():
    return tobiko.skip_unless('Container runtime not found',
                              has_container_runtime)