dropbox / nsot

Network Source of Truth is an open source IPAM and network inventory database
https://nsot.readthedocs.io
Other
399 stars 66 forks source link

[Issue #261] Update Circuit addresses to enumerate addresses of all child interfaces #336

Closed khardsonhurley closed 6 years ago

khardsonhurley commented 6 years ago

What this diff addresses This diff addresses Issue #261. I have added support to enumerate addresses for all child interfaces. I have also adjusted the unit tests to test that this works as expected.

See it in action For the following interfaces:

+----------------------------------------------------------------------------+
| ID   Name (Key)        Parent          MAC    Addresses         Attributes |
+----------------------------------------------------------------------------+
| 6    foo1-bb01:ae0     None            None   185.45.21.10/32              |
|                                               185.45.21.8/32               |
| 7    foo1-bb02:ae0     None            None                                |
| 8    foo1-bb01:ae0.0   foo1-bb01:ae0   None   185.45.21.6/32               |
| 9    foo1-bb02:ae0.0   foo1-bb02:ae0   None   185.45.21.7/32               |
|                                               185.45.21.5/32               |
+----------------------------------------------------------------------------+

The list of addresses would be a list of its own addresses, appended by all addresses of each child interface.

In [1]: circuits = Circuit.objects.all()

In [2]: circuits
Out[2]: <ResourceSetTheoryQuerySet [<Circuit: foo1-bb01:ae0_foo1-bb02:ae0>, <Circuit: foo1-bb01:ae0.0_foo1-bb02:ae0.0>]>

In [3]: circuit_of_parent_ifaces = circuits[0]

In [4]: circuit_of_parent_ifaces.addresses
Out[4]:
[<Network: 185.45.21.10/32>,
 <Network: 185.45.21.8/32>,
 <Network: 185.45.21.6/32>,
 <Network: 185.45.21.7/32>,
 <Network: 185.45.21.5/32>]

Note that the first two are addresses are associated with the circuit's a side interface, the third is the address associated with child interface on the a side, and the last two with the child interface on the z side.

TESTING


================================================================================ test session starts ================================================================================
platform linux2 -- Python 2.7.12, pytest-3.4.2, py-1.5.4, pluggy-0.6.0 -- /home/khardson/src/nsot/env/bin/python2
cachedir: ../../.pytest_cache
Django settings: tests.test_settings (from ini file)
Using NSoT API version: None
rootdir: /home/khardson/src/nsot/nsot, inifile: pytest.ini
plugins: django-3.1.2, pythonpath-0.6
collected 6 items

test_circuits.py::test_creation PASSED                                                                                                                                        [ 16%]
test_circuits.py::test_attributes PASSED                                                                                                                                      [ 33%]
test_circuits.py::TestInterfaceFor::test_normal_conditions PASSED                                                                                                             [ 50%]
test_circuits.py::TestInterfaceFor::test_single_sided PASSED                                                                                                                  [ 66%]
test_circuits.py::TestInterfaceFor::test_looped_circuit PASSED                                                                                                                [ 83%]
test_circuits.py::TestInterfaceFor::test_bogus_device PASSED                                                                                                                  [100%]

============================================================================= 6 passed in 3.56 seconds ==============================================================================```