Exemplo n.º 1
0
    def set_resources(self):
        """
        Prepare some values that include:
        image_ref, get an image id and set to image_ref.
                        if the image not existing, create it.
        image_ref_alt, get another image id and set to image_ref_alt.
                        if the image not existing, create it.
        public_network_id,  get public network id and
                        set to public_network_id.
        fixed_network_name, retrieve a fixed network name
                        and set to fixed_network_name,
                        if the network not existing, create it.
        public_router_id, get public router id and set to public_router_id.
                        if the router not existing, create it.
        flavor_ref, get a flavor id and set to flavor_ref.
        flavor_ref_alt, get another flavor id and set to flavor_ref_alt.
        compute_host_count, get the count of the compute host
                        and set to compute_host_count
        """
        image = Image(self.params)
        net = Network(self.params)
        compute = Compute(self.params)
        utils_misc.set_openstack_environment()
        # get image id and alt image id
        image_ref = image.get_image_id(self.image_ref_name)
        if image_ref is None:
            self.image_ref_path = os.environ["image_ref_path"]
            image_ref = image.create_image(self.image_ref_name,
                                           self.image_ref_path)
        self.image_ref = image_ref
        LOG.info("image_ref is %s" % self.image_ref)

        image_ref_alt = image.get_image_id(self.image_ref_alt_name)
        if image_ref_alt is None:
            self.image_ref_alt_path = os.environ["image_ref_alt_path"]
            image_ref_alt = image.create_image(self.image_ref_alt_name,
                                               self.image_ref_alt_path)
        self.image_ref_alt = image_ref_alt
        LOG.info("image_ref_alt is %s" % self.image_ref_alt)

        # get the public net id
        self.public_network_id = net.get_network_id(self.public_network_name)
        LOG.info("public_network_id is %s" % self.public_network_id)

        # get network and create it if it does not existing.
        fixed_network = net.get_network(self.fixed_network_name)
        if fixed_network is None:
            LOG.info('Creating fixed network: %s' % self.fixed_network_name)
            net.create_network(name=self.fixed_network_name, subnet=True)
        LOG.info("fixed_network_name is %s" % self.fixed_network_name)

        # get the public router id
        public_router_id = net.get_router_id(self.public_router_name)
        if public_router_id is None:
            public_router = net.create_router(
                {"name": self.public_router_name}, True)
            public_router_id = public_router["router"]["id"]
        self.public_router_id = public_router_id
        LOG.info("public_router_id is %s" % self.public_router_id)

        # get flavor id
        self.flavor_ref = compute.get_flavor_id(self.flavor_ref_name)
        LOG.info("flavor_ref is %s" % self.flavor_ref)
        self.flavor_ref_alt = compute.get_flavor_id(self.flavor_ref_alt_name)
        LOG.info("flavor_ref_alt is %s" % self.flavor_ref_alt)

        # get compute host count
        self.compute_host_count = compute.get_compute_host_count()
        LOG.info("compute_host_count is %s" % self.compute_host_count)
