Exemplo n.º 1
0
 def processed_browser_args(self):
     command_executor = self.wharf.config["webdriver_url"]
     view_msg = "tests can be viewed via vnc on display {}".format(self.wharf.config["vnc_display"])
     log.info("webdriver command executor set to %s", command_executor)
     log.info(view_msg)
     write_line(view_msg, cyan=True)
     return dict(super(WharfFactory, self).processed_browser_args(), command_executor=command_executor)
Exemplo n.º 2
0
def pytest_configure():
    if store.parallelizer_role == 'master' or 'url' not in trackerbot.conf:
        return

    write_line("Loading templates from trackerbot")
    provider_templates = trackerbot.provider_templates(trackerbot.api())
    for provider in filtered.providers:
        TEMPLATES[provider] = provider_templates.get(provider, [])
Exemplo n.º 3
0
def pytest_unconfigure():
    global proc
    yield
    if not SLAVEID:
        write_line('collecting artifacts')
        art_client.fire_hook('finish_session')
    art_client.fire_hook('teardown_merkyl', ip=appliance_ip_address)
    if not SLAVEID:
        art_client.fire_hook('terminate')
Exemplo n.º 4
0
def pytest_unconfigure():
    global proc
    yield
    if not SLAVEID:
        write_line('collecting artifacts')
        art_client.fire_hook('finish_session')
    art_client.fire_hook('teardown_merkyl', ip=appliance_ip_address)
    if not SLAVEID:
        art_client.terminate()
        if proc:
            proc.wait()
Exemplo n.º 5
0
 def processed_browser_args(self):
     command_executor = self.wharf.config['webdriver_url']
     view_msg = 'tests can be viewed via vnc on display {}'.format(
         self.wharf.config['vnc_display'])
     log.info('webdriver command executor set to %s', command_executor)
     log.info(view_msg)
     write_line(view_msg, cyan=True)
     return dict(
         super(WharfFactory, self).processed_browser_args(),
         command_executor=command_executor,
     )
Exemplo n.º 6
0
 def inner():
     try:
         self.wharf.checkout()
         return super(WharfFactory, self).create(url_key)
     except urllib2.URLError as ex:
         # connection to selenum was refused for unknown reasons
         log.error('URLError connecting to selenium; recycling container. URLError:')
         write_line('URLError caused container recycle, see log for details', red=True)
         log.exception(ex)
         self.wharf.checkin()
         raise
Exemplo n.º 7
0
 def inner():
     try:
         self.wharf.checkout()
         return super(WharfFactory, self).create(url_key)
     except urllib2.URLError as ex:
         # connection to selenum was refused for unknown reasons
         log.error('URLError connecting to selenium; recycling container. URLError:')
         write_line('URLError caused container recycle, see log for details', red=True)
         log.exception(ex)
         self.wharf.checkin()
         raise
Exemplo n.º 8
0
def pytest_configure(config):
    if store.parallelizer_role == 'master' or trackerbot.conf.get('url') is None:
        return

    # A further optimization here is to make the calls to trackerbot per provider
    # and perhaps only pull the providers that are needed, however that will need
    # to ensure that the tests that just randomly use providers adhere to the filters
    # which may be too tricky right now.

    count = 0

    if not config.getoption('use_template_cache'):
        write_line("Loading templates from trackerbot...")
        provider_templates = trackerbot.provider_templates(trackerbot.api())
        for provider in list_provider_keys():
            TEMPLATES[provider] = provider_templates.get(provider, [])
            config.cache.set('miq-trackerbot/{}'.format(provider), TEMPLATES[provider])
            count += len(TEMPLATES[provider])
    else:
        write_line("Using templates from cache...")
        provider_templates = None
        for provider in list_provider_keys():
            templates = config.cache.get('miq-trackerbot/{}'.format(provider), None)
            if templates is None:
                write_line("Loading templates for {} from source as not in cache".format(provider))
                if not provider_templates:
                    provider_templates = trackerbot.provider_templates(trackerbot.api())
                templates = provider_templates.get(provider, [])
                config.cache.set('miq-trackerbot/{}'.format(provider), templates)
            count += len(templates)
            TEMPLATES[provider] = templates
    write_line("  Loaded {} templates successfully!".format(count))
Exemplo n.º 9
0
def shutdown(config):
    with lock:
        proc = config._art_proc
        if proc:
            if not store.slave_manager:
                write_line('collecting artifacts')
                fire_art_hook(config, 'finish_session')
            fire_art_hook(config, 'teardown_merkyl',
                          ip=get_or_create_current_appliance().address)
            if not store.slave_manager:
                config._art_client.terminate()
                proc = config._art_proc
                if proc:
                    proc.wait()
