コード例 #1
0
def test_evm_automate_convert(request, rake, ssh_client):
    """This test checks whether conversion from older XML format works.

    Prerequisities:
        * ``data/qe_event_handler.xml`` file.

    Steps:
        * Upload the testing file to the appliance.
        * Convert the file to ZIP using ``evm:automate:convert`` rake task
        * Import the ZIP file using ``evm:automate_import`` rake task.
        * Use ``evm:automate:extract_methods FOLDER=/some_folder`` and verify that a file named
            ``relay_events.rb`` is present in the directory hierarchy.
    """
    ssh_client.put_file(data_path.join("qe_event_handler.xml").strpath, "/root/convert_test.xml")
    request.addfinalizer(lambda: ssh_client.run_command("rm -f /root/convert_test.xml"))
    rc, stdout = rake(
        "evm:automate:convert DOMAIN=Default FILE=/root/convert_test.xml "
        "ZIP_FILE=/root/convert_test.zip")
    request.addfinalizer(lambda: ssh_client.run_command("rm -f /root/convert_test.zip"))
    assert rc == 0, stdout
    rc, stdout = ssh_client.run_command("ls -l /root/convert_test.zip")
    assert rc == 0, stdout
    rc, stdout = rake(
        "evm:automate:import ZIP_FILE=/root/convert_test.zip DOMAIN=Default OVERWRITE=true "
        "PREVIEW=false")
    assert rc == 0, stdout
    # Extract the methods so we can see if it was imported
    rc, stdout = rake("evm:automate:extract_methods FOLDER=/root/automate_methods")
    request.addfinalizer(lambda: ssh_client.run_command("rm -rf /root/automate_methods"))
    assert rc == 0, stdout
    rc, stdout = ssh_client.run_command("find /root/automate_methods | grep 'relay_events[.]rb$'")
    assert rc == 0, "Could not find the method in the extracted methods directory"
コード例 #2
0
def set_yaml_config(config_name, data_dict, hostname=None):
    """Given a yaml name, dictionary and hostname, set the configuration yaml on the server

    The configuration yamls must be inserted into the DB using the ruby console, so this function
    uses SSH, not the database. It makes sense to be included here as a counterpart to
    :py:func:`get_yaml_config`

    Args:
        config_name: Name of the yaml configuration file
        data_dict: Dictionary with data to set/change
        hostname: Hostname/address of the server that we want to set up (default ``None``)

    Note:
        If hostname is set to ``None``, the default server set up for this session will be
        used. See :py:class:``utils.ssh.SSHClient`` for details of the default setup.

    Warning:

        Manually editing the config yamls is potentially dangerous. Furthermore,
        the rails runner doesn't return useful information on the outcome of the
        set request, so errors that arise from the newly loading config file
        will go unreported.

    Usage:

        # Update the appliance name, for example
        vmbd_yaml = get_yaml_config('vmdb')
        vmdb_yaml['server']['name'] = 'EVM IS AWESOME'
        set_yaml_config('vmdb', vmdb_yaml, '1.2.3.4')

    """
    # CFME does a lot of things when loading a configfile, so
    # let their native conf loader handle the job
    # If hostname is defined, connect to the specified server
    if hostname is not None:
        _ssh_client = SSHClient(hostname=hostname)
    # Else, connect to the default one set up for this session
    else:
        _ssh_client = store.current_appliance.ssh_client
    # Build & send new config
    temp_yaml = NamedTemporaryFile()
    dest_yaml = '/tmp/conf.yaml'
    yaml.dump(data_dict, temp_yaml, default_flow_style=False)
    _ssh_client.put_file(temp_yaml.name, dest_yaml)
    # Build and send ruby script
    dest_ruby = '/tmp/load_conf.rb'
    ruby_template = data_path.join('utils', 'cfmedb_load_config.rbt')
    ruby_replacements = {
        'config_name': config_name,
        'config_file': dest_yaml
    }
    temp_ruby = load_data_file(ruby_template.strpath, ruby_replacements)
    _ssh_client.put_file(temp_ruby.name, dest_ruby)

    # Run it
    _ssh_client.run_rails_command(dest_ruby)
    fire('server_details_changed')
    fire('server_config_changed')
コード例 #3
0
ファイル: conftest.py プロジェクト: petrblaho/cfme_tests
def fix_merkyl_workaround():
    """Workaround around merkyl not opening an iptables port for communication"""
    ssh_client = SSHClient()
    if ssh_client.run_command('test -f /etc/init.d/merkyl').rc == 0:
        logger.info('Rudely overwriting merkyl init.d on appliance;')
        local_file = data_path.join("bundles").join("merkyl").join("merkyl")
        remote_file = "/etc/init.d/merkyl"
        ssh_client.put_file(local_file.strpath, remote_file)
        ssh_client.run_command("service merkyl restart")
コード例 #4
0
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join(
        "test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = DomainCollection().instantiate(name='ManageIQ')
    miq_class = miq_domain.namespaces.instantiate(
        name='System').classes.instantiate(name='Request')
    miq_class.copy_to(domain)
    request_cls = domain.namespaces.instantiate(
        name='System').classes.instantiate(name='Request')
    request.addfinalizer(request_cls.delete)
    method = request_cls.methods.create(name="snapshot",
                                        location='inline',
                                        script=method_contents)
    request.addfinalizer(method.delete)
    instance = request_cls.instances.create(
        name="snapshot", fields={"meth5": {
            'value': "snapshot"
        }})
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(instance="Request",
             request="snapshot",
             target_type='VM and Instance',
             target_object=test_vm.name,
             execute_methods=True,
             attributes_values={"snap_name": snap_name})

    wait_for(snapshot.does_snapshot_exist,
             timeout="2m",
             delay=10,
             fail_func=sel.refresh,
             handle_exception=True)

    # Clean up if it appeared
    snapshot.delete()
コード例 #5
0
def fix_merkyl_workaround():
    """Workaround around merkyl not opening an iptables port for communication"""
    ssh_client = store.current_appliance.ssh_client
    if ssh_client.run_command('test -s /etc/init.d/merkyl').rc != 0:
        logger.info('Rudely overwriting merkyl init.d on appliance;')
        local_file = data_path.join("bundles").join("merkyl").join("merkyl")
        remote_file = "/etc/init.d/merkyl"
        ssh_client.put_file(local_file.strpath, remote_file)
        ssh_client.run_command("service merkyl restart")
        art_client.fire_hook('setup_merkyl', ip=appliance_ip_address)
コード例 #6
0
def fix_merkyl_workaround(request, appliance):
    """Workaround around merkyl not opening an iptables port for communication"""
    ssh_client = appliance.ssh_client
    if ssh_client.run_command('test -s /etc/init.d/merkyl').rc != 0:
        logger.info('Rudely overwriting merkyl init.d on appliance;')
        local_file = data_path.join("bundles").join("merkyl").join("merkyl")
        remote_file = "/etc/init.d/merkyl"
        ssh_client.put_file(local_file.strpath, remote_file)
        ssh_client.run_command("service merkyl restart")
        fire_art_hook(request.config, 'setup_merkyl', ip=appliance.address)
コード例 #7
0
ファイル: test_snapshot.py プロジェクト: dajohnso/cfme_tests
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join("test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = DomainCollection().instantiate(name='ManageIQ')
    miq_class = miq_domain.namespaces.instantiate(name='System').classes.instantiate(name='Request')
    miq_class.copy_to(domain)
    request_cls = domain.namespaces.instantiate(name='System').classes.instantiate(name='Request')
    request.addfinalizer(request_cls.delete)
    method = request_cls.methods.create(name="snapshot", location='inline', script=method_contents)
    request.addfinalizer(method.delete)
    instance = request_cls.instances.create(
        name="snapshot",
        fields={
            "meth5": {
                'value': "snapshot"}})
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(
        instance="Request",
        request="snapshot",
        target_type='VM and Instance',
        target_object=test_vm.name,
        execute_methods=True,
        attributes_values={"snap_name": snap_name})

    wait_for(lambda: snapshot.exists, timeout="2m", delay=10,
             fail_func=sel.refresh, handle_exception=True)

    # Clean up if it appeared
    snapshot.delete()
コード例 #8
0
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join(
        "test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = Domain("ManageIQ (Locked)")
    miq_class = Class("Request",
                      namespace=Namespace("System", domain=miq_domain))
    request_cls = miq_class.copy_to(domain)
    request.addfinalizer(request_cls.delete)
    method = Method("snapshot", data=method_contents, cls=request_cls)
    method.create()
    request.addfinalizer(method.delete)
    instance = Instance("snapshot",
                        values={"meth5": "snapshot"},
                        cls=request_cls)
    instance.create()
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(instance="Request",
             request="snapshot",
             attribute=["VM and Instance", test_vm.name],
             execute_methods=True,
             avp={"snap_name": snap_name})

    wait_for(snapshot.does_snapshot_exist, timeout="2m", delay=10)

    # Clean up if it appeared
    snapshot.delete()
コード例 #9
0
ファイル: browser.py プロジェクト: sshveta/cfme_tests
def _load_firefox_profile():
    # create a firefox profile using the template in data/firefox_profile.js.template
    global firefox_profile_tmpdir
    if firefox_profile_tmpdir is None:
        firefox_profile_tmpdir = mkdtemp(prefix='firefox_profile_')
        # Clean up tempdir at exit
        atexit.register(rmtree, firefox_profile_tmpdir)

    template = data_path.join('firefox_profile.js.template').read()
    profile_json = Template(template).substitute(profile_dir=firefox_profile_tmpdir)
    profile_dict = json.loads(profile_json)

    profile = FirefoxProfile(firefox_profile_tmpdir)
    for pref in profile_dict.iteritems():
        profile.set_preference(*pref)
    profile.update_preferences()
    return profile
コード例 #10
0
ファイル: test_snapshot.py プロジェクト: rananda/cfme_tests
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join("test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = Domain("ManageIQ (Locked)")
    miq_class = Class("Request", namespace=Namespace("System", domain=miq_domain))
    request_cls = miq_class.copy_to(domain)
    request.addfinalizer(request_cls.delete)
    method = Method("snapshot", data=method_contents, cls=request_cls)
    method.create()
    request.addfinalizer(method.delete)
    instance = Instance("snapshot", values={"meth5": "snapshot"}, cls=request_cls)
    instance.create()
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(
        instance="Request",
        request="snapshot",
        attribute=["VM and Instance", test_vm.name],
        execute_methods=True,
        avp={"snap_name": snap_name},
    )

    wait_for(snapshot.does_snapshot_exist, timeout="2m", delay=10)

    # Clean up if it appeared
    snapshot.delete()
コード例 #11
0
def _load_firefox_profile():
    # create a firefox profile using the template in data/firefox_profile.js.template

    # Make a new firefox profile dir if it's unset or doesn't exist for some reason
    firefox_profile_tmpdir = mkdtemp(prefix='firefox_profile_')
    log.debug("created firefox profile")
    # Clean up tempdir at exit
    atexit.register(rmtree, firefox_profile_tmpdir, ignore_errors=True)

    template = data_path.join('firefox_profile.js.template').read()
    profile_json = Template(template).substitute(profile_dir=firefox_profile_tmpdir)
    profile_dict = json.loads(profile_json)

    profile = FirefoxProfile(firefox_profile_tmpdir)
    for pref in profile_dict.iteritems():
        profile.set_preference(*pref)
    profile.update_preferences()
    return profile
コード例 #12
0
def _load_firefox_profile():
    # create a firefox profile using the template in data/firefox_profile.js.template

    # Make a new firefox profile dir if it's unset or doesn't exist for some reason
    firefox_profile_tmpdir = mkdtemp(prefix='firefox_profile_')
    log.debug("created firefox profile")
    # Clean up tempdir at exit
    atexit.register(rmtree, firefox_profile_tmpdir, ignore_errors=True)

    template = data_path.join('firefox_profile.js.template').read()
    profile_json = Template(template).substitute(profile_dir=firefox_profile_tmpdir)
    profile_dict = json.loads(profile_json)

    profile = FirefoxProfile(firefox_profile_tmpdir)
    for pref in profile_dict.iteritems():
        profile.set_preference(*pref)
    profile.update_preferences()
    return profile
コード例 #13
0
ファイル: browser.py プロジェクト: jkrocil/integration_tests
def _load_firefox_profile():
    # create a firefox profile using the template in data/firefox_profile.js.template
    global firefox_profile_tmpdir
    if firefox_profile_tmpdir is None:
        firefox_profile_tmpdir = mkdtemp(prefix='firefox_profile_')
        # Clean up tempdir at exit
        atexit.register(rmtree, firefox_profile_tmpdir)

    template = data_path.join('firefox_profile.js.template').read()
    profile_json = Template(template).substitute(
        profile_dir=firefox_profile_tmpdir)
    profile_dict = json.loads(profile_json)

    profile = FirefoxProfile(firefox_profile_tmpdir)
    for pref in profile_dict.iteritems():
        profile.set_preference(*pref)
    profile.update_preferences()
    return profile
コード例 #14
0
def test_evm_automate_convert(request, rake, ssh_client):
    ssh_client.put_file(data_path.join("qe_event_handler.xml").strpath, "/root/convert_test.xml")
    request.addfinalizer(lambda: ssh_client.run_command("rm -f /root/convert_test.xml"))
    rc, stdout = rake(
        "evm:automate:convert DOMAIN=Default FILE=/root/convert_test.xml "
        "ZIP_FILE=/root/convert_test.zip")
    request.addfinalizer(lambda: ssh_client.run_command("rm -f /root/convert_test.zip"))
    assert rc == 0, stdout
    rc, stdout = ssh_client.run_command("ls -l /root/convert_test.zip")
    assert rc == 0, stdout
    rc, stdout = rake(
        "evm:automate:import ZIP_FILE=/root/convert_test.zip DOMAIN=Default OVERWRITE=true "
        "PREVIEW=false")
    assert rc == 0, stdout
    # Extract the methods so we can see if it was imported
    rc, stdout = rake("evm:automate:extract_methods FOLDER=/root/automate_methods")
    request.addfinalizer(lambda: ssh_client.run_command("rm -rf /root/automate_methods"))
    assert rc == 0, stdout
    rc, stdout = ssh_client.run_command("find /root/automate_methods | grep 'relay_events[.]rb$'")
    assert rc == 0, "Could not find the method in the extracted methods directory"
コード例 #15
0
def test_evm_automate_convert(request, rake, appliance):
    """This test checks whether conversion from older XML format works.

    Prerequisities:
        * ``data/qe_event_handler.xml`` file.

    Steps:
        * Upload the testing file to the appliance.
        * Convert the file to ZIP using ``evm:automate:convert`` rake task
        * Import the ZIP file using ``evm:automate_import`` rake task.
        * Use ``evm:automate:extract_methods FOLDER=/some_folder`` and verify that a file named
            ``relay_events.rb`` is present in the directory hierarchy.
    """
    appliance.ssh_client.put_file(
        data_path.join("qe_event_handler.xml").strpath,
        "/root/convert_test.xml")
    request.addfinalizer(lambda: appliance.ssh_client.run_command(
        "rm -f /root/convert_test.xml"))
    rc, stdout = rake(
        "evm:automate:convert DOMAIN=Default FILE=/root/convert_test.xml "
        "ZIP_FILE=/root/convert_test.zip")
    request.addfinalizer(lambda: appliance.ssh_client.run_command(
        "rm -f /root/convert_test.zip"))
    assert rc == 0, stdout
    rc, stdout = appliance.ssh_client.run_command(
        "ls -l /root/convert_test.zip")
    assert rc == 0, stdout
    rc, stdout = rake(
        "evm:automate:import ZIP_FILE=/root/convert_test.zip DOMAIN=Default OVERWRITE=true "
        "PREVIEW=false SYSTEM=false")
    assert rc == 0, stdout
    # Extract the methods so we can see if it was imported
    rc, stdout = rake(
        "evm:automate:extract_methods FOLDER=/root/automate_methods")
    request.addfinalizer(lambda: appliance.ssh_client.run_command(
        "rm -rf /root/automate_methods"))
    assert rc == 0, stdout
    rc, stdout = appliance.ssh_client.run_command(
        "find /root/automate_methods | grep 'relay_events[.]rb$'")
    assert rc == 0, "Could not find the method in the extracted methods directory"
コード例 #16
0
def import_invalid_yaml_file(request):
    return data_path.join("ui/control/invalid.yaml").realpath().strpath
コード例 #17
0
ファイル: test_crud.py プロジェクト: jdemon519/cfme_tests
import fauxfactory
import pytest
import yaml

from cfme.fixtures import pytest_selenium as sel
from cfme.intelligence.reports.dashboards import Dashboard
from cfme.intelligence.reports.reports import CustomReport
from cfme.intelligence.reports.schedules import Schedule
from cfme.intelligence.reports.widgets import ChartWidget, MenuWidget, ReportWidget, RSSFeedWidget
from utils.path import data_path
from utils.update import update
from utils.blockers import BZ
from utils import version
from cfme import test_requirements

report_crud_dir = data_path.join("reports_crud")
schedules_crud_dir = data_path.join("schedules_crud")


def crud_files_reports():
    result = []
    if not report_crud_dir.exists():
        report_crud_dir.mkdir()
    for file in report_crud_dir.listdir():
        if file.isfile() and file.basename.endswith(".yaml"):
            result.append(file.basename)
    return result


def crud_files_schedules():
    result = []
コード例 #18
0
def import_policy_file(request):
    return data_path.join("ui/control/policies.yaml").realpath().strpath
コード例 #19
0
# -*- coding: utf-8 -*-
"""This module contains tests that are supposed to test CFME's CLI functionality."""
import pytest

from cfme.automate.explorer import Domain
from utils.path import data_path
from utils.update import update

cli_path = data_path.join("cli")


@pytest.yield_fixture(scope="function")
def rake(ssh_client):
    ssh_client.run_rake_command("evm:automate:clear")
    ssh_client.run_rake_command("evm:automate:reset")
    yield lambda command: ssh_client.run_rake_command(command)
    # A bit slower but it will at least make it reliable
    ssh_client.run_rake_command("evm:automate:clear")
    ssh_client.run_rake_command("evm:automate:reset")


@pytest.fixture(scope="function")
def qe_ae_data(ssh_client, rake):
    ssh_client.put_file(
        cli_path.join("QECliTesting.yaml").strpath, "/root/QECliTesting.yaml")
    rc, stdout = rake(
        "evm:automate:import DOMAIN=QECliTesting YAML_FILE=/root/QECliTesting.yaml PREVIEW=false "
        "ENABLED=true SYSTEM=false")
    assert rc == 0, stdout
    # Now we have to enable the domain to make it work.
    qe_cli_testing = Domain(name="QECliTesting")
コード例 #20
0
def import_invalid_yaml_file(request):
    return data_path.join("ui/control/invalid.yaml").realpath().strpath
コード例 #21
0
def import_policy_file(request):
    return data_path.join("ui/control/policies.yaml").realpath().strpath
コード例 #22
0
# -*- coding: utf-8 -*-
"""This module contains tests that are supposed to test CFME's CLI functionality."""
import pytest

from cfme.automate.explorer import Domain
from utils.path import data_path
from utils.update import update

cli_path = data_path.join("cli")

pytestmark = [pytest.mark.ignore_stream("5.2")]


@pytest.yield_fixture(scope="function")
def rake(ssh_client):
    ssh_client.run_rake_command("evm:automate:clear")
    ssh_client.run_rake_command("evm:automate:reset")
    yield lambda command: ssh_client.run_rake_command(command)
    # A bit slower but it will at least make it reliable
    ssh_client.run_rake_command("evm:automate:clear")
    ssh_client.run_rake_command("evm:automate:reset")


@pytest.fixture(scope="function")
def qe_ae_data(ssh_client, rake):
    ssh_client.put_file(cli_path.join("QECliTesting.yaml").strpath, "/root/QECliTesting.yaml")
    rc, stdout = rake(
        "evm:automate:import DOMAIN=QECliTesting YAML_FILE=/root/QECliTesting.yaml PREVIEW=false "
        "ENABLED=true")
    assert rc == 0, stdout
    # Now we have to enable the domain to make it work.
コード例 #23
0
ファイル: test_crud.py プロジェクト: jkrocil/cfme_tests
# -*- coding: utf-8 -*-
import pytest
import yaml

from cfme.fixtures import pytest_selenium as sel
from cfme.intelligence.reports.dashboards import Dashboard
from cfme.intelligence.reports.reports import CustomReport
from cfme.intelligence.reports.schedules import Schedule
from cfme.intelligence.reports.widgets import ChartWidget, MenuWidget, ReportWidget, RSSFeedWidget
from utils.path import data_path
from utils.randomness import generate_random_string
from utils.update import update


report_crud_dir = data_path.join("reports_crud")
schedules_crud_dir = data_path.join("schedules_crud")


def crud_files_reports():
    result = []
    if not report_crud_dir.exists():
        report_crud_dir.mkdir()
    for file in report_crud_dir.listdir():
        if file.isfile() and file.basename.endswith(".yaml"):
            result.append(file.basename)
    return result


def crud_files_schedules():
    result = []
    if not schedules_crud_dir.exists():