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(): ...@@ -205,13 +205,18 @@ def _updateLocalSoftwareReleaseRootPathIfNeeded():
execute_db('local_software_release_root', 'UPDATE %s SET path=?', [new_root_path]) execute_db('local_software_release_root', 'UPDATE %s SET path=?', [new_root_path])
# Rebase all URLs relative to the new root path # Rebase all URLs relative to the new root path
if current_root_path != new_root_path: if current_root_path != new_root_path:
app.logger.info('Updating local software release root path: %s --> %s', current_root_path, new_root_path)
def migrate_url(url): def migrate_url(url):
if not url or urlparse(url).scheme: if not url or urlparse(url).scheme:
app.logger.debug('Migrate URL ? N: %s is not a path', url)
return url return url
rel = os.path.relpath(url, current_root_path) rel = os.path.relpath(url, current_root_path)
if rel.startswith(os.pardir + os.sep): if rel.startswith(os.pardir + os.sep):
app.logger.debug('Migrate URL ? N: %s is not a subpath', url)
return 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) g.db.create_function('migrate_url', 1, migrate_url)
execute_db('software', 'UPDATE %s SET url=migrate_url(url)') execute_db('software', 'UPDATE %s SET url=migrate_url(url)')
execute_db('partition', 'UPDATE %s SET software_release=migrate_url(software_release)') execute_db('partition', 'UPDATE %s SET software_release=migrate_url(software_release)')
......
...@@ -2147,6 +2147,36 @@ class TestLocalSoftwareReleaseRootPathMigration(MasterMixin): ...@@ -2147,6 +2147,36 @@ class TestLocalSoftwareReleaseRootPathMigration(MasterMixin):
def test_request_multiple_moves(self): def test_request_multiple_moves(self):
self.checkMultipleMoves(self.checkRequestUrl) self.checkMultipleMoves(self.checkRequestUrl)
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//"
self.format_for_number_of_partitions(3)
for i, initial_url in enumerate((subpath_url, path_not_subpath_url, http_url)):
self.supply(initial_url)
self.request(initial_url, None, 'instance%d' % i, None)
self.moveProxy()
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(views.app, 'logger') as logger:
# Request something to trigger update
self.getFullComputerInformation()
logger.info.assert_called_once_with(
'Updating local software release root path: %s --> %s',
local_sr_root,
new_local_sr_root,
)
logger.debug.assert_has_calls([
mock.call('Migrate URL ? Y: %s -> %s', subpath_url, new_subpath_url),
mock.call('Migrate URL ? N: %s is not a subpath', path_not_subpath_url),
mock.call('Migrate URL ? N: %s is not a path', http_url)
]*2, any_order=True)
class _MigrationTestCase(TestInformation, TestRequest, TestSlaveRequest, TestMultiNodeSupport): 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