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
Łukasz Nowak
slapos.core
Commits
da6f9e88
Commit
da6f9e88
authored
Mar 31, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapproxy: Add tests for root path migration
parent
189fa3a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
21 deletions
+126
-21
slapos/tests/test_slapproxy.py
slapos/tests/test_slapproxy.py
+123
-18
slapos/tests/test_slapproxy/slapos_multimaster.cfg.in
slapos/tests/test_slapproxy/slapos_multimaster.cfg.in
+3
-3
No files found.
slapos/tests/test_slapproxy.py
View file @
da6f9e88
...
...
@@ -79,35 +79,39 @@ class BasicMixin(object):
Will set files and start slapproxy
"""
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_rootdir
=
self
.
initRootDir
()
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
self
.
setFiles
()
self
.
startProxy
()
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
def
initRootDir
(
self
):
return
self
.
_tempdir
def
createSlapOSConfigurationFile
(
self
):
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
f
.
write
(
"""[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
computer_id = computer
[slapproxy]
host = 127.0.0.1
port = 8080
database_uri = %(
temp
dir)s/lib/proxy.db
"""
%
{
'
tempdir'
:
self
.
_temp
dir
,
'proxyaddr'
:
self
.
proxyaddr
})
database_uri = %(
root
dir)s/lib/proxy.db
"""
%
{
'
rootdir'
:
self
.
_root
dir
,
'proxyaddr'
:
self
.
proxyaddr
})
def
setFiles
(
self
):
"""
Set environment to run slapproxy
"""
self
.
slapos_cfg
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'slapos.cfg'
)
self
.
proxy_db
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'lib'
,
'proxy.db'
)
self
.
slapos_cfg
=
os
.
path
.
join
(
self
.
_
root
dir
,
'slapos.cfg'
)
self
.
proxy_db
=
os
.
path
.
join
(
self
.
_
root
dir
,
'lib'
,
'proxy.db'
)
self
.
proxyaddr
=
'http://localhost:80/'
self
.
computer_id
=
'computer'
self
.
createSlapOSConfigurationFile
()
for
directory
in
[
'opt'
,
'srv'
,
'lib'
]:
path
=
os
.
path
.
join
(
self
.
_
temp
dir
,
directory
)
path
=
os
.
path
.
join
(
self
.
_
root
dir
,
directory
)
os
.
mkdir
(
path
)
def
startProxy
(
self
):
...
...
@@ -1192,16 +1196,16 @@ class CliMasterMixin(MasterMixin):
self
.
proxyaddr
=
'http://%s:8080'
%
host
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
f
.
write
(
"""[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
master_rest_url = %(proxyaddr)s/hateoas
computer_id = computer
[slapproxy]
host = %(host)s
port = 8080
database_uri = %(
temp
dir)s/lib/proxy.db
"""
%
{
'
tempdir'
:
self
.
_temp
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'host'
:
host
})
database_uri = %(
root
dir)s/lib/proxy.db
"""
%
{
'
rootdir'
:
self
.
_root
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'host'
:
host
})
def
cliDoSlapos
(
self
,
command
,
method
=
subprocess
.
check_output
,
**
kwargs
):
return
method
(
...
...
@@ -1317,7 +1321,7 @@ class TestCliInformation(CliMasterMixin):
],
)
try
:
output2
=
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance2'
),
stderr
=
subprocess
.
STDOUT
)
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance2'
),
stderr
=
subprocess
.
STDOUT
)
self
.
fail
()
except
subprocess
.
CalledProcessError
as
e
:
self
.
assertIn
(
'Instance MyInstance2 does not exist.'
,
e
.
output
)
...
...
@@ -1655,7 +1659,7 @@ class TestMultiMasterSupport(MasterMixin):
self
.
db
=
sqlite_connect
(
self
.
proxy_db
)
self
.
external_slapproxy_configuration_file_location
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'external_slapos.cfg'
)
self
.
_
root
dir
,
'external_slapos.cfg'
)
self
.
createExternalProxyConfigurationFile
()
self
.
startExternalProxy
()
...
...
@@ -1669,9 +1673,9 @@ computer_id = %(external_computer_id)s
[slapproxy]
host = %(host)s
port = %(port)s
database_uri = %(
temp
dir)s/lib/external_proxy.db
database_uri = %(
root
dir)s/lib/external_proxy.db
"""
%
{
'
tempdir'
:
self
.
_temp
dir
,
'
rootdir'
:
self
.
_root
dir
,
'host'
:
self
.
external_proxy_host
,
'port'
:
self
.
external_proxy_port
,
'external_computer_id'
:
self
.
external_computer_id
...
...
@@ -1716,7 +1720,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
configuration
=
bytes2str
(
pkg_resources
.
resource_string
(
'slapos.tests'
,
os
.
path
.
join
(
'test_slapproxy'
,
'slapos_multimaster.cfg.in'
)
))
%
{
'
tempdir'
:
self
.
_temp
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'
rootdir'
:
self
.
_root
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'external_proxy_host'
:
self
.
external_proxy_host
,
'external_proxy_port'
:
self
.
external_proxy_port
}
...
...
@@ -1925,7 +1929,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
with
sqlite3
.
connect
(
os
.
path
.
join
(
self
.
_
temp
dir
,
self
.
_
root
dir
,
'lib'
,
'external_proxy.db'
,
))
as
db
:
...
...
@@ -2014,7 +2018,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
with
sqlite3
.
connect
(
os
.
path
.
join
(
self
.
_
temp
dir
,
self
.
_
root
dir
,
'lib'
,
'external_proxy.db'
,
))
as
db
:
...
...
@@ -2043,6 +2047,107 @@ database_uri = %(tempdir)s/lib/external_proxy.db
}],
requested_by
)
class
TestLocalSoftwareReleaseRootPathMigration
(
MasterMixin
):
"""
Test local URL adaptation based on the local software release root path.
"""
def
initRootDir
(
self
):
rootdir
=
os
.
path
.
join
(
self
.
_tempdir
,
'0'
)
os
.
mkdir
(
rootdir
)
return
rootdir
def
newRootDir
(
self
):
return
os
.
path
.
join
(
self
.
_tempdir
,
str
(
1
+
int
(
os
.
path
.
basename
(
self
.
_rootdir
))))
def
createSlapOSConfigurationFile
(
self
):
super
(
TestLocalSoftwareReleaseRootPathMigration
,
self
).
createSlapOSConfigurationFile
()
with
open
(
self
.
slapos_cfg
,
'a'
)
as
f
:
f
.
write
(
"
\
n
local_software_release_root = %s/opt"
%
self
.
_rootdir
)
def
moveProxy
(
self
,
rootdir
=
None
):
if
not
rootdir
:
rootdir
=
self
.
newRootDir
()
os
.
rename
(
self
.
_rootdir
,
rootdir
)
self
.
_rootdir
=
rootdir
self
.
slapos_cfg
=
os
.
path
.
join
(
self
.
_rootdir
,
'slapos.cfg'
)
self
.
proxy_db
=
os
.
path
.
join
(
self
.
_rootdir
,
'lib'
,
'proxy.db'
)
self
.
createSlapOSConfigurationFile
()
views
.
is_schema_already_executed
=
False
self
.
startProxy
()
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
def
assertSoftwareUrls
(
self
,
*
expected_urls
):
sr_list
=
tuple
(
sr
.
getURI
()
for
sr
in
self
.
getFullComputerInformation
().
_software_release_list
)
self
.
assertEqual
(
sr_list
,
expected_urls
)
def
assertPartitionUrl
(
self
,
partition_id
,
expected_url
):
self
.
assertEqual
(
self
.
getPartitionInformation
(
partition_id
).
getSoftwareRelease
().
getURI
(),
expected_url
)
def
checkSupplyUrl
(
self
,
initial_url
,
expected_url
,
rootdir
=
None
):
self
.
supply
(
initial_url
)
self
.
assertSoftwareUrls
(
initial_url
)
self
.
moveProxy
(
rootdir
)
self
.
assertSoftwareUrls
(
expected_url
)
def
checkRequestUrl
(
self
,
initial_url
,
expected_url
,
rootdir
=
None
):
self
.
format_for_number_of_partitions
(
1
)
partition
=
self
.
request
(
initial_url
,
None
,
'MyInstance'
,
'slappart0'
)
self
.
assertPartitionUrl
(
partition
.
_partition_id
,
initial_url
)
self
.
moveProxy
(
rootdir
)
self
.
assertPartitionUrl
(
partition
.
_partition_id
,
expected_url
)
def
test_supply_local_url
(
self
):
initial_url
=
os
.
path
.
join
(
self
.
_rootdir
,
'opt'
,
'software.cfg'
)
new_rootdir
=
self
.
newRootDir
()
expected_url
=
os
.
path
.
join
(
new_rootdir
,
'opt'
,
'software.cfg'
)
self
.
checkSupplyUrl
(
initial_url
,
expected_url
,
new_rootdir
)
def
test_supply_not_in_root_url
(
self
):
url
=
os
.
path
.
join
(
self
.
_rootdir
,
'srv'
,
'software.cfg'
)
self
.
checkSupplyUrl
(
url
,
url
)
def
test_supply_http_url
(
self
):
url
=
"http://sr//"
self
.
checkSupplyUrl
(
url
,
url
)
def
test_supply_https_url
(
self
):
url
=
"https://sr//"
self
.
checkSupplyUrl
(
url
,
url
)
def
test_request_local_url
(
self
):
initial_url
=
os
.
path
.
join
(
self
.
_rootdir
,
'opt'
,
'software.cfg'
)
new_rootdir
=
self
.
newRootDir
()
expected_url
=
os
.
path
.
join
(
new_rootdir
,
'opt'
,
'software.cfg'
)
self
.
checkRequestUrl
(
initial_url
,
expected_url
,
new_rootdir
)
def
test_request_not_in_root_url
(
self
):
url
=
os
.
path
.
join
(
self
.
_rootdir
,
'srv'
,
'software.cfg'
)
self
.
checkRequestUrl
(
url
,
url
)
def
test_request_http_url
(
self
):
url
=
"http://sr//"
self
.
checkRequestUrl
(
url
,
url
)
def
test_request_https_url
(
self
):
url
=
"https://sr//"
self
.
checkRequestUrl
(
url
,
url
)
def
checkMultipleMoves
(
self
,
checkUrl
):
initial_url
=
os
.
path
.
join
(
self
.
_rootdir
,
'opt'
,
'software.cfg'
)
for
_
in
range
(
5
):
new_rootdir
=
self
.
newRootDir
()
expected_url
=
os
.
path
.
join
(
new_rootdir
,
'opt'
,
'software.cfg'
)
checkUrl
(
initial_url
,
expected_url
,
new_rootdir
)
initial_url
=
expected_url
def
test_supply_multiple_moves
(
self
):
self
.
checkMultipleMoves
(
self
.
checkSupplyUrl
)
def
test_request_multiple_moves
(
self
):
self
.
checkMultipleMoves
(
self
.
checkRequestUrl
)
class
_MigrationTestCase
(
TestInformation
,
TestRequest
,
TestSlaveRequest
,
TestMultiNodeSupport
):
"""
Test that old database version are automatically migrated without failure
...
...
slapos/tests/test_slapproxy/slapos_multimaster.cfg.in
View file @
da6f9e88
[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
computer_id = computer
[slapproxy]
host = 127.0.0.1
port = 8080
database_uri = %(
temp
dir)s/lib/proxy.db
database_uri = %(
root
dir)s/lib/proxy.db
# Here goes the list of slapos masters that slapproxy can contact
# Each section beginning by multimaster is a different SlapOS Master, represented by arbitrary name.
...
...
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