Merge lp:~jjo/juju-deployer/deployer-constraints-fix-subords-and-support-M_G-sizes into lp:juju-deployer

Proposed by JuanJo Ciarlante
Status: Merged
Merged at revision: 84
Proposed branch: lp:~jjo/juju-deployer/deployer-constraints-fix-subords-and-support-M_G-sizes
Merge into: lp:juju-deployer
Diff against target: 166 lines (+61/-12)
6 files modified
deployer/action/diff.py (+12/-7)
deployer/cli.py (+5/-1)
deployer/env/go.py (+7/-1)
deployer/tests/test_constraints.py (+24/-0)
deployer/tests/test_guiserver.py (+1/-0)
deployer/utils.py (+12/-3)
To merge this branch: bzr merge lp:~jjo/juju-deployer/deployer-constraints-fix-subords-and-support-M_G-sizes
Reviewer Review Type Date Requested Status
juju-deployers Pending
Review via email: mp+195403@code.launchpad.net

Commit message

[jjo, r=] constraints fixes + tests: don't fail on subords, parse M/G sizes,
cleanup YAML output from diff by default (--raw-output option to avoid this)

To post a comment you must log in.
84. By JuanJo Ciarlante

skip diffing units count for subordinates

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

thanks. merging, with minor changes (nice unicode output by default using yaml.representer).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/action/diff.py'
2--- deployer/action/diff.py 2013-10-30 06:11:47 +0000
3+++ deployer/action/diff.py 2013-11-16 01:13:00 +0000
4@@ -3,7 +3,7 @@
5
6 from .base import BaseAction
7 from ..relation import EndpointPair
8-from ..utils import _parse_constraints, yaml_dump
9+from ..utils import parse_constraints, yaml_dump
10
11
12 class Diff(BaseAction):
13@@ -111,7 +111,8 @@
14 for cs in env_svcs.intersection(dep_svcs):
15 d_s = self.deployment.get_service(cs).svc_data
16 e_s = self.env_state['services'][cs]
17- mod = self._diff_service(e_s, d_s)
18+ mod = self._diff_service(e_s, d_s,
19+ self.deployment.get_charm_for(cs))
20 if not mod:
21 continue
22 if not 'modified' in delta:
23@@ -119,10 +120,10 @@
24 delta['modified'][cs] = mod
25 return delta
26
27- def _diff_service(self, e_s, d_s):
28+ def _diff_service(self, e_s, d_s, charm):
29 mod = {}
30 if 'constraints' in d_s:
31- d_sc = _parse_constraints(d_s['constraints'])
32+ d_sc = parse_constraints(d_s['constraints'])
33 if d_sc != e_s['constraints']:
34 mod['constraints'] = e_s['constraints']
35 for k, v in d_s.get('options', {}).items():
36@@ -133,8 +134,9 @@
37 e_v = e_s['options'].get(k, {}).get('value')
38 if e_v != v:
39 mod['config'] = {k: e_v}
40- if e_s['unit_count'] != d_s.get('num_units', 1):
41- mod['num_units'] = e_s['unit_count'] - d_s['num_units']
42+ if not charm or not charm.is_subordinate():
43+ if e_s['unit_count'] != d_s.get('num_units', 1):
44+ mod['num_units'] = e_s['unit_count'] - d_s.get('num_units', 1)
45 return mod
46
47 def run(self):
48@@ -144,4 +146,7 @@
49 self.load_env()
50 delta = self.get_delta()
51 if delta:
52- print yaml_dump(delta)
53+ yaml_str = yaml_dump(delta)
54+ if not self.options.raw_output:
55+ yaml_str = yaml_str.replace('!!python/unicode', '')
56+ print yaml_str
57
58=== modified file 'deployer/cli.py'
59--- deployer/cli.py 2013-10-25 16:02:14 +0000
60+++ deployer/cli.py 2013-11-16 01:13:00 +0000
61@@ -99,7 +99,11 @@
62 parser.add_argument(
63 "--diff", action="store_true", default=False,
64 help=("Generate a delta between a configured deployment and a running"
65- " environment."))
66+ " environment."))
67+ parser.add_argument(
68+ "--raw-output", action="store_true", default=False,
69+ help=("Don't cleanup output YAML from strings like "
70+ "'!!python/unicode'"))
71 parser.add_argument(
72 '-w', '--relation-wait', action='store', dest='rel_wait',
73 default=60, type=int,
74
75=== modified file 'deployer/env/go.py'
76--- deployer/env/go.py 2013-11-12 04:54:58 +0000
77+++ deployer/env/go.py 2013-11-16 01:13:00 +0000
78@@ -58,7 +58,13 @@
79 return self.client.get_config(svc_name)
80
81 def get_constraints(self, svc_name):
82- return self.client.get_constraints(svc_name)
83+ try:
84+ return self.client.get_constraints(svc_name)
85+ except EnvError, e:
86+ if 'constraints do not apply to subordinate services' in str(e):
87+ return None
88+ else:
89+ raise e
90
91 def get_cli_status(self):
92 status = super(GoEnvironment, self).get_cli_status()
93
94=== added file 'deployer/tests/test_constraints.py'
95--- deployer/tests/test_constraints.py 1970-01-01 00:00:00 +0000
96+++ deployer/tests/test_constraints.py 2013-11-16 01:13:00 +0000
97@@ -0,0 +1,24 @@
98+from deployer.service import Service
99+from .base import Base
100+from ..utils import parse_constraints
101+
102+
103+class ConstraintsTest(Base):
104+
105+ def test_constraints(self):
106+ data = {
107+ 'branch': 'lp:precise/mysql',
108+ 'constraints': "instance-type=m1.small",
109+ }
110+ s = Service('db', data)
111+ self.assertEquals(s.constraints, "instance-type=m1.small")
112+ data = {
113+ 'branch': 'lp:precise/mysql',
114+ 'constraints': "cpu-cores=4 mem=2048M root-disk=10G",
115+ }
116+ s = Service('db', data)
117+ c = parse_constraints(s.constraints)
118+ self.assertEquals(s.constraints, "cpu-cores=4 mem=2048M root-disk=10G")
119+ self.assertEqual(c['cpu-cores'], 4)
120+ self.assertEqual(c['mem'], 2048)
121+ self.assertEqual(c['root-disk'], 10 * 1024)
122
123=== modified file 'deployer/tests/test_guiserver.py'
124--- deployer/tests/test_guiserver.py 2013-11-12 11:27:32 +0000
125+++ deployer/tests/test_guiserver.py 2013-11-16 01:13:00 +0000
126@@ -212,6 +212,7 @@
127 description=False,
128 destroy_services=False,
129 diff=False,
130+ raw_output=False,
131 find_service=None,
132 juju_env=None,
133 list_deploys=False,
134
135=== modified file 'deployer/utils.py'
136--- deployer/utils.py 2013-08-27 09:44:05 +0000
137+++ deployer/utils.py 2013-11-16 01:13:00 +0000
138@@ -133,16 +133,25 @@
139 os.chmod(extract_path, mode)
140
141
142-def _parse_constraints(value):
143+def parse_constraints(value):
144 constraints = {}
145 pairs = value.strip().split()
146+ units_dict = {
147+ 'M': 1,
148+ 'G': 1024,
149+ }
150 for p in pairs:
151 k, v = p.split('=')
152+ units = units_dict.get(v[-1], None)
153+ if units:
154+ v = v[0:-1]
155+ else:
156+ units = 1
157 try:
158- v = int(v)
159+ v = int(v) * units
160 except ValueError:
161 try:
162- v = float(v)
163+ v = float(v) * units
164 except:
165 pass
166 constraints[k] = v

Subscribers

People subscribed via source and target branches