Skip to content

Commit 189ecd3

Browse files
committed
Created vdm_utilities and db_utilities folder
1 parent 09b9da3 commit 189ecd3

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

sonic-xcvrd/tests/test_xcvrd.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xcvrd.xcvrd import *
88
from xcvrd.sff_mgr import *
99
from xcvrd.xcvrd_utilities.xcvr_table_helper import *
10-
from xcvrd.dom.dom_utilities.common_db_utils import DBUtils
10+
from xcvrd.dom.dom_utilities.db_utilities.common_db_utils import DBUtils
1111
import pytest
1212
import copy
1313
import os
@@ -2889,7 +2889,6 @@ def test_beautify_info_dict(self):
28892889
'eSNR' : '1.1',
28902890
}
28912891

2892-
from xcvrd.dom.dom_utilities.common_db_utils import DBUtils
28932892
db_utils = DBUtils(helper_logger)
28942893
db_utils.beautify_info_dict(dom_info_dict)
28952894
assert dom_info_dict == expected_dom_info_dict

sonic-xcvrd/xcvrd/dom/dom_mgr.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from xcvrd.xcvrd_utilities import sfp_status_helper
2121
from xcvrd.xcvrd_utilities.xcvr_table_helper import *
2222
from xcvrd.xcvrd_utilities import port_event_helper
23-
from xcvrd.dom.dom_utilities.common_db_utils import DBUtils
24-
from xcvrd.dom.dom_utilities.vdm_utils import VDMUtils
25-
from xcvrd.dom.dom_utilities.vdm_db_utils import VDMDBUtils
23+
from xcvrd.dom.dom_utilities.db_utilities.common_db_utils import DBUtils
24+
from xcvrd.dom.dom_utilities.vdm_utilities.vdm_utils import VDMUtils
25+
from xcvrd.dom.dom_utilities.vdm_utilities.vdm_db_utils import VDMDBUtils
2626
except ImportError as e:
2727
raise ImportError(str(e) + " - required module not found in dom_mgr.py")
2828

sonic-xcvrd/xcvrd/dom/dom_utilities/vdm_db_utils.py renamed to sonic-xcvrd/xcvrd/dom/dom_utilities/vdm_utilities/vdm_db_utils.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import datetime
2-
32
from xcvrd.xcvrd_utilities.xcvrd_utils import XCVRDUtils
43
from xcvrd.xcvrd_utilities.xcvr_table_helper import VDM_THRESHOLD_TYPES
5-
from xcvrd.dom.dom_utilities.common_db_utils import DBUtils
6-
from xcvrd.dom.dom_utilities.vdm_utils import VDMUtils
7-
4+
from xcvrd.dom.dom_utilities.db_utilities.common_db_utils import DBUtils
5+
from xcvrd.dom.dom_utilities.vdm_utilities.vdm_utils import VDMUtils
86
from swsscommon import swsscommon
97

10-
class VDMDBUtils:
8+
class VDMDBUtils(DBUtils):
119
"""
1210
This class provides utility functions for managing
1311
DB operations related to VDM on transceivers.
1412
"""
1513
def __init__(self, sfp_obj_dict, port_mapping, xcvr_table_helper, task_stopping_event, helper_logger):
14+
super().__init__(helper_logger)
1615
self.sfp_obj_dict = sfp_obj_dict
1716
self.port_mapping = port_mapping
1817
self.task_stopping_event = task_stopping_event
1918
self.xcvr_table_helper = xcvr_table_helper
2019
self.xcvrd_utils = XCVRDUtils(sfp_obj_dict, helper_logger)
2120
self.vdm_utils = VDMUtils(sfp_obj_dict, helper_logger)
22-
self.db_utils = DBUtils(helper_logger)
2321
self.helper_logger = helper_logger
2422

