1
1
import os
2
2
import json
3
3
import filecmp
4
- import importlib
5
4
import config .main as config
6
5
7
6
from click .testing import CliRunner
21
20
RUNNING_CONFIG_YANG_FAILURE = os .path .join (DATA_DIR , "running_config_yang_failure.json" )
22
21
GOLDEN_INPUT_YANG_FAILURE = os .path .join (DATA_DIR , "golden_input_yang_failure.json" )
23
22
FINAL_CONFIG_YANG_FAILURE = os .path .join (DATA_DIR , "final_config_yang_failure.json" )
24
- MULTI_ASIC_MACSEC_OV = os .path .join (DATA_DIR , "multi_asic_macsec_ov.json" )
25
- MULTI_ASIC_DEVICE_METADATA_RM = os .path .join (DATA_DIR , "multi_asic_dm_rm.json" )
26
23
27
24
# Load sonic-cfggen from source since /usr/local/bin/sonic-cfggen does not have .py extension.
28
25
sonic_cfggen = load_module_from_source ('sonic_cfggen' , '/usr/local/bin/sonic-cfggen' )
@@ -176,7 +173,7 @@ def test_yang_verification_enabled(self):
176
173
def is_yang_config_validation_enabled_side_effect (filename ):
177
174
return True
178
175
179
- def config_mgmt_side_effect (configdb ):
176
+ def config_mgmt_side_effect ():
180
177
return config_mgmt .ConfigMgmt (source = CONFIG_DB_JSON_FILE )
181
178
182
179
db = Db ()
@@ -235,7 +232,7 @@ def check_yang_verification_failure(self, db, config, running_config,
235
232
def read_json_file_side_effect (filename ):
236
233
return golden_config
237
234
238
- def config_mgmt_side_effect (configdb ):
235
+ def config_mgmt_side_effect ():
239
236
return config_mgmt .ConfigMgmt (source = CONFIG_DB_JSON_FILE )
240
237
241
238
# ConfigMgmt will call ConfigDBConnector to load default config_db.json.
@@ -260,73 +257,3 @@ def teardown_class(cls):
260
257
print ("TEARDOWN" )
261
258
os .environ ["UTILITIES_UNIT_TESTING" ] = "0"
262
259
return
263
-
264
-
265
- class TestConfigOverrideMultiasic (object ):
266
- @classmethod
267
- def setup_class (cls ):
268
- print ("SETUP" )
269
- os .environ ["UTILITIES_UNIT_TESTING" ] = "1"
270
- os .environ ["UTILITIES_UNIT_TESTING_TOPOLOGY" ] = "multi_asic"
271
- # change to multi asic config
272
- from .mock_tables import dbconnector
273
- from .mock_tables import mock_multi_asic
274
- importlib .reload (mock_multi_asic )
275
- dbconnector .load_namespace_config ()
276
- return
277
-
278
- def test_macsec_override (self ):
279
- def read_json_file_side_effect (filename ):
280
- with open (MULTI_ASIC_MACSEC_OV , "r" ) as f :
281
- macsec_profile = json .load (f )
282
- return macsec_profile
283
- db = Db ()
284
- cfgdb_clients = db .cfgdb_clients
285
-
286
- # The profile_content was copied from MULTI_ASIC_MACSEC_OV, where all
287
- # ns sharing the same content: {"profile": {"key": "value"}}
288
- profile_content = {"profile" : {"key" : "value" }}
289
-
290
- with mock .patch ('config.main.read_json_file' ,
291
- mock .MagicMock (side_effect = read_json_file_side_effect )):
292
- runner = CliRunner ()
293
- result = runner .invoke (config .config .commands ["override-config-table" ],
294
- ['golden_config_db.json' ], obj = db )
295
- assert result .exit_code == 0
296
-
297
- for ns , config_db in cfgdb_clients .items ():
298
- assert config_db .get_config ()['MACSEC_PROFILE' ] == profile_content
299
-
300
- def test_device_metadata_table_rm (self ):
301
- def read_json_file_side_effect (filename ):
302
- with open (MULTI_ASIC_DEVICE_METADATA_RM , "r" ) as f :
303
- device_metadata = json .load (f )
304
- return device_metadata
305
- db = Db ()
306
- cfgdb_clients = db .cfgdb_clients
307
-
308
- for ns , config_db in cfgdb_clients .items ():
309
- assert 'DEVICE_METADATA' in config_db .get_config ()
310
-
311
- with mock .patch ('config.main.read_json_file' ,
312
- mock .MagicMock (side_effect = read_json_file_side_effect )):
313
- runner = CliRunner ()
314
- result = runner .invoke (config .config .commands ["override-config-table" ],
315
- ['golden_config_db.json' ], obj = db )
316
- assert result .exit_code == 0
317
-
318
- for ns , config_db in cfgdb_clients .items ():
319
- assert 'DEVICE_METADATA' not in config_db .get_config ()
320
-
321
-
322
- @classmethod
323
- def teardown_class (cls ):
324
- print ("TEARDOWN" )
325
- os .environ ["UTILITIES_UNIT_TESTING" ] = "0"
326
- os .environ ["UTILITIES_UNIT_TESTING_TOPOLOGY" ] = ""
327
- # change back to single asic config
328
- from .mock_tables import dbconnector
329
- from .mock_tables import mock_single_asic
330
- importlib .reload (mock_single_asic )
331
- dbconnector .load_namespace_config ()
332
- return
0 commit comments