コード例 #1
0
ファイル: engine.py プロジェクト: Avi-Labs/taurus
    def __load_module(self, alias):
        """
        Load module class by alias
        :param alias: str
        :return: class
        """
        if alias in self.modules:
            return self.modules[alias]

        mod_conf = self.config.get('modules')
        if alias not in mod_conf:
            msg = "Module '%s' not found in list of available aliases %s" % (
                alias, sorted(mod_conf.keys()))
            raise TaurusConfigError(msg)

        settings = ensure_is_dict(mod_conf, alias, "class")

        acopy = copy.deepcopy(settings)
        BetterDict.traverse(acopy, Configuration.masq_sensitive)
        self.log.debug("Module config: %s %s", alias, acopy)

        err = TaurusConfigError(
            "Class name for alias '%s' is not found in module settings: %s" %
            (alias, settings))
        clsname = settings.get('class', err)

        self.modules[alias] = load_class(clsname)
        if not issubclass(self.modules[alias], EngineModule):
            raise TaurusInternalException(
                "Module class does not inherit from EngineModule: %s" %
                clsname)

        return self.modules[alias]
コード例 #2
0
ファイル: engine.py プロジェクト: andy7i/taurus
    def __load_module(self, alias):
        """
        Load module class by alias
        :param alias: str
        :return: class
        """
        if alias in self.modules:
            return self.modules[alias]

        mod_conf = self.config.get('modules')
        if alias not in mod_conf:
            msg = "Module '%s' not found in list of available aliases %s" % (alias, sorted(mod_conf.keys()))
            raise TaurusConfigError(msg)

        settings = ensure_is_dict(mod_conf, alias, "class")

        acopy = copy.deepcopy(settings)
        BetterDict.traverse(acopy, Configuration.masq_sensitive)
        self.log.debug("Module config: %s %s", alias, acopy)

        err = TaurusConfigError("Class name for alias '%s' is not found in module settings: %s" % (alias, settings))
        clsname = settings.get('class', err)

        self.modules[alias] = load_class(clsname)
        if not issubclass(self.modules[alias], EngineModule):
            raise TaurusInternalException("Module class does not inherit from EngineModule: %s" % clsname)

        return self.modules[alias]
コード例 #3
0
    def __load_module(self, alias):
        """
        Load module class by alias
        :param alias: str
        :return: class
        """
        if alias in self.modules:
            return self.modules[alias]

        mod_conf = self.config.get('modules')
        if alias not in mod_conf:
            self.log.info("Possible module aliases: %s", [str(x) for x in sorted(mod_conf.keys())])
            raise ValueError("Module alias '%s' not found in module settings" % alias)

        settings = ensure_is_dict(mod_conf, alias, "class")

        acopy = copy.deepcopy(settings)
        BetterDict.traverse(acopy, Configuration.masq_sensitive)
        self.log.debug("Module config: %s %s", alias, acopy)

        clsname = settings.get('class', None)
        if clsname is None:
            raise ValueError("Class name not found in module settings: %s" % settings)

        try:
            self.modules[alias] = load_class(clsname)
            if not issubclass(self.modules[alias], EngineModule):
                raise TypeError("Module class does not inherit from EngineModule: %s" % clsname)
        except BaseException:
            self.log.debug("Failed to load class %s: %s", clsname, traceback.format_exc())
            raise ValueError("Cannot load module '%s' with class %s" % (alias, clsname))

        return self.modules[alias]
