Commit 42ea5ed7 authored by Xavier Thompson's avatar Xavier Thompson

slapproxy: Add logs for local sr root path update

parent da6f9e88
......@@ -205,13 +205,18 @@ def _updateLocalSoftwareReleaseRootPathIfNeeded():
execute_db('local_software_release_root', 'UPDATE %s SET path=?', [new_root_path])
# Rebase all URLs relative to the new root path
if current_root_path != new_root_path:'Updating local software release root path: %s --> %s', current_root_path, new_root_path)
def migrate_url(url):
if not url or urlparse(url).scheme:
app.logger.debug('Migrate URL ? N: %s is not a path', url)
return url
rel = os.path.relpath(url, current_root_path)
if rel.startswith(os.pardir + os.sep):
app.logger.debug('Migrate URL ? N: %s is not a subpath', url)
return url
return os.path.join(new_root_path, rel)
new = os.path.join(new_root_path, rel)
app.logger.debug('Migrate URL ? Y: %s -> %s', url, new)
return new
g.db.create_function('migrate_url', 1, migrate_url)
execute_db('software', 'UPDATE %s SET url=migrate_url(url)')
execute_db('partition', 'UPDATE %s SET software_release=migrate_url(software_release)')
......@@ -2147,6 +2147,36 @@ class TestLocalSoftwareReleaseRootPathMigration(MasterMixin):
def test_request_multiple_moves(self):
def test_move_logs(self):
local_sr_root = os.path.join(self._rootdir, 'opt')
subpath_url = os.path.join(local_sr_root, 'software.cfg')
path_not_subpath_url = os.path.join(self._rootdir, 'srv', 'software.cfg')
http_url = "https://sr//"
for i, initial_url in enumerate((subpath_url, path_not_subpath_url, http_url)):
self.request(initial_url, None, 'instance%d' % i, None)
new_local_sr_root = os.path.join(self._rootdir, 'opt')
new_subpath_url = os.path.join(new_local_sr_root, 'software.cfg')
with mock.patch.object(, 'logger') as logger:
# Request something to trigger update
'Updating local software release root path: %s --> %s',
logger.debug.assert_has_calls(['Migrate URL ? Y: %s -> %s', subpath_url, new_subpath_url),'Migrate URL ? N: %s is not a subpath', path_not_subpath_url),'Migrate URL ? N: %s is not a path', http_url)
]*2, any_order=True)
class _MigrationTestCase(TestInformation, TestRequest, TestSlaveRequest, TestMultiNodeSupport):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment