From: Ondrej Lichtner olichtne@redhat.com
This option was in the netperf module since the beginning and was never used once. I'm not sure what it's original purpose was, but I'm removing it now.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- test_modules/Netperf.py | 1 - 1 file changed, 1 deletion(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py index 4ff8643..2033c57 100644 --- a/test_modules/Netperf.py +++ b/test_modules/Netperf.py @@ -33,7 +33,6 @@ class Netperf(TestGeneric): self._testname = self.get_opt("testname", default="TCP_STREAM") self._confidence = self.get_opt("confidence") self._bind = self.get_opt("bind", opt_type="addr") - self._family = self.get_opt("family") self._cpu_util = self.get_opt("cpu_util") self._num_parallel = int(self.get_opt("num_parallel", default=1)) self._runs = self.get_opt("runs", default=1)
From: Ondrej Lichtner olichtne@redhat.com
This redirects the perfrepo imports to the systemwide python perfrepo library. This is part of separating the PerfRepo implementation into it's own package.
This adds a new dependency on the python-perfrepo package that you can find here: https://www.github.com/olichtne/python-perfrepo
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/Task.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index db4ef9c..19499da 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -13,9 +13,9 @@ rpazdera@redhat.com (Radek Pazdera) import hashlib import re import logging -from lnst.Controller.PerfRepo import PerfRepoRESTAPI -from lnst.Controller.PerfRepo import PerfRepoTestExecution -from lnst.Controller.PerfRepo import PerfRepoValue +from perfrepo import PerfRepoRESTAPI +from perfrepo import PerfRepoTestExecution +from perfrepo import PerfRepoValue from lnst.Common.Utils import dict_to_dot, list_to_dot, deprecated from lnst.Common.Config import lnst_config from lnst.Controller.XmlTemplates import XmlTemplateError
From: Ondrej Lichtner olichtne@redhat.com
This removes the PerfRepo module along with the CLI application since these have been moved to their own package.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/PerfRepo.py | 1034 ------------------------------------------- perfrepo | 772 -------------------------------- 2 files changed, 1806 deletions(-) delete mode 100644 lnst/Controller/PerfRepo.py delete mode 100755 perfrepo
diff --git a/lnst/Controller/PerfRepo.py b/lnst/Controller/PerfRepo.py deleted file mode 100644 index 04791e8..0000000 --- a/lnst/Controller/PerfRepo.py +++ /dev/null @@ -1,1034 +0,0 @@ -""" -This module contains the API for PerfRepo. - -Copyright 2015 Red Hat, Inc. -Licensed under the GNU General Public License, version 2 as -published by the Free Software Foundation; see COPYING for details. -""" - -__author__ = """ -olichtne@redhat.com (Ondrej Lichtner) -""" - -import requests -import datetime -import re -import logging -import xml.dom.minidom -import textwrap -import pprint -from types import StringType, NoneType -from xml.etree import ElementTree -from xml.etree.ElementTree import Element, iselement -from lnst.Common.Utils import recursive_dict_update -from lnst.Common.Utils import dot_to_dict, dict_to_dot, indent - -class PerfRepoException(Exception): - pass - -class PerfRepoObject(object): - def __init__(self): - pass - - def get_obj_url(self): - return "/" - - def _set_element_atrib(self, element, name, value): - if value != None: - element.set(str(name), str(value)) - - def to_xml(self): - pass - - def to_xml_string(self): - root = self.to_xml() - return ElementTree.tostring(root) - - def to_pretty_xml_string(self): - tmp_xml = xml.dom.minidom.parseString(self.to_xml_string()) - return tmp_xml.toprettyxml() - - def __str__(self): - return self.to_pretty_xml_string() - -class PerfRepoTest(PerfRepoObject): - def __init__(self, xml=None): - if type(xml) is NoneType: - self._id = None - self._name = None - self._uid = None - self._description = None - self._groupid = None - self._metrics = [] - elif type(xml) is StringType or iselement(xml): - if type(xml) is StringType: - root = ElementTree.fromstring(xml) - elif iselement(xml): - root = xml - - if root.tag != "test": - raise PerfRepoException("Invalid xml.") - - self._id = root.get("id") - self._name = root.get("name") - self._uid = root.get("uid") - self._groupid = root.get("groupId") - self._description = root.find("description").text - self._metrics = [] - for metric in root.find("metrics"): - if metric.tag != "metric": - continue - self._metrics.append(PerfRepoMetric(metric)) - else: - raise PerfRepoException("Parameter xml must be"\ - " a string, an Element or None") - - def get_obj_url(self): - return "/test/%s" % self._id - - def get_id(self): - return self._id - - def get_name(self): - return self._name - - def get_uid(self): - return self._uid - - def get_description(self): - return self._description - - def get_groupid(self): - return self._groupid - - def get_metrics(self): - return self._metrics - - def set_id(self, id): - self._id = id - - def set_name(self, name): - self._name = name - - def set_uid(self, uid): - self._uid = uid - - def set_description(self, description): - self._description = description - - def set_groupid(self, groupid): - self._groupid = groupid - - def add_metric(self, metric): - if not isinstance(metric, PerfRepoMetric): - return None - else: - self._metrics.append(metric) - return metric - - def to_xml(self): - root = Element('test') - self._set_element_atrib(root, 'id', self._id) - self._set_element_atrib(root, 'name', self._name) - self._set_element_atrib(root, 'uid', self._uid) - self._set_element_atrib(root, 'groupId', self._groupid) - description = ElementTree.SubElement(root, 'description') - description.text = str(self._description) - metrics = ElementTree.SubElement(root, 'metrics') - for metric in self._metrics: - metrics.append(metric.to_xml()) - - return root - - def __str__(self): - ret_str = """\ - id = %s - uid = %s - name = %s - groupid = %s - description: - """ % ( self._id, - self._uid, - self._name, - self._groupid) - ret_str = textwrap.dedent(ret_str) - ret_str += indent(self._description + "\n", 4) - ret_str += "metrics:\n" - for metric in self._metrics: - ret_str += indent(str(metric), 4) - ret_str += indent("------------------------\n", 4) - return textwrap.dedent(ret_str) - -class PerfRepoTestExecution(PerfRepoObject): - def __init__(self, xml=None): - if type(xml) is NoneType: - self._id = None - self._name = None - self._started = datetime.datetime.utcnow().isoformat() - self._testId = None - self._testUid = None - self._comment = "" - - self._values = [] - self._tags = [] - self._parameters = [] - elif type(xml) is StringType or iselement(xml): - if type(xml) is StringType: - root = ElementTree.fromstring(xml) - elif iselement(xml): - root = xml - - if root.tag != "testExecution": - raise PerfRepoException("Invalid xml.") - - self._id = root.get("id") - self._name = root.get("name") - self._started = root.get("started") - self._testId = root.get("testId") - self._testUid = root.get("testUid") - self._comment = root.find("comment").text - - self._values = [] - for value in root.find("values"): - if value.tag != "value": - continue - self._values.append(PerfRepoValue(value)) - - self._tags = [] - for tag in root.find("tags"): - if tag.tag != "tag": - continue - self._tags.append(tag.get("name")) - - self._parameters = [] - for param in root.find("parameters"): - if param.tag != "parameter": - continue - self._parameters.append((param.get("name"), param.get("value"))) - else: - raise PerfRepoException("Parameter xml must be"\ - " a string, an Element or None") - - def get_obj_url(self): - return "/exec/%s" % self._id - - def set_id(self, id): - self._id = id - - def get_id(self): - return self._id - - def set_name(self, name): - self._name = name - - def get_name(self): - return self._name - - def set_started(self, date=None): - if isinstance(date, NoneType): - self._started = datetime.datetime.utcnow().isoformat() - else: - self._started = date - - def get_started(self): - return self._started - - def set_testId(self, testId): - if isinstance(testId, PerfRepoTest): - self._testId = testId.get_id() - else: - self._testId = testId - - def get_testId(self): - return self._testId - - def set_testUid(self, testUid): - if isinstance(testUid, PerfRepoTest): - self._testUid = testUid.get_uid() - else: - self._testUid = testUid - - def get_testUid(self): - return self._testUid - - def set_comment(self, comment): - self._comment = comment - - def get_comment(self): - return self._comment - - def add_value(self, value): - self._values.append(value) - - def get_values(self): - return self._values - - def get_value(self, metric_name): - for val in self._values: - if val.get_metricName() == metric_name: - return val - - def add_tag(self, tag): - if tag is None: - return - self._tags.append(str(tag)) - - def get_tags(self): - return self._tags - - def add_parameter(self, name, value): - self._parameters.append((name, value)) - - def get_parameters(self): - return self._parameters - - def to_xml(self): - root = Element('testExecution') - self._set_element_atrib(root, 'id', self._id) - self._set_element_atrib(root, 'name', self._name) - self._set_element_atrib(root, 'started', self._started) - self._set_element_atrib(root, 'testId', self._testId) - self._set_element_atrib(root, 'testUid', self._testUid) - comment = ElementTree.SubElement(root, 'comment') - comment.text = str(self._comment) - - parameters = ElementTree.SubElement(root, 'parameters') - for param in self._parameters: - param_elem = ElementTree.SubElement(parameters, 'parameter') - self._set_element_atrib(param_elem, "name", param[0]) - self._set_element_atrib(param_elem, "value", param[1]) - - tags = ElementTree.SubElement(root, 'tags') - for tag in self._tags: - tag_elem = ElementTree.SubElement(tags, 'tag') - self._set_element_atrib(tag_elem, "name", tag) - - values = ElementTree.SubElement(root, 'values') - for value in self._values: - values.append(value.to_xml()) - - return root - - def __str__(self): - ret_str = """\ - id = %s - name = %s - date = %s - testId = %s - testUid = %s - comment = %s - tags = %s - """ % ( self._id, - self._name, - self._started, - self._testId, - self._testUid, - self._comment, - " ".join(self._tags)) - ret_str = textwrap.dedent(ret_str) - ret_str += "parameters:\n" - for param in self._parameters: - ret_str += indent("%s = %s\n" % (param[0], param[1]), 4) - ret_str += "values:\n" - for val in self._values: - ret_str += indent(str(val), 4) - ret_str += indent("------------------------\n", 4) - return textwrap.dedent(ret_str) - -class PerfRepoValue(PerfRepoObject): - def __init__(self, xml=None): - if type(xml) is NoneType: - self._metricComparator = None - self._metricName = None - self._result = None - self._parameters = [] - elif type(xml) is StringType or iselement(xml): - if type(xml) is StringType: - root = ElementTree.fromstring(xml) - elif iselement(xml): - root = xml - - if root.tag != "value": - raise PerfRepoException("Invalid xml.") - - self._metricComparator = root.get("metricComparator") - self._metricName = root.get("metricName") - self._result = float(root.get("result")) - - self._parameters = [] - for param in root.find("parameters"): - if param.tag != "parameter": - continue - self._parameters.append((param.get("name"), param.get("value"))) - else: - raise PerfRepoException("Parameter xml must be"\ - " a string, an Element or None") - - def set_result(self, result): - self._result = result - - def set_comparator(self, comparator): - if comparator not in ["HB", "LB"]: - raise PerfRepoException("Comparator must be HB/LB.") - self._metricComparator = comparator - - def set_metricName(self, name): - self._metricName = name - - def add_parameter(self, name, value): - self._parameters.append((name, value)) - - def get_parameters(self): - return self._parameters - - def get_metricName(self): - return self._metricName - - def get_comparator(self): - return self._metricComparator - - def get_result(self): - return self._result - - def to_xml(self): - root = Element('value') - self._set_element_atrib(root, 'metricComparator', - self._metricComparator) - self._set_element_atrib(root, 'metricName', self._metricName) - self._set_element_atrib(root, 'result', self._result) - - parameters = ElementTree.SubElement(root, 'parameters') - for param in self._parameters: - param_elem = ElementTree.SubElement(parameters, 'parameter') - self._set_element_atrib(param_elem, "name", param[0]) - self._set_element_atrib(param_elem, "value", param[1]) - return root - - def __str__(self): - ret_str = """\ - metric name = %s - result = %s - """ % ( self._metricName, - self._result) - ret_str = textwrap.dedent(ret_str) - ret_str += "parameters:\n" - for param in self._parameters: - ret_str += indent("%s = %s\n" % (param[0], param[1]), 4) - return textwrap.dedent(ret_str) - -class PerfRepoMetric(PerfRepoObject): - def __init__(self, xml=None): - if type(xml) is NoneType: - self._id = None - self._name = None - self._description = None - self._comparator = None - elif type(xml) is StringType or iselement(xml): - if type(xml) is StringType: - root = ElementTree.fromstring(xml) - elif iselement(xml): - root = xml - - if root.tag != "metric": - raise PerfRepoException("Invalid xml.") - - self._id = root.get("id") - self._name = root.get("name") - self._comparator = root.get("comparator") - self._description = root.find("description").text - else: - raise PerfRepoException("Parameter xml must be"\ - " a string, an Element or None") - - def get_id(self): - return self._id - - def get_name(self): - return self._id - - def get_description(self): - return self._description - - def get_comparator(self): - return self._comparator - - def set_id(self, id): - self._id = id - - def set_name(self, name): - self._name = name - - def set_description(self, description): - self._description = description - - def set_comparator(self, comparator): - if comparator not in ["HB", "LB"]: - raise PerfRepoException("Invalid comparator value.") - self._comparator = comparator - - def to_xml(self): - root = Element('metric') - self._set_element_atrib(root, 'id', self._id) - self._set_element_atrib(root, 'name', self._name) - description = ElementTree.SubElement(root, 'description') - description.text = str(self._description) - self._set_element_atrib(root, 'comparator', self._comparator) - - return root - - def __str__(self): - ret_str = """\ - id = %s - name = %s - comparator = %s - description: - """ % ( self._id, - self._name, - self._comparator) - ret_str = textwrap.dedent(ret_str) - ret_str += indent(self._description + "\n", 4) - return ret_str - -class PerfRepoReport(PerfRepoObject): - def __init__(self, xml=None): - self._user = None - if type(xml) is NoneType: - self._id = None - self._name = None - self._type = None - self._properties = {} - elif type(xml) is StringType or iselement(xml): - if type(xml) is StringType: - root = ElementTree.fromstring(xml) - elif iselement(xml): - root = xml - - if root.tag != "report": - raise PerfRepoException("Invalid xml.") - - self._id = root.get("id") - self._name = root.get("name") - self._type = root.get("type") - self._properties = {} - for entry in root.find("properties"): - if entry.tag != "entry": - continue - key_tag = entry.find("key") - value_tag = entry.find("value") - tmp_dict = dot_to_dict(value_tag.get("name"), - value_tag.get("value")) - recursive_dict_update(self._properties, tmp_dict) - else: - raise PerfRepoException("Parameter xml must be"\ - " a string, an Element or None") - - def get_obj_url(self): - return "/reports/%s/%s" % (self._type.lower(), self._id) - - def _find_max_num(self, str_tmp, search_dict): - max_num = -1 - for key, item in search_dict.items(): - match = re.match(r'%s(\d)+' % str_tmp, key) - if match == None: - continue - num = int(match.group(1)) - - if num > max_num: - max_num = num - return max_num - - def get_chart(self, chart_num): - chart_name = "chart%d" % chart_num - for key, chart in self._properties.items(): - if key == chart_name: - return chart - return None - - def add_chart(self, name, test_id): - max_chart_num = self._find_max_num("chart", self._properties) - - chart_name = "chart%d" % (max_chart_num + 1) - - new_chart = self._properties[chart_name] = {} - new_chart["name"] = str(name) - new_chart["test"] = str(test_id) - - return new_chart - - def del_chart(self, chart_num): - chart_name = "chart%d" % chart_num - - if chart_name in self._properties: - chart = self._properties[chart_name] - del self._properties[chart_name] - return chart - else: - return None - - def set_chart_name(self, chart_num, name): - chart = self.get_chart(chart_num) - - if chart: - chart["name"] = name - return chart - else: - return None - - def set_chart_test_id(self, chart_num, test_id): - chart = self.get_chart(chart_num) - - if chart: - chart["test"] = test_id - return chart - else: - return None - - def get_baseline(self, chart_num=0, index=-1): - chart = self.get_chart(chart_num) - - if chart is None: - return None - - if index >= 0: - baseline_name = "baseline%d" % (index) - for key, item in chart.items(): - if key == baseline_name: - return item - return None - else: - baselines = [] - for key, item in chart.items(): - if re.match(r'baseline\d+', key): - baselines.append(item) - if abs(index) <= len(baselines): - return baselines[index] - else: - return None - - def add_baseline(self, chart_num, name, exec_id, metric_id): - if chart_num is None: - chart_num = self._find_max_num("chart", self._properties) - - chart = self.get_chart(chart_num) - if chart is None: - return None - - max_baseline_num = self._find_max_num("baseline", chart) - - baseline_name = "baseline%d" % (max_baseline_num + 1) - - new_baseline = chart[baseline_name] = {} - new_baseline["name"] = str(name) - new_baseline["metric"] = str(metric_id) - new_baseline["execId"] = str(exec_id) - - return new_baseline - - def del_baseline(self, chart_num, baseline_num): - chart = self.get_chart(chart_num) - if chart is None: - return None - - baseline_name = "baseline%d" % (baseline_num) - - if baseline_name in chart: - baseline = chart[baseline_name] - del chart[baseline_name] - return baseline - else: - return None - - def set_baseline_name(self, chart_num, baseline_num, name): - baseline = self.get_baseline(chart_num, baseline_num) - - if baseline is None: - return None - - baseline["name"] = name - return baseline - - def set_baseline_metric(self, chart_num, baseline_num, metric_id): - baseline = self.get_baseline(chart_num, baseline_num) - - if baseline is None: - return None - - baseline["metric"] = metric_id - return baseline - - def set_baseline_execid(self, chart_num, baseline_num, exec_id): - baseline = self.get_baseline(chart_num, baseline_num) - - if baseline is None: - return None - - baseline["execId"] = exec_id - return baseline - - def add_series(self, chart_num, name, metric_id, tags=[]): - if chart_num is None: - chart_num = self._find_max_num("chart", self._properties) - - chart = self.get_chart(chart_num) - if chart is None: - return None - - max_series_num = self._find_max_num("series", chart) - - series_name = "series%d" % (max_series_num + 1) - - new_series = chart[series_name] = {} - new_series["name"] = name - new_series["metric"] = metric_id - new_series["tags"] = " ".join(tags) - - return new_series - - def get_series(self, chart_num, series_num): - chart = self.get_chart(chart_num) - if chart is None: - return None - - series_name = "series%d" % int(series_num) - for key, item in chart.items(): - if key == series_name: - return item - return None - - def del_series(self, chart_num, series_num): - if chart_num is None: - chart_num = self._find_max_num("chart", self._properties) - - chart = self.get_chart(chart_num) - if chart is None: - return None - - series_name = "series%d" % (series_num) - - if series_name in chart: - series = chart[series_name] - del chart[series_name] - return series - else: - return None - - def set_series_name(self, chart_num, series_num, name): - series = self.get_series(chart_num, series_num) - - if series is None: - return None - - series["name"] = name - return series - - def set_series_metric(self, chart_num, series_num, metric_id): - series = self.get_series(chart_num, series_num) - - if series is None: - return None - - series["metric"] = metric_id - return series - - def set_series_tags(self, chart_num, series_num, tags): - series = self.get_series(chart_num, series_num) - - if series is None: - return None - - series["tags"] = " ".join(tags) - return series - - def remove_series_tags(self, chart_num, series_num, remove_tags): - series = self.get_series(chart_num, series_num) - - if series is None: - return None - - tags = series["tags"].split(" ") - - for tag in remove_tags: - for i in range(tags.count(tag)): - tags.remove(tag) - - series["tags"] = " ".join(tags) - return series - - def add_series_tags(self, chart_num, series_num, add_tags): - series = self.get_series(chart_num, series_num) - - if series is None: - return None - - tags = series["tags"].split(" ") - - for tag in add_tags: - if tags.count(tag) == 0: - tags.append(tag) - - series["tags"] = " ".join(tags) - return series - - def set_id(self, new_id=None): - self._id = new_id - - def get_id(self): - return self._id - - def set_name(self, new_name=None): - self._name = new_name - - def get_name(self): - return self._name - - def set_type(self, new_type=None): - self._type = new_type - - def get_type(self): - return self._type - - def set_user(self, new_user=None): - self._user = new_user - - def get_user(self): - return self._user - - def to_xml(self): - root = Element('report') - self._set_element_atrib(root, 'id', self._id) - self._set_element_atrib(root, 'name', self._name) - self._set_element_atrib(root, 'type', self._type) - self._set_element_atrib(root, 'user', self._user) - - properties = ElementTree.SubElement(root, 'properties') - dot_props = dict_to_dot(self._properties) - for prop in dot_props: - entry_elem = ElementTree.SubElement(properties, 'entry') - key_elem = ElementTree.SubElement(entry_elem, 'key') - value_elem = ElementTree.SubElement(entry_elem, 'value') - - key_elem.text = str(prop[0]) - self._set_element_atrib(value_elem, 'name', prop[0]) - self._set_element_atrib(value_elem, 'value', prop[1]) - - return root - - def __str__(self): - str_props = pprint.pformat(self._properties) - ret_str = """\ - id = %s - name = %s - type = %s - properties = - """ % ( self._id, - self._name, - self._type) - ret_str = textwrap.dedent(ret_str) - ret_str += str_props - return textwrap.dedent(ret_str) - -class PerfRepoRESTAPI(object): - '''Wrapper class for the REST API provided by PerfRepo''' - def __init__(self, url, user, password): - self._url = url - self._user = user - self._password = password - - self._session = requests.Session() - self._session.auth = (self._user, self._password) - self._session.stream = True - self._session.headers['Content-Type'] = 'text/xml' - logging.getLogger("requests").setLevel(logging.WARNING) - - def get_obj_url(self, obj): - if not isinstance(obj, PerfRepoObject): - return "" - return self._url + obj.get_obj_url() - - def test_get_by_id(self, test_id, log=True): - get_url = self._url + '/rest/test/id/%s' % test_id - response = self._session.get(get_url) - if response.status_code != 200: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("GET %s success" % get_url) - return PerfRepoTest(response.content) - - def test_get_by_uid(self, test_uid, log=True): - get_url = self._url + '/rest/test/uid/%s' % test_uid - response = self._session.get(get_url) - if response.status_code != 200: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("GET %s success" % get_url) - return PerfRepoTest(response.content) - - def test_create(self, test, log=True): - post_url = self._url + '/rest/test/create' - response = self._session.post(post_url, data=test.to_xml_string()) - if response.status_code != 201: - if log: - logging.debug(response.text) - return None - else: - new_id = response.headers["Location"].split('/')[-1] - test.set_id(new_id) - if log: - logging.debug("POST %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(test)) - return test - - def test_add_metric(self, test_id, metric, log=True): - post_url = self._url + '/rest/test/id/%s/addMetric' % test_id - response = self._session.post(post_url, data=metric.to_xml_string) - if response.status_code != 201: - if log: - logging.debug(response.text) - return None - else: - new_id = response.headers["Location"].split('/')[-1] - metric.set_id(new_id) - if log: - logging.debug("POST %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(metric)) - return metric - - def test_delete(self, test_id, log=True): - delete_url = self._url + '/rest/test/id/%s' % test_id - response = self._session.delete(delete_url) - if response.status_code != 204: - return False - else: - if log: - logging.debug("DELETE %s success" % delete_url) - return True - - def metric_get(self, metric_id, log=True): - get_url = self._url + '/rest/metric/%s' % metric_id - response = self._session.get(get_url) - if response.status_code != 200: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("GET %s success" % get_url) - return PerfRepoMetric(response.content) - - def testExecution_get(self, testExec_id, log=True): - get_url = self._url + '/rest/testExecution/%s' % testExec_id - response = self._session.get(get_url) - if response.status_code != 200: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("GET %s success" % get_url) - return PerfRepoTestExecution(response.content) - - def testExecution_create(self, testExec, log=True): - post_url = self._url + '/rest/testExecution/create' - response = self._session.post(post_url, data=testExec.to_xml_string()) - if response.status_code != 201: - if log: - logging.debug(response.text) - return None - else: - new_id = response.headers["Location"].split('/')[-1] - testExec.set_id(new_id) - if log: - logging.debug("POST %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(testExec)) - return testExec - - def testExecution_delete(self, testExec_id, log=True): - delete_url = self._url + '/rest/testExecution/%s' % testExec_id - response = self._session.delete(delete_url) - if response.status_code != 204: - if log: - logging.debug(response.text) - return False - else: - if log: - logging.debug("DELETE %s success" % delete_url) - return True - - def testExecution_add_value(self, value, log=True): - post_url = self._url + '/rest/testExecution/addValue' - #TODO - return self._session.post(post_url, data=value) - - def testExecution_get_attachment(self, attachment_id, log=True): - get_url = self._url + '/rest/testExecution/attachment/%s' % \ - attachment_id - #TODO - return self._session.get(get_url) - - def testExecution_add_attachment(self, testExec_id, attachment, log=True): - post_url = self._url + '/rest/testExecution/%s/addAttachment' % \ - testExec_id - #TODO - return self._session.post(post_url, data=attachment) - - def report_get_by_id(self, report_id, log=True): - get_url = self._url + '/rest/report/id/%s' % report_id - response = self._session.get(get_url) - if response.status_code != 200: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("GET %s success" % get_url) - return PerfRepoReport(response.content) - - def report_create(self, report, log=True): - post_url = self._url + '/rest/report/create' - - report.set_user(self._user) - - response = self._session.post(post_url, data=report.to_xml_string()) - if response.status_code != 201: - if log: - logging.debug(response.text) - return None - else: - new_id = response.headers["Location"].split('/')[-1] - report.set_id(new_id) - if log: - logging.debug("POST %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(report)) - return report - - def report_update(self, report, log=True): - post_url = self._url + '/rest/report/update/%s' % report.get_id() - - report.set_user(self._user) - - response = self._session.post(post_url, data=report.to_xml_string()) - if response.status_code != 201: - if log: - logging.debug(response.text) - return None - else: - if log: - logging.debug("UPDATE %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(report)) - return report - - def report_delete_by_id(self, report_id, log=True): - delete_url = self._url + '/rest/report/id/%s' % report_id - response = self._session.delete(delete_url) - if response.status_code != 204: - return False - else: - if log: - logging.debug("DELETE %s success" % delete_url) - return True diff --git a/perfrepo b/perfrepo deleted file mode 100755 index e4fa719..0000000 --- a/perfrepo +++ /dev/null @@ -1,772 +0,0 @@ -#! /usr/bin/env python2 -""" - -Copyright 2015 Red Hat, Inc. -Licensed under the GNU General Public License, version 2 as -published by the Free Software Foundation; see COPYING for details. -""" - -from __future__ import print_function - -__author__ = """ -olichtne@redhat.com (Ondrej Lichtner) -""" - -import sys -import logging -import os -import re -import datetime -import lnst.Controller.PerfRepo as PerfRepo -from lnst.Controller.PerfRepo import PerfRepoRESTAPI -from lnst.Common.Config import lnst_config - -def usage(retval=0, f=sys.stderr): - """ - Print usage of this app - """ - print("Usage: %s [OPTIONS...] OBJECT {COMMAND | help} [COMMAND_OPTS]" % sys.argv[0], file=f) - print("", file=f) - print("OBJECT := { report | testexec | test }", file=f) - print("OPTIONS := { -u URL | --url URL |", file=f) - print(" -n USERNAME | --username USERNAME |", file=f) - print(" -p PASSWORD | --password PASSWORD |", file=f) - print(" -c FILE | --config FILE}", file=f) - sys.exit(retval) - - -class GenericCLI(object): - def __init__(self, url, username, password, argv): - if url is not None: - self._url = url - else: - self._url = lnst_config.get_option("perfrepo", "url") - - if username is not None: - self._username = username - else: - self._username = lnst_config.get_option("perfrepo", "username") - - if password is not None: - self._password = password - else: - self._password = lnst_config.get_option("perfrepo", "password") - - self._argv = argv - self._perf_api = PerfRepoRESTAPI(self._url, - self._username, - self._password) - - def usage(self, f=sys.stderr): - pass - - def run(self): - print("Not implemented yet!", file=sys.stderr) - self.usage() - return -1 - -class TestCLI(GenericCLI): - def usage(self, f=sys.stderr): - """ - Print usage for the report object - """ - print("Usage: %s test help" % sys.argv[0], file=f) - print("", file=f) - print(" %s test get {ID | UID}" % sys.argv[0], file=f) - print(" %s test show {ID | UID}" % sys.argv[0], file=f) - print("", file=f) - print(" %s test create" % sys.argv[0], file=f) - print(" name NAME", file=f) - print(" uid UID", file=f) - print(" groupid GID", file=f) - print(" [description DESCRIPTION]", file=f) - print(" [metric ID ...]", file=f) - print("", file=f) - print(" %s test delete ID" % sys.argv[0], file=f) - - def _do_create(self, argv): - test = PerfRepo.PerfRepoTest() - i = 0 - try: - while i < len(argv): - if argv[i] == "name": - test.set_name(argv[i+1]) - i += 2 - continue - elif argv[i] == "uid": - test.set_uid(argv[i+1]) - i += 2 - continue - elif argv[i] == "groupid": - test.set_groupid(argv[i+1]) - i += 2 - continue - elif argv[i] == "description": - test.set_description(argv[i+1]) - i += 2 - continue - elif argv[i] == "metric": - metric = PerfRepo.PerfRepoMetric() - metric.set_id(argv[i+1]) - test.add_metric(metric) - i += 2 - continue - else: - print("Argument '%s' not supported for test create!" % argv[i]) - return -1 - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return -1 - - if test.get_name() is None: - print("Name not specified!") - return -1 - elif test.get_uid() is None: - print("UID not specified!") - return -1 - elif test.get_groupid() is None: - print("GID not specified!") - return -1 - - test = self._perf_api.test_create(test) - print("Created test with url: %s" % self._perf_api.get_obj_url(test)) - return 0 - - def _do_delete(self, argv): - if len(argv) < 1: - print("Test delete requires an ID!") - return -1 - if self._perf_api.test_delete(argv[0]): - print("Test deleted") - else: - print("Test not found") - return -1 - return 0 - - def run(self): - argv = self._argv - if len(argv) == 0: - return -1 - elif argv[0] == "help": - self.usage(sys.stdout) - return 0 - elif argv[0] in ["get", "show"]: - try: - test_id = int(argv[1]) - test = self._perf_api.test_get_by_id(test_id) - if test is None: - test = self._perf_api.test_get_by_uid(test_id) - if test is None: - print("Test not found.") - else: - print(test) - except IndexError: - print("No ID specified!", file=sys.stderr) - return -1 - except ValueError: - print("ID needs to be an integer!", file=sys.stderr) - return -1 - elif argv[0] == "create": - self._do_create(argv[1:]) - elif argv[0] == "delete": - self._do_delete(argv[1:]) - else: - print("Command '%s' not implemented for Tests." % argv[0], file=sys.stderr) - return -1 - return 0 - -class TestExecCLI(GenericCLI): - def usage(self, f=sys.stderr): - """ - Print usage for the report object - """ - print("Usage: %s texec help" % sys.argv[0], file=f) - print("", file=f) - print(" %s texec get ID" % sys.argv[0], file=f) - print(" %s texec show ID" % sys.argv[0], file=f) - print("", file=f) - print(" %s testexec create" % sys.argv[0], file=f) - print(" name NAME", file=f) - print(" {testid ID | testuid UID}", file=f) - print(" [comment COMMENT]", file=f) - print(" value NAME=VAL [value NAME=value ...]", file=f) - print(" tags TAG,[TAG,...]", file=f) - print(" [param NAME=VAL ...]", file=f) - print("", file=f) - print(" %s testexec delete ID" % sys.argv[0], file=f) - - def _do_create(self, argv): - texec = PerfRepo.PerfRepoTestExecution() - i = 0 - try: - while i < len(argv): - if argv[i] == "name": - texec.set_name(argv[i+1]) - i += 2 - continue - elif argv[i] == "testid": - texec.set_testId(argv[i+1]) - i += 2 - continue - elif argv[i] == "testuid": - texec.set_testUid(argv[i+1]) - i += 2 - continue - elif argv[i] == "comment": - texec.set_comment(argv[i+1]) - i += 2 - continue - elif argv[i] == "tags": - tags = argv[i+1].split(",") - for tag in tags: - texec.add_tag(tag) - i += 2 - continue - elif argv[i] == "param": - param = argv[i+1].split("=") - try: - param_name = param[0] - param_val = param[1] - except: - print("Invalid param '%s'" % argv[i+1]) - - texec.add_parameter(param_name, param_val) - i += 2 - elif argv[i] == "value": - value = argv[i+1].split("=") - try: - value_name = value[0] - value_val = float(value[1]) - except: - print("Invalid value '%s'" % argv[i+1]) - - value = PerfRepo.PerfRepoValue() - value.set_metricName(value_name) - value.set_result(value_val) - - texec.add_value(value) - i += 2 - continue - else: - print("Argument '%s' not supported for test create!" % argv[i]) - return -1 - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return -1 - - if texec.get_name() is None: - print("Name not specified!") - return -1 - elif texec.get_testUid() is None and texec.get_testId() is None: - print("Test ID/UID not specified!") - return -1 - - texec = self._perf_api.testExecution_create(texec) - print("Created TestExecution with url: %s" % self._perf_api.get_obj_url(texec)) - return 0 - - def _do_delete(self, argv): - if len(argv) < 1: - print("TestExecution delete requires an ID!") - return -1 - if self._perf_api.testExecution_delete(argv[0]): - print("TestExecution removed") - else: - print("TestExecution not found") - return -1 - return 0 - - def run(self): - argv = self._argv - if len(argv) == 0: - return -1 - elif argv[0] == "help": - self.usage(sys.stdout) - return 0 - elif argv[0] in ["get", "show"]: - try: - exec_id = int(argv[1]) - texec = self._perf_api.testExecution_get(exec_id) - if texec is None: - print("TestExecution not found.") - else: - print(texec) - except IndexError: - print("No ID specified!", file=sys.stderr) - return -1 - except ValueError: - print("ID needs to be an integer!", file=sys.stderr) - return -1 - elif argv[0] == "create": - self._do_create(argv[1:]) - return 0 - elif argv[0] == "delete": - self._do_delete(argv[1:]) - return 0 - else: - print("Command '%s' not implemented for TestExecutions." % argv[0], file=sys.stderr) - return -1 - return 0 - -class ReportCLI(GenericCLI): - def usage(self, f=sys.stderr): - """ - Print usage for the report object - """ - print("Usage: %s report help" % sys.argv[0], file=f) - print("", file=f) - print(" %s report get ID" % sys.argv[0], file=f) - print(" %s report show ID" % sys.argv[0], file=f) - print("", file=f) - print(" %s report create" % sys.argv[0], file=f) - print(" name NAME [type TYPE]", file=f) - print(" chart NAME", file=f) - print(" {testid ID | testuid UID}", file=f) - print(" series NAME", file=f) - print(" metric ID", file=f) - print(" tags TAG[,TAG,...]", file=f) - print(" baseline NAME", file=f) - print(" execid ID", file=f) - print(" metric ID", file=f) - print(" %s report update" % sys.argv[0], file=f) - print(" id ID", file=f) - print(" [name NAME]", file=f) - print(" OP chart [NUM | NAME]", file=f) - print(" [testid ID | testuid UID]", file=f) - print(" [name NAME]", file=f) - print(" [ OP series [NUM | NAME] ]", file=f) - print(" [name NAME]", file=f) - print(" [metric ID]", file=f) - print(" [+tags TAG[,TAG,...] ]", file=f) - print(" [-tags TAG[,TAG,...] ]", file=f) - print(" [ OP baseline [ NUM | NAME] ]", file=f) - print(" [name NAME]", file=f) - print(" [execid ID]", file=f) - print(" [metric ID]", file=f) - print(" WHERE OP is [add | del | edit]", file=f) - print(" edit is implicit - noOP == 'edit'", file=f) - print(" OPs 'edit' and 'del' require NUM, whereas 'add' requires NAME", file=f) - print(" if chart OP == 'add' then all further OPs are 'add' as in the 'report create' command", file=f) - - def _parse_baseline(self, argv): - baseline = {} - baseline["name"] = argv[0] - - i = 1 - try: - while i < len(argv): - if argv[i] == "execid": - baseline["execid"] = argv[i+1] - i += 2 - continue - elif argv[i] == "metric": - baseline["metric"] = argv[i+1] - i += 2 - continue - else: - return (baseline, i) - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return ({}, 0) - return (baseline, i) - - def _parse_series(self, argv): - series = {"tags": []} - series["name"] = argv[0] - - i = 1 - try: - while i < len(argv): - if argv[i] == "tags": - tags = argv[i+1].split(",") - series["tags"] = tags - i += 2 - continue - elif argv[i] == "metric": - series["metric"] = argv[i+1] - i += 2 - continue - else: - return (series, i) - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return ({}, 0) - return (series, i) - - def _parse_chart_add(self, argv): - chart = {"series": [], "baselines": []} - - baseline = None - series = None - - chart["name"] = argv[0] - i = 1 - try: - while i < len(argv): - if argv[i] == "testid": - chart["test"] = argv[i+1] - i += 2 - continue - elif argv[i] == "testuid": - test = self._perf_api.test_get_by_uid(argv[i+1]) - chart["test"] = test.get_id() - i += 2 - continue - elif argv[i] == "series": - series, new_i = self._parse_series(argv[i+1:]) - chart["series"].append(series) - i += 1 + new_i - elif argv[i] == "baseline": - baseline, new_i = self._parse_baseline(argv[i+1:]) - chart["baselines"].append(baseline) - i += 1 + new_i - continue - else: - return (chart, i) - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return ({}, 0) - return (chart, i) - - def _report_add_chart(self, report, chart): - report.add_chart(chart["name"], chart["test"]) - - for baseline in chart["baselines"]: - try: - report.add_baseline(None, baseline["name"], - baseline["execid"], - baseline["metric"]) - except KeyError as e: - print("Parameter '%s' is required for a baseline!" %\ - e.args[0]) - return -1 - - for series in chart["series"]: - try: - report.add_series(None, series["name"], - series["metric"], - series["tags"]) - except KeyError as e: - print("Parameter '%s' is required for a series!" %\ - e.args[0]) - return -1 - return 0 - - def _do_create(self, argv): - charts = [] - i = 1 - series = None - baseline = None - - report = PerfRepo.PerfRepoReport() - report.set_type("Metric") - - try: - while i < len(argv): - if argv[i] == "name": - if report.get_name() is None: - report.set_name(argv[i+1]) - i += 2 - continue - else: - print("Report name already specified!", - file=sys.stderr) - return -1 - elif argv[i] == "type": - report.set_type(argv[i+1]) - i += 2 - continue - elif argv[i] == "chart": - chart, new_i = self._parse_chart_add(argv[i+1:]) - charts.append(chart) - i += 1 + new_i - continue - else: - print("Parameter '%s' not defined/implemented!" %\ - argv[i], file=sys.stderr) - return -1 - except IndexError: - print("Parameter '%s' requires a value!" % argv[i]) - return -1 - - if report.get_name() is None: - print("Report name not specified!", file=sys.stderr) - return -1 - - for chart in charts: - self._report_add_chart(report, chart) - - report = self._perf_api.report_create(report) - print("Created report with url: %s" % self._perf_api.get_obj_url(report)) - return 0 - - def _do_update(self, argv): - report_id = None - try: - if argv[1] != "id": - print("Parameter 'id' is required!", file=sys.stderr) - return -1 - report_id = str(int(argv[2])) - except IndexError: - print("Parameter 'id' is required!", file=sys.stderr) - return -1 - except ValueError: - print("Value of parameter 'id' must be a number!", file=sys.stderr) - return -1 - - report = self._perf_api.report_get_by_id(report_id) - if report is None: - print("Invalid ID specified!", file=sys.stderr) - return -1 - - i = 3 - while i < len(argv): - if argv[i] == "name": - report.set_name(argv[i+1]) - i += 2 - continue - - op = "edit" - if argv[i] in ["add", "del", "edit"]: - op = argv[i] - i += 1 - if argv[i] == "chart": - if op == "add": - chart, new_i = self._parse_chart_add(argv[i+1:]) - i += 1 + new_i - - self._report_add_chart(report, chart) - elif op == "edit": - chart_num = int(argv[i+1]) - i += 2 - while i < len(argv): - if argv[i] == "name": - report.set_chart_name(chart_num, argv[i+1]) - i += 2 - continue - elif argv[i] == "testid": - report.set_chart_test_id(chart_num, argv[i+1]) - i += 2 - continue - elif argv[i] == "testuid": - test = self._perf_api.test_get_by_uid(argv[i+1]) - report.set_chart_test_id(chart_num, test.get_id()) - i += 2 - continue - - op2 = "edit" - if argv[i] in ["add", "del", "edit"]: - op = argv[i] - i += 1 - - if argv[i] == "series": - if op == "add": - series, new_i = self._parse_series(argv[i+1:]) - i += 1 + new_i - try: - report.add_series(chart_num, - series["name"], - series["metric"], - series["tags"]) - except KeyError as e: - print("Parameter '%s' is required for a series!"\ - % e.args[0]) - return -1 - elif op == "edit": - series_num = int(argv[i+1]) - i += 2 - while i < len(argv): - if argv[i] == "name": - report.set_series_name(chart_num, - series_num, - argv[i+1]) - i += 2 - continue - elif argv[i] == "metric": - report.set_series_metric(chart_num, - series_num, - argv[i+1]) - i += 2 - continue - elif argv[i] == "+tags": - tags = argv[i+1].split(',') - report.add_series_tags(chart_num, - series_num, - tags) - i += 2 - continue - elif argv[i] == "-tags": - tags = argv[i+1].split(',') - report.remove_series_tags(chart_num, - series_num, - tags) - i += 2 - continue - else: - break - elif op == "del": - series_num = int(argv[i+1]) - report.del_series(chart_num, series_num) - i += 2 - continue - elif argv[i] == "baseline": - if op == "add": - baseline, new_i = self._parse_baseline(argv[i+1:]) - i += 1 + new_i - - try: - report.add_baseline(None, baseline["name"], - baseline["metric"], - baseline["execid"]) - except KeyError as e: - print("Parameter '%s' is required for a baseline!"\ - % e.args[0]) - return -1 - elif op == "edit": - baseline_num = int(argv[i+1]) - i += 2 - while i < len(argv): - if argv[i] == "name": - report.set_baseline_name(chart_num, - baseline_num, - argv[i+1]) - i += 2 - continue - elif argv[i] == "metric": - report.set_baseline_metric(chart_num, - baseline_num, - argv[i+1]) - i += 2 - continue - elif argv[i] == "execid": - report.set_baseline_execid(chart_num, - baseline_num, - argv[i+1]) - i += 2 - continue - else: - break - elif op == "del": - baseline_num = int(argv[i+1]) - report.del_baseline(chart_num, baseline_num) - i += 2 - continue - else: - break - - elif op == "del": - chart_num = int(argv[i+1]) - report.del_chart(chart_num) - i += 2 - continue - else: - print("Unknown parameter '%s'!" % argv[i]) - return -1 - self._perf_api.report_update(report) - return 0 - - def run(self): - argv = self._argv - if len(argv) == 0: - return -1 - elif argv[0] == "help": - self.usage(sys.stdout) - return 0 - elif argv[0] in ["get", "show"]: - try: - report_id = int(argv[1]) - report = self._perf_api.report_get_by_id(report_id) - print(report) - except IndexError: - print("No ID specified!", file=sys.stderr) - return -1 - except ValueError: - print("ID needs to be an integer!", file=sys.stderr) - return -1 - elif argv[0] in ["create"]: - return self._do_create(argv) - elif argv[0] in ["update"]: - return self._do_update(argv) - elif argv[0] in ["delete"]: - try: - report_id = int(argv[1]) - result = self._perf_api.report_delete_by_id(report_id) - if result: - print("Report deleted.") - else: - print("Report delete failed.") - except IndexError: - print("No ID specified!", file=sys.stderr) - return -1 - except ValueError: - print("ID needs to be an integer!", file=sys.stderr) - return -1 - else: - print("Command '%s' not implemented for Reports." % argv[0], file=sys.stderr) - return -1 - return 0 - -def main(): - """ - Main function - """ - cli_classes = {"report": ReportCLI, - "testexec": TestExecCLI, - "test": TestCLI} - obj = None - conf_file = None - url = None - username = None - password = None - - i = 1 - while obj is None and i < len(sys.argv): - if sys.argv[i] in cli_classes: - obj = sys.argv[i] - i += 1 - elif sys.argv[i] in ["-u", "--url"]: - url = sys.argv[i+1] - i += 2 - elif sys.argv[i] in ["-n", "--username"]: - username = sys.argv[i+1] - i += 2 - elif sys.argv[i] in ["-p", "--password"]: - password = sys.argv[i+1] - i += 2 - elif sys.argv[i] in ["-c", "--config"]: - conf_file = sys.argv[i+1] - i += 2 - elif sys.argv[i] in ["-h", "--help", "help"]: - usage(0, sys.stdout) - else: - usage(-1) - - if obj is None: - usage(0, f=sys.stdout) - else: - lnst_config.controller_init() - dirname = os.path.dirname(sys.argv[0]) - gitcfg = os.path.join(dirname, "lnst-ctl.conf") - if os.path.isfile(gitcfg): - lnst_config.load_config(gitcfg) - else: - lnst_config.load_config('/etc/lnst-ctl.conf') - - usr_cfg = os.path.expanduser('~/.lnst/lnst-ctl.conf') - if os.path.isfile(usr_cfg): - lnst_config.load_config(usr_cfg) - - if conf_file is not None: - lnst_config.load_config(conf_file) - - cli = cli_classes[obj](url, username, password, sys.argv[i:]) - ret_val = cli.run() - - if ret_val < 0: - cli.usage() - return ret_val - - return 0 - -if __name__ == "__main__": - sys.exit(main())
Thu, Dec 03, 2015 at 02:59:46PM CET, olichtne@redhat.com wrote:
From: Ondrej Lichtner olichtne@redhat.com
This option was in the netperf module since the beginning and was never used once. I'm not sure what it's original purpose was, but I'm removing it now.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com
test_modules/Netperf.py | 1 - 1 file changed, 1 deletion(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py index 4ff8643..2033c57 100644 --- a/test_modules/Netperf.py +++ b/test_modules/Netperf.py @@ -33,7 +33,6 @@ class Netperf(TestGeneric): self._testname = self.get_opt("testname", default="TCP_STREAM") self._confidence = self.get_opt("confidence") self._bind = self.get_opt("bind", opt_type="addr")
self._family = self.get_opt("family") self._cpu_util = self.get_opt("cpu_util") self._num_parallel = int(self.get_opt("num_parallel", default=1)) self._runs = self.get_opt("runs", default=1)
-- 2.6.2 _______________________________________________ LNST-developers mailing list lnst-developers@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
ack to series
Acked-by: Jan Tluka jtluka@redhat.com
lnst-developers@lists.fedorahosted.org