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
=== modified file 'deployer/action/diff.py'
--- deployer/action/diff.py 2013-10-30 06:11:47 +0000
+++ deployer/action/diff.py 2013-11-16 01:13:00 +0000
@@ -3,7 +3,7 @@
33
4from .base import BaseAction4from .base import BaseAction
5from ..relation import EndpointPair5from ..relation import EndpointPair
6from ..utils import _parse_constraints, yaml_dump6from ..utils import parse_constraints, yaml_dump
77
88
9class Diff(BaseAction):9class Diff(BaseAction):
@@ -111,7 +111,8 @@
111 for cs in env_svcs.intersection(dep_svcs):111 for cs in env_svcs.intersection(dep_svcs):
112 d_s = self.deployment.get_service(cs).svc_data112 d_s = self.deployment.get_service(cs).svc_data
113 e_s = self.env_state['services'][cs]113 e_s = self.env_state['services'][cs]
114 mod = self._diff_service(e_s, d_s)114 mod = self._diff_service(e_s, d_s,
115 self.deployment.get_charm_for(cs))
115 if not mod:116 if not mod:
116 continue117 continue
117 if not 'modified' in delta:118 if not 'modified' in delta:
@@ -119,10 +120,10 @@
119 delta['modified'][cs] = mod120 delta['modified'][cs] = mod
120 return delta121 return delta
121122
122 def _diff_service(self, e_s, d_s):123 def _diff_service(self, e_s, d_s, charm):
123 mod = {}124 mod = {}
124 if 'constraints' in d_s:125 if 'constraints' in d_s:
125 d_sc = _parse_constraints(d_s['constraints'])126 d_sc = parse_constraints(d_s['constraints'])
126 if d_sc != e_s['constraints']:127 if d_sc != e_s['constraints']:
127 mod['constraints'] = e_s['constraints']128 mod['constraints'] = e_s['constraints']
128 for k, v in d_s.get('options', {}).items():129 for k, v in d_s.get('options', {}).items():
@@ -133,8 +134,9 @@
133 e_v = e_s['options'].get(k, {}).get('value')134 e_v = e_s['options'].get(k, {}).get('value')
134 if e_v != v:135 if e_v != v:
135 mod['config'] = {k: e_v}136 mod['config'] = {k: e_v}
136 if e_s['unit_count'] != d_s.get('num_units', 1):137 if not charm or not charm.is_subordinate():
137 mod['num_units'] = e_s['unit_count'] - d_s['num_units']138 if e_s['unit_count'] != d_s.get('num_units', 1):
139 mod['num_units'] = e_s['unit_count'] - d_s.get('num_units', 1)
138 return mod140 return mod
139141
140 def run(self):142 def run(self):
@@ -144,4 +146,7 @@
144 self.load_env()146 self.load_env()
145 delta = self.get_delta()147 delta = self.get_delta()
146 if delta:148 if delta:
147 print yaml_dump(delta)149 yaml_str = yaml_dump(delta)
150 if not self.options.raw_output:
151 yaml_str = yaml_str.replace('!!python/unicode', '')
152 print yaml_str
148153
=== modified file 'deployer/cli.py'
--- deployer/cli.py 2013-10-25 16:02:14 +0000
+++ deployer/cli.py 2013-11-16 01:13:00 +0000
@@ -99,7 +99,11 @@
99 parser.add_argument(99 parser.add_argument(
100 "--diff", action="store_true", default=False,100 "--diff", action="store_true", default=False,
101 help=("Generate a delta between a configured deployment and a running"101 help=("Generate a delta between a configured deployment and a running"
102 " environment."))102 " environment."))
103 parser.add_argument(
104 "--raw-output", action="store_true", default=False,
105 help=("Don't cleanup output YAML from strings like "
106 "'!!python/unicode'"))
103 parser.add_argument(107 parser.add_argument(
104 '-w', '--relation-wait', action='store', dest='rel_wait',108 '-w', '--relation-wait', action='store', dest='rel_wait',
105 default=60, type=int,109 default=60, type=int,
106110
=== modified file 'deployer/env/go.py'
--- deployer/env/go.py 2013-11-12 04:54:58 +0000
+++ deployer/env/go.py 2013-11-16 01:13:00 +0000
@@ -58,7 +58,13 @@
58 return self.client.get_config(svc_name)58 return self.client.get_config(svc_name)
5959
60 def get_constraints(self, svc_name):60 def get_constraints(self, svc_name):
61 return self.client.get_constraints(svc_name)61 try:
62 return self.client.get_constraints(svc_name)
63 except EnvError, e:
64 if 'constraints do not apply to subordinate services' in str(e):
65 return None
66 else:
67 raise e
6268
63 def get_cli_status(self):69 def get_cli_status(self):
64 status = super(GoEnvironment, self).get_cli_status()70 status = super(GoEnvironment, self).get_cli_status()
6571
=== added file 'deployer/tests/test_constraints.py'
--- deployer/tests/test_constraints.py 1970-01-01 00:00:00 +0000
+++ deployer/tests/test_constraints.py 2013-11-16 01:13:00 +0000
@@ -0,0 +1,24 @@
1from deployer.service import Service
2from .base import Base
3from ..utils import parse_constraints
4
5
6class ConstraintsTest(Base):
7
8 def test_constraints(self):
9 data = {
10 'branch': 'lp:precise/mysql',
11 'constraints': "instance-type=m1.small",
12 }
13 s = Service('db', data)
14 self.assertEquals(s.constraints, "instance-type=m1.small")
15 data = {
16 'branch': 'lp:precise/mysql',
17 'constraints': "cpu-cores=4 mem=2048M root-disk=10G",
18 }
19 s = Service('db', data)
20 c = parse_constraints(s.constraints)
21 self.assertEquals(s.constraints, "cpu-cores=4 mem=2048M root-disk=10G")
22 self.assertEqual(c['cpu-cores'], 4)
23 self.assertEqual(c['mem'], 2048)
24 self.assertEqual(c['root-disk'], 10 * 1024)
025
=== modified file 'deployer/tests/test_guiserver.py'
--- deployer/tests/test_guiserver.py 2013-11-12 11:27:32 +0000
+++ deployer/tests/test_guiserver.py 2013-11-16 01:13:00 +0000
@@ -212,6 +212,7 @@
212 description=False,212 description=False,
213 destroy_services=False,213 destroy_services=False,
214 diff=False,214 diff=False,
215 raw_output=False,
215 find_service=None,216 find_service=None,
216 juju_env=None,217 juju_env=None,
217 list_deploys=False,218 list_deploys=False,
218219
=== modified file 'deployer/utils.py'
--- deployer/utils.py 2013-08-27 09:44:05 +0000
+++ deployer/utils.py 2013-11-16 01:13:00 +0000
@@ -133,16 +133,25 @@
133 os.chmod(extract_path, mode)133 os.chmod(extract_path, mode)
134134
135135
136def _parse_constraints(value):136def parse_constraints(value):
137 constraints = {}137 constraints = {}
138 pairs = value.strip().split()138 pairs = value.strip().split()
139 units_dict = {
140 'M': 1,
141 'G': 1024,
142 }
139 for p in pairs:143 for p in pairs:
140 k, v = p.split('=')144 k, v = p.split('=')
145 units = units_dict.get(v[-1], None)
146 if units:
147 v = v[0:-1]
148 else:
149 units = 1
141 try:150 try:
142 v = int(v)151 v = int(v) * units
143 except ValueError:152 except ValueError:
144 try:153 try:
145 v = float(v)154 v = float(v) * units
146 except:155 except:
147 pass156 pass
148 constraints[k] = v157 constraints[k] = v

Subscribers

People subscribed via source and target branches