def docs_info(): if version.current_version() < "5.4.0.1": return [ 'Control', 'Lifecycle and Automation', 'Quick Start', 'Settings And Operations', 'Insight', 'Integration Services' ] elif version.current_version() < "5.5.0.12": return [ 'Insight', 'Control', 'Lifecycle and Automation', 'REST API', 'SOAP API', 'User', 'Settings and Operations' ] elif version.appliance_is_downstream(): return [ 'Monitoring Alerts Reporting', 'General Configuration', 'Virtual Machines Hosts', 'Methods For Automation', 'Infrastructure Inventory', 'Providers', 'Scripting Actions', 'Defining Policies Profiles' ] else: # Upstream version has no docs return []
def resolve_blockers(item, blockers): if not isinstance(blockers, (list, tuple, set)): raise ValueError("Type of the 'blockers' parameter must be one of: list, tuple, set") # Prepare the global env for the kwarg insertion global_env = dict( appliance_version=version.current_version(), appliance_downstream=version.appliance_is_downstream(), item=item, blockers=blockers, ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. params = extract_fixtures_values(item) for funcarg, value in params.iteritems(): if funcarg not in global_env: global_env[funcarg] = value # Check blockers use_blockers = [] # Bugzilla shortcut blockers = map(lambda b: "BZ#{}".format(b) if isinstance(b, int) else b, blockers) for blocker in map(Blocker.parse, blockers): if blocker.blocks: use_blockers.append(blocker) # Unblocking discard_blockers = set([]) for blocker in use_blockers: unblock_func = kwargify(blocker.kwargs.get("unblock", None)) local_env = {"blocker": blocker} local_env.update(global_env) if unblock_func(**local_env): discard_blockers.add(blocker) for blocker in discard_blockers: use_blockers.remove(blocker) # We now have those that block testing, so we have to skip # Let's go in the order that they were added # Custom actions first for blocker in use_blockers: if "custom_action" in blocker.kwargs: action = kwargify(blocker.kwargs["custom_action"]) local_env = {"blocker": blocker} local_env.update(global_env) action(**local_env) # And then skip if use_blockers: name, location = get_test_idents(item) bugs = [bug.bug_id for bug in use_blockers if hasattr(bug, "bug_id")] skip_data = {'type': 'blocker', 'reason': bugs} art_client.fire_hook('skip_test', test_location=location, test_name=name, skip_data=skip_data) pytest.skip("Skipping due to these blockers:\n{}".format( "\n".join( "- {}".format(str(blocker)) for blocker in use_blockers ) ))
def resolve_blockers(item, blockers): # Prepare the global env for the kwarg insertion global_env = dict( appliance_version=version.current_version(), appliance_downstream=version.appliance_is_downstream(), item=item, blockers=blockers, ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. params = extract_fixtures_values(item) for funcarg, value in params.iteritems(): if funcarg not in global_env: global_env[funcarg] = value # Check blockers use_blockers = [] if not isinstance(blockers, (list, tuple, set)): blockers = [blockers] # Bugzilla shortcut blockers = map(lambda b: "BZ#{}".format(b) if isinstance(b, int) else b, blockers) for blocker in map(Blocker.parse, blockers): if blocker.blocks: use_blockers.append(blocker) # Unblocking discard_blockers = set([]) for blocker in use_blockers: unblock_func = kwargify(blocker.kwargs.get("unblock", None)) local_env = {"blocker": blocker} local_env.update(global_env) if unblock_func(**local_env): discard_blockers.add(blocker) for blocker in discard_blockers: use_blockers.remove(blocker) # We now have those that block testing, so we have to skip # Let's go in the order that they were added # Custom actions first for blocker in use_blockers: if "custom_action" in blocker.kwargs: action = kwargify(blocker.kwargs["custom_action"]) local_env = {"blocker": blocker} local_env.update(global_env) action(**local_env) # And then skip if use_blockers: name, location = get_test_idents(item) bugs = [bug.bug_id for bug in use_blockers if hasattr(bug, "bug_id")] skip_data = {'type': 'blocker', 'reason': bugs} art_client.fire_hook('skip_test', test_location=location, test_name=name, skip_data=skip_data) pytest.skip("Skipping due to these blockers:\n{}".format( "\n".join( "- {}".format(str(blocker)) for blocker in use_blockers ) ))
def docs_info(): if version.appliance_is_downstream(): return [ 'Monitoring Alerts Reporting', 'General Configuration', 'Virtual Machines Hosts', 'Methods For Automation', 'Infrastructure Inventory', 'Providers', 'Scripting Actions', 'Defining Policies Profiles' ] else: # Upstream version has no docs return []
def blocks(self): bug = self.data if bug is None: return False result = False if bug.is_opened: result = True if bug.upstream_bug: if not version.appliance_is_downstream() and bug.can_test_on_upstream: result = False return result
def resolve_blockers(item, blockers): # Prepare the global env for the kwarg insertion global_env = dict( appliance_version=version.current_version(), appliance_downstream=version.appliance_is_downstream(), item=item, blockers=blockers, ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. params = extract_fixtures_values(item) for funcarg, value in params.iteritems(): if funcarg not in global_env: global_env[funcarg] = value # Check blockers use_blockers = [] if not isinstance(blockers, (list, tuple, set)): blockers = [blockers] # Bugzilla shortcut blockers = map(lambda b: "BZ#{}".format(b) if isinstance(b, int) else b, blockers) for blocker in map(Blocker.parse, blockers): if blocker.blocks: use_blockers.append(blocker) # Unblocking discard_blockers = set([]) for blocker in use_blockers: unblock_func = kwargify(blocker.kwargs.get("unblock", None)) local_env = {"blocker": blocker} local_env.update(global_env) if unblock_func(**local_env): discard_blockers.add(blocker) for blocker in discard_blockers: use_blockers.remove(blocker) # We now have those that block testing, so we have to skip # Let's go in the order that they were added # Custom actions first for blocker in use_blockers: if "custom_action" in blocker.kwargs: action = kwargify(blocker.kwargs["custom_action"]) local_env = {"blocker": blocker} local_env.update(global_env) action(**local_env) # And then skip if use_blockers: pytest.skip("Skipping due to these blockers:\n{}".format( "\n".join( "- {}".format(str(blocker)) for blocker in use_blockers ) ))
def blocks(self): try: bug = self.data if bug is None: return False result = False if bug.is_opened: result = True if bug.upstream_bug: if not version.appliance_is_downstream() and bug.can_test_on_upstream: result = False if result is False and version.appliance_is_downstream(): if bug.fixed_in is not None: return version.current_version() < bug.fixed_in return result except xmlrpclib.Fault as e: code = e.faultCode s = e.faultString.strip().split("\n")[0] logger.error("Bugzilla thrown a fault: %s/%s", code, s) logger.warning("Ignoring and taking the bug as non-blocking") store.terminalreporter.write( "Bugzila made a booboo: {}/{}\n".format(code, s), bold=True) return False
def blocks(self): try: bug = self.data if bug is None: return False result = False if bug.is_opened: result = True if bug.upstream_bug: if not version.appliance_is_downstream() and bug.can_test_on_upstream: result = False if result is False and version.appliance_is_downstream(): if bug.fixed_in is not None: return version.current_version() < bug.fixed_in return result except xmlrpclib.Fault as e: code = e.faultCode s = e.faultString.strip().split("\n")[0] logger.error("Bugzilla thrown a fault: {}/".format(code, s)) logger.warning("Ignoring and taking the bug as non-blocking") store.terminalreporter.write( "Bugzila made a booboo: {}/{}\n".format(code, s), bold=True) return False
def docs_info(): if version.appliance_is_downstream(): return [ "Monitoring Alerts Reporting", "General Configuration", "Virtual Machines Hosts", "Methods For Automation", "Infrastructure Inventory", "Providers", "Scripting Actions", "Defining Policies Profiles", ] else: # Upstream version has no docs return []
def blocks(self): if self.upstream_only and version.appliance_is_downstream(): return False if self.data.state == "closed": return False # Now let's check versions if self.since is None and self.until is None: # No version specifics return True elif self.since is not None and self.until is not None: # since inclusive, until exclusive return self.since <= version.current_version() < self.until elif self.since is not None: # Only since return version.current_version() >= self.since elif self.until is not None: # Only until return version.current_version() < self.until
def docs_info(): if version.current_version() < "5.4.0.1" or (not version.appliance_is_downstream()): return [ 'Control', 'Lifecycle and Automation', 'Quick Start', 'Settings And Operations', 'Insight', 'Integration Services' ] else: return [ 'Insight', 'Control', 'Lifecycle and Automation', 'REST API', 'SOAP API', 'User', 'Settings and Operations' ]
vm_name = catalog_item.provisioning_data["vm_name"] catalog_item.create() service_catalogs = ServiceCatalogs(catalog_item.name) service_catalogs.order() flash.assert_no_errors() logger.info('Waiting for cfme provision request for service %s', catalog_item.name) request_description = catalog_item.name request_row = Request(request_description, partial_check=True) request_row.wait_for_request() assert request_row.is_succeeded() return vm_name @pytest.mark.usefixtures("setup_provider") @pytest.mark.uncollectif(lambda: version.appliance_is_downstream()) @pytest.mark.long_running def test_vm_clone(provider, clone_vm_name, request, create_vm): vm_name = create_vm + "_0001" request.addfinalizer(lambda: cleanup_vm(vm_name, provider)) request.addfinalizer(lambda: cleanup_vm(clone_vm_name, provider)) vm = VM.factory(vm_name, provider) if provider.one_of(RHEVMProvider): provision_type = 'Native Clone' elif provider.one_of(VMwareProvider): provision_type = 'VMware' vm.clone_vm("*****@*****.**", "first", "last", clone_vm_name, provision_type) request_description = clone_vm_name request_row = Request(request_description, partial_check=True) request_row.wait_for_request(method='ui')
def is_opened(self): if self.upstream_bug and not appliance_is_downstream(): states = self._bugzilla.open_states else: states = self._bugzilla.open_states + ["POST", "MODIFIED"] return self.status in states
def get_streams_id(): if appliance_is_downstream(): return {"{}.{}".format(*current_version().version[:2]), "downstream"} else: return {"upstream"}
catalog_item.create() service_catalogs = ServiceCatalogs(catalog_item.name) service_catalogs.order() flash.assert_no_errors() logger.info('Waiting for cfme provision request for service %s', catalog_item.name) row_description = catalog_item.name cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=1400, delay=20) assert row.last_message.text == 'Request complete' return vm_name @pytest.mark.meta(blockers=[1255190]) @pytest.mark.usefixtures("setup_provider") @pytest.mark.uncollectif(lambda: version.appliance_is_downstream()) @pytest.mark.long_running def test_vm_clone(provider, clone_vm_name, request, create_vm): vm_name = create_vm + "_0001" request.addfinalizer(lambda: cleanup_vm(vm_name, provider)) request.addfinalizer(lambda: cleanup_vm(clone_vm_name, provider)) vm = VM.factory(vm_name, provider) if provider.type == 'rhevm': provision_type = 'Native Clone' elif provider.type == 'virtualcenter': provision_type = 'VMware' vm.clone_vm("*****@*****.**", "first", "last", clone_vm_name, provision_type) row_description = clone_vm_name cells = {'Description': row_description} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=4000, delay=20)
Metadata: test_flag: provision """ dt = datetime.utcnow() myservice.retire_on_date(dt) def test_crud_set_ownership_and_edit_tags(myservice): """Tests my service crud , edit tags and ownership Metadata: test_flag: provision """ myservice.set_ownership("Administrator", "EvmGroup-administrator") myservice.edit_tags("Cost Center *", "Cost Center 001") with update(myservice): myservice.description = "my edited description" myservice.delete() @pytest.mark.parametrize("filetype", ["Text", "CSV", "PDF"]) # PDF not present on upstream @pytest.mark.uncollectif(lambda filetype: filetype == 'PDF' and not appliance_is_downstream()) def test_download_file(needs_firefox, myservice, filetype): """Tests my service download files Metadata: test_flag: provision """ myservice.download_file(filetype)
def is_opened(self): states = self._bugzilla.open_states if not self.upstream_bug and appliance_is_downstream(): states = self._bugzilla.open_states + ["POST", "MODIFIED"] return self.status in states
selected_template = Vm(template_name, provider) quadicon = selected_template.find_quadicon(do_not_navigate=True, mark=False, refresh=False) with error.expected(NoSuchElementException): toolbar.select("Power") # Ensure there isn't a power button on the details page pytest.sel.click(quadicon) with error.expected(NoSuchElementException): toolbar.select("Power") @pytest.mark.usefixtures("test_vm") @pytest.mark.usefixtures("setup_provider_clsscope") @pytest.mark.uncollectif( lambda: appliance_is_downstream() and current_version() < "5.4") class TestPowerControlRESTAPI(object): @pytest.fixture(scope="function") def vm(self, rest_api, vm_name): result = rest_api.collections.vms.get(name=vm_name) assert result.name == vm_name return result def test_power_off(self, verify_vm_running, vm): assert "stop" in vm.action vm.action.stop() wait_for(lambda: vm.power_state == "off", num_sec=300, delay=5, fail_func=vm.reload)
test_flag: provision """ dt = datetime.utcnow() myservice.retire_on_date(dt) def test_crud_set_ownership_and_edit_tags(myservice): """Tests my service crud , edit tags and ownership Metadata: test_flag: provision """ myservice.set_ownership("Administrator", "EvmGroup-administrator") myservice.edit_tags("Cost Center *", "Cost Center 001") with update(myservice): myservice.description = "my edited description" myservice.delete() @pytest.mark.parametrize("filetype", ["Text", "CSV", "PDF"]) # PDF not present on upstream @pytest.mark.uncollectif( lambda filetype: filetype == 'PDF' and not appliance_is_downstream()) def test_download_file(needs_firefox, myservice, filetype): """Tests my service download files Metadata: test_flag: provision """ myservice.download_file(filetype)
def get_streams_id(): if appliance_is_downstream(): return {current_version().series(2), "downstream"} else: return {"upstream"}
def get_streams_id(): from utils.version import appliance_is_downstream, current_version if appliance_is_downstream(): return {current_version().series(2), "downstream"} else: return {"upstream"}
def pytest_runtest_setup(item): if not hasattr(item, "_bugzilla_bugs"): return skippers = set([]) xfailers = set([]) # We filter only bugs that are fixed in current release # Generic status-based skipping for bug in filter(lambda o: o is not None, map(lambda bug: item._bugzilla_bugs.get_bug(bug.id), item._bugzilla_bugs)): if bug.status in {"NEW", "ASSIGNED", "ON_DEV"}: skippers.add(bug.id) # POST/MODIFIED for upstream states = {"POST", "MODIFIED"} for bug in filter(lambda b: b.status in states, filter(lambda o: o is not None, map(lambda bug: item._bugzilla_bugs.get_bug(bug.id), item._bugzilla_bugs))): history = bug.get_history()["bugs"][0]["history"] changes = [] # We look for status changes in the history for event in history: for change in event["changes"]: if change["field_name"].lower() != "status": continue if change["added"] in states: changes.append(event["when"]) break if changes: if appliance_is_downstream(): # The possible fix is definitely not in the downstream build skippers.add(bug.id) continue # Given that the current bug state is what we want, we select the last change to the bug last_change = changes[-1] if last_change < appliance_build_datetime(): logger.info( "Decided to test {} on upstream, because the appliance was built " "after the bug {} status was modified".format(item.nodeid, bug.id) ) else: skippers.add(bug.id) # Custom skip/xfail handler global_env = dict( bugs=item._bugzilla_bugs, appliance_version=current_version(), appliance_downstream=appliance_is_downstream(), ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. for funcarg, value in item.callspec.params.iteritems(): if funcarg not in global_env: global_env[funcarg] = value for bug in set(map(lambda bug: item._bugzilla_bugs.get_bug(bug.id), item._bugzilla_bugs)): local_env = {"bug": bug} local_env.update(global_env) if item._skip_func(**local_env): skippers.add(bug.id) if item._xfail_func(**local_env): xfailers.add(bug.id) # Separate loop for unskipping for bug in set(map(lambda id: item._bugzilla_bugs.get_bug(id), skippers)): if bug.id not in item._unskip_dict: continue local_env = {"bug": bug} local_env.update(global_env) if item._unskip_dict[bug.id](**local_env): skippers.discard(bug.id) # We now have to resolve what to do with this test item # xfailing takes precedence over skipping (xfail is via custom function) if xfailers: item.add_marker( pytest.mark.xfail( "Xfailing due to these bugs: {}".format(", ".join(map(str, xfailers))))) elif skippers: bz_url = urlparse(item._bugzilla.url) pytest.skip("Skipping due to these bugs:\n{}".format( "\n".join([ "{}: {} ({}://{}/show_bug.cgi?id={})".format( bug.status, bug.summary, bz_url.scheme, bz_url.netloc, bug.id) for bug in set(map(lambda id: item._bugzilla_bugs.get_bug(id), skippers)) ]) )) else: logger.info("No action required by Bugzilla for {}. All good!".format(item.nodeid))
def is_opened(self): if self.upstream_bug and not appliance_is_downstream(): states = self._bugzilla.open_states else: states = self._bugzilla.open_states + ["POST"] return self.status in states
def blocks(self): if version.appliance_is_downstream(): return False return self.data.state != "closed"
templates = list(get_all_vms(True)) template_name = random.choice(templates) selected_template = VM.factory(template_name, provider, template=True) # Check the power button with checking the quadicon quadicon = selected_template.find_quadicon(do_not_navigate=True, mark=True, refresh=False) soft_assert(not toolbar.exists("Power"), "Power displayed when template quadicon checked!") # Ensure there isn't a power button on the details page pytest.sel.click(quadicon) soft_assert(not toolbar.exists("Power"), "Power displayed in template details!") @pytest.mark.usefixtures("test_vm") @pytest.mark.usefixtures("setup_provider_clsscope") @pytest.mark.uncollectif(lambda: appliance_is_downstream() and current_version() < "5.4") class TestPowerControlRESTAPI(object): @pytest.fixture(scope="function") def vm(self, rest_api, vm_name): result = rest_api.collections.vms.get(name=vm_name) assert result.name == vm_name return result def test_power_off(self, verify_vm_running, vm): assert "stop" in vm.action vm.action.stop() wait_for(lambda: vm.power_state == "off", num_sec=300, delay=5, fail_func=vm.reload) def test_power_on(self, verify_vm_stopped, vm): assert "start" in vm.action vm.action.start()
# Ensure selecting a template doesn't cause power menu to appear templates = list(get_all_vms(True)) template_name = random.choice(templates) selected_template = VM.factory(template_name, provider, template=True) # Check the power button with checking the quadicon quadicon = selected_template.find_quadicon(do_not_navigate=True, mark=True, refresh=False) soft_assert(not toolbar.exists("Power"), "Power displayed when template quadicon checked!") # Ensure there isn't a power button on the details page pytest.sel.click(quadicon) soft_assert(not toolbar.exists("Power"), "Power displayed in template details!") @pytest.mark.uncollectif(lambda: appliance_is_downstream() and current_version() < "5.4") class TestPowerControlRESTAPI(object): @pytest.fixture(scope="function") def vm(self, rest_api, test_vm): result = rest_api.collections.vms.get(name=test_vm.name) assert result.name == test_vm.name return result def test_power_off(self, vm, verify_vm_running): assert "stop" in vm.action vm.action.stop() wait_for(lambda: vm.power_state == "off", num_sec=300, delay=5, fail_func=vm.reload) def test_power_on(self, vm, verify_vm_stopped): assert "start" in vm.action vm.action.start()