Skip to content

Commit

Permalink
[change] NetJSON DeviceMonitoring compliance #2
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
purhan committed Jun 5, 2021
1 parent 11f8ea4 commit 0daab82
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 57 deletions.
35 changes: 14 additions & 21 deletions netengine/backends/snmp/airos.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,10 @@ def interfaces_to_dict(self):
result = self._dict(
{
'name': self.interfaces_MAC[i]['name'],
'type': self.interfaces_type[i]['type'],
'mac_address': self.interfaces_MAC[i]['mac_address'],
'rx_bytes': int(self.interfaces_bytes[i]['rx']),
'tx_bytes': int(self.interfaces_bytes[i]['tx']),
'state': self.interfaces_state[i]['state'],
'mtu': int(self.interfaces_mtu[i]['mtu']),
'speed': int(self.interfaces_speed[i]['speed']),
'statistics': {
'rx_bytes': int(self.interfaces_bytes[i]['rx']),
'tx_bytes': int(self.interfaces_bytes[i]['tx']),
},
}
)
results.append(result)
Expand Down Expand Up @@ -403,20 +400,16 @@ def RAM_free(self):
def to_dict(self):
return self._dict(
{
'name': self.name,
'type': 'radio',
'os': self.os[0],
'os_version': self.os[1],
'manufacturer': self.manufacturer,
'model': self.model,
'RAM_total': self.RAM_total,
'RAM_free': self.RAM_free,
'uptime': self.uptime,
'uptime_tuple': self.uptime_tuple,
'type': 'DeviceMonitoring',
'general': {
'uptime': self.uptime,
},
'resources': {
'memory': {
'total': self.RAM_total,
'free': self.RAM_free,
},
},
'interfaces': self.interfaces_to_dict,
'antennas': [],
'wireless_dbm': self.wireless_dbm,
'wireless_links': self.wireless_links,
'routing_protocols': None,
}
)
35 changes: 14 additions & 21 deletions netengine/backends/snmp/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,10 @@ def interfaces_to_dict(self):
result = self._dict(
{
'name': name,
'type': if_type,
'mac_address': mac_address,
'ip_address': ip_address,
'netmask': netmask,
'rx_bytes': rx_bytes,
'tx_bytes': tx_bytes,
'state': state,
'mtu': mtu,
'speed': speed,
'statistics': {
'rx_bytes': rx_bytes,
'tx_bytes': tx_bytes,
},
}
)
results.append(result)
Expand All @@ -392,17 +387,15 @@ def RAM_total(self):
def to_dict(self):
return self._dict(
{
'name': self.name,
'type': 'radio',
'os': self.os[0],
'os_version': self.os[1],
'manufacturer': self.manufacturer,
'model': None,
'RAM_total': self.RAM_total,
'uptime': self.uptime,
'uptime_tuple': self.uptime_tuple,
'interfaces': self.get_interfaces(),
'antennas': [],
'routing_protocols': None,
'type': 'DeviceMonitoring',
'general': {
'uptime': self.uptime,
},
'resources': {
'memory': {
'total': self.RAM_total,
}
},
'interfaces': self.interfaces_to_dict,
}
)
10 changes: 0 additions & 10 deletions tests/test_snmp/test_airos.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ def test_to_dict(self):
)
self.assertTrue(isinstance(self.device.to_dict(), dict))

def test_manufacturer_to_dict(self):
with self.nextcmd_patcher as np:
SpyMock._update_patch(
np,
_mock_side_effect=lambda *args: self._get_mocked_wireless_links(
data=args
),
)
self.assertIsNotNone(self.device.to_dict()['manufacturer'])

def test_manufacturer(self):
with self.nextcmd_patcher:
self.assertIsNotNone(self.device.manufacturer)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_snmp/test_openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,5 @@ def test_to_dict(self):
len(device_dict['interfaces']), len(self.device.get_interfaces()),
)

def test_manufacturer_to_dict(self):
with self.nextcmd_patcher as p:
SpyMock._update_patch(p, _mock_return_value=[0, 0, 0, [[[0, 1]]] * 5])
self.assertIsNotNone(self.device.to_dict()['manufacturer'])

def tearDown(self):
patch.stopall()

0 comments on commit 0daab82

Please sign in to comment.