コード例 #4
0
ファイル: engine.py プロジェクト: PurdyForks/taurus
    def __load_module(self, alias):
        """
        Load module class by alias
        :param alias: str
        :return: class
        """
        if alias in self.modules:
            return self.modules[alias]

        mod_conf = self.config.get('modules')
        if alias not in mod_conf:
            self.log.info("Possible module aliases: %s", [str(x) for x in sorted(mod_conf.keys())])
            raise ValueError("Module alias '%s' not found in module settings" % alias)

        settings = ensure_is_dict(mod_conf, alias, "class")

        acopy = copy.deepcopy(settings)
        BetterDict.traverse(acopy, Configuration.masq_sensitive)
        self.log.debug("Module config: %s %s", alias, acopy)

        clsname = settings.get('class', None)
        if clsname is None:
            raise ValueError("Class name not found in module settings: %s" % settings)

        try:
            self.modules[alias] = load_class(clsname)
            if not issubclass(self.modules[alias], EngineModule):
                raise TypeError("Module class does not inherit from EngineModule: %s" % clsname)
        except BaseException:
            self.log.debug("Failed to load class %s: %s", clsname, traceback.format_exc())
            raise ValueError("Cannot load module '%s' with class %s" % (alias, clsname))

        return self.modules[alias]
コード例 #5
0
    def __load_module(self, alias):
        if alias in self.modules:
            return self.modules[alias]

        mod_conf = self.config.get('modules')
        if alias not in mod_conf:
            raise ValueError("Module alias '%s' not found in module settings" %
                             alias)

        settings = ensure_is_dict(mod_conf, alias, "class")

        acopy = copy.deepcopy(settings)
        BetterDict.traverse(acopy, Configuration.masq_sensitive)
        self.log.debug("Module config: %s %s", alias, acopy)

        clsname = settings.get('class', None)
        try:
            self.modules[alias] = load_class(clsname)
            if not issubclass(self.modules[alias], EngineModule):
                raise TypeError(
                    "Module class does not inherit from EngineModule: %s" %
                    clsname)
        except BaseException as exc:
            self.log.debug("Failed to load class %s: %s", clsname,
                           traceback.format_exc())
            raise ValueError("Cannot load module '%s' with class %s" %
                             (alias, clsname))

        return self.modules[alias]
コード例 #6
0
def replace_in_config(config, samples, substitutes, log=None):
    def file_replacer(value, key, container):
        if value in samples:
            container[key] = substitutes[samples.index(value)]
            if container[key] != value and log:
                log.debug("Replaced %s with %s", value, container[key])

    BetterDict.traverse(config, file_replacer)
コード例 #7
0
    def test_configuration_smoothness(self):
        def find_ad_dict_ed(*args):
            if isinstance(args[0],
                          dict) and not isinstance(args[0], BetterDict):
                raise BaseException("dict found in Configuration")

        configs = [RESOURCES_DIR + "json/get-post.json", self.paths]
        self.obj.configure(configs)
        self.assertTrue(isinstance(self.obj.config, Configuration))
        BetterDict.traverse(self.obj.config, find_ad_dict_ed)
コード例 #8
0
ファイル: test_engine.py プロジェクト: infomaven/taurus
    def test_configuration_smoothness(self):
        def find_ad_dict_ed(*args):
            if isinstance(args[0], dict) and not isinstance(args[0], BetterDict):
                raise BaseException("dict found in Configuration")

        configs = [
            RESOURCES_DIR + "json/get-post.json",
            self.paths]
        self.obj.configure(configs)
        self.assertTrue(isinstance(self.obj.config, Configuration))
        BetterDict.traverse(self.obj.config, find_ad_dict_ed)
コード例 #9
0
 def test_masq_sensitive(self):
     obj = Configuration()
     obj.merge({
         "token": "my-precious",
         "my_password": "******",
         "secret": "secret",
         "secret_story": "story",
     })
     BetterDict.traverse(obj, Configuration.masq_sensitive)
     self.assertEquals(obj["token"], "*" * 8)
     self.assertEquals(obj["my_password"], "*" * 8)
     self.assertEquals(obj["secret"], "*" * 8)
     self.assertEquals(obj["secret_story"], "story")
コード例 #10
0
 def test_masq_sensitive(self):
     obj = Configuration()
     obj.merge({
         "token": "my-precious",
         "my_password": "******",
         "secret": "secret",
         "secret_story": "story",
     })
     BetterDict.traverse(obj, Configuration.masq_sensitive)
     self.assertEquals(obj["token"], "*" * 8)
     self.assertEquals(obj["my_password"], "*" * 8)
     self.assertEquals(obj["secret"], "*" * 8)
     self.assertEquals(obj["secret_story"], "story")
