From 277fb483a4e798bc49b5201fd596d11ff32c650a Mon Sep 17 00:00:00 2001 From: Scott Hussey Date: Tue, 1 Oct 2019 17:10:36 -0500 Subject: [PATCH] (chart) Fix import issue - The import script would skip creating a new boot source selection for a non-default distro in some cases due to a non-recommended if construct. Change to the recommended 'if ! grep -q' pattern Change-Id: I59e6732598f74fc34a6986dbdfe4200d8cd9ea9f --- .../templates/bin/_import-boot-resources.sh.tpl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/charts/maas/templates/bin/_import-boot-resources.sh.tpl b/charts/maas/templates/bin/_import-boot-resources.sh.tpl index 0c73ecd..17e7601 100644 --- a/charts/maas/templates/bin/_import-boot-resources.sh.tpl +++ b/charts/maas/templates/bin/_import-boot-resources.sh.tpl @@ -177,12 +177,16 @@ function configure_boot_sources { check_then_set http_boot ${MAAS_HTTP_BOOT} - selected_releases=$(maas ${ADMIN_USERNAME} boot-source-selections read 1 | tail -n +1 | jq -r '.[] | .release') + selected_releases="$(maas ${ADMIN_USERNAME} boot-source-selections read 1 | jq -r '.[] | .release')" - if [[ -z $(echo "${selected_releases}" | grep "${MAAS_DEFAULT_DISTRO}") ]] + if ! echo "${selected_releases}" | grep -q "${MAAS_DEFAULT_DISTRO}" then - maas ${ADMIN_USERNAME} boot-source-selections create 1 os="${MAAS_DEFAULT_OS}" \ - release="${MAAS_DEFAULT_DISTRO}" arches="amd64" subarches='*' labels='*' + # Need to start an import to get the availability data + maas "$ADMIN_USERNAME" boot-resources import + if ! maas ${ADMIN_USERNAME} boot-source-selections create 1 os="${MAAS_DEFAULT_OS}" \ + release="${MAAS_DEFAULT_DISTRO}" arches="amd64" subarches='*' labels='*' | grep -q 'Success'; then + return 1 + fi fi } @@ -203,7 +207,7 @@ configure_ntp configure_dns # make call to import images -configure_boot_sources +timer "$RETRY_TIMER" configure_boot_sources start_import if [[ $? -eq 0 ]]