From 0c8b7dcb435e52d3943cd92589262444def29cc8 Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Fri, 14 Oct 2022 15:46:04 +0900 Subject: [PATCH 1/2] lib: support passing change=None to ChangeHandler() Signed-off-by: Wataru Ishida --- src/lib/goldstone/lib/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/goldstone/lib/core.py b/src/lib/goldstone/lib/core.py index b8503a8f..3ec5ced0 100644 --- a/src/lib/goldstone/lib/core.py +++ b/src/lib/goldstone/lib/core.py @@ -17,12 +17,15 @@ class ChangeHandler(object): def __init__(self, server, change): self.server = server self.change = change - self.type = self.change.type + + @property + def type(self): + return self.change.type def setup_cache(self, user): cache = user.get("cache") if not user.get("cache"): - cache = self.server.conn.get_config_cache(user["changes"]) + cache = self.server.conn.get_config_cache(user.get("changes", {})) user["cache"] = cache return cache From 9b1340be510a5929c80a55da50bac7e9d0448110 Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Fri, 14 Oct 2022 15:47:20 +0900 Subject: [PATCH 2/2] south-gearbox: fix bug of reconcile() when pin-mode configuration exists Signed-off-by: Wataru Ishida --- .../goldstone/south/gearbox/interfaces.py | 39 +- src/south/gearbox/tests/platform.json | 45 +- src/south/gearbox/tests/tests.py | 419 ++++++++++-------- 3 files changed, 254 insertions(+), 249 deletions(-) diff --git a/src/south/gearbox/goldstone/south/gearbox/interfaces.py b/src/south/gearbox/goldstone/south/gearbox/interfaces.py index 0dbd34ae..9f78163e 100644 --- a/src/south/gearbox/goldstone/south/gearbox/interfaces.py +++ b/src/south/gearbox/goldstone/south/gearbox/interfaces.py @@ -759,14 +759,29 @@ async def reconcile_interface(self, ifname, obj, config): await obj.set("auto-negotiation", "true" if anlt else "false") async def reconcile(self): - prefix = "/goldstone-interfaces:interfaces/interface" + xpath = "/goldstone-interfaces:interfaces/interface/config" + config = self.get_running_data(xpath, default=[]) - for ifname, obj, _ in await self.get_ifname_list(): - xpath = f"{prefix}[name='{ifname}']" - config = self.get_running_data( - xpath, default={}, include_implicit_defaults=True - ) - await self.reconcile_interface(ifname, obj, config) + remove = set() + + for intf in config: + ifname = intf["name"] + pin_mode = intf.get("pin-mode") + if pin_mode: + info = self.get_interface_info(ifname, pin_mode.lower()) + remove |= set(info["interface"].get("conflicts-with", [])) + + create = set(self._interface_info.keys()) - remove + + h = PinModeHandler(self, None) + h.user = {} + # ensure TAI doesn't have interfaces that conflict with the current + # pin-mode configuration + await h.remove(remove) + + # ensure TAI has all interfaces that doesn't conflict with the current + # pin-mode configuration + await h.create(create) async def tai_cb(self, obj, attr_meta, msg): logger.info(f"{obj}, {obj.obj}") @@ -930,9 +945,15 @@ async def create_interface(self, ifname, config): index = v[2] - 1 if v[1] == 0: # hostif - obj = await m.create_hostif(index) + try: + obj = m.get_hostif(index) + except taish.TAIException: + obj = await m.create_hostif(index) elif v[1] == 1: # netif - obj = await m.create_netif(index) + try: + obj = m.get_netif(index) + except taish.TAIException: + obj = await m.create_netif(index) await self.reconcile_interface(ifname, obj, config) diff --git a/src/south/gearbox/tests/platform.json b/src/south/gearbox/tests/platform.json index cfdf72fb..842e5995 100644 --- a/src/south/gearbox/tests/platform.json +++ b/src/south/gearbox/tests/platform.json @@ -1,54 +1,11 @@ [ {"interface": {"name": "Interface1/0/1", "pin-mode": "nrz"}, "component": {"name": "port1"}}, - {"interface": {"name": "Interface1/0/2", "pin-mode": "nrz"}, "component": {"name": "port2"}}, - {"interface": {"name": "Interface1/0/3", "pin-mode": "nrz"}, "component": {"name": "port3"}}, - {"interface": {"name": "Interface1/0/4", "pin-mode": "nrz"}, "component": {"name": "port4"}}, - {"interface": {"name": "Interface1/0/5", "pin-mode": "nrz"}, "component": {"name": "port5"}}, - {"interface": {"name": "Interface1/0/6", "pin-mode": "nrz"}, "component": {"name": "port6"}}, - {"interface": {"name": "Interface1/0/7", "pin-mode": "nrz"}, "component": {"name": "port7"}}, - {"interface": {"name": "Interface1/0/8", "pin-mode": "nrz"}, "component": {"name": "port8"}}, {"interface": {"name": "Interface1/1/1", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "0", "index": 0}}}, {"interface": {"name": "Interface1/1/2", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface1/1/3", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "2", "index": 2}}}, - {"interface": {"name": "Interface1/1/4", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "3", "index": 3}}}, - {"interface": {"name": "Interface1/1/5", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface1/1/6", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface1/1/7", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "2", "index": 2}}}, - {"interface": {"name": "Interface1/1/8", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "3", "index": 3}}}, {"interface": {"name": "Interface1/1/1", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface1/1/2"]}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface1/1/3", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface1/1/4"]}, "tai": {"module": {"name": "piu1", "location": "1"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface1/1/5", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface1/1/6"]}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface1/1/7", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface1/1/8"]}, "tai": {"module": {"name": "piu2", "location": "2"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface2/0/1", "pin-mode": "nrz"}, "component": {"name": "port9"}}, - {"interface": {"name": "Interface2/0/2", "pin-mode": "nrz"}, "component": {"name": "port10"}}, - {"interface": {"name": "Interface2/0/3", "pin-mode": "nrz"}, "component": {"name": "port11"}}, - {"interface": {"name": "Interface2/0/4", "pin-mode": "nrz"}, "component": {"name": "port12"}}, - {"interface": {"name": "Interface2/0/5", "pin-mode": "nrz"}, "component": {"name": "port13"}}, - {"interface": {"name": "Interface2/0/6", "pin-mode": "nrz"}, "component": {"name": "port14"}}, - {"interface": {"name": "Interface2/0/7", "pin-mode": "nrz"}, "component": {"name": "port15"}}, - {"interface": {"name": "Interface2/0/8", "pin-mode": "nrz"}, "component": {"name": "port16"}}, - {"interface": {"name": "Interface2/1/1", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface2/1/2", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface2/1/3", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "2", "index": 2}}}, - {"interface": {"name": "Interface2/1/4", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "3", "index": 3}}}, - {"interface": {"name": "Interface2/1/5", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface2/1/6", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface2/1/7", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "2", "index": 2}}}, - {"interface": {"name": "Interface2/1/8", "default": true, "pin-mode": "pam4"}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "3", "index": 3}}}, - {"interface": {"name": "Interface2/1/1", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface2/1/2"]}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface2/1/3", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface2/1/4"]}, "tai": {"module": {"name": "piu3", "location": "3"}, "hostif": {"name": "1", "index": 1}}}, - {"interface": {"name": "Interface2/1/5", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface2/1/6"]}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "0", "index": 0}}}, - {"interface": {"name": "Interface2/1/7", "default": false, "pin-mode": "nrz", "conflicts-with": ["Interface2/1/8"]}, "tai": {"module": {"name": "piu4", "location": "4"}, "hostif": {"name": "1", "index": 1}}}, {"component": {"name": "piu1"}, "tai": {"module": {"name": "piu1", "location": "1"}, "netif": {"name": "0", "index": 0}}}, - {"component": {"name": "piu2"}, "tai": {"module": {"name": "piu2", "location": "2"}, "netif": {"name": "0", "index": 0}}}, - {"component": {"name": "piu3"}, "tai": {"module": {"name": "piu3", "location": "3"}, "netif": {"name": "0", "index": 0}}}, - {"component": {"name": "piu4"}, "tai": {"module": {"name": "piu4", "location": "4"}, "netif": {"name": "0", "index": 0}}}, {"synce-reference-clock": {"name": "0", "index": 0, "gearbox": {"name": "1"}}, "input-reference": {"name": "0", "index": 0, "dpll": {"name": "1"}}}, {"synce-reference-clock": {"name": "1", "index": 1, "gearbox": {"name": "1"}}, "input-reference": {"name": "1", "index": 1, "dpll": {"name": "1"}}}, {"synce-reference-clock": {"name": "2", "index": 2, "gearbox": {"name": "1"}}, "input-reference": {"name": "2", "index": 2, "dpll": {"name": "1"}}}, - {"synce-reference-clock": {"name": "3", "index": 3, "gearbox": {"name": "1"}}, "input-reference": {"name": "3", "index": 3, "dpll": {"name": "1"}}}, - {"synce-reference-clock": {"name": "0", "index": 0, "gearbox": {"name": "2"}}, "input-reference": {"name": "4", "index": 4, "dpll": {"name": "1"}}}, - {"synce-reference-clock": {"name": "1", "index": 1, "gearbox": {"name": "2"}}, "input-reference": {"name": "5", "index": 5, "dpll": {"name": "1"}}}, - {"synce-reference-clock": {"name": "2", "index": 2, "gearbox": {"name": "2"}}, "input-reference": {"name": "6", "index": 6, "dpll": {"name": "1"}}}, - {"synce-reference-clock": {"name": "3", "index": 3, "gearbox": {"name": "2"}}, "input-reference": {"name": "7", "index": 7, "dpll": {"name": "1"}}} + {"synce-reference-clock": {"name": "3", "index": 3, "gearbox": {"name": "1"}}, "input-reference": {"name": "3", "index": 3, "dpll": {"name": "1"}}} ] diff --git a/src/south/gearbox/tests/tests.py b/src/south/gearbox/tests/tests.py index 02cf852b..e299d70b 100644 --- a/src/south/gearbox/tests/tests.py +++ b/src/south/gearbox/tests/tests.py @@ -44,12 +44,16 @@ def test_get_default(self): class TestBase(unittest.IsolatedAsyncioTestCase): def patch_taish(self): - async def set_(*args): - self.set_logs.append(args) + async def set_(oid, *args): + logs = self.set_logs.get(oid, {}) + logs[args[0]] = args[1] + self.set_logs[oid] = logs - async def set_multiple(*args): + async def set_multiple(*args, oid): for a in args[0]: - self.set_logs.append(a) + logs = self.set_logs.get(oid, {}) + logs[a[0]] = a[1] + self.set_logs[oid] = logs async def module_get(*args, **kwargs): if args[0] in ["alarm-notification", "notify"]: @@ -192,8 +196,8 @@ def f(oid, spec): obj = mock.AsyncMock(spec=spec) obj.monitor = lambda *args, **kwargs: monitor(spec, *args, **kwargs) obj.get = lambda *args, **kwargs: get(spec, *args, **kwargs) - obj.set = set_ - obj.set_multiple = set_multiple + obj.set = lambda *args: set_(oid, *args) + obj.set_multiple = lambda *args: set_multiple(*args, oid=oid) obj.get_multiple = lambda *args, **kwargs: get_multiple( spec, *args, **kwargs ) @@ -211,12 +215,12 @@ def get_hostif(*args): module = mock.AsyncMock(spec=Module(None, None)) module.monitor = monitor module.get = module_get - module.set = set_ - module.set_multiple = set_multiple + module.set = lambda *args: set_(0x1, *args) + module.set_multiple = lambda *args: set_multiple(*args, oid=0x1) module.get_multiple = lambda *args, **kwargs: get_multiple( Module(None, None), *args, **kwargs ) - module.oid = 1 + module.oid = 0x1 module.get_netif = get_netif module.get_hostif = get_hostif module.get_attribute_capability = get_attribute_capability @@ -255,7 +259,7 @@ async def asyncSetUp(self): self.conn.delete_all("goldstone-interfaces") self.conn.apply() - self.set_logs = [] + self.set_logs = {} self.patch_taish() @@ -398,17 +402,16 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("signal-rate", "otu4"), - ("loopback-type", "none"), - ("prbs-type", "none"), - ("fec-type", "rs"), - ("auto-negotiation", "false"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x2000000010000], + { + "provision-mode": "none", + "signal-rate": "otu4", + "loopback-type": "none", + "prbs-type": "none", + "fec-type": "rs", + "auto-negotiation": "false", + "tx-timing-mode": "auto", + }, ) await asyncio.to_thread(test) @@ -428,17 +431,15 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "none"), - ("prbs-type", "none"), - ("fec-type", "rs"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "loopback-type": "none", + "prbs-type": "none", + "fec-type": "rs", + "tx-timing-mode": "auto", + }, ) - xpath = "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']" v = conn.get_operational(xpath, one=True) self.assertTrue("static-macsec" in v["ethernet"]) @@ -460,14 +461,13 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "none"), - ("prbs-type", "none"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x2000000010000], + { + "provision-mode": "none", + "loopback-type": "none", + "prbs-type": "none", + "tx-timing-mode": "auto", + }, ) xpath = "/goldstone-interfaces:interfaces/interface[name='Interface1/0/1']" @@ -506,15 +506,14 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "none"), - ("prbs-type", "none"), - ("fec-type", "rs"), - ("auto-negotiation", "false"), - ], + self.set_logs[0x2000000010000], + { + "provision-mode": "none", + "loopback-type": "none", + "prbs-type": "none", + "fec-type": "rs", + "auto-negotiation": "false", + }, ) xpath = "/goldstone-interfaces:interfaces/interface[name='Interface1/0/1']" @@ -543,15 +542,14 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "none"), - ("prbs-type", "none"), - ("fec-type", "rs"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "loopback-type": "none", + "prbs-type": "none", + "fec-type": "rs", + "tx-timing-mode": "auto", + }, ) await asyncio.to_thread(test) @@ -570,17 +568,17 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "shallow"), - ("prbs-type", "none"), - ("fec-type", "rs"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "loopback-type": "shallow", + "prbs-type": "none", + "fec-type": "rs", + "tx-timing-mode": "auto", + }, ) - self.set_logs = [] # clear set_logs + + self.set_logs = {} # clear set_logs conn.set( "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/loopback-mode", @@ -589,12 +587,13 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("loopback-type", "deep"), - ], + self.set_logs[0x3000000010000], + { + "loopback-type": "deep", + }, ) - self.set_logs = [] # clear set_logs + + self.set_logs = {} # clear set_logs conn.delete( "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/loopback-mode", @@ -602,10 +601,10 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("loopback-type", "none"), - ], + self.set_logs[0x3000000010000], + { + "loopback-type": "none", + }, ) await asyncio.to_thread(test) @@ -624,17 +623,17 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("provision-mode", "none"), - ("loopback-type", "none"), - ("prbs-type", "prbs7"), - ("fec-type", "rs"), - ("tx-timing-mode", "auto"), - ], + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "loopback-type": "none", + "prbs-type": "prbs7", + "fec-type": "rs", + "tx-timing-mode": "auto", + }, ) - self.set_logs = [] # clear set_logs + + self.set_logs = {} # clear set_logs conn.set( "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/prbs-mode", @@ -650,12 +649,13 @@ def test(): self.assertAlmostEqual(v, 1.20e-03) self.assertEqual( - self.set_logs, - [ - ("prbs-type", "prbs31"), - ], + self.set_logs[0x3000000010000], + { + "prbs-type": "prbs31", + }, ) - self.set_logs = [] # clear set_logs + + self.set_logs = {} # clear set_logs conn.delete( "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/prbs-mode", @@ -663,10 +663,10 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("prbs-type", "none"), - ], + self.set_logs[0x3000000010000], + { + "prbs-type": "none", + }, ) await asyncio.to_thread(test) @@ -681,7 +681,7 @@ async def asyncSetUp(self): self.conn.delete_all("goldstone-interfaces") self.conn.apply() - self.set_logs = [] + self.set_logs = {} self.patch_taish() @@ -694,7 +694,7 @@ async def asyncSetUp(self): async def test_synce_reference_clocks(self): self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) - self.set_logs = [] + self.set_logs = {} def test(): conn = Connector() @@ -714,14 +714,11 @@ def test(): conn.apply() self.assertEqual( - self.set_logs, - [ - ("pgmrclk-assignment", "oid:0x3000000010000,oid:0x3000000010000"), - ( - "tributary-mapping", - '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', - ), - ], + self.set_logs[0x1], + { + "pgmrclk-assignment": "oid:0x3000000010000,oid:0x3000000010000", + "tributary-mapping": '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', + }, ) await asyncio.to_thread(test) @@ -768,14 +765,18 @@ def test(): ) conn.apply() - self.assertTrue("tributary-mapping" in (v[0] for v in self.set_logs)) - self.set_logs = [] # clear set_logs + self.assertTrue(self.set_logs[0x1]["tributary-mapping"], []) + self.set_logs = {} # clear set_logs conn.set( "/goldstone-gearbox:gearboxes/gearbox[name='1']/config/enable-flexible-connection", False, ) conn.apply() - self.assertTrue("tributary-mapping" in (v[0] for v in self.set_logs)) + + self.assertTrue( + self.set_logs[0x1]["tributary-mapping"], + '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', + ) await asyncio.to_thread(test) @@ -827,28 +828,37 @@ def test_oper_cb(): async def test_reconcile(self): self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "nrz"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("auto-negotiation", "false"), - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "pam4"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("macsec-static-key", ""), - ( - "tributary-mapping", - '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', - ), - ("admin-status", "up"), - ], + self.set_logs[0x1], + { + "tributary-mapping": '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', + "admin-status": "up", + }, + ) + + self.assertEqual( + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "signal-rate": "100-gbe", + "pin-mode": "pam4", + "fec-type": "rs", + "mtu": DEFAULT_MTU, + "mru": DEFAULT_MTU, + "macsec-static-key": "", + }, + ) + + self.assertEqual( + self.set_logs[0x2000000010000], + { + "provision-mode": "none", + "signal-rate": "100-gbe", + "pin-mode": "nrz", + "fec-type": "rs", + "mtu": DEFAULT_MTU, + "mru": DEFAULT_MTU, + "auto-negotiation": "false", + }, ) async def test_reconcile_with_admin_status_down(self): @@ -864,29 +874,13 @@ def setup(): await asyncio.to_thread(setup) self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) + self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "nrz"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("auto-negotiation", "false"), - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "pam4"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("macsec-static-key", ""), - ( - "tributary-mapping", - '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', - ), - ("admin-status", "down"), - ], + self.set_logs[0x1], + { + "tributary-mapping": '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', + "admin-status": "down", + }, ) async def test_reconcile_with_admin_status_up(self): @@ -902,29 +896,39 @@ def setup(): await asyncio.to_thread(setup) self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) + + self.assertEqual( + self.set_logs[0x1], + { + "tributary-mapping": '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', + "admin-status": "up", + }, + ) + + self.assertEqual( + self.set_logs[0x2000000010000], + { + "provision-mode": "none", + "signal-rate": "100-gbe", + "pin-mode": "nrz", + "fec-type": "rs", + "mtu": DEFAULT_MTU, + "mru": DEFAULT_MTU, + "auto-negotiation": "false", + }, + ) + self.assertEqual( - self.set_logs, - [ - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "nrz"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("auto-negotiation", "false"), - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "pam4"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("macsec-static-key", ""), - ( - "tributary-mapping", - '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', - ), - ("admin-status", "up"), - ], + self.set_logs[0x3000000010000], + { + "provision-mode": "none", + "signal-rate": "100-gbe", + "pin-mode": "pam4", + "fec-type": "rs", + "mtu": DEFAULT_MTU, + "mru": DEFAULT_MTU, + "macsec-static-key": "", + }, ) async def test_reconcile_with_intf_admin_status_up(self): @@ -945,26 +949,49 @@ def setup(): self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) self.assertEqual( - self.set_logs, - [ - ("provision-mode", "normal"), - ("signal-rate", "100-gbe"), - ("pin-mode", "nrz"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("auto-negotiation", "false"), - ("provision-mode", "none"), - ("signal-rate", "100-gbe"), - ("pin-mode", "pam4"), - ("fec-type", "rs"), - ("mtu", DEFAULT_MTU), - ("mru", DEFAULT_MTU), - ("macsec-static-key", ""), - ( - "tributary-mapping", - '[{"oid:0x3000000010000": ["oid:0x2000000010000"]}]', - ), - ("admin-status", "up"), - ], + self.set_logs[0x2000000010000], + { + "auto-negotiation": "false", + "fec-type": "rs", + "mru": DEFAULT_MTU, + "mtu": DEFAULT_MTU, + "pin-mode": "nrz", + "provision-mode": "normal", + "signal-rate": "100-gbe", + }, + ) + + async def test_reconcile_with_intf_pin_mode(self): + def setup(): + conn = Connector() + conn.set( + "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/name", + "Interface1/1/1", + ) + conn.set( + "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/pin-mode", + "NRZ", + ) + conn.set( + "/goldstone-interfaces:interfaces/interface[name='Interface1/1/1']/config/admin-status", + "UP", + ) + + conn.apply() + + await asyncio.to_thread(setup) + + self.tasks = list(asyncio.create_task(c) for c in await self.server.start()) + + self.assertEqual( + self.set_logs[0x3000000010000], + { + "fec-type": "rs", + "macsec-static-key": "", + "mru": DEFAULT_MTU, + "mtu": DEFAULT_MTU, + "pin-mode": "nrz", + "provision-mode": "normal", + "signal-rate": "100-gbe", + }, )