Skip to content

Commit

Permalink
Merge pull request #1128 from CarlosNihelton/fix-integration-cls-empty
Browse files Browse the repository at this point in the history
Complementary to 1127 on integration side
  • Loading branch information
dbungert authored Dec 7, 2021
2 parents a80b750 + 22a8219 commit 55b2d4c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
8 changes: 5 additions & 3 deletions scripts/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ validate () {
echo "user not assigned with the expected group sudo"
exit 1
fi
if [ -z "$( ls .subiquity/var/cache/apt/archives/)" ] ; then
echo "expected not empty directory var/cache/apt/archives/"
lang="$(grep -Eo 'LANG="([^.@ _]+)' .subiquity/etc/default/locale | cut -d \" -f 2)"
if [ -z "$( ls .subiquity/var/cache/apt/archives/) | grep $lang" ] ; then
echo "expected $lang language packs in directory var/cache/apt/archives/"
exit 1
fi
if [ -z "$( diff -Nup .subiquity/etc/locale.gen .subiquity/etc/locale.gen-)" ] ; then
if [ -z "$( diff -Nup .subiquity/etc/locale.gen .subiquity/etc/locale.gen.test)" ] ; then
echo "expected changes in etc/locale.gen"
exit 1
fi
Expand All @@ -99,6 +100,7 @@ clean () {
rm -rf .subiquity/run/
rm -rf .subiquity/home/
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/*.conf
rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg
Expand Down
53 changes: 39 additions & 14 deletions system_setup/server/controllers/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ async def _activate_locale(self, lang, env) -> bool:

return True

async def _install_check_lang_support_packages(self, lang, env) -> bool:
""" Install packages recommended by check-language-support
command. lang is expected to be one single language/locale.
async def __recommended_language_packs(self, lang, env) -> List[str]:
""" Return a list of package names recommended by
check-language-support (or a fake list if in dryrun).
List returned can be empty on success. None for failure.
"""
clsCommand = "check-language-support"
# lang code may be separated by @, dot or spaces.
Expand All @@ -127,29 +128,48 @@ async def _install_check_lang_support_packages(self, lang, env) -> bool:
matches = pattern.match(lang)
if matches is None:
log.error("Failed to match expected language format: %s", lang)
return False
return None

langCodes = matches.groups()
if len(langCodes) != 1:
log.error("Only one match was expected for: %s", lang)
return False
return None

clsLang = langCodes[0]
packages = []
# Running that command doesn't require root.
cp = await arun_command([clsCommand, "-l", clsLang], env=env)
if cp.returncode != 0:
log.error('Command "%s" failed with return code %d',
cp.args, cp.returncode)
return False
if not self.app.opts.dry_run:
return None

packages = [pkg for pkg in cp.stdout.strip().split(' ') if pkg]
if len(packages) == 0:
log.debug("%s didn't recommend any packages. Nothing to do.",
clsCommand)
return True
else:
packages += [pkg for pkg in cp.stdout.strip().split(' ') if pkg]

# We will always have language-pack-{baseLang}-base in dryrun.
if len(packages) == 0 and self.app.opts.dry_run:
baseLang = clsLang.split('_')[0]
packages += ["language-pack-{}-base".format(baseLang)]

return packages

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_language_packs(lang, env)
if packages is None:
log.error('Failed to detect recommended language packs.')
return False

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,
apt_pkg.config
.find_dir("Dir::Cache::Archives")[1:])
Expand All @@ -160,10 +180,15 @@ async def _install_check_lang_support_packages(self, lang, env) -> bool:
archive = os.path.join(packs_dir, cache[package].fullname)
with open(archive, "wt") as f:
f.write(cache[package].candidate.uri)
except IOError:
log.error("Failed to write %s file.", archive)

return True

except IOError as e:
log.error("Failed to write file.", e)
return False

if len(packages) == 0:
log.info("No missing recommended packages. Nothing to do.")
return True

cache.update()
Expand Down

0 comments on commit 55b2d4c

Please sign in to comment.