Skip to content

Commit

Permalink
south-gearbox: fix bug of reconcile() when pin-mode configuration exists
Browse files Browse the repository at this point in the history
Signed-off-by: Wataru Ishida <[email protected]>
  • Loading branch information
ishidawataru committed Oct 14, 2022
1 parent 0c8b7dc commit d17c29b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/south/gearbox/goldstone/south/gearbox/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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}")
Expand Down Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions src/south/gearbox/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,27 @@ def setup():
("admin-status", "up"),
],
)

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(len(self.set_logs), 251)

0 comments on commit d17c29b

Please sign in to comment.