Merge lp:~mew/charm-helpers/relationset-withdict into lp:charm-helpers

Proposed by Matthew Wedgwood
Status: Merged
Approved by: Haw Loeung
Approved revision: 14
Merged at revision: 13
Proposed branch: lp:~mew/charm-helpers/relationset-withdict
Merge into: lp:charm-helpers
Diff against target: 41 lines (+10/-2)
2 files modified
charmhelpers/core/hookenv.py (+3/-1)
tests/core/test_hookenv.py (+7/-1)
To merge this branch: bzr merge lp:~mew/charm-helpers/relationset-withdict
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Review via email: mp+166678@code.launchpad.net

Commit message

Accommodate relation setting keys that are not valid python identifiers

Description of the change

**kwargs only accepts keys that are valid python identifiers. This change allows relation-set to take settings that, for example, contain dashes. It maintains backward compatibility with **kwargs settings.

To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

Looks good to me, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/core/hookenv.py'
--- charmhelpers/core/hookenv.py 2013-05-21 21:01:31 +0000
+++ charmhelpers/core/hookenv.py 2013-05-31 08:38:25 +0000
@@ -124,10 +124,12 @@
124 return None124 return None
125125
126126
127def relation_set(relation_id=None, **kwargs):127def relation_set(relation_id=None, relation_settings={}, **kwargs):
128 relation_cmd_line = ['relation-set']128 relation_cmd_line = ['relation-set']
129 if relation_id is not None:129 if relation_id is not None:
130 relation_cmd_line.extend(('-r', relation_id))130 relation_cmd_line.extend(('-r', relation_id))
131 for k, v in relation_settings.items():
132 relation_cmd_line.append('{}={}'.format(k, v))
131 for k, v in kwargs.items():133 for k, v in kwargs.items():
132 relation_cmd_line.append('{}={}'.format(k, v))134 relation_cmd_line.append('{}={}'.format(k, v))
133 subprocess.check_call(relation_cmd_line)135 subprocess.check_call(relation_cmd_line)
134136
=== modified file 'tests/core/test_hookenv.py'
--- tests/core/test_hookenv.py 2013-05-21 21:01:31 +0000
+++ tests/core/test_hookenv.py 2013-05-31 08:38:25 +0000
@@ -497,12 +497,18 @@
497 123, 'baz-scope', 'baz-unit'])497 123, 'baz-scope', 'baz-unit'])
498498
499 @patch('subprocess.check_call')499 @patch('subprocess.check_call')
500 def test_sets_relation(self, check_call_):500 def test_sets_relation_with_kwargs(self, check_call_):
501 hookenv.relation_set(foo="bar")501 hookenv.relation_set(foo="bar")
502 check_call_.assert_called_with(['relation-set','foo=bar'])502 check_call_.assert_called_with(['relation-set','foo=bar'])
503503
504504
505 @patch('subprocess.check_call')505 @patch('subprocess.check_call')
506 def test_sets_relation_with_dict(self, check_call_):
507 hookenv.relation_set(relation_settings={"foo":"bar"})
508 check_call_.assert_called_with(['relation-set','foo=bar'])
509
510
511 @patch('subprocess.check_call')
506 def test_sets_relation_with_relation_id(self, check_call_):512 def test_sets_relation_with_relation_id(self, check_call_):
507 hookenv.relation_set(relation_id="foo", bar="baz")513 hookenv.relation_set(relation_id="foo", bar="baz")
508 check_call_.assert_called_with(['relation-set', '-r', 'foo',514 check_call_.assert_called_with(['relation-set', '-r', 'foo',

Subscribers

People subscribed via source and target branches