Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
3cbe5e3e
Commit
3cbe5e3e
authored
Feb 01, 2019
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise: make tests work
parent
6148ceca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
34 deletions
+65
-34
slapos/promise/plugin/check_error_on_apache_log.py
slapos/promise/plugin/check_error_on_apache_log.py
+3
-3
slapos/test/promise/plugin/test_check_error_on_apache_log.py
slapos/test/promise/plugin/test_check_error_on_apache_log.py
+29
-8
slapos/test/promise/plugin/test_check_icmp_packet_lost.py
slapos/test/promise/plugin/test_check_icmp_packet_lost.py
+15
-12
slapos/test/promise/plugin/test_check_re6st_optimal_status.py
...os/test/promise/plugin/test_check_re6st_optimal_status.py
+18
-11
No files found.
slapos/promise/plugin/check_error_on_apache_log.py
View file @
3cbe5e3e
...
...
@@ -20,7 +20,7 @@ class RunPromise(GenericPromise):
Check if frontend URL is available
"""
log_file
=
self
.
getConfig
(
'log-file'
)
maximum_delay
=
int
(
self
.
getConfig
(
'maximum-delay'
))
maximum_delay
=
int
(
self
.
getConfig
(
'maximum-delay'
,
0
))
if
not
log_file
:
raise
ValueError
(
"log file was not set in promise parameters."
)
...
...
@@ -76,8 +76,8 @@ class RunPromise(GenericPromise):
if
error_amount
:
self
.
logger
.
error
(
"ERROR=%s (NOTROUTE=%s, UNREACHEABLENET=%s, TIMEOUT=%s)"
%
(
error_amount
,
no_route_error
,
network_is_unreacheable
,
timeout
))
self
.
logger
.
info
(
"OK"
)
else
:
self
.
logger
.
info
(
"OK"
)
def
anomaly
(
self
):
# only check the result of the two latest sense call
...
...
slapos/test/promise/plugin/test_check_error_on_apache_log.py
View file @
3cbe5e3e
...
...
@@ -27,7 +27,9 @@
from
slapos.test.promise.plugin
import
TestPromisePluginMixin
import
os
import
time
from
slapos.test.promise
import
data
from
slapos.grid.promise
import
PromiseError
class
TestCheckErrorOnApacheLog
(
TestPromisePluginMixin
):
...
...
@@ -63,6 +65,7 @@ class TestCheckErrorOnApacheLog(TestPromisePluginMixin):
self
.
_update_logs
()
self
.
promise_name
=
"check-error-on-apache-log.py"
self
.
promise_pyc
=
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
+
"c"
)
self
.
base_content
=
"""from slapos.promise.plugin.check_error_on_apache_log import RunPromise
...
...
@@ -95,6 +98,9 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
# remove previous pyc, so modified promise file will be used
if
os
.
path
.
exists
(
self
.
promise_pyc
):
os
.
unlink
(
self
.
promise_pyc
)
# Ignore periodicity of the promise
self
.
configureLauncher
(
force
=
True
)
self
.
launcher
.
run
()
...
...
@@ -111,7 +117,8 @@ extra_config_dict = {
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=2 (NOTROUTE=2, UNREACHEABLENET=0, TIMEOUT=0)"
)
...
...
@@ -122,12 +129,16 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
# remove previous pyc, so modified promise file will be used
if
os
.
path
.
exists
(
self
.
promise_pyc
):
os
.
unlink
(
self
.
promise_pyc
)
# Ignore periodicity of the promise
self
.
configureLauncher
(
force
=
True
)
self
.
launcher
.
run
()
self
.
configureLauncher
(
force
=
True
,
debug
=
True
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=1 (NOTROUTE=1, UNREACHEABLENET=0, TIMEOUT=0"
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=1 (NOTROUTE=1, UNREACHEABLENET=0, TIMEOUT=0
)
"
)
def
test_error_timeout
(
self
):
self
.
base_path
=
"/"
.
join
(
data
.
__file__
.
split
(
"/"
)[:
-
1
])
...
...
@@ -138,7 +149,8 @@ extra_config_dict = {
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=4 (NOTROUTE=0, UNREACHEABLENET=0, TIMEOUT=4)"
)
...
...
@@ -149,9 +161,13 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
# remove previous pyc, so modified promise file will be used
if
os
.
path
.
exists
(
self
.
promise_pyc
):
os
.
unlink
(
self
.
promise_pyc
)
# Ignore periodicity of the promise
self
.
configureLauncher
(
force
=
True
)
self
.
launcher
.
run
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=2 (NOTROUTE=0, UNREACHEABLENET=0, TIMEOUT=2)"
)
...
...
@@ -165,7 +181,8 @@ extra_config_dict = {
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=11 (NOTROUTE=0, UNREACHEABLENET=11, TIMEOUT=0)"
)
...
...
@@ -176,9 +193,13 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
# remove previous pyc, so modified promise file will be used
if
os
.
path
.
exists
(
self
.
promise_pyc
):
os
.
unlink
(
self
.
promise_pyc
)
# Ignore periodicity of the promise
self
.
configureLauncher
(
force
=
True
)
self
.
launcher
.
run
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR=11 (NOTROUTE=0, UNREACHEABLENET=11, TIMEOUT=0)"
)
...
...
slapos/test/promise/plugin/test_check_icmp_packet_lost.py
View file @
3cbe5e3e
...
...
@@ -26,6 +26,7 @@
##############################################################################
from
slapos.test.promise.plugin
import
TestPromisePluginMixin
from
slapos.grid.promise
import
PromiseError
import
os
import
os.path
import
socket
...
...
@@ -59,11 +60,11 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"0"
)
self
.
assert
True
(
'packet_lost_ratio=0'
in
result
[
'result'
][
'message'
]
)
def
test_error
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -73,11 +74,12 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"-1"
)
self
.
assert
True
(
'packet_lost_ratio=-1'
in
result
[
'result'
][
'message'
]
)
def
test_localhost6_with_ping6
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -87,11 +89,11 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"0"
)
self
.
assert
True
(
'packet_lost_ratio=0'
in
result
[
'result'
][
'message'
]
)
def
test_localhost6_with_ping4
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -101,11 +103,11 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"0"
)
self
.
assert
True
(
'packet_lost_ratio=0'
in
result
[
'result'
][
'message'
]
)
def
test_error6
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -115,11 +117,12 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"-1"
)
self
.
assert
True
(
'packet_lost_ratio=-1'
in
result
[
'result'
][
'message'
]
)
if
__name__
==
'__main__'
:
unittest
.
main
()
slapos/test/promise/plugin/test_check_re6st_optimal_status.py
View file @
3cbe5e3e
...
...
@@ -26,6 +26,7 @@
##############################################################################
from
slapos.test.promise.plugin
import
TestPromisePluginMixin
from
slapos.grid.promise
import
PromiseError
import
os
class
TestCheckRe6stOptimalStatus
(
TestPromisePluginMixin
):
...
...
@@ -34,7 +35,7 @@ class TestCheckRe6stOptimalStatus(TestPromisePluginMixin):
TestPromisePluginMixin
.
setUp
(
self
)
self
.
promise_name
=
"check-icmp-packet-lost.py"
self
.
base_content
=
"""from slapos.promise.plugin.check_
icmp_packet_lost
import RunPromise
self
.
base_content
=
"""from slapos.promise.plugin.check_
re6st_optimal_status
import RunPromise
extra_config_dict = {
'ipv4': '%(ipv4)s',
...
...
@@ -54,11 +55,12 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
last_message
=
result
[
'result'
][
'message'
].
split
(
'
\
n
'
)[
-
1
]
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
]
,
"OK"
)
self
.
assertEqual
(
last_message
,
"OK"
)
def
test_ipv4_is_faster
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -68,11 +70,13 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
last_message
=
result
[
'result'
][
'message'
].
split
(
'
\
n
'
)[
-
1
]
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"FAIL"
)
self
.
assert
True
(
last_message
.
startswith
(
'FAIL'
)
)
def
test_ipv4_unreacheable_and_ipv6_ok
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -82,11 +86,12 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
last_message
=
result
[
'result'
][
'message'
].
split
(
'
\
n
'
)[
-
1
]
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
]
,
"OK"
)
self
.
assertEqual
(
last_message
,
"OK"
)
def
test_ipv6_fail
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -96,11 +101,13 @@ extra_config_dict = {
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
last_message
=
result
[
'result'
][
'message'
].
split
(
'
\
n
'
)[
-
1
]
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
]
,
"FAILED"
)
self
.
assertEqual
(
last_message
,
"FAILED"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment