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
5b0c239e
Commit
5b0c239e
authored
5 years ago
by
Nikolay Stanchev
Browse files
Options
Downloads
Patches
Plain Diff
Refactors alerts integration test
parent
619c4793
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/clmctest/alerts/test_alerts.py
+28
-20
28 additions, 20 deletions
src/test/clmctest/alerts/test_alerts.py
with
28 additions
and
20 deletions
src/test/clmctest/alerts/test_alerts.py
+
28
−
20
View file @
5b0c239e
...
...
@@ -246,17 +246,12 @@ class TestAlerts(object):
# find the latest timestamp of the registered alerts
max_post_timestamp
=
0
tasks
=
get
(
"
http://{0}/kapacitor/v1/tasks
"
.
format
(
clmc_service_host
)).
json
()[
"
tasks
"
]
for
task
in
tasks
:
# get the configured variables of this alert
task_config
=
task
[
"
vars
"
]
# if configured for this SFC instance
if
task_config
[
"
sfc
"
][
"
value
"
]
==
sfc
and
task_config
[
"
sfci
"
][
"
value
"
]
==
sfc_instance
:
created_datestr
=
task
[
"
created
"
][:
26
]
# ignore the timezone and only take the first 6 digits of the microseconds
task_created_timestamp
=
datetime
.
datetime
.
strptime
(
created_datestr
,
"
%Y-%m-%dT%H:%M:%S.%f
"
)
max_post_timestamp
=
max
(
max_post_timestamp
,
task_created_timestamp
.
timestamp
())
print
(
"
Sleeping 2 seconds to ensure a difference between the timestamps when creating the alerts and when updating them...
"
)
sleep
(
2
)
for
timestamp
in
tasks_timestamps
(
tasks
,
sfc
,
sfc_instance
):
max_post_timestamp
=
max
(
max_post_timestamp
,
timestamp
)
delay
=
2
# seconds
print
(
"
Sleeping {0} seconds to ensure a difference between the timestamps when creating the alerts and when updating them...
"
.
format
(
delay
))
sleep
(
delay
)
# update the alerts with a PUT request and check that the "created" metadata is updated implying that the alerts were recreated
print
(
"
Sending alerts specification to clmc service for updating...
"
)
...
...
@@ -275,19 +270,32 @@ class TestAlerts(object):
# find the earliest timestamp of the updated alerts
min_put_timestamp
=
float
(
"
inf
"
)
tasks
=
get
(
"
http://{0}/kapacitor/v1/tasks
"
.
format
(
clmc_service_host
)).
json
()[
"
tasks
"
]
for
task
in
tasks
:
# get the configured variables of this alert
task_config
=
task
[
"
vars
"
]
# if configured for this SFC instance
if
task_config
[
"
sfc
"
][
"
value
"
]
==
sfc
and
task_config
[
"
sfci
"
][
"
value
"
]
==
sfc_instance
:
created_datestr
=
task
[
"
created
"
][:
26
]
# ignore the timezone and only take the first 6 digits of the microseconds
task_created_timestamp
=
datetime
.
datetime
.
strptime
(
created_datestr
,
"
%Y-%m-%dT%H:%M:%S.%f
"
)
min_put_timestamp
=
min
(
min_put_timestamp
,
task_created_timestamp
.
timestamp
())
for
timestamp
in
tasks_timestamps
(
tasks
,
sfc
,
sfc_instance
):
min_put_timestamp
=
min
(
min_put_timestamp
,
timestamp
)
print
(
"
Latest timestamp during the POST request
"
,
max_post_timestamp
,
"
Earliest timestamp during the PUT request
"
,
min_put_timestamp
)
assert
m
ax_pos
t_timestamp
<
m
in_pu
t_timestamp
,
"
There is an alert that wasn
'
t updated properly with a PUT request
"
assert
m
in_pu
t_timestamp
-
m
ax_pos
t_timestamp
>=
delay
,
"
There is an alert that wasn
'
t updated properly with a PUT request
"
# delete the alerts with a DELETE request
with
open
(
alerts_spec
,
'
rb
'
)
as
alerts
:
files
=
{
'
alert-spec
'
:
alerts
}
delete
(
"
http://{0}/clmc-service/alerts
"
.
format
(
clmc_service_host
),
files
=
files
)
def
tasks_timestamps
(
all_tasks
,
sfc_id
,
sfc_instance_id
):
"""
Generates the timestamps for the tasks related to the given SFC and SFC instance.
:param all_tasks: the full list of tasks from kapacitor
:param sfc_id: SFC identifier
:param sfc_instance_id: SFC instance identifier
"""
for
task
in
all_tasks
:
# get the configured variables of this alert
task_config
=
task
[
"
vars
"
]
# if configured for this SFC instance
if
task_config
[
"
sfc
"
][
"
value
"
]
==
sfc_id
and
task_config
[
"
sfci
"
][
"
value
"
]
==
sfc_instance_id
:
created_datestr
=
task
[
"
created
"
][:
26
]
# ignore the timezone and only take the first 6 digits of the microseconds
task_created_timestamp
=
datetime
.
datetime
.
strptime
(
created_datestr
,
"
%Y-%m-%dT%H:%M:%S.%f
"
)
yield
task_created_timestamp
.
timestamp
()
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