-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[db_migrator] Remove hardcoded config and migrate config from minigraph #2887
Changes from 5 commits
3a85220
7ae4c94
6e28286
2b66fa3
fcfd1fb
94bc8bd
126c187
2240d10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,10 @@ | |
|
||
from sonic_py_common import device_info, logger | ||
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig | ||
from db_migrator_constants import RESTAPI, TELEMETRY, CONSOLE_SWITCH | ||
from minigraph import parse_xml | ||
|
||
INIT_CFG_FILE = '/etc/sonic/init_cfg.json' | ||
MINIGRAPH_FILE = '/etc/sonic/minigraph.xml' | ||
|
||
# mock the redis for unit test purposes # | ||
try: | ||
|
@@ -22,6 +23,7 @@ | |
sys.path.insert(0, modules_path) | ||
sys.path.insert(0, tests_path) | ||
INIT_CFG_FILE = os.path.join(mocked_db_path, "init_cfg.json") | ||
MINIGRAPH_FILE = os.path.join(mocked_db_path, "minigraph.xml") | ||
except KeyError: | ||
pass | ||
|
||
|
@@ -51,6 +53,12 @@ def __init__(self, namespace, socket=None): | |
self.TABLE_KEY = 'DATABASE' | ||
self.TABLE_FIELD = 'VERSION' | ||
|
||
# load config data from minigraph to get the default/hardcoded values from minigraph.py | ||
# this is to avoid duplicating the hardcoded these values in db_migrator | ||
self.minigraph_data = None | ||
if os.path.isfile(MINIGRAPH_FILE): | ||
self.minigraph_data = parse_xml(MINIGRAPH_FILE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to protect against parse_xml throwing error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Added now. |
||
|
||
db_kwargs = {} | ||
if socket: | ||
db_kwargs['unix_socket_path'] = socket | ||
|
@@ -527,6 +535,9 @@ def migrate_vxlan_config(self): | |
|
||
def migrate_restapi(self): | ||
# RESTAPI - add missing key | ||
if not self.minigraph_data or 'RESTAPI' not in self.minigraph_data: | ||
return | ||
RESTAPI = self.minigraph_data['RESTAPI'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated now |
||
log.log_notice('Migrate RESTAPI configuration') | ||
config = self.configDB.get_entry('RESTAPI', 'config') | ||
if not config: | ||
|
@@ -537,6 +548,9 @@ def migrate_restapi(self): | |
|
||
def migrate_telemetry(self): | ||
# TELEMETRY - add missing key | ||
if not self.minigraph_data or 'TELEMETRY' not in self.minigraph_data: | ||
return | ||
TELEMETRY = self.minigraph_data['TELEMETRY'] | ||
log.log_notice('Migrate TELEMETRY configuration') | ||
gnmi = self.configDB.get_entry('TELEMETRY', 'gnmi') | ||
if not gnmi: | ||
|
@@ -547,6 +561,9 @@ def migrate_telemetry(self): | |
|
||
def migrate_console_switch(self): | ||
# CONSOLE_SWITCH - add missing key | ||
if not self.minigraph_data or 'CONSOLE_SWITCH' not in self.minigraph_data: | ||
return | ||
CONSOLE_SWITCH = self.minigraph_data['CONSOLE_SWITCH'] | ||
log.log_notice('Migrate CONSOLE_SWITCH configuration') | ||
console_mgmt = self.configDB.get_entry('CONSOLE_SWITCH', 'console_mgmt') | ||
if not console_mgmt: | ||
|
@@ -555,10 +572,13 @@ def migrate_console_switch(self): | |
|
||
def migrate_device_metadata(self): | ||
# DEVICE_METADATA - synchronous_mode entry | ||
log.log_notice('Migrate DEVICE_METADATA missing configuration (synchronous_mode=enable)') | ||
if not self.minigraph_data or 'DEVICE_METADATA' not in self.minigraph_data: | ||
return | ||
log.log_notice('Migrate DEVICE_METADATA missing configuration') | ||
metadata = self.configDB.get_entry('DEVICE_METADATA', 'localhost') | ||
DEVICE_METADATA = self.minigraph_data["DEVICE_METADATA"]["localhost"] | ||
if 'synchronous_mode' not in metadata: | ||
metadata['synchronous_mode'] = 'enable' | ||
metadata['synchronous_mode'] = DEVICE_METADATA.get("synchronous_mode") | ||
self.configDB.set_entry('DEVICE_METADATA', 'localhost', metadata) | ||
|
||
def migrate_port_qos_map_global(self): | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<DeviceMiniGraph xmlns="Microsoft.Search.Autopilot.Evolution" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | ||
<CpgDec/> | ||
<DpgDec> | ||
<DeviceDataPlaneInfo> | ||
<LoopbackIPInterfaces/> | ||
<ManagementIPInterfaces/> | ||
<Hostname>SONiC-Dummy</Hostname> | ||
<PortChannelInterfaces/> | ||
<VlanInterfaces/> | ||
<IPInterfaces/> | ||
<AclInterfaces/> | ||
</DeviceDataPlaneInfo> | ||
</DpgDec> | ||
<PngDec> | ||
<Devices> | ||
<Device i:type="TorRouter"> | ||
<Hostname>SONiC-Dummy</Hostname> | ||
</Device> | ||
</Devices> | ||
</PngDec> | ||
<MetadataDeclaration> | ||
<Devices xmlns:a="http://schemas"> | ||
<a:DeviceMetadata> | ||
<a:Properties/> | ||
</a:DeviceMetadata> | ||
</Devices> | ||
</MetadataDeclaration> | ||
<Hostname>SONiC-Dummy</Hostname> | ||
</DeviceMiniGraph> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a testcase for missing MINIGRAPH_FILE? It would be even better if you can add a testcase for L2 switch mode #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new testcase for missing minigraph. We can discuss what other fields are expected/unexpected in L2 switch's case and add a test for that in future PR. What do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for L2 switch in future is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per offline discussion: from unit test level the test for missing minigraph and absence of default entries is sufficient. L2 switch config and functionality needs to be tested separately as part of sonic-mgmt test. Raised a test gap for this: sonic-net/sonic-mgmt#8777