2523
def post_port_diagnostic_values_to_db(self, logical_port_name, table, get_values_func, db_cache=None):
@@ -29,13 +27,13 @@ def post_port_diagnostic_values_to_db(self, logical_port_name, table, get_values
2927
pport_list = self.port_mapping.get_logical_to_physical(logical_port_name)
3028
if not pport_list:
3129
self.helper_logger.log_error(f"Post port diagnostic values to db failed for {logical_port_name} "
32-
"as no physical port found")
30+
"as no physical port found")
3331
return
3432
physical_port = pport_list[0]
3533

3634
if physical_port not in self.sfp_obj_dict:
3735
self.helper_logger.log_error(f"Post port diagnostic values to db failed for {logical_port_name} "
38-
"as no sfp object found")
36+
"as no sfp object found")
3937
return
4038

4139
if not self.xcvrd_utils.get_transceiver_presence(physical_port):
@@ -53,7 +51,7 @@ def post_port_diagnostic_values_to_db(self, logical_port_name, table, get_values
5351
if diagnostic_values_dict is not None:
5452
if not diagnostic_values_dict:
5553
return
56-
self.db_utils.beautify_info_dict(diagnostic_values_dict)
54+
self.beautify_info_dict(diagnostic_values_dict)
5755
fvs = swsscommon.FieldValuePairs([(k, v) for k, v in diagnostic_values_dict.items()])
5856
table.set(logical_port_name, fvs)
5957
else:
@@ -120,13 +118,13 @@ def _post_port_vdm_thresholds_or_flags_to_db(self, logical_port_name, get_vdm_ta
120118
# for the flags
121119
if flag_data:
122120
asic_id = self.port_mapping.get_asic_id_for_logical_port(logical_port_name)
123-
self.db_utils.update_flag_metadata_tables(logical_port_name, new_key, value,
124-
vdm_values_dict_update_time,
125-
self.xcvr_table_helper.get_vdm_flag_tbl(asic_id, threshold_type),
126-
self.xcvr_table_helper.get_vdm_flag_change_count_tbl(asic_id, threshold_type),
127-
self.xcvr_table_helper.get_vdm_flag_set_time_tbl(asic_id, threshold_type),
128-
self.xcvr_table_helper.get_vdm_flag_clear_time_tbl(asic_id, threshold_type),
129-
f"VDM {threshold_type}")
121+
self.update_flag_metadata_tables(logical_port_name, new_key, value,
122+
vdm_values_dict_update_time,
123+
self.xcvr_table_helper.get_vdm_flag_tbl(asic_id, threshold_type),
124+
self.xcvr_table_helper.get_vdm_flag_change_count_tbl(asic_id, threshold_type),
125+
self.xcvr_table_helper.get_vdm_flag_set_time_tbl(asic_id, threshold_type),
126+
self.xcvr_table_helper.get_vdm_flag_clear_time_tbl(asic_id, threshold_type),
127+
f"VDM {threshold_type}")
130128

131129
if db_cache is not None:
132130
# If cache is enabled, put vdm values to cache
@@ -136,7 +134,7 @@ def _post_port_vdm_thresholds_or_flags_to_db(self, logical_port_name, get_vdm_ta
136134

137135
for threshold_type, threshold_value_dict in vdm_threshold_type_value_dict.items():
138136
if threshold_value_dict:
139-
self.db_utils.beautify_info_dict(threshold_value_dict)
137+
self.beautify_info_dict(threshold_value_dict)
140138
fvs = swsscommon.FieldValuePairs([(k, v) for k, v in threshold_value_dict.items()])
141139
table = get_vdm_table_func(self.port_mapping.get_asic_id_for_logical_port(logical_port_name), threshold_type)
142140
table.set(logical_port_name, fvs)

sonic-xcvrd/xcvrd/xcvrd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from .xcvrd_utilities.port_event_helper import PortChangeObserver
3535
from .xcvrd_utilities import media_settings_parser
3636
from .xcvrd_utilities import optics_si_parser
37-
from xcvrd.dom.dom_utilities.vdm_db_utils import VDMDBUtils
37+
from xcvrd.dom.dom_utilities.vdm_utilities.vdm_db_utils import VDMDBUtils
3838

3939
from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CmisApi
4040

0 commit comments

Comments
 (0)