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
Léo-Paul Géneau
slapos.core
Commits
3bc0dd76
Commit
3bc0dd76
authored
Feb 07, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli/boot: Read partition base name from config
also add missing test for slapos node boot /reviewed-on
!187
parent
be2cbf5b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
3 deletions
+64
-3
slapos/cli/boot.py
slapos/cli/boot.py
+7
-3
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+57
-0
No files found.
slapos/cli/boot.py
View file @
3bc0dd76
...
...
@@ -42,11 +42,14 @@ from slapos.cli.entry import SlapOSApp
from
slapos.cli.config
import
ConfigCommand
from
slapos.format
import
isGlobalScopeAddress
def
_removeTimestamp
(
instancehome
):
def
_removeTimestamp
(
instancehome
,
partition_base_name
):
"""
Remove .timestamp from all partitions
"""
timestamp_glob_path
=
"%s/slappart*/.timestamp"
%
instancehome
timestamp_glob_path
=
os
.
path
.
join
(
instancehome
,
"%s*"
%
partition_base_name
,
".timestamp"
)
for
timestamp_path
in
glob
.
glob
(
timestamp_glob_path
):
print
(
"Removing %s"
%
timestamp_path
)
os
.
remove
(
timestamp_path
)
...
...
@@ -157,6 +160,7 @@ class BootCommand(ConfigCommand):
def
take_action
(
self
,
args
):
configp
=
self
.
fetch_config
(
args
)
instance_root
=
configp
.
get
(
'slapos'
,
'instance_root'
)
partition_base_name
=
configp
.
get
(
'slapformat'
,
'partition_base_name'
)
master_url
=
urlparse
(
configp
.
get
(
'slapos'
,
'master_url'
))
master_hostname
=
master_url
.
hostname
...
...
@@ -187,4 +191,4 @@ class BootCommand(ConfigCommand):
print
(
"[BOOT] [ERROR] Fail to bang, try again in 15 seconds..."
)
sleep
(
15
)
_removeTimestamp
(
instance_root
)
_removeTimestamp
(
instance_root
,
partition_base_name
)
slapos/tests/test_cli.py
View file @
3bc0dd76
...
...
@@ -29,6 +29,9 @@ import logging
import
pprint
import
unittest
import
tempfile
import
shutil
import
socket
import
textwrap
import
sys
import
os
import
pkg_resources
...
...
@@ -282,6 +285,60 @@ class TestCliProxyShow(CliMixin):
self
.
assertIn
(
'287375f0cba269902ba1bc50242839d7'
,
f
.
read
())
class
TestCliBoot
(
CliMixin
):
def
test_node_boot
(
self
):
# initialize instance root, with a timestamp in a partition
temp_dir
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
temp_dir
)
instance_root
=
os
.
path
.
join
(
temp_dir
,
'instance'
)
partition_base_name
=
'partition'
os
.
mkdir
(
instance_root
)
os
.
mkdir
(
os
.
path
.
join
(
instance_root
,
partition_base_name
+
'1'
))
timestamp
=
os
.
path
.
join
(
instance_root
,
partition_base_name
+
'1'
,
'.timestamp'
)
with
open
(
timestamp
,
'w'
)
as
f
:
f
.
write
(
"1578552471"
)
# make a config file using this instance root
with
tempfile
.
NamedTemporaryFile
(
mode
=
'w'
)
as
slapos_conf
:
slapos_conf
.
write
(
textwrap
.
dedent
(
"""
\
[slapos]
instance_root = {instance_root}
master_url = https://slap.vifib.com/
[slapformat]
partition_base_name = {partition_base_name}
interface_name = interface_name_from_config
"""
).
format
(
**
locals
()))
slapos_conf
.
flush
()
# run slapos node boot
app
=
slapos
.
cli
.
entry
.
SlapOSApp
()
with
patch
(
'slapos.cli.command.check_root_user'
,
return_value
=
True
)
as
check_root_user
,
\
patch
(
'slapos.cli.boot.SlapOSApp'
)
as
SlapOSApp
,
\
patch
(
'slapos.cli.boot.ConfigCommand.config_path'
,
return_value
=
slapos_conf
.
name
),
\
patch
(
'slapos.cli.boot.netifaces.ifaddresses'
,
return_value
=
{
socket
.
AF_INET6
:
({
'addr'
:
'2000::1'
},),},)
as
ifaddresses
,
\
patch
(
'slapos.cli.boot._ping_hostname'
,
return_value
=
1
)
as
_ping_hostname
:
app
.
run
((
'node'
,
'boot'
))
# boot command runs as root
check_root_user
.
assert_called_once
()
# it waits for interface to have an IPv6 address
ifaddresses
.
assert_called_once_with
(
'interface_name_from_config'
)
# then ping master hostname to wait for connectivity
_ping_hostname
.
assert_called_once_with
(
'slap.vifib.com'
)
# then format and bang
SlapOSApp
().
run
.
assert_any_call
([
'node'
,
'format'
,
'--now'
,
'--verbose'
])
SlapOSApp
().
run
.
assert_any_call
([
'node'
,
'bang'
,
'-m'
,
'Reboot'
])
# timestamp files have been removed
self
.
assertFalse
(
os
.
path
.
exists
(
timestamp
))
class
TestCliNode
(
CliMixin
):
def
test_node_software
(
self
):
...
...
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