def get_sampler_pair(self, request): timeout = self.safe_time(request.priority_option('timeout')) # convert body to string if isinstance(request.body, (dict, list, numeric_types)): if request.get_header('content-type') == 'application/json' or isinstance(request.body, numeric_types): request.body = json.dumps(request.body) elif not simple_body_dict(request.body): LOG.debug('Header "Content-Type: application/json" is required for body: "%s"', request.body) request.body = json.dumps(request.body) use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (request.body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request(request.url, request.label, request.method, timeout, request.body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def get_sampler_pair(self, scenario, request): timeout = self.safe_time(request.priority_option('timeout')) content_type = self._get_merged_ci_headers(scenario, request, 'content-type') if content_type == 'application/json' and isinstance(request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request(request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def get_sampler_pair(self, scenario, request): timeout = self.safe_time(request.priority_option('timeout')) content_type = self._get_merged_ci_headers(scenario, request, 'content-type') if content_type == 'application/json' and isinstance( request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips( filter_loopbacks=True) if use_random_host_ip else [] http = JMX._get_http_request( request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), request.upload_files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def convert(self, group, target, load, concurrency): """ Convert a thread group to ThreadGroup/ConcurrencyThreadGroup for applying of load """ msg = "Converting %s (%s) to %s and apply load parameters" self.log.debug(msg, group.gtype, group.get_testname(), target) on_error = group.get_on_error() if target == ThreadGroup.__name__: new_group_element = JMX.get_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, iterations=load.iterations, testname=group.get_testname(), on_error=on_error) elif target == ConcurrencyThreadGroup.__name__: new_group_element = JMX.get_concurrency_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, steps=load.steps, testname=group.get_testname(), on_error=on_error) else: self.log.warning('Unsupported preferred thread group: %s', target) return group.element.getparent().replace(group.element, new_group_element)
def convert(self, group, target, load, concurrency): """ Convert a thread group to ThreadGroup/ConcurrencyThreadGroup for applying of load """ msg = "Converting %s (%s) to %s and apply load parameters" self.log.debug(msg, group.gtype, group.get_testname(), target) on_error = group.get_on_error() if target == ThreadGroup.__name__: new_group_element = JMX.get_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, iterations=load.iterations, testname=group.get_testname(), on_error=on_error) elif target == ConcurrencyThreadGroup.__name__: new_group_element = JMX.get_concurrency_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, steps=load.steps, testname=group.get_testname(), on_error=on_error) else: self.log.warning('Unsupported preferred thread group: %s', target) return group.element.getparent().replace(group.element, new_group_element)
def get_sampler_pair(self, request): action = etree.Element( "com.blazemeter.jmeter.rte.sampler.RTESampler", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTESamplerGui", testclass="com.blazemeter.jmeter.rte.sampler.", testname=request.label) action.append( JMX._string_prop("RTESampler.action", request.config.get('rte-action'))) if "wait-for" in request.config: self._gen_wait(action, request.config.get("wait-for")) if 'fields' in request.config: inputs = JMX._collection_prop("Inputs.inputs") for _input in request.config["fields"]: inputs.append(self._gen_input_prop(_input)) elem_props = JMX._element_prop( "Inputs.inputs", "com.blazemeter.jmeter.rte.sampler.Inputs") elem_props.append(inputs) action.append(elem_props) if 'attention-key' in request.config: action.append( JMX._string_prop("RTESampler.attentionKey", request.config.get('attention-key'))) children = etree.Element("hashTree") if 'extract-cursor-position' in request.config and request.config.get( 'extract-cursor-position'): element = request.config.get('extract-cursor-position') extractor = self._gen_rte_extractor(element['varname'], "CURSOR_POSITION") children.append(extractor) children.append( etree.Element("hashTree") ) # Is this an RTE extension bug? doesn't seem necesary, # but won't work without it. if 'extract-field-position' in request.config and request.config.get( 'extract-field-position'): element = request.config.get('extract-field-position') position = element['base-position'].strip("()") row, column = position.split(",") offset = element['field-offset'] extractor = self._gen_rte_extractor(element['varname'], "NEXT_FIELD_POSITION", row, column, offset) children.append(extractor) children.append(etree.Element("hashTree")) return action, children
def _gen_managers(self, scenario): elements = [] if scenario.get("store-cache", True): elements.append(JMX._get_cache_mgr()) elements.append(etree.Element("hashTree")) if scenario.get("store-cookie", True): elements.append(JMX._get_cookie_mgr(scenario)) elements.append(etree.Element("hashTree")) if scenario.get("use-dns-cache-mgr", True): elements.append(JMX.get_dns_cache_mgr()) elements.append(etree.Element("hashTree")) self.system_props.merge({"system-properties": {"sun.net.inetaddr.ttl": 0}}) return elements
def _gen_rte_extractor(varname, type, row="", column="", offset=""): extractor = etree.Element( "com.blazemeter.jmeter.rte.extractor.RTEExtractor", guiclass="com.blazemeter.jmeter.rte.extractor.RTEExtractorGui", testclass="com.blazemeter.jmeter.rte.extractor.RTEExtractor", testname="Cursor extractor") extractor.append( JMX._string_prop("RTEExtractor.variablePrefix", varname)) extractor.append(JMX._string_prop("RTEExtractor.positionType", type)) extractor.append(JMX._string_prop("RTEExtractor.row", row)) extractor.append(JMX._string_prop("RTEExtractor.offset", offset)) extractor.append(JMX._string_prop("RTEExtractor.column", column)) return extractor
def _gen_managers(self, scenario): elements = [] if scenario.get("store-cache", True): elements.append(JMX._get_cache_mgr()) elements.append(etree.Element("hashTree")) if scenario.get("store-cookie", True): elements.append(JMX._get_cookie_mgr(scenario)) elements.append(etree.Element("hashTree")) if scenario.get("use-dns-cache-mgr", True): elements.append(JMX.get_dns_cache_mgr()) elements.append(etree.Element("hashTree")) self.system_props.merge( {"system-properties": { "sun.net.inetaddr.ttl": 0 }}) return elements
def convert(self, source, target_gtype, load, concurrency): """ Convert a thread group to ThreadGroup/ConcurrencyThreadGroup for applying of load """ msg = "Converting %s (%s) to %s and apply load parameters" self.log.debug(msg, source.gtype, source.get_testname(), target_gtype) on_error = source.get_on_error() if not concurrency: concurrency = source.get_concurrency(raw=True) if target_gtype == ThreadGroup.__name__: thread_delay = None scheduler_delay = None if source.gtype == target_gtype: thread_delay = source.get_thread_delay() scheduler_delay = source.get_scheduler_delay() new_group_element = JMX.get_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, iterations=load.iterations, testname=source.get_testname(), on_error=on_error, thread_delay=thread_delay, scheduler_delay=scheduler_delay) elif target_gtype == ConcurrencyThreadGroup.__name__: if source.gtype == target_gtype: iterations = source.get_iterations() else: iterations = "" new_group_element = JMX.get_concurrency_thread_group( concurrency=concurrency, rampup=load.ramp_up, hold=load.hold, steps=load.steps, testname=source.get_testname(), on_error=on_error, iterations=iterations) else: self.log.warning('Unsupported preferred thread group: %s', target_gtype) return source.element.getparent().replace(source.element, new_group_element)
def get_sampler_pair(self, request): timeout = self.safe_time(request.priority_option('timeout')) # convert body to string if isinstance(request.body, (dict, list, numeric_types)): if request.get_header( 'content-type') == 'application/json' or isinstance( request.body, numeric_types): request.body = json.dumps(request.body) elif not simple_body_dict(request.body): LOG.debug( 'Header "Content-Type: application/json" is required for body: "%s"', request.body) request.body = json.dumps(request.body) use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips( filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (request.body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request( request.url, request.label, request.method, timeout, request.body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def _gen_server_config(self, scenario): cfg = etree.Element( "ConfigTestElement", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTEConfigGui", testclass="ConfigTestElement", testname="Server Config") data = scenario.data server = data.get("rte-server").split(":") if server: cfg.append( JMX._string_prop("%sserver" % RTE_CONNECTION_CONFIG_, server[0])) cfg.append( JMX._string_prop("%sport" % RTE_CONNECTION_CONFIG_, server[1])) if len(server) > 1 else None cfg.append(JMX._string_prop("%sprotocol" % RTE_CONNECTION_CONFIG_, data['rte-protocol'])) if 'rte-protocol' in data \ else None if 'rte-config' in data: config = data.get('rte-config') cfg.append( JMX._string_prop("%ssslType" % RTE_CONNECTION_CONFIG_, config['ssl'])) if 'ssl' in config else None cfg.append(JMX._string_prop("%sterminalType" % RTE_CONNECTION_CONFIG_, config['terminal-type'])) if \ 'terminal-type' in config else None connection_timeout = self.safe_time(config['connection-timeout']) cfg.append(JMX._string_prop("%sconnectTimeout" % RTE_CONNECTION_CONFIG_, connection_timeout)) if \ 'connection-timeout' in config else None return [cfg, etree.Element("hashTree")]
def _gen_defaults(self, scenario): default_address = scenario.get("default-address", None) retrieve_resources = scenario.get("retrieve-resources", True) resources_regex = scenario.get("retrieve-resources-regex", None) concurrent_pool_size = scenario.get("concurrent-pool-size", 4) content_encoding = scenario.get("content-encoding", None) timeout = scenario.get("timeout", None) timeout = self.safe_time(timeout) elements = [JMX._get_http_defaults(default_address, timeout, retrieve_resources, concurrent_pool_size, content_encoding, resources_regex), etree.Element("hashTree")] return elements
def _gen_defaults(self, scenario): default_address = scenario.get("default-address", None) retrieve_resources = scenario.get("retrieve-resources", True) resources_regex = scenario.get("retrieve-resources-regex", None) concurrent_pool_size = scenario.get("concurrent-pool-size", 4) content_encoding = scenario.get("content-encoding", None) timeout = scenario.get("timeout", None) timeout = self.safe_time(timeout) elements = [ JMX._get_http_defaults(default_address, timeout, retrieve_resources, concurrent_pool_size, content_encoding, resources_regex), etree.Element("hashTree") ] return elements
def _gen_input_prop(_input): row, col, label, text, tabs = RTEProtocolHandler._handle_input_notation( _input) if row and col: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.CoordInputRowGUI") prop.append(JMX._string_prop("CoordInputRowGUI.row", row)) prop.append(JMX._string_prop("CoordInputRowGUI.column", col)) elif label: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.LabelInputRowGUI") prop.append(JMX._string_prop("LabelInputRowGUI.label", label)) elif tabs is not None: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.TabulatorInputRowGui") prop.append( JMX._string_prop("TabulatorInputOffsetGUI.column", tabs)) prop.append(JMX._string_prop("Input.input", text)) return prop
def _gen_input_prop(_input): row, col, label, text = RTEProtocolHandler._handle_input_notaiton( _input) if row and col: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.CoordInputRowGUI") prop.append(JMX._string_prop("CoordInputRowGUI.row", row)) prop.append(JMX._string_prop("CoordInputRowGUI.column", col)) elif label: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.LabelInputRowGUI") prop.append(JMX._string_prop("LabelInputRowGUI.label", label)) prop.append(JMX._string_prop("Input.input", text)) return prop
def _get_publish_sampler(request): mqtt = etree.Element("net.xmeter.samplers.PubSampler", guiclass="net.xmeter.gui.PubSamplerUI", testclass="net.xmeter.samplers.PubSampler", testname=request.label) topic_missed = TaurusConfigError( f'Topic is required for request "{request.config}"') mqtt.append( JMX._string_prop("mqtt.topic_name", request.config.get("topic", topic_missed))) mqtt.append(JMX._string_prop("mqtt.qos_level", "0")) mqtt.append(JMX._bool_prop("mqtt.add_timestamp", True)) mqtt.append(JMX._string_prop("mqtt.message_type", "String")) mqtt.append(JMX._string_prop("mqtt.message_type_fixed_length", "1024")) mqtt.append( JMX._string_prop("mqtt.message_to_sent", request.config.get("message", ""))) mqtt.append(JMX._bool_prop("mqtt.retained_message", False)) return mqtt
def _gen_server_config(self, config_data): config = etree.Element( "ConfigTestElement", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTEConfigGui", testclass="ConfigTestElement", testname="Server Config") if "rte-server" in config_data: server = config_data.get("rte-server").split(":") config.append( JMX._string_prop("RTEConnectionConfig.server", server[0])) if len(server) > 1: config.append( JMX._string_prop("RTEConnectionConfig.port", server[1])) if 'rte-protocol' in config_data: config.append( JMX._string_prop("RTEConnectionConfig.protocol", config_data['rte-protocol'])) if 'rte-config' in config_data: rte_config = config_data.get('rte-config') if 'ssl' in rte_config: config.append( JMX._string_prop("RTEConnectionConfig.sslType", rte_config['ssl'])) if 'terminal-type' in rte_config: config.append( JMX._string_prop("RTEConnectionConfig.terminalType", rte_config['terminal-type'])) if 'connection-timeout' in rte_config: connection_timeout = self.safe_time( rte_config['connection-timeout']) config.append( JMX._string_prop("RTEConnectionConfig.connectTimeout", connection_timeout)) return [config, etree.Element("hashTree")]
def _get_subscribe_sampler(request): mqtt = etree.Element("net.xmeter.samplers.SubSampler", guiclass="net.xmeter.gui.SubSamplerUI", testclass="net.xmeter.samplers.SubSampler", testname=request.label) topic_missed = TaurusConfigError( f'Topic is required for request "{request.config}"') time_interval = int(dehumanize_time(request.config.get("time", 1))) mqtt.append( JMX._string_prop("mqtt.topic_name", request.config.get("topic", topic_missed))) mqtt.append(JMX._string_prop("mqtt.qos_level", "0")) mqtt.append(JMX._bool_prop("mqtt.add_timestamp", False)) mqtt.append(JMX._bool_prop("mqtt.debug_response", False)) mqtt.append( JMX._string_prop("mqtt.sample_condition", "specified elapsed time (ms)")) mqtt.append( JMX._string_prop("mqtt.sample_condition_value", str(time_interval * 1000))) return mqtt
def _gen_wait(self, action, wait_for): action.append( JMX._bool_prop("%swaitSync" % RTE_SAMPLER_, 'sync' in wait_for)) if 'sync' in wait_for: sync_timeout = self.safe_time(wait_for['sync']) action.append( JMX._string_prop("%swaitSyncTimeout" % RTE_SAMPLER_, sync_timeout)) action.append( JMX._bool_prop("%swaitCursor" % RTE_SAMPLER_, 'cursor' in wait_for)) if 'cursor' in wait_for: cursor = wait_for['cursor'] if type(cursor) is unicode: row, column = cursor.split(',') else: row, column = cursor['position'].split(',') action.append( JMX._string_prop("%swaitCursorRow" % RTE_SAMPLER_, row)) action.append( JMX._string_prop("%swaitCursorColumn" % RTE_SAMPLER_, column)) if 'timeout' in cursor: cursor_timeout = self.safe_time(cursor['timeout']) action.append( JMX._string_prop("%swaitCursorTimeout" % RTE_SAMPLER_, cursor_timeout)) action.append( JMX._bool_prop("%swaitSilent" % RTE_SAMPLER_, 'silent' in wait_for)) if 'silent' in wait_for: silent = wait_for['silent'] if type(silent) is unicode: stable_time = self.safe_time(silent) else: stable_time = self.safe_time(silent['stable-time']) action.append( JMX._string_prop("%swaitSilentTime" % RTE_SAMPLER_, stable_time)) if 'timeout' in silent: silent_timeout = self.safe_time(silent['timeout']) action.append( JMX._string_prop("%swaitSilentTimeout" % RTE_SAMPLER_, silent_timeout)) action.append( JMX._bool_prop("%swaitText" % RTE_SAMPLER_, 'text' in wait_for)) if 'text' in wait_for: text = wait_for['text'] if type(text) is unicode: regex = text else: regex = text['regex'] action.append( JMX._string_prop("%swaitTextRegex" % RTE_SAMPLER_, regex)) timeout = self.safe_time(text['timeout']) action.append(JMX._string_prop("%swaitTextTimeout" % RTE_SAMPLER_, timeout)) if \ 'timeout' in text else None if 'search-area' in text: top, left, bot, right = re.findall(r'\d+', text['search-area']) action.append( JMX._string_prop("%swaitTextAreaTop" % RTE_SAMPLER_, top)) action.append( JMX._string_prop("%swaitTextAreaLeft" % RTE_SAMPLER_, left)) action.append( JMX._string_prop("%swaitTextAreaBottom" % RTE_SAMPLER_, bot)) action.append( JMX._string_prop("%swaitTextAreaRight" % RTE_SAMPLER_, right))
def _get_connect_sampler(request): mqtt = etree.Element("net.xmeter.samplers.ConnectSampler", guiclass="net.xmeter.gui.ConnectSamplerUI", testclass="net.xmeter.samplers.ConnectSampler", testname=request.label) mqtt.append( JMX._string_prop("mqtt.server", request.config.get("addr", "127.0.0.1"))) mqtt.append(JMX._string_prop("mqtt.port", "1883")) mqtt.append(JMX._string_prop("mqtt.version", "3.1")) mqtt.append(JMX._string_prop("mqtt.conn_timeout", "10")) mqtt.append(JMX._string_prop("mqtt.protocol", "TCP")) mqtt.append(JMX._string_prop("mqtt.ws_path", "")) mqtt.append(JMX._bool_prop("mqtt.dual_ssl_authentication", False)) mqtt.append(JMX._string_prop("mqtt.clientcert_file_path", "")) mqtt.append(JMX._string_prop("mqtt.clientcert_password", "")) mqtt.append(JMX._string_prop("mqtt.client_id_prefix", "conn_")) mqtt.append(JMX._bool_prop("mqtt.client_id_suffix", True)) mqtt.append(JMX._string_prop("mqtt.conn_keep_alive", "300")) mqtt.append(JMX._string_prop("mqtt.conn_attampt_max", "0")) mqtt.append(JMX._string_prop("mqtt.reconn_attampt_max", "0")) mqtt.append(JMX._string_prop("mqtt.conn_clean_session", "true")) return mqtt