示例#1
0
def smtp_test(request):
    """Fixture, which prepares the appliance for e-mail capturing tests

    Returns: :py:class:`util.smtp_collector_client.SMTPCollectorClient` instance.
    """
    logger.info("Preparing start for e-mail collector")
    ports = env.get("mail_collector", {}).get("ports", {})
    mail_server_port = ports.get("smtp", None) or random_port()
    mail_query_port = ports.get("json", None) or random_port()
    my_ip = my_ip_address()
    logger.info("Mind that it needs ports %s and %s open", mail_query_port, mail_server_port)
    smtp_conf = configuration.SMTPSettings(host=my_ip, port=mail_server_port, auth="none")
    smtp_conf.update()
    server_filename = scripts_path.join("smtp_collector.py").strpath
    server_command = server_filename + " --smtp-port {} --query-port {}".format(mail_server_port, mail_query_port)
    logger.info("Starting mail collector %s", server_command)
    collector = None

    def _finalize():
        if collector is None:
            return
        logger.info("Sending KeyboardInterrupt to collector")
        try:
            collector.send_signal(signal.SIGINT)
        except OSError as e:
            # TODO: Better logging.
            logger.exception(e)
            logger.error("Something happened to the e-mail collector!")
            return
        time.sleep(2)
        if collector.poll() is None:
            logger.info("Sending SIGTERM to collector")
            collector.send_signal(signal.SIGTERM)
            time.sleep(5)
            if collector.poll() is None:
                logger.info("Sending SIGKILL to collector")
                collector.send_signal(signal.SIGKILL)
        collector.wait()
        logger.info("Collector finished")

    collector = subprocess.Popen(server_command, shell=True)
    request.addfinalizer(_finalize)
    logger.info("Collector pid %s", collector.pid)
    logger.info("Waiting for collector to become alive.")
    time.sleep(3)
    assert collector.poll() is None, "Collector has died. Something must be blocking selected ports"
    logger.info("Collector alive")
    query_port_open = net_check_remote(mail_query_port, my_ip, force=True)
    server_port_open = net_check_remote(mail_server_port, my_ip, force=True)
    assert query_port_open and server_port_open, (
        "Ports {} and {} on the machine executing the tests are closed.\n"
        "The ports are randomly chosen -> turn firewall off.".format(mail_query_port, mail_server_port)
    )
    client = SMTPCollectorClient(my_ip, mail_query_port)
    client.set_test_name(request.node.name)
    client.clear_database()
    return client
示例#2
0
 def create_pytest_envvars(self):
     self.env_details = {'APPLIANCE': self.appliance,
                         'BROWSER': self.args['browser'],
                         'CFME_CRED_REPO': self.args['cfme_cred_repo'],
                         'CFME_CRED_REPO_DIR': self.args['cfme_cred_repo_dir'],
                         'CFME_REPO': self.args['cfme_repo'],
                         'CFME_REPO_DIR': self.args['cfme_repo_dir'],
                         'CFME_MY_IP_ADDRESS': my_ip_address(),
                         'PYTEST': self.args['pytest'],
                         'BRANCH': self.args['branch'],
                         'ARTIFACTOR_DIR': self.args['artifactor_dir']}
     print "  REPO: {}".format(self.args['cfme_repo'])
     print "  BROWSER: {}".format(self.args['browser'])
     if self.args['update_pip']:
         print "  PIP: will be updated!"
         self.env_details['UPDATE_PIP'] = 'True'
