From 5e48e02adde98bf1f7c24d13000d6b012e7acfa8 Mon Sep 17 00:00:00 2001 From: Simon Meggle Date: Tue, 6 Apr 2021 07:57:09 +0200 Subject: [PATCH 1/5] Using the right encoding saves the Etree py3.8 xml_declaration parameter --- agents/plugins/robotmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/plugins/robotmk b/agents/plugins/robotmk index 67db4048..d462170c 100644 --- a/agents/plugins/robotmk +++ b/agents/plugins/robotmk @@ -1047,7 +1047,7 @@ def xml_remove_html(content): if 'html' in s.attrib: s.text = '(Robotmk has removed this HTML content for safety reasons)' content_wo_html = ET.tostring( - xml, encoding='UTF-8', method='xml', xml_declaration=True).decode() + xml, encoding='utf8', method='xml').decode() return content_wo_html From 38f35dfb90787ff37954273017377d5510b57461 Mon Sep 17 00:00:00 2001 From: Simon Meggle Date: Tue, 6 Apr 2021 17:10:25 +0200 Subject: [PATCH 2/5] Fixed: Reference error in Check: two Robot tests on same host get same result, closes #117 --- checks/robotmk | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/checks/robotmk b/checks/robotmk index df99d8c8..627ee1a5 100644 --- a/checks/robotmk +++ b/checks/robotmk @@ -81,11 +81,11 @@ def parse_robot(info): "Can not load Robotmk JSON data! (json.loads())") runner_data = info_dict['runner'] - for idx, suite in enumerate(info_dict['suites']): + for idx, json_suite in enumerate(info_dict['suites']): for k in keys_to_decode: - if k in suite: - if bool(suite[k]): - d = suite[k] + if k in json_suite: + if bool(json_suite[k]): + d = json_suite[k] if runner_data['encoding'] == 'zlib_codec': d = d.encode('utf-8') d_byte = base64.b64decode(d) @@ -95,9 +95,9 @@ def parse_robot(info): d_decomp = base64.b64decode(d) else: d_decomp = d - suite[k] = d_decomp + json_suite[k] = d_decomp try: - xml = ET.fromstring(suite['xml']) + xml = ET.fromstring(json_suite['xml']) xml_root_suite = xml.find('./suite') except Exception: continue @@ -110,24 +110,20 @@ def parse_robot(info): discovery_setting = namedtuple( 'DiscoverySetting', 'level blacklist_pattern')._make(setting) # now process the root suite - # root_item = parse_suite_xml(xml_root_suite, discovery_setting) - # and reveal the items in the discovery level: - # suite['discovered_items'] = root_item.discovered - # suite['parsed'] = copy.deepcopy(root_item) - # suite['parsed'] = parse_suite_xml(xml_root_suite, discovery_setting) info_dict['suites'][idx]['parsed'] = parse_suite_xml( xml_root_suite, discovery_setting) + # info_dict['suites'][idx]['parsed'] = idx return info_dict -def inventory_robot(parsed): +def inventory_robot(info_dict): # TODO: Error handling for no suites/runner_data keys? - for root_suite in parsed['suites']: - if 'parsed' in root_suite: - for discovered_item in root_suite['parsed'].discovered: + for json_suite in info_dict['suites']: + if 'parsed' in json_suite: + for discovered_item in json_suite['parsed'].discovered: item_svc_name = add_svc_prefix(discovered_item.name, - root_suite) + json_suite) yield item_svc_name, None # The meta service reporting overall runtimes, stale spool files etc. svc_robotmk = get_setting('robotmk_service_name', 'Robotmk') @@ -382,6 +378,7 @@ def get_svc_prefix(itemname, root_suite): TAG=root_suite['tag'], SUITEID=root_suite['id'], SUITENAME=root_suite['parsed'].name, + # EXEC_MODE= SPACE=' ') return prefix @@ -410,8 +407,7 @@ class RobotItem(object): 'test': 'RobotTest', 'kw': 'RobotKeyword' } - # list of suites/tests/kw which were discovered (depending on discovery_level) - discovered = [] + indentation_char = u"\u2504" # Indentation chars. @@ -453,6 +449,12 @@ class RobotItem(object): # list containing all messages from cmk_runtime, cmk_metric of sub nodes self.sub_messages = [] + if self.parent is None: + # list of suites/tests/kw which were discovered (depending on discovery_level) + # Ref: yoczO3 + RobotItem.root_suite = self + self.discovered = [] + # Bool flag to indicate whether this is a node where messages should be added # (not needed for Keywords) self.is_topnode = False @@ -466,7 +468,8 @@ class RobotItem(object): # Empty blacklist = inventorize all if self.discovery_setting.blacklist_pattern == '' or not re.match( self.discovery_setting.blacklist_pattern, self.name): - self.discovered.append(self) + # Ref: yoczO3 + self.root_suite.discovered.append(self) def _get_id(self, xmlnode, index): """suites and tests have a id attribute. Fake this for keywords. @@ -943,8 +946,8 @@ class RobotKeyword(RobotItem): def parse_suite_xml(root_xml, discovery_setting): # Store discovery level RobotItem.discovery_setting = discovery_setting - # clear the class var - RobotItem.discovered = [] + # # clear the class var + # RobotItem.discovered = [] # create the topmost suite from the root XML root_suite = RobotSuite(root_xml, 0, 0, None, None) return root_suite From 8d37167996e34d7db64226e46ad8408337045a9f Mon Sep 17 00:00:00 2001 From: Simon Meggle Date: Tue, 6 Apr 2021 17:10:58 +0200 Subject: [PATCH 3/5] Removed EXEC_MODE from Discovery naming variables - senseless option --- web/plugins/wato/robotmk_wato_params_discovery.py | 1 - 1 file changed, 1 deletion(-) diff --git a/web/plugins/wato/robotmk_wato_params_discovery.py b/web/plugins/wato/robotmk_wato_params_discovery.py index 80568f4a..311f5ceb 100644 --- a/web/plugins/wato/robotmk_wato_params_discovery.py +++ b/web/plugins/wato/robotmk_wato_params_discovery.py @@ -138,7 +138,6 @@ def _valuespec_inventory_robotmk_rules(): ${SUITENAME} - Name of top level suite (usually same name as path)
${TAG} - Suite tag
${SUITEID} - short for ${PATH}_${TAG}
- ${EXEC_MODE} - Execution mode
${SPACE} - Use this if there should be a space between the prefix and the item name

