Skip to content
Snippets Groups Projects
Commit 01a2d0fd authored by Robert Latta's avatar Robert Latta
Browse files

populated other_end_interfacec_name if it's empty; updated tests inline with other update

parent a932442f
No related branches found
No related tags found
No related merge requests found
......@@ -176,6 +176,20 @@ def _juniper_field_update(record):
record["interface_name"] += separator + str(record["port"])
if record["logical_unit"] is not None and record["logical_unit"] != "":
record["interface_name"] += "." + str(record["logical_unit"])
if not record["other_end_interface_name"]:
record["other_end_interface_name"] = record["other_end_card_id"]
if record["other_end_port"] is not None \
and record["other_end_port"] != "":
separator = ""
if "-" in record["other_end_interface_name"]:
separator = "/"
record["other_end_interface_name"] += \
separator + str(record["other_end_port"])
if record["other_end_logical_unit"] is not None \
and record["other_end_logical_unit"] != "":
record["other_end_interface_name"] += \
"." + str(record["other_end_logical_unit"])
return record
......
......@@ -52,53 +52,83 @@ def test_infinera_field_update():
def test_juniper_field_update():
i = {
"interface_name": "xe-1/2",
"logical_unit": None
"logical_unit": None,
"other_end_interface_name": "xe-3/2",
"other_end_logical_unit": None
}
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-1/2"
assert r["other_end_interface_name"] == "xe-3/2"
i["interface_name"] = "xe-1/2"
i["logical_unit"] = 101
i["other_end_interface_name"] = "xe-3/2"
i["other_end_logical_unit"] = 301
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-1/2.101"
assert r["other_end_interface_name"] == "xe-3/2.301"
i["interface_name"] = "xe-1/2"
i["logical_unit"] = 0
i["other_end_interface_name"] = "xe-3/2"
i["other_end_logical_unit"] = 0
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-1/2.0"
assert r["other_end_interface_name"] == "xe-3/2.0"
i["interface_name"] = "xe-1/2"
i["logical_unit"] = None
i["port"] = 0
i["other_end_interface_name"] = "xe-3/2"
i["other_end_logical_unit"] = None
i["other_end_port"] = 0
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-1/2"
assert r["other_end_interface_name"] == "xe-3/2"
i["interface_name"] = None
i["card_id"] = "xe-2/0"
i["logical_unit"] = None
i["port"] = None
i["other_end_interface_name"] = None
i["other_end_card_id"] = "xe-3/0"
i["other_end_logical_unit"] = None
i["other_end_port"] = None
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-2/0"
assert r["other_end_interface_name"] == "xe-3/0"
i["interface_name"] = None
i["port"] = "0"
i["other_end_interface_name"] = None
i["other_end_port"] = "0"
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-2/0/0"
assert r["other_end_interface_name"] == "xe-3/0/0"
i["interface_name"] = None
i["port"] = 0
i["other_end_interface_name"] = None
i["other_end_port"] = 0
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-2/0/0"
assert r["other_end_interface_name"] == "xe-3/0/0"
i["interface_name"] = None
i["logical_unit"] = "123"
i["other_end_interface_name"] = None
i["other_end_logical_unit"] = "323"
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-2/0/0.123"
assert r["other_end_interface_name"] == "xe-3/0/0.323"
i["interface_name"] = None
i["logical_unit"] = 123
i["other_end_interface_name"] = None
i["other_end_logical_unit"] = 323
r = inventory_provider.db.opsdb._juniper_field_update(i)
assert r["interface_name"] == "xe-2/0/0.123"
assert r["other_end_interface_name"] == "xe-3/0/0.323"
def test_coriant_update_fields():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment