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
0
Merge Requests
0
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
Xavier Thompson
slapos.core
Commits
8e05a091
Commit
8e05a091
authored
Jul 21, 2022
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Plain Diff
Fix errors in python3
See merge request
!403
parents
a6c5469b
35d7014b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
31 deletions
+167
-31
slapos/cli/register.py
slapos/cli/register.py
+3
-3
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+1
-1
slapos/grid/networkcache.py
slapos/grid/networkcache.py
+1
-1
slapos/tests/test_register.py
slapos/tests/test_register.py
+103
-12
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+59
-14
No files found.
slapos/cli/register.py
View file @
8e05a091
...
...
@@ -227,6 +227,7 @@ def slapconfig(conf):
if
os
.
path
.
dirname
(
directory
)
==
directory
:
break
# Do "chmod g+xro+xr"
if
(
os
.
stat
(
directory
).
st_mode
&
(
stat
.
S_IXGRP
|
stat
.
S_IRGRP
|
stat
.
S_IXOTH
|
stat
.
S_IROTH
)
!=
stat
.
S_IXGRP
|
stat
.
S_IRGRP
|
stat
.
S_IXOTH
|
stat
.
S_IROTH
):
os
.
chmod
(
directory
,
os
.
stat
(
directory
).
st_mode
|
stat
.
S_IXGRP
|
stat
.
S_IRGRP
|
stat
.
S_IXOTH
|
stat
.
S_IROTH
)
directory
=
os
.
path
.
dirname
(
directory
)
...
...
@@ -250,7 +251,6 @@ def slapconfig(conf):
with
open
(
dst
,
'w'
)
as
destination
:
destination
.
write
(
''
.
join
(
src
))
os
.
chmod
(
dst
,
0o600
)
os
.
chown
(
dst
,
0
,
0
)
certificate_repository_path
=
os
.
path
.
join
(
slap_conf_dir
,
'ssl'
,
'partition_pki'
)
if
not
os
.
path
.
exists
(
certificate_repository_path
):
...
...
@@ -282,7 +282,7 @@ def slapconfig(conf):
cfg
=
re
.
sub
(
'
\
n
\
\
s*%s
\
\
s*=.*'
%
key
,
'
\
n
%s = %s'
%
(
key
,
value
),
cfg
)
if
not
dry_run
:
with
open
(
config_path
,
'w'
)
as
fout
:
with
open
(
config_path
,
'w
b
'
)
as
fout
:
fout
.
write
(
cfg
.
encode
(
'utf8'
))
conf
.
logger
.
info
(
'SlapOS configuration written to %s'
,
config_path
)
...
...
slapos/grid/SlapObject.py
View file @
8e05a091
...
...
@@ -509,7 +509,7 @@ class Partition(object):
else
:
self
.
logger
.
info
(
'Changed %s content. Updating %r'
%
(
name
,
path
))
with
os
.
fdopen
(
os
.
open
(
path
,
os
.
O_CREAT
|
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0o400
),
'w
b
'
)
as
fout
:
with
os
.
fdopen
(
os
.
open
(
path
,
os
.
O_CREAT
|
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0o400
),
'w'
)
as
fout
:
fout
.
write
(
new_content
)
os
.
chown
(
path
,
uid
,
gid
)
...
...
slapos/grid/networkcache.py
View file @
8e05a091
...
...
@@ -160,7 +160,7 @@ def upload_network_cached(software_root, software_url, cached_key,
os
=
distribution_tuple
(),
)
f
=
open
(
path
,
'r'
)
f
=
open
(
path
,
'r
b
'
)
# convert '' into None in order to call nc nicely
if
not
signature_private_key_file
:
signature_private_key_file
=
None
...
...
slapos/tests/test_register.py
View file @
8e05a091
...
...
@@ -25,8 +25,20 @@
#
##############################################################################
import
httmock
import
mock
import
os
import
random
import
shutil
import
string
import
tempfile
import
unittest
import
slapos.cli.register
from
argparse
import
Namespace
from
six.moves.urllib
import
parse
import
slapos.slap
from
slapos.cli.register
import
RegisterCommand
,
RegisterConfig
,
fetch_configuration_template
,
do_register
from
slapos.cli.entry
import
SlapOSApp
class
TestRegister
(
unittest
.
TestCase
):
""" Tests for slapos.cli.register
...
...
@@ -34,10 +46,55 @@ class TestRegister(unittest.TestCase):
XXX There is a lack of tests for register, so include more.
"""
def
setUp
(
self
):
self
.
slap
=
slapos
.
slap
.
slap
()
self
.
app
=
SlapOSApp
()
self
.
temp_dir
=
tempfile
.
mkdtemp
()
self
.
computer_id
=
'COMP-%s'
%
random
.
randrange
(
10000
)
self
.
certificate
=
'CN=%s/emailAddress=admin@vifib.org'
%
self
.
computer_id
self
.
key
=
'key_test_%s'
%
''
.
join
(
random
.
choice
(
string
.
ascii_lowercase
)
for
i
in
range
(
64
))
self
.
default_args
=
[
'test-computer'
,
'--token'
,
'token-test'
]
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
temp_dir
):
shutil
.
rmtree
(
self
.
temp_dir
)
def
request_handler
(
self
,
url
,
req
):
"""
Define _callback.
Will register global sequence of message, sequence by partition
and error and error message by partition
"""
#self.sequence.append(url.path)
if
req
.
method
==
'GET'
:
qs
=
parse
.
parse_qs
(
url
.
query
)
else
:
qs
=
parse
.
parse_qs
(
req
.
body
)
print
(
"DEBUG THOMAS"
)
print
(
url
)
print
(
req
)
if
url
.
path
==
'/Person_requestComputer'
:
return
{
'status_code'
:
200
,
'content'
:
{
'certificate'
:
self
.
certificate
,
'key'
:
self
.
key
}
}
def
getConf
(
self
,
args
):
cmd
=
RegisterCommand
(
self
.
app
,
Namespace
())
cmd_parser
=
cmd
.
get_parser
(
"slapos node register for test"
)
parsed_args
=
cmd_parser
.
parse_args
(
args
)
conf
=
RegisterConfig
(
logger
=
self
.
app
.
log
)
conf
.
setConfig
(
parsed_args
)
return
conf
def
test_fetch_configuration
(
self
):
""" Simple test to Fetch the configuration template
"""
template
=
slapos
.
cli
.
register
.
fetch_configuration_template
()
template
=
fetch_configuration_template
()
self
.
assertNotEqual
(
""
,
template
)
for
entry
in
[
'computer_id'
,
...
...
@@ -50,3 +107,37 @@ class TestRegister(unittest.TestCase):
'partition_amount'
,
'create_tap'
]:
self
.
assertTrue
(
entry
in
template
,
"%s is not in template (%s)"
%
(
entry
,
template
))
def
test_default_token_rejected
(
self
):
""" Make sure that the token for test if rejected by default
"""
conf
=
self
.
getConf
(
self
.
default_args
)
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
do_register
(
conf
)
self
.
assertEqual
(
cm
.
exception
.
code
,
1
)
def
test_write_configuration
(
self
):
""" Simple test to see if we can write the configuration file
"""
conf
=
self
.
getConf
(
self
.
default_args
)
# we manually set the parameters below because we mock the function COMPConfig
# indeed, we don't want to put the config file in '/etc/opt/slapos'
conf
.
slapos_configuration
=
self
.
temp_dir
conf
.
computer_id
=
self
.
computer_id
conf
.
certificate
=
self
.
certificate
conf
.
key
=
self
.
key
with
httmock
.
HTTMock
(
self
.
request_handler
),
\
mock
.
patch
.
object
(
RegisterConfig
,
'COMPConfig'
)
as
COMPConfigMock
,
\
mock
.
patch
(
'slapos.cli.register.save_former_config'
)
as
save_former_config_mock
:
return_code
=
do_register
(
conf
)
COMPConfigMock
.
assert_called_with
(
slapos_configuration
=
'/etc/opt/slapos/'
,
computer_id
=
self
.
computer_id
,
certificate
=
self
.
certificate
,
key
=
self
.
key
)
save_former_config_mock
.
assert_called
()
self
.
assertEquals
(
0
,
return_code
)
self
.
assertTrue
(
os
.
path
.
exists
(
'%s/slapos.cfg'
%
self
.
temp_dir
))
config_content
=
open
(
'%s/slapos.cfg'
%
self
.
temp_dir
).
read
()
self
.
assertIn
(
'computer_id = %s'
%
self
.
computer_id
,
config_content
)
slapos/tests/test_slapgrid.py
View file @
8e05a091
...
...
@@ -181,6 +181,9 @@ class BasicMixin(object):
'supervisord'
)
self
.
usage_report_periodicity
=
1
self
.
buildout
=
None
self
.
certificate_repository_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'partition_pki'
);
if
not
os
.
path
.
isdir
(
self
.
certificate_repository_path
):
os
.
mkdir
(
self
.
certificate_repository_path
)
self
.
grid
=
slapgrid
.
Slapgrid
(
self
.
software_root
,
self
.
instance_root
,
self
.
master_url
,
...
...
@@ -189,7 +192,8 @@ class BasicMixin(object):
develop
=
develop
,
logger
=
logging
.
getLogger
(),
shared_part_list
=
self
.
shared_parts_root
,
force_stop
=
force_stop
)
force_stop
=
force_stop
,
certificate_repository_path
=
self
.
certificate_repository_path
)
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
...
...
@@ -430,6 +434,11 @@ class ComputerForTest(object):
'status_code'
:
200
,
'content'
:
dumps
(
ip_address_list
)
}
elif
url
.
path
==
'/getComputerPartitionCertificate'
:
return
{
'status_code'
:
200
,
'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
)
...
...
@@ -727,7 +736,10 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/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
):
"""
...
...
@@ -745,6 +757,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
def
test_one_free_partition
(
self
):
...
...
@@ -779,6 +792,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
...
...
@@ -798,6 +812,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
...
...
@@ -813,8 +828,12 @@ exit 1
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
def
test_one_partition_started_stopped
(
self
):
...
...
@@ -853,6 +872,7 @@ chmod 755 etc/run/wrapper
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -865,7 +885,9 @@ chmod 755 etc/run/wrapper
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
...
...
@@ -911,6 +933,7 @@ chmod 755 etc/run/wrapper
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -927,7 +950,9 @@ exit 1
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -947,6 +972,7 @@ exit 1
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
...
...
@@ -963,7 +989,9 @@ exit 1
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
...
...
@@ -989,6 +1017,7 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
...
...
@@ -1442,8 +1471,11 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
])
...
...
@@ -1467,8 +1499,11 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
...
...
@@ -1868,7 +1903,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -1887,6 +1922,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
...
...
@@ -1918,7 +1954,10 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
def
test_slapgrid_not_destroy_bad_instance
(
self
):
"""
...
...
@@ -1939,7 +1978,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
...
...
@@ -2812,6 +2851,7 @@ exit 0
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/getComputerPartitionCertificate'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
manager_list
=
slapmanager
.
from_config
({
'manager_list'
:
'prerm'
})
...
...
@@ -3059,6 +3099,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
'/getComputerPartitionCertificate',
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
...
...
@@ -3134,7 +3175,10 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
'/startedComputerPartition', '/startedComputerPartition'])
'/getComputerPartitionCertificate',
'/startedComputerPartition',
'/getComputerPartitionCertificate',
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
# Check the socat command
...
...
@@ -3721,6 +3765,7 @@ class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
'/getComputerPartitionCertificate',
'/startedComputerPartition'])
self.assertEqual(partition.state, 'started')
...
...
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