示例#3
0
def _smtp_test_session(request):
    """Fixture, which prepares the appliance for e-mail capturing tests

    Returns: :py:class:`util.smtp_collector_client.SMTPCollectorClient` instance.
    """
    logger.info("Preparing start for e-mail collector")
    ports = env.get("mail_collector", {}).get("ports", {})
    mail_server_port = ports.get("smtp", None) or random_port()
    mail_query_port = ports.get("json", None) or random_port()
    my_ip = my_ip_address()
    logger.info("Mind that it needs ports %d and %d open" % (mail_query_port, mail_server_port))
    smtp_conf = configuration.SMTPSettings(
        host=my_ip,
        port=mail_server_port,
        auth="none",
    )
    smtp_conf.update()
    server_filename = scripts_path.join('smtp_collector.py').strpath
    server_command = server_filename + " --smtp-port %d --query-port %d" % (
        mail_server_port,
        mail_query_port
    )
    logger.info("Starting mail collector %s" % server_command)
    collector = subprocess.Popen(server_command, shell=True)
    logger.info("Collector pid %d" % collector.pid)
    logger.info("Waiting for collector to become alive.")
    time.sleep(3)
    assert collector.poll() is None, "Collector has died. Something must be blocking selected ports"
    logger.info("Collector alive")
    query_port_open = net_check_remote(mail_query_port, my_ip, force=True)
    server_port_open = net_check_remote(mail_server_port, my_ip, force=True)
    assert query_port_open and server_port_open,\
        'Ports %d and %d on the machine executing the tests are closed.\n'\
        'The ports are randomly chosen -> turn firewall off.'\
        % (mail_query_port, mail_server_port)
    client = SMTPCollectorClient(
        my_ip,
        mail_query_port
    )
    yield client
    logger.info("Sending KeyboardInterrupt to collector")
    collector.send_signal(signal.SIGINT)
    collector.wait()
    logger.info("Collector finished")
示例#4
0
def _smtp_test_session(request):
    """Fixture, which prepares the appliance for e-mail capturing tests

    Returns: :py:class:`util.smtp_collector_client.SMTPCollectorClient` instance.
    """
    logger.info("Preparing start for e-mail collector")
    mail_server_port = random_port()
    mail_query_port = random_port()
    my_ip = my_ip_address()
    logger.info("Mind that it needs ports %d and %d open" %
                (mail_query_port, mail_server_port))
    smtp_conf = configuration.SMTPSettings(
        host=my_ip,
        port=mail_server_port,
        auth="none",
    )
    smtp_conf.update()
    server_filename = scripts_path.join('smtp_collector.py').strpath
    server_command = server_filename + " --smtp-port %d --query-port %d" % (
        mail_server_port, mail_query_port)
    logger.info("Starting mail collector %s" % server_command)
    collector = subprocess.Popen(server_command, shell=True)
    logger.info("Collector pid %d" % collector.pid)
    logger.info("Waiting for collector to become alive.")
    time.sleep(3)
    assert collector.poll(
    ) is None, "Collector has died. Something must be blocking selected ports"
    logger.info("Collector alive")
    query_port_open = net_check_remote(mail_query_port, my_ip, force=True)
    server_port_open = net_check_remote(mail_server_port, my_ip, force=True)
    assert query_port_open and server_port_open,\
        'Ports %d and %d on the machine executing the tests are closed.\n'\
        'The ports are randomly chosen -> turn firewall off.'\
        % (mail_query_port, mail_server_port)
    client = SMTPCollectorClient(my_ip, mail_query_port)
    yield client
    logger.info("Sending KeyboardInterrupt to collector")
    collector.send_signal(signal.SIGINT)
    collector.wait()
    logger.info("Collector finished")
示例#5
0
 def listener_host(self):
     return "http://{}".format(my_ip_address())
示例#6
0
def smtp_test(request):
    """Fixture, which prepares the appliance for e-mail capturing tests

    Returns: :py:class:`util.smtp_collector_client.SMTPCollectorClient` instance.
    """
    logger.info("Preparing start for e-mail collector")
    ports = env.get("mail_collector", {}).get("ports", {})
    mail_server_port = ports.get("smtp", None) or random_port()
    mail_query_port = ports.get("json", None) or random_port()
    my_ip = my_ip_address()
    logger.info("Mind that it needs ports {} and {} open".format(
        mail_query_port, mail_server_port))
    smtp_conf = configuration.SMTPSettings(
        host=my_ip,
        port=mail_server_port,
        auth="none",
    )
    smtp_conf.update()
    server_filename = scripts_path.join('smtp_collector.py').strpath
    server_command = server_filename + " --smtp-port {} --query-port {}".format(
        mail_server_port, mail_query_port)
    logger.info("Starting mail collector {}".format(server_command))
    collector = None

    def _finalize():
        if collector is None:
            return
        logger.info("Sending KeyboardInterrupt to collector")
        try:
            collector.send_signal(signal.SIGINT)
        except OSError as e:
            # TODO: Better logging.
            logger.exception(e)
            logger.error("Something happened to the e-mail collector!")
            return
        time.sleep(2)
        if collector.poll() is None:
            logger.info("Sending SIGTERM to collector")
            collector.send_signal(signal.SIGTERM)
            time.sleep(5)
            if collector.poll() is None:
                logger.info("Sending SIGKILL to collector")
                collector.send_signal(signal.SIGKILL)
        collector.wait()
        logger.info("Collector finished")

    collector = subprocess.Popen(server_command, shell=True)
    request.addfinalizer(_finalize)
    logger.info("Collector pid {}".format(collector.pid))
    logger.info("Waiting for collector to become alive.")
    time.sleep(3)
    assert collector.poll(
    ) is None, "Collector has died. Something must be blocking selected ports"
    logger.info("Collector alive")
    query_port_open = net_check_remote(mail_query_port, my_ip, force=True)
    server_port_open = net_check_remote(mail_server_port, my_ip, force=True)
    assert query_port_open and server_port_open,\
        'Ports {} and {} on the machine executing the tests are closed.\n'\
        'The ports are randomly chosen -> turn firewall off.'\
        .format(mail_query_port, mail_server_port)
    client = SMTPCollectorClient(my_ip, mail_query_port)
    client.set_test_name(request.node.name)
    client.clear_database()
    return client
示例#7
0
    def validate_args(self):
        ec = 0

        appliance = self.args.get('appliance', None)
        if self.args.get('appliance_name', None) and not appliance:
            self.args['appliance'] = docker_conf['appliances'][self.args['appliance_name']]

        self.check_arg('nowait', False)

        self.check_arg('banner', False)
        self.check_arg('watch', False)
        self.check_arg('output', True)
        self.check_arg('dry_run', False)
        self.check_arg('server_ip', None)

        if not self.args['server_ip']:
            self.args['server_ip'] = my_ip_address()

        self.check_arg('sprout', False)

        self.check_arg('provision_appliance', False)
        if self.args['provision_appliance']:
            if not self.args['provision_template'] or not self.args['provision_provider'] or \
               not self.args['provision_vm_name']:
                print "You don't have all the required options to provision an appliance"
                ec += 1

        self.check_arg('sprout_stream', None)
        if self.args['sprout'] and not self.args['sprout_stream']:
            print "You need to supply a stream for sprout"
            ec += 1

        self.check_arg('appliance_name', None)
        self.check_arg('appliance', None)

        if not self.args['appliance_name'] != self.args['appliance'] and \
           not self.args['provision_appliance'] and not self.args['sprout']:
            print "You must supply either an appliance OR an appliance name from config"
            ec += 1

        self.check_arg('branch', 'origin/master')
        self.check_arg('pr', None)

        self.check_arg('cfme_repo', None)
        self.check_arg('cfme_repo_dir', '/cfme_tests_te')
        self.check_arg('cfme_cred_repo', None)
        self.check_arg('cfme_cred_repo_dir', '/cfme-qe-yamls')

        if not self.args['cfme_repo']:
            print "You must supply a CFME REPO"
            ec += 1

        if not self.args['cfme_cred_repo']:
            print "You must supply a CFME Credentials REPO"
            ec += 1

        self.check_arg('selff', 'cfme/sel_ff_chrome')

        self.check_arg('gh_token', None)
        self.check_arg('gh_owner', None)
        self.check_arg('gh_repo', None)

        self.check_arg('browser', 'firefox')

        self.check_arg('pytest', None)
        self.check_arg('pytest_con', 'py_test_base')

        if not self.args['pytest']:
            print "You must specify a py.test command"
            ec += 1

        self.check_arg('update_pip', False)
        self.check_arg('wheel_host_url', None)
        self.check_arg('auto_gen_test', False)
        self.check_arg('artifactor_dir', '/log_depot')

        self.check_arg('log_depot', None)

        if not self.args['log_depot']:
            print "You must specify a log_depot"
            ec += 1

        if self.args['pr'] and self.args['auto_gen_test'] and not \
           all([self.args['gh_token'], self.args['gh_owner'], self.args['gh_repo']]):
            print "You chose to use Auto Test Gen, without supplying GitHub details"
            ec += 1

        self.check_arg('capture', False)
        self.check_arg('test_id', fauxfactory.gen_alphanumeric(8))

        self.check_arg('prtester', False)
        self.check_arg('trackerbot', None)
        self.check_arg('wharf', False)

        self.check_arg('sprout_username', None)
        self.check_arg('sprout_password', None)
        self.check_arg('sprout_description', None)

        if ec:
            sys.exit(127)
示例#8
0
    def validate_args(self):
        ec = 0

        appliance = self.args.get('appliance', None)
        if self.args.get('appliance_name', None) and not appliance:
            self.args['appliance'] = docker_conf['appliances'][
                self.args['appliance_name']]

        self.check_arg('nowait', False)

        self.check_arg('banner', False)
        self.check_arg('watch', False)
        self.check_arg('output', True)
        self.check_arg('dry_run', False)
        self.check_arg('server_ip', None)

        if not self.args['server_ip']:
            self.args['server_ip'] = my_ip_address()

        self.check_arg('sprout', False)

        self.check_arg('provision_appliance', False)
        if self.args['provision_appliance']:
            if not self.args['provision_template'] or not self.args['provision_provider'] or \
               not self.args['provision_vm_name']:
                print(
                    "You don't have all the required options to provision an appliance"
                )
                ec += 1

        self.check_arg('sprout_stream', None)
        if self.args['sprout'] and not self.args['sprout_stream']:
            print("You need to supply a stream for sprout")
            ec += 1

        self.check_arg('appliance_name', None)
        self.check_arg('appliance', None)

        if not self.args['appliance_name'] != self.args['appliance'] and \
           not self.args['provision_appliance'] and not self.args['sprout']:
            print(
                "You must supply either an appliance OR an appliance name from config"
            )
            ec += 1

        self.check_arg('branch', 'origin/master')
        self.check_arg('pr', None)

        self.check_arg('cfme_repo', None)
        self.check_arg('cfme_repo_dir', '/cfme_tests_te')
        self.check_arg('cfme_cred_repo', None)
        self.check_arg('cfme_cred_repo_dir', '/cfme-qe-yamls')

        if not self.args['cfme_repo']:
            print("You must supply a CFME REPO")
            ec += 1

        if not self.args['cfme_cred_repo']:
            print("You must supply a CFME Credentials REPO")
            ec += 1

        self.check_arg('selff', 'cfme/sel_ff_chrome')

        self.check_arg('gh_token', None)
        self.check_arg('gh_owner', None)
        self.check_arg('gh_repo', None)

        self.check_arg('browser', 'firefox')

        self.check_arg('pytest', None)
        self.check_arg('pytest_con', 'py_test_base')

        if not self.args['pytest']:
            print("You must specify a py.test command")
            ec += 1

        self.check_arg('update_pip', False)
        self.check_arg('wheel_host_url', None)
        self.check_arg('auto_gen_test', False)
        self.check_arg('artifactor_dir', '/log_depot')

        self.check_arg('log_depot', None)

        if not self.args['log_depot']:
            print("You must specify a log_depot")
            ec += 1

        if self.args['pr'] and self.args['auto_gen_test'] and not \
           all([self.args['gh_token'], self.args['gh_owner'], self.args['gh_repo']]):
            print(
                "You chose to use Auto Test Gen, without supplying GitHub details"
            )
            ec += 1

        self.check_arg('capture', False)
        self.check_arg('test_id', fauxfactory.gen_alphanumeric(8))

        self.check_arg('prtester', False)
        self.check_arg('trackerbot', None)
        self.check_arg('wharf', False)

        self.check_arg('sprout_username', None)
        self.check_arg('sprout_password', None)
        self.check_arg('sprout_description', None)

        if ec:
            sys.exit(127)
