Merge lp:~frankban/juju-deployer/fix-tags-constraint into lp:juju-deployer

Proposed by Francesco Banconi on 2015-09-03
Status: Merged
Merged at revision: 155
Proposed branch: lp:~frankban/juju-deployer/fix-tags-constraint
Merge into: lp:juju-deployer
Diff against target: 60 lines (+19/-3)
2 files modified
deployer/tests/test_constraints.py (+11/-1)
deployer/utils.py (+8/-2)
To merge this branch: bzr merge lp:~frankban/juju-deployer/fix-tags-constraint
Reviewer Review Type Date Requested Status
Tim Van Steenburgh 2015-09-03 Approve on 2015-09-03
Madison Scott-Clary (community) code Approve on 2015-09-03
Review via email: mp+270070@code.launchpad.net

Description of the Change

When deploying bundles, provide the tags constraint as a list rather than a string.
This fixes a problem reported by users, see http://pastebin.com/5McramHp

To post a comment you must log in.
Madison Scott-Clary (makyo) wrote :

LGTM - thanks!

review: Approve (code)
Tim Van Steenburgh (tvansteenburgh) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/tests/test_constraints.py'
2--- deployer/tests/test_constraints.py 2014-02-12 16:35:01 +0000
3+++ deployer/tests/test_constraints.py 2015-09-03 14:28:00 +0000
4@@ -113,10 +113,20 @@
5
6 def test_non_numerics_are_not_converted(self):
7 # Constraints that expect strings are not affected by the parsing.
8- keys = ['arch', 'container', 'tags']
9+ keys = ['arch', 'container']
10 for k in keys:
11 value = {
12 k: '1T',
13 }
14 result = parse_constraints(value)
15 self.assertEqual(result[k], '1T')
16+
17+ def test_tags(self):
18+ # Tags are provided as a list of strings.
19+ constraints = parse_constraints({'tags': 'foo,bar'})
20+ self.assertEqual({'tags': ['foo', 'bar']}, constraints)
21+
22+ def test_single_tag(self):
23+ # A single tag is converted to a list.
24+ constraints = parse_constraints({'tags': 'foo'})
25+ self.assertEqual({'tags': ['foo']}, constraints)
26
27=== modified file 'deployer/utils.py'
28--- deployer/utils.py 2015-03-16 22:25:44 +0000
29+++ deployer/utils.py 2015-09-03 14:28:00 +0000
30@@ -208,6 +208,7 @@
31 return value
32 constraints_with_units = ['mem', 'root-disk']
33 numerics = ['cpu-cores', 'cpu-power'] + constraints_with_units
34+ lists = ['tags']
35 constraints = {}
36 if isinstance(value, dict):
37 constraints.update(value)
38@@ -218,7 +219,12 @@
39 constraints[k] = v
40
41 for k, v in constraints.items():
42- if k in numerics:
43+ if k in lists:
44+ v = v.split(',')
45+ elif k in numerics:
46+ # Currently numeric constraints are never passed as slices. For
47+ # this reason, it is safe to assume that a numeric value is always
48+ # a string and never a list.
49 units = 1
50 if k in constraints_with_units:
51 v, units = _convert_units_specifier(v)
52@@ -377,7 +383,7 @@
53 def x_in_y(x, y):
54 """Check to see if the second argument is named in the first
55 argument's unit placement spec.
56-
57+
58 Both arguments provided are services with unit placement directives.
59 If the first service appears in the second service's unit placement,
60 either colocated on a default unit, colocated with a specific unit,

Subscribers

People subscribed via source and target branches