Exemplo n.º 10
0
    def set_trace(self, *args, **kwargs):
        """Start a pdb debugger available via telnet, and optionally email people the endpoint

        The endpoint will always be seen in the py.test runner output.

        Keyword Args:
            recipients: A list where, if set, an email will be sent to email addresses
                in this list.
            subject: If set, an optional custom email subject

        """
        host, port = self.sock.getsockname()
        endpoint = 'host {} port {}'.format(store.my_ip_address, port)

        recipients = kwargs.pop('recipients', None)
        if recipients:
            # write and send an email
            subject = kwargs.pop('subject', 'RDB Breakpoint: Manually invoked')
            body = dedent("""\
            A py.test run encountered an error. The remote debugger is running
            on {} (TCP), waiting for telnet connection.
            """).format(endpoint)

            try:
                smtp_server = smtp_conf['server']
                smtp = smtplib.SMTP(smtp_server)
                msg = MIMEText(body)
                msg['Subject'] = subject
                msg['To'] = ', '.join(recipients)
                smtp.sendmail('*****@*****.**', recipients,
                              msg.as_string())
            except socket.error:
                logger.critical("Couldn't send email")

        msg = 'Remote debugger listening on {}'.format(endpoint)
        logger.critical(msg)
        write_line(msg, red=True, bold=True)
        self.sock.listen(1)
        (client_socket, address) = self.sock.accept()
        client_fh = client_socket.makefile('rw')
        Pdb.__init__(self,
                     completekey='tab',
                     stdin=client_fh,
                     stdout=client_fh)
        sys.stdout = sys.stdin = client_fh
        Pdb.set_trace(self, *args, **kwargs)
        msg = 'Debugger on {} shut down'.format(endpoint)
        logger.critical(msg)
        write_line(msg, green=True, bold=True)
def shutdown(config):
    with lock:
        proc = config._art_proc
        if proc:
            if not store.slave_manager:
                write_line('collecting artifacts')
                fire_art_hook(config, 'finish_session')
            fire_art_hook(config,
                          'teardown_merkyl',
                          ip=urlparse(env['base_url']).netloc)
            if not store.slave_manager:
                config._art_client.terminate()
                proc = config._art_proc
                if proc:
                    proc.wait()
Exemplo n.º 12
0
def shutdown(config):
    with lock:
        proc = config._art_proc
        if proc:
            if not store.slave_manager:
                write_line('collecting artifacts')
                fire_art_hook(config, 'finish_session')
            fire_art_hook(config,
                          'teardown_merkyl',
                          ip=get_or_create_current_appliance().address)
            if not store.slave_manager:
                config._art_client.terminate()
                proc = config._art_proc
                if proc:
                    proc.wait()
Exemplo n.º 13
0
def shutdown(config):
    holder = config.pluginmanager.getplugin('appliance-holder')
    app = holder.held_appliance
    with lock:
        proc = config._art_proc
        if proc:
            if not store.slave_manager:
                write_line('collecting artifacts')
                fire_art_hook(config, 'finish_session')
            fire_art_hook(config, 'teardown_merkyl', ip=app.address)
            if not store.slave_manager:
                config._art_client.terminate()
                proc = config._art_proc
                if proc:
                    proc.wait()
Exemplo n.º 14
0
def shutdown(config):
    holder = config.pluginmanager.getplugin('appliance-holder')
    if holder:
        app = holder.held_appliance
        with lock:
            proc = config._art_proc
            if proc:
                if not store.slave_manager:
                    write_line('collecting artifacts')
                    fire_art_hook(config, 'finish_session')
                fire_art_hook(config, 'teardown_merkyl',
                              ip=app.hostname)
                if not store.slave_manager:
                    config._art_client.terminate()
                    proc = config._art_proc
                    if proc:
                        proc.wait()
