def setup_external_auth_openldap(**data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } current_appliance = get_or_create_current_appliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = current_appliance.hostname appliance_fqdn = '{}.{}'.format(appliance_name, data['domain_name']) with SSHClient(**connect_kwargs) as ldapserver_ssh: # updating the /etc/hosts is a workaround due to the # https://bugzilla.redhat.com/show_bug.cgi?id=1360928 command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ldapserver_ssh.run_command(command) ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ensure_browser_open() current_appliance.server.login_admin() current_appliance.server.authentication.set_auth_mode(mode='external', get_groups=data.pop( "get_groups", True)) current_appliance.configure_appliance_for_openldap_ext_auth(appliance_fqdn) current_appliance.server.logout()
def setup_external_auth_openldap(**data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } current_appliance = get_or_create_current_appliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = current_appliance.hostname appliance_fqdn = '{}.{}'.format(appliance_name, data['domain_name']) with SSHClient(**connect_kwargs) as ldapserver_ssh: # updating the /etc/hosts is a workaround due to the # https://bugzilla.redhat.com/show_bug.cgi?id=1360928 command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ldapserver_ssh.run_command(command) ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ensure_browser_open() current_appliance.server.login_admin() current_appliance.server.authentication.set_auth_mode( mode='external', get_groups=data.pop("get_groups", True) ) current_appliance.configure_appliance_for_openldap_ext_auth(appliance_fqdn) current_appliance.server.logout()
def step(self): # Can be either blank or logged in del self.view # In order to unbind the browser quit() ensure_browser_open(self.obj.appliance.server.address()) if not self.view.is_displayed: raise Exception('Could not open the login screen')
def needs_firefox(): """ Fixture which skips the test if not run under firefox. I recommend putting it in the first place. """ ensure_browser_open() if browser.browser().name != "firefox": pytest.skip(msg="This test needs firefox to run")
def disable_external_auth_ipa(): """Unconfigure external auth.""" current_appliance = get_or_create_current_appliance() with current_appliance.ssh_client as ssh: ensure_browser_open() current_appliance.server.login_admin() current_appliance.server.authentication.set_auth_mode() assert ssh.run_command("appliance_console_cli --uninstall-ipa") current_appliance.wait_for_web_ui() current_appliance.server.logout()
def setup_external_auth_ipa(**data): """Sets up the appliance for an external authentication with IPA. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaserver'], } current_appliance = get_or_create_current_appliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = current_appliance.address appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower()) with SSHClient(**connect_kwargs) as ipaserver_ssh: ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak') ipaserver_ssh.run_command( "sed -i -r '/^{}/d' /etc/hosts".format(appliance_address)) command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ipaserver_ssh.run_command(command) with current_appliance.ssh_client as ssh: result = ssh.run_command( 'appliance_console_cli --host {}'.format(appliance_fqdn)).success if not current_appliance.is_pod: assert result else: # appliance_console_cli fails when calls hostnamectl --host. it seems docker issue # raise BZ ? assert str(ssh.run_command('hostname')).rstrip() == appliance_fqdn ensure_browser_open() current_appliance.server.login_admin() if data["ipaserver"] not in ( current_appliance.server.settings.ntp_servers_form.values()): current_appliance.server.settings.update_ntp_servers( {'ntp_server_1': data["ipaserver"]}) sleep(120) appliance.server.authentication.set_auth_mode(mode='external', get_groups=data.pop( "get_groups", False)) creds = credentials.get(data.pop("credentials"), {}) data.update(**creds) assert ssh.run_command( "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} " "--ipaprincipal {principal} --ipapassword {password}".format( **data)) current_appliance.server.login_admin()
def step(self): # Can be either blank or logged in from cfme.utils import browser logged_in_view = self.create_view(BaseLoggedInPage) if logged_in_view.logged_in: logged_in_view.logout() if not self.view.is_displayed: # Something is wrong del self.view # In order to unbind the browser browser.quit() browser.ensure_browser_open(self.obj.appliance.server.address()) if not self.view.is_displayed: raise Exception('Could not open the login screen')
def really_logout(): """A convenience function logging out This function simply ensures that we are logged out and that a new browser is loaded ready for use. """ try: current_appliance.server.logout() except AttributeError: try: browser().quit() except AttributeError: ensure_browser_open()
def setup_external_auth_ipa(**data): """Sets up the appliance for an external authentication with IPA. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaserver'], } current_appliance = get_or_create_current_appliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = current_appliance.hostname appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower()) with SSHClient(**connect_kwargs) as ipaserver_ssh: ipaserver_ssh.run_command('cp /etc/hosts /etc/hosts_bak') ipaserver_ssh.run_command("sed -i -r '/^{}/d' /etc/hosts".format(appliance_address)) command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ipaserver_ssh.run_command(command) with current_appliance.ssh_client as ssh: result = ssh.run_command('appliance_console_cli --host {}'.format(appliance_fqdn)).success if not current_appliance.is_pod: assert result else: # appliance_console_cli fails when calls hostnamectl --host. it seems docker issue # raise BZ ? assert str(ssh.run_command('hostname')).rstrip() == appliance_fqdn ensure_browser_open() current_appliance.server.login_admin() if data["ipaserver"] not in ( current_appliance.server.settings.ntp_servers_values): current_appliance.server.settings.update_ntp_servers( {'ntp_server_1': data["ipaserver"]}) sleep(120) current_appliance.server.authentication.set_auth_mode( mode='external', get_groups=data.pop("get_groups", False) ) creds = credentials.get(data.pop("credentials"), {}) data.update(**creds) assert ssh.run_command( "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} " "--ipaprincipal {principal} --ipapassword {password}".format(**data) ) current_appliance.server.login_admin()
def wait_until(f, msg="Webdriver wait timed out", timeout=120.0): """This used to be a wrapper around WebDriverWait from selenium. Now it is just compatibility layer using :py:func:`utils.wait.wait_for` """ return wait_for(lambda: f(ensure_browser_open()), num_sec=timeout, message=msg, delay=0.5)
def setup_external_auth_openldap(appliance, **data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } with SSHClient(**connect_kwargs) as ldapserver_ssh: ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ensure_browser_open() appliance.server.login_admin() appliance.server.authentication.configure_auth( auth_mode='external', get_groups=data.pop("get_groups", True) ) appliance.configure_openldap() appliance.server.logout()
def setup_external_auth_openldap(appliance, **data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } with SSHClient(**connect_kwargs) as ldapserver_ssh: ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ensure_browser_open() appliance.server.login_admin() appliance.server.authentication.configure_auth(auth_mode='external', get_groups=data.pop( "get_groups", True)) appliance.configure_openldap() appliance.server.logout()
def _t(t, root=None): """Assume tuple is a 2-item tuple like (By.ID, 'myid'). Handles the case when root= locator resolves to multiple elements. In that case all of them are processed and all results are put in the same list.""" result = [] for root_element in (elements(root) if root is not None else [ensure_browser_open()]): # 20140920 - dajo - hack to get around selenium e is null bs count = 0 while count < 8: count += 1 try: result += root_element.find_elements(*t) break except Exception as e: logger.info('Exception detected: %s', str(e)) sleep(0.25) if count == 8: result += root_element.find_elements(*t) # Monkey patch them for elem in result: elem._source_locator = (t, root) return result
def prerequisite(self): ensure_browser_open(self.obj.appliance.server.address())
def reload(self): ensure_browser_open() self._object.load_topology_page() self._reload()
def _finalize(): quit() ensure_browser_open() auth_settings.set_session_timeout(hours="24", minutes="0")
def pytest_runtest_teardown(item, nextitem): if item.config.getoption('sauce'): from cfme.utils.browser import ensure_browser_open, quit, browser ensure_browser_open() browser().execute_script(f"sauce:job-name={item.name}") quit()
def refresh(self): ensure_browser_open() sel.click("//button[contains(., 'Refresh')]") self._reload()
def _on_detail_page(self): """ Returns ``True`` if on the providers detail page, ``False`` if not.""" ensure_browser_open() return sel.is_displayed( '//div//h1[contains(., "{} (Summary)")]'.format(self.name))
def prerequisite(self): from cfme.utils.browser import ensure_browser_open ensure_browser_open(self.obj.appliance.server.address())
def pytest_runtest_teardown(item, nextitem): if item.config.getoption('sauce'): from cfme.utils.browser import ensure_browser_open, quit, browser ensure_browser_open() browser().execute_script("sauce:job-name={}".format(item.name)) quit()
def load_utilization_page(self, refresh=True): ensure_browser_open() self._object.load_details(refresh=refresh) mon_btn("Utilization")