Mentions légales du service

Skip to content
Snippets Groups Projects
Commit f8cc43bd authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

Fix #105

parent abd4c647
No related branches found
No related tags found
No related merge requests found
......@@ -260,28 +260,30 @@ class NetDevice(object):
@classmethod
def sync_from_ansible(cls, device: Dict, networks: Networks):
"""
"ansible_enx106530ad1e3f": {
"active": true,
"device": "enx106530ad1e3f",
"ipv4": {
"address": "192.168.1.14",
"broadcast": "192.168.1.255",
"netmask": "255.255.255.0",
"network": "192.168.1.0"
"ansible_br0": {
"ipv4": {
"address": "172.16.99.11",
"broadcast": "172.16.111.255",
"netmask": "255.255.240.0",
"network": "172.16.96.0"
},
"ipv4_secondaries": [
{
"address": "10.158.0.2",
"broadcast": "",
"netmask": "255.255.252.0",
"network": "10.158.0.0"
}
"macaddress": "10:65:30:ad:1e:3f",
"module": "r8152",
"mtu": 1500,
"pciid": "2-1.2:1.0",
"promisc": false,
"speed": 1000,
"type": "ether"
],
"ipv6": [{...}
]
}
"""
# build all ips
addresses = set()
versions = ["ipv4", "ipv6"]
for version in versions:
keys = ["ipv4", "ipv4_secondaries", "ipv6"]
for version in keys:
if version not in device:
continue
ips = device[version]
......
......@@ -81,6 +81,29 @@ class TestGenerateInventoryString(EnosTest):
class TestGetHostNet(EnosTest):
def test_map_devices_with_secondary_ipv4(self):
n1, n2 = [
DefaultNetwork(address="1.2.3.0/24"),
DefaultNetwork(address="4.5.6.0/24"),
]
networks = dict(role1=[n1, n2])
# from ansible
facts = {
"ansible_interfaces": ["eth0", "eth1"],
"ansible_eth0": {
"device": "eth0",
"ipv4": {"address": "1.2.3.4", "netmask": "255.255.255.0"},
"ipv4_secondaries": [{"address": "4.5.6.7", "netmask": "255.255.255.0"}],
"type": "ether",
},
}
expected = [
NetDevice("eth0", set([IPAddress("1.2.3.4/24", n1)])),
NetDevice("eth0", set([IPAddress("4.5.6.7/24", n2)])),
]
self.assertCountEqual(expected, _build_devices(facts, networks))
def test__map_devices_all_match_single(self):
n1, n2 = [
DefaultNetwork(address="1.2.3.0/24"),
......
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