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
Ophélie Gagnard
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):
...
@@ -79,35 +79,39 @@ class BasicMixin(object):
Will set files and start slapproxy
Will set files and start slapproxy
"""
"""
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_rootdir
=
self
.
initRootDir
()
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
self
.
setFiles
()
self
.
setFiles
()
self
.
startProxy
()
self
.
startProxy
()
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
def
initRootDir
(
self
):
return
self
.
_tempdir
def
createSlapOSConfigurationFile
(
self
):
def
createSlapOSConfigurationFile
(
self
):
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
f
.
write
(
"""[slapos]
f
.
write
(
"""[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
master_url = %(proxyaddr)s
computer_id = computer
computer_id = computer
[slapproxy]
[slapproxy]
host = 127.0.0.1
host = 127.0.0.1
port = 8080
port = 8080
database_uri = %(
temp
dir)s/lib/proxy.db
database_uri = %(
root
dir)s/lib/proxy.db
"""
%
{
'
tempdir'
:
self
.
_temp
dir
,
'proxyaddr'
:
self
.
proxyaddr
})
"""
%
{
'
rootdir'
:
self
.
_root
dir
,
'proxyaddr'
:
self
.
proxyaddr
})
def
setFiles
(
self
):
def
setFiles
(
self
):
"""
"""
Set environment to run slapproxy
Set environment to run slapproxy
"""
"""
self
.
slapos_cfg
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'slapos.cfg'
)
self
.
slapos_cfg
=
os
.
path
.
join
(
self
.
_
root
dir
,
'slapos.cfg'
)
self
.
proxy_db
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'lib'
,
'proxy.db'
)
self
.
proxy_db
=
os
.
path
.
join
(
self
.
_
root
dir
,
'lib'
,
'proxy.db'
)
self
.
proxyaddr
=
'http://localhost:80/'
self
.
proxyaddr
=
'http://localhost:80/'
self
.
computer_id
=
'computer'
self
.
computer_id
=
'computer'
self
.
createSlapOSConfigurationFile
()
self
.
createSlapOSConfigurationFile
()
for
directory
in
[
'opt'
,
'srv'
,
'lib'
]:
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
)
os
.
mkdir
(
path
)
def
startProxy
(
self
):
def
startProxy
(
self
):
...
@@ -1192,16 +1196,16 @@ class CliMasterMixin(MasterMixin):
...
@@ -1192,16 +1196,16 @@ class CliMasterMixin(MasterMixin):
self
.
proxyaddr
=
'http://%s:8080'
%
host
self
.
proxyaddr
=
'http://%s:8080'
%
host
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
with
open
(
self
.
slapos_cfg
,
'w'
)
as
f
:
f
.
write
(
"""[slapos]
f
.
write
(
"""[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
master_url = %(proxyaddr)s
master_rest_url = %(proxyaddr)s/hateoas
master_rest_url = %(proxyaddr)s/hateoas
computer_id = computer
computer_id = computer
[slapproxy]
[slapproxy]
host = %(host)s
host = %(host)s
port = 8080
port = 8080
database_uri = %(
temp
dir)s/lib/proxy.db
database_uri = %(
root
dir)s/lib/proxy.db
"""
%
{
'
tempdir'
:
self
.
_temp
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'host'
:
host
})
"""
%
{
'
rootdir'
:
self
.
_root
dir
,
'proxyaddr'
:
self
.
proxyaddr
,
'host'
:
host
})
def
cliDoSlapos
(
self
,
command
,
method
=
subprocess
.
check_output
,
**
kwargs
):
def
cliDoSlapos
(
self
,
command
,
method
=
subprocess
.
check_output
,
**
kwargs
):
return
method
(
return
method
(
...
@@ -1317,7 +1321,7 @@ class TestCliInformation(CliMasterMixin):
...
@@ -1317,7 +1321,7 @@ class TestCliInformation(CliMasterMixin):
],
],
)
)
try
:
try
:
output2
=
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance2'
),
stderr
=
subprocess
.
STDOUT
)
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance2'
),
stderr
=
subprocess
.
STDOUT
)
self
.
fail
()
self
.
fail
()
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
self
.
assertIn
(
'Instance MyInstance2 does not exist.'
,
e
.
output
)
self
.
assertIn
(
'Instance MyInstance2 does not exist.'
,
e
.
output
)
...
@@ -1655,7 +1659,7 @@ class TestMultiMasterSupport(MasterMixin):
...
@@ -1655,7 +1659,7 @@ class TestMultiMasterSupport(MasterMixin):
self
.
db
=
sqlite_connect
(
self
.
proxy_db
)
self
.
db
=
sqlite_connect
(
self
.
proxy_db
)
self
.
external_slapproxy_configuration_file_location
=
os
.
path
.
join
(
self
.
external_slapproxy_configuration_file_location
=
os
.
path
.
join
(
self
.
_
temp
dir
,
'external_slapos.cfg'
)
self
.
_
root
dir
,
'external_slapos.cfg'
)
self
.
createExternalProxyConfigurationFile
()
self
.
createExternalProxyConfigurationFile
()
self
.
startExternalProxy
()
self
.
startExternalProxy
()
...
@@ -1669,9 +1673,9 @@ computer_id = %(external_computer_id)s
...
@@ -1669,9 +1673,9 @@ computer_id = %(external_computer_id)s
[slapproxy]
[slapproxy]
host = %(host)s
host = %(host)s
port = %(port)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
,
'host'
:
self
.
external_proxy_host
,
'port'
:
self
.
external_proxy_port
,
'port'
:
self
.
external_proxy_port
,
'external_computer_id'
:
self
.
external_computer_id
'external_computer_id'
:
self
.
external_computer_id
...
@@ -1716,7 +1720,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
...
@@ -1716,7 +1720,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
configuration
=
bytes2str
(
pkg_resources
.
resource_string
(
configuration
=
bytes2str
(
pkg_resources
.
resource_string
(
'slapos.tests'
,
os
.
path
.
join
(
'test_slapproxy'
,
'slapos_multimaster.cfg.in'
)
'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_host'
:
self
.
external_proxy_host
,
'external_proxy_port'
:
self
.
external_proxy_port
'external_proxy_port'
:
self
.
external_proxy_port
}
}
...
@@ -1925,7 +1929,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
...
@@ -1925,7 +1929,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
with
sqlite3
.
connect
(
os
.
path
.
join
(
with
sqlite3
.
connect
(
os
.
path
.
join
(
self
.
_
temp
dir
,
self
.
_
root
dir
,
'lib'
,
'lib'
,
'external_proxy.db'
,
'external_proxy.db'
,
))
as
db
:
))
as
db
:
...
@@ -2014,7 +2018,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
...
@@ -2014,7 +2018,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
self
.
assertEqual
({},
partition
.
getConnectionParameterDict
())
with
sqlite3
.
connect
(
os
.
path
.
join
(
with
sqlite3
.
connect
(
os
.
path
.
join
(
self
.
_
temp
dir
,
self
.
_
root
dir
,
'lib'
,
'lib'
,
'external_proxy.db'
,
'external_proxy.db'
,
))
as
db
:
))
as
db
:
...
@@ -2043,6 +2047,107 @@ database_uri = %(tempdir)s/lib/external_proxy.db
...
@@ -2043,6 +2047,107 @@ database_uri = %(tempdir)s/lib/external_proxy.db
}],
requested_by
)
}],
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
):
class
_MigrationTestCase
(
TestInformation
,
TestRequest
,
TestSlaveRequest
,
TestMultiNodeSupport
):
"""
"""
Test that old database version are automatically migrated without failure
Test that old database version are automatically migrated without failure
...
...
slapos/tests/test_slapproxy/slapos_multimaster.cfg.in
View file @
da6f9e88
[slapos]
[slapos]
software_root = %(
temp
dir)s/opt/slapgrid
software_root = %(
root
dir)s/opt/slapgrid
instance_root = %(
temp
dir)s/srv/slapgrid
instance_root = %(
root
dir)s/srv/slapgrid
master_url = %(proxyaddr)s
master_url = %(proxyaddr)s
computer_id = computer
computer_id = computer
[slapproxy]
[slapproxy]
host = 127.0.0.1
host = 127.0.0.1
port = 8080
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
# 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.
# 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