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
c1799012
Commit
c1799012
authored
Nov 14, 2019
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos/test: Update tests for monitor
parent
944a959b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
28 deletions
+53
-28
slapos/test/monitor/testglobalstate.py
slapos/test/monitor/testglobalstate.py
+53
-28
No files found.
slapos/test/monitor/testglobalstate.py
View file @
c1799012
...
@@ -8,7 +8,6 @@ import json
...
@@ -8,7 +8,6 @@ import json
import
pkg_resources
import
pkg_resources
from
slapos.monitor
import
globalstate
from
slapos.monitor
import
globalstate
#from slapos.monitor.runpromise import MonitorPromiseLauncher, getArgumentParser
from
slapos.monitor.monitor
import
Monitoring
from
slapos.monitor.monitor
import
Monitoring
from
jsonschema
import
validate
from
jsonschema
import
validate
...
@@ -18,7 +17,13 @@ class MonitorGlobalTest(unittest.TestCase):
...
@@ -18,7 +17,13 @@ class MonitorGlobalTest(unittest.TestCase):
self
.
base_dir
=
tempfile
.
mkdtemp
()
self
.
base_dir
=
tempfile
.
mkdtemp
()
self
.
etc_dir
=
os
.
path
.
join
(
self
.
base_dir
,
'etc'
)
self
.
etc_dir
=
os
.
path
.
join
(
self
.
base_dir
,
'etc'
)
self
.
output_dir
=
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/result'
)
self
.
output_dir
=
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/result'
)
self
.
output_history_dir
=
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/history'
)
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/history'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/result'
))
os
.
mkdir
(
self
.
etc_dir
)
os
.
mkdir
(
self
.
etc_dir
)
os
.
mkdir
(
os
.
path
.
join
(
self
.
etc_dir
,
'plugin'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
etc_dir
,
'plugin'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
etc_dir
,
'promise'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
etc_dir
,
'promise'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'public'
))
os
.
mkdir
(
os
.
path
.
join
(
self
.
base_dir
,
'public'
))
...
@@ -100,7 +105,7 @@ output-folder = %(base_dir)s/public
...
@@ -100,7 +105,7 @@ output-folder = %(base_dir)s/public
legacy-promise-folder = %(etc_dir)s/promise
legacy-promise-folder = %(etc_dir)s/promise
promise-folder = %(etc_dir)s/plugin
promise-folder = %(etc_dir)s/plugin
partition-folder = %(base_dir)s
partition-folder = %(base_dir)s
computer-id = COMP-1
234
computer-id = COMP-1
partition-cert =
partition-cert =
partition-key =
partition-key =
partition-id = slappart0
partition-id = slappart0
...
@@ -120,28 +125,51 @@ ipv4 = 10.0.151.118
...
@@ -120,28 +125,51 @@ ipv4 = 10.0.151.118
cfg
.
write
(
config
)
cfg
.
write
(
config
)
def
writePromise
(
self
,
name
,
success
=
True
):
def
writePromise
(
self
,
name
,
success
=
True
):
if
success
:
promise_status
=
{
result_dict
=
{
'output'
:
'success'
,
'code'
:
0
}
"result"
:
{
else
:
"date"
:
"2019-11-14T16:23:22+0000"
,
result_dict
=
{
'output'
:
'error'
,
'code'
:
1
}
"failed"
:
not
success
,
content
=
"""#!/bin/sh
"message"
:
"OK"
if
success
else
"ERROR"
,
"type"
:
"Test Result"
},
"path"
:
"%s.py"
%
os
.
path
.
join
(
self
.
etc_dir
,
'promise'
,
name
),
"name"
:
"%s.py"
%
name
,
"execution-time"
:
0.1
,
"title"
:
name
}
with
open
(
os
.
path
.
join
(
self
.
output_dir
,
"%s.status.json"
%
name
),
"w"
)
as
p
:
json
.
dump
(
promise_status
,
p
)
def
writeGlobalJson
(
self
,
success
=
0
,
error
=
0
):
global_json
=
{
"status"
:
"ERROR"
if
error
else
"OK"
,
"title"
:
"Instance Monitoring"
,
"data"
:
{
"process_state"
:
"monitor_process_resource.status"
,
"io_resource"
:
"monitor_resource_io.data"
,
"state"
:
"monitor_state.data"
,
"memory_resource"
:
"monitor_resource_memory.data"
,
"process_resource"
:
"monitor_resource_process.data"
,
"monitor_process_state"
:
"monitor_resource.status"
},
"portal_type"
:
"Software Instance"
,
"partition_id"
:
"slappart0"
,
"aggregate_reference"
:
"COMP-1"
,
"state"
:
{
"success"
:
success
,
"error"
:
error
},
"_links"
:
{},
"date"
:
"2019-11-14T16:50:19+0000"
,
"type"
:
"global"
}
echo "%(output)s"
with
open
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/global.json'
),
"w"
)
as
p
:
exit %(code)s
json
.
dump
(
global_json
,
p
)
"""
%
result_dict
promise_path
=
os
.
path
.
join
(
self
.
etc_dir
,
'promise'
,
name
)
self
.
writeContent
(
promise_path
,
content
)
os
.
chmod
(
promise_path
,
0o755
)
return
promise_path
def
getPromiseParser
(
self
):
public_json
=
{
pid_path
=
os
.
path
.
join
(
self
.
base_dir
,
'run'
,
'monitor-promise.pid'
)
"date"
:
"2019-11-14T17:04:05+0000"
,
"status"
:
"ERROR"
if
error
else
"OK"
,
"_links"
:
{}
}
promise_cmd
=
[
with
open
(
os
.
path
.
join
(
self
.
base_dir
,
'.slapgrid/promise/public.json'
),
"w"
)
as
p
:
'--pid-path'
,
json
.
dump
(
public_json
,
p
)
'%s'
%
pid_path
,
'-c'
,
self
.
monitor_config_file
]
arg_parser
=
getArgumentParser
()
return
arg_parser
.
parse_args
(
promise_cmd
)
def
test_monitor_instance_state
(
self
):
def
test_monitor_instance_state
(
self
):
self
.
maxDiff
=
None
self
.
maxDiff
=
None
...
@@ -155,9 +183,7 @@ exit %(code)s
...
@@ -155,9 +183,7 @@ exit %(code)s
self
.
writePromise
(
'promise_2'
,
success
=
False
)
self
.
writePromise
(
'promise_2'
,
success
=
False
)
self
.
writePromise
(
'promise_3'
,
success
=
False
)
self
.
writePromise
(
'promise_3'
,
success
=
False
)
self
.
writePromise
(
'promise_4'
)
self
.
writePromise
(
'promise_4'
)
parser
=
self
.
getPromiseParser
()
self
.
writeGlobalJson
(
2
,
2
)
promise_runner
=
MonitorPromiseLauncher
(
parser
)
promise_runner
.
start
()
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_dir
,
'promise_1.status.json'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_dir
,
'promise_1.status.json'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_dir
,
'promise_2.status.json'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_dir
,
'promise_2.status.json'
)))
...
@@ -223,7 +249,7 @@ exit %(code)s
...
@@ -223,7 +249,7 @@ exit %(code)s
{"href": "https://sub2.monitor.test.com/share/public"}
{"href": "https://sub2.monitor.test.com/share/public"}
]
]
},
},
"aggregate_reference": "COMP-1
234
",
"aggregate_reference": "COMP-1",
"type": "global",
"type": "global",
"specialise_title": "Monitor ROOT"
"specialise_title": "Monitor ROOT"
}"""
}"""
...
@@ -237,9 +263,8 @@ exit %(code)s
...
@@ -237,9 +263,8 @@ exit %(code)s
# all promises are OK now
# all promises are OK now
self
.
writePromise
(
'promise_2'
,
success
=
True
)
self
.
writePromise
(
'promise_2'
,
success
=
True
)
self
.
writePromise
(
'promise_3'
,
success
=
True
)
self
.
writePromise
(
'promise_3'
,
success
=
True
)
# rerun right now
self
.
writeGlobalJson
(
4
,
0
)
promise_runner
.
config
.
force
=
True
promise_runner
.
start
()
globalstate
.
run
(
self
.
monitor_config_file
)
globalstate
.
run
(
self
.
monitor_config_file
)
expected_result_dict
=
json
.
loads
(
expected_result
)
expected_result_dict
=
json
.
loads
(
expected_result
)
...
...
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