Exemplo n.º 2
0
    def _syntribosTest(self):
        params = self.params
        if params.get("dependency_failed") == 'yes':
            raise exceptions.TestNotFoundError("Test dependency failed")

            # Report cloud test version
            # logging.info(version.get_pretty_version_info())
            # Report the parameters we've received and write them as keyvals
        self.log.info("Test parameters:")
        keys = params.keys()
        keys.sort()
        for key in keys:
            self.log.info("    %s = %s", key, params[key])

        utils_misc.set_openstack_environment()
        process.run('syntribos init --force', shell=True)

        syntribos_dir = os.path.join(self.logdir, 'syntribos')
        os.mkdir(syntribos_dir)
        syntribos_config_file = os.path.join(syntribos_dir, 'syntribos.conf')

        conf1 = ConfigParser.ConfigParser()
        conf1.read(syntribos_config_file)
        conf1.add_section("syntribos")
        conf1.add_section("user")
        conf1.add_section("auth")
        conf1.add_section('logging')

        auth_url = params.get("OS_AUTH_URL")
        endpoint = '//'.join([i for i in auth_url.split('/') if ':' in i])

        conf1.set("syntribos", "endpoint",
                      self.__get_endpoint(params.get('project_name')))

        conf1.set("user", "endpoint", endpoint)
        conf1.set("user", "username", params.get('OS_USERNAME'))
        conf1.set("user", "password", params.get('OS_PASSWORD'))
        conf1.set("user", "domain_name", params.get('OS_DOMAIN_NAME', 'Default'))
        conf1.set("user", "project_name", params.get('OS_TENANT_NAME'))
        conf1.set("auth", "endpoint", auth_url)
        conf1.set("logging", "log_dir", self.logdir)

        try:
            syntribos_file = open(syntribos_config_file, "w")
            conf1.write(syntribos_file)
            syntribos_file.close()
        except IOError:
            raise exceptions.TestError("Failed to generate config file")

        with open(syntribos_config_file, 'r') as f:
            content = f.read()
            self.log.info("Syntribos config:\n %s" % content)

        cmd = 'syntribos --config-file %s --syntribos-custom_root %s run' % (
                  syntribos_config_file, syntribos_dir)
        failure_count = 0
        error_count = 0

        try:
            self.log.info('Try to run command: %s' % cmd)
            sub = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
            result = ""
            while True:
                line = sub.stdout.readline()
                if line.strip() != '':
                    self.log.info("[Syntribos output] %s" % line.strip('\n'))
                    result += '\n' + line
                if line == '' and sub.poll() is not None:
                    break

            pat1 = "%  :(.+?)Failure"
            pat2 = ",(.+?)Error"
            failures = re.findall(pat1, result)
            errors = re.findall(pat2, result)

            for failure in failures:
                if int(failure) > 0:
                    failure_count += int(failure)

            for error in errors:
                if int(error) > 0:
                    error_count += int(error)

            self.log.info('=================')
            self.log.info('Total Failure: %d' % failure_count)
            self.log.info('Total Error: %d' % error_count)
            if failure_count > 0:
                raise exceptions.TestFail("There are yntribos test failures")
        except Exception:
            self.log.debug("Exception happended during runing syntribos test")
            raise
        finally:
            syntribos_file = open(syntribos_config_file, "w")
            syntribos_file.truncate()
            syntribos_file.close()
            self.log.info("Test Completed")