コード例 #11
0
ファイル: engine.py プロジェクト: Avi-Labs/taurus
    def eval_env(self):
        """
        Should be done after `configure`
        """
        envs = self.__get_envs_from_config()
        envs = expand_envs_with_os(envs)

        def apply_env(value, key, container):
            if isinstance(value, str):
                container[key] = custom_expandvars(value, envs)

        BetterDict.traverse(self.config, apply_env)

        self.__export_variables_to_os()
コード例 #12
0
    def prepare(self):
        super(CloudProvisioning, self).prepare()
        self.browser_open = self.settings.get("browser-open",
                                              self.browser_open)
        self.client.logger_limit = self.settings.get("request-logging-limit",
                                                     self.client.logger_limit)

        # TODO: go to "blazemeter" section for these settings by default?
        self.client.address = self.settings.get("address", self.client.address)
        self.client.token = self.settings.get("token", self.client.token)
        self.client.timeout = dehumanize_time(
            self.settings.get("timeout", self.client.timeout))

        if not self.client.token:
            bmmod = self.engine.instantiate_module('blazemeter')
            self.client.token = bmmod.settings.get("token")
            if not self.client.token:
                raise ValueError(
                    "You must provide API token to use cloud provisioning")

        self.__prepare_locations()
        config = self.__get_config_for_cloud()
        rfiles = self.__get_rfiles()

        def file_replacer(container):
            if isinstance(container, dict):
                for key, val in iteritems(container):
                    if val in rfiles:
                        container[key] = os.path.basename(val)
                        if container[key] != val:
                            self.log.info("Replaced %s with %s in %s", val,
                                          container[key], key)

        BetterDict.traverse(config, file_replacer)

        bza_plugin = self.__get_bza_test_config()
        finder = ProjectFinder(self.parameters, self.settings, self.client,
                               self.engine)
        finder.default_test_name = "Taurus Cloud Test"
        self.test_id = finder.resolve_test_id(bza_plugin, config, rfiles)
        self.test_name = finder.test_name
        self.widget = CloudProvWidget(self)

        if isinstance(self.engine.aggregator, ConsolidatingAggregator):
            self.results_reader = ResultsFromBZA(self.client)
            self.results_reader.log = self.log
            self.engine.aggregator.add_underling(self.results_reader)
コード例 #13
0
    def prepare(self):
        if self.settings.get("dump-locations", False):
            self.log.warning(
                "Dumping available locations instead of running the test")
            self._configure_client()
            info = self.client.get_user_info()
            locations = self.client.get_available_locations()
            for item in info['locations']:
                if item['id'] in locations:
                    self.log.info("Location: %s\t%s", item['id'],
                                  item['title'])
            raise ManualShutdown("Done listing locations")

        super(CloudProvisioning, self).prepare()
        self.browser_open = self.settings.get("browser-open",
                                              self.browser_open)
        self._configure_client()

        self.__prepare_locations()
        config = self.__get_config_for_cloud()
        rfiles = self.__get_rfiles()

        def file_replacer(container):
            if isinstance(container, dict):
                for key, val in iteritems(container):
                    if val in rfiles:
                        container[key] = os.path.basename(val)
                        if container[key] != val:
                            self.log.info("Replaced %s with %s in %s", val,
                                          container[key], key)

        BetterDict.traverse(config, file_replacer)

        bza_plugin = self.__get_bza_test_config()
        finder = ProjectFinder(self.parameters, self.settings, self.client,
                               self.engine)
        finder.default_test_name = "Taurus Cloud Test"
        self.test_id = finder.resolve_test_id(bza_plugin, config, rfiles)
        self.test_name = finder.test_name
        self.widget = CloudProvWidget(self)

        if isinstance(self.engine.aggregator, ConsolidatingAggregator):
            self.results_reader = ResultsFromBZA(self.client)
            self.results_reader.log = self.log
            self.engine.aggregator.add_underling(self.results_reader)
コード例 #14
0
ファイル: blazemeter.py プロジェクト: AlexeyDeyneko/taurus
    def prepare(self):
        super(CloudProvisioning, self).prepare()
        self.browser_open = self.settings.get("browser-open", self.browser_open)
        self.client.logger_limit = self.settings.get("request-logging-limit", self.client.logger_limit)

        # TODO: go to "blazemeter" section for these settings by default?
        self.client.address = self.settings.get("address", self.client.address)
        self.client.token = self.settings.get("token", self.client.token)
        self.client.timeout = dehumanize_time(self.settings.get("timeout", self.client.timeout))

        if not self.client.token:
            bmmod = self.engine.instantiate_module('blazemeter')
            self.client.token = bmmod.settings.get("token")
            if not self.client.token:
                raise ValueError("You must provide API token to use cloud provisioning")

        self.__prepare_locations()
        config = self.__get_config_for_cloud()
        rfiles = self.__get_rfiles()

        def file_replacer(container):
            if isinstance(container, dict):
                for key, val in iteritems(container):
                    if val in rfiles:
                        container[key] = os.path.basename(val)
                        if container[key] != val:
                            self.log.info("Replaced %s with %s in %s", val, container[key], key)

        BetterDict.traverse(config, file_replacer)

        bza_plugin = self.__get_bza_test_config()
        finder = ProjectFinder(self.parameters, self.settings, self.client, self.engine)
        finder.default_test_name = "Taurus Cloud Test"
        self.test_id = finder.resolve_test_id(bza_plugin, config, rfiles)
        self.test_name = finder.test_name
        self.widget = CloudProvWidget(self)

        if isinstance(self.engine.aggregator, ConsolidatingAggregator):
            self.results_reader = ResultsFromBZA(self.client)
            self.results_reader.log = self.log
            self.engine.aggregator.add_underling(self.results_reader)
コード例 #15
0
    def eval_env(self):
        """
        Should be done after `configure`
        """
        envs = self.config.get(SETTINGS).get("env")
        for varname in envs:
            self.env.set({varname: envs[varname]})
            if envs[varname] is None:
                if varname in os.environ:
                    os.environ.pop(varname)
            else:
                os.environ[varname] = str(envs[varname])

        def apply_env(value, key, container):
            if key in ("scenario",
                       "scenarios"):  # might stop undesired branches
                return True  # don't traverse into
            if isinstance(value, string_types):
                container[key] = os.path.expandvars(value)

        BetterDict.traverse(self.config, apply_env)
コード例 #16
0
ファイル: blazemeter.py プロジェクト: VegiS/taurus
    def prepare(self):
        if self.settings.get("dump-locations", False):
            self.log.warning("Dumping available locations instead of running the test")
            self._configure_client()
            info = self.client.get_user_info()
            locations = self.client.get_available_locations()
            for item in info['locations']:
                if item['id'] in locations:
                    self.log.info("Location: %s\t%s", item['id'], item['title'])
            raise ManualShutdown("Done listing locations")

        super(CloudProvisioning, self).prepare()
        self.browser_open = self.settings.get("browser-open", self.browser_open)
        self._configure_client()

        self.__prepare_locations()
        config = self.__get_config_for_cloud()
        rfiles = self.__get_rfiles()

        def file_replacer(container):
            if isinstance(container, dict):
                for key, val in iteritems(container):
                    if val in rfiles:
                        container[key] = os.path.basename(val)
                        if container[key] != val:
                            self.log.info("Replaced %s with %s in %s", val, container[key], key)

        BetterDict.traverse(config, file_replacer)

        bza_plugin = self.__get_bza_test_config()
        finder = ProjectFinder(self.parameters, self.settings, self.client, self.engine)
        finder.default_test_name = "Taurus Cloud Test"
        self.test_id = finder.resolve_test_id(bza_plugin, config, rfiles)
        self.test_name = finder.test_name
        self.widget = CloudProvWidget(self)

        if isinstance(self.engine.aggregator, ConsolidatingAggregator):
            self.results_reader = ResultsFromBZA(self.client)
            self.results_reader.log = self.log
            self.engine.aggregator.add_underling(self.results_reader)