The default format string is "Robot Framework E2E $SUITEID$SPACE-$SPACE". """)), From e091511b71c38e460064ecdd7984d526b6ea68b5 Mon Sep 17 00:00:00 2001 From: Simon Meggle Date: Tue, 6 Apr 2021 17:27:17 +0200 Subject: [PATCH 4/5] CHANGELOG --- CHANGELOG.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f51bf0..bb5c6caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,10 +19,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated +## [v1.0.1 - 2021-04-06 -## [v1.0.0-beta - 2021-03-11] +### Fixed + +- Two suites on same host were not inventorized correctly (#117) + +### Removed + +- Removed EXEC_MODE from discovery naming variables - useless + + +## [v1.0.0-beta - 2021-03-25] -WARNING: This first major release is 100% incompatible with former versions. +**WARNING: This first major release is 100% incompatible with former versions.** Make sure to export all WATO rules because this version is not able to read the old data structures. From 621eb6a1ab82c1a792cfb067f3537b04a7048655 Mon Sep 17 00:00:00 2001 From: Simon Meggle Date: Tue, 6 Apr 2021 17:28:11 +0200 Subject: [PATCH 5/5] Version bump v1.0.1 --- agents/plugins/robotmk | 2 +- checks/robotmk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agents/plugins/robotmk b/agents/plugins/robotmk index d462170c..987188ad 100644 --- a/agents/plugins/robotmk +++ b/agents/plugins/robotmk @@ -43,7 +43,7 @@ import platform import xml.etree.ElementTree as ET local_tz = datetime.utcnow().astimezone().tzinfo -ROBOTMK_VERSION = 'v1.0.0' +ROBOTMK_VERSION = 'v1.0.1' class RMKConfig(): diff --git a/checks/robotmk b/checks/robotmk index 627ee1a5..61129b5d 100644 --- a/checks/robotmk +++ b/checks/robotmk @@ -51,7 +51,7 @@ except: utc = pytz.utc -ROBOTMK_VERSION = 'v1.0.0' +ROBOTMK_VERSION = 'v1.0.1' DEFAULT_SVC_PREFIX = 'Robot Framework E2E $SUITEID$SPACE-$SPACE'