Merge lp:~gary/juju-gui/exportBugs into lp:juju-gui/experimental

Proposed by Gary Poster
Status: Merged
Merged at revision: 1149
Proposed branch: lp:~gary/juju-gui/exportBugs
Merge into: lp:juju-gui/experimental
Diff against target: 182 lines (+74/-12)
5 files modified
app/models/models.js (+7/-3)
app/store/env/fakebackend.js (+7/-3)
test/data/wp-deployer.yaml (+2/-5)
test/test_fakebackend.js (+12/-1)
test/test_model.js (+46/-0)
To merge this branch: bzr merge lp:~gary/juju-gui/exportBugs
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+192286@code.launchpad.net

Description of the change

Fix export and import bugs

Our support for exporting and importing config values and expose flags was buggy. This fixes four discrete but related bugs.

 - Exporting config values would exclude those that had false-y default values.
 - We did not export the expose flag.
 - Importing config values did not work.
 - We called the expose flag "exposed", which is not what the actual delpoyer expects.

To qa, open up the sandbox, deploy apache with "enable_modules" set to something or other, and expose it. Then export the environment. When you look at the service in the file, you should see "expose: true" and "enable_modules: mod_proxy" or whatever value you set. Then reload the GUI and drag the file into the sandbox. When the service has loaded, you should see that it is exposed, and when you look at the config in the inspector, you should see your value in the "enable_modules" field.

https://codereview.appspot.com/15400052/

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :
Download full text (8.0 KiB)

Reviewers: mp+192286_code.launchpad.net,

Message:
Please take a look.

Description:
Fix export and import bugs

Our support for exporting and importing config values and expose flags
was buggy. This fixes four discrete but related bugs.

  - Exporting config values would exclude those that had false-y default
values.
  - We did not export the expose flag.
  - Importing config values did not work.
  - We called the expose flag "exposed", which is not what the actual
delpoyer expects.

To qa, open up the sandbox, deploy apache with "enable_modules" set to
something or other, and expose it. Then export the environment. When
you look at the service in the file, you should see "expose: true" and
"enable_modules: mod_proxy" or whatever value you set. Then reload the
GUI and drag the file into the sandbox. When the service has loaded,
you should see that it is exposed, and when you look at the config in
the inspector, you should see your value in the "enable_modules" field.

https://code.launchpad.net/~gary/juju-gui/exportBugs/+merge/192286

(do not edit description out of merge proposal)

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

Affected files (+76, -12 lines):
   A [revision details]
   M app/models/models.js
   M app/store/env/fakebackend.js
   M test/data/wp-deployer.yaml
   M test/test_fakebackend.js
   M test/test_model.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: test/test_fakebackend.js
=== modified file 'test/test_fakebackend.js'
--- test/test_fakebackend.js 2013-10-15 08:16:18 +0000
+++ test/test_fakebackend.js 2013-10-23 05:23:16 +0000
@@ -528,6 +528,10 @@
        });
      });

+ beforeEach(function() {
+ fakebackend = utils.makeFakeBackend();
+ });
+
      afterEach(function() {
        if (fakebackend) {
          fakebackend.destroy();
@@ -555,9 +559,16 @@

              // Verify config.
              var wordpress = fakebackend.db.services.getById('wordpress');
+ var wordpressCharm = fakebackend.db.charms.getById(
+ 'cs:precise/wordpress-15');
              var mysql = fakebackend.db.services.getById('mysql');
- assert.equal(wordpress.get('config.engine'), 'nginx');
+ // This value is different from the default (nginx).
+
assert.equal(wordpressCharm.get('options.engine.default'), 'nginx');
+ assert.equal(wordpress.get('config.engine'), 'apache');
+ // This value is the default, as provided by the charm.
              assert.equal(wordpress.get('config.tuning'), 'single');
+ assert.isTrue(wordpress.get('exposed'));
+ assert.isFalse(mysql.get('exposed'));

              // Constraints
              var constraints = mysql.get('constraints');

Index: test/test_model.js
=== modified file 'test/test_model.js'
--- test/test_model.js 2013-10-16 11:55:56 +0000
+++ test/test_model.js 2013-10-23 03:34:59 +0000
@@...

Read more...

Revision history for this message
Jeff Pihach (hatch) wrote :

Thanks for this fix!
LGTM QA OK!

https://codereview.appspot.com/15400052/diff/1/app/models/models.js
File app/models/models.js (right):

https://codereview.appspot.com/15400052/diff/1/app/models/models.js#newcode1193
app/models/models.js:1193: if (service.get('exposed')) {
Maybe we should change what the deployer expects or our service
attribute to match instead of doing this conversion.

https://codereview.appspot.com/15400052/diff/1/test/test_fakebackend.js
File test/test_fakebackend.js (right):

https://codereview.appspot.com/15400052/diff/1/test/test_fakebackend.js#newcode532
test/test_fakebackend.js:532: fakebackend = utils.makeFakeBackend();
How did this work before?

https://codereview.appspot.com/15400052/

Revision history for this message
Gary Poster (gary) wrote :

*** Submitted:

Fix export and import bugs

Our support for exporting and importing config values and expose flags
was buggy. This fixes four discrete but related bugs.

  - Exporting config values would exclude those that had false-y default
values.
  - We did not export the expose flag.
  - Importing config values did not work.
  - We called the expose flag "exposed", which is not what the actual
delpoyer expects.

To qa, open up the sandbox, deploy apache with "enable_modules" set to
something or other, and expose it. Then export the environment. When
you look at the service in the file, you should see "expose: true" and
"enable_modules: mod_proxy" or whatever value you set. Then reload the
GUI and drag the file into the sandbox. When the service has loaded,
you should see that it is exposed, and when you look at the config in
the inspector, you should see your value in the "enable_modules" field.

R=jeff.pihach
CC=
https://codereview.appspot.com/15400052

https://codereview.appspot.com/15400052/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/models/models.js'
2--- app/models/models.js 2013-10-16 11:55:56 +0000
3+++ app/models/models.js 2013-10-23 05:33:21 +0000
4@@ -1168,9 +1168,9 @@
5 // that are the default value for the charm.
6 Y.each(service.get('config'), function(value, key) {
7 var optionData = charmOptions && charmOptions[key];
8- if ((!optionData && value !== undefined) ||
9- (optionData && optionData['default'] &&
10- (value !== optionData['default']))) {
11+ var defaultVal = optionData && optionData['default'];
12+ var hasDefault = Y.Lang.isValue(defaultVal);
13+ if (Y.Lang.isValue(value) && (!hasDefault || value !== defaultVal)) {
14 serviceOptions[key] = value;
15 }
16 });
17@@ -1190,6 +1190,10 @@
18 serviceData.constraints = constraints;
19 }
20
21+ if (service.get('exposed')) {
22+ serviceData.expose = true;
23+ }
24+
25 // XXX: Only expose position. Currently these are position absolute
26 // rather than relative.
27 var anno = service.get('annotations');
28
29=== modified file 'app/store/env/fakebackend.js'
30--- app/store/env/fakebackend.js 2013-10-15 19:33:04 +0000
31+++ app/store/env/fakebackend.js 2013-10-23 05:33:21 +0000
32@@ -1368,9 +1368,9 @@
33 var seen = [];
34
35 /**
36- Helper to build out an inheritence chain
37+ Helper to build out an inheritance chain
38
39- @method setupinheritance
40+ @method setupInheritance
41 @param {Object} base object currently being inspected.
42 @param {Array} baseList chain of ancestors to later inherit.
43 @param {Object} bundleData import data used to resolve ancestors.
44@@ -1497,6 +1497,10 @@
45 if (!serviceData.unitCount) {
46 serviceData.unitCount = serviceData.num_units || 1;
47 }
48+ if (serviceData.options) {
49+ serviceData.config = serviceData.options;
50+ delete serviceData.options;
51+ }
52 servicePromises.push(
53 self.promiseDeploy(serviceData.charm, serviceData));
54 });
55@@ -1530,7 +1534,7 @@
56 }
57
58 // Expose
59- if (serviceData.exposed) {
60+ if (serviceData.expose) {
61 self.expose(serviceId);
62 }
63
64
65=== modified file 'test/data/wp-deployer.yaml'
66--- test/data/wp-deployer.yaml 2013-10-10 17:00:09 +0000
67+++ test/data/wp-deployer.yaml 2013-10-23 05:33:21 +0000
68@@ -9,8 +9,6 @@
69 "block-size": "5"
70 "dataset-size": "80%"
71 flavor: distro
72- 'gui-x': 50
73- 'gui-y': 50
74 "ha-bindiface": eth0
75 "ha-mcastport": "5411"
76 "max-connections": "-1"
77@@ -31,13 +29,12 @@
78 num_units: 2
79 options:
80 debug: "no"
81- engine: nginx
82- tuning: single
83+ engine: apache
84 "wp-content": ""
85 annotations:
86 "gui-x": 510
87 "gui-y": 184
88- exposed: true
89+ expose: true
90 relations:
91 - - "wordpress:db"
92 - "mysql:db"
93
94=== modified file 'test/test_fakebackend.js'
95--- test/test_fakebackend.js 2013-10-15 08:16:18 +0000
96+++ test/test_fakebackend.js 2013-10-23 05:33:21 +0000
97@@ -528,6 +528,10 @@
98 });
99 });
100
101+ beforeEach(function() {
102+ fakebackend = utils.makeFakeBackend();
103+ });
104+
105 afterEach(function() {
106 if (fakebackend) {
107 fakebackend.destroy();
108@@ -555,9 +559,16 @@
109
110 // Verify config.
111 var wordpress = fakebackend.db.services.getById('wordpress');
112+ var wordpressCharm = fakebackend.db.charms.getById(
113+ 'cs:precise/wordpress-15');
114 var mysql = fakebackend.db.services.getById('mysql');
115- assert.equal(wordpress.get('config.engine'), 'nginx');
116+ // This value is different from the default (nginx).
117+ assert.equal(wordpressCharm.get('options.engine.default'), 'nginx');
118+ assert.equal(wordpress.get('config.engine'), 'apache');
119+ // This value is the default, as provided by the charm.
120 assert.equal(wordpress.get('config.tuning'), 'single');
121+ assert.isTrue(wordpress.get('exposed'));
122+ assert.isFalse(mysql.get('exposed'));
123
124 // Constraints
125 var constraints = mysql.get('constraints');
126
127=== modified file 'test/test_model.js'
128--- test/test_model.js 2013-10-16 11:55:56 +0000
129+++ test/test_model.js 2013-10-23 05:33:21 +0000
130@@ -867,6 +867,52 @@
131 assert.isUndefined(result.services.puppet.num_units);
132 });
133
134+ it('exports non-default options', function() {
135+ db.services.add({
136+ id: 'wordpress',
137+ charm: 'precise/wordpress-1',
138+ config: {one: '1', two: '2', three: '3', four: '4', five: true},
139+ annotations: {'gui-x': 100, 'gui-y': 200}
140+ });
141+ db.charms.add([{id: 'precise/mysql-1'},
142+ {id: 'precise/wordpress-1',
143+ options: {
144+ one: {
145+ 'default': ''
146+ },
147+ two: {
148+ 'default': null
149+ },
150+ three: {
151+ 'default': undefined
152+ },
153+ four: {
154+ 'default': '0'
155+ },
156+ five: {
157+ 'default': false
158+ }
159+ }
160+ }
161+ ]);
162+ var result = db.exportDeployer().envExport;
163+ assert.equal(result.services.wordpress.options.one, '1');
164+ assert.equal(result.services.wordpress.options.two, '2');
165+ assert.equal(result.services.wordpress.options.three, '3');
166+ assert.equal(result.services.wordpress.options.four, '4');
167+ assert.equal(result.services.wordpress.options.five, true);
168+ });
169+
170+ it('exports exposed flag', function() {
171+ db.services.add({id: 'wordpress', charm: 'precise/wordpress-4'});
172+ db.charms.add([{id: 'precise/wordpress-4'}]);
173+ var result = db.exportDeployer().envExport;
174+ assert.isUndefined(result.services.wordpress.expose);
175+ db.services.getById('wordpress').set('exposed', true);
176+ result = db.exportDeployer().envExport;
177+ assert.isTrue(result.services.wordpress.expose);
178+ });
179+
180 });
181
182 describe('service models', function() {

Subscribers

People subscribed via source and target branches