コード例 #17
0
    def dump(self, filename=None, fmt=None):
        """
        Dump current state of dict into file. If no filename or format
        specified, defaults are used

        :type filename: str or NoneType
        :type fmt: str or NoneType
        """
        if not filename:
            filename = self.dump_filename

        if filename:
            if not fmt:
                self.dump(filename + ".yml", self.YAML)
                self.dump(filename + ".json", self.JSON)
                return

            acopy = copy.deepcopy(self)
            BetterDict.traverse(acopy, self.masq_sensitive)
            with open(filename, "w") as fhd:
                self.log.debug("Dumping %s config into %s", fmt, filename)
                acopy.write(fhd, fmt)
コード例 #18
0
    def eval_env(self):
        """
        Should be done after `configure`
        """
        envs = self.config.get(SETTINGS, force_set=True).get("env",
                                                             force_set=True)
        envs[TAURUS_ARTIFACTS_DIR] = self.artifacts_dir

        for varname in envs:
            if envs[varname]:
                envs[varname] = str(envs[varname])
                envs[varname] = os.path.expandvars(envs[varname])

        for varname in envs:
            self.env.set({varname: envs[varname]})
            if envs[varname] is None:
                if varname in os.environ:
                    os.environ.pop(varname)
            else:
                os.environ[varname] = str(envs[varname])

        def custom_expandvars(value):
            parts = re.split(r'(\$\{.*?\})', value)
            value = ''
            for item in parts:
                if item and item.startswith("${") and item.endswith("}"):
                    key = item[2:-1]
                    if key in envs:
                        item = envs[key]
                if item is not None:
                    value += text_type(item)
            return value

        def apply_env(value, key, container):
            if isinstance(value, string_types):
                container[key] = custom_expandvars(value)

        BetterDict.traverse(self.config, apply_env)
コード例 #19
0
ファイル: engine.py プロジェクト: PurdyForks/taurus
    def dump(self, filename=None, fmt=None):
        """
        Dump current state of dict into file. If no filename or format
        specified, defaults are used

        :type filename: str or NoneType
        :type fmt: str or NoneType
        :raise ValueError:
        """
        if not filename:
            filename = self.dump_filename

        if filename:
            if not fmt:
                self.dump(filename + ".yml", self.YAML)
                self.dump(filename + ".json", self.JSON)
                return

            acopy = copy.deepcopy(self)
            BetterDict.traverse(acopy, self.masq_sensitive)
            with open(filename, "w") as fhd:
                self.log.debug("Dumping %s config into %s", fmt, filename)
                acopy.write(fhd, fmt)
コード例 #20
0
ファイル: engine.py プロジェクト: infomaven/taurus
    def eval_env(self):
        """
        Should be done after `configure`
        """
        envs = self.config.get(SETTINGS, force_set=True).get("env", force_set=True)
        envs[TAURUS_ARTIFACTS_DIR] = self.artifacts_dir

        for varname in envs:
            if envs[varname]:
                envs[varname] = str(envs[varname])
                envs[varname] = os.path.expandvars(envs[varname])

        for varname in envs:
            self.env.set({varname: envs[varname]})
            if envs[varname] is None:
                if varname in os.environ:
                    os.environ.pop(varname)
            else:
                os.environ[varname] = str(envs[varname])

        def custom_expandvars(value):
            parts = re.split(r'(\$\{.*?\})', value)
            value = ''
            for item in parts:
                if item and item.startswith("${") and item.endswith("}"):
                    key = item[2:-1]
                    if key in envs:
                        item = envs[key]
                if item is not None:
                    value += text_type(item)
            return value

        def apply_env(value, key, container):
            if isinstance(value, string_types):
                container[key] = custom_expandvars(value)

        BetterDict.traverse(self.config, apply_env)