Fix cfn-init-data path in ignition

The 'local-data' in path /var/lib/os-collect-config/local-data should
be a directory, not a file. However, even if we can fix this, now
os-apply-config will merge configs based on the order [ec2, heat and
local], but actually there is no deployments collected local. Then
unfortunately, the deployments collected from Heat will be
overwriten because the merging order in os-apply-config. At this
moment, we can't change os-apply-config since it's deliberate.
So the only reasonable way we can do now is using
/var/lib/heat-cfntools/cfn-init-data and /var/lib/cloud/data/cfn-init-data.

Story: 2006566
Task: 36851

Change-Id: I3b1ed30967e9235e9e830c5e4156f739303be618
(cherry picked from commit ea18c18188)
This commit is contained in:
Feilong Wang 2019-10-14 16:35:27 +13:00
parent 747e4b7658
commit e11cfb569b
2 changed files with 18 additions and 11 deletions

View File

@ -448,10 +448,12 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
payload = jsonutils.loads(userdata)
encoded_metadata = urlparse.quote(jsonutils.dumps(metadata))
cfn_init_data = {
path_list = ["/var/lib/heat-cfntools/cfn-init-data",
"/var/lib/cloud/data/cfn-init-data"]
ignition_format_metadata = {
"filesystem": "root",
"group": {"name": "root"},
"path": "/var/lib/os-collect-config/local-data",
"path": "",
"user": {"name": "root"},
"contents": {
"source": "data:," + encoded_metadata,
@ -459,6 +461,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
"mode": 0o640
}
for path in path_list:
storage = payload.setdefault('storage', {})
try:
files = storage.setdefault('files', [])
@ -466,7 +469,9 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
raise ValueError('Ignition "storage" section must be a map')
else:
try:
files.append(cfn_init_data)
data = ignition_format_metadata.copy()
data["path"] = path
files.append(data)
except AttributeError:
raise ValueError('Ignition "files" section must be a list')

View File

@ -402,8 +402,10 @@ class NovaClientPluginUserdataTest(NovaClientPluginTestCase):
userdata=userdata,
user_data_format=ud_format)
ig = json.loads(data)
self.assertEqual("/var/lib/os-collect-config/local-data",
self.assertEqual("/var/lib/heat-cfntools/cfn-init-data",
ig["storage"]["files"][0]["path"])
self.assertEqual("/var/lib/cloud/data/cfn-init-data",
ig["storage"]["files"][1]["path"])
self.assertEqual("data:,%7B%22os-collect-config%22%3A%20%7B%22heat"
"%22%3A%20%7B%22password%22%3A%20%22%2A%2A%2A%22"
"%7D%7D%7D",