Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
xunit.report_test_suite('sample_labels')
labels = self.last_second[DataPoint.CUMULATIVE]
for key in sorted(labels.keys()):
if key == "": # skip total label
continue
errors = []
for er_dict in labels[key][KPISet.ERRORS]:
rc = str(er_dict["rc"])
msg = str(er_dict["msg"])
cnt = str(er_dict["cnt"])
if er_dict["type"] == KPISet.ERRTYPE_ASSERT:
err_element = etree.Element("failure", message=msg, type="Assertion Failure")
else:
err_element = etree.Element("error", message=msg, type="Error")
err_desc = "%s\n(status code is %s)\n(total errors of this type: %s)" % (msg, rc, cnt)
err_element.text = err_desc
errors.append(err_element)
xunit.report_test_case('sample_labels', key, errors)
def __gen_options(self, scenario):
options = etree.Element("options")
global_think_time = scenario.get_think_time()
if global_think_time:
think_time = int(dehumanize_time(global_think_time))
options.append(etree.Element("option", name="thinktime", value=str(think_time), random="false"))
global_tcp_timeout = scenario.get("timeout")
if global_tcp_timeout:
timeout = int(dehumanize_time(global_tcp_timeout) * 1000)
options.append(etree.Element("option", name="connect_timeout", value=str(timeout)))
global_max_retries = scenario.get("max-retries", 1)
options.append(etree.Element("option", name="max_retries", value=str(global_max_retries)))
return options
def _get_once_controller():
"""
Generates Once Only Controller
:return: etree element, OnceOnlyController
"""
controller = etree.Element("OnceOnlyController", guiclass="OnceOnlyControllerGui",
testclass="OnceOnlyController", testname="Once Only Controller")
return controller
def get_set_var_action(udv_dict, testname="Variables from Taurus"):
"""
:type testname: str
:type udv_dict: dict[str,str]
:rtype: etree.Element
"""
udv_element = etree.Element(JMX.SET_VAR_ACTION, guiclass=JMX.SET_VAR_ACTION + "Gui",
testclass=JMX.SET_VAR_ACTION, testname=testname)
arg_element = etree.Element("elementProp", name="SetVariablesAction", guiclass="ArgumentsPanel",
testclass="Arguments", testname="User Defined Variables", elementType="Arguments")
udv_element.append(arg_element)
udv_collection_prop = JMX._collection_prop("Arguments.arguments")
arg_element.append(udv_collection_prop)
for var_name in sorted(udv_dict.keys(), key=str):
udv_element_prop = JMX._element_prop(name=str(var_name), element_type="Argument")
udv_collection_prop.append(udv_element_prop)
udv_arg_name_prop = JMX._string_prop("Argument.name", var_name)
udv_arg_value_prop = JMX._string_prop("Argument.value", udv_dict[var_name])
udv_arg_meta_prop = JMX._string_prop("Argument.metadata", "=")
udv_element_prop.append(udv_arg_name_prop)
udv_element_prop.append(udv_arg_value_prop)
udv_element_prop.append(udv_arg_meta_prop)
:return:
"""
actions = {
'stop': 0,
'pause': 1,
'stop-now': 2,
'continue': 3,
}
targets = {'current-thread': 0, 'all-threads': 2}
action = actions[block.action]
target = targets[block.target]
duration = 0
if block.duration is not None:
duration = int(block.duration * 1000)
test_action = JMX._get_action_block(action, target, duration)
children = etree.Element("hashTree")
self.__add_jsr_elements(children, block)
return [test_action, children]
def _flag(flag_name, bool_value):
"""
Generates element for JMX flag node
:param flag_name:
:param bool_value:
:return:
"""
elm = etree.Element(flag_name)
elm.text = "true" if bool_value else "false"
return elm
def __gen_clients(self):
# TODO: distributed clients?
clients = etree.Element("clients")
client = etree.Element("client", host="localhost", use_controller_vm="true")
clients.append(client)
return clients
def gen_statement(statement, indent=None):
if indent is None:
indent = PythonGenerator.INDENT_STEP * 2
statement_elem = etree.Element("statement", indent=str(indent))
statement_elem.text = statement
return statement_elem
def __jtl_writer(filename, label, flags):
"""
Generates JTL writer
:param filename:
:return:
"""
jtl = etree.Element("stringProp", {"name": "filename"})
jtl.text = filename
name = etree.Element("name")
name.text = "saveConfig"
value = etree.Element("value")
value.set("class", "SampleSaveConfiguration")
for key, val in iteritems(flags):
value.append(JMX._flag(key, val))
obj_prop = etree.Element("objProp")
obj_prop.append(name)
obj_prop.append(value)
listener = etree.Element("ResultCollector",
testname=label,
testclass="ResultCollector",
guiclass="SimpleDataWriter")
listener.append(jtl)
listener.append(obj_prop)
return listener
def _get_cache_mgr():
"""
:rtype: lxml.etree.Element
"""
mgr = etree.Element("CacheManager", guiclass="CacheManagerGui", testclass="CacheManager", testname="Cache")
mgr.append(JMX._bool_prop("clearEachIteration", True))
mgr.append(JMX._bool_prop("useExpires", True))
return mgr