Exemplo n.º 1
0
def login_ui():
    """
    Login to OpenShift Console

    return:
        driver (Selenium WebDriver)

    """
    logger.info("Get URL of OCP console")
    console_url = run_cmd("oc get consoles.config.openshift.io cluster -o"
                          "jsonpath='{.status.consoleURL}'")
    logger.info("Get password of OCP console")
    password = get_kubeadmin_password()
    password = password.rstrip()

    ocp_version = get_ocp_version()
    login_loc = locators[ocp_version]["login"]

    browser = ocsci_config.UI_SELENIUM.get("browser_type")
    if browser == "chrome":
        logger.info("chrome browser")
        chrome_options = Options()

        ignore_ssl = ocsci_config.UI_SELENIUM.get("ignore_ssl")
        if ignore_ssl:
            chrome_options.add_argument("--ignore-ssl-errors=yes")
            chrome_options.add_argument("--ignore-certificate-errors")

        # headless browsers are web browsers without a GUI
        headless = ocsci_config.UI_SELENIUM.get("headless")
        if headless:
            chrome_options.add_argument("--headless")

        chrome_browser_type = ocsci_config.UI_SELENIUM.get("chrome_type")
        driver = webdriver.Chrome(
            ChromeDriverManager(chrome_type=chrome_browser_type).install(),
            chrome_options=chrome_options,
        )
    else:
        raise ValueError(f"Not Support on {browser}")

    wait = WebDriverWait(driver, 30)
    driver.maximize_window()
    driver.get(console_url)
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["username"][1], login_loc["username"][0])))
    element.send_keys("kubeadmin")
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["password"][1], login_loc["password"][0])))
    element.send_keys(password)
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["click_login"][1], login_loc["click_login"][0])))
    element.click()
    WebDriverWait(driver, 30).until(ec.title_is(login_loc["ocp_page"]))
    return driver
Exemplo n.º 2
0
 def deployment_with_ui(self):
     """
     This method will deploy OCS with openshift-console UI test.
     """
     # TODO: add support for other browsers
     logger.info("Deployment of OCS will be done by openshift-console")
     console_path = config.RUN['openshift_console_path']
     password_secret_yaml = os.path.join(
         console_path, constants.HTPASSWD_SECRET_YAML
     )
     patch_htpasswd_yaml = os.path.join(
         console_path, constants.HTPASSWD_PATCH_YAML
     )
     with open(patch_htpasswd_yaml) as fd_patch_htpasswd:
         content_patch_htpasswd_yaml = fd_patch_htpasswd.read()
     run_cmd(f"oc apply -f {password_secret_yaml}", cwd=console_path)
     run_cmd(
         f"oc patch oauths cluster --patch "
         f"\"{content_patch_htpasswd_yaml}\" --type=merge",
         cwd=console_path
     )
     bridge_base_address = run_cmd(
         "oc get consoles.config.openshift.io cluster -o"
         "jsonpath='{.status.consoleURL}'"
     )
     logger.info(f"Bridge base address: {bridge_base_address}")
     chrome_branch_base = config.RUN.get("force_chrome_branch_base")
     chrome_branch_sha = config.RUN.get("force_chrome_branch_sha256sum")
     live_deploy = '1' if config.DEPLOYMENT.get('live_deployment') else '0'
     openshift_console_env = {
         "BRIDGE_KUBEADMIN_PASSWORD": get_kubeadmin_password(),
         "BRIDGE_BASE_ADDRESS": bridge_base_address,
         "FORCE_CHROME_BRANCH_BASE": chrome_branch_base,
         "FORCE_CHROME_BRANCH_SHA256SUM": chrome_branch_sha,
         "OCS_LIVE": live_deploy,
     }
     openshift_console_env.update(os.environ)
     ui_deploy_output = run_cmd(
         "./test-gui.sh ceph-storage-install", cwd=console_path,
         env=openshift_console_env, timeout=1500,
     )
     ui_deploy_log_file = os.path.expanduser(
         os.path.join(config.RUN['log_dir'], "ui_deployment.log")
     )
     with open(ui_deploy_log_file, "w+") as log_fd:
         log_fd.write(ui_deploy_output)
