Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
flame
flame-clmc
Commits
18266783
Commit
18266783
authored
6 years ago
by
MJB
Browse files
Options
Downloads
Patches
Plain Diff
started to work on mock router API
parent
96cdd35d
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
src/service/clmcservice/test_sr_mock_view.py
+49
-0
49 additions, 0 deletions
src/service/clmcservice/test_sr_mock_view.py
src/service/clmcservice/views.py
+38
-0
38 additions, 0 deletions
src/service/clmcservice/views.py
with
87 additions
and
0 deletions
src/service/clmcservice/test_sr_mock_view.py
0 → 100644
+
49
−
0
View file @
18266783
import
pytest
from
pyramid
import
testing
from
pyramid.httpexceptions
import
HTTPBadRequest
from
time
import
sleep
from
clmcservice.utilities
import
CONFIG_ATTRIBUTES
,
PROCESS_ATTRIBUTE
,
RUNNING_FLAG
,
MALFORMED_FLAG
,
URL_REGEX
import
os
import
signal
class
TestSRMockAPI
(
object
):
@pytest.fixture
(
autouse
=
True
)
def
app_config
(
self
):
print
(
"
app_config
"
)
self
.
config
=
testing
.
setUp
()
# endpoint
# sr
# sfc_i
# sf_i
self
.
config
.
add_settings
({
'
my_endpoint_1
'
:
{
'
sfc_i
'
:
'
my_sfc_i_1
'
,
'
sf_i
'
:
'
my_sf_i_1
'
,
'
sr
'
:
'
my_sr_1
'
},
'
my_endpoint_2
'
:
{
'
sfc_i
'
:
'
my_sfc_i_2
'
,
'
sf_i
'
:
'
my_sf_i_2
'
,
'
sr
'
:
'
my_sr_2
'
}})
yield
testing
.
tearDown
()
def
test_GET_config
(
self
):
print
(
"
Test get
"
)
# nested import so that importing the class view is part of the test itself
from
clmcservice.views
import
SRMockConfig
request
=
testing
.
DummyRequest
()
response
=
SRMockConfig
(
request
).
get
()
print
(
"
response={0}
"
.
format
(
response
))
@pytest.mark.parametrize
(
"
input_body, output_value
"
,
[
(
'
{
"
aggregator_report_period
"
: 10,
"
aggregator_database_name
"
:
"
CLMCMetrics
"
,
"
aggregator_database_url
"
:
"
http://171.40.231.51:8086
"
}
'
,
{
'
aggregator_report_period
'
:
10
,
'
aggregator_database_name
'
:
"
CLMCMetrics
"
,
'
aggregator_database_url
'
:
"
http://171.40.231.51:8086
"
}),
])
def
test_PUT_config
(
self
,
input_body
,
output_value
):
print
(
"
Test put
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/service/clmcservice/views.py
+
38
−
0
View file @
18266783
...
...
@@ -306,3 +306,41 @@ class RoundTripTimeQuery(object):
reverse_data_delay
=
(
8
/
10
**
6
)
*
(
response_size
/
bandwidth
)
*
(
packet_size
/
(
packet_size
-
packet_header_size
))
return
forward_latency
+
forward_data_delay
+
service_delay
+
reverse_latency
+
reverse_data_delay
@view_defaults
(
route_name
=
'
sr_config
'
,
renderer
=
'
json
'
)
class
SRMockConfig
(
object
):
"""
A class-based view for accessing and mutating the configuration of the aggregator.
"""
def
__init__
(
self
,
request
):
"""
Initialises the instance of the view with the request argument.
:param request: client
'
s call request
"""
self
.
request
=
request
def
get
(
self
):
"""
A GET API call for endpoint configuration.
:return: A JSON response with the configuration of the aggregator.
"""
log
.
debug
(
"
\Getting endpoint configuration
\n
"
)
config
=
{
"
key
"
:
"
hello
"
}
return
config
def
put
(
self
):
"""
A PUT API call for the status of the aggregator.
:return: A JSON response to the PUT call - essentially with the new configured data and comment of the state of the aggregator
:raises HTTPBadRequest: if request body is not a valid JSON for the configurator
"""
log
.
debug
(
"
\Putting endpoint configuration
\n
"
)
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