Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mapping 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
Next Generation Map
Mapping Provider
Commits
965bb503
Commit
965bb503
authored
1 month ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added a unit test for the brian query response processing
parent
af131e6a
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mapping_provider/backends/brian.py
+44
-3
44 additions, 3 deletions
mapping_provider/backends/brian.py
test/data/brian-scid-rates.json
+33207
-0
33207 additions, 0 deletions
test/data/brian-scid-rates.json
test/test_utilization.py
+35
-0
35 additions, 0 deletions
test/test_utilization.py
with
33286 additions
and
3 deletions
mapping_provider/backends/brian.py
+
44
−
3
View file @
965bb503
...
...
@@ -19,6 +19,44 @@ logger = logging.getLogger(__name__)
BRIAN_SCID_RATES_FILENAME
=
'
brian-scid-rates.json
'
CACHED_SCID_RATES_SCHEMA
=
{
"
$schema
"
:
"
https://json-schema.org/draft/2020-12/schema
"
,
"
definitions
"
:
{
"
in-out-rates
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
ingress
"
:
{
"
type
"
:
[
"
number
"
,
"
null
"
]},
"
egress
"
:
{
"
type
"
:
[
"
number
"
,
"
null
"
]},
},
"
required
"
:
[
"
ingress
"
,
"
egress
"
],
"
additionalProperties
"
:
False
,
},
"
rate-stats
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
latest
"
:
{
"
$ref
"
:
"
#/definitions/in-out-rates
"
},
"
mean
"
:
{
"
$ref
"
:
"
#/definitions/in-out-rates
"
},
"
max
"
:
{
"
$ref
"
:
"
#/definitions/in-out-rates
"
},
},
"
required
"
:
[
"
latest
"
,
"
mean
"
,
"
max
"
],
"
additionalProperties
"
:
False
,
},
"
service-rate
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
scid
"
:
{
"
type
"
:
"
string
"
},
"
values
"
:
{
"
$ref
"
:
"
#/definitions/rate-stats
"
},
},
"
required
"
:
[
"
scid
"
,
"
values
"
],
"
additionalProperties
"
:
False
,
},
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/service-rate
"
},
}
@contextlib.contextmanager
def
influx_client
(
influx_params
:
config
.
InfluxConnectionParams
):
...
...
@@ -90,7 +128,7 @@ def _load_scid_rates_rows(influx_params: config.InfluxConnectionParams, window:
def
load_scid_rates
(
influx_params
:
config
.
InfluxConnectionParams
):
rates
=
{}
rates
=
[]
for
r
in
_load_scid_rates_rows
(
influx_params
):
def
_bitrate_or_none
(
field_name
:
str
)
->
float
|
None
:
...
...
@@ -112,10 +150,13 @@ def load_scid_rates(influx_params: config.InfluxConnectionParams):
'
egress
'
:
_bitrate_or_none
(
'
max_egress
'
)
},
}
rates
[
r
[
'
scid
'
]]
=
values
rates
.
append
({
'
scid
'
:
r
[
'
scid
'
],
'
values
'
:
values
})
cache
.
set
(
BRIAN_SCID_RATES_FILENAME
,
rates
)
return
rates
return
rates
# <-- caller can also retrieve this from the cache
def
worker_proc
(
...
...
This diff is collapsed.
Click to expand it.
test/data/brian-scid-rates.json
0 → 100644
+
33207
−
0
View file @
965bb503
This diff is collapsed.
Click to expand it.
test/test_utilization.py
0 → 100644
+
35
−
0
View file @
965bb503
import
tempfile
from
unittest.mock
import
patch
,
MagicMock
import
jsonschema
from
.common
import
load_test_data
from
mapping_provider.backends
import
brian
,
cache
from
mapping_provider.config
import
InfluxConnectionParams
def
test_utilization
():
with
tempfile
.
TemporaryDirectory
()
as
tmpdir
:
cache
.
init
(
tmpdir
)
with
patch
(
'
mapping_provider.backends.brian.InfluxDBClient
'
)
as
mocked_influx
:
# with patch('influxdb.InfluxDBClient') as mocked_influx_client:
mocked_client_instance
=
MagicMock
()
mocked_influx
.
return_value
=
mocked_client_instance
mocked_query
=
MagicMock
()
mocked_query
.
return_value
.
raw
=
load_test_data
(
'
brian-scid-rates.json
'
)
mocked_client_instance
.
query
=
mocked_query
brian
.
load_scid_rates
(
InfluxConnectionParams
(
hostname
=
'
bogus hostname
'
,
username
=
'
bogus username
'
,
password
=
'
bogus password
'
,
database
=
'
bogus database name
'
,
measurement
=
'
bogus measurement
'
))
cached_scid_rates
=
cache
.
get
(
brian
.
BRIAN_SCID_RATES_FILENAME
)
assert
cached_scid_rates
,
"
test data is not empty
"
jsonschema
.
validate
(
cached_scid_rates
,
brian
.
CACHED_SCID_RATES_SCHEMA
)
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