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
16
Merge Requests
16
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
b7ddce31
Commit
b7ddce31
authored
Oct 22, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
b78ac34d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
40 deletions
+37
-40
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+2
-2
slapos/grid/utils.py
slapos/grid/utils.py
+1
-1
slapos/manager/portredir.py
slapos/manager/portredir.py
+2
-2
slapos/manager/prerm.py
slapos/manager/prerm.py
+2
-3
slapos/proxy/views.py
slapos/proxy/views.py
+1
-1
slapos/tests/collect.py
slapos/tests/collect.py
+1
-1
slapos/tests/promise.py
slapos/tests/promise.py
+26
-29
slapos/util.py
slapos/util.py
+2
-1
No files found.
slapos/grid/promise/__init__.py
View file @
b7ddce31
...
...
@@ -184,8 +184,8 @@ class PromiseProcess(Process):
raise
AttributeError
(
"Class RunPromise not found in promise"
\
"%s"
%
self
.
name
)
if
not
interface
.
IPromise
.
implementedBy
(
promise_module
.
RunPromise
):
raise
RuntimeError
(
"RunPromise class in %s must implement
s
'IPromise'"
\
" interface.
zope_interface.implements
(interface.IPromise) is"
\
raise
RuntimeError
(
"RunPromise class in %s must implement 'IPromise'"
\
" interface.
@implementer
(interface.IPromise) is"
\
" missing ?"
%
self
.
name
)
from
slapos.grid.promise.generic
import
GenericPromise
...
...
slapos/grid/utils.py
View file @
b7ddce31
...
...
@@ -353,7 +353,7 @@ def updateFile(file_path, content, mode=0o600):
"""Creates or updates a file with "content" as content."""
altered
=
False
if
not
(
os
.
path
.
isfile
(
file_path
))
or
\
not
(
hashlib
.
md5
(
open
(
file_path
).
read
()).
digest
()
==
not
(
hashlib
.
md5
(
open
(
file_path
,
'rb'
).
read
()).
digest
()
==
hashlib
.
md5
(
content
).
digest
()):
with
open
(
file_path
,
'w'
)
as
fout
:
fout
.
write
(
content
)
...
...
slapos/manager/portredir.py
View file @
b7ddce31
...
...
@@ -5,7 +5,7 @@ import netaddr
import
os
from
.interface
import
IManager
from
itertools
import
i
filter
from
six.moves
import
filter
from
zope
import
interface
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -88,7 +88,7 @@ class Manager(object):
'full_ip_list'
,
[])
partition_ip_list
=
[
tup
[
1
]
for
tup
in
partition_ip_list
]
partition_ipv6
=
next
(
i
filter
(
lambda
ip_addr
:
':'
in
ip_addr
,
partition_ipv6
=
next
(
filter
(
lambda
ip_addr
:
':'
in
ip_addr
,
partition_ip_list
),
None
)
...
...
slapos/manager/prerm.py
View file @
b7ddce31
...
...
@@ -4,17 +4,16 @@ import os
import
sys
import
subprocess
from
zope
import
interface
as
zope_interface
from
zope
.interface
import
implementer
from
slapos.manager
import
interface
from
slapos.grid.slapgrid
import
COMPUTER_PARTITION_WAIT_LIST_FILENAME
logger
=
logging
.
getLogger
(
__name__
)
@
implementer
(
interface
.
IManager
)
class
Manager
(
object
):
"""Manager is called in every step of preparation of the computer."""
zope_interface
.
implements
(
interface
.
IManager
)
def
__init__
(
self
,
config
):
"""Manager needs to know config for its functioning.
"""
...
...
slapos/proxy/views.py
View file @
b7ddce31
...
...
@@ -359,7 +359,7 @@ def requestComputerPartition():
if
slave
:
# XXX: change schema to include a simple "partition_reference" which
# is name of the instance. Then, no need to do complex search here.
slave_reference
=
parsed_request_dict
[
'partition_id'
]
+
'_'
+
parsed_request_dict
[
'partition_reference'
]
slave_reference
=
parsed_request_dict
[
'partition_id'
]
+
b
'_'
+
parsed_request_dict
[
'partition_reference'
]
requested_computer_id
=
parsed_request_dict
[
'filter_kw'
].
get
(
'computer_guid'
,
app
.
config
[
'computer_id'
])
matching_partition
=
getAllocatedSlaveInstance
(
slave_reference
,
requested_computer_id
)
else
:
...
...
slapos/tests/collect.py
View file @
b7ddce31
...
...
@@ -36,7 +36,7 @@ import psutil
from
time
import
strftime
from
slapos.collect
import
entity
,
snapshot
,
db
,
reporter
from
slapos.cli.entry
import
SlapOSApp
from
ConfigP
arser
import
ConfigParser
from
six.moves.configp
arser
import
ConfigParser
class
FakeDatabase
(
object
):
def
__init__
(
self
):
...
...
slapos/tests/promise.py
View file @
b7ddce31
...
...
@@ -34,8 +34,8 @@ import json
import
random
import
logging
from
datetime
import
datetime
,
timedelta
import
Queue
from
zope
import
interface
as
zope_interfac
e
import
six
from
six.moves
import
queu
e
from
slapos.grid.promise
import
interface
,
PromiseLauncher
,
PromiseProcess
,
PromiseError
from
slapos.grid.promise.generic
import
(
GenericPromise
,
TestResult
,
AnomalyResult
,
PromiseQueueResult
,
PROMISE_STATE_FOLDER_NAME
,
...
...
@@ -111,7 +111,7 @@ class TestSlapOSPromiseMixin(unittest.TestCase):
'debug'
:
False
,
'name'
:
promise_name
,
'path'
:
os
.
path
.
join
(
self
.
plugin_dir
,
promise_name
),
'queue'
:
Q
ueue
.
Queue
(),
'queue'
:
q
ueue
.
Queue
(),
}
def
createPromiseProcess
(
self
,
promise_name
,
check_anomaly
=
False
,
wrap
=
False
):
...
...
@@ -135,14 +135,13 @@ class TestSlapOSPromiseMixin(unittest.TestCase):
def
generatePromiseScript
(
self
,
name
,
success
=
True
,
failure_count
=
1
,
content
=
""
,
periodicity
=
0.03
):
promise_content
=
"""from zope
import interface as zope_interface
promise_content
=
"""from zope
.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise import GenericPromise
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
GenericPromise.__init__(self, config)
self.setPeriodicity(minute=%(periodicity)s)
...
...
@@ -186,7 +185,9 @@ class TestSlapOSPromiseLauncher(TestSlapOSPromiseMixin):
with
self
.
assertRaises
(
ImportError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEquals
(
exc
.
exception
.
message
,
'No module named my_promise_no_py'
)
self
.
assertEquals
(
str
(
exc
.
exception
),
'No module named %s'
%
(
"'%s'"
%
promise_name
if
six
.
PY3
else
promise_name
))
def
test_promise_match_interface_no_implement
(
self
):
promise_name
=
'my_promise_noimplement.py'
...
...
@@ -208,19 +209,18 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
RuntimeError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
message
=
"RunPromise class in my_promise_noimplement.py must implement
s
"
\
" 'IPromise' interface.
zope_interface.implements
(interface.IPromise) is missing ?"
self
.
assertEquals
(
exc
.
exception
.
message
,
message
)
message
=
"RunPromise class in my_promise_noimplement.py must implement"
\
" 'IPromise' interface.
@implementer
(interface.IPromise) is missing ?"
self
.
assertEquals
(
str
(
exc
.
exception
)
,
message
)
def
test_promise_match_interface_no_generic
(
self
):
promise_name
=
'my_promise_nogeneric.py'
promise_content
=
"""from zope
import interface as zope_interface
promise_content
=
"""from zope
.interface import implementer
from slapos.grid.promise import interface
@implementer(interface.IPromise)
class RunPromise(object):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
pass
...
...
@@ -236,18 +236,17 @@ class RunPromise(object):
with
self
.
assertRaises
(
RuntimeError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEquals
(
exc
.
exception
.
message
,
'RunPromise class is not a subclass of GenericPromise class.'
)
self
.
assertEquals
(
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'
promise_content
=
"""from zope
import interface as zope_interface
promise_content
=
"""from zope
.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise import GenericPromise
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
pass
...
...
@@ -263,23 +262,22 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
TypeError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
promise
=
promise_module
.
RunPromise
({})
self
.
assertEquals
(
exc
.
exception
.
message
,
self
.
assertEquals
(
str
(
exc
.
exception
)
,
"Can't instantiate abstract class RunPromise with abstract methods sense"
)
def
test_promise_extra_config
(
self
):
promise_name
=
'my_promise_extra.py'
config_dict
=
{
'foo'
:
'bar'
,
'my-config'
:
4522111
,
'text'
:
'developers
\
n
information, sample
\
n
\
n
er'
}
promise_content
=
"""from zope
import interface as zope_interface
promise_content
=
"""from zope
.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise import GenericPromise
%(config_name)s = %(config_content)s
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def sense(self):
pass
...
...
@@ -299,16 +297,15 @@ class RunPromise(GenericPromise):
def
test_promise_extra_config_reserved_name
(
self
):
promise_name
=
'my_promise_extra.py'
config_dict
=
{
'name'
:
'bar'
,
'my-config'
:
4522111
}
promise_content
=
"""from zope
import interface as zope_interface
promise_content
=
"""from zope
.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise import GenericPromise
%(config_name)s = %(config_content)s
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def sense(self):
pass
...
...
@@ -321,7 +318,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
ValueError
)
as
exc
:
promise_module
=
promise_process
.
_loadPromiseModule
()
self
.
assertEquals
(
exc
.
exception
.
message
,
"Extra parameter name 'name' cannot be used.
\
n
%s"
%
config_dict
)
self
.
assertEquals
(
str
(
exc
.
exception
)
,
"Extra parameter name 'name' cannot be used.
\
n
%s"
%
config_dict
)
def
test_runpromise
(
self
):
promise_name
=
'my_promise.py'
...
...
@@ -693,7 +690,7 @@ class RunPromise(GenericPromise):
with
self
.
assertRaises
(
PromiseError
)
as
exc
:
self
.
launcher
.
run
()
self
.
assertEquals
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEquals
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
self
.
assertTrue
(
os
.
path
.
exists
(
first_state_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
second_state_file
))
...
...
@@ -708,7 +705,7 @@ 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
.
assertEquals
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
second_promise
)
self
.
assertEquals
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
second_promise
)
first_result
=
json
.
load
(
open
(
first_state_file
))
second_result
=
json
.
load
(
open
(
second_state_file
))
...
...
@@ -816,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
.
assertEquals
(
exc
.
exception
.
message
,
'Promise %r failed.'
%
promise_name
)
self
.
assertEquals
(
str
(
exc
.
exception
)
,
'Promise %r failed.'
%
promise_name
)
def
test_runpromise_wrapped_mixed
(
self
):
self
.
called
=
0
...
...
@@ -1073,7 +1070,7 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
self
.
configureLauncher
()
self
.
generatePromiseScript
(
self
.
promise_name
,
periodicity
=
1
,
content
=
promise_content
,
success
=
success
)
self
.
writeInit
()
self
.
queue
=
Q
ueue
.
Queue
()
self
.
queue
=
q
ueue
.
Queue
()
self
.
promise_config
=
{
'log-folder'
:
self
.
log_dir
,
'partition-folder'
:
self
.
partition_dir
,
...
...
slapos/util.py
View file @
b7ddce31
...
...
@@ -31,6 +31,7 @@ import errno
import
os
import
subprocess
import
sqlite3
import
six
def
mkdir_p
(
path
,
mode
=
0o700
):
...
...
@@ -84,7 +85,7 @@ def string_to_boolean(string):
The parser is completely arbitrary, see code for actual implementation.
"""
if
not
isinstance
(
string
,
s
tr
)
and
not
isinstance
(
string
,
unicod
e
):
if
not
isinstance
(
string
,
s
ix
.
binary_type
)
and
not
isinstance
(
string
,
six
.
text_typ
e
):
raise
ValueError
(
'Given value is not a string.'
)
acceptable_true_values
=
[
'true'
]
acceptable_false_values
=
[
'false'
]
...
...
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