Merge ~pengpengs/cloud-init:fix/load-DataSourceOVF-at-the-last-on-VMware-Platform-if-no-data-found into cloud-init:master

Proposed by Pengpeng Sun
Status: Needs review
Proposed branch: ~pengpengs/cloud-init:fix/load-DataSourceOVF-at-the-last-on-VMware-Platform-if-no-data-found
Merge into: cloud-init:master
Diff against target: 127 lines (+38/-20)
2 files modified
cloudinit/sources/DataSourceOVF.py (+34/-16)
tests/unittests/test_vmware_config_file.py (+4/-4)
Reviewer Review Type Date Requested Status
Scott Moser Needs Fixing
Review via email: mp+375587@code.launchpad.net

Description of the change

1. Generate random instance-id when vmware customization cfg found. If use fixed
   instance-id, network configuration in customization cfg will not be applied.
2. Load DatasourceOVF when no vmware customization cfg found if machine fulfills:
   a. VMware Virtualization Platform found
   b. flag vmware_customization_supported is True
   c. flag disable_vmware_customization is False
   d. VMware tools deployPkgPlugin found
   These conditions are same with the ones in ds-identify script, if ds-identify
   found OVF, then load DatasourceOVF.
3. Read instance-id from machine and set it to metadata when no vmware customization
   cfg found, this prevents cloud-init load default network configuration, so that
   existing network configuration will not be overwritten.
4. Modify check instance-id unittest.
5. Modify default timeout for waiting vmware customization cfg, 30 seconds
   should be enough.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

@Pengpeng,

Cloud-init has moved code-hosting and pull request to github. Please re-submit there.

https://lists.launchpad.net/cloud-init/msg00231.html

review: Needs Fixing
Revision history for this message
Pengpeng Sun (pengpengs) wrote :

Thanks @Scott, follows the instruction.

Revision history for this message
Pengpeng Sun (pengpengs) wrote :

@Scott, I have finished the instruction and "'Create pull request'", then waiting for the approval, am I doing correctly?

Unmerged commits

2120168... by Pengpeng Sun

This change is to fix LP bug #1835205, it includes:
1. Generate random instance-id when vmware customization cfg found. If use fixed
   instance-id, network configuration in customization cfg will not be applied.
2. Load DatasourceOVF when no vmware customization cfg found if machine fulfills:
   a. VMware Virtualization Platform found
   b. flag vmware_customization_supported is True
   c. flag disable_vmware_customization is False
   d. VMware tools deployPkgPlugin found
   These conditions are same with the ones in ds-identify script, if ds-identify
   found OVF, then load DatasourceOVF.
3. Read instance-id from machine and set it to metadata when no vmware customization
   cfg found, this prevents cloud-init load default network configuration, so that
   existing network configuration will not be overwritten.
4. Modify check instance-id unittest.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
2index 896841e..2125df3 100644
3--- a/cloudinit/sources/DataSourceOVF.py
4+++ b/cloudinit/sources/DataSourceOVF.py
5@@ -65,7 +65,7 @@ class DataSourceOVF(sources.DataSource):
6 self._network_config = None
7 self._vmware_nics_to_enable = None
8 self._vmware_cust_conf = None
9- self._vmware_cust_found = False
10+ self._vmware_cust_enabled = False
11
12 def __str__(self):
13 root = sources.DataSource.__str__(self)
14@@ -113,6 +113,12 @@ class DataSourceOVF(sources.DataSource):
15 if deployPkgPluginPath:
16 LOG.debug("Found the customization plugin at %s",
17 deployPkgPluginPath)
18+ # Set True when below conditions are all fulfilled
19+ # 1. VMware Virtualization Platfrom found
20+ # 2. VMware Customization supported is True
21+ # 3. disable_vmware_customization config is False
22+ # 4. libdeployPkgPlugin.so found
23+ self._vmware_cust_enabled = True
24 break
25
26 if deployPkgPluginPath:
27@@ -246,8 +252,7 @@ class DataSourceOVF(sources.DataSource):
28 GuestCustEvent.GUESTCUST_EVENT_CUSTOMIZE_FAILED,
29 vmwareImcConfigFilePath)
30
31- self._vmware_cust_found = True
32- found.append('vmware-tools')
33+ found.append('vmware-tools-new-config')
34
35 # TODO: Need to set the status to DONE only when the
36 # customization is done successfully.
37@@ -272,7 +277,11 @@ class DataSourceOVF(sources.DataSource):
38
39 # There was no OVF transports found
40 if len(found) == 0:
41- return False
42+ if self._vmware_cust_enabled:
43+ found.append("vmware-tools-no-config")
44+ (md, ud, cfg) = read_vmware_imc(None, self.paths)
45+ else:
46+ return False
47
48 if 'seedfrom' in md and md['seedfrom']:
49 seedfrom = md['seedfrom']
50@@ -336,7 +345,7 @@ class DataSourceOVFNet(DataSourceOVF):
51
52
53 def get_max_wait_from_cfg(cfg):
54- default_max_wait = 90
55+ default_max_wait = 30
56 max_wait_cfg_option = 'vmware_cust_file_max_wait'
57 max_wait = default_max_wait
58
59@@ -393,20 +402,29 @@ def get_network_config(nics=None, nameservers=None, search=None):
60
61 # This will return a dict with some content
62 # meta-data, user-data, some config
63-def read_vmware_imc(config):
64+def read_vmware_imc(config, paths=None):
65 md = {}
66 cfg = {}
67 ud = None
68- if config.host_name:
69- if config.domain_name:
70- md['local-hostname'] = config.host_name + "." + config.domain_name
71- else:
72- md['local-hostname'] = config.host_name
73-
74- if config.timezone:
75- cfg['timezone'] = config.timezone
76-
77- md['instance-id'] = "iid-vmware-imc"
78+ if config is not None:
79+ if config.host_name:
80+ if config.domain_name:
81+ md['local-hostname'] = config.host_name + "." +\
82+ config.domain_name
83+ else:
84+ md['local-hostname'] = config.host_name
85+ if config.timezone:
86+ cfg['timezone'] = config.timezone
87+ # Set a random new instance-id if there is new config
88+ md['instance-id'] = "iid-vmware-imc-" + util.rand_str(strlen=8)
89+ else:
90+ # Set the same intance-id with previous one if no config
91+ dp = paths.get_cpath('data')
92+ iid_fn = os.path.join(dp, 'instance-id')
93+ try:
94+ md['instance-id'] = util.load_file(iid_fn).strip()
95+ except Exception:
96+ md['instance-id'] = "iid-vmware-imc"
97 return (md, ud, cfg)
98
99
100diff --git a/tests/unittests/test_vmware_config_file.py b/tests/unittests/test_vmware_config_file.py
101index 16343ed..91adab9 100644
102--- a/tests/unittests/test_vmware_config_file.py
103+++ b/tests/unittests/test_vmware_config_file.py
104@@ -56,19 +56,19 @@ class TestVmwareConfigFile(CiTestCase):
105 """Tests instance id for the DatasourceOVF"""
106 cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
107
108- instance_id_prefix = 'iid-vmware-'
109+ instance_id_prefix = 'iid-vmware-imc'
110
111 conf = Config(cf)
112
113 (md1, _, _) = read_vmware_imc(conf)
114 self.assertIn(instance_id_prefix, md1["instance-id"])
115- self.assertEqual(md1["instance-id"], 'iid-vmware-imc')
116+ self.assertEqual(len(md1["instance-id"]), len(instance_id_prefix) + 9)
117
118 (md2, _, _) = read_vmware_imc(conf)
119 self.assertIn(instance_id_prefix, md2["instance-id"])
120- self.assertEqual(md2["instance-id"], 'iid-vmware-imc')
121+ self.assertEqual(len(md2["instance-id"]), len(instance_id_prefix) + 9)
122
123- self.assertEqual(md2["instance-id"], md1["instance-id"])
124+ self.assertNotEqual(md2["instance-id"], md1["instance-id"])
125
126 def test_configfile_static_2nics(self):
127 """Tests Config class for a configuration with two static NICs."""

Subscribers

People subscribed via source and target branches