Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
feat: Updates to fix configs in IPF v4.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeff07 committed Apr 21, 2022
1 parent 7e624ed commit fde1016
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
15 changes: 8 additions & 7 deletions ipfabric/tools/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@


class Config(BaseModel):
config_id: str = Field(alias="_id")
config_id: str = Field(alias="id")
sn: str
hostname: str
config_hash: str = Field(alias="hash")
status: str
last_change: datetime = Field(alias="lastChange")
last_check: datetime = Field(alias="lastCheck")
last_change: datetime = Field(alias="lastChangeAt")
last_check: datetime = Field(alias="lastCheckAt")
text: Optional[str] = None


Expand Down Expand Up @@ -57,16 +57,17 @@ def get_all_configurations(self, device: Optional[str] = None, sn: Optional[str]
else:
res = self.ipf.fetch_all(
"tables/management/configuration",
sort={"order": "desc", "column": "lastChange"},
sort={"order": "desc", "column": "lastChangeAt"},
columns=[
"_id",
"id",
"sn",
"hostname",
"lastChange",
"lastCheck",
"lastChangeAt",
"lastCheckAt",
"status",
"hash",
],
snapshot=False
)
results = defaultdict(list)
[results[cfg["sn"]].append(Config(**cfg)) for cfg in res]
Expand Down
54 changes: 27 additions & 27 deletions tests/unittests/tools/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class Models(unittest.TestCase):
def test_config(self):
cfg = configuration.Config(
_id="test",
id="test",
sn="test",
hostname="test",
hash="test",
status="test",
lastCheck=1637629200,
lastChange=1637629200,
lastCheckAt=1637629200,
lastChangeAt=1637629200,
)
self.assertIsInstance(cfg, configuration.Config)

Expand All @@ -24,12 +24,12 @@ def setUp(self) -> None:

def test_get_all_configurations(self):
example = {
"_id": "619d84648eec5403579025bf",
"id": "619d84648eec5403579025bf",
"sn": "OVAEB9DD0",
"hostname": "McastRouter2",
"hash": "be6ae3d00363cd034be33e16e0623c25fe03c3c3",
"lastChange": 1637712996000,
"lastCheck": 1637712996000,
"lastChangeAt": 1637712996000,
"lastCheckAt": 1637712996000,
"status": "saved",
}
self.dc.ipf.fetch_all.return_value = [example]
Expand All @@ -38,12 +38,12 @@ def test_get_all_configurations(self):

def test_get_all_configurations_device(self):
example = {
"_id": "619d84648eec5403579025bf",
"id": "619d84648eec5403579025bf",
"sn": "OVAEB9DD0",
"hostname": "McastRouter2",
"hash": "be6ae3d00363cd034be33e16e0623c25fe03c3c3",
"lastChange": 1637712996000,
"lastCheck": 1637712996000,
"lastChangeAt": 1637712996000,
"lastCheckAt": 1637712996000,
"status": "saved",
}
self.dc.ipf.fetch_all.return_value = [example]
Expand Down Expand Up @@ -77,13 +77,13 @@ def test_get_configuration(self, configs, device):
"OVAEB9DD0": [
configuration.Config(
**{
"_id": "619d84648eec5403579025bf",
"id": "619d84648eec5403579025bf",
"sn": "OVAEB9DD0",
"hostname": "McastRouter2",
"status": "saved",
"hash": "be6ae3d00363cd034be33e16e0623c25fe03c3c3",
"lastChange": 1637712996000,
"lastCheck": 1637712996000,
"lastChangeAt": 1637712996000,
"lastCheckAt": 1637712996000,
}
)
]
Expand Down Expand Up @@ -114,13 +114,13 @@ def test_get_configuration_hash_none(self, hash, configs, device):
"test_sn": [
configuration.Config(
**{
"_id": "619d84648eec5403579025bf",
"id": "619d84648eec5403579025bf",
"sn": "OVAEB9DD0",
"hostname": "McastRouter2",
"status": "saved",
"hash": "be6ae3d00363cd034be33e16e0623c25fe03c3c3",
"lastChange": 1637712996000,
"lastCheck": 1637712996000,
"lastChangeAt": 1637712996000,
"lastCheckAt": 1637712996000,
}
)
]
Expand All @@ -131,39 +131,39 @@ def test_get_configuration_hash_none(self, hash, configs, device):
def test_get_hash(self):
data = [
{
"_id": "619d83a68eec5403579025b8",
"id": "619d83a68eec5403579025b8",
"sn": "a22ff67",
"hostname": "L34R3",
"hash": "2ec117a68eba80b1d0d644937cd3ab8d29fcde14",
"lastChange": 1637712806000,
"lastCheck": 1637712806000,
"lastChangeAt": 1637712806000,
"lastCheckAt": 1637712806000,
"status": "saved",
},
{
"_id": "616dffd4c476400368b3fd3c",
"id": "616dffd4c476400368b3fd3c",
"sn": "a22ff67",
"hostname": "L34R3",
"hash": "ea732ea21150a0d9f1826bc59b4023dcc609c853",
"lastChange": 1634598867000,
"lastCheck": 1637626401276,
"lastChangeAt": 1634598867000,
"lastCheckAt": 1637626401276,
"status": "saved",
},
{
"_id": "608747d43eb36603a1b48db3",
"id": "608747d43eb36603a1b48db3",
"sn": "a22ff67",
"hostname": "L34R3",
"hash": "e415efae4fedba53ca13e11a014a1893400cd92f",
"lastChange": 1619478484000,
"lastCheck": 1625008990651,
"lastChangeAt": 1619478484000,
"lastCheckAt": 1625008990651,
"status": "saved",
},
{
"_id": "6070de4cf58e8c66c307c09e",
"id": "6070de4cf58e8c66c307c09e",
"sn": "10.34.255.103",
"hostname": "L34R3",
"hash": "0140c1010e60c5efe2eea68fd90282b21aa2ad3b",
"lastChange": 1618009676000,
"lastCheck": 1619392682986,
"lastChangeAt": 1618009676000,
"lastCheckAt": 1619392682986,
"status": "saved",
},
]
Expand Down

0 comments on commit fde1016

Please sign in to comment.