Exemplo n.º 3
0
    def setup_console_prereq(self):
        """
        Setup openshift console prerequisites

        Raises:
            UnsupportedBrowser: in case the browser is not supported

        """
        # TODO: add support for other browsers
        if self.browser not in constants.SUPPORTED_BROWSERS:
            raise UnsupportedBrowser(
                f"Support for {self.browser} hasn't been implemented yet!")
        if self.browser == constants.CHROME_BROWSER:
            chrome_branch_base = config.RUN.get("force_chrome_branch_base")
            chrome_branch_sha = config.RUN.get("force_chrome_branch_sha256sum")
            self.env_vars["FORCE_CHROME_BRANCH_BASE"] = chrome_branch_base
            self.env_vars["FORCE_CHROME_BRANCH_SHA256SUM"] = chrome_branch_sha

        htpasswd_secret = OCP(kind="Secret",
                              resource_name=constants.HTPASSWD_SECRET_NAME)
        try:
            htpasswd_secret.get()
            logger.info(
                "Htpasswd secret is already set! Skipping secret setup")
        except CommandFailed:
            logger.info(
                "Setting up htpasswd secret file for openshift console")
            password_secret_yaml = os.path.join(self.console_path,
                                                constants.HTPASSWD_SECRET_YAML)
            patch_htpasswd_yaml = os.path.join(self.console_path,
                                               constants.HTPASSWD_PATCH_YAML)
            with open(patch_htpasswd_yaml) as fd_patch_htpasswd:
                content_patch_htpasswd_yaml = fd_patch_htpasswd.read()
            run_cmd(f"oc apply -f {password_secret_yaml}",
                    cwd=self.console_path)
            run_cmd(
                f"oc patch oauths cluster --patch "
                f"\"{content_patch_htpasswd_yaml}\" --type=merge",
                cwd=self.console_path)
        self.bridge_base_address = run_cmd(
            "oc get consoles.config.openshift.io cluster -o"
            "jsonpath='{.status.consoleURL}'")
        logger.info(f"Bridge base address: {self.bridge_base_address}")
        self.env_vars["BRIDGE_KUBEADMIN_PASSWORD"] = get_kubeadmin_password()
        self.env_vars["BRIDGE_BASE_ADDRESS"] = self.bridge_base_address
        self.env_vars.update(os.environ)
