From 794a6a218411a5620d7af11b77b7204f6e706798 Mon Sep 17 00:00:00 2001 From: "david.zagury" Date: Thu, 25 Feb 2021 21:08:38 +0200 Subject: [PATCH 1/3] [db migrator]: Add lacp_key to portchannel table --- scripts/db_migrator.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 41ef8ee516..4f01add557 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -44,7 +44,7 @@ def __init__(self, namespace, socket=None): none-zero values. build: sequentially increase within a minor version domain. """ - self.CURRENT_VERSION = 'version_2_0_0' + self.CURRENT_VERSION = 'version_2_0_2' self.TABLE_NAME = 'VERSIONS' self.TABLE_KEY = 'DATABASE' @@ -525,9 +525,24 @@ def version_2_0_0(self): def version_2_0_1(self): """ - Current latest version. Nothing to do here. + Version 2_0_1. """ log.log_info('Handling version_2_0_1') + warmreboot_state = self.stateDB.get(self.stateDB.STATE_DB, 'WARM_RESTART_ENABLE_TABLE|system', 'enable') + + if warmreboot_state != 'true': + portchannel_table = self.configDB.get_table('PORTCHANNEL') + for name, data in portchannel_table.items(): + data['lacp_key'] = 'auto' + self.configDB.set_entry('PORTCHANNEL', name, data) + self.set_version('version_2_0_2') + return 'version_2_0_2' + + def version_2_0_2(self): + """ + Current latest version. Nothing to do here. + """ + log.log_info('Handling version_2_0_2') return None def get_version(self): From 96df0229807c1c818d67c76ee01aad06cb3a9f1a Mon Sep 17 00:00:00 2001 From: "david.zagury" Date: Thu, 22 Apr 2021 14:38:49 +0300 Subject: [PATCH 2/3] [db migrator]: Add unit test to test DB upgrade has added lacp_key to portchannel table --- .../config_db/portchannel-expected.json | 39 +++++++++++++++++++ .../config_db/portchannel-input.json | 33 ++++++++++++++++ tests/db_migrator_test.py | 23 +++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tests/db_migrator_input/config_db/portchannel-expected.json create mode 100644 tests/db_migrator_input/config_db/portchannel-input.json diff --git a/tests/db_migrator_input/config_db/portchannel-expected.json b/tests/db_migrator_input/config_db/portchannel-expected.json new file mode 100644 index 0000000000..acc61d1316 --- /dev/null +++ b/tests/db_migrator_input/config_db/portchannel-expected.json @@ -0,0 +1,39 @@ +{ + "PORTCHANNEL|PortChannel0": { + "admin_status": "up", + "members@": "Ethernet0,Ethernet4", + "min_links": "2", + "mtu": "9100", + "lacp_key": "auto" + }, + "PORTCHANNEL|PortChannel1": { + "admin_status": "up", + "members@": "Ethernet8,Ethernet12", + "min_links": "2", + "mtu": "9100", + "lacp_key": "auto" + }, + "PORTCHANNEL|PortChannel0123": { + "admin_status": "up", + "members@": "Ethernet16", + "min_links": "1", + "mtu": "9100", + "lacp_key": "auto" + }, + "PORTCHANNEL|PortChannel0011": { + "admin_status": "up", + "members@": "Ethernet20,Ethernet24", + "min_links": "2", + "mtu": "9100", + "lacp_key": "auto" + }, + "PORTCHANNEL|PortChannel9999": { + "admin_status": "up", + "mtu": "9100", + "lacp_key": "auto" + }, + "VERSIONS|DATABASE": { + "VERSION": "version_2_0_2" + } +} + diff --git a/tests/db_migrator_input/config_db/portchannel-input.json b/tests/db_migrator_input/config_db/portchannel-input.json new file mode 100644 index 0000000000..5a890755a0 --- /dev/null +++ b/tests/db_migrator_input/config_db/portchannel-input.json @@ -0,0 +1,33 @@ +{ + "PORTCHANNEL|PortChannel0": { + "admin_status": "up", + "members@": "Ethernet0,Ethernet4", + "min_links": "2", + "mtu": "9100" + }, + "PORTCHANNEL|PortChannel1": { + "admin_status": "up", + "members@": "Ethernet8,Ethernet12", + "min_links": "2", + "mtu": "9100" + }, + "PORTCHANNEL|PortChannel0123": { + "admin_status": "up", + "members@": "Ethernet16", + "min_links": "1", + "mtu": "9100" + }, + "PORTCHANNEL|PortChannel0011": { + "admin_status": "up", + "members@": "Ethernet20,Ethernet24", + "min_links": "2", + "mtu": "9100" + }, + "PORTCHANNEL|PortChannel9999": { + "admin_status": "up", + "mtu": "9100" + }, + "VERSIONS|DATABASE": { + "VERSION": "version_2_0_1" + } +} diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index b5f12e4f5e..f871350fd5 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -247,3 +247,26 @@ def test_init_config_feature_migration(self): assert not diff assert not expected_db.cfgdb.get_table('CONTAINER_FEATURE') + + +class TestLacpKeyMigrator(object): + @classmethod + def setup_class(cls): + os.environ['UTILITIES_UNIT_TESTING'] = "2" + + @classmethod + def teardown_class(cls): + os.environ['UTILITIES_UNIT_TESTING'] = "0" + dbconnector.dedicated_dbs['CONFIG_DB'] = None + + def test_lacp_key_migrator(self): + dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-input') + import db_migrator + dbmgtr = db_migrator.DBMigrator(None) + dbmgtr.migrate() + dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-expected') + expected_db = Db() + advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb, 'version_2_0_2') + + assert dbmgtr.configDB.get_table('PORTCHANNEL') == expected_db.cfgdb.get_table('PORTCHANNEL') + assert dbmgtr.configDB.get_table('VERSIONS') == expected_db.cfgdb.get_table('VERSIONS') From cab01d041baed1a99a6da20b313dcc7822dfedae Mon Sep 17 00:00:00 2001 From: "david.zagury" Date: Thu, 18 Feb 2021 13:38:12 +0200 Subject: [PATCH 3/3] [config]: Create portchannel with LACP key --- config/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 828c447e5f..851e78b75f 100644 --- a/config/main.py +++ b/config/main.py @@ -1500,7 +1500,8 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback): ctx.fail("{} already exists!".format(portchannel_name)) fvs = {'admin_status': 'up', - 'mtu': '9100'} + 'mtu': '9100', + 'lacp_key': 'auto'} if min_links != 0: fvs['min_links'] = str(min_links) if fallback != 'false':