added migration host capabilities

migration_mirror
Иван Дзюбенко 3 years ago
parent 1dd1cd46a4
commit 4c1f92d549

@ -1489,15 +1489,17 @@ class Update(MethodsInterface):
class Reason(): class Reason():
Success = 0 Success = 0
BadSign = 1 LevelWrong = 1
Outdated = 2 BadSign = 2
Skip = 3 Outdated = 3
Updating = 4 Skip = 4
WrongBinhost = 5 Updating = 5
BadEnv = 6 WrongBinhost = 6
EnvNotFound = 7 BadEnv = 7
SkipSlower = 8 EnvNotFound = 8
UnknownError = 9 SkipSlower = 9
UnknownError = 10
@staticmethod @staticmethod
@ -1512,7 +1514,9 @@ class Update(MethodsInterface):
Update.Reason.BadSign: "FAILED (Bad sign)", Update.Reason.BadSign: "FAILED (Bad sign)",
Update.Reason.Skip: "SKIP", Update.Reason.Skip: "SKIP",
Update.Reason.SkipSlower: "", Update.Reason.SkipSlower: "",
Update.Reason.Success: "" Update.Reason.Success: "",
#TODO formulate better
Update.Reason.LevelWrong: "FAILED (binhost level is wrong)"
}.get(reason,reason) }.get(reason,reason)
def _get_binhost_logger(self): def _get_binhost_logger(self):
@ -1571,11 +1575,12 @@ class Update(MethodsInterface):
reason = errors.get(status, self.Reason.UnknownError) reason = errors.get(status, self.Reason.UnknownError)
elif binhost.bad_sign: elif binhost.bad_sign:
reason = self.Reason.BadSign reason = self.Reason.BadSign
elif not self.is_binhost_level_valid(binhost):
reason = self.Reason.LevelWrong
else: else:
# SUCCESS # SUCCESS
if not binhost.downgraded or stabilization: if not binhost.downgraded or stabilization:
host = "-> %s" % host host = "-> %s" % host
#TODO add migration binhost check there
reason = self.Reason.Success reason = self.Reason.Success
else: else:
reason = self.Reason.Skip reason = self.Reason.Skip
@ -1602,10 +1607,26 @@ class Update(MethodsInterface):
self.Reason.Skip, self.Reason.Skip,
self.Reason.Updating): self.Reason.Updating):
raise UpdateError(_("Failed to find the server with appropriate updates")) 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)
#TODO add translation
raise UpdateError(_("Failed to find the server with appropriate level of updates"))
else: else:
raise UpdateError(_("Failed to find the working server with updates")) raise UpdateError(_("Failed to find the working server with updates"))
return retval return retval
def is_binhost_level_valid(self, binhost):
return self.compare_update_level(binhost) == 0
# @variable_module("update")
def compare_update_level(self, binhost):
# < 0 binhost level low
# == 0 binhost level adequate
# > 0 binhost level high
if binhost.level is None:
return None
return binhost.level - int(self.clVars.Get("update.cl_update_level"))
def check_current_binhost(self, binhost_url): def check_current_binhost(self, binhost_url):
""" """
Проверка текущего сервера обновлений на валидность Проверка текущего сервера обновлений на валидность
@ -1614,7 +1635,8 @@ class Update(MethodsInterface):
raise UpdateError(_("Current binhost is absent in list of update servers")) raise UpdateError(_("Current binhost is absent in list of update servers"))
binhost = self.binhosts_data.get_binhost(binhost_url) binhost = self.binhosts_data.get_binhost(binhost_url)
if binhost.valid and not binhost.outdated and not binhost.downgraded: if binhost.valid and not binhost.outdated and not binhost.downgraded \
and self.is_binhost_level_valid(binhost):
if binhost.status == self.binhosts_data.BinhostStatus.Success: if binhost.status == self.binhosts_data.BinhostStatus.Success:
self.clVars.Set('update.cl_update_binhost_data', self.clVars.Set('update.cl_update_binhost_data',
[[binhost.host, binhost.data, [[binhost.host, binhost.data,
@ -1626,6 +1648,13 @@ class Update(MethodsInterface):
if not binhost.valid: if not binhost.valid:
raise UpdateError( raise UpdateError(
_("Current binhost {} is not valid").format(binhost_url)) _("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 wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
elif binhost.outdated: elif binhost.outdated:
raise UpdateError( raise UpdateError(
_("Current binhost {} is outdated").format(binhost_url)) _("Current binhost {} is outdated").format(binhost_url))
@ -1633,6 +1662,7 @@ class Update(MethodsInterface):
raise UpdateError( raise UpdateError(
_("Binary packages on the current binhost {} " _("Binary packages on the current binhost {} "
"are older than local").format(binhost_url)) "are older than local").format(binhost_url))
if self.binhosts_data.gpg: if self.binhosts_data.gpg:
packages_fn = self.clVars.Get('update.cl_update_package_cache') packages_fn = self.clVars.Get('update.cl_update_package_cache')
packages_sign_fn = self.clVars.Get('update.cl_update_package_cache_sign') packages_sign_fn = self.clVars.Get('update.cl_update_package_cache_sign')
@ -1658,6 +1688,9 @@ class Update(MethodsInterface):
binhost_url)) binhost_url))
return True return True
def get_migration_mirror_url(self, host, level):
return f"{host}level{level}/"
@variable_module("update") @variable_module("update")
def detect_best_binhost(self): def detect_best_binhost(self):
# выполняется переход с серверов unstable обновлней на stable # выполняется переход с серверов unstable обновлней на stable
@ -1670,12 +1703,34 @@ class Update(MethodsInterface):
self.startTask(_("Searching new binhost")) self.startTask(_("Searching new binhost"))
retval = self._search_best_binhost(self.binhosts_data, stabilization) retval = self._search_best_binhost(self.binhosts_data, stabilization)
self.clVars.Set('update.cl_update_binhost_data', self.clVars.Set('update.cl_update_binhost_data',
retval or Variable.EmptyTable, force=True) retval or Variable.EmptyTable, force=True)
self.endTask() self.endTask()
return True return True
def set_migration_host(self):
print("TESTTEST")
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')
binhost_list = [self.get_migration_mirror_url(x, level) for x in binhost_list]
binhosts_data = Binhosts(
# значение малозначимо, поэтому берётся из собирающей системы
dv.GetInteger('cl_update_binhost_timeout'),
dv.Get('cl_update_binhost_revision_path'),
dv.Get('cl_update_binhost_timestamp_path'),
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)])
return retval
def update_rep_list(self): def update_rep_list(self):
""" """

@ -78,26 +78,33 @@ def get_synchronization_tasks(object_name):
'depend': (Tasks.success() & ~AllTasks.has_any("not_use_search") & 'depend': (Tasks.success() & ~AllTasks.has_any("not_use_search") &
(~AllTasks.success_one_of("check_current_binhost") | (~AllTasks.success_one_of("check_current_binhost") |
AllTasks.success_all("sync_reps"))), AllTasks.success_all("sync_reps"))),
'condition': lambda Get: Get('update.cl_update_use_migration_host') == 'off'
},
{'name': 'set_migration_binhost',
'method': Object('set_migration_host()'),
'depend': (Tasks.success() & ~AllTasks.has_any("not_use_search")|
AllTasks.success_all("sync_reps")),
'condition': lambda Get: Get('update.cl_update_use_migration_host') == 'on'
}, },
# запасная синхронизация, в ходе которой ветки обновляются до # запасная синхронизация, в ходе которой ветки обновляются до
# master # master
{'name': 'sync_reps_fallback', # {'name': 'sync_reps_fallback',
'foreach': 'update.cl_update_sync_rep', # 'foreach': 'update.cl_update_sync_rep',
'message': # 'message':
__("Fallback syncing the {eachvar:capitalize} repository"), # __("Fallback syncing the {eachvar:capitalize} repository"),
'method': Object('syncRepositories(eachvar,True)'), # 'method': Object('syncRepositories(eachvar,True)'),
'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"), # 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
}, # },
# обновление переменных информации из binhost # # обновление переменных информации из binhost
{'name': 'sync_reps_fallback:update_binhost_list', # {'name': 'sync_reps_fallback:update_binhost_list',
'method': Object('update_binhost_list()'), # 'method': Object('update_binhost_list()'),
'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"), # 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
}, # },
# найти лучший сервер обновлений # # найти лучший сервер обновлений
{'name': 'sync_reps_fallback:detect_best_binhost', # {'name': 'sync_reps_fallback:detect_best_binhost',
'method': Object('detect_best_binhost()'), # 'method': Object('detect_best_binhost()'),
'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"), # 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
}, # },
{'name': 'sync_reps', {'name': 'sync_reps',
'foreach': 'update.cl_update_sync_rep', 'foreach': 'update.cl_update_sync_rep',
'message': __("Checking {eachvar:capitalize} updates"), 'message': __("Checking {eachvar:capitalize} updates"),

@ -1561,13 +1561,13 @@ class VariableClUpdateBinhostUnstableList(Variable):
value = ["https://testing.calculate-linux.org/"] value = ["https://testing.calculate-linux.org/"]
# value = ["ftp://ftp.calculate-linux.ru/testing"] # value = ["ftp://ftp.calculate-linux.ru/testing"]
class VariableClUpdateBinhostListMigration(Variable): class VariableClUpdateBinhostMigrationList(Variable):
""" """
Список хостов с бинарными обновлениями для стабильной миграции Список хостов с бинарными обновлениями для стабильной миграции
""" """
type = "list" type = "list"
#TODO placeholder #TODO placeholder
value = ["https://testing.calculate-linux.org/"] value = ["https://mirror.calculate-linux.org/migrate/"]
class VariableClUpdateBinhostBase(Variable): class VariableClUpdateBinhostBase(Variable):
""" """
@ -1858,4 +1858,19 @@ class VariableClUpdateLevel(Variable):
Текущий уровень обновления Текущий уровень обновления
Используется для выбора зеркала Используется для выбора зеркала
""" """
value = "0" value = "1"
class VariableClUpdateUseMigrationHost(Variable):
"""
Уровень обновления на бинхосте
"""
type = "bool"
value = "off"
class VariableClCheckUpdateLevel(Variable):
"""
Проверять уровень обновления
при соединении с binhost
"""
type = "bool"
value = "on"
Loading…
Cancel
Save