multiple improvements to migration algo

migration_mirror 3.7.1.9
idziubenko 2 years ago
parent 9d49a68b38
commit 98c4deae97

@ -1610,7 +1610,7 @@ class Update(MethodsInterface):
self.Reason.Updating):
raise UpdateError(_("Failed to find the server with appropriate updates"))
elif actual_reason is self.Reason.LevelWrong:
self.clVars.Set("update.cl_update_use_migration_host", Variable.On)
self.set_migration_mode()
#TODO add translation
raise UpdateError(_("Failed to find the server with appropriate level of updates"))
else:
@ -1650,13 +1650,6 @@ class Update(MethodsInterface):
if not binhost.valid:
raise UpdateError(
_("Current binhost {} is not valid").format(binhost_url))
#TODO migr
elif not self.is_binhost_level_valid(binhost):
self.clVars.Set("update.cl_update_use_migration_host", Variable.On)
#TODO translate
raise UpdateError(
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
elif binhost.outdated:
raise UpdateError(
_("Current binhost {} is outdated").format(binhost_url))
@ -1664,6 +1657,14 @@ class Update(MethodsInterface):
raise UpdateError(
_("Binary packages on the current binhost {} "
"are older than local").format(binhost_url))
elif not self.is_binhost_level_valid(binhost):
self.stashBinhost(binhost_url)
self.set_migration_mode(True)
#TODO translate
raise UpdateError(
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
if self.binhosts_data.gpg:
packages_fn = self.clVars.Get('update.cl_update_package_cache')
@ -1711,15 +1712,46 @@ class Update(MethodsInterface):
self.endTask()
return True
def set_migration_mode(self, val=True):
val_to_write = Variable.On if val else Variable.Off
self.clVars.Write("update.cl_update_use_migration_host", val_to_write, location="system")
def set_migration_host(self):
#TODO translate
self.startTask(_("Setting up migration host"))
retval = []
dv = self.clVars
last_ts = dv.Get('cl_update_last_timestamp')
binhost_list = dv.Get('cl_update_binhost_migration_list')
level = self.clVars.Get('update.cl_update_level')
migration_host = None
migr_binhost_data = []
while level < 20: #TODO set a const var? or just while true?
migration_host_candidate = self._choose_migration_host(level, binhost_list, last_ts)
if not migration_host_candidate:
break
elif migration_host_candidate.downgraded:
self._update_increment_current_level()
level += 1
else:
migration_host = migration_host_candidate
break
if migration_host:
migr_binhost_data = [migration_host.host, migration_host.data,
str(migration_host.timestamp),
str(migration_host.duration)]
self.clVars.Set('update.cl_update_binhost_data',
migr_binhost_data or Variable.EmptyTable, force=True)
if not migr_binhost_data:
#TODO translate
raise UpdateError(_("Failed to find the working migration server with appropriate level"))
self.endTask()
return True
def _choose_migration_host(self, level, binhost_list, last_ts):
dv = self.clVars
binhost_list = [self.get_migration_mirror_url(x, level) for x in binhost_list]
binhosts_data = Binhosts(
dv.GetInteger('cl_update_binhost_timeout'),
@ -1728,15 +1760,9 @@ class Update(MethodsInterface):
last_ts, binhost_list,
self.get_arch_machine(),
gpg=dv.Get('update.cl_update_gpg'))
migration_host = sorted(binhosts_data.get_binhosts(), reverse=True)[0]
retval.append([migration_host.host, migration_host.data,
str(migration_host.timestamp),
str(migration_host.duration)])
self.clVars.Set('update.cl_update_binhost_data',
retval or Variable.EmptyTable, force=True)
return sorted(binhosts_data.get_binhosts(), reverse=True)[0]
self.endTask()
return True
def update_rep_list(self):
@ -1828,11 +1854,28 @@ class Update(MethodsInterface):
def update_increment_current_level(self):
#TODO add translation
self.startTask(_("Increasing update level"))
self._update_increment_current_level()
self.set_migration_mode(False)
self.delete_binhost()
self.endTask()
return True
def _update_increment_current_level(self):
current_level = int(self.clVars.Get('cl_update_level'))
self.clVars.Write('cl_update_level',
str(current_level + 1), location="system")
self.clVars.Set("update.cl_update_use_migration_host",
Variable.Off)
self.delete_binhost()
self.endTask()
return True
def stashBinhost(self, binhost_url):
"""
Бекап адреса бинхоста
"""
self.clVars.Write("update.cl_update_binhost_stash", binhost_url, location="system")
def unstashBinhost(self):
"""
Восстановление сохраненного бинхоста (если он есть)
"""
val_to_write = self.clVars.Get("update.cl_update_binhost_stash")
if val_to_write:
self.clVars.Write('cl_update_binhost', val_to_write, location="system")

@ -1867,6 +1867,18 @@ class VariableClUpdateUseMigrationHost(Variable):
type = "bool"
value = "off"
class VariableClUpdateMigrationHost(Variable):
"""
Используемый хост миграции
"""
value = ""
class VariableClBinhostStash(Variable):
"""
Бекап хоста обновления
"""
value = ""
class VariableClCheckUpdateLevel(Variable):
"""
Проверять уровень обновления

@ -18,7 +18,7 @@
# limitations under the License.
__app__ = "calculate-update"
__version__ = "3.2.2"
__version__ = "3.2.2" #TODO bump version
import os
from glob import glob

Loading…
Cancel
Save