Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
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
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
372a3111
Commit
372a3111
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
additional tests of peering cache data structures
parent
6fb3c30c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_worker_utils.py
+178
-13
178 additions, 13 deletions
test/test_worker_utils.py
with
178 additions
and
13 deletions
test/test_worker_utils.py
+
178
−
13
View file @
372a3111
"""
tests of a few worker utilities
"""
import
ipaddress
import
json
import
re
...
...
@@ -22,42 +23,206 @@ def backend_db():
def
test_build_subnet_db
(
mocked_worker_module
):
"""
checks that valid reverse subnet objects are created
Verify that valid reverse subnet objects are created.
:param mocked_worker_module: fixture
:return:
"""
address_schema
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
name
'
:
{
'
type
'
:
'
string
'
},
'
interface address
'
:
{
'
type
'
:
'
string
'
},
'
interface name
'
:
{
'
type
'
:
'
string
'
},
'
router
'
:
{
'
type
'
:
'
string
'
}
'
definitions
'
:
{
'
interface
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
name
'
:
{
'
type
'
:
'
string
'
},
'
interface address
'
:
{
'
type
'
:
'
string
'
},
'
interface name
'
:
{
'
type
'
:
'
string
'
},
'
router
'
:
{
'
type
'
:
'
string
'
}
},
'
required
'
:
[
'
name
'
,
'
interface address
'
,
'
interface name
'
,
'
router
'
],
'
additionalProperties
'
:
False
}
},
'
required
'
:
[
'
name
'
,
'
interface address
'
,
'
interface name
'
,
'
router
'
],
'
additionalProperties
'
:
False
'
type
'
:
'
array
'
,
'
items
'
:
{
"
$ref
"
:
"
#/definitions/interface
"
},
}
db
=
backend_db
()
# also forces initialization
def
_x
(
k
):
return
k
.
startswith
(
'
subnets:
'
)
for
k
in
list
(
filter
(
_x
,
db
.
keys
())):
del
db
[
k
]
worker
.
_build_subnet_db
()
found_record
=
False
for
key
,
value
in
db
.
items
():
if
not
key
.
startswith
(
'
reverse_interface_addresses:
'
):
if
not
_x
(
key
):
continue
found_record
=
True
m
=
re
.
match
(
'
^
reverse_interface_addresse
s:(.+)
'
,
key
)
m
=
re
.
match
(
'
^
subnet
s:(.+)
'
,
key
)
assert
m
address
=
m
.
group
(
1
)
value
=
json
.
loads
(
value
)
jsonschema
.
validate
(
value
,
address_schema
)
assert
value
[
'
name
'
]
==
address
for
ifc
in
value
:
assert
ifc
[
'
interface address
'
]
==
address
assert
found_record
def
test_build_juniper_peering_db
(
mocked_worker_module
):
"""
Verify that valid juniper peering db objects are created.
:param mocked_worker_module: fixture
"""
peering_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
definitions
"
:
{
"
instance-peering
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
instance
"
:
{
"
type
"
:
"
string
"
},
"
group
"
:
{
"
type
"
:
"
string
"
},
"
description
"
:
{
"
type
"
:
"
string
"
},
"
address
"
:
{
"
type
"
:
"
string
"
},
"
remote-asn
"
:
{
"
type
"
:
"
integer
"
},
"
local-asn
"
:
{
"
type
"
:
"
integer
"
},
"
hostname
"
:
{
"
type
"
:
"
string
"
}
},
# description and-or local-asn is not always present,
# just based on empirical tests - not a problem
"
required
"
:
[
"
instance
"
,
"
group
"
,
"
address
"
,
"
remote-asn
"
,
"
hostname
"
],
"
additionalProperties
"
:
False
},
"
logical-system-peering
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
logical-system
"
:
{
"
type
"
:
"
string
"
},
"
group
"
:
{
"
type
"
:
"
string
"
},
"
description
"
:
{
"
type
"
:
"
string
"
},
"
address
"
:
{
"
type
"
:
"
string
"
},
"
remote-asn
"
:
{
"
type
"
:
"
integer
"
},
"
local-asn
"
:
{
"
type
"
:
"
integer
"
},
"
hostname
"
:
{
"
type
"
:
"
string
"
}
},
# local/remote-asn and/or description are not always present,
# just based on empirical tests - not a problem
"
required
"
:
[
"
logical-system
"
,
"
group
"
,
"
address
"
,
"
hostname
"
],
"
additionalProperties
"
:
False
},
"
peering
"
:
{
"
oneOf
"
:
[
{
"
$ref
"
:
"
#/definitions/instance-peering
"
},
{
"
$ref
"
:
"
#/definitions/logical-system-peering
"
}
]
}
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/peering
"
}
}
db
=
backend_db
()
# also forces initialization
def
_x
(
k
):
if
not
k
.
startswith
(
'
juniper-peerings
'
):
return
False
if
k
.
startswith
(
'
juniper-peerings:hosts:
'
):
return
False
return
True
for
k
in
list
(
filter
(
_x
,
db
.
keys
())):
del
db
[
k
]
worker
.
_build_juniper_peering_db
()
found_record
=
False
for
key
,
value
in
db
.
items
():
if
not
_x
(
key
):
continue
value
=
json
.
loads
(
value
)
assert
value
found_record
=
True
if
key
.
startswith
(
'
juniper-peerings:ix-groups:
'
):
for
address
in
value
:
canonical
=
ipaddress
.
ip_interface
(
address
).
ip
.
exploded
assert
address
==
canonical
continue
jsonschema
.
validate
(
value
,
peering_list_schema
)
assert
found_record
def
test_build_snmp_peering_db
(
mocked_worker_module
):
"""
Verify that valid snmp peering db objects are .
:param mocked_worker_module: fixture
"""
peering_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
definitions
"
:
{
"
peering
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
local
"
:
{
"
type
"
:
"
string
"
},
"
remote
"
:
{
"
type
"
:
"
string
"
},
"
oid
"
:
{
"
type
"
:
"
string
"
},
"
community
"
:
{
"
type
"
:
"
string
"
},
"
hostname
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
local
"
,
"
remote
"
,
"
oid
"
,
"
community
"
,
"
hostname
"
],
"
additionalProperties
"
:
False
}
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/peering
"
}
}
db
=
backend_db
()
# also forces initialization
def
_x
(
k
):
if
not
k
.
startswith
(
'
snmp-peerings
'
):
return
False
if
k
.
startswith
(
'
snmp-peerings:hosts:
'
):
return
False
return
True
for
k
in
list
(
filter
(
_x
,
db
.
keys
())):
del
db
[
k
]
worker
.
_build_snmp_peering_db
()
found_record
=
False
for
key
,
value
in
db
.
items
():
if
not
_x
(
key
):
continue
value
=
json
.
loads
(
value
)
jsonschema
.
validate
(
value
,
peering_list_schema
)
assert
value
found_record
=
True
assert
found_record
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