Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
19
Merge Requests
19
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
9de598f2
Commit
9de598f2
authored
Oct 30, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
d1e941b3
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
203 additions
and
205 deletions
+203
-205
slapos/cli/configure_local/__init__.py
slapos/cli/configure_local/__init__.py
+4
-4
slapos/client.py
slapos/client.py
+2
-2
slapos/collect/entity.py
slapos/collect/entity.py
+6
-10
slapos/collect/reporter.py
slapos/collect/reporter.py
+4
-2
slapos/collect/snapshot.py
slapos/collect/snapshot.py
+3
-1
slapos/collect/temperature/__init__.py
slapos/collect/temperature/__init__.py
+2
-1
slapos/grid/promise/generic.py
slapos/grid/promise/generic.py
+2
-2
slapos/manager/portredir.py
slapos/manager/portredir.py
+2
-3
slapos/proxy/db_version.py
slapos/proxy/db_version.py
+1
-1
slapos/proxy/views.py
slapos/proxy/views.py
+2
-2
slapos/slap/slap.py
slapos/slap/slap.py
+3
-3
slapos/tests/collect.py
slapos/tests/collect.py
+24
-24
slapos/tests/promise.py
slapos/tests/promise.py
+148
-148
slapos/util.py
slapos/util.py
+0
-2
No files found.
slapos/cli/configure_local/__init__.py
View file @
9de598f2
...
@@ -149,8 +149,8 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
...
@@ -149,8 +149,8 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
slapos_node_configuration_content = re.sub(
slapos_node_configuration_content = re.sub(
'
(
key_file
|
cert_file
|
certificate_repository_path
).
*=
.
*
\
n
',
'
(
key_file
|
cert_file
|
certificate_repository_path
).
*=
.
*
\
n
',
'', slapos_node_configuration_content)
'', slapos_node_configuration_content)
with open(slapos_node_config_path, '
w
b
') as fout:
with open(slapos_node_config_path, '
w
') as fout:
fout.write(slapos_node_configuration_content
.encode('
utf8
')
)
fout.write(slapos_node_configuration_content)
def _generateSlaposProxyConfigurationFile(conf):
def _generateSlaposProxyConfigurationFile(conf):
template_arg_list = (__name__, '
..
/
..
/
slapos
-
proxy
.
cfg
.
example
')
template_arg_list = (__name__, '
..
/
..
/
slapos
-
proxy
.
cfg
.
example
')
...
@@ -172,8 +172,8 @@ def _generateSlaposProxyConfigurationFile(conf):
...
@@ -172,8 +172,8 @@ def _generateSlaposProxyConfigurationFile(conf):
slapos_proxy_configuration_content = _replaceParameterValue(
slapos_proxy_configuration_content = _replaceParameterValue(
slapos_proxy_configuration_template, to_replace)
slapos_proxy_configuration_template, to_replace)
with open(slapos_proxy_configuration_path, '
w
b
') as fout:
with open(slapos_proxy_configuration_path, '
w
') as fout:
fout.write(slapos_proxy_configuration_content
.encode('
utf8
')
)
fout.write(slapos_proxy_configuration_content)
return slapos_proxy_configuration_path
return slapos_proxy_configuration_path
...
...
slapos/client.py
View file @
9de598f2
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
##############################################################################
##############################################################################
import
atexit
import
atexit
import
six.moves.
configparser
from
six.moves
import
configparser
import
os
import
os
import
sys
import
sys
...
@@ -52,7 +52,7 @@ class ClientConfig(object):
...
@@ -52,7 +52,7 @@ class ClientConfig(object):
# Merges the arguments and configuration
# Merges the arguments and configuration
try
:
try
:
configuration_dict
=
dict
(
configp
.
items
(
'slapconsole'
))
configuration_dict
=
dict
(
configp
.
items
(
'slapconsole'
))
except
ConfigP
arser
.
NoSectionError
:
except
configp
arser
.
NoSectionError
:
pass
pass
else
:
else
:
for
key
in
configuration_dict
:
for
key
in
configuration_dict
:
...
...
slapos/collect/entity.py
View file @
9de598f2
...
@@ -74,19 +74,15 @@ class User(object):
...
@@ -74,19 +74,15 @@ class User(object):
time_cycle
=
self
.
disk_snapshot_params
.
get
(
'time_cycle'
,
0
)
time_cycle
=
self
.
disk_snapshot_params
.
get
(
'time_cycle'
,
0
)
database
.
connect
()
database
.
connect
()
if
time_cycle
:
if
time_cycle
:
order
=
'date DESC, time DESC'
for
date_time
in
database
.
select
(
table
=
"folder"
,
columns
=
"date, time"
,
limit
=
1
order
=
'date DESC, time DESC'
,
limit
=
1
,
query
=
database
.
select
(
table
=
"folder"
,
columns
=
"date, time"
,
where
=
"partition='%s'"
%
self
.
name
):
order
=
order
,
limit
=
limit
,
latest_date
=
datetime
.
strptime
(
'%s %s'
%
date_time
,
where
=
"partition='%s'"
%
self
.
name
)
query_result
=
zip
(
*
query
)
if
len
(
query_result
):
date
,
time
=
(
query_result
[
0
][
0
],
query_result
[
1
][
0
])
latest_date
=
datetime
.
strptime
(
'%s %s'
%
(
date
,
time
),
"%Y-%m-%d %H:%M:%S"
)
"%Y-%m-%d %H:%M:%S"
)
if
(
datetime
.
now
()
-
latest_date
).
seconds
<
time_cycle
:
if
(
datetime
.
now
()
-
latest_date
).
seconds
<
time_cycle
:
# wait the time cycle
# wait the time cycle
return
return
break
pid_file
=
self
.
disk_snapshot_params
.
get
(
'pid_folder'
,
None
)
pid_file
=
self
.
disk_snapshot_params
.
get
(
'pid_folder'
,
None
)
if
pid_file
is
not
None
:
if
pid_file
is
not
None
:
pid_file
=
os
.
path
.
join
(
pid_file
,
'%s_disk_size.pid'
%
self
.
name
)
pid_file
=
os
.
path
.
join
(
pid_file
,
'%s_disk_size.pid'
%
self
.
name
)
...
...
slapos/collect/reporter.py
View file @
9de598f2
...
@@ -40,6 +40,8 @@ import tarfile
...
@@ -40,6 +40,8 @@ import tarfile
import
time
import
time
import
psutil
import
psutil
import
six
log_file
=
False
log_file
=
False
class
Dumper
(
object
):
class
Dumper
(
object
):
...
@@ -59,10 +61,10 @@ class SystemReporter(Dumper):
...
@@ -59,10 +61,10 @@ class SystemReporter(Dumper):
""" Dump data """
""" Dump data """
_date
=
time
.
strftime
(
"%Y-%m-%d"
)
_date
=
time
.
strftime
(
"%Y-%m-%d"
)
self
.
db
.
connect
()
self
.
db
.
connect
()
for
item
,
collected_item_list
in
s
elf
.
db
.
exportSystemAsDict
(
_date
).
iteritems
(
):
for
item
,
collected_item_list
in
s
ix
.
iteritems
(
self
.
db
.
exportSystemAsDict
(
_date
)
):
self
.
writeFile
(
item
,
folder
,
collected_item_list
)
self
.
writeFile
(
item
,
folder
,
collected_item_list
)
for
partition
,
collected_item_list
in
s
elf
.
db
.
exportDiskAsDict
(
_date
).
iteritems
(
):
for
partition
,
collected_item_list
in
s
ix
.
iteritems
(
self
.
db
.
exportDiskAsDict
(
_date
)
):
partition_id
=
"_"
.
join
(
partition
.
split
(
"-"
)[:
-
1
]).
replace
(
"/"
,
"_"
)
partition_id
=
"_"
.
join
(
partition
.
split
(
"-"
)[:
-
1
]).
replace
(
"/"
,
"_"
)
item
=
"memory_%s"
%
partition
.
split
(
"-"
)[
-
1
]
item
=
"memory_%s"
%
partition
.
split
(
"-"
)[
-
1
]
self
.
writeFile
(
"disk_%s_%s"
%
(
item
,
partition_id
),
folder
,
collected_item_list
)
self
.
writeFile
(
"disk_%s_%s"
%
(
item
,
partition_id
),
folder
,
collected_item_list
)
...
...
slapos/collect/snapshot.py
View file @
9de598f2
...
@@ -36,6 +36,8 @@ from .temperature import collectComputerTemperature, \
...
@@ -36,6 +36,8 @@ from .temperature import collectComputerTemperature, \
from
.temperature.heating
import
get_contribution_ratio
from
.temperature.heating
import
get_contribution_ratio
import
six
MEASURE_INTERVAL
=
5
MEASURE_INTERVAL
=
5
class
_Snapshot
(
object
):
class
_Snapshot
(
object
):
...
@@ -242,6 +244,6 @@ class ComputerSnapshot(_Snapshot):
...
@@ -242,6 +244,6 @@ class ComputerSnapshot(_Snapshot):
DiskPartitionSnapshot
(
partition
.
device
,
DiskPartitionSnapshot
(
partition
.
device
,
partition
.
mountpoint
))
partition
.
mountpoint
))
return
[(
k
,
v
)
for
k
,
v
in
partition_dict
.
iteritems
(
)]
return
[(
k
,
v
)
for
k
,
v
in
six
.
iteritems
(
partition_dict
)]
slapos/collect/temperature/__init__.py
View file @
9de598f2
...
@@ -18,7 +18,8 @@ def collectComputerTemperature(sensor_bin="sensors"):
...
@@ -18,7 +18,8 @@ def collectComputerTemperature(sensor_bin="sensors"):
cmd
=
[
"%s -u"
%
sensor_bin
]
cmd
=
[
"%s -u"
%
sensor_bin
]
sp
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
sp
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
stderr
=
subprocess
.
PIPE
,
shell
=
True
,
universal_newlines
=
True
)
stdout
,
stderr
=
sp
.
communicate
()
stdout
,
stderr
=
sp
.
communicate
()
...
...
slapos/grid/promise/generic.py
View file @
9de598f2
...
@@ -161,8 +161,8 @@ class GenericPromise(object):
...
@@ -161,8 +161,8 @@ class GenericPromise(object):
self
.
logger
.
removeHandler
(
handler
)
self
.
logger
.
removeHandler
(
handler
)
if
self
.
__log_folder
is
None
:
if
self
.
__log_folder
is
None
:
# configure logger with StringIO
# configure logger with StringIO
import
cStringIO
from
six.moves
import
cStringIO
self
.
__logger_buffer
=
cStringIO
.
StringIO
()
self
.
__logger_buffer
=
cStringIO
()
logger_handler
=
logging
.
StreamHandler
(
self
.
__logger_buffer
)
logger_handler
=
logging
.
StreamHandler
(
self
.
__logger_buffer
)
self
.
__log_file
=
None
self
.
__log_file
=
None
else
:
else
:
...
...
slapos/manager/portredir.py
View file @
9de598f2
...
@@ -6,7 +6,7 @@ import os
...
@@ -6,7 +6,7 @@ import os
from
.interface
import
IManager
from
.interface
import
IManager
from
six.moves
import
filter
from
six.moves
import
filter
from
zope
import
interface
from
zope
.interface
import
implementer
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -22,9 +22,8 @@ def which(exename):
...
@@ -22,9 +22,8 @@ def which(exename):
return
full_path
return
full_path
return
None
return
None
@
implementer
(
IManager
)
class
Manager
(
object
):
class
Manager
(
object
):
interface
.
implements
(
IManager
)
port_redirect_filename
=
'.slapos-port-redirect'
port_redirect_filename
=
'.slapos-port-redirect'
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
...
...
slapos/proxy/db_version.py
View file @
9de598f2
...
@@ -3,5 +3,5 @@
...
@@ -3,5 +3,5 @@
import
pkg_resources
import
pkg_resources
from
slapos.util
import
bytes2str
from
slapos.util
import
bytes2str
DB_VERSION
=
bytes2str
(
pkg_resources
.
resource_stream
(
'slapos.proxy'
,
'schema.sql'
).
readline
()
.
strip
().
split
(
b':'
)[
1
])
DB_VERSION
=
bytes2str
(
pkg_resources
.
resource_stream
(
'slapos.proxy'
,
'schema.sql'
).
readline
()
).
strip
().
split
(
':'
)[
1
]
slapos/proxy/views.py
View file @
9de598f2
...
@@ -298,7 +298,7 @@ def useComputer():
...
@@ -298,7 +298,7 @@ def useComputer():
@
app
.
route
(
'/loadComputerConfigurationFromXML'
,
methods
=
[
'POST'
])
@
app
.
route
(
'/loadComputerConfigurationFromXML'
,
methods
=
[
'POST'
])
def
loadComputerConfigurationFromXML
():
def
loadComputerConfigurationFromXML
():
xml
=
request
.
form
[
'xml'
]
xml
=
request
.
form
[
'xml'
]
computer_dict
=
xml_marshaller
.
xml_marshaller
.
loads
(
str
(
xml
)
.
encode
(
'utf-8'
))
computer_dict
=
xml_marshaller
.
xml_marshaller
.
loads
(
xml
.
encode
(
'utf-8'
))
execute_db
(
'computer'
,
'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)'
,
execute_db
(
'computer'
,
'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)'
,
computer_dict
)
computer_dict
)
for
partition
in
computer_dict
[
'partition_list'
]:
for
partition
in
computer_dict
[
'partition_list'
]:
...
@@ -622,7 +622,7 @@ def requestNotSlave(software_release, software_type, partition_reference, partit
...
@@ -622,7 +622,7 @@ def requestNotSlave(software_release, software_type, partition_reference, partit
execute_db
(
'partition'
,
q
,
args
)
execute_db
(
'partition'
,
q
,
args
)
args
=
[]
args
=
[]
partition
=
execute_db
(
'partition'
,
'SELECT * FROM %s WHERE reference=? and computer_reference=?'
,
partition
=
execute_db
(
'partition'
,
'SELECT * FROM %s WHERE reference=? and computer_reference=?'
,
[
partition
[
'reference'
]
.
encode
(),
partition
[
'computer_reference'
].
encode
()
],
one
=
True
)
[
partition
[
'reference'
]
,
partition
[
'computer_reference'
]
],
one
=
True
)
address_list
=
[]
address_list
=
[]
for
address
in
execute_db
(
'partition_network'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
[
partition
[
'reference'
]]):
for
address
in
execute_db
(
'partition_network'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
[
partition
[
'reference'
]]):
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
...
...
slapos/slap/slap.py
View file @
9de598f2
...
@@ -873,12 +873,12 @@ class slap:
...
@@ -873,12 +873,12 @@ class slap:
# XXX-Cedric: should raise something smarter than NotFound
# XXX-Cedric: should raise something smarter than NotFound
raise
NotFoundError
raise
NotFoundError
xml
=
bytes
(
self
.
_connection_helper
.
GET
(
'registerComputerPartition'
,
xml
=
self
.
_connection_helper
.
GET
(
'registerComputerPartition'
,
params
=
{
params
=
{
'computer_reference'
:
computer_guid
,
'computer_reference'
:
computer_guid
,
'computer_partition_reference'
:
partition_id
,
'computer_partition_reference'
:
partition_id
,
}
}
)
)
)
result
=
xml_marshaller
.
loads
(
xml
)
result
=
xml_marshaller
.
loads
(
xml
)
# XXX: dirty hack to make computer partition usable. xml_marshaller is too
# XXX: dirty hack to make computer partition usable. xml_marshaller is too
# low-level for our needs here.
# low-level for our needs here.
...
@@ -913,7 +913,7 @@ class slap:
...
@@ -913,7 +913,7 @@ class slap:
'software_release_url parameters are specified.'
)
'software_release_url parameters are specified.'
)
params
[
'software_release_url'
]
=
software_release_url
params
[
'software_release_url'
]
=
software_release_url
xml
=
bytes
(
self
.
_connection_helper
.
GET
(
url
,
params
=
params
)
)
xml
=
self
.
_connection_helper
.
GET
(
url
,
params
=
params
)
result
=
xml_marshaller
.
loads
(
xml
)
result
=
xml_marshaller
.
loads
(
xml
)
assert
(
type
(
result
)
==
list
)
assert
(
type
(
result
)
==
list
)
return
result
return
result
...
...
slapos/tests/collect.py
View file @
9de598f2
...
@@ -364,7 +364,7 @@ class TestCollectReport(unittest.TestCase):
...
@@ -364,7 +364,7 @@ class TestCollectReport(unittest.TestCase):
with
tarfile
.
open
(
"%s.tar.gz"
%
dump_folder
)
as
tf
:
with
tarfile
.
open
(
"%s.tar.gz"
%
dump_folder
)
as
tf
:
self
.
assertEquals
(
tf
.
getmembers
()[
0
].
name
,
"1990-01-01"
)
self
.
assertEquals
(
tf
.
getmembers
()[
0
].
name
,
"1990-01-01"
)
self
.
assertEquals
(
tf
.
getmembers
()[
1
].
name
,
"1990-01-01/test.txt"
)
self
.
assertEquals
(
tf
.
getmembers
()[
1
].
name
,
"1990-01-01/test.txt"
)
self
.
assertEquals
(
tf
.
extractfile
(
tf
.
getmembers
()[
1
]).
read
(),
'hi'
)
self
.
assertEquals
(
tf
.
extractfile
(
tf
.
getmembers
()[
1
]).
read
(),
b
'hi'
)
class
TestCollectSnapshot
(
unittest
.
TestCase
):
class
TestCollectSnapshot
(
unittest
.
TestCase
):
...
@@ -482,10 +482,10 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -482,10 +482,10 @@ class TestCollectEntity(unittest.TestCase):
config
.
set
(
'slapos'
,
'instance_root'
,
self
.
instance_root
)
config
.
set
(
'slapos'
,
'instance_root'
,
self
.
instance_root
)
user_dict
=
entity
.
get_user_list
(
config
)
user_dict
=
entity
.
get_user_list
(
config
)
username_
list
=
[
'slapuser0'
,
'slapuser1'
,
'slapuser2'
]
username_
set
=
{
'slapuser0'
,
'slapuser1'
,
'slapuser2'
}
self
.
assertEquals
(
username_
list
,
user_dict
.
keys
(
))
self
.
assertEquals
(
username_
set
,
set
(
user_dict
))
for
name
in
username_
lis
t
:
for
name
in
username_
se
t
:
self
.
assertEquals
(
user_dict
[
name
].
name
,
name
)
self
.
assertEquals
(
user_dict
[
name
].
name
,
name
)
self
.
assertEquals
(
user_dict
[
name
].
snapshot_list
,
[])
self
.
assertEquals
(
user_dict
[
name
].
snapshot_list
,
[])
expected_path
=
"%s/slappart%s"
%
(
self
.
instance_root
,
name
.
strip
(
"slapuser"
))
expected_path
=
"%s/slappart%s"
%
(
self
.
instance_root
,
name
.
strip
(
"slapuser"
))
...
@@ -508,11 +508,11 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -508,11 +508,11 @@ class TestCollectEntity(unittest.TestCase):
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
1
][
1
][
1
]
),
[
'cpu_time'
,
'cpu_percent'
,
'process'
,
{
'cpu_time'
,
'cpu_percent'
,
'process'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_cycles_counter'
,
'cpu_num_threads'
]
)
'io_cycles_counter'
,
'cpu_num_threads'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
...
@@ -527,19 +527,19 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -527,19 +527,19 @@ class TestCollectEntity(unittest.TestCase):
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
1
][
1
][
1
]
),
[
'cpu_time'
,
'cpu_percent'
,
'process'
,
{
'cpu_time'
,
'cpu_percent'
,
'process'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_cycles_counter'
,
'cpu_num_threads'
]
)
'io_cycles_counter'
,
'cpu_num_threads'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
4
],
(
"connect"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
4
],
(
"connect"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
0
],
"inserFolderSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
0
],
"inserFolderSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
5
][
1
][
1
]
),
[
'insertion_date'
,
'disk_usage'
,
'insertion_time'
]
)
{
'insertion_date'
,
'disk_usage'
,
'insertion_time'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
6
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
6
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
7
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
7
],
(
"close"
,
""
))
...
@@ -554,23 +554,23 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -554,23 +554,23 @@ class TestCollectEntity(unittest.TestCase):
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertUserSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
1
][
1
][
1
]
),
[
'cpu_time'
,
'cpu_percent'
,
'process'
,
{
'cpu_time'
,
'cpu_percent'
,
'process'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'memory_rss'
,
'pid'
,
'memory_percent'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_rw_counter'
,
'insertion_date'
,
'insertion_time'
,
'io_cycles_counter'
,
'cpu_num_threads'
]
)
'io_cycles_counter'
,
'cpu_num_threads'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
2
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
3
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
4
],
(
"connect"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
4
],
(
"connect"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
0
],
"select"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
0
],
"select"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
5
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
5
][
1
][
1
]
),
[
'table'
,
'where'
,
'limit'
,
'order'
,
'columns'
]
)
{
'table'
,
'where'
,
'limit'
,
'order'
,
'columns'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
6
][
0
],
"inserFolderSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
6
][
0
],
"inserFolderSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
6
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
6
][
1
][
0
],
(
"fakeuser0"
,))
self
.
assertEquals
(
database
.
invoked_method_list
[
6
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
6
][
1
][
1
]
),
[
'insertion_date'
,
'disk_usage'
,
'insertion_time'
]
)
{
'insertion_date'
,
'disk_usage'
,
'insertion_time'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
7
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
7
],
(
"commit"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
8
],
(
"close"
,
""
))
self
.
assertEquals
(
database
.
invoked_method_list
[
8
],
(
"close"
,
""
))
...
@@ -583,14 +583,14 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -583,14 +583,14 @@ class TestCollectEntity(unittest.TestCase):
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertComputerSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
0
],
"insertComputerSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
1
][
1
][
1
].
keys
(
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
1
][
1
][
1
]
),
[
'insertion_time'
,
'insertion_date'
,
'cpu_num_core'
,
{
'insertion_time'
,
'insertion_date'
,
'cpu_num_core'
,
'partition_list'
,
'cpu_frequency'
,
'memory_size'
,
'partition_list'
,
'cpu_frequency'
,
'memory_size'
,
'cpu_type'
,
'memory_type'
]
)
'cpu_type'
,
'memory_type'
}
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
][
0
],
"insertSystemSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
][
0
],
"insertSystemSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
2
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
2
][
1
][
0
],
())
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
2
][
1
][
1
]
.
keys
()
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
2
][
1
][
1
]),
set
([
'memory_used'
,
'cpu_percent'
,
'insertion_date'
,
'insertion_time'
,
set
([
'memory_used'
,
'cpu_percent'
,
'insertion_date'
,
'insertion_time'
,
'loadavg'
,
'memory_free'
,
'net_in_bytes'
,
'net_in_dropped'
,
'loadavg'
,
'memory_free'
,
'net_in_bytes'
,
'net_in_dropped'
,
'net_in_errors'
,
'net_out_bytes'
,
'net_out_dropped'
,
'net_in_errors'
,
'net_out_bytes'
,
'net_out_dropped'
,
...
@@ -598,7 +598,7 @@ class TestCollectEntity(unittest.TestCase):
...
@@ -598,7 +598,7 @@ class TestCollectEntity(unittest.TestCase):
self
.
assertEquals
(
database
.
invoked_method_list
[
3
][
0
],
"insertDiskPartitionSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
3
][
0
],
"insertDiskPartitionSnapshot"
)
self
.
assertEquals
(
database
.
invoked_method_list
[
3
][
1
][
0
],
())
self
.
assertEquals
(
database
.
invoked_method_list
[
3
][
1
][
0
],
())
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
3
][
1
][
1
]
.
keys
()
),
self
.
assertEquals
(
set
(
database
.
invoked_method_list
[
3
][
1
][
1
]),
set
([
'used'
,
'insertion_date'
,
'partition'
,
'free'
,
set
([
'used'
,
'insertion_date'
,
'partition'
,
'free'
,
'mountpoint'
,
'insertion_time'
]))
'mountpoint'
,
'insertion_time'
]))
...
...
slapos/tests/promise.py
View file @
9de598f2
...
@@ -290,9 +290,9 @@ class RunPromise(GenericPromise):
...
@@ -290,9 +290,9 @@ class RunPromise(GenericPromise):
promise_module
=
promise_process
.
_loadPromiseModule
()
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
(
promise_process
.
argument_dict
)
promise
=
promise_module
.
RunPromise
(
promise_process
.
argument_dict
)
self
.
assertEqual
(
promise
.
getConfig
(
'foo'
),
'bar'
)
self
.
assertEqual
s
(
promise
.
getConfig
(
'foo'
),
'bar'
)
self
.
assertEqual
(
promise
.
getConfig
(
'my-config'
),
4522111
)
self
.
assertEqual
s
(
promise
.
getConfig
(
'my-config'
),
4522111
)
self
.
assertEqual
(
promise
.
getConfig
(
'text'
),
config_dict
[
'text'
])
self
.
assertEqual
s
(
promise
.
getConfig
(
'text'
),
config_dict
[
'text'
])
def
test_promise_extra_config_reserved_name
(
self
):
def
test_promise_extra_config_reserved_name
(
self
):
promise_name
=
'my_promise_extra.py'
promise_name
=
'my_promise_extra.py'
...
@@ -347,7 +347,7 @@ class RunPromise(GenericPromise):
...
@@ -347,7 +347,7 @@ class RunPromise(GenericPromise):
with
open
(
state_file
)
as
f
:
with
open
(
state_file
)
as
f
:
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
result_dict
[
'result'
].
pop
(
'date'
)
self
.
assertEqual
(
json
.
loads
(
expected_result
),
result_dict
)
self
.
assertEqual
s
(
json
.
loads
(
expected_result
),
result_dict
)
def
test_runpromise_multiple
(
self
):
def
test_runpromise_multiple
(
self
):
promise_name
=
'my_promise.py'
promise_name
=
'my_promise.py'
...
@@ -381,7 +381,7 @@ class RunPromise(GenericPromise):
...
@@ -381,7 +381,7 @@ class RunPromise(GenericPromise):
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
result_dict
[
'result'
].
pop
(
'date'
)
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_promise'
}
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_promise'
}
self
.
assertEqual
(
json
.
loads
(
expected_dict
),
result_dict
)
self
.
assertEqual
s
(
json
.
loads
(
expected_dict
),
result_dict
)
# second promise
# second promise
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_second_promise.status.json'
)
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_second_promise.status.json'
)
...
@@ -390,7 +390,7 @@ class RunPromise(GenericPromise):
...
@@ -390,7 +390,7 @@ class RunPromise(GenericPromise):
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
result_dict
[
'result'
].
pop
(
'date'
)
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_second_promise'
}
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_second_promise'
}
self
.
assertEqual
(
json
.
loads
(
expected_dict
),
result_dict
)
self
.
assertEqual
s
(
json
.
loads
(
expected_dict
),
result_dict
)
def
test_runpromise_no_logdir
(
self
):
def
test_runpromise_no_logdir
(
self
):
promise_name
=
'my_promise.py'
promise_name
=
'my_promise.py'
...
@@ -410,11 +410,11 @@ class RunPromise(GenericPromise):
...
@@ -410,11 +410,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -432,11 +432,11 @@ class RunPromise(GenericPromise):
...
@@ -432,11 +432,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
# no promise log output dir
# no promise log output dir
...
@@ -455,11 +455,11 @@ class RunPromise(GenericPromise):
...
@@ -455,11 +455,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
)
...
@@ -480,11 +480,11 @@ class RunPromise(GenericPromise):
...
@@ -480,11 +480,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
name
in
[
promise_failed
,
promise_name
])
self
.
assertTrue
(
result
.
name
in
[
promise_failed
,
promise_name
])
if
result
.
name
==
promise_failed
:
if
result
.
name
==
promise_failed
:
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
item
.
message
,
"failed"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"failed"
)
else
:
else
:
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -494,7 +494,7 @@ class RunPromise(GenericPromise):
...
@@ -494,7 +494,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
):
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertTrue
(
os
.
path
.
exists
(
state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_failed_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_failed_promise.log'
)))
...
@@ -508,8 +508,8 @@ class RunPromise(GenericPromise):
...
@@ -508,8 +508,8 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
,
third_promise
])
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
,
third_promise
])
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -520,7 +520,7 @@ class RunPromise(GenericPromise):
...
@@ -520,7 +520,7 @@ class RunPromise(GenericPromise):
# run promise will not fail
# run promise will not fail
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
3
)
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
assertTrue
(
os
.
path
.
exists
(
state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_first_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_first_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_second_promise.log'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_second_promise.log'
)))
...
@@ -562,15 +562,15 @@ class RunPromise(GenericPromise):
...
@@ -562,15 +562,15 @@ class RunPromise(GenericPromise):
def
test_method_first
(
result
):
def
test_method_first
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
def
test_method_one
(
result
):
def
test_method_one
(
result
):
self
.
counter
+=
1
self
.
counter
+=
1
self
.
assertEqual
(
result
.
name
,
first_promise
)
self
.
assertEqual
s
(
result
.
name
,
first_promise
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
configureLauncher
(
save_method
=
test_method_first
)
self
.
configureLauncher
(
save_method
=
test_method_first
)
# ~2 seconds
# ~2 seconds
...
@@ -579,19 +579,19 @@ class RunPromise(GenericPromise):
...
@@ -579,19 +579,19 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.05
)
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.05
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method_one
)
self
.
configureLauncher
(
save_method
=
test_method_one
)
time
.
sleep
(
2
)
time
.
sleep
(
2
)
self
.
counter
=
0
self
.
counter
=
0
self
.
launcher
.
run
()
# only my_first_promise will run
self
.
launcher
.
run
()
# only my_first_promise will run
self
.
assertEqual
(
self
.
counter
,
1
)
self
.
assertEqual
s
(
self
.
counter
,
1
)
time
.
sleep
(
3
)
time
.
sleep
(
3
)
self
.
counter
=
0
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method_first
)
self
.
configureLauncher
(
save_method
=
test_method_first
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
def
test_runpromise_with_periodicity_same
(
self
):
def
test_runpromise_with_periodicity_same
(
self
):
first_promise
=
'my_first_promise.py'
first_promise
=
'my_first_promise.py'
...
@@ -600,8 +600,8 @@ class RunPromise(GenericPromise):
...
@@ -600,8 +600,8 @@ class RunPromise(GenericPromise):
def
test_method
(
result
):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -610,19 +610,19 @@ class RunPromise(GenericPromise):
...
@@ -610,19 +610,19 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
(
self
.
counter
,
0
)
self
.
assertEqual
s
(
self
.
counter
,
0
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
def
test_runpromise_with_periodicity_result_failed
(
self
):
def
test_runpromise_with_periodicity_result_failed
(
self
):
first_promise
=
'my_first_promise.py'
first_promise
=
'my_first_promise.py'
...
@@ -640,14 +640,14 @@ class RunPromise(GenericPromise):
...
@@ -640,14 +640,14 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
self
.
assertTrue
(
os
.
path
.
exists
(
first_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
first_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertEqual
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
s
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
(
second_result
[
'name'
],
second_promise
)
self
.
assertEqual
s
(
second_result
[
'name'
],
second_promise
)
first_date
=
first_result
[
'result'
][
'date'
]
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
@@ -655,19 +655,19 @@ class RunPromise(GenericPromise):
...
@@ -655,19 +655,19 @@ class RunPromise(GenericPromise):
time
.
sleep
(
2
)
time
.
sleep
(
2
)
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
# only my_first_promise will run but second_promise still failing
self
.
launcher
.
run
()
# only my_first_promise will run but second_promise still failing
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertEqual
(
second_result
[
'result'
][
'date'
],
second_date
)
self
.
assertEqual
s
(
second_result
[
'result'
][
'date'
],
second_date
)
first_date
=
first_result
[
'result'
][
'date'
]
first_date
=
first_result
[
'result'
][
'date'
]
time
.
sleep
(
3
)
time
.
sleep
(
3
)
self
.
configureLauncher
()
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
...
@@ -696,8 +696,8 @@ class RunPromise(GenericPromise):
...
@@ -696,8 +696,8 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertEqual
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
s
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
(
second_result
[
'name'
],
second_promise
)
self
.
assertEqual
s
(
second_result
[
'name'
],
second_promise
)
first_date
=
first_result
[
'result'
][
'date'
]
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
@@ -710,7 +710,7 @@ class RunPromise(GenericPromise):
...
@@ -710,7 +710,7 @@ class RunPromise(GenericPromise):
first_result
=
json
.
load
(
open
(
first_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertEqual
(
second_result
[
'result'
][
'date'
],
second_date
)
self
.
assertEqual
s
(
second_result
[
'result'
][
'date'
],
second_date
)
first_date
=
first_result
[
'result'
][
'date'
]
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
@@ -735,8 +735,8 @@ class RunPromise(GenericPromise):
...
@@ -735,8 +735,8 @@ class RunPromise(GenericPromise):
def
test_method
(
result
):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -745,30 +745,30 @@ class RunPromise(GenericPromise):
...
@@ -745,30 +745,30 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
(
self
.
counter
,
0
)
self
.
assertEqual
s
(
self
.
counter
,
0
)
self
.
configureLauncher
(
save_method
=
test_method
,
force
=
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
force
=
True
)
self
.
counter
=
0
self
.
counter
=
0
self
.
launcher
.
run
()
# will run all as force is True
self
.
launcher
.
run
()
# will run all as force is True
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
(
self
.
counter
,
0
)
self
.
assertEqual
s
(
self
.
counter
,
0
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
# after 2 seconds will run all
self
.
launcher
.
run
()
# after 2 seconds will run all
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
def
test_runpromise_wrapped
(
self
):
def
test_runpromise_wrapped
(
self
):
promise_name
=
"my_bash_promise"
promise_name
=
"my_bash_promise"
...
@@ -785,11 +785,11 @@ echo "success"
...
@@ -785,11 +785,11 @@ echo "success"
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
(
result
.
title
,
promise_name
)
self
.
assertEqual
s
(
result
.
title
,
promise_name
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -822,12 +822,12 @@ exit 1
...
@@ -822,12 +822,12 @@ exit 1
self
.
called
+=
1
self
.
called
+=
1
result_dict
.
pop
(
result
.
name
)
result_dict
.
pop
(
result
.
name
)
if
result
.
title
==
"first_promise"
or
result
.
title
==
"second_promise"
:
if
result
.
title
==
"first_promise"
or
result
.
title
==
"second_promise"
:
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
if
result
.
title
==
"my_bash_promise"
:
if
result
.
title
==
"my_bash_promise"
:
self
.
assertEqual
(
result
.
item
.
message
,
"promise 1 succeeded"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"promise 1 succeeded"
)
if
result
.
title
==
"my_bash_promise2"
:
if
result
.
title
==
"my_bash_promise2"
:
self
.
assertEqual
(
result
.
item
.
message
,
"promise 2 succeeded"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"promise 2 succeeded"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
promise_name
=
"my_bash_promise"
promise_name
=
"my_bash_promise"
promise_path
=
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
)
promise_path
=
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
)
...
@@ -850,7 +850,7 @@ exit 0
...
@@ -850,7 +850,7 @@ exit 0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
called
,
4
)
self
.
assertEqual
s
(
self
.
called
,
4
)
def
test_runpromise_run_only
(
self
):
def
test_runpromise_run_only
(
self
):
...
@@ -861,8 +861,8 @@ exit 0
...
@@ -861,8 +861,8 @@ exit 0
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
def
test_method
(
result
):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -872,14 +872,14 @@ exit 0
...
@@ -872,14 +872,14 @@ exit 0
# run promise will not fail
# run promise will not fail
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
3
)
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
counter
=
0
self
.
counter
=
0
self
.
check_list
=
[
second_promise
]
self
.
check_list
=
[
second_promise
]
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
[
second_promise
],
force
=
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
[
second_promise
],
force
=
True
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
1
)
self
.
assertEqual
s
(
self
.
counter
,
1
)
def
test_runpromise_run_only_multiple
(
self
):
def
test_runpromise_run_only_multiple
(
self
):
first_promise
=
'my_first_promise.py'
first_promise
=
'my_first_promise.py'
...
@@ -889,8 +889,8 @@ exit 0
...
@@ -889,8 +889,8 @@ exit 0
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
def
test_method
(
result
):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
configureLauncher
(
save_method
=
test_method
)
...
@@ -900,14 +900,14 @@ exit 0
...
@@ -900,14 +900,14 @@ exit 0
# run promise will not fail
# run promise will not fail
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
3
)
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
counter
=
0
self
.
counter
=
0
self
.
check_list
=
[
third_promise
,
second_promise
]
self
.
check_list
=
[
third_promise
,
second_promise
]
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
self
.
check_list
,
force
=
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
self
.
check_list
,
force
=
True
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launcher
.
run
()
self
.
launcher
.
run
()
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
assertEqual
s
(
self
.
counter
,
2
)
def
writeLatestPromiseResult
(
self
):
def
writeLatestPromiseResult
(
self
):
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_promise.status.json'
)
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_promise.status.json'
)
...
@@ -962,10 +962,10 @@ exit 0
...
@@ -962,10 +962,10 @@ exit 0
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
,
timeout
=
1
)
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
,
timeout
=
1
)
self
.
generatePromiseScript
(
promise_name
,
success
=
True
,
content
=
"""import time
self
.
generatePromiseScript
(
promise_name
,
success
=
True
,
content
=
"""import time
...
@@ -993,11 +993,11 @@ echo "success"
...
@@ -993,11 +993,11 @@ echo "success"
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertEqual
(
result
.
title
,
promise_name
)
self
.
assertEqual
s
(
result
.
title
,
promise_name
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
promise_path
)
self
.
assertEqual
s
(
result
.
path
,
promise_path
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
,
timeout
=
1
)
self
.
configureLauncher
(
save_method
=
test_method
,
timeout
=
1
)
...
@@ -1105,16 +1105,16 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1105,16 +1105,16 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise_process
=
self
.
createPromiseProcess
()
promise_process
=
self
.
createPromiseProcess
()
promise_module
=
promise_process
.
_loadPromiseModule
()
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
self
.
assertEqual
(
promise
.
getPeriodicity
(),
1
)
self
.
assertEqual
s
(
promise
.
getPeriodicity
(),
1
)
self
.
assertEqual
(
promise
.
getName
(),
self
.
promise_name
)
self
.
assertEqual
s
(
promise
.
getName
(),
self
.
promise_name
)
self
.
assertEqual
(
promise
.
getTitle
(),
'my_promise'
)
self
.
assertEqual
s
(
promise
.
getTitle
(),
'my_promise'
)
self
.
assertEqual
(
promise
.
getPartitionFolder
(),
self
.
partition_dir
)
self
.
assertEqual
s
(
promise
.
getPartitionFolder
(),
self
.
partition_dir
)
self
.
assertEqual
(
promise
.
getPromiseFile
(),
self
.
promise_path
)
self
.
assertEqual
s
(
promise
.
getPromiseFile
(),
self
.
promise_path
)
self
.
assertEqual
(
promise
.
getLogFolder
(),
self
.
log_dir
)
self
.
assertEqual
s
(
promise
.
getLogFolder
(),
self
.
log_dir
)
self
.
assertEqual
(
promise
.
getLogFile
(),
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
))
self
.
assertEqual
s
(
promise
.
getLogFile
(),
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
))
promise
.
setPeriodicity
(
2
)
promise
.
setPeriodicity
(
2
)
self
.
assertEqual
(
promise
.
getPeriodicity
(),
2
)
self
.
assertEqual
s
(
promise
.
getPeriodicity
(),
2
)
with
self
.
assertRaises
(
ValueError
):
with
self
.
assertRaises
(
ValueError
):
promise
.
setPeriodicity
(
0
)
promise
.
setPeriodicity
(
0
)
...
@@ -1122,11 +1122,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1122,11 +1122,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
self
.
queue
.
get
(
True
,
1
)
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
def
test_promise_anomaly_disabled
(
self
):
def
test_promise_anomaly_disabled
(
self
):
...
@@ -1139,11 +1139,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1139,11 +1139,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
self
.
queue
.
get
(
True
,
1
)
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
def
test_promise_with_raise
(
self
):
def
test_promise_with_raise
(
self
):
...
@@ -1156,10 +1156,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1156,10 +1156,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
# no raise
promise
.
run
()
promise
.
run
()
result
=
self
.
queue
.
get
(
True
,
1
)
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
item
.
message
,
"Bad Promise raised"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"Bad Promise raised"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
def
test_promise_no_return
(
self
):
def
test_promise_no_return
(
self
):
promise_content
=
"return"
promise_content
=
"return"
...
@@ -1171,10 +1171,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1171,10 +1171,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
# no raise
promise
.
run
()
promise
.
run
()
result
=
self
.
queue
.
get
(
True
,
1
)
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
item
.
message
,
"No result found!"
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"No result found!"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
def
test_promise_resultfromlog
(
self
):
def
test_promise_resultfromlog
(
self
):
promise_content
=
"self.logger.info('Promise is running...')"
promise_content
=
"self.logger.info('Promise is running...')"
...
@@ -1188,11 +1188,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1188,11 +1188,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
# get all messages during the latest minute
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
0
],
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
@@ -1208,12 +1208,12 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1208,12 +1208,12 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
# get all messages during the latest minute
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
0
],
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'ERROR'
,
{
'date'
:
date
,
'status'
:
'ERROR'
,
'message'
:
'Promise is running...
\
n
message in new line'
})
'message'
:
'Promise is running...
\
n
message in new line'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
@@ -1227,17 +1227,17 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1227,17 +1227,17 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
date
=
datetime
.
now
()
date
=
datetime
.
now
()
promise
.
sense
()
promise
.
sense
()
self
.
assertEqual
(
promise
.
getLogFolder
(),
None
)
self
.
assertEqual
s
(
promise
.
getLogFolder
(),
None
)
self
.
assertEqual
(
promise
.
getLogFile
(),
None
)
self
.
assertEqual
s
(
promise
.
getLogFile
(),
None
)
# get all messages during the latest minute
# get all messages during the latest minute
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
1
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
date
=
datetime
.
strptime
(
date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
0
],
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
@@ -1264,13 +1264,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1264,13 +1264,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
start_date
=
datetime
.
strptime
(
start_date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
start_date
=
datetime
.
strptime
(
start_date
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
'%Y-%m-%d %H:%M:%S'
)
end_date_string
=
(
start_date
-
timedelta
(
minutes
=
9
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date_string
=
(
start_date
-
timedelta
(
minutes
=
9
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
self
.
assertEqual
(
len
(
latest_message_list
),
10
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
10
)
for
message
in
latest_message_list
:
for
message
in
latest_message_list
:
self
.
assertEqual
(
len
(
message
),
1
)
self
.
assertEqual
s
(
len
(
message
),
1
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
0
],
latest_message_list
[
0
][
0
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 49'
})
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 49'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
-
1
][
0
],
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 40'
})
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 40'
})
...
@@ -1309,13 +1309,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1309,13 +1309,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
*
19
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
*
19
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
# there is 2 result line per minutes
# there is 2 result line per minutes
self
.
assertEqual
(
len
(
latest_message_list
),
10
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
10
)
for
message
in
latest_message_list
:
for
message
in
latest_message_list
:
self
.
assertEqual
(
len
(
message
),
2
)
self
.
assertEqual
s
(
len
(
message
),
2
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
-
1
][
0
],
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 19'
})
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 19'
})
...
@@ -1353,11 +1353,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1353,11 +1353,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
# there is 2 result line per minutes
# there is 2 result line per minutes
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
0
],
latest_message_list
[
0
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 1'
})
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 1'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
...
@@ -1395,19 +1395,19 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1395,19 +1395,19 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
*
3
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date_string
=
(
start_date
-
timedelta
(
seconds
=
30
*
3
)).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
end_date
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
# there is 2 result line per minutes
# there is 2 result line per minutes
self
.
assertEqual
(
len
(
latest_message_list
),
2
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
2
)
for
message
in
latest_message_list
:
for
message
in
latest_message_list
:
self
.
assertEqual
(
len
(
message
),
2
)
self
.
assertEqual
s
(
len
(
message
),
2
)
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
0
][
1
],
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
self
.
assertEqual
(
self
.
assertEqual
s
(
latest_message_list
[
-
1
][
0
],
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 3'
})
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 3'
})
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
100
)
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
100
)
# all results
# all results
self
.
assertEqual
(
len
(
latest_message_list
),
25
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
25
)
def
test_promise_defaulttest
(
self
):
def
test_promise_defaulttest
(
self
):
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
...
@@ -1420,8 +1420,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1420,8 +1420,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
s
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
def
test_promise_defaulttest_failure
(
self
):
def
test_promise_defaulttest_failure
(
self
):
self
.
initialisePromise
(
success
=
False
)
self
.
initialisePromise
(
success
=
False
)
...
@@ -1433,8 +1433,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1433,8 +1433,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
def
test_promise_defaulttest_error_if_two_fail
(
self
):
def
test_promise_defaulttest_error_if_two_fail
(
self
):
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
...
@@ -1447,8 +1447,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1447,8 +1447,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# fail if 2 errors found
# fail if 2 errors found
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
promise_process
=
self
.
createPromiseProcess
()
promise_process
=
self
.
createPromiseProcess
()
...
@@ -1456,8 +1456,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1456,8 +1456,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
.
sense
()
promise
.
sense
()
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
# will continue to fail
# will continue to fail
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
...
@@ -1466,8 +1466,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1466,8 +1466,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
.
sense
()
promise
.
sense
()
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
def
test_promise_defaulttest_anomaly
(
self
):
def
test_promise_defaulttest_anomaly
(
self
):
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
...
@@ -1480,8 +1480,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
...
@@ -1480,8 +1480,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_anomaly
(
result_count
=
1
,
failure_amount
=
1
)
result
=
promise
.
_anomaly
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
AnomalyResult
))
self
.
assertTrue
(
isinstance
(
result
,
AnomalyResult
))
self
.
assertEqual
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
s
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
slapos/util.py
View file @
9de598f2
...
@@ -84,8 +84,6 @@ def string_to_boolean(string):
...
@@ -84,8 +84,6 @@ def string_to_boolean(string):
The parser is completely arbitrary, see code for actual implementation.
The parser is completely arbitrary, see code for actual implementation.
"""
"""
if
isinstance
(
string
,
bytes
):
string
=
string
.
decode
(
'utf-8'
)
try
:
try
:
return
(
'false'
,
'true'
).
index
(
string
.
lower
())
return
(
'false'
,
'true'
).
index
(
string
.
lower
())
except
Exception
:
except
Exception
:
...
...
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