def test_multiple_host_bad_creds(setup_provider, provider): """ Tests multiple host credentialing with bad credentials """ details_view = navigate_to(provider, 'Details') details_view.contents.relationships.click_at('Hosts') quads = Quadicon.all("host", this_page=True) for quad in quads: sel.check(quad.checkbox()) tb.select("Configuration", config_option()) cfme_host = random.choice(provider.data["hosts"]) creds = conf.credentials['bad_credentials'] fill( credential_form, { 'default_principal': creds['username'], 'default_secret': creds['password'], 'default_verify_secret': creds['password'], 'validate_host': cfme_host["name"] }) sel.click(credential_form.validate_multi_host) flash.assert_message_match( 'Cannot complete login due to an incorrect user name or password.') sel.click(credential_form.cancel_changes)
def test_multiple_host_good_creds(setup_provider, provider): """ Tests multiple host credentialing with good credentials """ details_view = navigate_to(provider, 'Details') details_view.contents.relationships.click_at('Hosts') quads = Quadicon.all("host", this_page=True) for quad in quads: sel.check(quad.checkbox()) tb.select("Configuration", config_option()) cfme_host = random.choice(provider.data["hosts"]) cred = cfme_host['credentials'] creds = conf.credentials[cred] fill( credential_form, { 'default_principal': creds['username'], 'default_secret': creds['password'], 'default_verify_secret': creds['password'], 'validate_host': cfme_host["name"] }) sel.click(credential_form.validate_multi_host) flash.assert_message_match('Credential validation was successful') sel.click(credential_form.save_btn) flash.assert_message_match('Credentials/Settings saved successfully')
def test_providers_discovery_amazon(): # This test was being uncollected anyway, and needs to be parametrized and not directory call # out to specific credential keys # amazon_creds = get_credentials_from_config('cloudqe_amazon') # discover(amazon_creds, d_type="Amazon") flash.assert_message_match('Amazon Cloud Providers: Discovery successfully initiated') wait_for_a_provider()
def test_delete_dialog_before_parent_item(catalog_item): service_dialog = ServiceDialog(label=catalog_item.dialog) service_dialog.delete() flash.assert_message_match( ("Dialog \"{}\": Error during 'destroy': Dialog cannot be deleted " + "because it is connected to other components.").format( catalog_item.dialog))
def update(self, updates, cancel=False, validate_credentials=False): """Updates the manager through UI args: updates (dict): Data to change. cancel (bool): Whether to cancel out of the update. The cancel is done after all the new information has been filled in the UI. validate_credentials (bool): Whether to validate credentials - if True and the credentials are invalid, an error will be raised. Note: utils.update use is recommended over use of this method. """ navigate_to(self, 'Edit') # Workaround - without this, update was failing on downstream appliance sel.wait_for_ajax() sel.wait_for_element(properties_form.name_text) fill(properties_form, self._form_mapping(**updates)) fill(credential_form, updates.get('credentials', None), validate=validate_credentials) self._submit(cancel, edit_manager_btn) name = updates['name'] or self.name if not cancel: flash.assert_message_match('{} Provider "{}" was updated'.format(self.type, name)) self.__dict__.update(**updates)
def test_no_template_catalog_item(provider, provisioning, vm_name, dialog, catalog): """Tests no template catalog item Metadata: test_flag: provision """ template, catalog_item_type = map(provisioning.get, ('template', 'catalog_item_type')) if provider.type == 'rhevm': catalog_item_type = version.pick({ version.LATEST: "RHEV", '5.3': "RHEV", '5.2': "Redhat" }) item_name = fauxfactory.gen_alphanumeric() catalog_item = CatalogItem(item_type=catalog_item_type, name=item_name, description="my catalog", display_in=True, catalog=catalog, dialog=dialog) catalog_item.create() flash.assert_message_match( version.pick({ version.LOWEST: "'Catalog/Name' is required", "5.4": "Source_id must have valid template" }))
def test_charge_report_filter_owner(setup_first_provider, request): """Tests creation of chargeback report that is filtered by owner """ report = CustomReport( menu_name=fauxfactory.gen_alphanumeric(), title=fauxfactory.gen_alphanumeric(), base_report_on="Chargebacks", report_fields=[ "Network I/O Used", "Network I/O Used Cost", "Storage Used", "Storage Used Cost", "Disk I/O Used", "Disk I/O Used Cost", "Owner", "Total Cost", ], filter_show_costs="Owner", filter_owner="Administrator", ) report.create() def cleanup_report(report): return lambda: _cleanup_report(report) request.addfinalizer(cleanup_report(report)) flash.assert_message_match('Report "{}" was added'.format(report.menu_name)) report.queue(wait_for_finish=True)
def test_multiple_host_bad_creds(setup_provider, provider, hosts, host_list): """ Tests multiple host credentialing with bad credentials """ sel.force_navigate('infrastructure_provider', context={'provider': provider}) sel.click(details_page.infoblock.element("Relationships", "Hosts")) quads = Quadicon.all("host", this_page=True) for quad in quads: sel.check(quad.checkbox()) tb.select("Configuration", config_option()) cfme_host = random.choice(provider.get_yaml_data()["hosts"]) creds = conf.credentials['bad_credentials'] fill( credential_form, { 'default_principal': creds['username'], 'default_secret': creds['password'], 'default_verify_secret': creds['password'], 'validate_host': cfme_host["name"] }) sel.click(credential_form.validate_multi_host) flash.assert_message_match( 'Cannot complete login due to an incorrect user name or password.') sel.click(credential_form.cancel_changes)
def test_multiple_host_good_creds(setup_provider, provider, hosts, host_list): """ Tests multiple host credentialing with good credentials """ sel.force_navigate('infrastructure_provider', context={'provider': provider}) sel.click(details_page.infoblock.element("Relationships", "Hosts")) quads = Quadicon.all("host", this_page=True) for quad in quads: sel.check(quad.checkbox()) tb.select("Configuration", config_option()) cfme_host = random.choice(provider.get_yaml_data()["hosts"]) cred = cfme_host['credentials'] creds = conf.credentials[cred] fill( credential_form, { 'default_principal': creds['username'], 'default_secret': creds['password'], 'default_verify_secret': creds['password'], 'validate_host': cfme_host["name"] }) sel.click(credential_form.validate_multi_host) flash.assert_message_match('Credential validation was successful') sel.click(credential_form.save_btn) flash.assert_message_match('Credentials/Settings saved successfully')
def test_charge_report_filter_tag(setup_first_provider, request): """Tests creation of chargeback report that is filtered by tag """ report = CustomReport( menu_name=fauxfactory.gen_alphanumeric(), title=fauxfactory.gen_alphanumeric(), base_report_on="Chargebacks", report_fields=[ "CPU Used", "CPU Used Cost", "Memory Used", "Memory Used Cost", "Owner", "vCPUs Allocated Cost", "Total Cost", ], filter_show_costs="My Company Tag", filter_tag_cat="Location", filter_tag_value="Chicago", ) report.create() def cleanup_report(report): return lambda: _cleanup_report(report) request.addfinalizer(cleanup_report(report)) flash.assert_message_match('Report "{}" was added'.format( report.menu_name)) report.queue(wait_for_finish=True)
def delete(self, cancel=False, wait_deleted=True, force=False): """Deletes the manager through UI Args: cancel (bool): Whether to cancel out of the deletion, when the alert pops up. wait_deleted (bool): Whether we want to wait for the manager to disappear from the UI. True will wait; False will only delete it and move on. force (bool): Whether to try to delete the manager even though it doesn't exist. True will try to delete it anyway; False will check for its existence and leave, if not present. """ if not force and not self.exists: return navigate_to(self, 'All') sel.check(Quadicon(self.quad_name, None).checkbox()) item_text = version.pick({'5.6': 'Remove selected items from the VMDB', '5.7': 'Remove selected items'}) cfg_btn(item_text, invokes_alert=True) sel.handle_alert(cancel) if not cancel: flash_msg = version.pick({'5.6': 'Delete initiated for 1 provider', '5.7': 'Delete initiated for 1 Provider'}) flash.assert_message_match(flash_msg) if wait_deleted: wait_for(func=lambda: self.exists, fail_condition=True, delay=15, num_sec=60)
def revert_to(self, cancel=False): self._nav_to_snapshot_mgmt() self.snapshot_tree.click_path(*self.snapshot_tree.find_path_to(re.compile(self.name))) toolbar.select('Revert to selected snapshot', invokes_alert=True) sel.handle_alert(cancel=cancel) flash.assert_message_match('Revert To Snapshot initiated for 1 VM and Instance from ' 'the CFME Database')
def test_charge_report_filter_tag(setup_first_provider, request): """Tests creation of chargeback report that is filtered by tag """ report = CustomReport( menu_name=fauxfactory.gen_alphanumeric(), title=fauxfactory.gen_alphanumeric(), base_report_on="Chargebacks", report_fields=[ "CPU Used", "CPU Used Cost", "Memory Used", "Memory Used Cost", "Owner", "vCPUs Allocated Cost", "Total Cost", ], filter_show_costs="My Company Tag", filter_tag_cat="Location", filter_tag_value="Chicago", ) report.create() def cleanup_report(report): return lambda: _cleanup_report(report) request.addfinalizer(cleanup_report(report)) flash.assert_message_match('Report "{}" was added'.format(report.menu_name)) report.queue(wait_for_finish=True)
def test_password_mismatch_validation(): cred = Credential(principal=fauxfactory.gen_alphanumeric(5), secret=fauxfactory.gen_alphanumeric(5), verify_secret=fauxfactory.gen_alphanumeric(7)) discover(cred, d_type="Amazon") flash.assert_message_match('Password/Verify Password do not match')
def delete(self, cancel=False, wait_deleted=True, force=False): """Deletes the manager through UI Args: cancel (bool): Whether to cancel out of the deletion, when the alert pops up. wait_deleted (bool): Whether we want to wait for the manager to disappear from the UI. True will wait; False will only delete it and move on. force (bool): Whether to try to delete the manager even though it doesn't exist. True will try to delete it anyway; False will check for its existence and leave, if not present. """ if not force and not self.exists: return navigate_to(self, 'All') sel.check(Quadicon(self.quad_name, None).checkbox()) item_text = version.pick({ '5.6': 'Remove selected items from the VMDB', '5.7': 'Remove selected items' }) cfg_btn(item_text, invokes_alert=True) sel.handle_alert(cancel) if not cancel: flash_msg = version.pick({ '5.6': 'Delete initiated for 1 provider', '5.7': 'Delete initiated for 1 Provider' }) flash.assert_message_match(flash_msg) if wait_deleted: wait_for(func=lambda: self.exists, fail_condition=True, delay=15, num_sec=60)
def update(self, updates, cancel=False, validate_credentials=False): """Updates the manager through UI args: updates (dict): Data to change. cancel (bool): Whether to cancel out of the update. The cancel is done after all the new information has been filled in the UI. validate_credentials (bool): Whether to validate credentials - if True and the credentials are invalid, an error will be raised. Note: utils.update use is recommended over use of this method. """ navigate_to(self, 'Edit') # Workaround - without this, update was failing on downstream appliance sel.wait_for_ajax() sel.wait_for_element(properties_form.name_text) fill(properties_form, self._form_mapping(**updates)) fill(credential_form, updates.get('credentials', None), validate=validate_credentials) self._submit(cancel, edit_manager_btn) name = updates['name'] or self.name if not cancel: flash.assert_message_match('{} Provider "{}" was updated'.format( self.type, name)) self.__dict__.update(**updates)
def test_discovery_cancelled_validation(): """ Tests that the flash message is correct when discovery is cancelled.""" discover(None, cancel=True, d_type="Amazon") msg = version.pick( {version.LOWEST: 'Amazon Cloud Providers Discovery was cancelled by the user', '5.5': 'Cloud Providers Discovery was cancelled by the user'}) flash.assert_message_match(msg)
def delete_all(self, cancel=False): self._nav_to_snapshot_mgmt() toolbar.select('Delete Snapshots', 'Delete All Existing Snapshots', invokes_alert=True) sel.handle_alert(cancel=cancel) if not cancel: flash.assert_message_match('Remove All Snapshots initiated for 1 VM and ' 'Instance from the CFME Database')
def test_charge_report_filter_owner(setup_first_provider, request): """Tests creation of chargeback report that is filtered by owner """ report = CustomReport( menu_name=fauxfactory.gen_alphanumeric(), title=fauxfactory.gen_alphanumeric(), base_report_on="Chargebacks", report_fields=[ "Network I/O Used", "Network I/O Used Cost", "Storage Used", "Storage Used Cost", "Disk I/O Used", "Disk I/O Used Cost", "Owner", "Total Cost", ], filter_show_costs="Owner", filter_owner="Administrator", ) report.create() def cleanup_report(report): return lambda: _cleanup_report(report) request.addfinalizer(cleanup_report(report)) flash.assert_message_match('Report "{}" was added'.format( report.menu_name)) report.queue(wait_for_finish=True)
def test_add_cancelled_validation(request): """Tests that the flash message is correct when add is cancelled.""" prov = EC2Provider() request.addfinalizer(prov.delete_if_exists) prov.create(cancel=True) flash.assert_message_match( 'Add of new Cloud Provider was cancelled by the user')
def test_edit_default_group(): flash_msg = 'Read Only EVM Group "{}" can not be edited' group = Group(description="EvmGroup-approver") navigate_to(Group, "All") row = group_table.find_row_by_cells({"Name": group.description}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select("Configuration", "Edit the selected Group") flash.assert_message_match(flash_msg.format(group.description))
def delete(self, cancel=False): sel.force_navigate("automate_explorer_tree_path", context={"tree_item": self}) cfg_btn("Remove this Domain", invokes_alert=True) sel.handle_alert(cancel) flash.assert_message_match( 'Automate Domain "{}": Delete successful'.format(self.description or self.name))
def test_edit_default_analysis_profile(): """ Test to validate edit default profiles.""" p = HostAnalysisProfile("host sample", None, None) sel.force_navigate("cfg_analysis_profiles") row = records_table.find_row_by_cells({"Name": p.name}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select("Configuration", "Edit the selected Analysis Profiles") flash.assert_message_match('Sample Analysis Profile "{}" can not be edited'.format(p.name))
def test_password_mismatch_validation(): cred = Credential( principal=generate_random_string(size=5), secret=generate_random_string(size=5), verify_secret=generate_random_string(size=7)) provider.discover(cred) flash.assert_message_match('Password/Verify Password do not match')
def test_edit_default_analysis_profile(): """ Test to validate edit default profiles.""" p = AnalysisProfile(name="host sample", description=None, profile_type='Host') navigate_to(p, 'All') row = records_table.find_row_by_cells({'Name': p.name}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select('Configuration', 'Edit the selected Analysis Profiles') flash.assert_message_match('Sample Analysis Profile "{}" can not be edited' .format(p.name))
def refresh_relationships(self, cancel=False): """Refreshes relationships and power states of this manager""" sel.force_navigate('infrastructure_config_manager_refresh', context={'manager': self}) sel.handle_alert(cancel) if not cancel: flash.assert_message_match( 'Refresh {0} initiated for 1 Provider ({0}) from the CFME Database' .format(self.type))
def test_providers_discovery_amazon(): raise pytest.skip( 'discovery and teardown is not parallel; this routinely times out') amazon_creds = provider.get_credentials_from_config('cloudqe_amazon') provider.discover(amazon_creds) flash.assert_message_match( 'Amazon Cloud Providers: Discovery successfully initiated') provider.wait_for_a_provider()
def test_edit_default_analysis_profile(): """ Test to validate edit default profiles.""" p = HostAnalysisProfile("host sample", None, None) sel.force_navigate("cfg_analysis_profiles") row = records_table.find_row_by_cells({'Name': p.name}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select('Configuration', 'Edit the selected Analysis Profiles') flash.assert_message_match('Sample Analysis Profile "{}" can not be edited' .format(p.name))
def test_edit_default_group(): flash_msg = 'Read Only EVM Group "{}" can not be edited' group = ac.Group(description='EvmGroup-approver') sel.force_navigate("cfg_accesscontrol_groups") row = group_table.find_row_by_cells({'Name': group.description}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select('Configuration', 'Edit the selected Group') flash.assert_message_match(flash_msg.format(group.description))
def test_add_cancelled_validation(request): """Tests that the flash message is correct when add is cancelled.""" prov = EC2Provider() request.addfinalizer(prov.delete_if_exists) prov.create(cancel=True) flash.assert_message_match({ version.LOWEST: 'Add of new Cloud Provider was cancelled by the user', '5.5': 'Add of Cloud Provider was cancelled by the user'})
def test_password_mismatch_validation(): cred = Credential( principal=fauxfactory.gen_alphanumeric(5), secret=fauxfactory.gen_alphanumeric(5), verify_secret=fauxfactory.gen_alphanumeric(7)) discover(cred, d_type="Amazon") flash.assert_message_match('Password/Verify Password do not match')
def generate(self, wait=True, **kwargs): navigate_to(self, 'Details') toolbar.select("Configuration", "Generate Widget content now", invokes_alert=True) sel.handle_alert() flash.assert_message_match("Content generation for this Widget has been initiated") flash.assert_no_errors() if wait: self.wait_generated(**kwargs)
def test_zone_add_cancel_validation(): zone = conf.Zone(name=fauxfactory.gen_alphanumeric(5), description=fauxfactory.gen_alphanumeric(8)) zone.create(cancel=True) if version.current_version() >= 5.6: msg = 'Add of new Zone was cancelled by the user' else: msg = 'Add of new Miq Zone was cancelled by the user' flash.assert_message_match(msg)
def test_edit_storage_chargeback(): scb = new_storage_rate() scb.create() with update(scb): scb.description = scb.description + "-edited" scb.storage_fixed_2 = (2000, cb.MONTHLY) scb.storage_alloc = (3000, cb.WEEKLY) scb.storage_used = (6000, cb.MONTHLY) flash.assert_message_match('Chargeback Rate "%s" was saved' % scb.description)
def test_delete_default_group(): flash_msg = "EVM Group \"{}\": Error during 'destroy': A read only group cannot be deleted." group = ac.Group(description="EvmGroup-administrator") sel.force_navigate("cfg_accesscontrol_groups") row = group_table.find_row_by_cells({"Name": group.description}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select("Configuration", "Delete selected Groups", invokes_alert=True) sel.handle_alert() flash.assert_message_match(flash_msg.format(group.description))
def revert_to(self, cancel=False): self._nav_to_snapshot_mgmt() self._click_tree_path(self.name or self.description) toolbar.select('Revert to selected snapshot', invokes_alert=True) sel.handle_alert(cancel=cancel) flash.assert_message_match('Revert To Snapshot initiated for 1 VM and Instance from ' 'the CFME Database')
def test_add_cancelled_validation(): """Tests that the flash message is correct when add is cancelled.""" prov = VMwareProvider() prov.create(cancel=True) if version.current_version() >= 5.6: msg = 'Add of Infrastructure Provider was cancelled by the user' else: msg = 'Add of new Infrastructure Provider was cancelled by the user' flash.assert_message_match(msg)
def create(self, cancel=False): """Create new keypair""" sel.force_navigate('clouds_key_pairs', context={'keypairs': self.name}) cfg_btn('Add a new Key Pair') fill(keypair_form, {'name': self.name}, action=keypair_form.save_button) if not cancel: flash.assert_message_match('Creating Key Pair {}'.format(self.name)) else: flash.assert_message_match('Add of new Key Pair was cancelled by the user')
def test_delete_default_analysis_profile(): """ Test to validate delete default profiles.""" p = HostAnalysisProfile("host sample", None, None) sel.force_navigate("cfg_analysis_profiles") row = records_table.find_row_by_cells({"Name": p.name}) sel.check(sel.element(".//input[@type='checkbox']", root=row[0])) tb.select("Configuration", "Delete the selected Analysis Profiles from the VMDB", invokes_alert=True) sel.handle_alert() flash.assert_message_match('Default Analysis Profile "{}" can not be deleted'.format(p.name))
def refresh_relationships(self, cancel=False): """Refreshes relationships and power states of this manager""" navigate_to(self, 'All') sel.check(Quadicon(self.quad_name, None).checkbox()) cfg_btn('Refresh Relationships and Power states', invokes_alert=True) sel.handle_alert(cancel) if not cancel: flash.assert_message_match(self._refresh_flash_msg)
def register_appliances(*appliance_names): """ Register appliances by names Args: appliance_names: Names of appliances to register; will register all if empty """ select_appliances(*appliance_names) sel.click(update_buttons.register) flash.assert_message_match("Registration has been initiated for the selected Servers") flash.dismiss()
def update_appliances(*appliance_names): """ Update appliances by names Args: appliance_names: Names of appliances to update; will update all if empty """ select_appliances(*appliance_names) sel.click(update_buttons.apply_updates) flash.assert_message_match("Update has been initiated for the selected Servers") flash.dismiss()
def check_updates(*appliance_names): """ Run update check on appliances by names Args: appliance_names: Names of appliances to check; will check all if empty """ select_appliances(*appliance_names) sel.click(update_buttons.check_updates) flash.assert_message_match("Check for updates has been initiated for the selected Servers") flash.dismiss()
def test_assign_storage_enterprise(provider): enterprise = cb.Assign(assign_to="The Enterprise", selections={"Enterprise": "Default"}) enterprise.storageassign() flash.assert_message_match("Rate Assignments saved") assert ( sel.text(cb.assign_form.selections.select_by_name("Enterprise").first_selected_option) == "Default", "Selection does not match", )
def revert_to(self, cancel=False): self._nav_to_snapshot_mgmt() title = self.description if self.vm.provider.one_of(RHEVMProvider) else self.name self._click_tree_path(title) toolbar.select('Revert to selected snapshot', invokes_alert=True) sel.handle_alert(cancel=cancel) flash.assert_message_match('Revert To Snapshot initiated for 1 VM and Instance from ' 'the CFME Database')
def revert_to(self, cancel=False): self._nav_to_snapshot_mgmt() self._click_tree_path(self.name or self.description) toolbar.select('Revert to selected snapshot', invokes_alert=True) sel.handle_alert(cancel=cancel) flash.assert_message_match( 'Revert To Snapshot initiated for 1 VM and Instance from ' 'the CFME Database')
def test_delete_dialog_before_parent_item(catalog_item): service_dialog = ServiceDialog(label=catalog_item.dialog) service_dialog.delete() message = version.pick({'5.6': (("Dialog \"{}\": Error during delete: Dialog cannot be " + "deleted because it is connected to other components."). format(catalog_item.dialog)), '5.5': (("Dialog \"{}\": Error during 'destroy': Dialog cannot be " + "deleted because it is connected to other components."). format(catalog_item.dialog))}) flash.assert_message_match(message)
def test_providers_discovery(request, provider): """Tests provider discovery Metadata: test_flag: crud """ provider.discover() flash.assert_message_match('Infrastructure Providers: Discovery successfully initiated') request.addfinalizer(lambda: BaseProvider.clear_provider_by_type(InfraProvider)) wait_for_a_provider()
def test_assign_compute_enterprise(provider): enterprise = cb.Assign(assign_to="The Enterprise", selections={"Enterprise": "Default"}) enterprise.computeassign() flash.assert_message_match("Rate Assignments saved") # Assert that the selection made is listed on the UI assert ( sel.text(cb.assign_form.selections.select_by_name("Enterprise").first_selected_option) == "Default", "Selection does not match", )