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
146f0e0d
Commit
146f0e0d
authored
Oct 26, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
b7ddce31
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
212 additions
and
251 deletions
+212
-251
slapos/cli/configure_local/__init__.py
slapos/cli/configure_local/__init__.py
+4
-2
slapos/client.py
slapos/client.py
+1
-1
slapos/collect/reporter.py
slapos/collect/reporter.py
+10
-20
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+2
-2
slapos/grid/networkcache.py
slapos/grid/networkcache.py
+2
-2
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+3
-3
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+2
-2
slapos/grid/utils.py
slapos/grid/utils.py
+3
-1
slapos/proxy/views.py
slapos/proxy/views.py
+2
-15
slapos/slap/slap.py
slapos/slap/slap.py
+2
-7
slapos/tests/promise.py
slapos/tests/promise.py
+157
-157
slapos/tests/slap.py
slapos/tests/slap.py
+19
-19
slapos/tests/util.py
slapos/tests/util.py
+0
-9
slapos/util.py
slapos/util.py
+5
-11
No files found.
slapos/cli/configure_local/__init__.py
View file @
146f0e0d
...
...
@@ -126,7 +126,8 @@ def _replaceParameterValue(original_content, to_replace):
def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
template_arg_list = (__name__, '
..
/
..
/
slapos
.
cfg
.
example
')
slapos_node_configuration_template = pkg_resources.resource_string(*template_arg_list).decode('
utf
-
8
')
slapos_node_configuration_template =
\
pkg_resources.resource_string(*template_arg_list).decode('
utf
-
8
')
master_url = '
http
:
//%
s
:
%
s
' % (args.daemon_listen_ip, args.daemon_listen_port)
slapos_home = args.slapos_buildout_directory
to_replace = [
...
...
@@ -152,7 +153,8 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
def _generateSlaposProxyConfigurationFile(conf):
template_arg_list = (__name__, '
..
/
..
/
slapos
-
proxy
.
cfg
.
example
')
slapos_proxy_configuration_template = pkg_resources.resource_string(*template_arg_list).decode('
utf
-
8
')
slapos_proxy_configuration_template =
\
pkg_resources.resource_string(*template_arg_list).decode('
utf
-
8
')
slapos_proxy_configuration_path = os.path.join(
conf.slapos_configuration_directory, '
slapos
-
proxy
.
cfg
')
listening_ip, listening_port =
\
...
...
slapos/client.py
View file @
146f0e0d
...
...
@@ -119,7 +119,7 @@ def _getSoftwareReleaseFromSoftwareString(logger, software_string, product):
try
:
return
product
.
__getattr__
(
software_string
[
len
(
SOFTWARE_PRODUCT_NAMESPACE
):])
except
AttributeError
as
e
:
logger
.
error
(
'Error: %s Exiting now.'
%
e
)
logger
.
error
(
'Error: %s Exiting now.'
,
e
)
sys
.
exit
(
1
)
def
do_console
(
local
):
...
...
slapos/collect/reporter.py
View file @
146f0e0d
...
...
@@ -27,8 +27,6 @@
#
##############################################################################
from
six.moves
import
zip
from
lxml
import
etree
as
ElementTree
from
slapos.util
import
mkdir_p
...
...
@@ -137,19 +135,17 @@ class ConsumptionReportBase(object):
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
query_result_cursor
=
self
.
db
.
select
(
"user"
,
date_scope
,
cpu_percent_sum
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(cpu_percent)"
,
where
=
"partition = '%s'"
%
partition_id
)
cpu_percent_sum
=
list
(
zip
(
*
query_result_cursor
))
if
len
(
cpu_percent_sum
)
and
cpu_percent_sum
[
0
][
0
]
is
None
:
return
query_result_cursor
=
self
.
db
.
select
(
"user"
,
date_scope
,
sample_amount
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
sample_amount
=
list
(
zip
(
*
query_result_cursor
))
self
.
db
.
close
()
if
len
(
sample_amount
)
and
len
(
cpu_percent_sum
):
...
...
@@ -157,19 +153,17 @@ class ConsumptionReportBase(object):
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
query_result_cursor
=
self
.
db
.
select
(
"user"
,
date_scope
,
memory_sum
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(memory_rss)"
,
where
=
"partition = '%s'"
%
partition_id
)
memory_sum
=
list
(
zip
(
*
query_result_cursor
))
if
len
(
memory_sum
)
and
memory_sum
[
0
][
0
]
is
None
:
return
query_result_cursor
=
self
.
db
.
select
(
"user"
,
date_scope
,
sample_amount
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
sample_amount
=
list
(
zip
(
*
query_result_cursor
))
self
.
db
.
close
()
if
len
(
sample_amount
)
and
len
(
memory_sum
):
...
...
@@ -177,18 +171,16 @@ class ConsumptionReportBase(object):
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
query_result_cursor
=
self
.
db
.
select
(
"folder"
,
date_scope
,
disk_used_sum
=
self
.
db
.
select
(
"folder"
,
date_scope
,
columns
=
"SUM(disk_used)"
,
where
=
"partition = '%s'"
%
partition_id
)
disk_used_sum
=
list
(
zip
(
*
query_result_cursor
))
if
len
(
disk_used_sum
)
and
disk_used_sum
[
0
][
0
]
is
None
:
return
query_result_cursor
=
self
.
db
.
select
(
"folder"
,
date_scope
,
collect_amount
=
self
.
db
.
select
(
"folder"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
collect_amount
=
list
(
zip
(
*
query_result_cursor
))
self
.
db
.
close
()
if
len
(
collect_amount
)
and
len
(
disk_used_sum
):
...
...
@@ -289,7 +281,7 @@ class ConsumptionReport(ConsumptionReportBase):
reference
=
user
,
category
=
""
)
with
open
(
xml_report_path
,
'w'
)
as
f
:
with
open
(
xml_report_path
,
'w
b
'
)
as
f
:
f
.
write
(
journal
.
getXML
())
f
.
close
()
...
...
@@ -300,20 +292,18 @@ class ConsumptionReport(ConsumptionReportBase):
def
_getCpuLoadAverageConsumption
(
self
,
date_scope
):
self
.
db
.
connect
()
query_result_cursor
=
self
.
db
.
select
(
"system"
,
date_scope
,
cpu_load_percent_list
=
self
.
db
.
select
(
"system"
,
date_scope
,
columns
=
"SUM(cpu_percent)/COUNT(cpu_percent)"
)
cpu_load_percent_list
=
list
(
zip
(
*
query_result_cursor
))
self
.
db
.
close
()
if
len
(
cpu_load_percent_list
):
return
cpu_load_percent_list
[
0
][
0
]
def
_getMemoryAverageConsumption
(
self
,
date_scope
):
self
.
db
.
connect
()
query_result_cursor
=
self
.
db
.
select
(
"system"
,
date_scope
,
memory_used_list
=
self
.
db
.
select
(
"system"
,
date_scope
,
columns
=
"SUM(memory_used)/COUNT(memory_used)"
)
memory_used_list
=
list
(
zip
(
*
query_result_cursor
))
self
.
db
.
close
()
if
len
(
memory_used_list
):
return
memory_used_list
[
0
][
0
]
...
...
@@ -331,7 +321,7 @@ class Journal(object):
def
getXML
(
self
):
report
=
ElementTree
.
tostring
(
self
.
root
)
return
"<?xml version='1.0' encoding='utf-8'?>%s"
%
report
return
b
"<?xml version='1.0' encoding='utf-8'?>%s"
%
report
def
newTransaction
(
self
,
portal_type
=
"Sale Packing List"
):
transaction
=
ElementTree
.
SubElement
(
self
.
root
,
"transaction"
)
...
...
slapos/grid/SlapObject.py
View file @
146f0e0d
...
...
@@ -292,8 +292,8 @@ class Software(object):
f
.
close
()
def
_create_buildout_profile
(
self
,
buildout_cfg
,
url
):
with
open
(
buildout_cfg
,
'w
b
'
)
as
fout
:
fout
.
write
(
(
'[buildout]
\
n
extends = '
+
url
+
'
\
n
'
).
encode
(
'utf-8'
)
)
with
open
(
buildout_cfg
,
'w'
)
as
fout
:
fout
.
write
(
'[buildout]
\
n
extends = '
+
url
+
'
\
n
'
)
self
.
_set_ownership
(
buildout_cfg
)
def
uploadSoftwareRelease
(
self
,
tarpath
):
...
...
slapos/grid/networkcache.py
View file @
146f0e0d
...
...
@@ -30,8 +30,8 @@ try:
else
:
LIBNETWORKCACHE_ENABLED
=
True
except
:
print
(
'There was problem while trying to import slapos.libnetworkcache:
'
\
'
\
n
%s'
%
traceback
.
format_exc
())
print
(
'There was problem while trying to import slapos.libnetworkcache:
\
n
%s'
%
traceback
.
format_exc
())
LIBNETWORKCACHE_ENABLED
=
False
print
(
'Networkcache forced to be disabled.'
)
...
...
slapos/grid/promise/__init__.py
View file @
146f0e0d
...
...
@@ -38,7 +38,7 @@ import importlib
import
traceback
import
psutil
from
multiprocessing
import
Process
,
Queue
as
MQueue
from
six.moves
import
queue
from
six.moves
import
queue
,
reload_module
from
slapos.util
import
mkdir_p
,
chownDirectory
from
slapos.grid.utils
import
dropPrivileges
,
killProcessTree
from
slapos.grid.promise
import
interface
...
...
@@ -195,7 +195,7 @@ class PromiseProcess(Process):
if
promise_module
.
__file__
!=
self
.
promise_path
:
# cached module need to be updated
promise_module
=
reload
(
promise_module
)
promise_module
=
reload
_module
(
promise_module
)
# load extra parameters
self
.
_loadPromiseParameterDict
(
promise_module
)
...
...
@@ -208,7 +208,7 @@ class PromiseProcess(Process):
if
not
isinstance
(
extra_dict
,
dict
):
raise
ValueError
(
"Extra parameter is not a dict"
)
for
key
in
extra_dict
:
if
self
.
argument_dict
.
has_key
(
key
)
:
if
key
in
self
.
argument_dict
:
raise
ValueError
(
"Extra parameter name %r cannot be used.
\
n
%s"
%
(
key
,
extra_dict
))
self
.
argument_dict
[
key
]
=
extra_dict
[
key
]
...
...
slapos/grid/slapgrid.py
View file @
146f0e0d
...
...
@@ -32,7 +32,7 @@ import os
import
pkg_resources
import
random
import
socket
from
six
import
String
IO
from
io
import
Bytes
IO
import
subprocess
import
sys
import
tempfile
...
...
@@ -1309,7 +1309,7 @@ stderr_logfile_backups=1
def
validateXML
(
self
,
to_be_validated
,
xsd_model
):
"""Validates a given xml file"""
#We retrieve the xsd model
xsd_model
=
StringIO
.
String
IO
(
xsd_model
)
xsd_model
=
Bytes
IO
(
xsd_model
)
xmlschema_doc
=
etree
.
parse
(
xsd_model
)
xmlschema
=
etree
.
XMLSchema
(
xmlschema_doc
)
...
...
slapos/grid/utils.py
View file @
146f0e0d
...
...
@@ -352,10 +352,12 @@ def launchBuildout(path, buildout_binary, logger,
def
updateFile
(
file_path
,
content
,
mode
=
0o600
):
"""Creates or updates a file with "content" as content."""
altered
=
False
if
isinstance
(
content
,
six
.
text_type
):
content
=
content
.
encode
(
'utf-8'
)
if
not
(
os
.
path
.
isfile
(
file_path
))
or
\
not
(
hashlib
.
md5
(
open
(
file_path
,
'rb'
).
read
()).
digest
()
==
hashlib
.
md5
(
content
).
digest
()):
with
open
(
file_path
,
'w'
)
as
fout
:
with
open
(
file_path
,
'w
b
'
)
as
fout
:
fout
.
write
(
content
)
altered
=
True
os
.
chmod
(
file_path
,
stat
.
S_IREAD
|
stat
.
S_IWRITE
|
stat
.
S_IEXEC
)
...
...
slapos/proxy/views.py
View file @
146f0e0d
...
...
@@ -55,19 +55,10 @@ class UnauthorizedError(Exception):
pass
# cast everything to string, utf-8 encoded
def
to_str
(
v
):
if
isinstance
(
v
,
six
.
binary_type
):
return
v
if
not
isinstance
(
v
,
six
.
text_type
):
v
=
six
.
text_type
(
v
)
return
v
.
encode
(
'utf-8'
)
def
xml2dict
(
xml
):
result_dict
=
{}
if
xml
is
not
None
and
xml
!=
''
:
tree
=
etree
.
fromstring
(
to_str
(
xml
)
)
if
xml
:
tree
=
etree
.
fromstring
(
xml
)
for
element
in
tree
.
iter
(
tag
=
etree
.
Element
):
if
element
.
tag
==
'parameter'
:
key
=
element
.
get
(
'id'
)
...
...
@@ -83,8 +74,6 @@ def xml2dict(xml):
def
dict2xml
(
dictionary
):
instance
=
etree
.
Element
(
'instance'
)
for
parameter_id
,
parameter_value
in
six
.
iteritems
(
dictionary
):
# cast everything to string
parameter_value
=
six
.
text_type
(
parameter_value
)
etree
.
SubElement
(
instance
,
"parameter"
,
attrib
=
{
'id'
:
parameter_id
}).
text
=
parameter_value
return
etree
.
tostring
(
instance
,
...
...
@@ -511,8 +500,6 @@ def forwardRequestToExternalMaster(master_url, request_form):
new_request_form
[
'filter_xml'
]
=
dumps
(
filter_kw
)
xml
=
slap
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
data
=
new_request_form
)
if
type
(
xml
)
is
six
.
text_type
:
xml
.
encode
(
'utf-8'
)
partition
=
loads
(
xml
)
# XXX move to other end
...
...
slapos/slap/slap.py
View file @
146f0e0d
...
...
@@ -94,8 +94,6 @@ class SlapRequester(SlapDocument):
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
)
if
type
(
xml
)
is
six
.
text_type
:
xml
.
encode
(
'utf-8'
)
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
...
...
@@ -206,12 +204,11 @@ class SoftwareInstance(SlapDocument):
Contains Software Instance information
"""
def
__init__
(
self
,
**
kw
args
):
def
__init__
(
self
,
**
kw
):
"""
Makes easy initialisation of class parameters
"""
for
k
,
v
in
six
.
iteritems
(
kwargs
):
setattr
(
self
,
k
,
v
)
self
.
__dict__
.
update
(
kw
)
"""Exposed exceptions"""
...
...
@@ -728,8 +725,6 @@ class ConnectionHelper:
# We should stablise slap library soon.
xml
=
self
.
GET
(
'getComputerInformation'
,
params
=
params
)
if
type
(
xml
)
is
six
.
text_type
:
xml
.
encode
(
'utf-8'
)
return
xml_marshaller
.
loads
(
xml
)
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
):
...
...
slapos/tests/promise.py
View file @
146f0e0d
...
...
@@ -185,7 +185,7 @@ class TestSlapOSPromiseLauncher(TestSlapOSPromiseMixin):
with
self
.
assertRaises
(
ImportError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEqual
s
(
str
(
exc
.
exception
),
'No module named %s'
%
self
.
assertEqual
(
str
(
exc
.
exception
),
'No module named %s'
%
(
"'%s'"
%
promise_name
if
six
.
PY3
else
promise_name
))
...
...
@@ -211,7 +211,7 @@ class RunPromise(GenericPromise):
promise_module
=
promise_process
.
_loadPromiseModule
()
message
=
"RunPromise class in my_promise_noimplement.py must implement"
\
" 'IPromise' interface. @implementer(interface.IPromise) is missing ?"
self
.
assertEqual
s
(
str
(
exc
.
exception
),
message
)
self
.
assertEqual
(
str
(
exc
.
exception
),
message
)
def
test_promise_match_interface_no_generic
(
self
):
promise_name
=
'my_promise_nogeneric.py'
...
...
@@ -236,7 +236,7 @@ class RunPromise(object):
with
self
.
assertRaises
(
RuntimeError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEqual
s
(
str
(
exc
.
exception
),
'RunPromise class is not a subclass of GenericPromise class.'
)
self
.
assertEqual
(
str
(
exc
.
exception
),
'RunPromise class is not a subclass of GenericPromise class.'
)
def
test_promise_match_interface_no_sense
(
self
):
promise_name
=
'my_promise_nosense.py'
...
...
@@ -262,7 +262,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
TypeError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
({})
self
.
assertEqual
s
(
str
(
exc
.
exception
),
self
.
assertEqual
(
str
(
exc
.
exception
),
"Can't instantiate abstract class RunPromise with abstract methods sense"
)
def
test_promise_extra_config
(
self
):
...
...
@@ -290,9 +290,9 @@ class RunPromise(GenericPromise):
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
(
promise_process
.
argument_dict
)
self
.
assertEqual
s
(
promise
.
getConfig
(
'foo'
),
'bar'
)
self
.
assertEqual
s
(
promise
.
getConfig
(
'my-config'
),
4522111
)
self
.
assertEqual
s
(
promise
.
getConfig
(
'text'
),
config_dict
[
'text'
])
self
.
assertEqual
(
promise
.
getConfig
(
'foo'
),
'bar'
)
self
.
assertEqual
(
promise
.
getConfig
(
'my-config'
),
4522111
)
self
.
assertEqual
(
promise
.
getConfig
(
'text'
),
config_dict
[
'text'
])
def
test_promise_extra_config_reserved_name
(
self
):
promise_name
=
'my_promise_extra.py'
...
...
@@ -318,7 +318,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
ValueError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEqual
s
(
str
(
exc
.
exception
),
"Extra parameter name 'name' cannot be used.
\
n
%s"
%
config_dict
)
self
.
assertEqual
(
str
(
exc
.
exception
),
"Extra parameter name 'name' cannot be used.
\
n
%s"
%
config_dict
)
def
test_runpromise
(
self
):
promise_name
=
'my_promise.py'
...
...
@@ -347,7 +347,7 @@ class RunPromise(GenericPromise):
with
open
(
state_file
)
as
f
:
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
self
.
assertEqual
s
(
json
.
loads
(
expected_result
),
result_dict
)
self
.
assertEqual
(
json
.
loads
(
expected_result
),
result_dict
)
def
test_runpromise_multiple
(
self
):
promise_name
=
'my_promise.py'
...
...
@@ -381,7 +381,7 @@ class RunPromise(GenericPromise):
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_promise'
}
self
.
assertEqual
s
(
json
.
loads
(
expected_dict
),
result_dict
)
self
.
assertEqual
(
json
.
loads
(
expected_dict
),
result_dict
)
# second promise
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_second_promise.status.json'
)
...
...
@@ -390,7 +390,7 @@ class RunPromise(GenericPromise):
result_dict
=
json
.
loads
(
f
.
read
())
result_dict
[
'result'
].
pop
(
'date'
)
expected_dict
=
expected_result
%
{
'promise_dir'
:
self
.
plugin_dir
,
'name'
:
'my_second_promise'
}
self
.
assertEqual
s
(
json
.
loads
(
expected_dict
),
result_dict
)
self
.
assertEqual
(
json
.
loads
(
expected_dict
),
result_dict
)
def
test_runpromise_no_logdir
(
self
):
promise_name
=
'my_promise.py'
...
...
@@ -410,11 +410,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -432,11 +432,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
# no promise log output dir
...
...
@@ -455,11 +455,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
)
...
...
@@ -480,11 +480,11 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
name
in
[
promise_failed
,
promise_name
])
if
result
.
name
==
promise_failed
:
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"failed"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
item
.
message
,
"failed"
)
else
:
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -494,7 +494,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
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_failed_promise.log'
)))
...
...
@@ -508,8 +508,8 @@ class RunPromise(GenericPromise):
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
,
third_promise
])
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -520,7 +520,7 @@ class RunPromise(GenericPromise):
# run promise will not fail
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
assertEqual
(
self
.
counter
,
3
)
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_second_promise.log'
)))
...
...
@@ -537,7 +537,7 @@ class RunPromise(GenericPromise):
# run promise will fail when promise fail (usefull for slapgrid)
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEqual
s
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
# force to reload the module without rerun python
os
.
system
(
'rm %s/*.pyc'
%
self
.
plugin_dir
)
...
...
@@ -562,15 +562,15 @@ class RunPromise(GenericPromise):
def
test_method_first
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
def
test_method_one
(
result
):
self
.
counter
+=
1
self
.
assertEqual
s
(
result
.
name
,
first_promise
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
name
,
first_promise
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
configureLauncher
(
save_method
=
test_method_first
)
# ~2 seconds
...
...
@@ -579,19 +579,19 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.05
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method_one
)
time
.
sleep
(
2
)
self
.
counter
=
0
self
.
launcher
.
run
()
# only my_first_promise will run
self
.
assertEqual
s
(
self
.
counter
,
1
)
self
.
assertEqual
(
self
.
counter
,
1
)
time
.
sleep
(
3
)
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method_first
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
def
test_runpromise_with_periodicity_same
(
self
):
first_promise
=
'my_first_promise.py'
...
...
@@ -600,8 +600,8 @@ class RunPromise(GenericPromise):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -610,19 +610,19 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
s
(
self
.
counter
,
0
)
self
.
assertEqual
(
self
.
counter
,
0
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
def
test_runpromise_with_periodicity_result_failed
(
self
):
first_promise
=
'my_first_promise.py'
...
...
@@ -640,14 +640,14 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEqual
s
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertTrue
(
os
.
path
.
exists
(
first_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertEqual
s
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
s
(
second_result
[
'name'
],
second_promise
)
self
.
assertEqual
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
(
second_result
[
'name'
],
second_promise
)
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
...
@@ -655,19 +655,19 @@ class RunPromise(GenericPromise):
time
.
sleep
(
2
)
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
# only my_first_promise will run but second_promise still failing
self
.
assertEqual
s
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertEqual
s
(
second_result
[
'result'
][
'date'
],
second_date
)
self
.
assertEqual
(
second_result
[
'result'
][
'date'
],
second_date
)
first_date
=
first_result
[
'result'
][
'date'
]
time
.
sleep
(
3
)
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEqual
s
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
...
...
@@ -690,14 +690,14 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEqual
s
(
str
(
exc
.
exception
),
'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
(
second_state_file
))
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertEqual
s
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
s
(
second_result
[
'name'
],
second_promise
)
self
.
assertEqual
(
first_result
[
'name'
],
first_promise
)
self
.
assertEqual
(
second_result
[
'name'
],
second_promise
)
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
...
@@ -705,12 +705,12 @@ class RunPromise(GenericPromise):
time
.
sleep
(
2
)
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
# only my_first_promise will run but second_promise still failing
self
.
assertEqual
s
(
str
(
exc
.
exception
),
'Promise %r failed.'
%
second_promise
)
self
.
assertEqual
(
str
(
exc
.
exception
),
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
self
.
assertNotEquals
(
first_result
[
'result'
][
'date'
],
first_date
)
self
.
assertEqual
s
(
second_result
[
'result'
][
'date'
],
second_date
)
self
.
assertEqual
(
second_result
[
'result'
][
'date'
],
second_date
)
first_date
=
first_result
[
'result'
][
'date'
]
second_date
=
second_result
[
'result'
][
'date'
]
...
...
@@ -735,8 +735,8 @@ class RunPromise(GenericPromise):
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
[
first_promise
,
second_promise
])
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -745,30 +745,30 @@ class RunPromise(GenericPromise):
self
.
generatePromiseScript
(
second_promise
,
success
=
True
,
periodicity
=
0.03
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
s
(
self
.
counter
,
0
)
self
.
assertEqual
(
self
.
counter
,
0
)
self
.
configureLauncher
(
save_method
=
test_method
,
force
=
True
)
self
.
counter
=
0
self
.
launcher
.
run
()
# will run all as force is True
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
self
.
configureLauncher
(
save_method
=
test_method
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
launcher
.
run
()
# run nothing
self
.
assertEqual
s
(
self
.
counter
,
0
)
self
.
assertEqual
(
self
.
counter
,
0
)
time
.
sleep
(
1
)
self
.
counter
=
0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
# after 2 seconds will run all
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
def
test_runpromise_wrapped
(
self
):
promise_name
=
"my_bash_promise"
...
...
@@ -785,11 +785,11 @@ echo "success"
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
!=
0
)
self
.
assertEqual
s
(
result
.
title
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
promise_name
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -813,7 +813,7 @@ exit 1
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_STATE_FOLDER_NAME
)
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEqual
s
(
str
(
exc
.
exception
),
'Promise %r failed.'
%
promise_name
)
self
.
assertEqual
(
str
(
exc
.
exception
),
'Promise %r failed.'
%
promise_name
)
def
test_runpromise_wrapped_mixed
(
self
):
self
.
called
=
0
...
...
@@ -822,12 +822,12 @@ exit 1
self
.
called
+=
1
result_dict
.
pop
(
result
.
name
)
if
result
.
title
==
"first_promise"
or
result
.
title
==
"second_promise"
:
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
if
result
.
title
==
"my_bash_promise"
:
self
.
assertEqual
s
(
result
.
item
.
message
,
"promise 1 succeeded"
)
self
.
assertEqual
(
result
.
item
.
message
,
"promise 1 succeeded"
)
if
result
.
title
==
"my_bash_promise2"
:
self
.
assertEqual
s
(
result
.
item
.
message
,
"promise 2 succeeded"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"promise 2 succeeded"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
promise_name
=
"my_bash_promise"
promise_path
=
os
.
path
.
join
(
self
.
legacy_promise_dir
,
promise_name
)
...
...
@@ -850,7 +850,7 @@ exit 0
self
.
configureLauncher
(
save_method
=
test_method
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
called
,
4
)
self
.
assertEqual
(
self
.
called
,
4
)
def
test_runpromise_run_only
(
self
):
...
...
@@ -861,8 +861,8 @@ exit 0
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -872,14 +872,14 @@ exit 0
# run promise will not fail
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
assertEqual
(
self
.
counter
,
3
)
self
.
counter
=
0
self
.
check_list
=
[
second_promise
]
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
[
second_promise
],
force
=
True
)
time
.
sleep
(
1
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
1
)
self
.
assertEqual
(
self
.
counter
,
1
)
def
test_runpromise_run_only_multiple
(
self
):
first_promise
=
'my_first_promise.py'
...
...
@@ -889,8 +889,8 @@ exit 0
self
.
check_list
=
[
first_promise
,
second_promise
,
third_promise
]
def
test_method
(
result
):
self
.
assertTrue
(
result
.
name
in
self
.
check_list
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
counter
+=
1
self
.
configureLauncher
(
save_method
=
test_method
)
...
...
@@ -900,14 +900,14 @@ exit 0
# run promise will not fail
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
3
)
self
.
assertEqual
(
self
.
counter
,
3
)
self
.
counter
=
0
self
.
check_list
=
[
third_promise
,
second_promise
]
self
.
configureLauncher
(
save_method
=
test_method
,
run_list
=
self
.
check_list
,
force
=
True
)
time
.
sleep
(
1
)
self
.
launcher
.
run
()
self
.
assertEqual
s
(
self
.
counter
,
2
)
self
.
assertEqual
(
self
.
counter
,
2
)
def
writeLatestPromiseResult
(
self
):
state_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_RESULT_FOLDER_NAME
,
'my_promise.status.json'
)
...
...
@@ -962,10 +962,10 @@ exit 0
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
configureLauncher
(
save_method
=
test_method
,
enable_anomaly
=
True
,
timeout
=
1
)
self
.
generatePromiseScript
(
promise_name
,
success
=
True
,
content
=
"""import time
...
...
@@ -993,11 +993,11 @@ echo "success"
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertTrue
(
result
.
execution_time
>=
1
)
self
.
assertEqual
s
(
result
.
title
,
promise_name
)
self
.
assertEqual
s
(
result
.
name
,
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
promise_path
)
self
.
assertEqual
(
result
.
title
,
promise_name
)
self
.
assertEqual
(
result
.
name
,
promise_name
)
self
.
assertEqual
(
result
.
path
,
promise_path
)
self
.
assertTrue
(
"Promise timed out after"
in
result
.
item
.
message
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
self
.
configureLauncher
(
save_method
=
test_method
,
timeout
=
1
)
...
...
@@ -1105,16 +1105,16 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise_process
=
self
.
createPromiseProcess
()
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
self
.
assertEqual
s
(
promise
.
getPeriodicity
(),
1
)
self
.
assertEqual
s
(
promise
.
getName
(),
self
.
promise_name
)
self
.
assertEqual
s
(
promise
.
getTitle
(),
'my_promise'
)
self
.
assertEqual
s
(
promise
.
getPartitionFolder
(),
self
.
partition_dir
)
self
.
assertEqual
s
(
promise
.
getPromiseFile
(),
self
.
promise_path
)
self
.
assertEqual
s
(
promise
.
getLogFolder
(),
self
.
log_dir
)
self
.
assertEqual
s
(
promise
.
getLogFile
(),
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
))
self
.
assertEqual
(
promise
.
getPeriodicity
(),
1
)
self
.
assertEqual
(
promise
.
getName
(),
self
.
promise_name
)
self
.
assertEqual
(
promise
.
getTitle
(),
'my_promise'
)
self
.
assertEqual
(
promise
.
getPartitionFolder
(),
self
.
partition_dir
)
self
.
assertEqual
(
promise
.
getPromiseFile
(),
self
.
promise_path
)
self
.
assertEqual
(
promise
.
getLogFolder
(),
self
.
log_dir
)
self
.
assertEqual
(
promise
.
getLogFile
(),
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
))
promise
.
setPeriodicity
(
2
)
self
.
assertEqual
s
(
promise
.
getPeriodicity
(),
2
)
self
.
assertEqual
(
promise
.
getPeriodicity
(),
2
)
with
self
.
assertRaises
(
ValueError
):
promise
.
setPeriodicity
(
0
)
...
...
@@ -1122,11 +1122,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
AnomalyResult
))
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
def
test_promise_anomaly_disabled
(
self
):
...
...
@@ -1139,11 +1139,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertTrue
(
isinstance
(
result
,
PromiseQueueResult
))
self
.
assertTrue
(
isinstance
(
result
.
item
,
TestResult
))
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
s
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
path
,
os
.
path
.
join
(
self
.
plugin_dir
,
self
.
promise_name
))
self
.
assertEqual
(
result
.
item
.
message
,
"success"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertTrue
(
isinstance
(
result
.
item
.
date
,
datetime
))
def
test_promise_with_raise
(
self
):
...
...
@@ -1156,10 +1156,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
promise
.
run
()
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"Bad Promise raised"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
item
.
message
,
"Bad Promise raised"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
True
)
def
test_promise_no_return
(
self
):
promise_content
=
"return"
...
...
@@ -1171,10 +1171,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
promise
.
run
()
result
=
self
.
queue
.
get
(
True
,
1
)
self
.
assertEqual
s
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
s
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
s
(
result
.
item
.
message
,
"No result found!"
)
self
.
assertEqual
s
(
result
.
item
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
title
,
'my_promise'
)
self
.
assertEqual
(
result
.
name
,
self
.
promise_name
)
self
.
assertEqual
(
result
.
item
.
message
,
"No result found!"
)
self
.
assertEqual
(
result
.
item
.
hasFailed
(),
False
)
def
test_promise_resultfromlog
(
self
):
promise_content
=
"self.logger.info('Promise is running...')"
...
...
@@ -1188,11 +1188,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
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'
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
...
@@ -1208,12 +1208,12 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
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'
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'ERROR'
,
'message'
:
'Promise is running...
\
n
message in new line'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
...
@@ -1227,17 +1227,17 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
date
=
datetime
.
now
()
promise
.
sense
()
self
.
assertEqual
s
(
promise
.
getLogFolder
(),
None
)
self
.
assertEqual
s
(
promise
.
getLogFile
(),
None
)
self
.
assertEqual
(
promise
.
getLogFolder
(),
None
)
self
.
assertEqual
(
promise
.
getLogFile
(),
None
)
# get all messages during the latest minute
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'
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
latest_message_list
[
0
][
0
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'Promise is running...'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
date
,
'status'
:
'INFO'
,
'message'
:
'success'
})
...
...
@@ -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'
)
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'
)
self
.
assertEqual
s
(
len
(
latest_message_list
),
10
)
self
.
assertEqual
(
len
(
latest_message_list
),
10
)
for
message
in
latest_message_list
:
self
.
assertEqual
s
(
len
(
message
),
1
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
message
),
1
)
self
.
assertEqual
(
latest_message_list
[
0
][
0
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 49'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 40'
})
...
...
@@ -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
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
# there is 2 result line per minutes
self
.
assertEqual
s
(
len
(
latest_message_list
),
10
)
self
.
assertEqual
(
len
(
latest_message_list
),
10
)
for
message
in
latest_message_list
:
self
.
assertEqual
s
(
len
(
message
),
2
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
message
),
2
)
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 19'
})
...
...
@@ -1353,11 +1353,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
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'
)
# there is 2 result line per minutes
self
.
assertEqual
s
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
latest_message_list
),
1
)
self
.
assertEqual
(
latest_message_list
[
0
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 1'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
...
...
@@ -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
=
datetime
.
strptime
(
end_date_string
,
'%Y-%m-%d %H:%M:%S'
)
# there is 2 result line per minutes
self
.
assertEqual
s
(
len
(
latest_message_list
),
2
)
self
.
assertEqual
(
len
(
latest_message_list
),
2
)
for
message
in
latest_message_list
:
self
.
assertEqual
s
(
len
(
message
),
2
)
self
.
assertEqual
s
(
self
.
assertEqual
(
len
(
message
),
2
)
self
.
assertEqual
(
latest_message_list
[
0
][
1
],
{
'date'
:
start_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 0'
})
self
.
assertEqual
s
(
self
.
assertEqual
(
latest_message_list
[
-
1
][
0
],
{
'date'
:
end_date
,
'status'
:
'INFO'
,
'message'
:
'Promise result 3'
})
latest_message_list
=
promise
.
getLastPromiseResultList
(
result_count
=
100
)
# all results
self
.
assertEqual
s
(
len
(
latest_message_list
),
25
)
self
.
assertEqual
(
len
(
latest_message_list
),
25
)
def
test_promise_defaulttest
(
self
):
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
...
...
@@ -1420,8 +1420,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
s
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
def
test_promise_defaulttest_failure
(
self
):
self
.
initialisePromise
(
success
=
False
)
...
...
@@ -1433,8 +1433,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
def
test_promise_defaulttest_error_if_two_fail
(
self
):
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
...
...
@@ -1447,8 +1447,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# fail if 2 errors found
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertTrue
(
isinstance
(
result
,
TestResult
))
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
promise_process
=
self
.
createPromiseProcess
()
...
...
@@ -1456,8 +1456,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
.
sense
()
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
# will continue to fail
self
.
initialisePromise
(
success
=
False
,
timeout
=
1
)
...
...
@@ -1466,8 +1466,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise
=
promise_module
.
RunPromise
(
self
.
promise_config
)
promise
.
sense
()
result
=
promise
.
_test
(
result_count
=
2
,
failure_amount
=
2
)
self
.
assertEqual
s
(
result
.
message
,
'failed'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
True
)
self
.
assertEqual
(
result
.
message
,
'failed'
)
self
.
assertEqual
(
result
.
hasFailed
(),
True
)
def
test_promise_defaulttest_anomaly
(
self
):
promise_content
=
'self.logger.info("Promise is running...
\
\
nmessage in new line")'
...
...
@@ -1480,8 +1480,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result
=
promise
.
_anomaly
(
result_count
=
1
,
failure_amount
=
1
)
self
.
assertTrue
(
isinstance
(
result
,
AnomalyResult
))
self
.
assertEqual
s
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
s
(
result
.
hasFailed
(),
False
)
self
.
assertEqual
(
result
.
message
,
'Promise is running...
\
n
message in new line
\
n
success'
)
self
.
assertEqual
(
result
.
hasFailed
(),
False
)
if
__name__
==
'__main__'
:
...
...
slapos/tests/slap.py
View file @
146f0e0d
...
...
@@ -30,7 +30,7 @@ from __future__ import print_function
import
logging
import
os
import
unittest
import
url
parse
from
six.moves.urllib
import
parse
import
tempfile
import
httmock
...
...
@@ -187,7 +187,7 @@ class TestSlap(SlapMixin):
self
.
slap
.
registerComputer
(
computer_guid
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
qs
==
{
'computer_reference'
:
[
computer_guid
],
...
...
@@ -228,7 +228,7 @@ class TestSlap(SlapMixin):
partition_id
=
'PARTITION_01'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
qs
==
{
'computer_reference'
:
[
computer_guid
],
...
...
@@ -320,7 +320,7 @@ class TestSlap(SlapMixin):
software_release_url_list
=
[
'1'
,
'2'
]
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getSoftwareReleaseListFromSoftwareProduct'
and
qs
==
{
'software_product_reference'
:
[
software_product_reference
]}):
return
{
...
...
@@ -346,7 +346,7 @@ class TestSlap(SlapMixin):
software_release_url_list
=
[
'1'
,
'2'
]
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getSoftwareReleaseListFromSoftwareProduct'
and
qs
==
{
'software_release_url'
:
[
software_release_url
]}):
return
{
...
...
@@ -387,7 +387,7 @@ class TestSlap(SlapMixin):
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
return
{
'status_code'
:
200
,
...
...
@@ -408,7 +408,7 @@ class TestSlap(SlapMixin):
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
self
.
fail
(
'slap should not have contacted master to get Hateoas URL.'
)
...
...
@@ -426,7 +426,7 @@ class TestSlap(SlapMixin):
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
return
{
'status_code'
:
404
,
...
...
@@ -452,7 +452,7 @@ class TestComputer(SlapMixin):
slap
.
initializeConnection
(
self
.
server_url
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -522,7 +522,7 @@ class TestComputer(SlapMixin):
self
.
slap
.
initializeConnection
(
self
.
server_url
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
qs
==
{
'computer_reference'
:
[
self
.
computer_guid
],
...
...
@@ -604,7 +604,7 @@ class TestComputerPartition(SlapMixin):
partition_id
=
'PARTITION_01'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -649,7 +649,7 @@ class TestComputerPartition(SlapMixin):
partition_id
=
'PARTITION_01'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -693,7 +693,7 @@ class TestComputerPartition(SlapMixin):
partition_id
=
'PARTITION_01'
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -742,7 +742,7 @@ class TestComputerPartition(SlapMixin):
computer_guid
=
self
.
_getTestComputerId
()
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -803,7 +803,7 @@ class TestComputerPartition(SlapMixin):
transaction_file_path
=
os
.
path
.
join
(
partition_root
,
transaction_file_name
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
'computer_reference'
in
qs
and
'computer_partition_reference'
in
qs
):
...
...
@@ -881,7 +881,7 @@ class TestComputerPartition(SlapMixin):
slap
.
initializeConnection
(
self
.
server_url
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
qs
[
'computer_reference'
][
0
]
==
computer_guid
and
qs
[
'computer_partition_reference'
][
0
]
==
partition_id
):
...
...
@@ -925,7 +925,7 @@ class TestComputerPartition(SlapMixin):
slap
.
initializeConnection
(
self
.
server_url
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/registerComputerPartition'
and
qs
[
'computer_reference'
][
0
]
==
computer_guid
and
qs
[
'computer_partition_reference'
][
0
]
==
partition_id
):
...
...
@@ -936,7 +936,7 @@ class TestComputerPartition(SlapMixin):
'content'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
partition
)
}
elif
url
.
path
==
'/softwareInstanceError'
:
parsed_qs_body
=
url
parse
.
parse_qs
(
req
.
body
)
parsed_qs_body
=
parse
.
parse_qs
(
req
.
body
)
# XXX: why do we have computer_id and not computer_reference?
# XXX: why do we have computer_partition_id and not
# computer_partition_reference?
...
...
@@ -997,7 +997,7 @@ class TestSoftwareRelease(SlapMixin):
slap
.
initializeConnection
(
self
.
server_url
)
def
handler
(
url
,
req
):
qs
=
url
parse
.
parse_qs
(
req
.
body
)
qs
=
parse
.
parse_qs
(
req
.
body
)
if
(
url
.
path
==
'/softwareReleaseError'
and
qs
[
'computer_id'
][
0
]
==
computer_guid
and
qs
[
'url'
][
0
]
==
software_release_uri
and
...
...
slapos/tests/util.py
View file @
146f0e0d
...
...
@@ -109,23 +109,14 @@ class TestUtil(unittest.TestCase):
shutil
.
rmtree
(
root_slaptest
)
def
test_string_to_boolean_with_true_values
(
self
):
"""
Check that mkdir_p doesn't raise if directory already exist.
"""
for
value
in
[
'true'
,
'True'
,
'TRUE'
]:
self
.
assertTrue
(
string_to_boolean
(
value
))
def
test_string_to_boolean_with_false_values
(
self
):
"""
Check that mkdir_p doesn't raise if directory already exist.
"""
for
value
in
[
'false'
,
'False'
,
'False'
]:
self
.
assertFalse
(
string_to_boolean
(
value
))
def
test_string_to_boolean_with_incorrect_values
(
self
):
"""
Check that mkdir_p doesn't raise if directory already exist.
"""
for
value
in
[
True
,
False
,
1
,
'1'
,
't'
,
'tru'
,
'truelle'
,
'f'
,
'fals'
,
'falsey'
]:
self
.
assertRaises
(
ValueError
,
string_to_boolean
,
value
)
...
...
slapos/util.py
View file @
146f0e0d
...
...
@@ -31,7 +31,6 @@ import errno
import
os
import
subprocess
import
sqlite3
import
six
def
mkdir_p
(
path
,
mode
=
0o700
):
...
...
@@ -85,16 +84,11 @@ def string_to_boolean(string):
The parser is completely arbitrary, see code for actual implementation.
"""
if
not
isinstance
(
string
,
six
.
binary_type
)
and
not
isinstance
(
string
,
six
.
text_type
):
raise
ValueError
(
'Given value is not a string.'
)
acceptable_true_values
=
[
'true'
]
acceptable_false_values
=
[
'false'
]
string
=
string
.
lower
()
if
string
in
acceptable_true_values
:
return
True
if
string
in
acceptable_false_values
:
return
False
else
:
if
isinstance
(
string
,
bytes
):
string
=
string
.
decode
(
'utf-8'
)
try
:
return
(
'false'
,
'true'
).
index
(
string
.
lower
())
except
Exception
:
raise
ValueError
(
'%s is neither True nor False.'
%
string
)
...
...
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