Skip to content

Commit c15d909

Browse files
committed
fix(controller): allow unicode in config:set and app logging
1 parent 5e66379 commit c15d909

5 files changed

Lines changed: 34 additions & 8 deletions

File tree

client/deis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,13 @@ def config_list(self, args):
11121112
width = max(map(len, keys)) + 5
11131113
for k in keys:
11141114
v = values[k]
1115+
k, v = k.encode('utf-8'), v.encode('utf-8')
11151116
self._logger.info(("{k:<" + str(width) + "} {v}").format(**locals()))
11161117
else:
11171118
output = []
11181119
for k in keys:
11191120
v = values[k]
1121+
k, v = k.encode('utf-8'), v.encode('utf-8')
11201122
output.append("{k}={v}".format(**locals()))
11211123
self._logger.info(' '.join(output))
11221124
else:
@@ -1162,6 +1164,7 @@ def config_set(self, args):
11621164
self._logger.info('No configuration')
11631165
return
11641166
for k, v in values.items():
1167+
k, v = k.encode('utf-8'), v.encode('utf-8')
11651168
self._logger.info("{k}: {v}".format(**locals()))
11661169
else:
11671170
raise ResponseError(response)

controller/api/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ def log(self, message):
172172
existing logging configurations.
173173
"""
174174
with open(os.path.join(settings.DEIS_LOG_DIR, self.id + '.log'), 'a') as f:
175-
f.write('{} deis[api]: {}\n'.format(
176-
time.strftime('%Y-%m-%d %H:%M:%S'),
177-
message))
175+
msg = "{} deis[api]: {}\n".format(time.strftime('%Y-%m-%d %H:%M:%S'), message)
176+
f.write(msg.encode('utf-8'))
178177

179178
def create(self, *args, **kwargs):
180179
config = Config.objects.create(owner=self.owner, app=self)

controller/api/tests/test_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Unit tests for the Deis api app.
34
@@ -127,6 +128,29 @@ def test_config_set_same_key(self):
127128
self.assertIn('PORT', json.loads(response.data['values']))
128129
self.assertEqual(json.loads(response.data['values'])['PORT'], '5001')
129130

131+
@mock.patch('requests.post', mock_import_repository_task)
132+
def test_config_set_unicode(self):
133+
"""
134+
Test that config sets with unicode values are accepted.
135+
"""
136+
url = '/api/apps'
137+
body = {'cluster': 'autotest'}
138+
response = self.client.post(url, json.dumps(body), content_type='application/json')
139+
self.assertEqual(response.status_code, 201)
140+
app_id = response.data['id']
141+
url = "/api/apps/{app_id}/config".format(**locals())
142+
# set an initial config value
143+
body = {'values': json.dumps({'POWERED_BY': 'Деис'})}
144+
response = self.client.post(url, json.dumps(body), content_type='application/json')
145+
self.assertEqual(response.status_code, 201)
146+
self.assertIn('POWERED_BY', json.loads(response.data['values']))
147+
# reset same config value
148+
body = {'values': json.dumps({'POWERED_BY': 'Кроликов'})}
149+
response = self.client.post(url, json.dumps(body), content_type='application/json')
150+
self.assertEqual(response.status_code, 201)
151+
self.assertIn('POWERED_BY', json.loads(response.data['values']))
152+
self.assertEqual(json.loads(response.data['values'])['POWERED_BY'], 'Кроликов')
153+
130154
@mock.patch('requests.post', mock_import_repository_task)
131155
def test_config_str(self):
132156
"""Test the text representation of a node."""

controller/registry/private.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ def _construct_env(env, config):
166166
if k in config:
167167
# update values defined by config
168168
v = config.pop(k)
169-
new_env.append("{}={}".format(k, v))
169+
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
170170
# add other config ENV items
171171
for k, v in config.items():
172-
new_env.append("{}={}".format(k, v))
172+
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
173173
return new_env
174174

175175

tests/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
var (
1212
configListCmd = "config:list --app={{.AppName}}"
13-
configSetCmd = "config:set jaf=1 --app={{.AppName}}"
14-
configUnsetCmd = "config:unset jaf --app={{.AppName}}"
13+
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
14+
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
1515
)
1616

1717
func TestConfig(t *testing.T) {
@@ -48,7 +48,7 @@ func configSetup(t *testing.T) *utils.DeisTestConfig {
4848

4949
func configListTest(
5050
t *testing.T, params *utils.DeisTestConfig, notflag bool) {
51-
utils.CheckList(t, configListCmd, params, "jaf", notflag)
51+
utils.CheckList(t, configListCmd, params, "FOO", notflag)
5252
}
5353

5454
func configSetTest(t *testing.T, params *utils.DeisTestConfig) {

0 commit comments

Comments
 (0)