Merge "baremetal.configdrive: tolerate user_data as a string"
This commit is contained in:
@@ -52,7 +52,11 @@ def populate_directory(metadata, user_data=None, versions=None,
|
||||
json.dump(network_data, fp)
|
||||
|
||||
if user_data:
|
||||
with open(os.path.join(subdir, 'user_data'), 'wb') as fp:
|
||||
# Strictly speaking, user data is binary, but in many cases
|
||||
# it's actually a text (cloud-init, ignition, etc).
|
||||
flag = 't' if isinstance(user_data, six.text_type) else 'b'
|
||||
with open(os.path.join(subdir, 'user_data'),
|
||||
'w%s' % flag) as fp:
|
||||
fp.write(user_data)
|
||||
|
||||
yield d
|
||||
|
@@ -48,6 +48,8 @@ class TestPopulateDirectory(testtools.TestCase):
|
||||
if user_data is None:
|
||||
self.assertFalse(os.path.exists(user_data_file))
|
||||
else:
|
||||
if isinstance(user_data, six.text_type):
|
||||
user_data = user_data.encode()
|
||||
with open(user_data_file, 'rb') as fp:
|
||||
self.assertEqual(user_data, fp.read())
|
||||
|
||||
@@ -60,6 +62,9 @@ class TestPopulateDirectory(testtools.TestCase):
|
||||
def test_with_user_data(self):
|
||||
self._check({'foo': 42}, b'I am user data')
|
||||
|
||||
def test_with_user_data_as_string(self):
|
||||
self._check({'foo': 42}, u'I am user data')
|
||||
|
||||
def test_with_network_data(self):
|
||||
self._check({'foo': 42}, network_data={'networks': {}})
|
||||
|
||||
|
Reference in New Issue
Block a user