From 1bde852751996300485ae9f4d2e985eeed287bf5 Mon Sep 17 00:00:00 2001 From: croy Date: Wed, 19 Feb 2025 12:08:22 -0500 Subject: [PATCH] Improvement to SystemTableParser - Handling loose lines - Handling \x1b[?2004l prefix - Supporting '+' mid-line for timestamp values Change-Id: If53b06a41cd93d975d07ad69ffd548f1c14c9af6 --- .../system/system_table_parser.py | 6 +++- unit_tests/parser/system_parser_test.py | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/keywords/cloud_platform/system/system_table_parser.py b/keywords/cloud_platform/system/system_table_parser.py index a14262da..01b467e9 100644 --- a/keywords/cloud_platform/system/system_table_parser.py +++ b/keywords/cloud_platform/system/system_table_parser.py @@ -42,8 +42,12 @@ class SystemTableParser: for line in self.system_output: + # Skip lines that aren't part of the table. + if not (line.startswith("|") or line.__contains__("+--")): + continue + # We have hit a separator which enters Headers, Content, or Ends the table - if line.__contains__('+'): + if line.__contains__('+--'): # Find out in which part of the table we are, based on the "+----" separator. if not is_in_headers_block and not is_in_content_block: # First separator -> Enter Headers diff --git a/unit_tests/parser/system_parser_test.py b/unit_tests/parser/system_parser_test.py index e6588535..8940c4a8 100644 --- a/unit_tests/parser/system_parser_test.py +++ b/unit_tests/parser/system_parser_test.py @@ -164,6 +164,23 @@ system_application_upload = [ "Please use 'system application-list' or 'system application-show hello-kitty' to view the current progress.\n", ] +system_oam_show_output = [ + 'system oam-show\n', + '\x1b[?2004l+----------------+--------------------------------------+', + '| Property | Value |\n', + '+----------------+--------------------------------------+\n', + '| created_at | 2025-02-18T18:36:41.267146+00:00 |\n', + '| isystem_uuid | 572d2cb4-f5ee-449a-899c-e5a9582147f9 |\n', + '| oam_end_ip | 10.66.77.254 |\n', + '| oam_gateway_ip | 10.66.77.1 |\n', + '| oam_ip | 10.66.77.234 |\n', + '| oam_start_ip | 10.66.77.1 |\n', + '| oam_subnet | 10.66.77.0/24 |\n', + '| updated_at | None |\n', + '| uuid | 920531a8-55f0-4263-c8cf-6938965f5d45 |\n', + '+----------------+--------------------------------------+\n', +] + system_host_if_ptp_remove_wrapped_output = [ '+--------------------------------------+---------+-----------+---------------+\n', '| uuid | name | ptp_insta | parameters |\n', @@ -198,6 +215,20 @@ def test_system_parser(): assert output['operational'] == 'enabled' assert output['availability'] == 'available' +def test_system_parser_with_text_after(): + """ + Tests the system parser + Returns: + + """ + system_table_parser = SystemTableParser(system_oam_show_output) + output_list = system_table_parser.get_output_values_list() + assert len(output_list) == 9 + assert output_list[0]['Property'] == 'created_at' + assert output_list[0]['Value'] == '2025-02-18T18:36:41.267146+00:00' + assert output_list[8]['Property'] == 'uuid' + assert output_list[8]['Value'] == '920531a8-55f0-4263-c8cf-6938965f5d45' + def test_system_parser_application_list_output(): """