Exemplo n.º 3
0
    def _runTest(self):
        params = self.params

        # If a dependency test prior to this test has failed, let's fail
        # it right away as TestNA.
        if params.get("dependency_failed") == 'yes':
            raise exceptions.TestNotFoundError("Test dependency failed")

        utils_misc.set_openstack_environment()

        # Report cloud test version
        # logging.info(version.get_pretty_version_info())
        # Report the parameters we've received and write them as keyvals
        self.log.info("Test parameters:")
        keys = params.keys()
        keys.sort()
        for key in keys:
            if key != 'test_cases':
                self.log.info("    %s = %s", key, params[key])

        self.ct_type = self.params.get('ct_type')
        test_script = self.params.get('script')
        class_name = self.params.get('class_name')
        # Import the module
        mod_name = 'cloudtest.tests.nfv.%s' % test_script
        test_module = importlib.import_module(mod_name)

        for _, obj in inspect.getmembers(test_module):
            if (inspect.isclass(obj) and obj.__name__ == class_name
                    and inspect.getmodule(obj) == test_module):
                test_class = obj
                break
        self.log.info("Initialize test class: %s" % class_name)

        env_filename = os.path.join(data_dir.get_tmp_dir(),
                                    params.get("env", "env"))
        env = utils_env.Env(env_filename, self.env_version)
        self.runner_queue.put({
            "func_at_exit": utils_env.cleanup_env,
            "args": (env_filename, self.env_version),
            "once": True
        })

        comp = test_class(params, env)

        test_passed = False
        try:
            try:
                try:
                    # Preprocess
                    # try:
                    #     params = env_process.preprocess(self, params, env)
                    # finally:
                    #     self.__safe_env_save(env)

                    quotas_to_update = params.get('quotas_need_to_update', '')
                    if quotas_to_update:
                        self.log.info('Need to update quotas before test: %s' %
                                      quotas_to_update)
                        compute_utils = Compute(self.params)
                        quotas_to_update = quotas_to_update.split(',')
                        expected_quota = dict()
                        for q in quotas_to_update:
                            k, v = q.split(':')
                            expected_quota[k] = v
                        compute_utils.update_quotas(expected_quota)

                    # Initialize injection tests including workload and fault
                    need_injection = (
                        self.params.get('workload_injection') in 'true'
                        or self.params.get('fault_injection') in 'true')

                    force_injection = (self.params.get(
                        'workload_injection_force',
                        'false') in 'true' or self.params.get(
                            'fault_injection_force', 'false') in 'true')

                    if need_injection:
                        injector = utils_injection.Injection(params, env)
                        if not injector:
                            self.log.error("Failed to initialize injection")
                            if force_injection:
                                raise Exception("Failed to inject"
                                                "workload and/or fault")

                        if not injector.start() and force_injection:
                            msg = "Failed to inject workload/fault"
                            raise exceptions.InjectionFail(msg)
                        # Sleep specified time after injection
                        delay = int(params.get('sleep_after_injection', 3))
                        logging.info("Sleep %d seconds before running test" %
                                     delay)
                        time.sleep(delay)

                    # Run the test function
                    self.log.info(
                        "Start to run NFV test: '%s:%s:%s'" %
                        (test_script, class_name, params.get('func_name')))
                    try:
                        comp.setup()
                        func = getattr(comp, params.get('func_name', 'test'))
                        func()
                    finally:
                        self.__safe_env_save(env)

                except Exception, e:
                    # try:
                    #     env_process.postprocess_on_error(self, params, env)
                    # finally:
                    #     self.__safe_env_save(env)
                    stacktrace.log_exc_info(sys.exc_info(),
                                            logger='avocado.test')
                    logging.debug("Exception happened during running test")
                    raise e

            finally:
                try:
                    comp.teardown()
                except Exception, e:
                    self.log.error("Exception happened during teardown: %s" %
                                   e)

                # Postprocess
                try:
                    try:
                        # Stop injection
                        if need_injection:
                            injector.stop()

                        params['test_passed'] = str(test_passed)
                        # env_process.postprocess(self, params, env)
                        error_message = funcatexit.run_exitfuncs(
                            env, self.ct_type)
                        if error_message:
                            logging.error(error_message)
                    except Exception, e:
                        if test_passed:
                            raise
                        self.log.error(
                            "Exception raised during "
                            "postprocessing: %s", e)

                finally:
                    if self.__safe_env_save(env):
                        env.destroy()  # Force-clean as it can't be stored
                    if params.get('sleep_after_test') is not None:
                        time.sleep(int(params.get('sleep_after_test')))

                    # Perform health check after test if needed
                    health_check = \
                        self.params.get("perform_health_check_after_case")
                    health_check = health_check.lower() == "true"
                    if health_check:
                        self._stop_logging()
                        self._start_logging_hc()
                        cloud_manager = CloudManager(params, env)
                        nodes = cloud_manager.get_controller_node(
                            select_policy="all")
                        nodes.extend(
                            cloud_manager.get_compute_node(
                                select_policy="all"))
                        self._run_health_check(nodes)
                        self._stop_logging_hc()
                        self._start_logging()

        except Exception, e:
            if params.get("abort_on_error") != "yes":
                raise
            # Abort on error
            self.log.info("Aborting job (%s)", e)
    def _runTest(self):
        params = self.params

        # If a dependency test prior to this test has failed, let's fail
        # it right away as TestNA.
        if params.get("dependency_failed") == 'yes':
            raise exceptions.TestNotFoundError("Test dependency failed")

        # Report the parameters we've received and write them as keyvals
        self.log.info("Test parameters:")
        keys = params.keys()
        keys.sort()
        for key in keys:
            self.log.info("    %s = %s", key, params[key])

        # Set environment variables for OpenStack
        utils_misc.set_openstack_environment()

        test_passed = False
        vm_reliability_test_dir = os.path.join(data_dir.CLOUDTEST_TEST_DIR,
                                               'vm_reliability_tester')

        self._generate_openrc_py_file(vm_reliability_test_dir)
        self._generate_config_ini_file(vm_reliability_test_dir, False)
        self._generate_config_ini_file(vm_reliability_test_dir, True)
        self._generate_vm_list_csv_file(vm_reliability_test_dir)

        try:
            try:
                try:
                    self.log.info("start to execute vm reliability test")
                    execute_cmd = "python %s" % os.path.join(
                        vm_reliability_test_dir, "vm-reliability-tester.py")
                    process = subprocess.Popen(execute_cmd,
                                               shell=True,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.STDOUT)
                    while True:
                        line = process.stdout.readline()
                        if line.strip() != '':
                            self.log.info("[vm reliability test run] %s" %
                                          line)
                        if line == '' and process.poll() is not None:
                            break
                    if process.returncode != 0:
                        test_passed = False
                        raise exceptions.TestFail(
                            "vm reliability test failed, return code is %s" %
                            process.returncode)
                    self._collect_csv_result(vm_reliability_test_dir,
                                             self.logdir)
                    algorithm_params = self._get_algorithm_result(
                        vm_reliability_test_dir, "dweibull")
                    self.log.info(algorithm_params)
                    success_rate = self._get_success_rate(
                        vm_reliability_test_dir)
                    if success_rate >= float(params.get('vm_success_rate')):
                        test_passed = True
                    else:
                        raise exceptions.TestFail(
                            "can not reach the success rate threshold")
                    self.verify_background_errors()
                except Exception:
                    # try:
                    #     env_process.postprocess_on_error(self, params, env)
                    # finally:
                    #     self.__safe_env_save(env)
                    self.log.debug("Exception happened during running test")
                    raise

            finally:
                pass
                #     if self.__safe_env_save(env):
                #         env.destroy()   # Force-clean as it can't be stored

        except Exception, e:
            if params.get("abort_on_error") != "yes":
                raise
            # Abort on error
            self.log.info("Aborting job (%s)", e)
Exemplo n.º 5
0
if __name__ == "__main__":
    parser = cartesian_config.Parser()
    cfg = os.path.join(settings.get_value('datadir.paths', 'base_dir'),
                       'config/tests.cfg')
    parser.parse_file(cfg)
    dicts = parser.get_dicts()
    params = {
        "health_check_cpu": "false",
        "health_check_memory": "false",
        "health_check_disk": "false",
        "health_check_ceph": "true",
        "health_check_process": "false",
        "health_check_vm_count": "false",
        "health_check_service_log": "false",
        "health_check_service": "false",
        "health_check_cluster_status": "false",
        "health_check_compute_node_status": "false"
    }
    # params = None
    for tmp_params in (_ for _ in dicts):
        if 'health_check' in tmp_params.get('ct_type'):
            params = tmp_params
            break
    utils_misc.set_openstack_environment()
    health_check = HealthCheck('192.168.50.3',
                               params,
                               username='******',
                               is_raise_health_check_excp=True,
                               is_debug=True)
    health_check.get_health_status()
Exemplo n.º 6
0
    def _runTest(self):
        params = self.params

        # If a dependency test prior to this test has failed, let's fail
        # it right away as TestNA.
        if params.get("dependency_failed") == 'yes':
            raise exceptions.TestNotFoundError("Test dependency failed")

        # Report cloud test version
        # logging.info(version.get_pretty_version_info())
        # Report the parameters we've received and write them as keyvals
        self.log.info("Test parameters:")
        keys = params.keys()
        keys.sort()
        for key in keys:
            self.log.info("    %s = %s", key, params[key])

        env_filename = os.path.join(data_dir.get_tmp_dir(),
                                    params.get("env", "env"))
        env = utils_env.Env(env_filename, self.env_version)
        self.runner_queue.put({"func_at_exit": utils_env.cleanup_env,
                               "args": (env_filename, self.env_version),
                               "once": True})

        test_passed = False

        try:
            try:
                try:
                    # Preprocess
                    # try:
                    #     params = env_process.preprocess(self, params, env)
                    # finally:
                    #     self.__safe_env_save(env)

                    # Run the test function
                    self.log.info("Start to run benchmark test")
                    os.chdir('cloudtest/tests/benchmarker/perfkit/')
                    utils_misc.set_openstack_environment()
                    try:
                        cmd = "python pkb.py --cloud=OpenStack"
                        cmd += ' --benchmarks=%s' % params.get(
                            'benchmarker_name')

                        flavor = params.get('flavor_name', '2-2048-40')
                        cmd += " --machine_type=%s" % flavor

                        net_name = params.get('network_name', 'share_net')
                        cmd += ' --openstack_network=%s' % net_name

                        if params.get('floatingip_pool_name'):
                            cmd += (' --openstack_floating_ip_pool=%s' %
                                    params.get('floatingip_pool_name'))

                        if params.get('volume_size') is not None:
                            cmd += (' --openstack_volume_size=%s' %
                                    params.get('volume_size'))

                        self.log.info("Start running benchmark via command: %s"
                                      % cmd)
                        result = process.run(cmd, shell=True)
                        if result.exit_status != 0:
                            self.log.error(result.stderr)
                        self.log.info(result.stdout)

                    finally:
                        self.__safe_env_save(env)

                except Exception:
                    # try:
                    #     env_process.postprocess_on_error(self, params, env)
                    # finally:
                    #     self.__safe_env_save(env)
                    logging.debug("Exception happened during running test")
                    raise

            finally:
                # Postprocess
                try:
                    try:
                        params['test_passed'] = str(test_passed)
                        # env_process.postprocess(self, params, env)
                        error_message = \
                            funcatexit.run_exitfuncs(env, params.get(
                                'ct_type'))
                        if error_message:
                            logging.error(error_message)
                    except Exception, e:
                        if test_passed:
                            raise
                        self.log.error("Exception raised during "
                                       "postprocessing: %s", e)

                finally:
                    if self.__safe_env_save(env):
                        env.destroy()  # Force-clean as it can't be stored

        except Exception, e:
            if params.get("abort_on_error") != "yes":
                raise
            # Abort on error
            self.log.info("Aborting job (%s)", e)