Skip to content

Commit 2f8508f

Browse files
authored
Revert PR: Add scope to field validator (#3689)
* Revert PR: Add scope to field validator Reverts #3675 since it would cause PR test failure:
1 parent 5481d0e commit 2f8508f

File tree

3 files changed

+58
-122
lines changed

3 files changed

+58
-122
lines changed

generic_config_updater/field_operation_validators.py

+11-17
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import jsonpointer
55
import subprocess
66
from sonic_py_common import device_info
7-
from .gu_common import GenericConfigUpdaterError, HOST_NAMESPACE
7+
from .gu_common import GenericConfigUpdaterError
88
from swsscommon import swsscommon
99
from utilities_common.constants import DEFAULT_SUPPORTED_FECS_LIST
1010

11-
STATE_DB_NAME = 'STATE_DB'
12-
REDIS_TIMEOUT_MSECS = 0
1311
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
1412
GCU_TABLE_MOD_CONF_FILE = f"{SCRIPT_DIR}/gcu_field_operation_validators.conf.json"
13+
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
1514

1615

17-
def get_asic_name(scope):
16+
def get_asic_name():
1817
asic = "unknown"
1918

2019
if os.path.exists(GCU_TABLE_MOD_CONF_FILE):
@@ -29,12 +28,7 @@ def get_asic_name(scope):
2928
if asic_type == 'cisco-8000':
3029
asic = "cisco-8000"
3130
elif asic_type == 'mellanox' or asic_type == 'vs' or asic_type == 'broadcom':
32-
get_hwsku_cmds = []
33-
if scope == HOST_NAMESPACE:
34-
get_hwsku_cmds = ["sonic-cfggen", "-d", "-v", "DEVICE_METADATA.localhost.hwsku"]
35-
else:
36-
get_hwsku_cmds = ["sonic-cfggen", "-d", "-n", scope, "-v", "DEVICE_METADATA.localhost.hwsku"]
37-
proc = subprocess.Popen(get_hwsku_cmds, shell=False, universal_newlines=True, stdout=subprocess.PIPE)
31+
proc = subprocess.Popen(GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
3832
output, err = proc.communicate()
3933
hwsku = output.rstrip('\n')
4034
if asic_type == 'mellanox' or asic_type == 'vs':
@@ -67,8 +61,8 @@ def get_asic_name(scope):
6761
return asic
6862

6963

70-
def rdma_config_update_validator(scope, patch_element):
71-
asic = get_asic_name(scope)
64+
def rdma_config_update_validator(patch_element):
65+
asic = get_asic_name()
7266
if asic == "unknown":
7367
return False
7468
version_info = device_info.get_sonic_version_info()
@@ -140,17 +134,17 @@ def _get_fields_in_patch():
140134
return True
141135

142136

143-
def read_statedb_entry(scope, table, key, field):
144-
state_db = swsscommon.DBConnector(STATE_DB_NAME, REDIS_TIMEOUT_MSECS, True, scope)
137+
def read_statedb_entry(table, key, field):
138+
state_db = swsscommon.DBConnector("STATE_DB", 0)
145139
tbl = swsscommon.Table(state_db, table)
146140
return tbl.hget(key, field)[1]
147141

148142

149-
def port_config_update_validator(scope, patch_element):
143+
def port_config_update_validator(patch_element):
150144

151145
def _validate_field(field, port, value):
152146
if field == "fec":
153-
supported_fecs_str = read_statedb_entry(scope, "PORT_TABLE", port, "supported_fecs")
147+
supported_fecs_str = read_statedb_entry("PORT_TABLE", port, "supported_fecs")
154148
if supported_fecs_str:
155149
if supported_fecs_str != 'N/A':
156150
supported_fecs_list = [element.strip() for element in supported_fecs_str.split(',')]
@@ -162,7 +156,7 @@ def _validate_field(field, port, value):
162156
return False
163157
return True
164158
if field == "speed":
165-
supported_speeds_str = read_statedb_entry(scope, "PORT_TABLE", port, "supported_speeds") or ''
159+
supported_speeds_str = read_statedb_entry("PORT_TABLE", port, "supported_speeds") or ''
166160
try:
167161
supported_speeds = [int(s) for s in supported_speeds_str.split(',') if s]
168162
if supported_speeds and int(value) not in supported_speeds:

generic_config_updater/gu_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _invoke_validating_function(cmd, jsonpatch_element):
191191
raise GenericConfigUpdaterError("Attempting to call invalid method {} in module {}. Module must be generic_config_updater.field_operation_validators, and method must be a defined validator".format(method_name, module_name))
192192
module = importlib.import_module(module_name, package=None)
193193
method_to_call = getattr(module, method_name)
194-
return method_to_call(self.scope, jsonpatch_element)
194+
return method_to_call(jsonpatch_element)
195195

196196
if os.path.exists(GCU_FIELD_OP_CONF_FILE):
197197
with open(GCU_FIELD_OP_CONF_FILE, "r") as s:

0 commit comments

Comments
 (0)