Commit 3c01d90e authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

slapos: Encode unicode to UTF-8

/reviewed-on nexedi/slapos!480
parent faa89605
...@@ -190,12 +190,15 @@ class Recipe(object): ...@@ -190,12 +190,15 @@ class Recipe(object):
# Then try to get all the parameters. In case of problem, put empty string. # Then try to get all the parameters. In case of problem, put empty string.
for param in return_parameters: for param in return_parameters:
options['connection-%s' % param] = '' value = ''
try: try:
options['connection-%s' % param] = return_parameter_dict[param] value = return_parameter_dict[param]
except KeyError: except KeyError:
if self.failed is None: if self.failed is None:
self.failed = param self.failed = param
if isinstance(value, unicode):
value = value.encode('UTF-8')
options['connection-%s' % param] = value
def _filterForStorage(self, partition_parameter_kw): def _filterForStorage(self, partition_parameter_kw):
return partition_parameter_kw return partition_parameter_kw
......
...@@ -264,6 +264,8 @@ class Recipe(object): ...@@ -264,6 +264,8 @@ class Recipe(object):
# be very careful with overriding master's information # be very careful with overriding master's information
for key, value in flatten_dict(partition_params).items(): for key, value in flatten_dict(partition_params).items():
if key not in options: if key not in options:
if isinstance(value, unicode):
value = value.encode('UTF-8')
options[key] = value options[key] = value
# print out augmented options to see what we are passing # print out augmented options to see what we are passing
logger.debug(str(options)) logger.debug(str(options))
......
...@@ -83,6 +83,7 @@ class RecipeTestMixin(object): ...@@ -83,6 +83,7 @@ class RecipeTestMixin(object):
result = recipe.install() result = recipe.install()
self.assertEqual([], result) self.assertEqual([], result)
self.assertEqual(options['connection-anything'], 'done') self.assertEqual(options['connection-anything'], 'done')
self.assertIsInstance(options['connection-anything'], str)
self.request_instance.assert_called_with( self.request_instance.assert_called_with(
'', 'RootSoftwareInstance', '', filter_kw={}, '', 'RootSoftwareInstance', '', filter_kw={},
partition_parameter_kw=self.called_partition_parameter_kw, partition_parameter_kw=self.called_partition_parameter_kw,
......
...@@ -18,7 +18,7 @@ class SlapConfigurationTest(unittest.TestCase): ...@@ -18,7 +18,7 @@ class SlapConfigurationTest(unittest.TestCase):
self.resource_file = os.path.join(self.instance_root, slapformat.Partition.resource_file) self.resource_file = os.path.join(self.instance_root, slapformat.Partition.resource_file)
self.resource = { self.resource = {
"tun": { "tun": {
"ipv4": "192.168.0.1" "ipv4": u"192.168.0.1"
}, },
"address_list": [ "address_list": [
10, 20 10, 20
...@@ -48,6 +48,7 @@ class SlapConfigurationTest(unittest.TestCase): ...@@ -48,6 +48,7 @@ class SlapConfigurationTest(unittest.TestCase):
self.assertEqual(options['tun-ipv4'], "192.168.0.1", self.assertEqual(options['tun-ipv4'], "192.168.0.1",
"Folded attrs should be separated by -") "Folded attrs should be separated by -")
self.assertIsInstance(options['tun-ipv4'], str)
self.assertEqual(options['address-list'], [10, 20], self.assertEqual(options['address-list'], [10, 20],
"All underscores should be replaced with -") "All underscores should be replaced with -")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment