Merge lp:~hatch/juju-gui/num-units-1253113 into lp:juju-gui/experimental

Proposed by Jeff Pihach
Status: Merged
Merged at revision: 1219
Proposed branch: lp:~hatch/juju-gui/num-units-1253113
Merge into: lp:juju-gui/experimental
Diff against target: 199 lines (+116/-7)
4 files modified
app/store/env/fakebackend.js (+5/-4)
app/store/env/sandbox.js (+1/-1)
test/test_fakebackend.js (+108/-0)
test/test_sandbox_go.js (+2/-2)
To merge this branch: bzr merge lp:~hatch/juju-gui/num-units-1253113
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+197597@code.launchpad.net

Description of the change

Fix: Removing units throws notification error

Removing units in the sandbox and in a real environment no longer
always throws an error.

https://codereview.appspot.com/36690043/

To post a comment you must log in.
Revision history for this message
Jeff Pihach (hatch) wrote :

Reviewers: mp+197597_code.launchpad.net,

Message:
Please take a look.

Description:
Fix: Removing units throws notification error

Removing units in the sandbox and in a real environment no longer
always throws an error.

To QA:
Sandbox:
Deploy a service with 10 units, change it to 1 unit, it should scale
down to 1.

Real environment:
Deploy a failtester service with 3 units in the GUI
after they are up scale it down to 1, they should scale down without
notifications.

https://code.launchpad.net/~hatch/juju-gui/num-units-1253113/+merge/197597

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/36690043/

Affected files (+118, -7 lines):
   [revision details]
   app/store/env/fakebackend.js
   app/store/env/sandbox.js
   test/test_fakebackend.js
   test/test_sandbox_go.js

Revision history for this message
Madison Scott-Clary (makyo) wrote :
Revision history for this message
Jeff Pihach (hatch) wrote :
Revision history for this message
Jeff Pihach (hatch) wrote :

*** Submitted:

Fix: Removing units throws notification error

Removing units in the sandbox and in a real environment no longer
always throws an error.

R=matthew.scott
CC=
https://codereview.appspot.com/36690043

https://codereview.appspot.com/36690043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/store/env/fakebackend.js'
2--- app/store/env/fakebackend.js 2013-11-25 18:52:14 +0000
3+++ app/store/env/fakebackend.js 2013-12-03 20:04:11 +0000
4@@ -510,13 +510,13 @@
5 // default.
6 var unitNames = service.get('units').get('id');
7 var result = this.removeUnits(unitNames);
8- if (result.error.length > 0) {
9+ if (result.error && result.error.length > 0) {
10 console.log(result, result.error);
11 return {
12 error: 'Error removing units [' + unitNames.join(', ') +
13 '] of ' + serviceName
14 };
15- } else if (result.warning.length > 0) {
16+ } else if (result.warning && result.warning.length > 0) {
17 console.log(result, result.warning);
18 return {
19 error: 'Warning removing units [' + unitNames.join(', ') +
20@@ -705,8 +705,7 @@
21 */
22 removeUnits: function(unitNames) {
23 var service, removedUnit,
24- error = [],
25- warning = [];
26+ warning, error;
27
28 // XXX: BradCrittenden 2013-04-15: Remove units should optionally remove
29 // the corresponding machines.
30@@ -716,6 +715,7 @@
31 Y.Array.each(unitNames, function(unitName) {
32 service = this.db.services.getById(unitName.split('/')[0]);
33 if (service && service.get('is_subordinate')) {
34+ if (!Y.Lang.isArray(error)) { error = []; }
35 error.push(unitName + ' is a subordinate, cannot remove.');
36 } else {
37 // For now we also need to clean up the services unit list but the
38@@ -729,6 +729,7 @@
39 return;
40 }
41 }
42+ if (!Y.Lang.isArray(warning)) { warning = []; }
43 warning.push(unitName + ' does not exist, cannot remove.');
44 }
45 }, this);
46
47=== modified file 'app/store/env/sandbox.js'
48--- app/store/env/sandbox.js 2013-11-26 02:52:25 +0000
49+++ app/store/env/sandbox.js 2013-12-03 20:04:11 +0000
50@@ -612,7 +612,7 @@
51 */
52 performOp_remove_units: function(data) {
53 var res = this.get('state').removeUnits(data.unit_names);
54- if (res.error.length > 0) {
55+ if (res.error && res.error.length > 0) {
56 data.err = res.error;
57 data.result = false;
58 } else {
59
60=== modified file 'test/test_fakebackend.js'
61--- test/test_fakebackend.js 2013-11-25 18:52:14 +0000
62+++ test/test_fakebackend.js 2013-12-03 20:04:11 +0000
63@@ -1220,6 +1220,114 @@
64
65 });
66
67+ describe('FakeBackend.removeUnit', function() {
68+ var requires = [
69+ 'node', 'juju-tests-utils', 'juju-models', 'juju-charm-models'];
70+ var Y, fakebackend, utils, unitsRemoveData = '',
71+ removeCalled = 0;
72+
73+ before(function(done) {
74+ Y = YUI(GlobalConfig).use(requires, function(Y) {
75+ utils = Y.namespace('juju-tests.utils');
76+ done();
77+ });
78+ });
79+
80+ beforeEach(function() {
81+ fakebackend = utils.makeFakeBackend();
82+ });
83+
84+ afterEach(function() {
85+ fakebackend.destroy();
86+ removeCalled = 0;
87+ unitsRemoveData = '';
88+ });
89+
90+ function modifyDb(isSubordinate, unitIds) {
91+ fakebackend.db.services.getById = function() {
92+ return {
93+ get: function(type) {
94+ if (type === 'is_subordinate') { return isSubordinate; }
95+ if (type === 'units') {
96+ return {
97+ remove: function(removeData) {
98+ unitsRemoveData += removeData;
99+ removeCalled += 1;
100+ },
101+ getById: function() {
102+ return unitIds;
103+ }};
104+ }}};
105+ };
106+ }
107+
108+ it('can remove a single unit', function() {
109+ // This assumes that the addUnit tests above pass
110+ fakebackend.deploy('cs:precise/wordpress-15', function() {
111+ var unitId = 'wordpress/0';
112+ modifyDb(false, unitId);
113+ var result = fakebackend.removeUnits(unitId);
114+ assert.deepEqual(result, {
115+ error: undefined,
116+ warning: undefined
117+ });
118+ assert.equal(removeCalled, 1);
119+ assert.equal(unitsRemoveData, unitId);
120+ });
121+ });
122+
123+ it('can remove multiple units', function() {
124+ // This assumes that the addUnit tests above pass
125+ fakebackend.deploy('cs:precise/wordpress-15', function() {
126+ var unitIds = ['wordpress/0', 'wordpress/1'];
127+ modifyDb(false, unitIds);
128+
129+ var result = fakebackend.removeUnits(unitIds);
130+ assert.deepEqual(result, {
131+ error: undefined,
132+ warning: undefined
133+ });
134+ assert.equal(removeCalled, 2);
135+ // This join thing is kind of ugly but it's simply like this so that
136+ // we can share the same simple modify method across all tests.
137+ assert.equal(unitsRemoveData, unitIds.join(',') + unitIds.join(','));
138+ });
139+ });
140+
141+ it('returns an error when removing a subordinate', function() {
142+ // This assumes that the addUnit tests above pass
143+ fakebackend.deploy('cs:precise/wordpress-15', function() {
144+ var unitId = 'wordpress/0';
145+ modifyDb(true, unitId);
146+ var result = fakebackend.removeUnits(unitId);
147+ assert.deepEqual(result, {
148+ error: [
149+ 'wordpress/0 is a subordinate, cannot remove.'
150+ ],
151+ warning: undefined
152+ });
153+ assert.equal(removeCalled, 0);
154+ assert.equal(unitsRemoveData, '');
155+ });
156+ });
157+
158+ it('returns a warning when removing a service which doesn\'t exist',
159+ function() {
160+ // This assumes that the addUnit tests above pass
161+ fakebackend.deploy('cs:precise/wordpress-15', function() {
162+ modifyDb(false, null);
163+ var result = fakebackend.removeUnits('wordpress/0');
164+ assert.deepEqual(result, {
165+ error: undefined,
166+ warning: [
167+ 'wordpress/0 does not exist, cannot remove.'
168+ ]
169+ });
170+ });
171+ });
172+
173+ });
174+
175 describe('FakeBackend.next*', function() {
176 var requires = [
177 'node', 'juju-tests-utils', 'juju-models', 'juju-charm-models'];
178
179=== modified file 'test/test_sandbox_go.js'
180--- test/test_sandbox_go.js 2013-11-26 19:51:23 +0000
181+++ test/test_sandbox_go.js 2013-12-03 20:04:11 +0000
182@@ -478,7 +478,7 @@
183 assert.equal(receivedData.RequestId, data.RequestId);
184 // fakebackend defaults error and warning to [] which carries
185 // through.
186- assert.deepEqual(receivedData.Error, []);
187+ assert.isUndefined(receivedData.Error);
188 assert.equal(state.db.services.item(0).get('units').size(), 0);
189 done();
190 };
191@@ -493,7 +493,7 @@
192 var callback = function(result) {
193 // fakebackend defaults error and warning to [] which carries
194 // through.
195- assert.deepEqual(result.err, []);
196+ assert.isUndefined(result.err);
197 assert.equal(state.db.services.item(0).get('units').size(), 0);
198 done();
199 };

Subscribers

People subscribed via source and target branches