-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature.addpatchposition #381
Open
Josephine-Rutten
wants to merge
12
commits into
SUNET:develop
Choose a base branch
from
Josephine-Rutten:feature.addpatchposition
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
482b0e0
add the patch position to the file
419f202
changes to add patch positions to interfaces
40d8114
add the patch position to the file
4f49b40
changes to add patch positions to interfaces
611eaa2
Merge branch 'feature.addpatchposition' of https://github.com/Josephi…
Josephine-Rutten 82c7500
update requirements to fix junos interface bug
fc7e14b
fixed bugs and added unit tests
da6c763
changed values to be more realistic
fce3f20
improved unit test cleanup
c8c0f2b
change names of interfaces to not disturb other tests
df5ce01
change names of interfaces to be more realistic
94c3674
add patch_position to sync_devices
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import json | ||
import os | ||
import unittest | ||
from ipaddress import IPv4Address | ||
|
||
import pkg_resources | ||
import pytest | ||
import yaml | ||
|
||
from cnaas_nms.api import app | ||
from cnaas_nms.api.tests.app_wrapper import TestAppWrapper | ||
from cnaas_nms.db.device import Device, DeviceState, DeviceType | ||
from cnaas_nms.db.interface import Interface, InterfaceConfigType | ||
from cnaas_nms.db.session import sqla_session | ||
|
||
|
||
@pytest.mark.integration | ||
class InterfaceTests(unittest.TestCase): | ||
@pytest.fixture(autouse=True) | ||
def requirements(self, postgresql, settings_directory): | ||
"""Ensures the required pytest fixtures are loaded implicitly for all these tests""" | ||
pass | ||
|
||
def cleandb(self): | ||
with sqla_session() as session: # type: ignore | ||
for interface_name in ["custom", "downlink"]: | ||
interface = session.query(Interface).filter(Interface.name == interface_name).one_or_none() | ||
if interface: | ||
session.delete(interface) | ||
session.commit() | ||
for hostname in ["testdevice"]: | ||
device = session.query(Device).filter(Device.hostname == hostname).one_or_none() | ||
if device: | ||
session.delete(device) | ||
session.commit() | ||
|
||
def setUp(self): | ||
self.jwt_auth_token = None | ||
data_dir = pkg_resources.resource_filename(__name__, "data") | ||
with open(os.path.join(data_dir, "testdata.yml"), "r") as f_testdata: | ||
self.testdata = yaml.safe_load(f_testdata) | ||
if "jwt_auth_token" in self.testdata: | ||
self.jwt_auth_token = self.testdata["jwt_auth_token"] | ||
self.app = app.app | ||
self.app.wsgi_app = TestAppWrapper(self.app.wsgi_app, self.jwt_auth_token) | ||
self.client = self.app.test_client() | ||
self.cleandb() | ||
device_id, hostname = self.add_device() | ||
self.device_id = device_id | ||
self.device_hostname = hostname | ||
self.add_interfaces(device_id) | ||
|
||
def tearDown(self): | ||
self.cleandb() | ||
|
||
def add_device(self): | ||
with sqla_session() as session: # type: ignore | ||
device = Device( | ||
hostname="testdevice", | ||
platform="eos", | ||
management_ip=IPv4Address("10.0.1.22"), | ||
state=DeviceState.MANAGED, | ||
device_type=DeviceType.ACCESS, | ||
) | ||
session.add(device) | ||
session.commit() | ||
return device.id, device.hostname | ||
|
||
def add_interfaces(self, device_id): | ||
with sqla_session() as session: # type: ignore | ||
interface = Interface( | ||
name="custom", | ||
configtype=InterfaceConfigType.ACCESS_AUTO, | ||
data={ | ||
"patch_position": "3E-H12", | ||
}, | ||
device_id=device_id, | ||
) | ||
interface2 = Interface( | ||
name="downlink", | ||
configtype=InterfaceConfigType.ACCESS_AUTO, | ||
data={}, | ||
device_id=device_id, | ||
) | ||
session.add(interface) | ||
session.add(interface2) | ||
session.commit() | ||
|
||
def test_get_interface(self): | ||
result = self.client.get(f"/api/v1.0/device/{self.device_hostname}/interfaces") | ||
self.assertEqual(result.status_code, 200) | ||
json_data = json.loads(result.data.decode()) | ||
self.assertEqual( | ||
["custom", "downlink"], | ||
[interface["name"] for interface in json_data["data"]["interfaces"]], | ||
) | ||
|
||
def test_update_interface_invalid_patch_position_not_unique(self): | ||
modify_data = { | ||
"interfaces": { | ||
"custom": { | ||
"data": { | ||
"description": "new description", | ||
} | ||
}, | ||
"downlink": { | ||
"data": { | ||
"patch_position": "3E-H12", | ||
} | ||
}, | ||
} | ||
} | ||
result = self.client.put(f"/api/v1.0/device/{self.device_hostname}/interfaces", json=modify_data) | ||
json_data = json.loads(result.data.decode()) | ||
self.assertEqual(result.status_code, 400) | ||
self.assertEqual(json_data["status"], "error") | ||
|
||
def test_update_interface(self): | ||
modify_data = { | ||
"interfaces": { | ||
"custom": { | ||
"data": { | ||
"description": "test", | ||
} | ||
}, | ||
"downlink": { | ||
"data": { | ||
"description": "test", | ||
"patch_position": "XW.H4.23", | ||
} | ||
}, | ||
} | ||
} | ||
result = self.client.put(f"/api/v1.0/device/{self.device_hostname}/interfaces", json=modify_data) | ||
json_data = json.loads(result.data.decode()) | ||
self.assertEqual(result.status_code, 200) | ||
self.assertEqual(["custom", "downlink"], list(json_data["data"]["updated"].keys())) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,7 +271,7 @@ def populate_device_vars( | |
ifindexnum = 0 | ||
if "ifclass" not in intf: | ||
continue | ||
extra_keys = ["aggregate_id", "enabled", "cli_append_str", "metric", "mtu", "tags"] | ||
extra_keys = ["aggregate_id", "enabled", "cli_append_str", "metric", "mtu", "tags", "patch_postion"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is for dist/core devices, if you want to have an option for patch_position on those devices as well you need to make some changes in settings_fields.py as well |
||
if intf["ifclass"] == "downlink": | ||
data = {} | ||
if intf["name"] in ifname_peer_map: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these lines looks like some left over debug info maybe?