def default_alerts(appliance): file_name = data_path.join('ui/control/default_alerts.yaml').strpath alerts = {} if os.path.exists(file_name): with open(file_name,'r') as f: all_alerts = yaml.safe_load(f) alerts = ( all_alerts.get('v5.10') if appliance.version >= '5.10' else all_alerts.get('v5.9') ) else: pytest.skip('Could not find {}, skipping test.'.format(file_name)) # instantiate a list of alerts based on default_alerts.yaml alert_collection = appliance.collections.alerts default_alerts = [ alert_collection.instantiate( description=alert.get('Description'), active=alert.get('Active'), based_on=alert.get('Based On'), evaluate=alert.get('What is evaluated'), emails=alert.get('Email'), snmp_trap=alert.get('SNMP'), timeline_event=alert.get('Event on Timeline'), mgmt_event=alert.get('Management Event Raised') ) for key,alert in alerts.items() ] return default_alerts
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")) result = 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 result.success, result.output result = appliance.ssh_client.run_command("ls -l /root/convert_test.zip") assert result.success, result.output result = rake( "evm:automate:import ZIP_FILE=/root/convert_test.zip DOMAIN=Default OVERWRITE=true " "PREVIEW=false SYSTEM=false") assert result.success, result.output # Extract the methods so we can see if it was imported result = rake("evm:automate:extract_methods FOLDER=/root/automate_methods") request.addfinalizer(lambda: appliance.ssh_client.run_command("rm -rf /root/automate_methods")) assert result.success, result.output result = appliance.ssh_client.run_command( "find /root/automate_methods | grep 'relay_events[.]rb$'") assert result.success, "Could not find the method in the extracted methods directory"
def test_create_snapshot_via_ae(appliance, request, domain, small_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. Polarion: assignee: apagac casecomponent: Infra caseimportance: medium initialEstimate: 1/3h """ # 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(appliance).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 = InfraVm.Snapshot(name=snap_name, parent_vm=small_test_vm) simulate( appliance=appliance, instance="Request", request="snapshot", target_type='VM and Instance', target_object=small_test_vm.name, execute_methods=True, attributes_values={"snap_name": snap_name}) wait_for(lambda: snapshot.exists, timeout="2m", delay=10, fail_func=small_test_vm.provider.browser.refresh, handle_exception=True, message="Waiting for snapshot create") # Clean up if it appeared snapshot.delete()
def test_create_snapshot_via_ae(appliance, request, domain, small_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(appliance).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=small_test_vm) simulate(instance="Request", request="snapshot", target_type='VM and Instance', target_object=small_test_vm.name, execute_methods=True, attributes_values={"snap_name": snap_name}) wait_for(lambda: snapshot.exists, timeout="2m", delay=10, fail_func=small_test_vm.provider.browser.refresh, handle_exception=True) # Clean up if it appeared snapshot.delete()
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)
def yaml_path(yaml_name): """ Returns yaml path of the file with yaml_name name""" yaml_name = "{}.yaml".format(yaml_name) try: fs = FTPClientWrapper(cfme_data.ftpserver.entities.reports) file_path = fs.download(yaml_name, os.path.join("/tmp", yaml_name)) except (FTPException, AttributeError): logger.exception("FTP download or YAML lookup of %s failed, defaulting to local", yaml_name) file_path = data_path.join("ui", "intelligence", yaml_name).realpath().strpath logger.info("Importing from data path: %s", file_path) return file_path
def fix_merkyl_workaround(request, appliance): """Workaround around merkyl not opening an iptables port for communication""" if isinstance(appliance, DummyAppliance): return 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.hostname)
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) [profile.set_preference(*pref) for pref in profile_dict.items()] profile.update_preferences() return profile
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.items(): profile.set_preference(*pref) profile.update_preferences() return profile
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. Polarion: assignee: sbulage casecomponent: Automate initialEstimate: 1/6h """ 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")) result = 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 result.success, result.output result = appliance.ssh_client.run_command("ls -l /root/convert_test.zip") assert result.success, result.output result = rake( "evm:automate:import ZIP_FILE=/root/convert_test.zip DOMAIN=Default OVERWRITE=true " "PREVIEW=false SYSTEM=false") assert result.success, result.output # Extract the methods so we can see if it was imported result = rake("evm:automate:extract_methods FOLDER=/root/automate_methods") request.addfinalizer(lambda: appliance.ssh_client.run_command( "rm -rf /root/automate_methods")) assert result.success, result.output result = appliance.ssh_client.run_command( "find /root/automate_methods | grep 'relay_events[.]rb$'") assert result.success, "Could not find the method in the extracted methods directory"
import yaml from cfme import test_requirements from cfme.intelligence.reports.schedules import NewScheduleView from cfme.intelligence.reports.schedules import ScheduleDetailsView from cfme.rest.gen_data import users as _users from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.conf import cfme_data from cfme.utils.ftp import FTPClientWrapper from cfme.utils.log_validator import LogValidator from cfme.utils.path import data_path from cfme.utils.wait import wait_for pytestmark = [test_requirements.report, pytest.mark.tier(3), pytest.mark.sauce] SCHEDULES_REPORT_DIR = data_path.join("schedules_crud") TIMER = { "monthly": { "run": "Monthly", "timer_month": "2 Months", "hour": "12", "minute": "5", "time_zone": "(GMT+10:00) Melbourne", }, "hourly": { "run": "Hourly", "timer_hour": "6 Hours", "hour": "12", "minute": "5", "time_zone": "(GMT+10:00) Melbourne",
# -*- coding: utf-8 -*- import fauxfactory import pytest import yaml from cfme import test_requirements from cfme.intelligence.reports.schedules import ScheduleCollection from cfme.intelligence.reports.widgets import AllDashboardWidgetsView from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ from cfme.utils.path import data_path from cfme.utils.rest import assert_response from cfme.utils.update import update from cfme.utils.wait import wait_for_decorator 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_name in report_crud_dir.listdir(): if file_name.isfile() and file_name.basename.endswith(".yaml"): result.append(file_name.basename) return result def crud_files_schedules(): result = []
def import_invalid_yaml_file(request): return data_path.join("ui/control/invalid.yaml").realpath().strpath
def import_policy_file(request): return data_path.join("ui/control/policies.yaml").realpath().strpath
# -*- coding: utf-8 -*- import random import pytest import yaml from cfme import test_requirements from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.path import data_path pytestmark = [test_requirements.report] report_crud_dir = data_path.join("reports_crud") # EvmGroup-super_administrator -> user `admin` # If we add more, will need relogin + user creation GROUPS = ["EvmGroup-super_administrator"] def shuffle(l): """Simple deterministic shuffle. Ensures, that there is a change by moving all fields of iterable by 1. We need to ensure change to unlock Save button. """ return [l[-1]] + l[:-1] @pytest.fixture(scope="function") def report_menus(group, appliance):
"text": "are open", "coverage_text": " open" }, "closed_bzs": { "val": "false", "text": "are closed", "coverage_text": " closed" }, "all_bzs": { "val": None, "text": "have coverage", "coverage_text": "" } } QUERY_PATH = data_path.join("/bugzilla-queries/") BZ_URL = conf.env.bugzilla.url def get_report(directory): click.echo("Generating a BZ report in bz-report.yaml") pytest.main([ "--use-provider", "complete", "--long-running", "--use-template-cache", "--collect-only", "--dummy-appliance", "--include-manual", "-q", "--generate-bz-report", directory ]) # read the generated yaml try: with open("bz-report.yaml", "r") as stream: info = yaml.load(stream, Loader=yaml.BaseLoader) except IOError:
# -*- coding: utf-8 -*- import fauxfactory import pytest import yaml from cfme import test_requirements from cfme.intelligence.reports.schedules import ScheduleCollection from cfme.intelligence.reports.widgets import AllDashboardWidgetsView from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ from cfme.utils.path import data_path from cfme.utils.rest import assert_response from cfme.utils.update import update from cfme.utils.wait import wait_for_decorator 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_name in report_crud_dir.listdir(): if file_name.isfile() and file_name.basename.endswith(".yaml"): result.append(file_name.basename) return result def crud_files_schedules(): result = []
# -*- coding: utf-8 -*- """This module contains tests that are supposed to test CFME's CLI functionality.""" import pytest from cfme.automate.explorer.domain import DomainCollection from cfme.utils.path import data_path from cfme.utils.update import update cli_path = data_path.join("cli") @pytest.fixture(scope="function") def rake(appliance): appliance.ssh_client.run_rake_command("evm:automate:clear") appliance.ssh_client.run_rake_command("evm:automate:reset") yield lambda command: appliance.ssh_client.run_rake_command(command) # A bit slower but it will at least make it reliable appliance.ssh_client.run_rake_command("evm:automate:clear") appliance.ssh_client.run_rake_command("evm:automate:reset") @pytest.fixture(scope="function") def qe_ae_data(request, appliance, rake): appliance.ssh_client.put_file( cli_path.join("QECliTesting.yaml").strpath, "/root/QECliTesting.yaml") result = rake( "evm:automate:import DOMAIN=QECliTesting YAML_FILE=/root/QECliTesting.yaml PREVIEW=false " "ENABLED=true SYSTEM=false") assert result.success, result.output # Now we have to enable the domain to make it work. qe_cli_testing = DomainCollection(appliance).instantiate(name='QECliTesting')
# -*- coding: utf-8 -*- import random import pytest import yaml from cfme import test_requirements from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ from cfme.utils.path import data_path report_crud_dir = data_path.join("reports_crud") # EvmGroup-super_administrator -> user `admin` # If we add more, will need relogin + user creation GROUPS = ["EvmGroup-super_administrator"] def shuffle(l): """Simple deterministic shuffle. Ensures, that there is a change by moving all fields of iterable by 1. We need to ensure change to unlock Save button. """ return [l[-1]] + l[:-1] @pytest.fixture(scope="function") def report_menus(group, appliance):
# -*- coding: utf-8 -*- import pytest import yaml from cfme import test_requirements from cfme.intelligence.reports.schedules import ScheduleDetailsView from cfme.utils.path import data_path schedules_report_dir = data_path.join("schedules_report") def schedule_files(): result = [] for file_name in schedules_report_dir.listdir(): if file_name.isfile() and file_name.basename.endswith(".yaml"): result.append(file_name.basename) return result @pytest.fixture(params=schedule_files(), ids=[schedule.split(".")[0] for schedule in schedule_files()]) def schedule_data(request): with schedules_report_dir.join(request.param).open(mode="r") as rep_yaml: return yaml.load(rep_yaml) @pytest.fixture(scope='function') def schedule(schedule_data, appliance): collection = appliance.collections.schedules schedule = collection.create(**schedule_data)
def import_policy_file(request): return data_path.join("ui/control/policies.yaml").realpath().strpath
import fauxfactory import pytest from cfme import test_requirements from cfme.base.credential import Credential from cfme.rest.gen_data import users as _users from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ from cfme.utils.conf import cfme_data from cfme.utils.ftp import FTPClientWrapper from cfme.utils.path import data_path pytestmark = [pytest.mark.tier(3), test_requirements.report] REPORT_CRUD_DIR = data_path.join("reports_crud") # EvmGroup-super_administrator -> user `admin` # If we add more, will need relogin + user creation GROUPS = ["EvmGroup-super_administrator"] def shuffle(l): """Simple deterministic shuffle. Ensures, that there is a change by moving all fields of iterable by 1. We need to ensure change to unlock Save button. """ return [l[-1]] + l[:-1]
def import_invalid_yaml_file(request): return data_path.join("ui/control/invalid.yaml").realpath().strpath
# -*- coding: utf-8 -*- import fauxfactory import pytest import yaml from cfme import test_requirements from cfme.intelligence.reports.widgets import AllDashboardWidgetsView from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ from cfme.utils.path import data_path from cfme.utils.rest import assert_response from cfme.utils.update import update from cfme.utils.wait import wait_for_decorator 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_name in REPORT_CRUD_DIR.listdir(): if file_name.isfile() and file_name.basename.endswith(".yaml"): result.append(file_name.basename) return result def crud_files_schedules(): result = []
# -*- coding: utf-8 -*- import pytest import yaml from cfme import test_requirements from cfme.intelligence.reports.schedules import ScheduleDetailsView from cfme.utils.path import data_path schedules_report_dir = data_path.join("schedules_report") def schedule_files(): result = [] for file_name in schedules_report_dir.listdir(): if file_name.isfile() and file_name.basename.endswith(".yaml"): result.append(file_name.basename) return result @pytest.fixture(params=schedule_files(), ids=[schedule.split(".")[0] for schedule in schedule_files()]) def schedule_data(request): with schedules_report_dir.join(request.param).open(mode="r") as rep_yaml: return yaml.load(rep_yaml) @pytest.fixture(scope='function') def schedule(schedule_data, appliance): collection = appliance.collections.schedules schedule = collection.create(**schedule_data) yield schedule
# -*- coding: utf-8 -*- """This module contains tests that are supposed to test CFME's CLI functionality.""" import pytest from cfme.automate.explorer.domain import DomainCollection from cfme.utils.path import data_path from cfme.utils.update import update cli_path = data_path.join("cli") @pytest.yield_fixture(scope="function") def rake(appliance): appliance.ssh_client.run_rake_command("evm:automate:clear") appliance.ssh_client.run_rake_command("evm:automate:reset") yield lambda command: appliance.ssh_client.run_rake_command(command) # A bit slower but it will at least make it reliable appliance.ssh_client.run_rake_command("evm:automate:clear") appliance.ssh_client.run_rake_command("evm:automate:reset") @pytest.fixture(scope="function") def qe_ae_data(request, appliance, rake): appliance.ssh_client.put_file( cli_path.join("QECliTesting.yaml").strpath, "/root/QECliTesting.yaml") result = rake( "evm:automate:import DOMAIN=QECliTesting YAML_FILE=/root/QECliTesting.yaml PREVIEW=false " "ENABLED=true SYSTEM=false") assert result.success, result.output # Now we have to enable the domain to make it work. qe_cli_testing = DomainCollection(appliance).instantiate(