Exemplo n.º 4
0
def login_ui(console_url=None):
    """
    Login to OpenShift Console

    Args:
        console_url (str): ocp console url

    return:
        driver (Selenium WebDriver)

    """
    default_console = False
    if not console_url:
        console_url = get_ocp_url()
        default_console = True
    logger.info("Get password of OCP console")
    password = get_kubeadmin_password()
    password = password.rstrip()

    ocp_version = get_ocp_version()
    login_loc = locators[ocp_version]["login"]

    browser = ocsci_config.UI_SELENIUM.get("browser_type")
    if browser == "chrome":
        logger.info("chrome browser")
        chrome_options = Options()

        ignore_ssl = ocsci_config.UI_SELENIUM.get("ignore_ssl")
        if ignore_ssl:
            chrome_options.add_argument("--ignore-ssl-errors=yes")
            chrome_options.add_argument("--ignore-certificate-errors")
            chrome_options.add_argument("--allow-insecure-localhost")
            if config.ENV_DATA.get("import_clusters_to_acm"):
                # Dev shm should be disabled when sending big amonut characters, like the cert sections of a kubeconfig
                chrome_options.add_argument("--disable-dev-shm-usage")
            capabilities = chrome_options.to_capabilities()
            capabilities["acceptInsecureCerts"] = True

        # headless browsers are web browsers without a GUI
        headless = ocsci_config.UI_SELENIUM.get("headless")
        if headless:
            chrome_options.add_argument("--headless")
            chrome_options.add_argument("window-size=1920,1400")

        # use proxy server, if required
        if (
            config.DEPLOYMENT.get("proxy")
            or config.DEPLOYMENT.get("disconnected")
            or config.ENV_DATA.get("private_link")
        ) and config.ENV_DATA.get("client_http_proxy"):
            client_proxy = urlparse(config.ENV_DATA.get("client_http_proxy"))
            # there is a big difference between configuring not authenticated
            # and authenticated proxy server for Chrome:
            # * not authenticated proxy can be configured via --proxy-server
            #   command line parameter
            # * authenticated proxy have to be provided through customly
            #   created Extension and it doesn't work in headless mode!
            if not client_proxy.username:
                # not authenticated proxy
                logger.info(
                    f"Configuring not authenticated proxy ('{client_proxy.geturl()}') for browser"
                )
                chrome_options.add_argument(f"--proxy-server={client_proxy.geturl()}")
            elif not headless:
                # authenticated proxy, not headless mode
                # create Chrome extension with proxy settings
                logger.info(
                    f"Configuring authenticated proxy ('{client_proxy.geturl()}') for browser"
                )
                _templating = Templating()
                manifest_json = _templating.render_template(
                    constants.CHROME_PROXY_EXTENSION_MANIFEST_TEMPLATE, {}
                )
                background_js = _templating.render_template(
                    constants.CHROME_PROXY_EXTENSION_BACKGROUND_TEMPLATE,
                    {"proxy": client_proxy},
                )
                pluginfile = "/tmp/proxy_auth_plugin.zip"
                with zipfile.ZipFile(pluginfile, "w") as zp:
                    zp.writestr("manifest.json", manifest_json)
                    zp.writestr("background.js", background_js)
                chrome_options.add_extension(pluginfile)
            else:
                # authenticated proxy, headless mode
                logger.error(
                    "It is not possible to configure authenticated proxy "
                    f"('{client_proxy.geturl()}') for browser in headless mode"
                )
                raise NotSupportedProxyConfiguration(
                    "Unable to configure authenticated proxy in headless browser mode!"
                )

        chrome_browser_type = ocsci_config.UI_SELENIUM.get("chrome_type")
        driver = webdriver.Chrome(
            ChromeDriverManager(chrome_type=chrome_browser_type).install(),
            options=chrome_options,
        )
    else:
        raise ValueError(f"Not Support on {browser}")

    wait = WebDriverWait(driver, 60)
    driver.maximize_window()
    driver.implicitly_wait(10)
    driver.get(console_url)
    # Validate proceeding to the login console before taking any action:
    proceed_to_login_console(driver)
    if config.ENV_DATA.get("flexy_deployment") or config.ENV_DATA.get(
        "import_clusters_to_acm"
    ):
        try:
            element = wait.until(
                ec.element_to_be_clickable(
                    (
                        login_loc["kubeadmin_login_approval"][1],
                        login_loc["kubeadmin_login_approval"][0],
                    )
                )
            )
            element.click()
        except TimeoutException as e:
            take_screenshot(driver)
            copy_dom(driver)
            logger.error(e)
    element = wait.until(
        ec.element_to_be_clickable((login_loc["username"][1], login_loc["username"][0]))
    )
    take_screenshot(driver)
    copy_dom(driver)
    element.send_keys("kubeadmin")
    element = wait.until(
        ec.element_to_be_clickable((login_loc["password"][1], login_loc["password"][0]))
    )
    element.send_keys(password)
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["click_login"][1], login_loc["click_login"][0])
        )
    )
    element.click()
    if default_console:
        WebDriverWait(driver, 60).until(ec.title_is(login_loc["ocp_page"]))
    return driver
