Improved control over lang packs on integration

- Dryrun should never return empty packages list unless under failure.
- runtests check if the mimic-installed files match the proper language.
This commit is contained in:
Carlos Nihelton 2021-11-22 12:16:01 -03:00
parent 1e6c4472a5
commit 37758047f2
2 changed files with 32 additions and 20 deletions

View File

@ -78,8 +78,9 @@ validate () {
echo "user not assigned with the expected group sudo" echo "user not assigned with the expected group sudo"
exit 1 exit 1
fi fi
if [ -z "$( ls .subiquity/var/cache/apt/archives/)" ] ; then lang="$(grep -Eo 'LANG="([^.@ _]+)' .subiquity/etc/default/locale | cut -d \" -f 2)"
echo "expected not empty directory var/cache/apt/archives/" if [ -z "$( ls .subiquity/var/cache/apt/archives/) | grep $lang" ] ; then
echo "expected $lang language packs in directory var/cache/apt/archives/"
exit 1 exit 1
fi fi
if [ -z "$( diff -Nup .subiquity/etc/locale.gen .subiquity/etc/locale.gen.test)" ] ; then if [ -z "$( diff -Nup .subiquity/etc/locale.gen .subiquity/etc/locale.gen.test)" ] ; then
@ -99,6 +100,7 @@ clean () {
rm -rf .subiquity/run/ rm -rf .subiquity/run/
rm -rf .subiquity/home/ rm -rf .subiquity/home/
rm -rf .subiquity/etc/.pwd.lock rm -rf .subiquity/etc/.pwd.lock
rm -rf .subiquity/etc/default/locale
rm -rf .subiquity/etc/{locale*,passwd*,shadow*,group*,gshadow*,subgid*,subuid*} rm -rf .subiquity/etc/{locale*,passwd*,shadow*,group*,gshadow*,subgid*,subuid*}
rm -rf .subiquity/etc/*.conf rm -rf .subiquity/etc/*.conf
rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg

View File

@ -116,9 +116,10 @@ class ConfigureController(SubiquityController):
return True return True
async def _install_check_lang_support_packages(self, lang, env) -> bool: async def __recommended_packages_to_install(self, lang, env) -> List[str]:
""" Install packages recommended by check-language-support """ Return a list of package names recommended by
command. lang is expected to be one single language/locale. check-language-support (or a fake list if in dryrun).
List returned can be empty, but never None.
""" """
clsCommand = "check-language-support" clsCommand = "check-language-support"
# lang code may be separated by @, dot or spaces. # lang code may be separated by @, dot or spaces.
@ -127,12 +128,12 @@ class ConfigureController(SubiquityController):
matches = pattern.match(lang) matches = pattern.match(lang)
if matches is None: if matches is None:
log.error("Failed to match expected language format: %s", lang) log.error("Failed to match expected language format: %s", lang)
return False return []
langCodes = matches.groups() langCodes = matches.groups()
if len(langCodes) != 1: if len(langCodes) != 1:
log.error("Only one match was expected for: %s", lang) log.error("Only one match was expected for: %s", lang)
return False return []
clsLang = langCodes[0] clsLang = langCodes[0]
# Running that command doesn't require root. # Running that command doesn't require root.
@ -140,26 +141,31 @@ class ConfigureController(SubiquityController):
if cp.returncode != 0: if cp.returncode != 0:
log.error('Command "%s" failed with return code %d', log.error('Command "%s" failed with return code %d',
cp.args, cp.returncode) cp.args, cp.returncode)
return False return []
packages = [pkg for pkg in cp.stdout.strip().split(' ') if pkg] packages = cp.stdout.strip().split(' ')
# We will always have language-pack-{clsLang}-base in dryrun.
if len(packages) == 0 and self.app.opts.dryrun:
packages += ["language-pack-{}-base".format(clsLang)]
return [pkg for pkg in packages if pkg]
async def _install_check_lang_support_packages(self, lang, env) -> bool:
""" Install recommended packages.
lang is expected to be one single language/locale.
"""
packages = await self.__recommended_packages_to_install(lang, env)
cache = apt.Cache() cache = apt.Cache()
if self.app.opts.dry_run: if self.app.opts.dry_run: # only empty in dry-run on failure.
if len(packages) == 0:
log.error("Packages list in dry-run should never be empty.")
return False
packs_dir = os.path.join(self.model.root, packs_dir = os.path.join(self.model.root,
apt_pkg.config apt_pkg.config
.find_dir("Dir::Cache::Archives")[1:]) .find_dir("Dir::Cache::Archives")[1:])
os.makedirs(packs_dir, exist_ok=True) os.makedirs(packs_dir, exist_ok=True)
try: try:
if len(packages) == 0:
message = "{} didn't recommend any packages." \
" Nothing to do.".format(clsCommand)
log.debug(message)
msgFile = os.path.join(packs_dir, "msgFile")
with open(msgFile, "wt") as f:
f.write(message)
return True
for package in packages: for package in packages:
# Just write the package uri to a file. # Just write the package uri to a file.
archive = os.path.join(packs_dir, cache[package].fullname) archive = os.path.join(packs_dir, cache[package].fullname)
@ -172,6 +178,10 @@ class ConfigureController(SubiquityController):
log.error("Failed to write %s file.", archive) log.error("Failed to write %s file.", archive)
return False return False
if len(packages) == 0:
log.info("No missing recommended packages. Nothing to do.")
return True
cache.update() cache.update()
cache.open(None) cache.open(None)
with cache.actiongroup(): with cache.actiongroup():