summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-04-30 19:57:32 -0400
committerScott Moser <smoser@ubuntu.com>2018-04-30 19:57:32 -0400
commit8c8d6ddfe4315c7fa98560f4db3ae52f44aebc74 (patch)
treeb2f395bfdec7006660b272be39be8ce325751e92 /debian
parent3016815595bc824e2a821144922622503c566b0c (diff)
downloadvyos-cloud-init-8c8d6ddfe4315c7fa98560f4db3ae52f44aebc74.tar.gz
vyos-cloud-init-8c8d6ddfe4315c7fa98560f4db3ae52f44aebc74.zip
cherry pick 11172924
LP: #1766401
Diffstat (limited to 'debian')
-rw-r--r--debian/patches/cpick-11172924-IBMCloud-Disable-config-drive-and-nocloud-only-if230
-rw-r--r--debian/patches/series1
2 files changed, 231 insertions, 0 deletions
diff --git a/debian/patches/cpick-11172924-IBMCloud-Disable-config-drive-and-nocloud-only-if b/debian/patches/cpick-11172924-IBMCloud-Disable-config-drive-and-nocloud-only-if
new file mode 100644
index 00000000..83aca30c
--- /dev/null
+++ b/debian/patches/cpick-11172924-IBMCloud-Disable-config-drive-and-nocloud-only-if
@@ -0,0 +1,230 @@
+From 11172924a48a47a7231d19d9cefe628dfddda8bf Mon Sep 17 00:00:00 2001
+From: Scott Moser <smoser@ubuntu.com>
+Date: Mon, 30 Apr 2018 13:21:51 -0600
+Subject: [PATCH] IBMCloud: Disable config-drive and nocloud only if IBMCloud
+ is enabled.
+
+Ubuntu images on IBMCloud for 16.04 have some seed data in
+/var/lib/cloud/data/seed/nocloud-net. In order to have systems with
+IBMCloud enabled, we modified ds-identify detection to skip that seed
+if the system was on IBMCloud. That change did not consider the
+fact that IBMCloud might not be in the datasource list.
+
+There was similar logic in the ConfigDrive datasource in ds-identify
+and the datasource itself.
+
+Config drive is now updated to only check and avoid IBMCloud if IBMCloud
+is enabled. The check in ds-identify for nocloud was dropped. If a
+user provides a nocloud seed on IBMCloud, then that can be used.
+
+This means that systems running Xenial will continue to get their
+old datasources.
+
+LP: #1766401
+---
+ cloudinit/sources/DataSourceConfigDrive.py | 11 +++-
+ tests/unittests/test_ds_identify.py | 77 ++++++++++++++++++++--
+ tools/ds-identify | 17 +++--
+ 3 files changed, 91 insertions(+), 14 deletions(-)
+
+--- a/cloudinit/sources/DataSourceConfigDrive.py
++++ b/cloudinit/sources/DataSourceConfigDrive.py
+@@ -69,7 +69,8 @@ class DataSourceConfigDrive(openstack.So
+ util.logexc(LOG, "Failed reading config drive from %s", sdir)
+
+ if not found:
+- for dev in find_candidate_devs():
++ dslist = self.sys_cfg.get('datasource_list')
++ for dev in find_candidate_devs(dslist=dslist):
+ try:
+ # Set mtype if freebsd and turn off sync
+ if dev.startswith("/dev/cd"):
+@@ -211,7 +212,7 @@ def write_injected_files(files):
+ util.logexc(LOG, "Failed writing file: %s", filename)
+
+
+-def find_candidate_devs(probe_optical=True):
++def find_candidate_devs(probe_optical=True, dslist=None):
+ """Return a list of devices that may contain the config drive.
+
+ The returned list is sorted by search order where the first item has
+@@ -227,6 +228,9 @@ def find_candidate_devs(probe_optical=Tr
+ * either vfat or iso9660 formated
+ * labeled with 'config-2' or 'CONFIG-2'
+ """
++ if dslist is None:
++ dslist = []
++
+ # query optical drive to get it in blkid cache for 2.6 kernels
+ if probe_optical:
+ for device in OPTICAL_DEVICES:
+@@ -257,7 +261,8 @@ def find_candidate_devs(probe_optical=Tr
+ devices = [d for d in candidates
+ if d in by_label or not util.is_partition(d)]
+
+- if devices:
++ LOG.debug("devices=%s dslist=%s", devices, dslist)
++ if devices and "IBMCloud" in dslist:
+ # IBMCloud uses config-2 label, but limited to a single UUID.
+ ibm_platform, ibm_path = get_ibm_platform()
+ if ibm_path in devices:
+--- a/tests/unittests/test_ds_identify.py
++++ b/tests/unittests/test_ds_identify.py
+@@ -184,17 +184,18 @@ class DsIdentifyBase(CiTestCase):
+ data, RC_FOUND, dslist=[data.get('ds'), DS_NONE])
+
+ def _check_via_dict(self, data, rc, dslist=None, **kwargs):
+- found_rc, out, err, cfg, files = self._call_via_dict(data, **kwargs)
++ ret = self._call_via_dict(data, **kwargs)
+ good = False
+ try:
+- self.assertEqual(rc, found_rc)
++ self.assertEqual(rc, ret.rc)
+ if dslist is not None:
+- self.assertEqual(dslist, cfg['datasource_list'])
++ self.assertEqual(dslist, ret.cfg['datasource_list'])
+ good = True
+ finally:
+ if not good:
+- _print_run_output(rc, out, err, cfg, files)
+- return rc, out, err, cfg, files
++ _print_run_output(ret.rc, ret.stdout, ret.stderr, ret.cfg,
++ ret.files)
++ return ret
+
+
+ class TestDsIdentify(DsIdentifyBase):
+@@ -245,13 +246,40 @@ class TestDsIdentify(DsIdentifyBase):
+ def test_config_drive(self):
+ """ConfigDrive datasource has a disk with LABEL=config-2."""
+ self._test_ds_found('ConfigDrive')
+- return
+
+ def test_config_drive_upper(self):
+ """ConfigDrive datasource has a disk with LABEL=CONFIG-2."""
+ self._test_ds_found('ConfigDriveUpper')
+ return
+
++ def test_config_drive_seed(self):
++ """Config Drive seed directory."""
++ self._test_ds_found('ConfigDrive-seed')
++
++ def test_config_drive_interacts_with_ibmcloud_config_disk(self):
++ """Verify ConfigDrive interaction with IBMCloud.
++
++ If ConfigDrive is enabled and not IBMCloud, then ConfigDrive
++ should claim the ibmcloud 'config-2' disk.
++ If IBMCloud is enabled, then ConfigDrive should skip."""
++ data = copy.deepcopy(VALID_CFG['IBMCloud-config-2'])
++ files = data.get('files', {})
++ if not files:
++ data['files'] = files
++ cfgpath = 'etc/cloud/cloud.cfg.d/99_networklayer_common.cfg'
++
++ # with list including IBMCloud, config drive should be not found.
++ files[cfgpath] = 'datasource_list: [ ConfigDrive, IBMCloud ]\n'
++ ret = self._check_via_dict(data, shell_true)
++ self.assertEqual(
++ ret.cfg.get('datasource_list'), ['IBMCloud', 'None'])
++
++ # But if IBMCloud is not enabled, config drive should claim this.
++ files[cfgpath] = 'datasource_list: [ ConfigDrive, NoCloud ]\n'
++ ret = self._check_via_dict(data, shell_true)
++ self.assertEqual(
++ ret.cfg.get('datasource_list'), ['ConfigDrive', 'None'])
++
+ def test_ibmcloud_template_userdata_in_provisioning(self):
+ """Template provisioned with user-data during provisioning stage.
+
+@@ -307,6 +335,37 @@ class TestDsIdentify(DsIdentifyBase):
+ self._check_via_dict(
+ data, rc=RC_FOUND, dslist=['ConfigDrive', DS_NONE])
+
++ def test_ibmcloud_with_nocloud_seed(self):
++ """NoCloud seed should be preferred over IBMCloud.
++
++ A nocloud seed should be preferred over IBMCloud even if enabled.
++ Ubuntu 16.04 images have <vlc>/seed/nocloud-net. LP: #1766401."""
++ data = copy.deepcopy(VALID_CFG['IBMCloud-config-2'])
++ files = data.get('files', {})
++ if not files:
++ data['files'] = files
++ files.update(VALID_CFG['NoCloud-seed']['files'])
++ ret = self._check_via_dict(data, shell_true)
++ self.assertEqual(
++ ['NoCloud', 'IBMCloud', 'None'],
++ ret.cfg.get('datasource_list'))
++
++ def test_ibmcloud_with_configdrive_seed(self):
++ """ConfigDrive seed should be preferred over IBMCloud.
++
++ A ConfigDrive seed should be preferred over IBMCloud even if enabled.
++ Ubuntu 16.04 images have a fstab entry that mounts the
++ METADATA disk into <vlc>/seed/config_drive. LP: ##1766401."""
++ data = copy.deepcopy(VALID_CFG['IBMCloud-config-2'])
++ files = data.get('files', {})
++ if not files:
++ data['files'] = files
++ files.update(VALID_CFG['ConfigDrive-seed']['files'])
++ ret = self._check_via_dict(data, shell_true)
++ self.assertEqual(
++ ['ConfigDrive', 'IBMCloud', 'None'],
++ ret.cfg.get('datasource_list'))
++
+ def test_policy_disabled(self):
+ """A Builtin policy of 'disabled' should return not found.
+
+@@ -684,6 +743,12 @@ VALID_CFG = {
+ },
+ ],
+ },
++ 'ConfigDrive-seed': {
++ 'ds': 'ConfigDrive',
++ 'files': {
++ os.path.join(P_SEED_DIR, 'config_drive', 'openstack',
++ 'latest', 'meta_data.json'): 'md\n'},
++ },
+ 'Hetzner': {
+ 'ds': 'Hetzner',
+ 'files': {P_SYS_VENDOR: 'Hetzner\n'},
+--- a/tools/ds-identify
++++ b/tools/ds-identify
+@@ -601,7 +601,6 @@ dscheck_NoCloud() {
+ *\ ds=nocloud*) return ${DS_FOUND};;
+ esac
+
+- is_ibm_cloud && return ${DS_NOT_FOUND}
+ for d in nocloud nocloud-net; do
+ check_seed_dir "$d" meta-data user-data && return ${DS_FOUND}
+ check_writable_seed_dir "$d" meta-data user-data && return ${DS_FOUND}
+@@ -612,11 +611,12 @@ dscheck_NoCloud() {
+ return ${DS_NOT_FOUND}
+ }
+
++is_ds_enabled() {
++ local name="$1" pad=" ${DI_DSLIST} "
++ [ "${pad#* $name }" != "${pad}" ]
++}
++
+ check_configdrive_v2() {
+- is_ibm_cloud && return ${DS_NOT_FOUND}
+- if has_fs_with_label CONFIG-2 config-2; then
+- return ${DS_FOUND}
+- fi
+ # look in /config-drive <vlc>/seed/config_drive for a directory
+ # openstack/YYYY-MM-DD format with a file meta_data.json
+ local d=""
+@@ -631,6 +631,13 @@ check_configdrive_v2() {
+ debug 1 "config drive seeded directory had only 'latest'"
+ return ${DS_FOUND}
+ fi
++
++ is_ds_enabled "IBMCloud"
++ debug 1 "is_ds_enabled returned $?: $DI_DSLIST"
++ is_ds_enabled "IBMCloud" && is_ibm_cloud && return ${DS_NOT_FOUND}
++ if has_fs_with_label CONFIG-2 config-2; then
++ return ${DS_FOUND}
++ fi
+ return ${DS_NOT_FOUND}
+ }
+
diff --git a/debian/patches/series b/debian/patches/series
index b38df2bf..7351c3a2 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@ azure-use-walinux-agent.patch
ds-identify-behavior-xenial.patch
stable-release-no-jsonschema-dep.patch
cpick-6ef92c98-IBMCloud-recognize-provisioning-environment-during
+cpick-11172924-IBMCloud-Disable-config-drive-and-nocloud-only-if