def process(self): output_format = Configuration.JSON if self.options.json else Configuration.YAML self.log.info('Loading Swagger spec %s', self.file_to_convert) self.file_to_convert = os.path.abspath(os.path.expanduser(self.file_to_convert)) if not os.path.exists(self.file_to_convert): raise TaurusInternalException("File does not exist: %s" % self.file_to_convert) self.converter = SwaggerConverter(self.log) try: converted_config = self.converter.convert(self.file_to_convert) except BaseException: self.log.error("Error while processing Swagger spec: %s", self.file_to_convert) raise exporter = Configuration() exporter.merge(converted_config) if self.options.file_name: file_name = self.options.file_name else: file_name = self.file_to_convert + "." + output_format.lower() exporter.dump(file_name, output_format) self.log.info("Done processing, result saved in %s", file_name)
def process(self): """ Process file :return: """ output_format = Configuration.JSON if self.options.json else Configuration.YAML self.log.info('Loading jmx file %s', self.file_to_convert) self.file_to_convert = os.path.abspath(os.path.expanduser(self.file_to_convert)) if not os.path.exists(self.file_to_convert): self.log.error("File %s does not exist", self.file_to_convert) raise RuntimeError("File does not exist: %s" % self.file_to_convert) self.converter = Converter(self.log) try: jmx_as_dict = self.converter.convert(self.file_to_convert, self.options.dump_jmx) except BaseException: self.log.error("Error while processing jmx file: %s", self.file_to_convert) raise exporter = Configuration() exporter.merge(jmx_as_dict) if self.options.file_name: file_name = self.options.file_name else: file_name = self.file_to_convert + "." + output_format.lower() exporter.dump(file_name, output_format) self.log.info("Done processing, result saved in %s", file_name)
def test_tabs(self): obj = Configuration() obj.tab_replacement_spaces = 4 obj.load([RESOURCES_DIR + "yaml/tabs-issue.yml"]) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) self.assertFilesEqual(RESOURCES_DIR + "yaml/tabs-issue-spaces.yml", fname)
def test_tabs(self): obj = Configuration() obj.tab_replacement_spaces = 4 obj.load([RESOURCES_DIR + "yaml/tabs-issue.yml"]) fname = temp_file() obj.dump(fname, Configuration.YAML) self.assertFilesEqual(RESOURCES_DIR + "yaml/tabs-issue-spaces.yml", fname)
def __get_jmx_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jmxes = [] for filename in configs[:]: if filename.lower().endswith(".jmx"): jmxes.append(filename) configs.remove(filename) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds = NamedTemporaryFile(prefix="jmx_", suffix=".json") fname = fds.name fds.close() config = Configuration() for jmx_file in jmxes: config.get(ScenarioExecutor.EXEC, []).append({"executor": "jmeter", "scenario": jmx_file}) config.dump(fname, Configuration.JSON) return [fname] else: return []
def process(self): output_format = Configuration.JSON if self.options.json else Configuration.YAML self.log.info('Loading Swagger spec %s', self.file_to_convert) self.file_to_convert = os.path.abspath( os.path.expanduser(self.file_to_convert)) if not os.path.exists(self.file_to_convert): raise TaurusInternalException("File does not exist: %s" % self.file_to_convert) self.converter = SwaggerConverter( self.log, scenarios_from_paths=self.options.scenarios_from_paths, parameter_interpolation=self.options.parameter_interpolation, ) try: converted_config = self.converter.convert_path( self.file_to_convert) except BaseException: self.log.error("Error while processing Swagger spec: %s", self.file_to_convert) raise exporter = Configuration() exporter.merge(converted_config) if self.options.file_name: file_name = self.options.file_name else: file_name = self.file_to_convert + "." + output_format.lower() exporter.dump(file_name, output_format) self.log.info("Done processing, result saved in %s", file_name)
def __get_jtl_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jtls = [] for filename in configs[:]: if filename.lower().endswith(".jtl"): jtls.append(filename) configs.remove(filename) if jtls: self.log.debug("Adding JTL shorthand config for: %s", jtls) fds = NamedTemporaryFile(prefix="jtl_", suffix=".json") fname = fds.name fds.close() config = Configuration() for jtl in jtls: piece = BetterDict.from_dict({"executor": "external-results-loader", "data-file": jtl}) config.get(ScenarioExecutor.EXEC, [], force_set=True).append(piece) config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_jmx_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jmxes = [] for filename in configs[:]: if filename.lower().endswith(".jmx"): jmxes.append(filename) configs.remove(filename) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds, fname = tempfile.mkstemp(".json", "jmxes_", dir=self.engine.artifacts_base_dir) os.close(fds) config = Configuration() for jmx_file in jmxes: config.get("execution", []).append({"executor": "jmeter", "scenario": {"script": jmx_file}}) config.dump(fname, Configuration.JSON) return [fname] else: return []
def process(self): """ Process file :return: """ output_format = Configuration.JSON if self.options.json else Configuration.YAML self.log.info('Loading jmx file %s', self.file_to_convert) self.file_to_convert = os.path.abspath( os.path.expanduser(self.file_to_convert)) if not os.path.exists(self.file_to_convert): self.log.error("File %s does not exist", self.file_to_convert) raise RuntimeError("File does not exist: %s" % self.file_to_convert) self.converter = Converter(self.log) try: jmx_as_dict = self.converter.convert(self.file_to_convert, self.options.dump_jmx) except BaseException: self.log.error("Error while processing jmx file: %s", self.file_to_convert) raise exporter = Configuration() exporter.merge(jmx_as_dict) if self.options.file_name: file_name = self.options.file_name else: file_name = self.file_to_convert + "." + output_format.lower() exporter.dump(file_name, output_format) self.log.info("Done processing, result saved in %s", file_name)
def process(self): output_format = Configuration.JSON if self.options.json else Configuration.YAML self.log.info('Loading SoapUI project %s', self.file_to_convert) self.file_to_convert = os.path.abspath( os.path.expanduser(self.file_to_convert)) if not os.path.exists(self.file_to_convert): raise TaurusInternalException("File does not exist: %s" % self.file_to_convert) self.converter = SoapUIScriptConverter(self.log) try: converted_config = self.converter.convert_script( self.file_to_convert, self.options.test_case) except BaseException: self.log.error("Error while processing SoapUI project: %s", self.file_to_convert) raise self._cleanup_config(converted_config) exporter = Configuration() exporter.merge(converted_config) if self.options.file_name: file_name = self.options.file_name else: file_name = self.file_to_convert + "." + output_format.lower() exporter.dump(file_name, output_format) self.log.info("Done processing, result saved in %s", file_name)
def test_merge(self): obj = Configuration() configs = [ __dir__() + "/resources/yaml/test.yml", __dir__() + "/resources/json/merge1.json", __dir__() + "/resources/json/merge2.json", ] obj.load(configs) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: logging.debug("JSON:\n%s", fh.read()) jmeter = obj['modules']['jmeter'] classval = jmeter['class'] self.assertEquals("bzt.modules.jmeter.JMeterExecutor", classval) self.assertEquals("value", obj['key']) self.assertEquals(6, len(obj["list-append"])) self.assertEquals(2, len(obj["list-replace"])) self.assertEquals(2, len(obj["list-replace-notexistent"])) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertFalse("properties" in jmeter) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) checker = Configuration() checker.load([fname]) token = checker["list-complex"][1][0]['token'] self.assertNotEquals('test', token) token_orig = obj["list-complex"][1][0]['token'] self.assertEquals('test', token_orig)
def __get_jmx_shorthands(self, configs): jmxes = [] for n, filename in enumerate(configs): if filename.lower().endswith(".jmx"): jmxes.append(configs.pop(n)) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds, fname = tempfile.mkstemp(".json", "jmxes_", dir=self.engine.artifacts_base_dir) os.close(fds) config = Configuration() for jmx_file in jmxes: config.get("execution", []).append({ "executor": "jmeter", "scenario": { "script": jmx_file } }) config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_jtl_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jtls = [] for filename in configs[:]: if filename.lower().endswith(".jtl"): jtls.append(filename) configs.remove(filename) if jtls: self.log.debug("Adding JTL shorthand config for: %s", jtls) fds = NamedTemporaryFile(prefix="jtl_", suffix=".json") fname = fds.name fds.close() config = Configuration() for jtl in jtls: piece = BetterDict.from_dict({ "executor": "external-results-loader", "data-file": jtl }) config.get(EXEC, [], force_set=True).append(piece) config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_jmx_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jmxes = [] for filename in configs[:]: if filename.lower().endswith(".jmx"): jmxes.append(filename) configs.remove(filename) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds = NamedTemporaryFile(prefix="jmx_", suffix=".json") fname = fds.name fds.close() config = Configuration() for jmx_file in jmxes: piece = BetterDict.from_dict({ "executor": "jmeter", "scenario": { "script": jmx_file } }) config.get(EXEC, [], force_set=True).append( piece) # Does it brake single execution? config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_jmx_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jmxes = [] for filename in configs[:]: if filename.lower().endswith(".jmx"): jmxes.append(filename) configs.remove(filename) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds = NamedTemporaryFile(prefix="jmx_", suffix=".json") fname = fds.name fds.close() config = Configuration() for jmx_file in jmxes: config.get(ScenarioExecutor.EXEC, []).append({ "executor": "jmeter", "scenario": jmx_file }) config.dump(fname, Configuration.JSON) return [fname] else: return []
def test_merge(self): obj = Configuration() configs = [ RESOURCES_DIR + "yaml/test.yml", RESOURCES_DIR + "json/merge1.json", RESOURCES_DIR + "json/merge2.json", ] obj.load(configs) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: ROOT_LOGGER.debug("JSON:\n%s", fh.read()) jmeter = obj['modules']['jmeter'] classval = jmeter['class'] self.assertEquals("bzt.modules.jmeter.JMeterExecutor", classval) self.assertEquals("value", obj['key']) self.assertEquals(6, len(obj["list-append"])) self.assertEquals(2, len(obj["list-replace"])) self.assertEquals(2, len(obj["list-replace-notexistent"])) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertIsInstance(obj["list-complex"][1][0], BetterDict) self.assertFalse("properties" in jmeter) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) checker = Configuration() checker.load([fname]) token = checker["list-complex"][1][0]['token'] self.assertNotEquals('test', token) token_orig = obj["list-complex"][1][0]['token'] self.assertEquals('test', token_orig)
def test_tabs(self): obj = Configuration() obj.tab_replacement_spaces = 4 obj.load([RESOURCES_DIR + "yaml/tabs-issue.yml"]) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) # import shutil; shutil.copy(fname, RESOURCES_DIR + "yaml/tabs-issue-spaces.yml") self.assertFilesEqual(RESOURCES_DIR + "yaml/tabs-issue-spaces.yml", fname)
def test_save(self): obj = Configuration() obj.merge({"str": "text", "uc": six.u("ucstring")}) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: written = fh.read() logging.debug("YAML:\n%s", written) self.assertNotIn("unicode", written)
def test_tabs(self): obj = Configuration() obj.tab_replacement_spaces = 4 obj.load([__dir__() + "/resources/yaml/tabs-issue.yml"]) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) # import shutil; shutil.copy(fname, __dir__() + "/resources/yaml/tabs-issue-spaces.yml") self.assertFilesEqual( __dir__() + "/resources/yaml/tabs-issue-spaces.yml", fname)
def test_encode_decode_infinities(self): engine = EngineEmul() obj = Configuration() obj.merge({ "foo": float("inf"), }) cfg = engine.create_artifact("config", ".json") obj.dump(cfg, Configuration.JSON) with open(cfg) as fds: dump = json.loads(fds.read()) self.assertEqual(dump["foo"], "inf") self.assertEqual(dehumanize_time(dump["foo"]), float("inf"))
def test_save(self): obj = Configuration() obj.merge({ "str": "text", "uc": six.u("ucstring") }) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: written = fh.read() ROOT_LOGGER.debug("YAML:\n%s", written) self.assertNotIn("unicode", written)
def test_load(self): obj = Configuration() configs = [ BASE_CONFIG, RESOURCES_DIR + "json/jmx.json", RESOURCES_DIR + "json/concurrency.json" ] obj.load(configs) logging.debug("config:\n%s", obj) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: logging.debug("JSON:\n%s", fh.read()) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: logging.debug("YAML:\n%s", fh.read())
def test_load(self): obj = Configuration() configs = [ __dir__() + "/../bzt/10-base.json", __dir__() + "/json/jmx.json", __dir__() + "/json/concurrency.json" ] obj.load(configs) logging.debug("config:\n%s", obj) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: logging.debug("JSON:\n%s", fh.read()) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: logging.debug("YAML:\n%s", fh.read())
def test_load(self): obj = Configuration() configs = [ __dir__() + "/../bzt/resources/base-config.yml", __dir__() + "/resources/json/jmx.json", __dir__() + "/resources/json/concurrency.json" ] obj.load(configs) logging.debug("config:\n%s", obj) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: logging.debug("JSON:\n%s", fh.read()) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: logging.debug("YAML:\n%s", fh.read())
def test_load(self): obj = Configuration() configs = [ BASE_CONFIG, RESOURCES_DIR + "json/jmx.json", RESOURCES_DIR + "json/concurrency.json" ] obj.load(configs) ROOT_LOGGER.debug("config:\n%s", obj) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.JSON) with open(fname) as fh: ROOT_LOGGER.debug("JSON:\n%s", fh.read()) fname = tempfile.mkstemp()[1] obj.dump(fname, Configuration.YAML) with open(fname) as fh: ROOT_LOGGER.debug("YAML:\n%s", fh.read())
def __get_jmx_shorthands(self, configs): """ Generate json file with execution, executor and scenario settings :type configs: list :return: list """ jmxes = [] for filename in configs[:]: if filename.lower().endswith(".jmx"): jmxes.append(filename) configs.remove(filename) if jmxes: self.log.debug("Adding JMX shorthand config for: %s", jmxes) fds, fname = tempfile.mkstemp(".json", "jmxes_", dir=self.engine.artifacts_base_dir) os.close(fds) config = Configuration() for jmx_file in jmxes: config.get("execution", []).append({ "executor": "jmeter", "scenario": { "script": jmx_file } }) config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_url_shorthands(self, configs): """ :type configs: list :return: list """ urls = [] for candidate in configs[:]: if is_url(candidate): urls.append(candidate) configs.remove(candidate) if urls: self.log.debug("Adding HTTP shorthand config for: %s", urls) config_fds = NamedTemporaryFile(prefix="http_", suffix=".yml") fname = config_fds.name config_fds.close() config = Configuration() config.merge({ "execution": [{ "concurrency": "${__tstFeedback(Throughput_Limiter,1,${__P(concurrencyCap,1)},2)}", "hold-for": "2m", "throughput": "${__P(throughput,600)}", "scenario": "linear-growth", }], "scenarios": { "linear-growth": { "retrieve-resources": False, "timeout": "5s", "keepalive": False, "requests": [{ "action": "pause", "pause-duration": 0, "jsr223": [{ "language": "javascript", "execute": "before", "script-text": """ var startTime = parseInt(props.get("startTime")); if (!startTime) { startTime = Math.floor((new Date()).getTime() / 1000); props.put("startTime", startTime); } else { var now = Math.floor((new Date()).getTime() / 1000); var offset = now - startTime; if (offset < 60) { var targetOffset = Math.max(offset * 10, 10); props.put("throughput", targetOffset.toString()); } }""" }] }] + urls, } }, "modules": { "jmeter": { "properties": { "throughput": 1, "concurrencyCap": 500, }, } } }) config.dump(fname, Configuration.JSON) return [fname] else: return []