mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 18:58:01 +00:00 
			
		
		
		
	Enable better titles in Grafana dashboards with multiple test tags
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
		| @@ -280,7 +280,7 @@ class GhostRequest: | ||||
|         subtest_pass_fail = list() | ||||
|         subtest_pass_total = 0 | ||||
|         subtest_fail_total = 0 | ||||
|         test_tag = dict() | ||||
|         test_tag_1 = list() | ||||
|         columns = ['test-rig', 'dut-hw-version', 'dut-sw-version', | ||||
|                    'dut-model-num', 'dut-serial-num'] | ||||
|         duts = dict() | ||||
| @@ -296,10 +296,7 @@ class GhostRequest: | ||||
|                         duts[column] = column_data | ||||
|                     except: | ||||
|                         print('no column named %s' % column) | ||||
|                 try: | ||||
|                     test_tag[test_id] = csvreader.get_column(df, 'test-tag')[0] | ||||
|                 except: | ||||
|                     print('no test-id') | ||||
|                     test_tag_1.append([test_id, list(set(csvreader.get_column(df, 'test-tag')))]) | ||||
|                 pass_fail = Counter(csvreader.get_column(df, 'pass/fail')) | ||||
|                 test_pass_fail.append(pass_fail) | ||||
|                 subtest_pass = csvreader.get_column(df, 'Subtest-Pass') | ||||
| @@ -387,17 +384,25 @@ class GhostRequest: | ||||
|                         pass | ||||
|  | ||||
|                 low_priority = csvreader.filter_df(results, 'test-priority', 'less than', 94) | ||||
|                 if self.debug: | ||||
|                     print('Low Priority results %s' % len(low_priority)) | ||||
|                 high_priority = csvreader.filter_df(results, 'test-priority', 'greater than or equal to', 95) | ||||
|                 high_priority_list.append(high_priority) | ||||
|                 low_priority_list.append(low_priority) | ||||
|  | ||||
|             except: | ||||
|                 print("Failure") | ||||
|                 print("Failed to process %s" % target_folder) | ||||
|                 target_folders.remove(target_folder) | ||||
|                 failuredict = dict() | ||||
|                 failuredict[target_folder] = ['Failure'] | ||||
|                 web_pages_and_pdfs.append(failuredict) | ||||
|         test_tag = dict() | ||||
|         for x in list(set([x[0] for x in test_tag_1])): | ||||
|             l3 = list() | ||||
|             for sublist in test_tag_1: | ||||
|                 if sublist[0] == x: | ||||
|                     l3 += sublist[1] | ||||
|             test_tag[x] = l3 | ||||
|         if len(times) == 0: | ||||
|             return ArithmeticError("There are no datapoints in any folders passed into Ghost") | ||||
|  | ||||
| @@ -447,6 +452,7 @@ class GhostRequest: | ||||
|             short_description = 'Tests passed'  # variable name | ||||
|             numeric_score = test_pass_fail_results['PASS']  # value | ||||
|             tags = dict() | ||||
|             if self.debug: | ||||
|                 print(datetime.utcfromtimestamp(max(times))) | ||||
|             tags['testbed'] = testbeds[0] | ||||
|             tags['script'] = 'GhostRequest' | ||||
| @@ -466,6 +472,7 @@ class GhostRequest: | ||||
|             short_description = 'Subtests passed'  # variable name | ||||
|             numeric_score = subtest_pass_fail_results['PASS']  # value | ||||
|             tags = dict() | ||||
|             if self.debug: | ||||
|                 print(datetime.utcfromtimestamp(max(times))) | ||||
|             tags['testbed'] = testbeds[0] | ||||
|             tags['script'] = 'GhostRequest' | ||||
| @@ -483,11 +490,14 @@ class GhostRequest: | ||||
|             influxdb.post_to_influx(short_description, numeric_score, tags, date) | ||||
|  | ||||
|         text = 'Testbed: %s<br />' % testbeds[0] | ||||
|         raw_test_tags = list() | ||||
|         test_tag_table = '' | ||||
|         for tag in list(set(test_tag.values())): | ||||
|             print(tag) | ||||
|             for value in tag: | ||||
|                 raw_test_tags.append(value) | ||||
|         for value in list(set(raw_test_tags)): | ||||
|             test_tag_table += ( | ||||
|                     '<tr><td style="border-color: gray; border-style: solid; border-width: 1px; ">Test Tag</td><td colspan="3" style="border-color: gray; border-style: solid; border-width: 1px; ">%s</td></tr>' % tag) | ||||
|                     '<tr><td style="border-color: gray; border-style: solid; border-width: 1px; ">Test Tag</td><td colspan="3" style="border-color: gray; border-style: solid; border-width: 1px; ">%s</td></tr>' % value) | ||||
|         dut_table_column_names = {'test-rig': 'Testbed', | ||||
|                                   'dut-hw-version': 'DUT HW', | ||||
|                                   'dut-sw-version': 'DUT SW', | ||||
| @@ -540,9 +550,11 @@ class GhostRequest: | ||||
|         if grafana_token is not None: | ||||
|             grafana = GrafanaRequest(grafana_token, | ||||
|                                      grafana_host, | ||||
|                                      grafanajson_port=grafana_port | ||||
|                                      grafanajson_port=grafana_port, | ||||
|                                      debug_=self.debug | ||||
|                                      ) | ||||
|             print(test_tag) | ||||
|             if self.debug: | ||||
|                 print('Test Tag: %s' % test_tag) | ||||
|             grafana.create_custom_dashboard(target_csvs=target_files, | ||||
|                                             title=title, | ||||
|                                             datasource=grafana_datasource, | ||||
|   | ||||
| @@ -209,7 +209,7 @@ class GrafanaRequest: | ||||
|                                 from_date='now-1y', | ||||
|                                 to_date='now', | ||||
|                                 graph_height=8, | ||||
|                                 graph__width=12, | ||||
|                                 graph_width=12, | ||||
|                                 pass_fail=None, | ||||
|                                 test_tag=None): | ||||
|         options = string.ascii_lowercase + string.ascii_uppercase + string.digits | ||||
| @@ -248,14 +248,73 @@ class GrafanaRequest: | ||||
|         if pass_fail is not None: | ||||
|             graph_groups[pass_fail] = ['PASS', 'FAIL'] | ||||
|  | ||||
|         print('Test Tag in Grafana: %s' % test_tag) | ||||
|  | ||||
|         for scriptname in graph_groups.keys(): | ||||
|             print(scriptname) | ||||
|             if scriptname in test_tag.keys(): | ||||
|                 for tag in test_tag[scriptname]: | ||||
|                     print('Script: %s, Tag: %s' % (scriptname, tag)) | ||||
|                     panel = self.create_panel(graph_groups, | ||||
|                                               graph_height, | ||||
|                                               graph_width, | ||||
|                                               scriptname, | ||||
|                                               bucket, | ||||
|                                               testbed, | ||||
|                                               tag, | ||||
|                                               datasource, | ||||
|                                               index) | ||||
|                     panels.append(panel) | ||||
|                     index = index + 1 | ||||
|             else: | ||||
|                 panel = self.create_panel(graph_groups, | ||||
|                                           graph_height, | ||||
|                                           graph_width, | ||||
|                                           scriptname, | ||||
|                                           bucket, | ||||
|                                           testbed, | ||||
|                                           None, | ||||
|                                           datasource, | ||||
|                                           index) | ||||
|                 panels.append(panel) | ||||
|                 index = index + 1 | ||||
|  | ||||
|         input1['annotations'] = annot | ||||
|         input1['editable'] = True | ||||
|         input1['gnetId'] = None | ||||
|         input1['graphTooltip'] = 0 | ||||
|         input1['links'] = list() | ||||
|         input1['panels'] = panels | ||||
|         input1['refresh'] = False | ||||
|         input1['schemaVersion'] = 27 | ||||
|         input1['style'] = 'dark' | ||||
|         input1['tags'] = list() | ||||
|         input1['templating'] = templating | ||||
|         input1['time'] = timedict | ||||
|         input1['timepicker'] = dict() | ||||
|         input1['timezone'] = '' | ||||
|         input1['title'] = ("Testbed: %s" % title) | ||||
|         input1['uid'] = uid | ||||
|         input1['version'] = 11 | ||||
|         return self.create_dashboard_from_dict(dictionary=json.dumps(input1)) | ||||
|  | ||||
|     def create_panel(self, | ||||
|                      graph_groups, | ||||
|                      graph_height, | ||||
|                      graph_width, | ||||
|                      scriptname, | ||||
|                      bucket, | ||||
|                      testbed, | ||||
|                      test_tag, | ||||
|                      datasource, | ||||
|                      index): | ||||
|         print('Test Tag: %s' % test_tag) | ||||
|         for graph_group in graph_groups[scriptname]: | ||||
|             panel = dict() | ||||
|  | ||||
|             gridpos = dict() | ||||
|             gridpos['h'] = graph_height | ||||
|                 gridpos['w'] = graph__width | ||||
|             gridpos['w'] = graph_width | ||||
|             gridpos['x'] = 0 | ||||
|             gridpos['y'] = 0 | ||||
|  | ||||
| @@ -284,7 +343,7 @@ class GrafanaRequest: | ||||
|                                               counter, | ||||
|                                               graph_group, | ||||
|                                               testbed, | ||||
|                                                   test_tag=test_tag[scriptname]) | ||||
|                                               test_tag=test_tag) | ||||
|             except: | ||||
|                 new_target = self.maketargets(bucket, scriptname, groupBy, counter, graph_group, testbed) | ||||
|             targets.append(new_target) | ||||
| @@ -352,10 +411,15 @@ class GrafanaRequest: | ||||
|             panel['timeFrom'] = None | ||||
|             panel['timeRegions'] = list() | ||||
|             panel['timeShift'] = None | ||||
|  | ||||
|             if graph_group is not None: | ||||
|                     panel['title'] = scriptname + ' ' + graph_group | ||||
|                 else: | ||||
|                 scriptname = '%s: %s' % (scriptname, graph_group) | ||||
|             if test_tag is not None: | ||||
|                 scriptname = '%s: %s' % (scriptname, test_tag) | ||||
|             scriptname = '%s: %s' % (scriptname, testbed) | ||||
|             panel['title'] = scriptname | ||||
|  | ||||
|             if self.debug: | ||||
|                 print(panel['title']) | ||||
|             panel['transformations'] = list() | ||||
|             panel['transformations'].append(transformation) | ||||
| @@ -365,32 +429,7 @@ class GrafanaRequest: | ||||
|             panel['yaxes'].append(yaxis) | ||||
|             panel['yaxes'].append(yaxis) | ||||
|             panel['yaxis'] = yaxis1 | ||||
|  | ||||
|                 panels.append(panel) | ||||
|                 index = index + 1 | ||||
|         input1['annotations'] = annot | ||||
|         input1['editable'] = True | ||||
|         input1['gnetId'] = None | ||||
|         input1['graphTooltip'] = 0 | ||||
|         input1['links'] = list() | ||||
|         input1['panels'] = panels | ||||
|         input1['refresh'] = False | ||||
|         input1['schemaVersion'] = 27 | ||||
|         input1['style'] = 'dark' | ||||
|         input1['tags'] = list() | ||||
|         input1['templating'] = templating | ||||
|         input1['time'] = timedict | ||||
|         input1['timepicker'] = dict() | ||||
|         input1['timezone'] = '' | ||||
|         input1['title'] = ("Testbed: %s" % title) | ||||
|         input1['uid'] = uid | ||||
|         input1['version'] = 11 | ||||
|         return self.create_dashboard_from_dict(dictionary=json.dumps(input1)) | ||||
|  | ||||
|     #    def create_custom_dashboard(self, | ||||
|     #                               datastore=None): | ||||
|     #      data = json.dumps(datastore, indent=4) | ||||
|     #     return requests.post(self.grafanajson_url, headers=self.headers, data=data, verify=False) | ||||
|             return panel | ||||
|  | ||||
|     def create_snapshot(self, title): | ||||
|         print('create snapshot') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Matthew Stidham
					Matthew Stidham