sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
c1c26e
From 8a3bf53398f312b46ed4f304df4c66d061e612c7 Mon Sep 17 00:00:00 2001
c1c26e
From: Eduardo Otubo <otubo@redhat.com>
c1c26e
Date: Thu, 28 Feb 2019 12:38:36 +0100
c1c26e
Subject: cloud-init-per: don't use dashes in sem names
c1c26e
c1c26e
RH-Author: Eduardo Otubo <otubo@redhat.com>
c1c26e
Message-id: <20190228123836.17979-1-otubo@redhat.com>
c1c26e
Patchwork-id: 84743
c1c26e
O-Subject: [RHEL-7.7 cloud-init PATCH] This is to fix https://bugs.launchpad.net/cloud-init/+bug/1812676
c1c26e
Bugzilla: 1664876
c1c26e
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
c1c26e
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
c1c26e
c1c26e
From: Vitaly Kuznetsov <vkuznets@redhat.com>
c1c26e
c1c26e
    It was found that when there is a dash in cloud-init-per command
c1c26e
    name and cloud-init-per is executed through cloud-init's bootcmd, e.g:
c1c26e
c1c26e
    bootcmd:
c1c26e
     - cloud-init-per instance mycmd-bootcmd /usr/bin/mycmd
c1c26e
c1c26e
    the command is executed on each boot. However, running the same
c1c26e
    cloud-init-per command manually after boot doesn't reveal the issue. Turns
c1c26e
    out the issue comes from 'migrator' cloud-init module which renames all
c1c26e
    files in /var/lib/cloud/instance/sem/ replacing dashes with underscores. As
c1c26e
    migrator runs before bootcmd it renames
c1c26e
c1c26e
    /var/lib/cloud/instance/sem/bootper.mycmd-bootcmd.instance
c1c26e
    to
c1c26e
    /var/lib/cloud/instance/sem/bootper.mycmd_bootcmd.instance
c1c26e
c1c26e
    so cloud-init-per doesn't see it and thinks that the comment was never ran
c1c26e
    before. On next boot the sequence repeats.
c1c26e
c1c26e
    There are multiple ways to resolve the issue. This patch takes the
c1c26e
    following approach: 'canonicalize' sem names by replacing dashes with
c1c26e
    underscores (this is consistent with post-'migrator' contents of
c1c26e
    /var/lib/cloud/instance/sem/). We, however, need to be careful: in case
c1c26e
    someone had a command with dashes before and he had migrator module enables
c1c26e
    we need to see the old sem file (or the command will run again and this can
c1c26e
    be as bad as formatting a partition!) so we add a small 'migrator' part to
c1c26e
    cloud-init-per script itself checking for legacy sem names.
c1c26e
c1c26e
    Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
c1c26e
c1c26e
commit 9cf9d8cdd3a8fd7d4d425f7051122d0ac8af2bbd
c1c26e
Author: Vitaly Kuznetsov <vkuznets@redhat.com>
c1c26e
Date:   Mon Feb 18 22:55:49 2019 +0000
c1c26e
c1c26e
    This is to fix https://bugs.launchpad.net/cloud-init/+bug/1812676
c1c26e
c1c26e
Resolves: rhbz#1664876
c1c26e
X-downstream-only: false
c1c26e
c1c26e
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
c1c26e
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c1c26e
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
c1c26e
---
c1c26e
 tools/cloud-init-per | 8 +++++++-
c1c26e
 1 file changed, 7 insertions(+), 1 deletion(-)
c1c26e
c1c26e
diff --git a/tools/cloud-init-per b/tools/cloud-init-per
c1c26e
index 7d6754b6..eae3e93f 100755
c1c26e
--- a/tools/cloud-init-per
c1c26e
+++ b/tools/cloud-init-per
c1c26e
@@ -38,7 +38,7 @@ fi
c1c26e
 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage ; exit 0; }
c1c26e
 [ $# -ge 3 ] || { Usage 1>&2; exit 1; }
c1c26e
 freq=$1
c1c26e
-name=$2
c1c26e
+name=${2/-/_}
c1c26e
 shift 2;
c1c26e
 
c1c26e
 [ "${name#*/}" = "${name}" ] || fail "name cannot contain a /"
c1c26e
@@ -53,6 +53,12 @@ esac
c1c26e
 [ -d "${sem%/*}" ] || mkdir -p "${sem%/*}" ||
c1c26e
    fail "failed to make directory for ${sem}"
c1c26e
 
c1c26e
+# Rename legacy sem files with dashes in their names. Do not overwrite existing
c1c26e
+# sem files to prevent clobbering those which may have been created from calls
c1c26e
+# outside of cloud-init.
c1c26e
+sem_legacy="${sem/_/-}"
c1c26e
+[ "$sem" != "$sem_legacy" -a -e "$sem_legacy" ] && mv -n "$sem_legacy" "$sem"
c1c26e
+
c1c26e
 [ "$freq" != "always" -a -e "$sem" ] && exit 0
c1c26e
 "$@"
c1c26e
 ret=$?
c1c26e
-- 
c1c26e
2.20.1
c1c26e