Set Debian snapshots URL to CENGN

* Set default Debian snapshots URL to CENGN
* Upgrade existing stx.conf file to match

TESTS
=======================

Run "stx config --upgrade" with various combinations of the old, new &
missing values of debian_snapshot_base and debian_security_snapshot_base

Story: 2010055
Task: 46096

Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
Change-Id: Id5dd6a8054a8ac5b1a89f5bdd355450d6a7e3b1a
This commit is contained in:
Davlet Panech 2022-08-23 16:26:29 -04:00
parent 2a3cdf47d8
commit 1b2bcc8010
2 changed files with 49 additions and 2 deletions

View File

@ -14,8 +14,10 @@ debian_version = 11.3
# These URLs must contain snapshots of debian & debian-security repos.
# We will append debian_snapshot_timestamp to each of them when creating
# apt.sources lists
debian_snapshot_base = http://snapshot.debian.org/archive/debian
debian_security_snapshot_base = http://snapshot.debian.org/archive/debian-security
#debian_snapshot_base = http://snapshot.debian.org/archive/debian
debian_snapshot_base = http://mirror.starlingx.cengn.ca/mirror/debian/debian/snapshot.debian.org/archive/debian
#debian_security_snapshot_base = http://snapshot.debian.org/archive/debian-security
debian_security_snapshot_base = http://mirror.starlingx.cengn.ca/mirror/debian/debian/snapshot.debian.org/archive/debian-security
debian_snapshot_timestamp = 20220331T000000Z
[builder]

View File

@ -125,6 +125,16 @@ class STXConfigParser:
def syncConfigFile(self):
self.cf.write(open(self.configpath, "w"))
def __get(self, section, option, fallback=None):
if self.cf.has_section(section):
return self.cf.get(section, option, fallback=fallback)
return fallback
def __set(self, section, option, value):
if not self.cf.has_section(section):
self.cf.add_section(section)
self.cf.set(section, option, value)
def __delete_key(self, section, option):
if self.cf.has_option(section, option):
self.cf.remove_option(section, option)
@ -141,7 +151,16 @@ class STXConfigParser:
logger.error("Please upgrade %s manually", self.configpath)
raise RuntimeError("Failed to upgrade %s" % self.configpath)
def __upgrade_id_exists(self, upgrade_id):
return self.__get('upgrade_ids', upgrade_id, "").lower() in ['1', 'true', 'yes']
def __save_upgrade_id(self, upgrade_id):
self.__set('upgrade_ids', upgrade_id, "1")
def upgradeConfigFile(self):
need_restart = False
ref_config_path = os.path.join(os.environ['PRJDIR'], "stx.conf.sample")
ref_config = configparser.ConfigParser()
ref_config.read(ref_config_path, encoding="utf-8")
@ -195,9 +214,35 @@ class STXConfigParser:
# delete old key
self.__delete_key('project', 'debian_security_snapshot')
# Change debian_snapshot_* to CENGN
if not self.__upgrade_id_exists('debian_snapshot_cengn'):
debian_snapshot_cengn_upgraded = False
# debian_snapshot_base
old_value = 'http://snapshot.debian.org/archive/debian'
new_value = 'http://mirror.starlingx.cengn.ca/mirror/debian/debian/snapshot.debian.org/archive/debian'
current_value = self.__get('project', 'debian_snapshot_base')
if current_value == old_value:
self.__upgrade_nonempty_key('project', 'debian_snapshot_base', new_value)
debian_snapshot_cengn_upgraded = True
# debian_security_snapshot_base
old_value = 'http://snapshot.debian.org/archive/debian-security'
new_value = 'http://mirror.starlingx.cengn.ca/mirror/debian/debian/snapshot.debian.org/archive/debian-security'
current_value = self.__get('project', 'debian_security_snapshot_base')
if current_value == old_value:
self.__upgrade_nonempty_key('project', 'debian_security_snapshot_base', new_value)
debian_snapshot_cengn_upgraded = True
if debian_snapshot_cengn_upgraded:
self.__save_upgrade_id('debian_snapshot_cengn')
need_restart = True
# Save changes
self.syncConfigFile()
if need_restart:
logger.warning("One or more configuration keeys have been upgraded")
logger.warning("These changes will take effect after you restart your builder containers")
class HandleConfigTask:
'''Handle the task for the config sub-command'''