jasondchambers / netorganizer

Network Organizer enables you to bring some order to the chaos that might be your network. It enables you to take inventory of active hosts and to neatly classify each of them taking care of fixed IP reservations. It can bring to your attention un-classified hosts that are actively on your network and invite you to classify them.
Apache License 2.0
2 stars 0 forks source link

Defect in SNA push to host groups #26

Open yzxbmlf opened 2 years ago

yzxbmlf commented 2 years ago

$ cnetorg -o Organize Loading config file /home/netorg/.netorg.cfg Loading known devices from /home/netorg/devices.yml Loading known devices from /home/netorg/devices.yml Generating devices.yml file at /home/netorg/devices.yml KnownDevicesGenerator: Skipping localhost,f8:04:2e:86:77:7a Loading known devices from /home/netorg/devices.yml NetorgGenerator: Known devices (devices.yml) differences are as follows: Adding devices: unclassified: Jasons-iPhone-11-Pro-Max ce:13:2f:72:24:17 MerakiFixedIpReservationsGenerator: skipping f8:04:2e:86:77:7a Fixed IP reservation differences are as follows: Adding reservations: 192.168.128.170 for device ce:13:2f:72:24:17 named Jasons-iPhone-11-Pro-Max Removing reservations: 192.168.128.117 for device f8:04:2e:86:77:7a named localhost $ cnetorg -p Pushing changes to Secure Network Analytics Loading config file /home/netorg/.netorg.cfg Pushing changes to Secure Network Analytics Loading known devices from /home/netorg/devices.yml Net Organizer Groups already exists No new host groups to add No host groups to update # <------------------------------------ UNEXPECTED No host groups to delete

Image

SNA doesn't match devicetable:

$ cnetorg -d | grep unclassified 66,ae:a0:45:70:3b:a6,True,True,False,192.168.128.61,unclassified,None 67,ba:5f:4e:25:84:e5,True,True,False,192.168.128.21,unclassified,None 68,a0:e7:0b:13:0c:04,True,True,True,192.168.128.223,unclassified,LT6221 69,ea:86:a8:cd:f6:6e,True,True,True,192.168.128.33,unclassified,None 70,ce:13:2f:72:24:17,True,True,True,192.168.128.170,unclassified,Jasons-iPhone-11-Pro-Max

yzxbmlf commented 2 years ago

Hmm unable to reproduce

yzxbmlf commented 2 years ago

I did manage to reproduce it. It is basically a misunderstanding on the behavior of how DeepDiff works when the lists(in this case host groups) are the same length. In this scenario, look for 'values_changed' in the diff. The bug is in SnaHostGroupManager.get_hostgroups_to_update().

yzxbmlf commented 2 years ago

Here's a new test that fails.


def test_analyze_changes_update(self):
        current_hostgroups = {
            'lights': [
                '192.168.129.61', 
                '192.168.129.21',
                '192.168.129.223',
                '192.168.129.33',
                '192.168.129.117'],
            'unclassified': [
                '192.168.128.61', 
                '192.168.128.21',
                '192.168.128.223',
                '192.168.128.33',
                '192.168.128.117']
        }
        new_hostgroups = {
            'lights': [
                '192.168.129.61', 
                '192.168.129.21',
                '192.168.129.223',
                '192.168.129.33',
                '192.168.129.170'], # Changed
            'unclassified': [
                '192.168.128.61', 
                '192.168.128.21',
                '192.168.128.223',
                '192.168.128.33',
                '192.168.128.170'] # Changed
        }
        sna_hostgroup_manager = SnaHostGroupManager(None)
        sna_hostgroup_manager.analyze_changes(current_hostgroups,new_hostgroups)
        self.assertEqual(0,len(sna_hostgroup_manager.hostgroups_to_create_set))
        self.assertEqual(2,len(sna_hostgroup_manager.hostgroups_to_update_set))
        self.assertIn('unclassified', sna_hostgroup_manager.hostgroups_to_update_set)
        self.assertIn('lights', sna_hostgroup_manager.hostgroups_to_update_set)```