Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Resource Manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
Resource Manager
Commits
94dd7a67
Commit
94dd7a67
authored
2 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
updated router loading data test
parent
534843f8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resource_management/hardware/router.py
+1
-1
1 addition, 1 deletion
resource_management/hardware/router.py
test/test_parse_router.py
+40
-11
40 additions, 11 deletions
test/test_parse_router.py
with
41 additions
and
12 deletions
resource_management/hardware/router.py
+
1
−
1
View file @
94dd7a67
...
@@ -39,7 +39,7 @@ LINE_CARDS_LIST_SCHEMA = {
...
@@ -39,7 +39,7 @@ LINE_CARDS_LIST_SCHEMA = {
'
type
'
:
'
string
'
,
'
type
'
:
'
string
'
,
# TODO: enum not really needed, but \
# TODO: enum not really needed, but \
# make it strict for now, during development
# make it strict for now, during development
'
enum
'
:
[
'
40GE
'
,
'
4x10GE
'
,
'
100GE
'
,
'
4x25GE
'
,
'
4x100GE
'
,
'
400GE
'
]
'
enum
'
:
[
'
10GE
'
,
'
40GE
'
,
'
4x10GE
'
,
'
100GE
'
,
'
4x25GE
'
,
'
4x100GE
'
,
'
400GE
'
]
}
}
},
},
'
cable
'
:
{
'
type
'
:
'
string
'
},
'
cable
'
:
{
'
type
'
:
'
string
'
},
...
...
This diff is collapsed.
Click to expand it.
test/test_parse_router.py
+
40
−
11
View file @
94dd7a67
import
re
from
jsonschema
import
validate
from
jsonschema
import
validate
from
lxml
import
etree
from
resource_management.hardware.router
\
from
resource_management.hardware.router
\
import
load_line_cards
,
LINE_CARDS_LIST_SCHEMA
import
load_router_ports
,
LINE_CARDS_LIST_SCHEMA
def
_remove_ns
(
xml
):
# cf. https://stackoverflow.com/a/51972010
doc
=
etree
.
fromstring
(
xml
)
for
elem
in
doc
.
getiterator
():
if
hasattr
(
elem
,
'
tag
'
):
elem
.
tag
=
etree
.
QName
(
elem
).
localname
# Remove unused namespace declarations
etree
.
cleanup_namespaces
(
doc
)
return
doc
def
test_load_line_cards
(
mocked_router
,
mocked_router_input_tables
):
# def _expected_fpcs(all_replies):
# # root rpc-replly element has complicated namespaces definitions
# # which mess up xpath queries ... strip these
# full_inventory_reply = etree.fromstring(all_replies['inventory'])
# chassis_inventory = full_inventory_reply[0][0]
# x = etree.tostring(chassis_inventory)
# return list(chassis_inventory.xpath(".//name[starts-with(.,'FPC')]/parent::*"))
def
test_router_ports
(
mocked_router
,
netconf_rpc_replies
):
ssh
=
{
ssh
=
{
'
username
'
:
'
bogus
'
,
'
username
'
:
'
bogus
'
,
'
private-key
'
:
'
no file
'
'
private-key
'
:
'
no file
'
}
}
fpcs
=
load_
line_card
s
(
hostname
=
'
bogus
'
,
ssh_config
=
ssh
)
fpcs
=
load_
router_port
s
(
hostname
=
'
bogus
'
,
ssh_config
=
ssh
)
fpcs
=
list
(
fpcs
)
fpcs
=
list
(
fpcs
)
validate
(
fpcs
,
LINE_CARDS_LIST_SCHEMA
)
validate
(
fpcs
,
LINE_CARDS_LIST_SCHEMA
)
expected_line_cards
=
set
(
mocked_router_input_tables
[
'
FpcHwTable
'
].
keys
())
inventory
=
_remove_ns
(
netconf_rpc_replies
[
'
inventory
'
])
expected_ports
=
set
(
mocked_router_input_tables
[
'
PhyPortTable
'
].
keys
())
expected_fpcs
=
list
(
inventory
.
xpath
(
"
.//name[starts-with(.,
'
FPC
'
)]/parent::*
"
))
assert
len
(
expected_fpcs
)
==
len
(
fpcs
)
line_cards
=
{
f
[
'
name
'
]
for
f
in
fpcs
}
def
_slot_number
(
node
):
ports
=
set
()
name
=
node
.
xpath
(
'
./name/text()
'
)[
0
]
for
f
in
fpcs
:
m
=
re
.
match
(
r
'
^(FPC|PIC) (\d+)$
'
,
name
)
ports
|=
{
p
[
'
name
'
]
for
p
in
f
[
'
ports
'
]}
assert
m
,
f
"
can
'
t parse fpc/pic name:
{
name
}
"
return
int
(
m
.
group
(
2
))
assert
line_cards
==
expected_line_cards
# not a strong test, maybe TODO: pre-compute the expected interfaces
assert
ports
==
expected_ports
# (but wait before trying this, since that
# would be hard to maintain against code changes)
assert
set
(
map
(
_slot_number
,
expected_fpcs
))
\
==
{
f
[
'
slot
'
]
for
f
in
fpcs
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment