FEAT: added tag saving

master
idziubenko 2 years ago
parent 94e768f5a9
commit 3843da48ef

@ -1689,12 +1689,11 @@ class Update(MethodsInterface):
_("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))
elif not ignore_level and not self.is_binhost_level_valid(binhost): elif not ignore_level and not self.is_binhost_level_valid(binhost):
# self.stash_binhost(binhost_url) if self.compare_update_level(binhost.level) > 0:
if self.compare_update_level(binhost.level) > 0: self.set_migration_mode(True)
self.set_migration_mode(True) raise UpdateError((
raise UpdateError(( _("Current binhost {} has wrong update level. Current level: {} Binhost level: {}").\
_("Current binhost {} has wrong update level. Current level: {} Binhost level: {}").\ format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level)))
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level)))
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')
@ -1772,7 +1771,6 @@ class Update(MethodsInterface):
def set_migration_mode(self, val=True): def set_migration_mode(self, val=True):
val_to_write = Variable.On if val else Variable.Off val_to_write = Variable.On if val else Variable.Off
# self.clVars.Write("cl_update_use_migration_host", val_to_write, location="system")
self.clVars.Set("cl_update_use_migration_host", val_to_write) self.clVars.Set("cl_update_use_migration_host", val_to_write)
return True return True
@ -1780,14 +1778,22 @@ class Update(MethodsInterface):
def cmp_rep_tag_to_current_calc_rep_tag(self): def cmp_rep_tag_to_current_calc_rep_tag(self):
#TODO value to Var #TODO value to Var
repname = 'calculate' repname = 'calculate'
git = self.getGit() revision = (self.clVars.Select(["cl_update_rep_rev"],
rpath, revision = (
self.clVars.Select(["cl_update_rep_path",
"cl_update_rep_rev"],
where="cl_update_rep_name", where="cl_update_rep_name",
eq=repname, limit=1)) eq=repname, limit=1))[0]
#try ValueError? saved_tag = self.get_current_saved_tag()
return int(revision) - int(git.getCurrentTag(rpath)) # git = self.getGit()
# rpath = '/var/db/repos/calculate'
# tggg = git.getCurrentTag(rpath)
if saved_tag is not None:
return int(revision) - saved_tag
else:
return 1
def get_current_saved_tag(self):
tg = self.clVars.Get("cl_update_saved_tag")
return int(tg) if tg else None
def set_migration_host(self): def set_migration_host(self):
self.startTask(_("Setting up migration host")) self.startTask(_("Setting up migration host"))
@ -1926,15 +1932,33 @@ class Update(MethodsInterface):
self.startTask(_("Increasing local update level")) self.startTask(_("Increasing local update level"))
self._update_increment_current_level() self._update_increment_current_level()
self.set_migration_mode(False) self.set_migration_mode(False)
# self.unstash_binhost()
self.delete_binhost() self.delete_binhost()
self.endTask() self.endTask()
return True return True
#should not do when on a branch
def update_set_current_saved_tag(self):
#TODO add to var?
repname = "calculate"
git = self.getGit()
rpath, revision = (
self.clVars.Select(["cl_update_rep_path",
"cl_update_rep_rev"],
where="cl_update_rep_name",
eq=repname, limit=1))
try:
branch_name = self.clVars.Select(["cl_update_branch_name"],
where="cl_update_branch_rep", eq=repname, limit=1)[0]
tag = git.getCurrentTag(rpath)
if branch_name == Git.Reference.Tag and tag.isdigit():
self._set_saved_tag(tag)
return True
except ValueError as e:
return False
def _update_increment_current_level(self): def _update_increment_current_level(self):
current_level = int(self.clVars.Get('cl_update_level')) current_level = int(self.clVars.Get('cl_update_level'))
self.clVars.Write('cl_update_level', self._set_update_level(str(current_level + 1))
str(current_level + 1), location="system")
def is_current_level_a_digit(self): def is_current_level_a_digit(self):
""" """
@ -1948,21 +1972,20 @@ class Update(MethodsInterface):
return True return True
def _set_update_level(self, level): def _set_update_level(self, level):
level = level if level else 0 self._set_val_in_system(level, 'cl_update_level')
self.clVars.Write('cl_update_level',
str(level), location="system") def _set_saved_tag(self, tag):
self._set_val_in_system(tag, 'cl_update_saved_tag')
# def stash_binhost(self, binhost_url):
# """ def _set_val_in_system(self, val, val_name):
# Бекап адреса бинхоста """
# """ val should be int >= 0
# self.clVars.Write("cl_update_binhost_stash", binhost_url, location="system") """
if isinstance(val, str):
# def unstash_binhost(self): val = val if val.isdigit() else 0
# """ elif isinstance(val, int):
# Восстановление сохраненного бинхоста (если он есть) val = val if val >= 0 else 0
# """ else:
# val_to_write = self.clVars.Get("update.cl_update_binhost_stash") val = val if val else 0
# if val_to_write: self.clVars.Write(val_name, str(val), location="system")
# self.clVars.Write('cl_update_binhost', val_to_write, location="system")

@ -466,11 +466,26 @@ class ClUpdateAction(Action):
}, },
{'name': 'update:set_current_level', {'name': 'update:set_current_level',
'method': 'Update.update_increment_current_level()', 'method': 'Update.update_increment_current_level()',
'depend': (Tasks.success() & Tasks.hasnot("interrupt") & Tasks.success_all("update")), 'depend': (Tasks.success() & Tasks.hasnot("interrupt") &
Tasks.success_all("update") & Tasks.hasnot("check_schedule")),
'condition': lambda Get: Get('cl_update_sync_only_set') == 'off' and 'condition': lambda Get: Get('cl_update_sync_only_set') == 'off' and
Get('cl_update_pretend_set') == 'off' and Get('cl_update_pretend_set') == 'off' and
Get('update.cl_update_use_migration_host') == 'on' Get('update.cl_update_use_migration_host') == 'on'
}, },
{'name': 'update_world:set_latest_tag',
'method': 'Update.update_set_current_saved_tag()',
'depend': (Tasks.success() & Tasks.hasnot("interrupt") &
Tasks.success_all("update") & Tasks.hasnot("check_schedule")),
'condition': lambda Get: Get('cl_update_sync_only_set') == 'off' and
Get('cl_update_pretend_set') == 'off'
},
{'name': 'clear_migration_host',
'method': 'Update.delete_binhost()',
'depend': (Tasks.hasnot("check_schedule")),
'condition': lambda Get: Get('cl_update_sync_only_set') == 'off' and
Get('cl_update_pretend_set') == 'off' and
Get('update.cl_update_use_migration_host') == 'on'
},
# сообщение удачного завершения при обновлении ревизии # сообщение удачного завершения при обновлении ревизии
{'name': 'success_rev', {'name': 'success_rev',
'message': __("System update finished!"), 'message': __("System update finished!"),

@ -1876,17 +1876,11 @@ class VariableClUpdateUseMigrationHost(Variable):
type = "bool" type = "bool"
value = "off" value = "off"
class VariableClUpdateMigrationHost(Variable): # class VariableClUpdateMigrationHost(Variable):
""" # """
Используемый хост миграции # Используемый хост миграции
""" # """
value = "" # value = ""
class VariableClBinhostStash(Variable):
"""
Бекап хоста обновления
"""
value = ""
class VariableClUpdateIgnoreLevel(Variable): class VariableClUpdateIgnoreLevel(Variable):
""" """
@ -1920,3 +1914,9 @@ class VariableClUpdateForceLevelMode(Variable):
""" """
type = "bool" type = "bool"
value = "off" value = "off"
class VariableClUpdateSavedTag(Variable):
"""
Сохраняемый тэг репозитория calculate
"""
type = "int"
Loading…
Cancel
Save