Exemplo n.º 15
0
    def set_trace(self, *args, **kwargs):
        """Start a pdb debugger available via telnet, and optionally email people the endpoint

        The endpoint will always be seen in the py.test runner output.

        Keyword Args:
            recipients: A list where, if set, an email will be sent to email addresses
                in this list.
            subject: If set, an optional custom email subject

        """
        host, port = self.sock.getsockname()
        endpoint = 'host {} port {}'.format(store.my_ip_address, port)

        recipients = kwargs.pop('recipients', None)
        if recipients:
            # write and send an email
            subject = kwargs.pop('subject', 'RDB Breakpoint: Manually invoked')
            body = dedent("""\
            A py.test run encountered an error. The remote debugger is running
            on {} (TCP), waiting for telnet connection.
            """).format(endpoint)

            try:
                smtp_server = smtp_conf['server']
                smtp = smtplib.SMTP(smtp_server)
                msg = MIMEText(body)
                msg['Subject'] = subject
                msg['To'] = ', '.join(recipients)
                smtp.sendmail('*****@*****.**', recipients, msg.as_string())
            except socket.error:
                logger.critical("Couldn't send email")

        msg = 'Remote debugger listening on {}'.format(endpoint)
        logger.critical(msg)
        write_line(msg, red=True, bold=True)
        self.sock.listen(1)
        (client_socket, address) = self.sock.accept()
        client_fh = client_socket.makefile('rw')
        Pdb.__init__(self, completekey='tab', stdin=client_fh, stdout=client_fh)
        sys.stdout = sys.stdin = client_fh
        Pdb.set_trace(self, *args, **kwargs)
        msg = 'Debugger on {} shut down'.format(endpoint)
        logger.critical(msg)
        write_line(msg, green=True, bold=True)
Exemplo n.º 16
0
def start(webdriver_name=None, base_url=None, **kwargs):
    """Starts a new web browser

    If a previous browser was open, it will be closed before starting the new browser

    Args:
        webdriver_name: The name of the selenium Webdriver to use. Default: 'Firefox'
        base_url: Optional, will use ``utils.conf.env['base_url']`` by default
        **kwargs: Any additional keyword arguments will be passed to the webdriver constructor

    """
    # Try to clean up an existing browser session if starting a new one
    if thread_locals.browser is not None:
        quit()

    browser_conf = conf.env.get('browser', {})

    if webdriver_name is None:
        # If unset, look to the config for the webdriver type
        # defaults to Firefox
        webdriver_name = browser_conf.get('webdriver', 'Firefox')
    webdriver_class = getattr(webdriver, webdriver_name)

    if base_url is None:
        base_url = store.base_url

    # Pull in browser kwargs from browser yaml
    browser_kwargs = browser_conf.get('webdriver_options', {})

    # Handle firefox profile for Firefox or Remote webdriver
    if webdriver_name == 'Firefox':
        browser_kwargs['firefox_profile'] = _load_firefox_profile()
    elif (webdriver_name == 'Remote' and
          browser_kwargs['desired_capabilities']['browserName'] == 'firefox'):
        browser_kwargs['browser_profile'] = _load_firefox_profile()

    # Update it with passed-in options/overrides
    browser_kwargs.update(kwargs)

    if webdriver_name != 'Remote' and 'desired_capabilities' in browser_kwargs:
        # desired_capabilities is only for Remote driver, but can sneak in
        del(browser_kwargs['desired_capabilities'])

    if webdriver_name == 'Remote' and 'webdriver_wharf' in browser_conf and not thread_locals.wharf:
        # Configured to use wharf, but it isn't configured yet; check out a webdriver container
        wharf = Wharf(browser_conf['webdriver_wharf'])
        # TODO: Error handling! :D
        wharf.checkout()
        atexit.register(wharf.checkin)
        thread_locals.wharf = wharf

        if browser_kwargs['desired_capabilities']['browserName'] == 'chrome':
            # chrome uses containers to sandbox the browser, and we use containers to
            # run chrome in wharf, so disable the sandbox if running chrome in wharf
            co = browser_kwargs['desired_capabilities'].get('chromeOptions', {})
            arg = '--no-sandbox'
            if 'args' not in co:
                co['args'] = [arg]
            elif arg not in co['args']:
                co['args'].append(arg)
            browser_kwargs['desired_capabilities']['chromeOptions'] = co

    if thread_locals.wharf:
        # Wharf is configured, make sure to use its command_executor
        wharf_config = thread_locals.wharf.config
        browser_kwargs['command_executor'] = wharf_config['webdriver_url']
        view_msg = 'tests can be viewed via vnc on display %s' % wharf_config['vnc_display']
        logger.info('webdriver command executor set to %s' % wharf_config['webdriver_url'])
        logger.info(view_msg)
        write_line(view_msg, cyan=True)

    try:
        browser = tries(3, WebDriverException, webdriver_class, **browser_kwargs)
        browser.maximize_window()
        browser.get(base_url)
        thread_locals.browser = browser
    except urllib2.URLError as ex:
        # connection to selenium was refused for unknown reasons
        if thread_locals.wharf:
            # If we're running wharf, try again with a new container
            logger.error('URLError connecting to selenium; recycling container. URLError:')
            # Plus, since this is a really weird thing that we need to figure out,
            # throw a message out to the terminal for visibility
            write_line('URLError caused container recycle, see log for details', red=True)
            logger.exception(ex)
            thread_locals.wharf.checkin()
            thread_locals.wharf = None
            start(webdriver_name, base_url, **kwargs)
        else:
            # If we aren't running wharf, raise it
            raise

    return thread_locals.browser
Exemplo n.º 17
0
def start(webdriver_name=None, base_url=None, **kwargs):
    """Starts a new web browser

    If a previous browser was open, it will be closed before starting the new browser

    Args:
        webdriver_name: The name of the selenium Webdriver to use. Default: 'Firefox'
        base_url: Optional, will use ``utils.conf.env['base_url']`` by default
        **kwargs: Any additional keyword arguments will be passed to the webdriver constructor

    """
    # Try to clean up an existing browser session if starting a new one
    if thread_locals.browser is not None:
        quit()

    browser_conf = conf.env.get('browser', {})

    if webdriver_name is None:
        # If unset, look to the config for the webdriver type
        # defaults to Firefox
        webdriver_name = browser_conf.get('webdriver', 'Firefox')
    webdriver_class = getattr(webdriver, webdriver_name)

    if base_url is None:
        base_url = store.base_url

    # Pull in browser kwargs from browser yaml
    browser_kwargs = browser_conf.get('webdriver_options', {})

    # Handle firefox profile for Firefox or Remote webdriver
    if webdriver_name == 'Firefox':
        browser_kwargs['firefox_profile'] = _load_firefox_profile()
    elif (webdriver_name == 'Remote' and
          browser_kwargs['desired_capabilities']['browserName'] == 'firefox'):
        browser_kwargs['browser_profile'] = _load_firefox_profile()

    # Update it with passed-in options/overrides
    browser_kwargs.update(kwargs)

    if webdriver_name != 'Remote' and 'desired_capabilities' in browser_kwargs:
        # desired_capabilities is only for Remote driver, but can sneak in
        del (browser_kwargs['desired_capabilities'])

    if webdriver_name == 'Remote' and 'webdriver_wharf' in browser_conf and not thread_locals.wharf:
        # Configured to use wharf, but it isn't configured yet; check out a webdriver container
        wharf = Wharf(browser_conf['webdriver_wharf'])
        # TODO: Error handling! :D
        wharf.checkout()
        atexit.register(wharf.checkin)
        thread_locals.wharf = wharf

        if browser_kwargs['desired_capabilities']['browserName'] == 'chrome':
            # chrome uses containers to sandbox the browser, and we use containers to
            # run chrome in wharf, so disable the sandbox if running chrome in wharf
            co = browser_kwargs['desired_capabilities'].get(
                'chromeOptions', {})
            arg = '--no-sandbox'
            if 'args' not in co:
                co['args'] = [arg]
            elif arg not in co['args']:
                co['args'].append(arg)
            browser_kwargs['desired_capabilities']['chromeOptions'] = co

    if thread_locals.wharf:
        # Wharf is configured, make sure to use its command_executor
        wharf_config = thread_locals.wharf.config
        browser_kwargs['command_executor'] = wharf_config['webdriver_url']
        view_msg = 'tests can be viewed via vnc on display {}'.format(
            wharf_config['vnc_display'])
        logger.info('webdriver command executor set to %s',
                    wharf_config['webdriver_url'])
        logger.info(view_msg)
        write_line(view_msg, cyan=True)

    try:
        browser = tries(3, WebDriverException, webdriver_class,
                        **browser_kwargs)
        browser.file_detector = UselessFileDetector()
        browser.maximize_window()
        browser.get(base_url)
        thread_locals.browser = browser
    except urllib2.URLError as ex:
        # connection to selenium was refused for unknown reasons
        if thread_locals.wharf:
            # If we're running wharf, try again with a new container
            logger.error(
                'URLError connecting to selenium; recycling container. URLError:'
            )
            # Plus, since this is a really weird thing that we need to figure out,
            # throw a message out to the terminal for visibility
            write_line(
                'URLError caused container recycle, see log for details',
                red=True)
            logger.exception(ex)
            thread_locals.wharf.checkin()
            thread_locals.wharf = None
            start(webdriver_name, base_url, **kwargs)
        else:
            # If we aren't running wharf, raise it
            raise

    return thread_locals.browser