Exemplo n.º 5
0
    def setup_console_prereq(self):
        """
        Setup openshift console prerequisites

        Raises:
            UnsupportedBrowser: in case the browser is not supported

        """
        # TODO: add support for other browsers
        if self.browser not in constants.SUPPORTED_BROWSERS:
            raise UnsupportedBrowser(
                f"Support for {self.browser} hasn't been implemented yet!"
            )
        if self.browser == constants.CHROME_BROWSER:
            # Those values are deprected in latest version of openshift-console
            # but keeping them here for backward compatibility
            chrome_branch_base = config.RUN.get("force_chrome_branch_base")
            chrome_branch_sha = config.RUN.get("force_chrome_branch_sha256sum")
            self.env_vars["FORCE_CHROME_BRANCH_BASE"] = chrome_branch_base
            self.env_vars["FORCE_CHROME_BRANCH_SHA256SUM"] = chrome_branch_sha
            # End of the deprecated section

            chrome_path = config.RUN["chrome_binary_path"]
            self.env_vars["CHROME_BINARY_PATH"] = chrome_path
            chrome_version = run_cmd(f"{chrome_path} --version")
            logger.info(f"Chrome version is: {chrome_version}")
            self.env_vars["CHROME_VERSION"] = chrome_version

        htpasswd_secret = OCP(
            kind="Secret", resource_name=constants.HTPASSWD_SECRET_NAME
        )
        try:
            htpasswd_secret.get()
            logger.info("Htpasswd secret is already set! Skipping secret setup")
        except CommandFailed:
            logger.info("Setting up htpasswd secret file for openshift console")
            password_secret_yaml = os.path.join(
                self.console_path, constants.HTPASSWD_SECRET_YAML
            )
            patch_htpasswd_yaml = os.path.join(
                self.console_path, constants.HTPASSWD_PATCH_YAML
            )
            with open(patch_htpasswd_yaml) as fd_patch_htpasswd:
                content_patch_htpasswd_yaml = fd_patch_htpasswd.read()
            run_cmd(
                f"oc apply -f {password_secret_yaml}", cwd=self.console_path
            )
            run_cmd(
                f"oc patch oauths cluster --patch "
                f"\"{content_patch_htpasswd_yaml}\" --type=merge",
                cwd=self.console_path
            )
        self.bridge_base_address = run_cmd(
            "oc get consoles.config.openshift.io cluster -o"
            "jsonpath='{.status.consoleURL}'"
        )
        logger.info(f"Bridge base address: {self.bridge_base_address}")
        self.env_vars["BRIDGE_KUBEADMIN_PASSWORD"] = get_kubeadmin_password()
        self.env_vars["BRIDGE_BASE_ADDRESS"] = self.bridge_base_address
        no_failfast = config.RUN.get("openshift_console_no_failfast", False)
        if no_failfast:
            self.env_vars["NO_FAILFAST"] = "true"
        extra_env_vars = config.RUN.get("extra_openshift_console_env_vars", {})
        for key, value in extra_env_vars.items():
            self.env_vars[key] = value
        self.env_vars.update(os.environ)
Exemplo n.º 6
0
def login_ui():
    """
    Login to OpenShift Console

    return:
        driver (Selenium WebDriver)

    """
    logger.info("Get URL of OCP console")
    console_url = run_cmd("oc get consoles.config.openshift.io cluster -o"
                          "jsonpath='{.status.consoleURL}'")
    logger.info("Get password of OCP console")
    password = get_kubeadmin_password()
    password = password.rstrip()

    ocp_version = get_ocp_version()
    login_loc = locators[ocp_version]["login"]

    browser = ocsci_config.UI_SELENIUM.get("browser_type")
    if browser == "chrome":
        logger.info("chrome browser")
        chrome_options = Options()

        ignore_ssl = ocsci_config.UI_SELENIUM.get("ignore_ssl")
        if ignore_ssl:
            chrome_options.add_argument("--ignore-ssl-errors=yes")
            chrome_options.add_argument("--ignore-certificate-errors")
            chrome_options.add_argument("--allow-insecure-localhost")
            capabilities = chrome_options.to_capabilities()
            capabilities["acceptInsecureCerts"] = True

        # headless browsers are web browsers without a GUI
        headless = ocsci_config.UI_SELENIUM.get("headless")
        if headless:
            chrome_options.add_argument("--headless")
            chrome_options.add_argument("window-size=1920,1400")

        chrome_browser_type = ocsci_config.UI_SELENIUM.get("chrome_type")
        driver = webdriver.Chrome(
            ChromeDriverManager(chrome_type=chrome_browser_type).install(),
            options=chrome_options,
        )
    else:
        raise ValueError(f"Not Support on {browser}")

    wait = WebDriverWait(driver, 60)
    driver.maximize_window()
    driver.get(console_url)
    if config.ENV_DATA["flexy_deployment"]:
        try:
            element = wait.until(
                ec.element_to_be_clickable((login_loc["flexy_kubeadmin"][1],
                                            login_loc["flexy_kubeadmin"][0])))
            element.click()
        except TimeoutException as e:
            take_screenshot(driver)
            logger.error(e)
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["username"][1], login_loc["username"][0])))
    take_screenshot(driver)
    element.send_keys("kubeadmin")
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["password"][1], login_loc["password"][0])))
    element.send_keys(password)
    element = wait.until(
        ec.element_to_be_clickable(
            (login_loc["click_login"][1], login_loc["click_login"][0])))
    element.click()
    WebDriverWait(driver, 60).until(ec.title_is(login_loc["ocp_page"]))
    return driver