Skip to content
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

[action] [PR:3100] Fix database initialization for db_migrator (#3100) #3137

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import re

from sonic_py_common import device_info, logger
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from minigraph import parse_xml
from utilities_common.helper import update_config
from utilities_common.general import load_db_config

INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
MINIGRAPH_FILE = '/etc/sonic/minigraph.xml'
Expand Down Expand Up @@ -1256,10 +1257,7 @@ def main():
socket_path = args.socket
namespace = args.namespace

if args.namespace is not None:
SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace)
else:
SonicDBConfig.initialize()
load_db_config()

if socket_path:
dbmgtr = DBMigrator(namespace, socket=socket_path)
Expand Down
18 changes: 17 additions & 1 deletion tests/db_migrator_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import pytest
import sys

import argparse
from unittest import mock
from deepdiff import DeepDiff

from swsscommon.swsscommon import SonicV2Connector
Expand Down Expand Up @@ -904,3 +905,18 @@ def test_golden_config_hostname(self):
hostname = host.get('hostname', '')
# hostname is from minigraph.xml
assert hostname == 'SONiC-Dummy'

class TestMain(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"

@mock.patch('argparse.ArgumentParser.parse_args')
def test_init(self, mock_args):
mock_args.return_value=argparse.Namespace(namespace=None, operation='get_version', socket=None)
import db_migrator
db_migrator.main()
Loading