示例#9
0
 def listener_host(self):
     return "http://%s" % my_ip_address()
示例#10
0
    def validate_args(self):
        ec = 0

        appliance = self.args.get("appliance", None)
        if self.args.get("appliance_name", None) and not appliance:
            self.args["appliance"] = docker_conf["appliances"][self.args["appliance_name"]]

        self.check_arg("nowait", False)

        self.check_arg("banner", False)
        self.check_arg("watch", False)
        self.check_arg("output", True)
        self.check_arg("dry_run", False)
        self.check_arg("server_ip", None)

        if not self.args["server_ip"]:
            self.args["server_ip"] = my_ip_address()

        self.check_arg("sprout", False)

        self.check_arg("provision_appliance", False)
        if self.args["provision_appliance"]:
            if (
                not self.args["provision_template"]
                or not self.args["provision_provider"]
                or not self.args["provision_vm_name"]
            ):
                print("You don't have all the required options to provision an appliance")
                ec += 1

        self.check_arg("sprout_stream", None)
        if self.args["sprout"] and not self.args["sprout_stream"]:
            print("You need to supply a stream for sprout")
            ec += 1

        self.check_arg("appliance_name", None)
        self.check_arg("appliance", None)

        if (
            not self.args["appliance_name"] != self.args["appliance"]
            and not self.args["provision_appliance"]
            and not self.args["sprout"]
        ):
            print("You must supply either an appliance OR an appliance name from config")
            ec += 1

        self.check_arg("branch", "origin/master")
        self.check_arg("pr", None)

        self.check_arg("cfme_repo", None)
        self.check_arg("cfme_repo_dir", "/cfme_tests_te")
        self.check_arg("cfme_cred_repo", None)
        self.check_arg("cfme_cred_repo_dir", "/cfme-qe-yamls")

        if not self.args["cfme_repo"]:
            print("You must supply a CFME REPO")
            ec += 1

        if not self.args["cfme_cred_repo"]:
            print("You must supply a CFME Credentials REPO")
            ec += 1

        self.check_arg("selff", "cfme/sel_ff_chrome")

        self.check_arg("gh_token", None)
        self.check_arg("gh_owner", None)
        self.check_arg("gh_repo", None)

        self.check_arg("browser", "firefox")

        self.check_arg("pytest", None)
        self.check_arg("pytest_con", "py_test_base")

        if not self.args["pytest"]:
            print("You must specify a py.test command")
            ec += 1

        self.check_arg("update_pip", False)
        self.check_arg("wheel_host_url", None)
        self.check_arg("auto_gen_test", False)
        self.check_arg("artifactor_dir", "/log_depot")

        self.check_arg("log_depot", None)

        if not self.args["log_depot"]:
            print("You must specify a log_depot")
            ec += 1

        if (
            self.args["pr"]
            and self.args["auto_gen_test"]
            and not all([self.args["gh_token"], self.args["gh_owner"], self.args["gh_repo"]])
        ):
            print("You chose to use Auto Test Gen, without supplying GitHub details")
            ec += 1

        self.check_arg("capture", False)
        self.check_arg("test_id", fauxfactory.gen_alphanumeric(8))

        self.check_arg("prtester", False)
        self.check_arg("trackerbot", None)
        self.check_arg("wharf", False)

        self.check_arg("sprout_username", None)
        self.check_arg("sprout_password", None)
        self.check_arg("sprout_description", None)

        if ec:
            sys.exit(127)
示例#11
0
 def listener_host(self):
     return "http://%s" % my_ip_address()