
UrlResponse: biggest change... make readurl return bytes, making user know what to do with it. util: add load_tfile_or_url for loading text file or url as read_file_or_url now returns bytes ec2_utils: all meta-data is text, remove non-obvious string translations DigitalOcean: adjust for ec2_utils DataSourceGCE, DataSourceMAAS: user-data is binary other fields are text. openstack.py: read paths without decoding to text. This is ok as paths other than user-data are json, and load_json will handle load_file still returns text, and that is what most things use.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from cloudinit import util
|
|
|
|
from .helpers import TestCase, populate_dir
|
|
|
|
import shutil
|
|
import tempfile
|
|
|
|
|
|
class TestPathPrefix2Dict(TestCase):
|
|
|
|
def setUp(self):
|
|
super(TestPathPrefix2Dict, self).setUp()
|
|
self.tmp = tempfile.mkdtemp()
|
|
self.addCleanup(shutil.rmtree, self.tmp)
|
|
|
|
def test_required_only(self):
|
|
dirdata = {'f1': b'f1content', 'f2': b'f2content'}
|
|
populate_dir(self.tmp, dirdata)
|
|
|
|
ret = util.pathprefix2dict(self.tmp, required=['f1', 'f2'])
|
|
self.assertEqual(dirdata, ret)
|
|
|
|
def test_required_missing(self):
|
|
dirdata = {'f1': b'f1content'}
|
|
populate_dir(self.tmp, dirdata)
|
|
kwargs = {'required': ['f1', 'f2']}
|
|
self.assertRaises(ValueError, util.pathprefix2dict, self.tmp, **kwargs)
|
|
|
|
def test_no_required_and_optional(self):
|
|
dirdata = {'f1': b'f1c', 'f2': b'f2c'}
|
|
populate_dir(self.tmp, dirdata)
|
|
|
|
ret = util.pathprefix2dict(self.tmp, required=None,
|
|
optional=['f1', 'f2'])
|
|
self.assertEqual(dirdata, ret)
|
|
|
|
def test_required_and_optional(self):
|
|
dirdata = {'f1': b'f1c', 'f2': b'f2c'}
|
|
populate_dir(self.tmp, dirdata)
|
|
|
|
ret = util.pathprefix2dict(self.tmp, required=['f1'], optional=['f2'])
|
|
self.assertEqual(dirdata, ret)
|
|
|
|
# vi: ts=4 expandtab
|