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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
3a98bda4
Commit
3a98bda4
authored
Jan 22, 2025
by
Romain Courteaud
🐙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: revert everything!!!
parent
447d3da4
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
518 additions
and
5823 deletions
+518
-5823
slapos/cli/entry.py
slapos/cli/entry.py
+2
-2
slapos/cli/register.py
slapos/cli/register.py
+6
-23
slapos/cli/request.py
slapos/cli/request.py
+10
-38
slapos/cli/supply.py
slapos/cli/supply.py
+6
-19
slapos/format.py
slapos/format.py
+11
-50
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+18
-52
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+109
-303
slapos/grid/templates/buildout-tail.cfg.in
slapos/grid/templates/buildout-tail.cfg.in
+0
-9
slapos/grid/watchdog.py
slapos/grid/watchdog.py
+6
-26
slapos/manager/portredir.py
slapos/manager/portredir.py
+2
-1
slapos/slap/hateoas.py
slapos/slap/hateoas.py
+20
-51
slapos/slap/slap.py
slapos/slap/slap.py
+2
-3
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+0
-1
slapos/tests/test_object.py
slapos/tests/test_object.py
+6
-13
slapos/tests/test_slapformat.py
slapos/tests/test_slapformat.py
+0
-78
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+320
-584
slapos/tests/test_slapgrid_slaptool.py
slapos/tests/test_slapgrid_slaptool.py
+0
-4570
No files found.
slapos/cli/entry.py
View file @
3a98bda4
...
@@ -111,11 +111,11 @@ class SlapOSHelpAction(argparse.Action):
...
@@ -111,11 +111,11 @@ class SlapOSHelpAction(argparse.Action):
try
:
try
:
factory
=
ep
.
load
()
factory
=
ep
.
load
()
except
Exception
as
err
:
except
Exception
as
err
:
r
aise
r
eturn
'Could not load %r
\
n
'
%
ep
try
:
try
:
cmd
=
factory
(
self
,
None
)
cmd
=
factory
(
self
,
None
)
except
Exception
as
err
:
except
Exception
as
err
:
r
aise
r
eturn
'Could not instantiate %r: %s
\
n
'
%
(
ep
,
err
)
one_liner
=
cmd
.
get_description
().
split
(
'
\
n
'
)[
0
]
one_liner
=
cmd
.
get_description
().
split
(
'
\
n
'
)[
0
]
group
=
getattr
(
factory
,
'command_group'
,
'other'
)
group
=
getattr
(
factory
,
'command_group'
,
'other'
)
return
group
,
' %-13s %s
\
n
'
%
(
name
,
one_liner
)
return
group
,
' %-13s %s
\
n
'
%
(
name
,
one_liner
)
...
...
slapos/cli/register.py
View file @
3a98bda4
...
@@ -59,8 +59,6 @@ class RegisterCommand(Command):
...
@@ -59,8 +59,6 @@ class RegisterCommand(Command):
ap
=
super
(
RegisterCommand
,
self
).
get_parser
(
prog_name
)
ap
=
super
(
RegisterCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'node_name'
,
ap
.
add_argument
(
'node_name'
,
default
=
''
,
nargs
=
'?'
,
help
=
'Chosen title for the node'
)
help
=
'Chosen title for the node'
)
ap
.
add_argument
(
'--interface-name'
,
ap
.
add_argument
(
'--interface-name'
,
...
@@ -150,19 +148,6 @@ def get_certificate_key_pair(logger, master_url_web, node_name, token=None, logi
...
@@ -150,19 +148,6 @@ def get_certificate_key_pair(logger, master_url_web, node_name, token=None, logi
"""Download certificates from SlapOS Master"""
"""Download certificates from SlapOS Master"""
if
token
:
if
token
:
if
token
.
startswith
(
"V2/"
):
_
,
compute_node_id
,
token
=
token
.
split
(
"/"
)
data
=
{}
if
node_name
:
data
=
{
'title'
:
node_name
}
req
=
requests
.
post
(
'/'
.
join
([
master_url_web
.
strip
(
"/"
),
'compute_node_module/%s/ComputeNode_approveComputer'
%
compute_node_id
]),
data
=
data
,
headers
=
{
'X-Access-Token'
:
token
},
verify
=
False
)
else
:
req
=
requests
.
post
(
'/'
.
join
([
master_url_web
,
'Person_requestComputer'
]),
req
=
requests
.
post
(
'/'
.
join
([
master_url_web
,
'Person_requestComputer'
]),
data
=
{
'title'
:
node_name
},
data
=
{
'title'
:
node_name
},
headers
=
{
'X-Access-Token'
:
token
},
headers
=
{
'X-Access-Token'
:
token
},
...
@@ -349,7 +334,7 @@ def gen_auth(conf):
...
@@ -349,7 +334,7 @@ def gen_auth(conf):
def
do_register
(
conf
):
def
do_register
(
conf
):
"""Register new computer on SlapOS Master and generate slapos.cfg"""
"""Register new computer on SlapOS Master and generate slapos.cfg"""
if
conf
.
login
or
conf
.
login_auth
and
conf
.
node_name
:
if
conf
.
login
or
conf
.
login_auth
:
for
login
,
password
in
gen_auth
(
conf
):
for
login
,
password
in
gen_auth
(
conf
):
if
check_credentials
(
conf
.
master_url_web
,
login
,
password
):
if
check_credentials
(
conf
.
master_url_web
,
login
,
password
):
break
break
...
@@ -365,9 +350,7 @@ def do_register(conf):
...
@@ -365,9 +350,7 @@ def do_register(conf):
else
:
else
:
while
not
conf
.
token
:
while
not
conf
.
token
:
conf
.
token
=
input
(
'Computer security token: '
).
strip
()
conf
.
token
=
input
(
'Computer security token: '
).
strip
()
if
not
conf
.
token
.
startswith
(
"V2/"
)
and
not
conf
.
node_name
:
while
not
conf
.
node_name
:
conf
.
node_name
=
input
(
'Computer Name: '
).
strip
()
certificate
,
key
=
get_certificate_key_pair
(
conf
.
logger
,
certificate
,
key
=
get_certificate_key_pair
(
conf
.
logger
,
conf
.
master_url_web
,
conf
.
master_url_web
,
conf
.
node_name
,
conf
.
node_name
,
...
...
slapos/cli/request.py
View file @
3a98bda4
...
@@ -161,31 +161,6 @@ def do_request(logger, conf, local):
...
@@ -161,31 +161,6 @@ def do_request(logger, conf, local):
else
:
else
:
parameters
=
conf
.
parameters
parameters
=
conf
.
parameters
try
:
try
:
if
local
[
'slap'
].
jio_api_connector
:
request_dict
=
{
"title"
:
conf
.
reference
,
"portal_type"
:
"Software Instance"
,
"software_release_uri"
:
conf
.
software_url
,
}
if
conf
.
state
:
request_dict
[
'state'
]
=
conf
.
state
if
conf
.
slave
:
request_dict
[
"shared"
]
=
True
if
conf
.
node
:
request_dict
[
"sla_parameters"
]
=
conf
.
node
if
conf
.
parameters
:
request_dict
[
"parameters"
]
=
json
.
dumps
(
conf
.
parameters
)
if
conf
.
type
:
request_dict
[
"software_type"
]
=
conf
.
type
partition_dict
=
local
[
'slap'
].
jio_api_connector
.
post
(
request_dict
)
if
"$schema"
in
partition_dict
and
"error-response-schema.json"
in
partition_dict
[
"$schema"
]:
logger
.
warning
(
'Server Response: %s'
%
json
.
dumps
(
partition_dict
,
indent
=
2
))
logger
.
warning
(
'Instance requested. Master is provisioning it. Please rerun in a '
'couple of minutes to get connection information.'
)
exit
(
2
)
instance_state
=
partition_dict
[
"state"
]
connection_parameter_dict
=
partition_dict
[
"connection_parameters"
]
else
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
conf
.
software_url
,
software_release
=
conf
.
software_url
,
partition_reference
=
conf
.
reference
,
partition_reference
=
conf
.
reference
,
...
@@ -195,10 +170,7 @@ def do_request(logger, conf, local):
...
@@ -195,10 +170,7 @@ def do_request(logger, conf, local):
state
=
conf
.
state
,
state
=
conf
.
state
,
shared
=
conf
.
slave
shared
=
conf
.
slave
)
)
instance_state
=
partition
.
getState
()
logger
.
info
(
'Instance requested.
\
n
State is : %s.'
,
partition
.
getState
())
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
logger
.
info
(
'Instance requested.
\
n
State is : %s.'
,
instance_state
)
logger
.
info
(
'Connection parameters of instance are:'
)
logger
.
info
(
'Connection parameters of instance are:'
)
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
if
software_schema
.
getSerialisation
()
==
SoftwareReleaseSerialisation
.
JsonInXml
:
if
software_schema
.
getSerialisation
()
==
SoftwareReleaseSerialisation
.
JsonInXml
:
...
...
slapos/cli/supply.py
View file @
3a98bda4
...
@@ -27,8 +27,6 @@
...
@@ -27,8 +27,6 @@
#
#
##############################################################################
##############################################################################
import
json
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
init
,
ClientConfig
,
_getSoftwareReleaseFromSoftwareString
from
slapos.client
import
init
,
ClientConfig
,
_getSoftwareReleaseFromSoftwareString
...
@@ -65,18 +63,7 @@ def do_supply(logger, software_release, computer_id, local):
...
@@ -65,18 +63,7 @@ def do_supply(logger, software_release, computer_id, local):
software_release
=
_getSoftwareReleaseFromSoftwareString
(
software_release
=
_getSoftwareReleaseFromSoftwareString
(
logger
,
software_release
,
local
[
'product'
])
logger
,
software_release
,
local
[
'product'
])
if
local
[
'slap'
].
jio_api_connector
:
software_installation
=
local
[
'slap'
].
jio_api_connector
.
post
({
"portal_type"
:
"Software Installation"
,
"software_release_uri"
:
software_release
,
"compute_node_id"
:
computer_id
,
"state"
:
'available'
})
if
"$schema"
in
software_installation
and
"error-response-schema.json"
in
software_installation
[
"$schema"
]:
logger
.
warning
(
'Issue during the request. Server Response: %s'
%
json
.
dumps
(
software_installation
,
indent
=
2
))
logger
.
warning
(
'Message: %s'
%
software_installation
.
get
(
"message"
,
""
))
exit
(
2
)
else
:
local
[
'supply'
](
local
[
'supply'
](
software_release
=
software_release
,
software_release
=
software_release
,
computer_guid
=
computer_id
,
computer_guid
=
computer_id
,
...
...
slapos/format.py
View file @
3a98bda4
...
@@ -366,37 +366,6 @@ class Computer(object):
...
@@ -366,37 +366,6 @@ class Computer(object):
connection_dict
[
'cert_file'
]
=
conf
.
cert_file
connection_dict
[
'cert_file'
]
=
conf
.
cert_file
slap_instance
.
initializeConnection
(
conf
.
master_url
,
slap_instance
.
initializeConnection
(
conf
.
master_url
,
**
connection_dict
)
**
connection_dict
)
if
slap_instance
.
jio_api_connector
:
partition_list
=
[]
for
partition
in
self
.
partition_list
:
ip_list
=
[]
network_interface
=
partition
.
tap
.
name
if
partition
.
tap
else
partition
.
reference
for
address
in
partition
.
address_list
:
ip_list
.
append
({
"ip-address"
:
address
[
"addr"
],
"network-interface"
:
network_interface
,
})
if
partition
.
tap
and
partition
.
tap
.
ipv4_addr
:
ip_list
.
append
({
"ip-address"
:
partition
.
tap
.
ipv4_addr
,
"network-interface"
:
partition
.
tap
.
name
,
"gateway-ip-address"
:
partition
.
tap
.
ipv4_gateway
,
"netmask"
:
partition
.
tap
.
netmask
,
"network-address"
:
partition
.
tap
.
ipv4_network
})
partition_list
.
append
({
"partition_id"
:
partition
.
reference
,
"ip_list"
:
ip_list
})
if
conf
.
dry_run
:
return
slap_instance
.
jio_api_connector
.
put
({
"compute_node_id"
:
self
.
reference
,
"compute_partition_list"
:
partition_list
,
"portal_type"
:
"Compute Node"
,
})
else
:
slap_computer
=
slap_instance
.
registerComputer
(
self
.
reference
)
slap_computer
=
slap_instance
.
registerComputer
(
self
.
reference
)
if
conf
.
dry_run
:
if
conf
.
dry_run
:
...
@@ -1697,15 +1666,7 @@ def do_format(conf):
...
@@ -1697,15 +1666,7 @@ def do_format(conf):
conf
.
logger
.
exception
(
'slapos failed to prepare the computer.'
)
conf
.
logger
.
exception
(
'slapos failed to prepare the computer.'
)
return
FormatReturn
.
FAILURE
return
FormatReturn
.
FAILURE
computer
.
update
()
# Dumping and sending to the erp5 the current configuration
if
not
conf
.
dry_run
:
computer
.
dump
(
path_to_xml
=
conf
.
computer_xml
,
path_to_json
=
conf
.
computer_json
,
logger
=
conf
.
logger
)
conf
.
logger
.
info
(
'Posting information to %r'
%
conf
.
master_url
)
computer
.
send
(
conf
)
conf
.
logger
.
info
(
'slapos successfully prepared the computer.'
)
class
FormatConfig
(
object
):
class
FormatConfig
(
object
):
"""This class represents the options for slapos node format
"""This class represents the options for slapos node format
...
...
slapos/grid/SlapObject.py
View file @
3a98bda4
...
@@ -30,7 +30,6 @@
...
@@ -30,7 +30,6 @@
import
datetime
import
datetime
import
errno
import
errno
import
json
import
os
import
os
import
pkg_resources
import
pkg_resources
import
pwd
import
pwd
...
@@ -57,7 +56,6 @@ from slapos.grid.svcbackend import getSupervisorRPC
...
@@ -57,7 +56,6 @@ from slapos.grid.svcbackend import getSupervisorRPC
from
slapos.grid.exception
import
(
BuildoutFailedError
,
WrongPermissionError
,
from
slapos.grid.exception
import
(
BuildoutFailedError
,
WrongPermissionError
,
PathDoesNotExistError
,
DiskSpaceError
)
PathDoesNotExistError
,
DiskSpaceError
)
from
slapos.grid.networkcache
import
download_network_cached
,
upload_network_cached
from
slapos.grid.networkcache
import
download_network_cached
,
upload_network_cached
from
slapos.grid.utils
import
md5digest
from
slapos.human
import
bytes2human
from
slapos.human
import
bytes2human
from
slapos.util
import
bytes2str
,
rmtree
from
slapos.util
import
bytes2str
,
rmtree
...
@@ -77,8 +75,6 @@ GROUP_PARTITION_TEMPLATE = bytes2str(
...
@@ -77,8 +75,6 @@ GROUP_PARTITION_TEMPLATE = bytes2str(
pkg_resources
.
resource_string
(
pkg_resources
.
resource_string
(
__name__
,
'templates/group_partition_supervisord.conf.in'
))
__name__
,
'templates/group_partition_supervisord.conf.in'
))
SOFTWARE_INSTANCE_JSON_FILENAME
=
'.software-instance.json'
def
free_space
(
path
,
fn
):
def
free_space
(
path
,
fn
):
while
True
:
while
True
:
...
@@ -519,15 +515,21 @@ class Partition(object):
...
@@ -519,15 +515,21 @@ class Partition(object):
available
=
bytes2human
(
available
),
available
=
bytes2human
(
available
),
required
=
bytes2human
(
required
)))
required
=
bytes2human
(
required
)))
def
_updateCertificate
(
self
,
partition_certificates
):
def
_updateCertificate
(
self
):
if
not
self
.
key_file
or
not
self
.
cert_file
:
if
not
self
.
key_file
or
not
self
.
cert_file
:
# Certificate files are unset, skip.
# Certificate files are unset, skip.
return
return
try
:
partition_certificate
=
self
.
computer_partition
.
getCertificate
()
except
NotFoundError
:
raise
NotFoundError
(
'Partition %s is not known by SlapOS Master.'
%
self
.
partition_id
)
uid
,
gid
=
self
.
getUserGroupId
()
uid
,
gid
=
self
.
getUserGroupId
()
for
name
,
path
in
[(
'certificate'
,
self
.
cert_file
),
(
'key'
,
self
.
key_file
)]:
for
name
,
path
in
[(
'certificate'
,
self
.
cert_file
),
(
'key'
,
self
.
key_file
)]:
new_content
=
partition_certificate
s
[
name
]
new_content
=
partition_certificate
[
name
]
old_content
=
None
old_content
=
None
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
with
open
(
path
)
as
f
:
with
open
(
path
)
as
f
:
...
@@ -583,7 +585,7 @@ class Partition(object):
...
@@ -583,7 +585,7 @@ class Partition(object):
installs the software partition with the help of buildout
installs the software partition with the help of buildout
"""
"""
self
.
logger
.
info
(
"Installing Computer Partition %s..."
self
.
logger
.
info
(
"Installing Computer Partition %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
%
self
.
partition_id
)
self
.
check_free_space
()
self
.
check_free_space
()
...
@@ -604,20 +606,6 @@ class Partition(object):
...
@@ -604,20 +606,6 @@ class Partition(object):
(
self
.
instance_path
,
permission
,
(
self
.
instance_path
,
permission
,
REQUIRED_COMPUTER_PARTITION_PERMISSION
))
REQUIRED_COMPUTER_PARTITION_PERMISSION
))
uid
,
gid
=
self
.
getUserGroupId
()
# Store software instance json
instance_json_location
=
os
.
path
.
join
(
self
.
instance_path
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
partiton_dict
=
self
.
computer_partition
.
copy
()
partiton_dict
.
pop
(
"slap_partition"
,
None
)
# XXX Check if we want them or not
partiton_dict
.
pop
(
"access_status_message"
,
None
)
with
open
(
instance_json_location
,
'w'
)
as
f
:
json
.
dump
(
partiton_dict
,
f
,
indent
=
2
)
os
.
chown
(
instance_json_location
,
uid
,
gid
)
# Check that Software Release directory is present
# Check that Software Release directory is present
if
not
os
.
path
.
exists
(
self
.
software_path
):
if
not
os
.
path
.
exists
(
self
.
software_path
):
# XXX What should it raise?
# XXX What should it raise?
...
@@ -635,7 +623,6 @@ class Partition(object):
...
@@ -635,7 +623,6 @@ class Partition(object):
# XXX What should it raise?
# XXX What should it raise?
raise
IOError
(
'Software Release %s is not correctly installed.
\
n
Missing file: %s'
%
(
raise
IOError
(
'Software Release %s is not correctly installed.
\
n
Missing file: %s'
%
(
self
.
software_release_url
,
template_location
))
self
.
software_release_url
,
template_location
))
config_location
=
os
.
path
.
join
(
self
.
instance_path
,
'buildout.cfg'
)
config_location
=
os
.
path
.
join
(
self
.
instance_path
,
'buildout.cfg'
)
self
.
logger
.
debug
(
"Copying %r to %r"
%
(
template_location
,
config_location
))
self
.
logger
.
debug
(
"Copying %r to %r"
%
(
template_location
,
config_location
))
shutil
.
copy
(
template_location
,
config_location
)
shutil
.
copy
(
template_location
,
config_location
)
...
@@ -647,27 +634,13 @@ class Partition(object):
...
@@ -647,27 +634,13 @@ class Partition(object):
'templates/buildout-tail.cfg.in'
))
%
{
'templates/buildout-tail.cfg.in'
))
%
{
'computer_id'
:
self
.
computer_id
,
'computer_id'
:
self
.
computer_id
,
'partition_id'
:
self
.
partition_id
,
'partition_id'
:
self
.
partition_id
,
'software_instance_reference'
:
self
.
computer_partition
.
get
(
"reference"
),
'server_url'
:
self
.
server_url
,
'server_url'
:
self
.
server_url
,
'software_release_url'
:
self
.
software_release_url
,
'software_release_url'
:
self
.
software_release_url
,
'key_file'
:
self
.
key_file
,
'key_file'
:
self
.
key_file
,
'cert_file'
:
self
.
cert_file
,
'cert_file'
:
self
.
cert_file
,
'storage_home'
:
self
.
instance_storage_home
,
'storage_home'
:
self
.
instance_storage_home
,
'global_ipv4_network_prefix'
:
self
.
ipv4_global_network
,
'global_ipv4_network_prefix'
:
self
.
ipv4_global_network
,
'shared_part_list'
:
' '
.
join
(
self
.
shared_part_list
.
strip
().
splitlines
(
True
)),
'shared_part_list'
:
' '
.
join
(
self
.
shared_part_list
.
strip
().
splitlines
(
True
))
'parameters_md5sum'
:
md5digest
(
json
.
dumps
(
self
.
computer_partition
.
get
(
"parameters"
,
{}),
sort_keys
=
True
)
),
'connection_parameters_md5sum'
:
md5digest
(
json
.
dumps
(
self
.
computer_partition
.
get
(
"connection_parameters"
,
{}),
sort_keys
=
True
)
),
'instance_state'
:
self
.
computer_partition
.
get
(
"state"
),
'instance_software_type'
:
self
.
computer_partition
.
get
(
"software_type"
),
'instance_processing_timestamp'
:
self
.
computer_partition
.
get
(
"processing_timestamp"
)
}
}
with
open
(
config_location
,
'w'
)
as
f
:
with
open
(
config_location
,
'w'
)
as
f
:
f
.
write
(
buildout_text
)
f
.
write
(
buildout_text
)
...
@@ -683,6 +656,7 @@ class Partition(object):
...
@@ -683,6 +656,7 @@ class Partition(object):
if
q
.
startswith
(
'bootstrap'
)]
if
q
.
startswith
(
'bootstrap'
)]
else
:
else
:
bootstrap_candidate_list
=
[]
bootstrap_candidate_list
=
[]
uid
,
gid
=
self
.
getUserGroupId
()
os
.
chown
(
config_location
,
-
1
,
int
(
gid
))
os
.
chown
(
config_location
,
-
1
,
int
(
gid
))
if
len
(
bootstrap_candidate_list
)
==
0
:
if
len
(
bootstrap_candidate_list
)
==
0
:
buildout_binary
=
os
.
path
.
join
(
self
.
software_path
,
'bin'
,
'buildout'
)
buildout_binary
=
os
.
path
.
join
(
self
.
software_path
,
'bin'
,
'buildout'
)
...
@@ -758,14 +732,6 @@ class Partition(object):
...
@@ -758,14 +732,6 @@ class Partition(object):
self
.
logger
.
warning
(
'No runners nor services found for partition %r'
%
self
.
logger
.
warning
(
'No runners nor services found for partition %r'
%
self
.
partition_id
)
self
.
partition_id
)
else
:
else
:
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
group_partition_template
=
bytes2str
(
pkg_resources
.
resource_string
(
__name__
,
'templates/group_partition_supervisord.conf.in'
))
self
.
supervisor_configuration_group
=
group_partition_template
%
{
'instance_id'
:
partition_id
,
'program_list'
:
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
for
runner
in
runner_list
+
service_list
])
}
# Same method to add to service and run
# Same method to add to service and run
self
.
addServicesToGroup
(
runner_list
,
self
.
run_path
)
self
.
addServicesToGroup
(
runner_list
,
self
.
run_path
)
self
.
addServicesToGroup
(
self
.
addServicesToGroup
(
...
@@ -838,22 +804,22 @@ class Partition(object):
...
@@ -838,22 +804,22 @@ class Partition(object):
"""Asks supervisord to start the instance. If this instance is not
"""Asks supervisord to start the instance. If this instance is not
installed, we install it.
installed, we install it.
"""
"""
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
self
.
updateSupervisorConfiguration
()
partition_id
=
self
.
partition_id
try
:
try
:
with
self
.
getSupervisorRPC
()
as
supervisor
:
with
self
.
getSupervisorRPC
()
as
supervisor
:
supervisor
.
startProcessGroup
(
partition_id
,
False
)
supervisor
.
startProcessGroup
(
partition_id
,
False
)
except
xmlrpclib
.
Fault
as
exc
:
except
xmlrpclib
.
Fault
as
exc
:
if
exc
.
faultString
.
startswith
(
'BAD_NAME:'
):
if
exc
.
faultString
.
startswith
(
'BAD_NAME:'
):
self
.
logger
.
info
(
"Nothing to start on %s..."
%
self
.
logger
.
info
(
"Nothing to start on %s..."
%
partition_id
)
self
.
computer_partition
.
get
(
"compute_partition_id"
))
else
:
else
:
raise
raise
else
:
else
:
self
.
logger
.
info
(
"Requested start of %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
self
.
logger
.
info
(
"Requested start of %s..."
%
partition_id
)
def
stop
(
self
):
def
stop
(
self
):
"""Asks supervisord to stop the instance."""
"""Asks supervisord to stop the instance."""
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
partition_id
=
self
.
partition_id
filename
=
partition_id
+
'.conf'
filename
=
partition_id
+
'.conf'
filepath
=
os
.
path
.
join
(
filepath
=
os
.
path
.
join
(
self
.
supervisord_partition_configuration_dir
,
filename
)
self
.
supervisord_partition_configuration_dir
,
filename
)
...
@@ -864,13 +830,13 @@ class Partition(object):
...
@@ -864,13 +830,13 @@ class Partition(object):
raise
raise
else
:
else
:
self
.
updateSupervisor
()
self
.
updateSupervisor
()
self
.
logger
.
info
(
"Requested stop of %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
self
.
logger
.
info
(
"Requested stop of %s..."
%
partition_id
)
def
destroy
(
self
):
def
destroy
(
self
):
"""Destroys the partition and makes it available for subsequent use."
"""Destroys the partition and makes it available for subsequent use."
"""
"""
self
.
logger
.
info
(
"Destroying Computer Partition %s..."
self
.
logger
.
info
(
"Destroying Computer Partition %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
%
self
.
partition_id
)
self
.
createRetentionLockDate
()
self
.
createRetentionLockDate
()
if
not
self
.
checkRetentionIsAuthorized
():
if
not
self
.
checkRetentionIsAuthorized
():
...
...
slapos/grid/slapgrid.py
View file @
3a98bda4
...
@@ -322,6 +322,7 @@ def create_slapgrid_object(options, logger):
...
@@ -322,6 +322,7 @@ def create_slapgrid_object(options, logger):
force_stop
=
op
.
get
(
'force_stop'
,
False
),
force_stop
=
op
.
get
(
'force_stop'
,
False
),
partition_timeout
=
partition_timeout
)
partition_timeout
=
partition_timeout
)
def
check_required_only_partitions
(
existing
,
required
):
def
check_required_only_partitions
(
existing
,
required
):
"""
"""
Verify the existence of partitions specified by the --only parameter
Verify the existence of partitions specified by the --only parameter
...
@@ -437,7 +438,6 @@ class Slapgrid(object):
...
@@ -437,7 +438,6 @@ class Slapgrid(object):
if
computer_partition_filter_list
is
not
None
:
if
computer_partition_filter_list
is
not
None
:
self
.
computer_partition_filter_list
=
\
self
.
computer_partition_filter_list
=
\
computer_partition_filter_list
.
split
(
","
)
computer_partition_filter_list
.
split
(
","
)
self
.
computer_partition_list
=
None
self
.
maximum_periodicity
=
maximum_periodicity
self
.
maximum_periodicity
=
maximum_periodicity
self
.
software_min_free_space
=
software_min_free_space
self
.
software_min_free_space
=
software_min_free_space
self
.
instance_min_free_space
=
instance_min_free_space
self
.
instance_min_free_space
=
instance_min_free_space
...
@@ -572,70 +572,22 @@ stderr_logfile_backups=1
...
@@ -572,70 +572,22 @@ stderr_logfile_backups=1
launchSupervisord
(
instance_root
=
self
.
instance_root
,
logger
=
self
.
logger
)
launchSupervisord
(
instance_root
=
self
.
instance_root
,
logger
=
self
.
logger
)
def
getComputerPartitionList
(
self
):
def
getComputerPartitionList
(
self
):
if
not
self
.
api_backward_compatibility
:
if
self
.
computer_partition_list
is
None
:
self
.
computer_partition_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
self
.
computer_id
,
}).
get
(
"result_list"
,
[])
else
:
try
:
try
:
slap_partition_list
=
self
.
computer
.
getComputerPartitionList
()
return
self
.
computer
.
getComputerPartitionList
()
except
socket
.
error
as
exc
:
except
socket
.
error
as
exc
:
self
.
logger
.
fatal
(
exc
)
self
.
logger
.
fatal
(
exc
)
raise
raise
self
.
computer_partition_list
=
[]
for
partition
in
slap_partition_list
:
try
:
software_release_uri
=
partition
.
getSoftwareRelease
().
getURI
()
except
(
NotFoundError
,
TypeError
,
NameError
):
software_release_uri
=
None
parameter_dict
=
partition
.
getInstanceParameterDict
()
instance_dict
=
{
"reference"
:
getattr
(
partition
,
'_instance_guid'
,
None
),
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
getattr
(
partition
,
'_computer_id'
,
None
),
"compute_partition_id"
:
partition
.
getId
(),
"state"
:
partition
.
getState
(),
"shared"
:
False
,
"software_type"
:
parameter_dict
.
pop
(
'slap_software_type'
,
None
),
"processing_timestamp"
:
parameter_dict
.
pop
(
"timestamp"
,
None
),
"slap_partition"
:
partition
,
"ip_list"
:
parameter_dict
.
pop
(
"ip_list"
,
[]),
"full_ip_list"
:
parameter_dict
.
pop
(
"full_ip_list"
,
[]),
"access_status_message"
:
partition
.
getAccessStatus
(),
"software_release_uri"
:
software_release_uri
,
"sla_parameters"
:
getattr
(
partition
,
'_filter_dict'
,
{}),
"connection_parameters"
:
partition
.
getConnectionParameterDict
(),
"root_instance_title"
:
parameter_dict
.
pop
(
"root_instance_title"
,
None
),
"title"
:
parameter_dict
.
pop
(
"instance_title"
,
None
),
}
instance_dict
[
"parameters"
]
=
parameter_dict
self
.
computer_partition_list
.
append
(
instance_dict
)
return
self
.
computer_partition_list
def
sendPartitionError
(
self
,
partition
,
error_message
,
logger
=
None
):
if
not
self
.
api_backward_compatibility
:
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reported_state"
:
"error"
,
"status_message"
:
str
(
error_message
),
"reference"
:
partition
.
get
(
"reference"
)
})
else
:
partition
[
"slap_partition"
].
error
(
error_message
,
logger
=
logger
)
def
getRequiredComputerPartitionList
(
self
):
def
getRequiredComputerPartitionList
(
self
):
"""Return the computer partitions that should be processed.
"""Return the computer partitions that should be processed.
"""
"""
cp_list
=
self
.
getComputerPartitionList
()
cp_list
=
self
.
getComputerPartitionList
()
cp_id_list
=
[
cp
.
get
(
"compute_partition_id"
,
""
)
for
cp
in
cp_list
]
cp_id_list
=
[
cp
.
get
Id
(
)
for
cp
in
cp_list
]
required_cp_id_set
=
check_required_only_partitions
(
required_cp_id_set
=
check_required_only_partitions
(
cp_id_list
,
self
.
computer_partition_filter_list
)
cp_id_list
,
self
.
computer_partition_filter_list
)
busy_cp_list
=
self
.
FilterComputerPartitionList
(
cp_list
)
busy_cp_list
=
self
.
FilterComputerPartitionList
(
cp_list
)
if
required_cp_id_set
:
if
required_cp_id_set
:
return
[
cp
for
cp
in
busy_cp_list
if
cp
.
get
(
"computer_partition_id"
,
""
)
in
required_cp_id_set
]
return
[
cp
for
cp
in
busy_cp_list
if
cp
.
get
Id
(
)
in
required_cp_id_set
]
return
busy_cp_list
return
busy_cp_list
def
processSoftwareReleaseList
(
self
):
def
processSoftwareReleaseList
(
self
):
...
@@ -645,27 +597,10 @@ stderr_logfile_backups=1
...
@@ -645,27 +597,10 @@ stderr_logfile_backups=1
self
.
logger
.
info
(
'Processing software releases...'
)
self
.
logger
.
info
(
'Processing software releases...'
)
# Boolean to know if every instance has correctly been deployed
# Boolean to know if every instance has correctly been deployed
clean_run
=
True
clean_run
=
True
if
not
self
.
api_backward_compatibility
:
software_installation_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
})
if
"result_list"
in
software_installation_list
:
software_installation_list
=
software_installation_list
[
"result_list"
]
else
:
software_installation_list
=
[]
else
:
software_installation_list
=
[]
for
software_release
in
self
.
computer
.
getSoftwareReleaseList
():
for
software_release
in
self
.
computer
.
getSoftwareReleaseList
():
software_installation_list
.
append
({
state
=
software_release
.
getState
()
"software_release_uri"
:
software_release
.
getURI
(),
"state"
:
software_release
.
getState
(),
"compatibility_software_release"
:
software_release
,
})
for
software_release
in
software_installation_list
:
state
=
software_release
[
"state"
]
try
:
try
:
software_release_uri
=
software_release
[
"software_release_uri"
]
software_release_uri
=
software_release
.
getURI
()
url_hash
=
md5digest
(
software_release_uri
)
url_hash
=
md5digest
(
software_release_uri
)
software_path
=
os
.
path
.
join
(
self
.
software_root
,
url_hash
)
software_path
=
os
.
path
.
join
(
self
.
software_root
,
url_hash
)
software
=
Software
(
url
=
software_release_uri
,
software
=
Software
(
url
=
software_release_uri
,
...
@@ -707,15 +642,7 @@ stderr_logfile_backups=1
...
@@ -707,15 +642,7 @@ stderr_logfile_backups=1
url_hash
in
self
.
software_release_filter_list
or
url_hash
in
self
.
software_release_filter_list
or
url_hash
in
(
md5digest
(
uri
)
for
uri
in
self
.
software_release_filter_list
)):
url_hash
in
(
md5digest
(
uri
)
for
uri
in
self
.
software_release_filter_list
)):
try
:
try
:
if
not
self
.
api_backward_compatibility
:
software_release
.
building
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"reported_state"
:
"building"
,
})
else
:
software_release
[
"compatibility_software_release"
].
building
()
except
NotFoundError
:
except
NotFoundError
:
pass
pass
software
.
install
()
software
.
install
()
...
@@ -732,32 +659,14 @@ stderr_logfile_backups=1
...
@@ -732,32 +659,14 @@ stderr_logfile_backups=1
manager
.
softwareTearDown
(
software
)
manager
.
softwareTearDown
(
software
)
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
if
not
self
.
api_backward_compatibility
:
software_release
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"error_status"
:
traceback
.
format_exc
(),
})
else
:
software_release
[
"compatibility_software_release"
].
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
# Buildout failed: send log but don't print it to output (already done)
# Buildout failed: send log but don't print it to output (already done)
except
BuildoutFailedError
as
exc
:
except
BuildoutFailedError
as
exc
:
clean_run
=
False
clean_run
=
False
try
:
try
:
if
not
self
.
api_backward_compatibility
:
software_release
.
error
(
exc
,
logger
=
self
.
logger
)
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"error_status"
:
str
(
exc
),
})
else
:
software_release
[
"compatibility_software_release"
].
error
(
exc
,
logger
=
self
.
logger
)
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
...
@@ -766,43 +675,17 @@ stderr_logfile_backups=1
...
@@ -766,43 +675,17 @@ stderr_logfile_backups=1
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
except
Exception
:
except
Exception
:
self
.
logger
.
exception
(
''
)
self
.
logger
.
exception
(
''
)
if
not
self
.
api_backward_compatibility
:
software_release
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"error_status"
:
traceback
.
format_exc
(),
})
else
:
software_release
[
"compatibility_software_release"
].
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
clean_run
=
False
clean_run
=
False
else
:
else
:
if
state
==
'available'
:
if
state
==
'available'
:
try
:
try
:
if
not
self
.
api_backward_compatibility
:
software_release
.
available
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"reported_state"
:
"available"
,
})
else
:
software_release
[
"compatibility_software_release"
].
available
()
except
(
NotFoundError
,
ServerError
):
except
(
NotFoundError
,
ServerError
):
pass
pass
elif
state
==
'destroyed'
:
elif
state
==
'destroyed'
:
try
:
try
:
if
not
self
.
api_backward_compatibility
:
software_release
.
destroyed
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
self
.
computer_id
,
"software_release_uri"
:
software_release_uri
,
"reported_state"
:
"destroyed"
,
})
else
:
software_release
[
"compatibility_software_release"
].
destroyed
()
except
(
NotFoundError
,
ServerError
):
except
(
NotFoundError
,
ServerError
):
self
.
logger
.
exception
(
''
)
self
.
logger
.
exception
(
''
)
self
.
logger
.
info
(
'Finished software releases.'
)
self
.
logger
.
info
(
'Finished software releases.'
)
...
@@ -896,7 +779,7 @@ stderr_logfile_backups=1
...
@@ -896,7 +779,7 @@ stderr_logfile_backups=1
return
PromiseLauncher
(
config
=
promise_config
,
logger
=
self
.
logger
).
run
()
return
PromiseLauncher
(
config
=
promise_config
,
logger
=
self
.
logger
).
run
()
def
_endInstallationTransaction
(
self
,
computer_partition
):
def
_endInstallationTransaction
(
self
,
computer_partition
):
partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
partition_id
=
computer_partition
.
get
Id
(
)
transaction_file_name
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
partition_id
transaction_file_name
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
partition_id
transaction_file_path
=
os
.
path
.
join
(
self
.
instance_root
,
transaction_file_path
=
os
.
path
.
join
(
self
.
instance_root
,
partition_id
,
partition_id
,
...
@@ -905,14 +788,7 @@ stderr_logfile_backups=1
...
@@ -905,14 +788,7 @@ stderr_logfile_backups=1
if
os
.
path
.
exists
(
transaction_file_path
):
if
os
.
path
.
exists
(
transaction_file_path
):
with
open
(
transaction_file_path
,
'r'
)
as
tf
:
with
open
(
transaction_file_path
,
'r'
)
as
tf
:
try
:
try
:
if
not
self
.
api_backward_compatibility
:
computer_partition
.
setComputerPartitionRelatedInstanceList
(
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"requested_instance_list"
:
[
reference
for
reference
in
tf
.
read
().
split
(
'
\
n
'
)
if
reference
],
})
else
:
computer_partition
[
"slap_partition"
].
setComputerPartitionRelatedInstanceList
(
[
reference
for
reference
in
tf
.
read
().
split
(
'
\
n
'
)
if
reference
]
[
reference
for
reference
in
tf
.
read
().
split
(
'
\
n
'
)
if
reference
]
)
)
except
NotFoundError
as
e
:
except
NotFoundError
as
e
:
...
@@ -1125,20 +1001,7 @@ stderr_logfile_backups=1
...
@@ -1125,20 +1001,7 @@ stderr_logfile_backups=1
elif
valid_ipv6
(
ip
):
elif
valid_ipv6
(
ip
):
ipv6_list
.
append
(
ip
)
ipv6_list
.
append
(
ip
)
if
not
self
.
api_backward_compatibility
:
hosting_ip_list
=
computer_partition
.
getFullHostingIpAddressList
()
hosting_ip_list
=
[]
# Get all the instances of the instance tree
related_instance_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Software Instance"
,
"root_instance_title"
:
computer_partition
[
"root_instance_title"
],
}).
get
(
"result_list"
,
[])
for
instance_result
in
related_instance_list
:
if
instance_result
[
"reference"
]
!=
computer_partition
[
"reference"
]:
instance
=
self
.
slap
.
jio_api_connector
.
get
(
instance_result
[
"get_parameters"
])
hosting_ip_list
=
hosting_ip_list
+
instance
[
"ip_list"
]
else
:
hosting_ip_list
=
computer_partition
[
"slap_partition"
].
getFullHostingIpAddressList
()
for
iface
,
ip
in
hosting_ip_list
:
for
iface
,
ip
in
hosting_ip_list
:
if
valid_ipv4
(
ip
):
if
valid_ipv4
(
ip
):
if
not
ip
in
ipv4_list
:
if
not
ip
in
ipv4_list
:
...
@@ -1147,7 +1010,7 @@ stderr_logfile_backups=1
...
@@ -1147,7 +1010,7 @@ stderr_logfile_backups=1
if
not
ip
in
ipv6_list
:
if
not
ip
in
ipv6_list
:
hosting_ipv6_list
.
append
(
ip
)
hosting_ipv6_list
.
append
(
ip
)
filter_dict
=
computer_partition
.
get
(
'sla_parameters
'
,
None
)
filter_dict
=
getattr
(
computer_partition
,
'_filter_dict
'
,
None
)
extra_list
=
[]
extra_list
=
[]
accept_ip_list
=
[]
accept_ip_list
=
[]
if
filter_dict
is
not
None
:
if
filter_dict
is
not
None
:
...
@@ -1167,24 +1030,11 @@ stderr_logfile_backups=1
...
@@ -1167,24 +1030,11 @@ stderr_logfile_backups=1
for
ip
in
ipv4_list
:
for
ip
in
ipv4_list
:
cmd_list
=
getFirewallRules
(
ip
,
hosting_ipv4_list
,
cmd_list
=
getFirewallRules
(
ip
,
hosting_ipv4_list
,
source_ipv4_list
,
ip_type
=
'ipv4'
)
source_ipv4_list
,
ip_type
=
'ipv4'
)
self
.
_checkAddFirewallRules
(
computer_partition
.
get
(
"compute_partition_id"
),
self
.
_checkAddFirewallRules
(
computer_partition
.
get
Id
(
),
cmd_list
,
add
=
add_rules
)
cmd_list
,
add
=
add_rules
)
def
retrieveCertificates
(
self
,
computer_partition
):
if
not
self
.
api_backward_compatibility
:
partition_certificates
=
self
.
slap
.
jio_api_connector
.
get
({
"portal_type"
:
"Software Instance Certificate Record"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
})
else
:
try
:
partition_certificates
=
computer_partition
[
"slap_partition"
].
getCertificate
()
except
NotFoundError
:
raise
NotFoundError
(
'Partition %s is not known by SlapOS Master.'
%
computer_partition
.
get
(
"reference"
))
return
partition_certificates
def
_checkPromiseAnomaly
(
self
,
local_partition
,
computer_partition
):
def
_checkPromiseAnomaly
(
self
,
local_partition
,
computer_partition
):
partition_access_status
=
computer_partition
.
get
(
"access_status_message"
,
""
)
partition_access_status
=
computer_partition
.
get
AccessStatus
(
)
status_error
=
False
status_error
=
False
if
partition_access_status
and
partition_access_status
.
startswith
(
"#error"
):
if
partition_access_status
and
partition_access_status
.
startswith
(
"#error"
):
status_error
=
True
status_error
=
True
...
@@ -1195,25 +1045,18 @@ stderr_logfile_backups=1
...
@@ -1195,25 +1045,18 @@ stderr_logfile_backups=1
except
PromiseError
as
e
:
except
PromiseError
as
e
:
self
.
logger
.
error
(
e
)
self
.
logger
.
error
(
e
)
if
partition_access_status
is
None
or
not
status_error
:
if
partition_access_status
is
None
or
not
status_error
:
local_partition
.
_updateCertificate
(
self
.
retrieveCertificates
(
computer_partition
)
)
local_partition
.
_updateCertificate
()
self
.
sendPartitionError
(
computer_partition
,
e
,
logger
=
self
.
logger
)
computer_partition
.
error
(
e
,
logger
=
self
.
logger
)
else
:
else
:
if
partition_access_status
is
None
or
status_error
:
if
partition_access_status
is
None
or
status_error
:
local_partition
.
_updateCertificate
(
self
.
retrieveCertificates
(
computer_partition
))
local_partition
.
_updateCertificate
()
if
not
self
.
api_backward_compatibility
:
computer_partition
.
started
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"started"
})
else
:
computer_partition
[
"slap_partition"
].
started
()
def
processPromise
(
self
,
computer_partition
):
def
processPromise
(
self
,
computer_partition
):
"""
"""
Process the promises from a given Computer Partition, depending on its state
Process the promises from a given Computer Partition, depending on its state
"""
"""
computer_partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
computer_partition_id
=
computer_partition
.
get
Id
(
)
# Sanity checks before processing
# Sanity checks before processing
# Those values should not be None or empty string or any falsy value
# Those values should not be None or empty string or any falsy value
...
@@ -1222,7 +1065,12 @@ stderr_logfile_backups=1
...
@@ -1222,7 +1065,12 @@ stderr_logfile_backups=1
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
os
.
environ
[
'SLAPGRID_INSTANCE_ROOT'
]
=
self
.
instance_root
os
.
environ
[
'SLAPGRID_INSTANCE_ROOT'
]
=
self
.
instance_root
software_url
=
computer_partition
.
get
(
"software_release_uri"
)
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
except
NotFoundError
:
# Problem with instance: SR URI not set.
# Try to process it anyway, it may need to be deleted.
software_url
=
None
try
:
try
:
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
...
@@ -1231,7 +1079,7 @@ stderr_logfile_backups=1
...
@@ -1231,7 +1079,7 @@ stderr_logfile_backups=1
# Try to process it anyway, it may need to be deleted.
# Try to process it anyway, it may need to be deleted.
software_path
=
None
software_path
=
None
computer_partition_state
=
computer_partition
.
get
(
"state"
)
computer_partition_state
=
computer_partition
.
get
State
(
)
local_partition
=
Partition
(
local_partition
=
Partition
(
software_path
=
software_path
,
software_path
=
software_path
,
...
@@ -1249,7 +1097,7 @@ stderr_logfile_backups=1
...
@@ -1249,7 +1097,7 @@ stderr_logfile_backups=1
buildout
=
self
.
buildout
,
buildout
=
self
.
buildout
,
buildout_debug
=
self
.
buildout_debug
,
buildout_debug
=
self
.
buildout_debug
,
logger
=
self
.
logger
,
logger
=
self
.
logger
,
retention_delay
=
computer_partition
.
get
(
'sla_parameters
'
,
{}).
get
(
'retention_delay'
,
'0'
),
retention_delay
=
getattr
(
computer_partition
,
'_filter_dict
'
,
{}).
get
(
'retention_delay'
,
'0'
),
instance_min_free_space
=
self
.
instance_min_free_space
,
instance_min_free_space
=
self
.
instance_min_free_space
,
instance_storage_home
=
self
.
instance_storage_home
,
instance_storage_home
=
self
.
instance_storage_home
,
ipv4_global_network
=
self
.
ipv4_global_network
,
ipv4_global_network
=
self
.
ipv4_global_network
,
...
@@ -1268,7 +1116,7 @@ stderr_logfile_backups=1
...
@@ -1268,7 +1116,7 @@ stderr_logfile_backups=1
"""
"""
Process a Computer Partition, depending on its state
Process a Computer Partition, depending on its state
"""
"""
computer_partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
computer_partition_id
=
computer_partition
.
get
Id
(
)
# Sanity checks before processing
# Sanity checks before processing
# Those values should not be None or empty string or any falsy value
# Those values should not be None or empty string or any falsy value
...
@@ -1292,14 +1140,20 @@ stderr_logfile_backups=1
...
@@ -1292,14 +1140,20 @@ stderr_logfile_backups=1
instance_path
,
instance_path
,
COMPUTER_PARTITION_TIMESTAMP_FILENAME
COMPUTER_PARTITION_TIMESTAMP_FILENAME
)
)
timestamp
=
computer_partition
.
get
(
"processing_timestamp"
)
parameter_dict
=
computer_partition
.
getInstanceParameterDict
()
timestamp
=
parameter_dict
.
get
(
'timestamp'
)
error_output_file
=
os
.
path
.
join
(
error_output_file
=
os
.
path
.
join
(
instance_path
,
instance_path
,
COMPUTER_PARTITION_INSTALL_ERROR_FILENAME
%
computer_partition_id
COMPUTER_PARTITION_INSTALL_ERROR_FILENAME
%
computer_partition_id
)
)
software_url
=
computer_partition
.
get
(
"software_release_uri"
)
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
except
NotFoundError
:
# Problem with instance: SR URI not set.
# Try to process it anyway, it may need to be deleted.
software_url
=
None
try
:
try
:
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
except
TypeError
:
except
TypeError
:
...
@@ -1307,7 +1161,7 @@ stderr_logfile_backups=1
...
@@ -1307,7 +1161,7 @@ stderr_logfile_backups=1
# Try to process it anyway, it may need to be deleted.
# Try to process it anyway, it may need to be deleted.
software_path
=
None
software_path
=
None
computer_partition_state
=
computer_partition
.
get
(
"state"
)
computer_partition_state
=
computer_partition
.
get
State
(
)
periodicity
=
self
.
maximum_periodicity
periodicity
=
self
.
maximum_periodicity
if
software_path
:
if
software_path
:
periodicity_path
=
os
.
path
.
join
(
software_path
,
'periodicity'
)
periodicity_path
=
os
.
path
.
join
(
software_path
,
'periodicity'
)
...
@@ -1335,11 +1189,11 @@ stderr_logfile_backups=1
...
@@ -1335,11 +1189,11 @@ stderr_logfile_backups=1
buildout
=
self
.
buildout
,
buildout
=
self
.
buildout
,
buildout_debug
=
self
.
buildout_debug
,
buildout_debug
=
self
.
buildout_debug
,
logger
=
self
.
logger
,
logger
=
self
.
logger
,
retention_delay
=
computer_partition
.
get
(
'sla_parameters
'
,
{}).
get
(
'retention_delay'
,
'0'
),
retention_delay
=
getattr
(
computer_partition
,
'_filter_dict
'
,
{}).
get
(
'retention_delay'
,
'0'
),
instance_min_free_space
=
self
.
instance_min_free_space
,
instance_min_free_space
=
self
.
instance_min_free_space
,
instance_storage_home
=
self
.
instance_storage_home
,
instance_storage_home
=
self
.
instance_storage_home
,
ipv4_global_network
=
self
.
ipv4_global_network
,
ipv4_global_network
=
self
.
ipv4_global_network
,
partition_timeout
=
self
.
partition_timeout
,
partition_timeout
=
self
.
partition_timeout
)
)
# let managers modify current partition
# let managers modify current partition
...
@@ -1413,10 +1267,10 @@ stderr_logfile_backups=1
...
@@ -1413,10 +1267,10 @@ stderr_logfile_backups=1
self
.
logger
.
info
(
' Instance path: %s'
%
instance_path
)
self
.
logger
.
info
(
' Instance path: %s'
%
instance_path
)
# Update certifcate at late as possible
# Update certifcate at late as possible
local_partition
.
_updateCertificate
(
self
.
retrieveCertificates
(
computer_partition
)
)
local_partition
.
_updateCertificate
()
# XXX this line breaks 37 tests
# XXX this line breaks 37 tests
# self.logger.info(' Instance type: %s' % computer_partition.get
("software_type"
))
# self.logger.info(' Instance type: %s' % computer_partition.get
Type(
))
self
.
logger
.
info
(
' Instance status: %s'
%
computer_partition_state
)
self
.
logger
.
info
(
' Instance status: %s'
%
computer_partition_state
)
if
os
.
path
.
exists
(
error_output_file
):
if
os
.
path
.
exists
(
error_output_file
):
...
@@ -1424,7 +1278,7 @@ stderr_logfile_backups=1
...
@@ -1424,7 +1278,7 @@ stderr_logfile_backups=1
partition_ip_list
=
full_hosting_ip_list
=
[]
partition_ip_list
=
full_hosting_ip_list
=
[]
if
self
.
firewall_conf
:
if
self
.
firewall_conf
:
partition_ip_list
=
computer_partition
[
'ip_list'
]
+
computer_partition
.
get
(
partition_ip_list
=
parameter_dict
[
'ip_list'
]
+
parameter_dict
.
get
(
'full_ip_list'
,
[])
'full_ip_list'
,
[])
if
computer_partition_state
==
COMPUTER_PARTITION_STARTED_STATE
:
if
computer_partition_state
==
COMPUTER_PARTITION_STARTED_STATE
:
...
@@ -1438,14 +1292,7 @@ stderr_logfile_backups=1
...
@@ -1438,14 +1292,7 @@ stderr_logfile_backups=1
partition_ip_list
)
partition_ip_list
)
if
not
self
.
force_stop
:
if
not
self
.
force_stop
:
self
.
_checkPromiseList
(
local_partition
)
self
.
_checkPromiseList
(
local_partition
)
if
not
self
.
api_backward_compatibility
:
computer_partition
.
started
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"started"
})
else
:
computer_partition
[
"slap_partition"
].
started
()
self
.
_endInstallationTransaction
(
computer_partition
)
self
.
_endInstallationTransaction
(
computer_partition
)
elif
computer_partition_state
==
COMPUTER_PARTITION_STOPPED_STATE
:
elif
computer_partition_state
==
COMPUTER_PARTITION_STOPPED_STATE
:
try
:
try
:
...
@@ -1459,16 +1306,9 @@ stderr_logfile_backups=1
...
@@ -1459,16 +1306,9 @@ stderr_logfile_backups=1
# Instance has to be stopped even if buildout/reporting is wrong.
# Instance has to be stopped even if buildout/reporting is wrong.
local_partition
.
stop
()
local_partition
.
stop
()
try
:
try
:
if
not
self
.
api_backward_compatibility
:
computer_partition
.
stopped
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"stopped"
})
else
:
computer_partition
[
"slap_partition"
].
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
Exception
:
except
Exception
:
pass
pass
...
@@ -1480,23 +1320,16 @@ stderr_logfile_backups=1
...
@@ -1480,23 +1320,16 @@ stderr_logfile_backups=1
partition_ip_list
,
partition_ip_list
,
drop_entries
=
True
)
drop_entries
=
True
)
try
:
try
:
if
not
self
.
api_backward_compatibility
:
computer_partition
.
stopped
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"destroyed"
})
else
:
computer_partition
[
"slap_partition"
].
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
Exception
:
except
Exception
:
pass
pass
else
:
else
:
error_string
=
"Computer Partition %r has unsupported state: %s"
%
\
error_string
=
"Computer Partition %r has unsupported state: %s"
%
\
(
computer_partition_id
,
computer_partition_state
)
(
computer_partition_id
,
computer_partition_state
)
self
.
sendPartitionError
(
computer_partition
,
error_string
,
logger
=
self
.
logger
)
computer_partition
.
error
(
error_string
,
logger
=
self
.
logger
)
raise
NotImplementedError
(
error_string
)
raise
NotImplementedError
(
error_string
)
except
Exception
as
e
:
except
Exception
as
e
:
if
not
isinstance
(
e
,
PromiseError
):
if
not
isinstance
(
e
,
PromiseError
):
...
@@ -1532,7 +1365,7 @@ stderr_logfile_backups=1
...
@@ -1532,7 +1365,7 @@ stderr_logfile_backups=1
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
try
:
try
:
computer_partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
get
(
"compute_partition_id"
))
computer_partition
.
get
Id
(
))
if
not
os
.
path
.
exists
(
computer_partition_path
):
if
not
os
.
path
.
exists
(
computer_partition_path
):
raise
NotFoundError
(
'Partition directory %s does not exist.'
%
raise
NotFoundError
(
'Partition directory %s does not exist.'
%
computer_partition_path
)
computer_partition_path
)
...
@@ -1541,8 +1374,11 @@ stderr_logfile_backups=1
...
@@ -1541,8 +1374,11 @@ stderr_logfile_backups=1
# partition, and check if it has some Software information.
# partition, and check if it has some Software information.
# XXX-Cedric: Temporary AND ugly solution to check if an instance
# XXX-Cedric: Temporary AND ugly solution to check if an instance
# is in the partition. Dangerous because not 100% sure it is empty
# is in the partition. Dangerous because not 100% sure it is empty
computer_partition_state
=
computer_partition
.
get
(
"state"
)
computer_partition_state
=
computer_partition
.
getState
()
software_url
=
computer_partition
.
get
(
"software_release_uri"
)
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
except
(
NotFoundError
,
TypeError
,
NameError
):
software_url
=
None
if
computer_partition_state
==
COMPUTER_PARTITION_DESTROYED_STATE
and
\
if
computer_partition_state
==
COMPUTER_PARTITION_DESTROYED_STATE
and
\
not
software_url
:
not
software_url
:
# Exclude files which may come from concurrent processing
# Exclude files which may come from concurrent processing
...
@@ -1560,7 +1396,7 @@ stderr_logfile_backups=1
...
@@ -1560,7 +1396,7 @@ stderr_logfile_backups=1
# Ignore .slapos-resource file dumped by slapformat.
# Ignore .slapos-resource file dumped by slapformat.
if
os
.
listdir
(
computer_partition_path
)
not
in
empty_partition_listdir
:
if
os
.
listdir
(
computer_partition_path
)
not
in
empty_partition_listdir
:
self
.
logger
.
warning
(
"Free partition %s contains file(s) in %s."
%
(
self
.
logger
.
warning
(
"Free partition %s contains file(s) in %s."
%
(
computer_partition
.
get
(
"compute_partition_id"
),
computer_partition_path
))
computer_partition
.
get
Id
(
),
computer_partition_path
))
continue
continue
# Everything seems fine
# Everything seems fine
...
@@ -1570,7 +1406,7 @@ stderr_logfile_backups=1
...
@@ -1570,7 +1406,7 @@ stderr_logfile_backups=1
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
Exception
as
exc
:
except
Exception
as
exc
:
...
@@ -1579,7 +1415,7 @@ stderr_logfile_backups=1
...
@@ -1579,7 +1415,7 @@ stderr_logfile_backups=1
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
self
.
logger
.
exception
(
''
)
self
.
logger
.
exception
(
''
)
try
:
try
:
self
.
sendPartitionError
(
computer_partition
,
exc
,
logger
=
self
.
logger
)
computer_partition
.
error
(
exc
,
logger
=
self
.
logger
)
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
...
@@ -1616,17 +1452,6 @@ stderr_logfile_backups=1
...
@@ -1616,17 +1452,6 @@ stderr_logfile_backups=1
# Nothing should raise outside of the current loop iteration, so that
# Nothing should raise outside of the current loop iteration, so that
# even if something is terribly wrong while processing an instance, it
# even if something is terribly wrong while processing an instance, it
# won't prevent processing other ones.
# won't prevent processing other ones.
if
not
self
.
api_backward_compatibility
:
# Try to use partition certificate
# TODO: find a clean way to request the certificate
partition_certificate_file
=
os
.
path
.
join
(
self
.
certificate_repository_path
,
computer_partition
[
"compute_partition_id"
]
+
".crt"
)
partition_key_file
=
os
.
path
.
join
(
self
.
certificate_repository_path
,
computer_partition
[
"compute_partition_id"
]
+
".key"
)
if
os
.
path
.
exists
(
partition_certificate_file
)
and
os
.
path
.
exists
(
partition_key_file
):
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
],
cert_key
=
(
partition_certificate_file
,
partition_key_file
))
else
:
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
])
try
:
try
:
# Process the partition itself
# Process the partition itself
self
.
processComputerPartition
(
computer_partition
)
self
.
processComputerPartition
(
computer_partition
)
...
@@ -1637,14 +1462,14 @@ stderr_logfile_backups=1
...
@@ -1637,14 +1462,14 @@ stderr_logfile_backups=1
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
PromiseError
as
exc
:
except
PromiseError
as
exc
:
clean_run_promise
=
False
clean_run_promise
=
False
try
:
try
:
self
.
logger
.
error
(
exc
)
self
.
logger
.
error
(
exc
)
self
.
sendPartitionError
(
computer_partition
,
exc
,
logger
=
self
.
logger
)
computer_partition
.
error
(
exc
,
logger
=
self
.
logger
)
promise_error_partition_list
.
append
((
computer_partition
,
exc
))
promise_error_partition_list
.
append
((
computer_partition
,
exc
))
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
...
@@ -1658,7 +1483,7 @@ stderr_logfile_backups=1
...
@@ -1658,7 +1483,7 @@ stderr_logfile_backups=1
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
self
.
logger
.
exception
(
''
)
self
.
logger
.
exception
(
''
)
try
:
try
:
self
.
sendPartitionError
(
computer_partition
,
exc
,
logger
=
self
.
logger
)
computer_partition
.
error
(
exc
,
logger
=
self
.
logger
)
process_error_partition_list
.
append
((
computer_partition
,
exc
))
process_error_partition_list
.
append
((
computer_partition
,
exc
))
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
...
@@ -1668,8 +1493,9 @@ stderr_logfile_backups=1
...
@@ -1668,8 +1493,9 @@ stderr_logfile_backups=1
def
getPartitionType
(
part
):
def
getPartitionType
(
part
):
"""returns the partition type, if known at that point.
"""returns the partition type, if known at that point.
"""
"""
software_type
=
partition
.
get
(
"software_type"
,
None
)
try
:
if
software_type
is
None
:
return
part
.
getType
()
except
slapos
.
slap
.
ResourceNotReady
:
return
'(not ready)'
return
'(not ready)'
self
.
logger
.
info
(
'Finished computer partitions.'
)
self
.
logger
.
info
(
'Finished computer partitions.'
)
...
@@ -1677,11 +1503,11 @@ stderr_logfile_backups=1
...
@@ -1677,11 +1503,11 @@ stderr_logfile_backups=1
if
process_error_partition_list
:
if
process_error_partition_list
:
self
.
logger
.
info
(
'Error while processing the following partitions:'
)
self
.
logger
.
info
(
'Error while processing the following partitions:'
)
for
partition
,
exc
in
process_error_partition_list
:
for
partition
,
exc
in
process_error_partition_list
:
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
(
"compute_partition_id"
),
getPartitionType
(
partition
),
exc
)
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
Id
(
),
getPartitionType
(
partition
),
exc
)
if
promise_error_partition_list
:
if
promise_error_partition_list
:
self
.
logger
.
info
(
'Error with promises for the following partitions:'
)
self
.
logger
.
info
(
'Error with promises for the following partitions:'
)
for
partition
,
exc
in
promise_error_partition_list
:
for
partition
,
exc
in
promise_error_partition_list
:
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
(
"compute_partition_id"
),
getPartitionType
(
partition
),
exc
)
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
Id
(
),
getPartitionType
(
partition
),
exc
)
# Return success value
# Return success value
if
not
clean_run
:
if
not
clean_run
:
...
@@ -1750,8 +1576,6 @@ stderr_logfile_backups=1
...
@@ -1750,8 +1576,6 @@ stderr_logfile_backups=1
promise_error_partition_list
=
[]
promise_error_partition_list
=
[]
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
if
not
self
.
api_backward_compatibility
:
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
])
try
:
try
:
# Process the partition itself
# Process the partition itself
self
.
processPromise
(
computer_partition
)
self
.
processPromise
(
computer_partition
)
...
@@ -1767,14 +1591,15 @@ stderr_logfile_backups=1
...
@@ -1767,14 +1591,15 @@ stderr_logfile_backups=1
def
getPartitionType
(
part
):
def
getPartitionType
(
part
):
"""returns the partition type, if known at that point.
"""returns the partition type, if known at that point.
"""
"""
software_type
=
partition
.
get
(
"software_type"
,
None
)
try
:
if
software_type
is
None
:
return
part
.
getType
()
except
slapos
.
slap
.
ResourceNotReady
:
return
'(not ready)'
return
'(not ready)'
if
promise_error_partition_list
:
if
promise_error_partition_list
:
self
.
logger
.
info
(
'Finished computer partitions.'
)
self
.
logger
.
info
(
'Finished computer partitions.'
)
for
partition
,
exc
in
promise_error_partition_list
:
for
partition
,
exc
in
promise_error_partition_list
:
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
(
"compute_partition_id"
),
getPartitionType
(
partition
),
exc
)
self
.
logger
.
info
(
' %s[%s]: %s'
,
partition
.
get
Id
(
),
getPartitionType
(
partition
),
exc
)
# Return success value
# Return success value
if
not
clean_run_promise
:
if
not
clean_run_promise
:
...
@@ -1867,6 +1692,7 @@ stderr_logfile_backups=1
...
@@ -1867,6 +1692,7 @@ stderr_logfile_backups=1
self
.
checkEnvironmentAndCreateStructure
()
self
.
checkEnvironmentAndCreateStructure
()
self
.
_launchSupervisord
()
self
.
_launchSupervisord
()
slap_computer_usage
=
self
.
slap
.
registerComputer
(
self
.
computer_id
)
computer_partition_usage_list
=
[]
computer_partition_usage_list
=
[]
self
.
logger
.
info
(
'Aggregating and sending usage reports...'
)
self
.
logger
.
info
(
'Aggregating and sending usage reports...'
)
...
@@ -1896,11 +1722,11 @@ stderr_logfile_backups=1
...
@@ -1896,11 +1722,11 @@ stderr_logfile_backups=1
clean_run
=
True
clean_run
=
True
# Loop over the different computer partitions
# Loop over the different computer partitions
computer_partition_list
=
self
.
FilterComputerPartitionList
(
computer_partition_list
=
self
.
FilterComputerPartitionList
(
s
elf
.
getComputerPartitionList
())
s
lap_computer_usage
.
getComputerPartitionList
())
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
try
:
try
:
computer_partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
computer_partition_id
=
computer_partition
.
get
Id
(
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
...
@@ -1937,18 +1763,18 @@ stderr_logfile_backups=1
...
@@ -1937,18 +1763,18 @@ stderr_logfile_backups=1
failed_script_list
.
append
(
"Script %r failed."
%
script
)
failed_script_list
.
append
(
"Script %r failed."
%
script
)
self
.
logger
.
warning
(
'Failed to run %r'
%
invocation_list
)
self
.
logger
.
warning
(
'Failed to run %r'
%
invocation_list
)
if
len
(
failed_script_list
):
if
len
(
failed_script_list
):
self
.
sendPartitionError
(
computer_partition
,
'
\
n
'
.
join
(
failed_script_list
),
logger
=
self
.
logger
)
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
),
logger
=
self
.
logger
)
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
self
.
logger
.
exception
(
'Cannot run usage script(s) for %r:'
%
self
.
logger
.
exception
(
'Cannot run usage script(s) for %r:'
%
computer_partition
.
get
(
"compute_partition_id"
))
computer_partition
.
get
Id
(
))
# Now we loop through the different computer partitions to report
# Now we loop through the different computer partitions to report
report_usage_issue_cp_list
=
[]
report_usage_issue_cp_list
=
[]
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
try
:
try
:
filename_delete_list
=
[]
filename_delete_list
=
[]
computer_partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
computer_partition_id
=
computer_partition
.
get
Id
(
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition_id
)
dir_report_list
=
[
os
.
path
.
join
(
instance_path
,
'var'
,
'xml_report'
),
dir_report_list
=
[
os
.
path
.
join
(
instance_path
,
'var'
,
'xml_report'
),
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'xml_report'
,
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'xml_report'
,
...
@@ -1993,7 +1819,7 @@ stderr_logfile_backups=1
...
@@ -1993,7 +1819,7 @@ stderr_logfile_backups=1
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
self
.
logger
.
exception
(
'Cannot run usage script(s) for %r:'
%
self
.
logger
.
exception
(
'Cannot run usage script(s) for %r:'
%
computer_partition
.
get
(
"compute_partition_id"
))
computer_partition
.
get
Id
(
))
for
computer_partition_usage
in
computer_partition_usage_list
:
for
computer_partition_usage
in
computer_partition_usage_list
:
self
.
logger
.
info
(
'computer_partition_usage_list: %s - %s'
%
self
.
logger
.
info
(
'computer_partition_usage_list: %s - %s'
%
...
@@ -2019,7 +1845,7 @@ stderr_logfile_backups=1
...
@@ -2019,7 +1845,7 @@ stderr_logfile_backups=1
if
self
.
validateXML
(
usage
,
computer_consumption_model
):
if
self
.
validateXML
(
usage
,
computer_consumption_model
):
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
s
elf
.
computer
.
reportUsage
(
usage
)
s
lap_computer_usage
.
reportUsage
(
usage
)
filename_delete_list
.
append
(
filename
)
filename_delete_list
.
append
(
filename
)
else
:
else
:
self
.
logger
.
info
(
'XML file is invalid %s'
%
file_path
)
self
.
logger
.
info
(
'XML file is invalid %s'
%
file_path
)
...
@@ -2039,42 +1865,37 @@ stderr_logfile_backups=1
...
@@ -2039,42 +1865,37 @@ stderr_logfile_backups=1
# We test the XML report before sending it
# We test the XML report before sending it
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
s
elf
.
computer
.
reportUsage
(
computer_consumption
)
s
lap_computer_usage
.
reportUsage
(
computer_consumption
)
else
:
else
:
self
.
logger
.
info
(
'XML file generated by asXML is not valid !'
)
self
.
logger
.
info
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
except
Exception
:
except
Exception
:
issue
=
"Cannot report usage for %r: %s"
%
(
issue
=
"Cannot report usage for %r: %s"
%
(
computer_partition
.
get
(
"compute_partition_id"
),
computer_partition
.
get
Id
(
),
traceback
.
format_exc
())
traceback
.
format_exc
())
self
.
logger
.
info
(
issue
)
self
.
logger
.
info
(
issue
)
self
.
sendPartitionError
(
computer_partition
,
issue
,
logger
=
self
.
logger
)
computer_partition
.
error
(
issue
,
logger
=
self
.
logger
)
report_usage_issue_cp_list
.
append
(
computer_partition_id
)
report_usage_issue_cp_list
.
append
(
computer_partition_id
)
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
if
computer_partition
.
get
(
"state"
)
==
COMPUTER_PARTITION_DESTROYED_STATE
:
if
computer_partition
.
get
State
(
)
==
COMPUTER_PARTITION_DESTROYED_STATE
:
destroyed
=
False
destroyed
=
False
try
:
try
:
computer_partition_id
=
computer_partition
.
get
(
"compute_partition_id"
)
computer_partition_id
=
computer_partition
.
getId
()
software_url
=
computer_partition
.
get
(
"software_release_uri"
)
try
:
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
except
TypeError
:
except
(
NotFoundError
,
TypeError
):
# Problem with instance: SR URI not set.
software_url
=
None
# Try to process it anyway, it may need to be deleted.
software_path
=
None
software_path
=
None
if
not
self
.
api_backward_compatibility
:
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
])
local_partition
=
Partition
(
local_partition
=
Partition
(
software_path
=
software_path
,
software_path
=
software_path
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
get
(
"compute_partition_id"
)),
computer_partition
.
get
Id
(
)),
shared_part_list
=
self
.
shared_part_list
,
shared_part_list
=
self
.
shared_part_list
,
supervisord_partition_configuration_path
=
os
.
path
.
join
(
supervisord_partition_configuration_dir
=
(
_getSupervisordConfigurationDirectory
(
self
.
instance_root
),
'%s.conf'
%
_getSupervisordConfigurationDirectory
(
self
.
instance_root
)),
computer_partition_id
),
supervisord_socket
=
self
.
supervisord_socket
,
supervisord_socket
=
self
.
supervisord_socket
,
computer_partition
=
computer_partition
,
computer_partition
=
computer_partition
,
computer_id
=
self
.
computer_id
,
computer_id
=
self
.
computer_id
,
...
@@ -2087,21 +1908,13 @@ stderr_logfile_backups=1
...
@@ -2087,21 +1908,13 @@ stderr_logfile_backups=1
logger
=
self
.
logger
,
logger
=
self
.
logger
,
instance_storage_home
=
self
.
instance_storage_home
,
instance_storage_home
=
self
.
instance_storage_home
,
ipv4_global_network
=
self
.
ipv4_global_network
,
ipv4_global_network
=
self
.
ipv4_global_network
,
api_backward_compatibility
=
self
.
api_backward_compatibility
,
)
)
local_partition
.
stop
()
local_partition
.
stop
()
local_partition
.
_updateCertificate
(
self
.
retrieveCertificates
(
computer_partition
)
)
local_partition
.
_updateCertificate
()
try
:
try
:
if
not
self
.
api_backward_compatibility
:
computer_partition
.
stopped
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"stopped"
})
else
:
computer_partition
[
"slap_partition"
].
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
Exception
:
except
Exception
:
pass
pass
...
@@ -2109,9 +1922,9 @@ stderr_logfile_backups=1
...
@@ -2109,9 +1922,9 @@ stderr_logfile_backups=1
for
manager
in
self
.
_manager_list
:
for
manager
in
self
.
_manager_list
:
manager
.
report
(
local_partition
)
manager
.
report
(
local_partition
)
if
computer_partition
.
get
(
"compute_partition_id"
)
in
report_usage_issue_cp_list
:
if
computer_partition
.
get
Id
(
)
in
report_usage_issue_cp_list
:
self
.
logger
.
info
(
'Ignoring destruction of %r, as no report usage was sent'
%
self
.
logger
.
info
(
'Ignoring destruction of %r, as no report usage was sent'
%
computer_partition
.
get
(
"compute_partition_id"
))
computer_partition
.
get
Id
(
))
continue
continue
if
self
.
_checkWaitProcessList
(
local_partition
,
if
self
.
_checkWaitProcessList
(
local_partition
,
state_list
=
[
'RUNNING'
,
'STARTING'
]):
state_list
=
[
'RUNNING'
,
'STARTING'
]):
...
@@ -2120,31 +1933,24 @@ stderr_logfile_backups=1
...
@@ -2120,31 +1933,24 @@ stderr_logfile_backups=1
continue
continue
destroyed
=
local_partition
.
destroy
()
destroyed
=
local_partition
.
destroy
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
computer_partition
.
error
(
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
raise
except
Exception
:
except
Exception
:
clean_run
=
False
clean_run
=
False
self
.
logger
.
exception
(
''
)
self
.
logger
.
exception
(
''
)
exc
=
traceback
.
format_exc
()
exc
=
traceback
.
format_exc
()
self
.
sendPartitionError
(
computer_partition
,
exc
,
logger
=
self
.
logger
)
computer_partition
.
error
(
exc
,
logger
=
self
.
logger
)
try
:
try
:
if
destroyed
:
if
destroyed
:
if
not
self
.
api_backward_compatibility
:
computer_partition
.
destroyed
()
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"destroyed"
})
else
:
computer_partition
[
"slap_partition"
].
destroyed
()
except
NotFoundError
:
except
NotFoundError
:
self
.
logger
.
debug
(
'Ignored slap error while trying to inform about '
self
.
logger
.
debug
(
'Ignored slap error while trying to inform about '
'destroying not fully configured Computer Partition %r'
%
'destroying not fully configured Computer Partition %r'
%
computer_partition
.
get
(
"compute_partition_id"
))
computer_partition
.
get
Id
(
))
except
ServerError
as
server_error
:
except
ServerError
as
server_error
:
self
.
logger
.
debug
(
'Ignored server error while trying to inform about '
self
.
logger
.
debug
(
'Ignored server error while trying to inform about '
'destroying Computer Partition %r. Error is:
\
n
%r'
%
'destroying Computer Partition %r. Error is:
\
n
%r'
%
(
computer_partition
.
get
(
"compute_partition_id"
),
server_error
.
args
[
0
]))
(
computer_partition
.
get
Id
(
),
server_error
.
args
[
0
]))
self
.
logger
.
info
(
'Finished usage reports.'
)
self
.
logger
.
info
(
'Finished usage reports.'
)
...
...
slapos/grid/templates/buildout-tail.cfg.in
View file @
3a98bda4
...
@@ -15,7 +15,6 @@ key-file = %(key_file)s
...
@@ -15,7 +15,6 @@ key-file = %(key_file)s
cert-file = %(cert_file)s
cert-file = %(cert_file)s
shared-part-list =
shared-part-list =
%(shared_part_list)s
%(shared_part_list)s
software-instance-reference = %(software_instance_reference)s
[slap_connection]
[slap_connection]
# Kept for backward compatiblity
# Kept for backward compatiblity
...
@@ -32,11 +31,3 @@ storage-home = %(storage_home)s
...
@@ -32,11 +31,3 @@ storage-home = %(storage_home)s
[network-information]
[network-information]
global-ipv4-network = %(global_ipv4_network_prefix)s
global-ipv4-network = %(global_ipv4_network_prefix)s
# This is end of zc.buildout profile's tail added by slapgrid
# This is end of zc.buildout profile's tail added by slapgrid
[software-instance-data]
state = %(instance_state)s
software-type = %(instance_software_type)s
reference = %(software_instance_reference)s
processing-timestamp = %(instance_processing_timestamp)s
connection-parameters-md5sum = %(connection_parameters_md5sum)s
parameters-md5sum = %(parameters_md5sum)s
slapos/grid/watchdog.py
View file @
3a98bda4
...
@@ -187,26 +187,6 @@ class Watchdog(object):
...
@@ -187,26 +187,6 @@ class Watchdog(object):
def
handle_process_state_change_event
(
self
,
headers
,
payload_dict
):
def
handle_process_state_change_event
(
self
,
headers
,
payload_dict
):
partition_id
=
payload_dict
[
'groupname'
]
partition_id
=
payload_dict
[
'groupname'
]
self
.
initialize_connection
(
partition_id
)
self
.
initialize_connection
(
partition_id
)
if
self
.
slap
.
jio_api_connector
:
instance_list
=
self
.
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
self
.
computer_id
,
"compute_partition_id"
:
partition_id
,
}).
get
(
"result_list"
,
[])
if
len
(
instance_list
)
!=
1
:
raise
ValueError
(
"No instance found for %s %s %s"
%
(
self
.
computer_id
,
partition_id
,
instance_list
,
))
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reported_state"
:
"bang"
,
"status_message"
:
"%s process in partition %s encountered a problem"
%
(
payload_dict
[
'processname'
],
partition_id
),
"reference"
:
instance_list
[
0
][
"reference"
]
})
else
:
partition
=
slapos
.
slap
.
ComputerPartition
(
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
=
self
.
computer_id
,
computer_id
=
self
.
computer_id
,
connection_helper
=
self
.
slap
.
_connection_helper
,
connection_helper
=
self
.
slap
.
_connection_helper
,
...
...
slapos/manager/portredir.py
View file @
3a98bda4
...
@@ -82,8 +82,9 @@ class Manager(object):
...
@@ -82,8 +82,9 @@ class Manager(object):
# Get partitions IPv6 address
# Get partitions IPv6 address
computer_partition
=
partition
.
computer_partition
computer_partition
=
partition
.
computer_partition
parameter_dict
=
computer_partition
.
getInstanceParameterDict
()
partition_ip_list
=
computer_partition
[
'ip_list'
]
+
computer_partition
.
get
(
partition_ip_list
=
parameter_dict
[
'ip_list'
]
+
parameter_dict
.
get
(
'full_ip_list'
,
[])
'full_ip_list'
,
[])
partition_ip_list
=
[
tup
[
1
]
for
tup
in
partition_ip_list
]
partition_ip_list
=
[
tup
[
1
]
for
tup
in
partition_ip_list
]
...
...
slapos/slap/hateoas.py
View file @
3a98bda4
...
@@ -60,42 +60,6 @@ ALLOWED_JIO_FIELD_LIST = [
...
@@ -60,42 +60,6 @@ ALLOWED_JIO_FIELD_LIST = [
"FloatField"
,
"FloatField"
,
"TextAreaField"
]
"TextAreaField"
]
# https://stackoverflow.com/a/33571117
def
_byteify
(
data
,
ignore_dicts
=
False
):
if
isinstance
(
data
,
str
):
return
data
# if this is a list of values, return list of byteified values
if
isinstance
(
data
,
list
):
return
[
_byteify
(
item
,
ignore_dicts
=
True
)
for
item
in
data
]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if
isinstance
(
data
,
dict
)
and
not
ignore_dicts
:
return
{
_byteify
(
key
,
ignore_dicts
=
True
):
_byteify
(
value
,
ignore_dicts
=
True
)
for
key
,
value
in
data
.
items
()
# changed to .items() for python 2.7/3
}
# python 3 compatible duck-typing
# if this is a unicode string, return its string representation
if
str
(
type
(
data
))
==
"<type 'unicode'>"
:
return
data
.
encode
(
'utf-8'
)
# if it's anything else, return it in its original form
return
data
def
json_loads_byteified
(
json_text
):
"""
Encode string when loading JSON
"""
return
_byteify
(
json
.
loads
(
json_text
,
object_hook
=
_byteify
),
ignore_dicts
=
True
)
class
TempDocument
(
object
):
class
TempDocument
(
object
):
def
__init__
(
self
,
**
kw
):
def
__init__
(
self
,
**
kw
):
"""
"""
...
@@ -122,8 +86,7 @@ class ConnectionHelper:
...
@@ -122,8 +86,7 @@ class ConnectionHelper:
self
.
session
=
CacheControl
(
self
.
uncached_session
,
self
.
session
=
CacheControl
(
self
.
uncached_session
,
cache
=
FileCache
(
os
.
path
.
expanduser
(
"~/.slapos_cached_get"
)))
cache
=
FileCache
(
os
.
path
.
expanduser
(
"~/.slapos_cached_get"
)))
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
,
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
):
expect_json_error
=
False
,
cert_key
=
None
):
url
=
parse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
url
=
parse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
if
headers
is
None
:
if
headers
is
None
:
headers
=
{}
headers
=
{}
...
@@ -133,22 +96,24 @@ class ConnectionHelper:
...
@@ -133,22 +96,24 @@ class ConnectionHelper:
# raise ValueError('method path should be relative: %s' % path)
# raise ValueError('method path should be relative: %s' % path)
try
:
try
:
if
url
.
startswith
(
'https'
)
and
cert_key
is
None
:
if
url
.
startswith
(
'https'
):
cert_key
=
(
self
.
cert_file
,
self
.
key_file
)
cert
=
(
self
.
cert_file
,
self
.
key_file
)
else
:
cert
=
None
# XXX TODO: handle host cert verify
# XXX TODO: handle host cert verify
# Old behavior was to pass empty parameters as "None" value.
# Old behavior was to pass empty parameters as "None" value.
# Behavior kept for compatibility with old slapproxies (< v1.3.3).
# Behavior kept for compatibility with old slapproxies (< v1.3.3).
# Can be removed when old slapproxies are no longer in use.
# Can be removed when old slapproxies are no longer in use.
if
data
and
isinstance
(
data
,
dict
)
:
if
data
:
for
k
,
v
in
six
.
iteritems
(
data
):
for
k
,
v
in
six
.
iteritems
(
data
):
if
v
is
None
:
if
v
is
None
:
data
[
k
]
=
'None'
data
[
k
]
=
'None'
req
=
method
(
url
=
url
,
req
=
method
(
url
=
url
,
params
=
params
,
params
=
params
,
cert
=
cert
_key
,
cert
=
cert
,
verify
=
False
,
verify
=
False
,
data
=
data
,
data
=
data
,
headers
=
headers
,
headers
=
headers
,
...
@@ -166,8 +131,6 @@ class ConnectionHelper:
...
@@ -166,8 +131,6 @@ class ConnectionHelper:
"enabled on your machine and that the server is available. The "
"enabled on your machine and that the server is available. The "
"original error was:
\
n
%s"
%
exc
)
"original error was:
\
n
%s"
%
exc
)
except
requests
.
HTTPError
as
exc
:
except
requests
.
HTTPError
as
exc
:
if
expect_json_error
and
not
int
(
exc
.
response
.
status_code
)
>=
500
:
return
req
if
exc
.
response
.
status_code
==
requests
.
status_codes
.
codes
.
not_found
:
if
exc
.
response
.
status_code
==
requests
.
status_codes
.
codes
.
not_found
:
msg
=
url
msg
=
url
if
params
:
if
params
:
...
@@ -193,15 +156,21 @@ class ConnectionHelper:
...
@@ -193,15 +156,21 @@ class ConnectionHelper:
return
req
return
req
def
callJsonRpcAPI
(
self
,
path
,
data
,
cert_key
=
None
):
def
GET
(
self
,
path
,
params
=
None
,
headers
=
None
):
req
=
self
.
do_request
(
requests
.
pos
t
,
req
=
self
.
do_request
(
self
.
session
.
ge
t
,
path
=
path
,
path
=
path
,
data
=
json
.
dumps
(
data
),
params
=
params
,
headers
=
{
'Content-type'
:
'application/json'
},
headers
=
headers
)
expect_json_error
=
True
,
return
req
.
text
.
encode
(
'utf-8'
)
cert_key
=
cert_key
)
return
json_loads_byteified
(
req
.
text
)
def
POST
(
self
,
path
,
params
=
None
,
data
=
None
,
content_type
=
'application/x-www-form-urlencoded'
):
req
=
self
.
do_request
(
requests
.
post
,
path
=
path
,
params
=
params
,
data
=
data
,
headers
=
{
'Content-type'
:
content_type
})
return
req
.
text
.
encode
(
'utf-8'
)
class
HateoasNavigator
(
object
):
class
HateoasNavigator
(
object
):
"""
"""
...
...
slapos/slap/slap.py
View file @
3a98bda4
...
@@ -52,7 +52,7 @@ except ImportError: # XXX to be removed once we depend on typing
...
@@ -52,7 +52,7 @@ except ImportError: # XXX to be removed once we depend on typing
from
.exception
import
ResourceNotReady
,
ServerError
,
NotFoundError
,
\
from
.exception
import
ResourceNotReady
,
ServerError
,
NotFoundError
,
\
ConnectionError
ConnectionError
from
.hateoas
import
SlapHateoasNavigator
,
ConnectionHelper
,
json_loads_byteified
from
.hateoas
import
SlapHateoasNavigator
,
ConnectionHelper
from
slapos.util
import
(
SoftwareReleaseSchema
,
SoftwareReleaseSchemaValidationError
,
from
slapos.util
import
(
SoftwareReleaseSchema
,
SoftwareReleaseSchemaValidationError
,
bytes2str
,
calculate_dict_hash
,
dict2xml
,
dumps
,
loads
,
bytes2str
,
calculate_dict_hash
,
dict2xml
,
dumps
,
loads
,
unicode2str
,
xml2dict
)
unicode2str
,
xml2dict
)
...
@@ -762,9 +762,7 @@ class SlapConnectionHelper(ConnectionHelper):
...
@@ -762,9 +762,7 @@ class SlapConnectionHelper(ConnectionHelper):
return
loads
(
xml
)
return
loads
(
xml
)
getHateoasUrl_cache
=
{}
getHateoasUrl_cache
=
{}
getjIOAPI_cache
=
{}
@
implementer
(
interface
.
slap
)
@
implementer
(
interface
.
slap
)
class
slap
:
class
slap
:
...
@@ -775,6 +773,7 @@ class slap:
...
@@ -775,6 +773,7 @@ class slap:
slapgrid_rest_uri
=
None
):
slapgrid_rest_uri
=
None
):
if
master_ca_file
:
if
master_ca_file
:
raise
NotImplementedError
(
'Master certificate not verified in this version: %s'
%
master_ca_file
)
raise
NotImplementedError
(
'Master certificate not verified in this version: %s'
%
master_ca_file
)
self
.
_connection_helper
=
SlapConnectionHelper
(
self
.
_connection_helper
=
SlapConnectionHelper
(
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
...
...
slapos/tests/test_cli.py
View file @
3a98bda4
...
@@ -89,7 +89,6 @@ class CliMixin(unittest.TestCase):
...
@@ -89,7 +89,6 @@ class CliMixin(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
self
.
logger
=
create_autospec
(
logging
.
Logger
)
self
.
logger
=
create_autospec
(
logging
.
Logger
)
slap
.
initializeConnection
(
"http://127.0.0.1:80/"
)
self
.
local
=
{
'slap'
:
slap
,
'product'
:
SoftwareProductCollection
(
self
.
logger
,
slap
)}
self
.
local
=
{
'slap'
:
slap
,
'product'
:
SoftwareProductCollection
(
self
.
logger
,
slap
)}
self
.
conf
=
create_autospec
(
ClientConfig
)
self
.
conf
=
create_autospec
(
ClientConfig
)
self
.
sign_cert_list
=
signature_certificate_list
self
.
sign_cert_list
=
signature_certificate_list
...
...
slapos/tests/test_object.py
View file @
3a98bda4
...
@@ -149,6 +149,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -149,6 +149,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
self
,
self
,
software_release_url
,
software_release_url
,
partition_id
=
None
,
partition_id
=
None
,
slap_computer_partition
=
None
,
retention_delay
=
None
,
retention_delay
=
None
,
partition_timeout
=
None
,
partition_timeout
=
None
,
shared_part_list
=
''
,
shared_part_list
=
''
,
...
@@ -166,18 +167,10 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -166,18 +167,10 @@ class MasterMixin(BasicMixin, unittest.TestCase):
if
partition_id
is
None
:
if
partition_id
is
None
:
partition_id
=
'mypartition'
partition_id
=
'mypartition'
software_instance
=
{
if
slap_computer_partition
is
None
:
"reference"
:
partition_id
,
slap_computer_partition
=
SlapComputerPartition
(
"compute_node_id"
:
'bidon'
,
computer_id
=
'bidon'
,
"portal_type"
:
"Software Instance"
,
partition_id
=
partition_id
)
"compute_partition_id"
:
partition_id
,
"state"
:
"stopped"
,
"software_type"
:
None
,
"parameters"
:
{},
"processing_timestamp"
:
0
,
"ip_list"
:
[],
"full_ip_list"
:
[],
}
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
partition_id
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
partition_id
)
os
.
mkdir
(
instance_path
)
os
.
mkdir
(
instance_path
)
...
@@ -193,7 +186,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
...
@@ -193,7 +186,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
supervisord_partition_configuration_dir
=
supervisor_configuration_path
,
supervisord_partition_configuration_dir
=
supervisor_configuration_path
,
supervisord_socket
=
svcbackend
.
_getSupervisordSocketPath
(
supervisord_socket
=
svcbackend
.
_getSupervisordSocketPath
(
self
.
instance_root
,
logging
.
getLogger
(
self
.
id
())),
self
.
instance_root
,
logging
.
getLogger
(
self
.
id
())),
computer_partition
=
s
oftware_instance
,
computer_partition
=
s
lap_computer_partition
,
computer_id
=
'bidon'
,
computer_id
=
'bidon'
,
partition_id
=
partition_id
,
partition_id
=
partition_id
,
server_url
=
'bidon'
,
server_url
=
'bidon'
,
...
...
slapos/tests/test_slapformat.py
View file @
3a98bda4
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
from
__future__
import
print_function
from
__future__
import
print_function
import
glob
import
glob
import
json
import
logging
import
logging
import
os
import
os
import
shutil
import
shutil
...
@@ -52,8 +51,6 @@ import os
...
@@ -52,8 +51,6 @@ import os
import
pwd
import
pwd
import
time
import
time
import
mock
import
mock
import
httmock
from
six.moves.urllib
import
parse
from
.test_slapgrid
import
DummyManager
from
.test_slapgrid
import
DummyManager
...
@@ -687,81 +684,6 @@ class TestFormatDump(SlapformatMixin):
...
@@ -687,81 +684,6 @@ class TestFormatDump(SlapformatMixin):
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
super
(
TestFormatDump
,
self
).
tearDown
()
super
(
TestFormatDump
,
self
).
tearDown
()
class
TestConfForAPI
():
def
__init__
(
self
):
self
.
master_url
=
"https://127.0.0.1"
self
.
key_file
=
None
self
.
cert_file
=
None
self
.
dry_run
=
False
class
TestFormatSendToMaster
(
SlapformatMixin
):
def
setUp
(
self
):
super
(
TestFormatSendToMaster
,
self
).
setUp
()
self
.
restoreOs
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
sequence
=
[]
self
.
body_sequence
=
[]
def
jio_api_request_handler
(
self
,
url
,
req
):
self
.
sequence
.
append
(
url
.
path
)
if
req
.
method
==
'GET'
:
qs
=
parse
.
parse_qs
(
url
.
query
)
else
:
qs
=
parse
.
parse_qs
(
req
.
body
)
if
url
.
path
.
startswith
(
'/api/'
):
content
=
json
.
loads
(
req
.
body
)
self
.
body_sequence
.
append
(
content
)
return
json
.
dumps
({})
def
test
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
instance_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance_root'
),
software_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'software_root'
),
tap_ipv6
=
True
,
interface
=
slapos
.
format
.
Interface
(
logger
=
self
.
logger
,
name
=
'myinterface'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
global
INTERFACE_DICT
INTERFACE_DICT
[
'myinterface'
]
=
{
socket
.
AF_INET
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
'netmask'
:
'255.255.255.0'
}],
socket
.
AF_INET6
:
[{
'addr'
:
'2a01:e35:2e27::e59c'
,
'netmask'
:
'ffff:ffff:ffff:ffff::'
}]
}
computer
.
format
(
alter_user
=
False
,
alter_network
=
False
,
create_tap
=
False
)
test_configuration
=
TestConfForAPI
()
with
httmock
.
HTTMock
(
self
.
jio_api_request_handler
):
computer
.
send
(
test_configuration
)
self
.
assertEqual
(
self
.
sequence
,
[
'/getHateoasUrl'
,
'/api/put/'
])
self
.
assertEqual
(
self
.
body_sequence
,
[
{
'portal_type'
:
'Compute Node'
,
'compute_node_id'
:
'computer'
,
'compute_partition_list'
:
[
{
'ip_list'
:
[
{
'ip-address'
:
computer
.
partition_list
[
0
].
address_list
[
0
][
"addr"
],
'network-interface'
:
'tap'
},
{
'ip-address'
:
computer
.
partition_list
[
0
].
address_list
[
1
][
"addr"
],
'network-interface'
:
'tap'
}
],
'partition_id'
:
'partition'
}
]
}
]
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
super
(
TestFormatSendToMaster
,
self
).
tearDown
()
class
SlapGridPartitionMock
:
class
SlapGridPartitionMock
:
...
...
slapos/tests/test_slapgrid.py
View file @
3a98bda4
...
@@ -194,9 +194,7 @@ class BasicMixin(object):
...
@@ -194,9 +194,7 @@ class BasicMixin(object):
logger
=
logging
.
getLogger
(),
logger
=
logging
.
getLogger
(),
shared_part_list
=
self
.
shared_parts_root
,
shared_part_list
=
self
.
shared_parts_root
,
force_stop
=
force_stop
,
force_stop
=
force_stop
,
certificate_repository_path
=
self
.
certificate_repository_path
,
certificate_repository_path
=
self
.
certificate_repository_path
)
)
self
.
use_jio_api
=
True
self
.
grid
.
_manager_list
=
self
.
manager_list
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
# monkey patch buildout bootstrap
...
@@ -263,16 +261,6 @@ class BasicMixin(object):
...
@@ -263,16 +261,6 @@ class BasicMixin(object):
instance_list
.
append
(
'sv.sock'
)
instance_list
.
append
(
'sv.sock'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
instance_root
),
instance_list
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
instance_root
),
instance_list
)
def
assertSoftwareInstanceJSONIsCorrect
(
self
,
partition_path
,
instance
):
json_path
=
os
.
path
.
join
(
partition_path
,
'.software-instance.json'
)
self
.
assertTrue
(
os
.
path
.
exists
(
json_path
))
with
open
(
json_path
,
"r"
)
as
f
:
json_data
=
json
.
load
(
f
)
self
.
maxDiff
=
1000
# XXx CLN Hackish
instance
.
pop
(
"access_status_message"
,
None
)
self
.
assertEqual
(
json_data
,
instance
)
def
tearDown
(
self
):
def
tearDown
(
self
):
# XXX: Hardcoded pid, as it is not configurable in slapos
# XXX: Hardcoded pid, as it is not configurable in slapos
svc
=
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
,
'supervisord.pid'
)
svc
=
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
,
'supervisord.pid'
)
...
@@ -393,6 +381,7 @@ class MasterMixin(BasicMixin):
...
@@ -393,6 +381,7 @@ class MasterMixin(BasicMixin):
self
.
_unmock_sleep
()
self
.
_unmock_sleep
()
BasicMixin
.
tearDown
(
self
)
BasicMixin
.
tearDown
(
self
)
class
ComputerForTest
(
object
):
class
ComputerForTest
(
object
):
"""
"""
Class to set up environment for tests setting instance, software
Class to set up environment for tests setting instance, software
...
@@ -408,7 +397,6 @@ class ComputerForTest(object):
...
@@ -408,7 +397,6 @@ class ComputerForTest(object):
Will set up instances, software and sequence
Will set up instances, software and sequence
"""
"""
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
body_sequence
=
[]
self
.
instance_amount
=
instance_amount
self
.
instance_amount
=
instance_amount
self
.
software_amount
=
software_amount
self
.
software_amount
=
software_amount
self
.
software_root
=
software_root
self
.
software_root
=
software_root
...
@@ -438,233 +426,75 @@ class ComputerForTest(object):
...
@@ -438,233 +426,75 @@ class ComputerForTest(object):
qs
=
parse
.
parse_qs
(
url
.
query
)
qs
=
parse
.
parse_qs
(
url
.
query
)
else
:
else
:
qs
=
parse
.
parse_qs
(
req
.
body
)
qs
=
parse
.
parse_qs
(
req
.
body
)
if
(
url
.
path
==
'/getFullComputerInformation'
# Catch API calls
and
'computer_id'
in
qs
):
if
url
.
path
.
startswith
(
'/api/'
):
slap_computer
=
self
.
getComputer
(
qs
[
'computer_id'
][
0
])
content
=
json
.
loads
(
req
.
body
)
return
{
self
.
body_sequence
.
append
(
content
)
'status_code'
:
self
.
status_code
,
if
(
url
.
path
==
'/api/allDocs/'
):
'content'
:
dumps
(
slap_computer
)
if
content
[
"portal_type"
]
==
"Software Installation"
:
return
json
.
dumps
({
"current_page_full"
:
False
,
"next_page_request"
:
{
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
content
[
"compute_node_id"
],
},
"result_list"
:
[{
"software_release_uri"
:
x
.
name
,
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
content
[
"compute_node_id"
],
"state"
:
x
.
requested_state
,
"api_revision"
:
"12121"
,
"get_parameters"
:
{
"software_release_uri"
:
x
.
name
,
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
content
[
"compute_node_id"
],
}
}
for
x
in
self
.
software_list
]
})
if
content
[
"portal_type"
]
==
"Software Instance"
:
if
"compute_node_id"
in
content
:
if
"compute_partition_id"
in
content
:
return
json
.
dumps
({
"current_page_full"
:
False
,
"next_page_request"
:
{
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
content
[
"compute_partition_id"
],
},
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
,
"api_revision"
:
"12132"
,
"get_parameters"
:
{
"portal_type"
:
"Software Instance"
,
"reference"
:
x
.
name
,
}
}
for
x
in
self
.
instance_list
if
x
.
name
==
content
[
"compute_partition_id"
]]
})
else
:
return
json
.
dumps
({
"current_page_full"
:
False
,
"next_page_request"
:
{
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
content
[
"compute_node_id"
],
},
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
,
"get_parameters"
:
{
"portal_type"
:
"Software Instance"
,
"reference"
:
x
.
name
,
}
}
}
for
x
in
self
.
instance_list
]
elif
url
.
path
==
'/getHostingSubscriptionIpList'
:
})
ip_address_list
=
self
.
ip_address_list
elif
"root_instance_title"
in
content
:
return
{
return
json
.
dumps
({
'status_code'
:
self
.
status_code
,
"current_page_full"
:
False
,
'content'
:
dumps
(
ip_address_list
)
"next_page_request"
:
{
"portal_type"
:
"Software Instance"
,
"root_instance_title"
:
content
[
"root_instance_title"
],
},
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
,
"get_parameters"
:
{
"portal_type"
:
"Software Instance"
,
"reference"
:
x
.
name
,
},
}
for
x
in
self
.
instance_list
]
+
[
{
"software_release_uri"
:
"foo.cfg"
,
"reference"
:
"related_instance"
,
"title"
:
"related_instance"
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
"related_instance"
,
"state"
:
"stopped"
,
"get_parameters"
:
{
"portal_type"
:
"Software Instance"
,
"reference"
:
"related_instance"
,
}
}
elif
url
.
path
==
'/getComputerPartitionCertificate'
:
return
{
'status_code'
:
self
.
status_code
,
'content'
:
dumps
({
'certificate'
:
'SLAPOS_cert'
,
'key'
:
'SLAPOS_key'
})
}
}
if
req
.
method
==
'POST'
and
'computer_partition_id'
in
qs
:
instance
=
self
.
instance_list
[
int
(
qs
[
'computer_partition_id'
][
0
])]
instance
.
sequence
.
append
(
url
.
path
)
instance
.
header_list
.
append
(
req
.
headers
)
if
url
.
path
==
'/startedComputerPartition'
:
instance
.
state
=
'started'
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/stoppedComputerPartition'
:
instance
.
state
=
'stopped'
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/destroyedComputerPartition'
:
instance
.
state
=
'destroyed'
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/softwareInstanceBang'
:
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
"/updateComputerPartitionRelatedInstanceList"
:
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/softwareInstanceError'
:
instance
.
error_log
=
'
\
n
'
.
join
(
[
line
for
line
in
qs
[
'error_log'
][
0
].
splitlines
()
if
'dropPrivileges'
not
in
line
]
]
})
)
instance
.
error
=
True
return
{
'status_code'
:
self
.
status_code
}
elif
(
url
.
path
==
'/api/put/'
)
:
elif
req
.
method
==
'POST'
and
'url'
in
qs
:
if
content
[
"portal_type"
]
==
"Software Installation"
:
# XXX hardcoded to first software release!
software
=
self
.
software_list
[
0
]
software
=
self
.
software_list
[
0
]
software
.
sequence
.
append
((
url
.
path
,
content
))
software
.
sequence
.
append
(
url
.
path
)
if
"error_status"
in
content
:
if
url
.
path
==
'/availableSoftwareRelease'
:
software
.
error_log
=
content
[
'error_status'
]
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/buildingSoftwareRelease'
:
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/destroyedSoftwareRelease'
:
return
{
'status_code'
:
self
.
status_code
}
if
url
.
path
==
'/softwareReleaseError'
:
software
.
error_log
=
'
\
n
'
.
join
(
[
line
for
line
in
qs
[
'error_log'
][
0
].
splitlines
()
if
'dropPrivileges'
not
in
line
]
)
software
.
error
=
True
software
.
error
=
True
return
{
'status_code'
:
self
.
status_code
}
return
json
.
dumps
({
"id"
:
content
[
"software_release_uri"
]})
elif
content
[
"portal_type"
]
==
"Software Instance"
:
reference
=
content
[
"reference"
]
requested_instance
=
None
for
instance
in
self
.
instance_list
:
if
instance
.
name
==
reference
:
requested_instance
=
instance
break
if
requested_instance
:
requested_instance
.
sequence
.
append
((
url
.
path
,
content
))
if
"reported_state"
in
content
:
if
content
[
"reported_state"
]
==
"error"
:
instance
.
error
=
True
instance
.
error_log
=
content
[
"status_message"
]
elif
content
[
"reported_state"
]
==
"bang"
:
instance
.
error_log
=
content
[
"status_message"
]
else
:
requested_instance
.
state
=
content
[
"reported_state"
]
return
json
.
dumps
({
"reference"
:
requested_instance
.
name
,
"portal_type"
:
"Software Instance"
,
"success"
:
"Done"
},
indent
=
2
)
if
"requested_instance_list"
in
content
:
return
json
.
dumps
({
"reference"
:
requested_instance
.
name
,
"portal_type"
:
"Software Instance"
,
"success"
:
"Done"
},
indent
=
2
)
else
:
else
:
return
json
.
dumps
({
return
{
'status_code'
:
500
}
"status"
:
"404"
,
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
})
elif
(
url
.
path
==
'/api/get/'
):
if
content
[
"portal_type"
]
==
"Software Instance"
:
reference
=
content
[
"reference"
]
# Treat the case of firewall
if
reference
==
"related_instance"
:
return
json
.
dumps
({
"title"
:
"related_instance"
,
"reference"
:
"related_instance"
,
"software_release_uri"
:
"foo.cfg"
,
"software_type"
:
None
,
"state"
:
"stopped"
,
"connection_parameters"
:
{
},
"parameters"
:
{},
"shared"
:
False
,
"root_instance_title"
:
"0"
,
"ip_list"
:
self
.
ip_address_list
,
"X509"
:
{
"certificate"
:
""
,
"key"
:
""
},
"sla_parameters"
:
{},
"compute_node_id"
:
None
,
"compute_partition_id"
:
"requested_instance"
,
"processing_timestamp"
:
0
,
"access_status_message"
:
""
,
"portal_type"
:
"Software Instance"
})
requested_instance
=
None
for
instance
in
self
.
instance_list
:
if
instance
.
name
==
reference
:
requested_instance
=
instance
break
if
requested_instance
:
requested_instance
.
sequence
.
append
((
url
.
path
,
content
))
return
json
.
dumps
({
"title"
:
requested_instance
.
name
,
"reference"
:
requested_instance
.
name
,
"software_release_uri"
:
requested_instance
.
software
.
name
,
"software_type"
:
None
,
"state"
:
requested_instance
.
requested_state
,
"connection_parameters"
:
{
},
"parameters"
:
{},
"shared"
:
False
,
"root_instance_title"
:
requested_instance
.
name
,
"ip_list"
:
requested_instance
.
ip_list
,
"full_ip_list"
:
requested_instance
.
full_ip_list
,
"sla_parameters"
:
requested_instance
.
filter_dict
,
"compute_node_id"
:
None
,
"compute_partition_id"
:
requested_instance
.
name
,
"processing_timestamp"
:
requested_instance
.
timestamp
,
"access_status_message"
:
requested_instance
.
error_log
,
"portal_type"
:
"Software Instance"
})
else
:
return
json
.
dumps
({
"status"
:
"404"
,
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
})
elif
content
[
"portal_type"
]
==
"Software Instance Certificate Record"
:
reference
=
content
[
"reference"
]
requested_instance
=
None
for
instance
in
self
.
instance_list
:
if
instance
.
name
==
reference
:
requested_instance
=
instance
break
if
requested_instance
:
# We don't need to check certificates are being retrieved
return
json
.
dumps
({
"reference"
:
requested_instance
.
name
,
"certificate"
:
requested_instance
.
certificate
,
"key"
:
requested_instance
.
key
,
"portal_type"
:
"Software Instance Certificate Record"
,
})
if
req
.
method
==
'GET'
:
if
url
.
path
==
"/getHateoasUrl"
:
return
""
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
def
getTestSoftwareClass
(
self
):
def
getTestSoftwareClass
(
self
):
return
SoftwareForTest
return
SoftwareForTest
...
@@ -729,13 +559,9 @@ class InstanceForTest(object):
...
@@ -729,13 +559,9 @@ class InstanceForTest(object):
self
.
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
self
.
name
)
self
.
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
self
.
name
)
os
.
mkdir
(
self
.
partition_path
,
0o750
)
os
.
mkdir
(
self
.
partition_path
,
0o750
)
self
.
timestamp
=
None
self
.
timestamp
=
None
self
.
ip_list
=
[[
'interface0'
,
'10.0.8.2'
]]
self
.
ip_list
=
[(
'interface0'
,
'10.0.8.2'
)]
self
.
full_ip_list
=
[[
'route_interface0'
,
'10.10.2.3'
,
'10.10.0.1'
,
self
.
full_ip_list
=
[(
'route_interface0'
,
'10.10.2.3'
,
'10.10.0.1'
,
'255.0.0.0'
,
'10.0.0.0'
]]
'255.0.0.0'
,
'10.0.0.0'
)]
self
.
certificate
=
str
(
random
.
random
())
self
.
key
=
str
(
random
.
random
())
self
.
filter_dict
=
{}
def
getInstance
(
self
,
computer_id
,
):
def
getInstance
(
self
,
computer_id
,
):
"""
"""
...
@@ -744,6 +570,7 @@ class InstanceForTest(object):
...
@@ -744,6 +570,7 @@ class InstanceForTest(object):
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
.
_software_release_document
=
self
.
getSoftwareRelease
()
partition
.
_software_release_document
=
self
.
getSoftwareRelease
()
partition
.
_requested_state
=
self
.
requested_state
partition
.
_requested_state
=
self
.
requested_state
if
getattr
(
self
,
'filter_dict'
,
None
):
partition
.
_filter_dict
=
self
.
filter_dict
partition
.
_filter_dict
=
self
.
filter_dict
partition
.
_parameter_dict
=
{
'ip_list'
:
self
.
ip_list
,
partition
.
_parameter_dict
=
{
'ip_list'
:
self
.
ip_list
,
'full_ip_list'
:
self
.
full_ip_list
'full_ip_list'
:
self
.
full_ip_list
...
@@ -755,28 +582,6 @@ class InstanceForTest(object):
...
@@ -755,28 +582,6 @@ class InstanceForTest(object):
self
.
current_partition
=
partition
self
.
current_partition
=
partition
return
partition
return
partition
def
asJSONText
(
self
):
return
{
"title"
:
self
.
name
,
"reference"
:
self
.
name
,
"software_release_uri"
:
self
.
software
.
name
,
"software_type"
:
None
,
"state"
:
self
.
requested_state
,
"connection_parameters"
:
{
},
"parameters"
:
{},
"shared"
:
False
,
"root_instance_title"
:
self
.
name
,
"ip_list"
:
self
.
ip_list
,
"full_ip_list"
:
self
.
full_ip_list
,
"sla_parameters"
:
self
.
filter_dict
,
"compute_node_id"
:
None
,
"compute_partition_id"
:
self
.
name
,
"processing_timestamp"
:
self
.
timestamp
,
"access_status_message"
:
self
.
error_log
,
"portal_type"
:
"Software Instance"
}
def
getSoftwareRelease
(
self
):
def
getSoftwareRelease
(
self
):
"""
"""
Return software release for Instance
Return software release for Instance
...
@@ -824,10 +629,12 @@ class InstanceForTest(object):
...
@@ -824,10 +629,12 @@ class InstanceForTest(object):
os
.
mkdir
(
certificate_repository_path
)
os
.
mkdir
(
certificate_repository_path
)
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
"%s.crt"
%
self
.
name
)
"%s.crt"
%
self
.
name
)
self
.
certificate
=
str
(
random
.
random
())
with
open
(
self
.
cert_file
,
'w'
)
as
f
:
with
open
(
self
.
cert_file
,
'w'
)
as
f
:
f
.
write
(
self
.
certificate
)
f
.
write
(
self
.
certificate
)
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
'%s.key'
%
self
.
name
)
'%s.key'
%
self
.
name
)
self
.
key
=
str
(
random
.
random
())
with
open
(
self
.
key_file
,
'w'
)
as
f
:
with
open
(
self
.
key_file
,
'w'
)
as
f
:
f
.
write
(
self
.
key
)
f
.
write
(
self
.
key
)
...
@@ -930,14 +737,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -930,14 +737,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'buildout.cfg'
,
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
[
'/getFullComputerInformation'
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
'/getComputerPartitionCertificate'
,
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
open
(
os
.
path
.
join
(
self
.
certificate_repository_path
,
'0.crt'
)).
read
(),
'SLAPOS_cert'
)
self
.
assertEqual
(
open
(
os
.
path
.
join
(
self
.
certificate_repository_path
,
'0.key'
)).
read
(),
'SLAPOS_key'
)
def
test_one_partition_instance_cfg
(
self
):
def
test_one_partition_instance_cfg
(
self
):
"""
"""
...
@@ -951,14 +758,12 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -951,14 +758,12 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'buildout.cfg'
,
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/
api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
[
'/
getFullComputerInformation'
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
'/getComputerPartitionCertificate'
,
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
'/stoppedComputerPartition'
]
)
def
test_one_free_partition
(
self
):
def
test_one_free_partition
(
self
):
"""
"""
...
@@ -986,15 +791,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -986,15 +791,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
partition
.
partition_path
,
partition
.
asJSONText
())
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
[
'/getFullComputerInformation'
,
self
.
assertEqual
(
partition
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
def
test_one_partition_started_fail
(
self
):
def
test_one_partition_started_fail
(
self
):
...
@@ -1007,15 +811,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -1007,15 +811,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
partition
.
partition_path
,
partition
.
asJSONText
())
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
[
'/getFullComputerInformation'
,
self
.
assertEqual
(
partition
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
...
@@ -1027,15 +830,16 @@ exit 1
...
@@ -1027,15 +830,16 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
,
'/getHateoasUrl'
,
[
'/getFullComputerInformation'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
'/getComputerPartitionCertificate'
,
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'error'
)
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertTrue
(
instance
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
def
test_one_partition_started_stopped
(
self
):
def
test_one_partition_started_stopped
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1067,15 +871,14 @@ chmod 755 etc/run/wrapper
...
@@ -1067,15 +871,14 @@ chmod 755 etc/run/wrapper
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
[
'/getFullComputerInformation'
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -1084,14 +887,13 @@ chmod 755 etc/run/wrapper
...
@@ -1084,14 +887,13 @@ chmod 755 etc/run/wrapper
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/get/'
,
'/api/put/'
])
'/getFullComputerInformation'
,
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_broken_partition_stopped
(
self
):
def
test_one_broken_partition_stopped
(
self
):
...
@@ -1129,19 +931,15 @@ chmod 755 etc/run/wrapper
...
@@ -1129,19 +931,15 @@ chmod 755 etc/run/wrapper
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -1154,19 +952,14 @@ exit 1
...
@@ -1154,19 +952,14 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/softwareInstanceError'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'error'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertTrue
(
instance
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
def
test_one_partition_stopped_started
(
self
):
def
test_one_partition_stopped_started
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1179,17 +972,13 @@ exit 1
...
@@ -1179,17 +972,13 @@ exit 1
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/stoppedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
...
@@ -1199,20 +988,16 @@ exit 1
...
@@ -1199,20 +988,16 @@ exit 1
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'etc'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'etc'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertSoftwareInstanceJSONIsCorrect
(
instance
.
partition_path
,
instance
.
asJSONText
())
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_one_partition_destroyed
(
self
):
def
test_one_partition_destroyed
(
self
):
...
@@ -1236,11 +1021,9 @@ exit 1
...
@@ -1236,11 +1021,9 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
dummy_file_name
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
dummy_file_name
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/stoppedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
def
test_one_partition_started_no_master
(
self
):
def
test_one_partition_started_no_master
(
self
):
...
@@ -1411,8 +1194,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1411,8 +1194,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_daemon.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_daemon.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
self
.
assertLogContent
(
daemon_log
,
'Failing'
)
self
.
assertLogContent
(
daemon_log
,
'Failing'
)
self
.
assertIsCreated
(
self
.
watchdog_banged
)
self
.
assertIsCreated
(
self
.
watchdog_banged
)
...
@@ -1460,7 +1242,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1460,7 +1242,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_daemon.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_daemon.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'launched'
,
'crashed'
,
'.software-instance.json'
])
'launched'
,
'crashed'
])
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
self
.
assertLogContent
(
daemon_log
,
'Failing'
)
self
.
assertLogContent
(
daemon_log
,
'Failing'
)
self
.
assertIsNotCreated
(
self
.
watchdog_banged
)
self
.
assertIsNotCreated
(
self
.
watchdog_banged
)
...
@@ -1490,7 +1272,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1490,7 +1272,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
def
test_unwanted_events_will_not_bang
(
self
):
def
test_unwanted_events_will_not_bang
(
self
):
"""
"""
...
@@ -1566,7 +1348,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1566,7 +1348,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1601,7 +1383,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1601,7 +1383,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1636,7 +1418,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1636,7 +1418,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
# Second bang
# Second bang
event
=
watchdog
.
process_state_events
[
0
]
event
=
watchdog
.
process_state_events
[
0
]
...
@@ -1690,7 +1472,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1690,7 +1472,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1721,7 +1503,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -1721,7 +1503,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
payload
=
'processname:%s groupname:%s from_state:RUNNING'
%
(
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
'daemon'
+
WATCHDOG_MARK
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'bang'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceBang'
]
)
with
open
(
os
.
path
.
join
(
with
open
(
os
.
path
.
join
(
partition
,
partition
,
...
@@ -1752,16 +1534,15 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1752,16 +1534,15 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
with
open
(
timestamp_path
)
as
f
:
with
open
(
timestamp_path
)
as
f
:
self
.
assertIn
(
timestamp
,
f
.
read
())
self
.
assertIn
(
timestamp
,
f
.
read
())
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
def
test_partition_timestamp_develop
(
self
):
def
test_partition_timestamp_develop
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1775,18 +1556,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1775,18 +1556,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
self
.
launchSlapgrid
(
develop
=
True
),
self
.
assertEqual
(
self
.
launchSlapgrid
(
develop
=
True
),
slapgrid
.
SLAPGRID_SUCCESS
)
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance
.
sequence
[
3
][
0
],
'/api/put/'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
def
test_partition_old_timestamp
(
self
):
def
test_partition_old_timestamp
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1799,13 +1578,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1799,13 +1578,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
def
test_partition_timestamp_new_timestamp
(
self
):
def
test_partition_timestamp_new_timestamp
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1818,16 +1596,22 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1818,16 +1596,22 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
assertEqual
(
computer
.
sequence
,
[
x
[
0
]
for
x
in
instance
.
sequence
],
[
'/getHateoasUrl'
,
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
,
'/api/get/'
]
'/getFullComputerInformation'
,
)
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
])
def
test_partition_timestamp_no_timestamp
(
self
):
def
test_partition_timestamp_no_timestamp
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
)
...
@@ -1840,16 +1624,20 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1840,16 +1624,20 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
None
instance
.
timestamp
=
None
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
self
.
assertEqual
(
computer
.
sequence
,
[
x
[
0
]
for
x
in
instance
.
sequence
],
[
'/getHateoasUrl'
,
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
]
'/getFullComputerInformation'
,
)
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
def
test_partition_periodicity_remove_timestamp
(
self
):
"""
"""
...
@@ -1869,8 +1657,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1869,8 +1657,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
time
.
sleep
(
2
)
time
.
sleep
(
2
)
# dummify install() so that it doesn't actually do anything so that it
# dummify install() so that it doesn't actually do anything so that it
...
@@ -1880,8 +1667,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1880,8 +1667,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
def
test_one_partition_periodicity_from_file_does_not_disturb_others
(
self
):
def
test_one_partition_periodicity_from_file_does_not_disturb_others
(
self
):
"""
"""
...
@@ -1916,17 +1702,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1916,17 +1702,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
[
'/startedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
'/startedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'started'
)
]
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertGreater
(
self
.
assertGreater
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
last_runtime
)
...
@@ -1956,17 +1742,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1956,17 +1742,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
'.timestamp'
)),
last_runtime
)
last_runtime
)
...
@@ -1997,19 +1782,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1997,19 +1782,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
instance0
.
requested_state
=
'destroyed'
instance0
.
requested_state
=
'destroyed'
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
'.timestamp'
)),
last_runtime
)
last_runtime
)
...
@@ -2073,15 +1856,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -2073,15 +1856,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance0
.
software
.
setBuildout
(
"""#!/bin/sh
instance0
.
software
.
setBuildout
(
"""#!/bin/sh
exit 42"""
)
exit 42"""
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertTrue
(
instance0
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance1
.
sequence
[
1
],
[
'/softwareInstanceError'
])
(
self
.
assertEqual
(
instance1
.
sequence
,
'/api/put/'
,
[
'/stoppedComputerPartition'
])
{
'portal_type'
:
'Software Instance'
,
'reference'
:
'1'
,
'reported_state'
:
'stopped'
}
)
)
def
test_one_partition_lacking_software_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_software_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -2095,15 +1873,10 @@ exit 42""")
...
@@ -2095,15 +1873,10 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srdir
)
shutil
.
rmtree
(
instance0
.
software
.
srdir
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
[
'/softwareInstanceError'
])
self
.
assertIn
(
self
.
assertEqual
(
instance1
.
sequence
,
"Software Release http://sr0/ is not present on system"
,
[
'/stoppedComputerPartition'
])
instance0
.
sequence
[
1
][
1
][
"status_message"
]
)
self
.
assertIn
(
"Cannot deploy instance."
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_lacking_software_bin_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_software_bin_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -2117,12 +1890,10 @@ exit 42""")
...
@@ -2117,12 +1890,10 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srbindir
)
shutil
.
rmtree
(
instance0
.
software
.
srbindir
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
[
'/softwareInstanceError'
])
self
.
assertIn
(
"No such file or directory"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
,
self
.
assertIn
(
"sbin/buildout"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
[
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_lacking_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -2136,12 +1907,10 @@ exit 42""")
...
@@ -2136,12 +1907,10 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
partition_path
)
shutil
.
rmtree
(
instance0
.
partition_path
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
[
0
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
0
][
1
][
"reported_state"
],
'error'
)
[
'/softwareInstanceError'
])
self
.
assertIn
(
"Partition directory"
,
instance0
.
sequence
[
0
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
,
self
.
assertIn
(
"does not exist"
,
instance0
.
sequence
[
0
][
1
][
"status_message"
])
[
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_buildout_fail_is_correctly_logged
(
self
):
def
test_one_partition_buildout_fail_is_correctly_logged
(
self
):
"""
"""
...
@@ -2157,8 +1926,7 @@ exit 42""")
...
@@ -2157,8 +1926,7 @@ exit 42""")
instance
.
software
.
setBuildout
(
"""#!/bin/sh
instance
.
software
.
setBuildout
(
"""#!/bin/sh
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
"error"
)
# We don't care of actual formatting, we just want to have full log
# We don't care of actual formatting, we just want to have full log
self
.
assertIn
(
line1
,
instance
.
error_log
)
self
.
assertIn
(
line1
,
instance
.
error_log
)
self
.
assertIn
(
line2
,
instance
.
error_log
)
self
.
assertIn
(
line2
,
instance
.
error_log
)
...
@@ -2239,12 +2007,10 @@ echo %s; echo %s; exit 42""" % (line1, line2))
...
@@ -2239,12 +2007,10 @@ echo %s; echo %s; exit 42""" % (line1, line2))
six
.
assertCountEqual
(
self
,
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
os
.
listdir
(
instance
.
partition_path
),
[
'etc'
,
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
[
'etc'
,
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
]
'.software-instance.json'
]
)
)
self
.
assertFalse
(
os
.
path
.
exists
(
promise_ran
))
self
.
assertFalse
(
os
.
path
.
exists
(
promise_ran
))
self
.
assertEqual
(
len
(
instance
.
sequence
),
1
)
self
.
assertFalse
(
instance
.
sequence
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
0
],
"/api/get/"
)
def
test_supervisor_partition_files_removed_on_stop
(
self
):
def
test_supervisor_partition_files_removed_on_stop
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
,
2
,
1
)
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
,
2
,
1
)
...
@@ -2309,25 +2075,19 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2309,25 +2075,19 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# Then destroy the instance
# Then destroy the instance
computer
.
sequence
=
[]
computer
.
sequence
=
[]
instance
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
instance
.
requested_state
=
'destroyed'
# Reset Cache
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -2339,13 +2099,10 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2339,13 +2099,10 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/stoppedComputerPartition'
,
'/api/put/'
,
'/destroyedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance
.
sequence
[
2
][
1
][
"reported_state"
],
'destroyed'
)
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
def
test_partition_list_is_complete_if_empty_destroyed_partition
(
self
):
def
test_partition_list_is_complete_if_empty_destroyed_partition
(
self
):
...
@@ -2363,7 +2120,6 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2363,7 +2120,6 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer
.
sequence
=
[]
computer
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
instance
.
requested_state
=
'destroyed'
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -2374,15 +2130,12 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2374,15 +2130,12 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
[
'/api/allDocs/'
,
computer
.
sequence
,
'/api/get/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/put/'
,
'/stoppedComputerPartition'
,
'/api/put/'
])
'/destroyedComputerPartition'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance
.
sequence
[
2
][
1
][
"reported_state"
],
'destroyed'
)
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
def
test_slapgrid_not_destroy_bad_instance
(
self
):
def
test_slapgrid_not_destroy_bad_instance
(
self
):
"""
"""
...
@@ -2397,41 +2150,38 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2397,41 +2150,38 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# Then run usage report and see if it is still working
# Then run usage report and see if it is still working
computer
.
sequence
=
[]
computer
.
sequence
=
[]
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# registerComputerPartition will create one more file:
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
request_list_file
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
instance
.
name
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-retention-lock-delay'
,
request_list_file
])
'.software-instance.json'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-retention-lock-delay'
,
request_list_file
])
'.software-instance.json'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/
api/allDocs/
'
])
[
'/
getFullComputerInformation
'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_slapgrid_instance_ignore_free_instance
(
self
):
def
test_slapgrid_instance_ignore_free_instance
(
self
):
...
@@ -2451,7 +2201,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2451,7 +2201,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
api/allDocs/
'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation
'
])
def
test_slapgrid_report_ignore_free_instance
(
self
):
def
test_slapgrid_report_ignore_free_instance
(
self
):
"""
"""
...
@@ -2470,18 +2220,31 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -2470,18 +2220,31 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
api/allDocs/
'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation
'
])
class
TestSlapgridSoftwareRelease
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridSoftwareRelease
(
MasterMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
MasterMixin
.
setUp
(
self
)
self
.
pwuid_patch
=
patch
.
object
(
pwd
,
'getpwuid'
,
new
=
self
.
fake_getpwuid
)
self
.
pwuid_patch
.
start
()
def
tearDown
(
self
):
self
.
pwuid_patch
.
stop
()
def
fake_getpwuid
(
self
,
uid
):
return
pwd
.
struct_passwd
(
(
"fake"
,
"x"
,
uid
,
uid
,
""
,
self
.
software_root
,
"/bin/bash"
)
)
fake_waiting_time
=
0.05
fake_waiting_time
=
0.05
def
test_one_software_buildout_fail_is_correctly_logged
(
self
):
def
test_one_software_buildout_fail_is_correctly_logged
(
self
):
"""
"""
1. We set up a software using a corrupted buildout
1. We set up a software using a corrupted buildout
2. It will fail, make sure that whole log is sent to master
2. It will fail, make sure that whole log is sent to master
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
self
.
getTestComputerClass
()
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software
=
computer
.
software_list
[
0
]
...
@@ -2490,36 +2253,15 @@ class TestSlapgridSoftwareRelease(MasterMixin, unittest.TestCase):
...
@@ -2490,36 +2253,15 @@ class TestSlapgridSoftwareRelease(MasterMixin, unittest.TestCase):
software
.
setBuildout
(
"""#!/bin/sh
software
.
setBuildout
(
"""#!/bin/sh
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
self
.
launchSlapgridSoftware
()
self
.
launchSlapgridSoftware
()
self
.
assertEqual
(
self
.
assertEqual
(
software
.
sequence
,
software
.
sequence
,
[
'/buildingSoftwareRelease'
,
'/softwareReleaseError'
])
[
(
'/api/put/'
,
{
'compute_node_id'
:
self
.
computer_id
,
'portal_type'
:
'Software Installation'
,
'reported_state'
:
'building'
,
'software_release_uri'
:
software
.
name
,
}
),
(
'/api/put/'
,
{
'compute_node_id'
:
self
.
computer_id
,
'portal_type'
:
'Software Installation'
,
'error_status'
:
software
.
error_log
,
'software_release_uri'
:
software
.
name
,
}
)
]
)
# We don't care of actual formatting, we just want to have full log
# We don't care of actual formatting, we just want to have full log
self
.
assertIn
(
line1
,
software
.
error_log
)
self
.
assertIn
(
line1
,
software
.
error_log
)
self
.
assertIn
(
line2
,
software
.
error_log
)
self
.
assertIn
(
line2
,
software
.
error_log
)
self
.
assertIn
(
'Failed to run buildout'
,
software
.
error_log
)
self
.
assertIn
(
'Failed to run buildout'
,
software
.
error_log
)
def
test_software_install_generate_buildout_cfg_with_shared_part_list
(
self
):
def
test_software_install_generate_buildout_cfg_with_shared_part_list
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
self
.
getTestComputerClass
()
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software
=
computer
.
software_list
[
0
]
# examine the genrated buildout
# examine the genrated buildout
...
@@ -2529,7 +2271,7 @@ echo %s; echo %s; exit 42""" % (line1, line2))
...
@@ -2529,7 +2271,7 @@ echo %s; echo %s; exit 42""" % (line1, line2))
self
.
assertIn
(
'shared-part-list = %s'
%
self
.
shared_parts_root
,
software
.
error_log
)
self
.
assertIn
(
'shared-part-list = %s'
%
self
.
shared_parts_root
,
software
.
error_log
)
def
test_remove_software
(
self
):
def
test_remove_software
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
self
.
getTestComputerClass
()
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software
=
computer
.
software_list
[
0
]
...
@@ -2546,7 +2288,7 @@ touch directory/file
...
@@ -2546,7 +2288,7 @@ touch directory/file
def
test_remove_software_chmod
(
self
):
def
test_remove_software_chmod
(
self
):
# This software is "hard" to remove, as permissions have been changed
# This software is "hard" to remove, as permissions have been changed
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
self
.
getTestComputerClass
()
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software
=
computer
.
software_list
[
0
]
...
@@ -2563,6 +2305,42 @@ chmod a-rxw directory
...
@@ -2563,6 +2305,42 @@ chmod a-rxw directory
self
.
launchSlapgridSoftware
()
self
.
launchSlapgridSoftware
()
self
.
assertEqual
(
os
.
listdir
(
self
.
software_root
),
[])
self
.
assertEqual
(
os
.
listdir
(
self
.
software_root
),
[])
def
test_build_software_with_netrc
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
netrc_file
=
os
.
path
.
join
(
self
.
software_root
,
'.netrc'
)
with
open
(
netrc_file
,
'w'
)
as
f
:
f
.
write
(
'machine localhost login foo password bar'
)
with
open
(
os
.
path
.
join
(
self
.
software_root
,
'testing'
),
'w'
)
as
f
:
f
.
write
(
'this is not buildout home'
)
os
.
chmod
(
netrc_file
,
0o600
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software_path
=
os
.
path
.
join
(
self
.
software_root
,
software
.
software_hash
)
buildout_netrc
=
os
.
path
.
join
(
software_path
,
'.netrc'
)
command
=
"""#!/bin/sh
# $HOME is different from buildout netrc home location
if [ -s "$HOME/testing" ]; then
echo "testing file exists"
exit 1
fi
"""
software
.
setBuildout
(
command
)
self
.
launchSlapgridSoftware
()
self
.
assertTrue
(
os
.
path
.
exists
(
netrc_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
buildout_netrc
))
with
open
(
buildout_netrc
)
as
f
:
content
=
f
.
read
()
self
.
assertEqual
(
content
,
'machine localhost login foo password bar'
)
completed
=
os
.
path
.
join
(
software_path
,
'.completed'
)
os
.
remove
(
netrc_file
)
# force rerun of software
os
.
remove
(
completed
)
self
.
launchSlapgridSoftware
()
self
.
assertFalse
(
os
.
path
.
exists
(
buildout_netrc
))
class
SlapgridInitialization
(
unittest
.
TestCase
):
class
SlapgridInitialization
(
unittest
.
TestCase
):
"""
"""
...
@@ -2784,7 +2562,7 @@ exit 1
...
@@ -2784,7 +2562,7 @@ exit 1
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'.slapgrid-0-error.log'
,
'.software-instance.json'
])
'.slapgrid-0-error.log'
])
promise_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_ran'
)
promise_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_ran'
)
promise
=
textwrap
.
dedent
(
"""
\
promise
=
textwrap
.
dedent
(
"""
\
...
@@ -2810,7 +2588,7 @@ exit 1
...
@@ -2810,7 +2588,7 @@ exit 1
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'.slapgrid-0-error.log'
,
'.software-instance.json'
])
'.slapgrid-0-error.log'
])
promise_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_ran'
)
promise_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_ran'
)
promise
=
textwrap
.
dedent
(
"""
\
promise
=
textwrap
.
dedent
(
"""
\
...
@@ -2846,8 +2624,6 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
...
@@ -2846,8 +2624,6 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
)))
)))
instance
.
requested_state
=
'destroyed'
instance
.
requested_state
=
'destroyed'
# Reset Cache
self
.
grid
.
computer_partition_list
=
None
self
.
grid
.
agregateAndSendUsage
()
self
.
grid
.
agregateAndSendUsage
()
self
.
assertTrue
(
os
.
path
.
exists
(
dummy_instance_file_path
))
self
.
assertTrue
(
os
.
path
.
exists
(
dummy_instance_file_path
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
...
@@ -3299,20 +3075,16 @@ exit 0
...
@@ -3299,20 +3075,16 @@ exit 0
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'.software-instance.json'
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/api/get/'
,
'/getComputerPartitionCertificate'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
partition
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
manager_list
=
slapmanager
.
from_config
({
'manager_list'
:
'prerm'
})
manager_list
=
slapmanager
.
from_config
({
'manager_list'
:
'prerm'
})
self
.
grid
.
_manager_list
=
manager_list
self
.
grid
.
_manager_list
=
manager_list
partition
.
requested_state
=
'destroyed'
partition
.
requested_state
=
'destroyed'
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is not destroyed (pre-delete is running)
# Assert partition directory is not destroyed (pre-delete is running)
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -3320,14 +3092,13 @@ exit 0
...
@@ -3320,14 +3092,13 @@ exit 0
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.s
oftware-instance.json
'
])
'.s
lapos-request-transaction-0
'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
[
partition
.
software
.
software_hash
])
# wait until the pre-delete script is finished
# wait until the pre-delete script is finished
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -3358,13 +3129,12 @@ exit 0
...
@@ -3358,13 +3129,12 @@ exit 0
self
.
grid
.
_manager_list
=
manager_list
self
.
grid
.
_manager_list
=
manager_list
partition
.
requested_state
=
'destroyed'
partition
.
requested_state
=
'destroyed'
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is not destroyed (retention-delay-lock)
# Assert partition directory is not destroyed (retention-delay-lock)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-retention-lock-date'
,
'.s
oftware-instance.json
'
])
'.slapos-retention-lock-date'
,
'.s
lapos-request-transaction-0
'
])
self
.
assertTrue
(
os
.
path
.
exists
(
pre_delete_script
))
self
.
assertTrue
(
os
.
path
.
exists
(
pre_delete_script
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
partition
.
partition_path
,
partition
.
partition_path
,
...
@@ -3372,7 +3142,6 @@ exit 0
...
@@ -3372,7 +3142,6 @@ exit 0
)))
)))
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is not destroyed (pre-delete is running)
# Assert partition directory is not destroyed (pre-delete is running)
...
@@ -3380,7 +3149,7 @@ exit 0
...
@@ -3380,7 +3149,7 @@ exit 0
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-retention-lock-date'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-retention-lock-date'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.s
oftware-instance.json
'
])
'.s
lapos-request-transaction-0
'
])
# wait until the pre-delete script is finished
# wait until the pre-delete script is finished
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
...
@@ -3406,14 +3175,12 @@ exit 0
...
@@ -3406,14 +3175,12 @@ exit 0
self
.
grid
.
_manager_list
=
manager_list
self
.
grid
.
_manager_list
=
manager_list
partition
.
requested_state
=
'destroyed'
partition
.
requested_state
=
'destroyed'
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is not destroyed (pre-delete is running)
# Assert partition directory is not destroyed (pre-delete is running)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-request-transaction-0'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
])
'.software-instance.json'
])
# wait until the pre-delete script is finished
# wait until the pre-delete script is finished
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
self
.
_wait_prerm_script_finished
(
partition
.
partition_path
)
...
@@ -3421,7 +3188,6 @@ exit 0
...
@@ -3421,7 +3188,6 @@ exit 0
# the script is well finished...
# the script is well finished...
self
.
assertIn
(
"finished prerm script."
,
f
.
read
())
self
.
assertIn
(
"finished prerm script."
,
f
.
read
())
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -3444,14 +3210,12 @@ exit 0
...
@@ -3444,14 +3210,12 @@ exit 0
self
.
grid
.
_manager_list
=
manager_list
self
.
grid
.
_manager_list
=
manager_list
partition
.
requested_state
=
'destroyed'
partition
.
requested_state
=
'destroyed'
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is not destroyed (pre-delete is running)
# Assert partition directory is not destroyed (pre-delete is running)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
[
'.slapgrid'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapos-request-transaction-0'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
,
'.0-prerm_slapos_pre_delete.log'
,
'.slapos-report-wait-service-list'
])
'.software-instance.json'
])
stat_info
=
os
.
stat
(
partition
.
partition_path
)
stat_info
=
os
.
stat
(
partition
.
partition_path
)
uid
=
stat_info
.
st_uid
uid
=
stat_info
.
st_uid
...
@@ -3480,7 +3244,6 @@ exit 0
...
@@ -3480,7 +3244,6 @@ exit 0
# wait until the pre-delete script is finished
# wait until the pre-delete script is finished
self._wait_prerm_script_finished(partition.partition_path)
self._wait_prerm_script_finished(partition.partition_path)
self.grid.computer_partition_list = None
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty
# Assert partition directory is empty
self.assertInstanceDirectoryListEqual(['0'])
self.assertInstanceDirectoryListEqual(['0'])
...
@@ -3530,29 +3293,8 @@ exit 1 # do not proceed trying to use this software
...
@@ -3530,29 +3293,8 @@ exit 1 # do not proceed trying to use this software
self.launchSlapgridSoftware()
self.launchSlapgridSoftware()
self.assertEqual(
self.assertEqual(software.sequence,
software.sequence,
['/buildingSoftwareRelease', '/softwareReleaseError'])
[
(
'/api/put/',
{
'compute_node_id': self.computer_id,
'portal_type': 'Software Installation',
'reported_state': 'building',
'software_release_uri': software.name,
}
),
(
'/api/put/',
{
'compute_node_id': self.computer_id,
'portal_type': 'Software Installation',
'error_status': software.error_log,
'software_release_uri': software.name,
}
)
]
)
self.assertNotIn("
file
descriptors
:
leaked
", software.error_log)
self.assertNotIn("
file
descriptors
:
leaked
", software.error_log)
self.assertIn("
file
descriptors
:
ok
", software.error_log)
self.assertIn("
file
descriptors
:
ok
", software.error_log)
...
@@ -3587,8 +3329,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -3587,8 +3329,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
self.assertEqual(self.computer.sequence,
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
['/getFullComputerInformation',
self.assertEqual(self.partition.sequence[1][1]["
reported_state
"], 'started')
'/getComputerPartitionCertificate',
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
self.assertEqual(self.partition.state, 'started')
def test_simple_port_redirection(self):
def test_simple_port_redirection(self):
...
@@ -3662,15 +3405,11 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -3662,15 +3405,11 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
self.assertEqual(self.computer.sequence,
['/api/allDocs/',
['/getFullComputerInformation',
'/api/get/',
'/getComputerPartitionCertificate',
'/api/get/',
'/startedComputerPartition',
'/api/put/',
'/getComputerPartitionCertificate',
'/api/get/',
'/startedComputerPartition'])
'/api/get/',
'/api/put/'])
self.assertEqual(self.partition.sequence[1][1]["
reported_state
"], 'started')
self.assertEqual(self.partition.sequence[3][1]["
reported_state
"], 'started')
self.assertEqual(self.partition.state, 'started')
self.assertEqual(self.partition.state, 'started')
# Check the socat command
# Check the socat command
...
@@ -4052,7 +3791,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
...
@@ -4052,7 +3791,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.grid.computer_partition_list = None
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
self.assertEqual(
...
@@ -4071,7 +3809,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
...
@@ -4071,7 +3809,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.grid.computer_partition_list = None
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
self.assertEqual(
...
@@ -4096,7 +3833,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
...
@@ -4096,7 +3833,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.grid.computer_partition_list = None
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
self.assertEqual(
...
@@ -4181,7 +3917,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
...
@@ -4181,7 +3917,6 @@ class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'destroyed'
self.partition.requested_state = 'destroyed'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.grid.computer_partition_list = None
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
self.assertEqual(
...
@@ -4238,8 +3973,9 @@ class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
...
@@ -4238,8 +3973,9 @@ class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
self.assertEqual(self.computer.sequence,
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
['/getFullComputerInformation',
self.assertEqual(partition.sequence[1][1]["
reported_state
"], 'started')
'/getComputerPartitionCertificate',
'/startedComputerPartition'])
self.assertEqual(partition.state, 'started')
self.assertEqual(partition.state, 'started')
self.assertEqual(self.manager.sequence,
self.assertEqual(self.manager.sequence,
...
...
slapos/tests/test_slapgrid_slaptool.py
deleted
100644 → 0
View file @
447d3da4
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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