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.
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
// 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: app/models/models.js
=== modified file 'app/models/models.js'
--- app/models/models.js 2013-10-16 11:55:56 +0000
+++ app/models/models.js 2013-10-23 03:34:59 +0000
@@ -1168,9 +1168,9 @@
// that are the default value for the charm. Y.each(service.get('config'), function(value, key) {
var optionData = charmOptions && charmOptions[key];
- if ((!optionData && value !== undefined) ||
- (optionData && optionData['default'] &&
- (value !== optionData['default']))) {
+ var defaultVal = optionData && optionData['default'];
+ var hasDefault = Y.Lang.isValue(defaultVal);
+ if (Y.Lang.isValue(value) && (!hasDefault || value !==
defaultVal)) { serviceOptions[key] = value;
}
});
@@ -1190,6 +1190,10 @@ serviceData.constraints = constraints;
}
+ if (service.get('exposed')) {
+ serviceData.expose = true;
+ }
+
// XXX: Only expose position. Currently these are position absolute
// rather than relative.
var anno = service.get('annotations');
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): models. js env/fakebackend .js wp-deployer. yaml fakebackend. js
A [revision details]
M app/models/
M app/store/
M test/data/
M test/test_
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 fakebackend. js' fakebackend. js 2013-10-15 08:16:18 +0000 fakebackend. js 2013-10-23 05:23:16 +0000
=== modified file 'test/test_
--- test/test_
+++ test/test_
@@ -528,6 +528,10 @@
});
});
+ beforeEach( function( ) { ackend( ); (function( ) {
fakebackend. destroy( );
+ fakebackend = utils.makeFakeB
+ });
+
afterEach
if (fakebackend) {
@@ -555,9 +559,16 @@
// Verify config. db.services. getById( 'wordpress' ); db.charms. getById( wordpress- 15'); db.services. getById( 'mysql' ); equal(wordpress .get('config. engine' ), 'nginx'); equal(wordpress Charm.get( 'options. engine. default' ), 'nginx'); equal(wordpress .get('config. engine' ), 'apache');
assert. equal(wordpress .get('config. tuning' ), 'single'); isTrue( wordpress. get('exposed' )); isFalse( mysql.get( 'exposed' ));
var wordpress = fakebackend.
+ var wordpressCharm = fakebackend.
+ 'cs:precise/
var mysql = fakebackend.
- assert.
+ // This value is different from the default (nginx).
+
assert.
+ assert.
+ // This value is the default, as provided by the charm.
+ assert.
+ assert.
// Constraints 'constraints' );
var constraints = mysql.get(
Index: test/test_model.js model.js'
assert. isUndefined( result. services. puppet. num_units) ;
=== modified file 'test/test_
--- test/test_model.js 2013-10-16 11:55:56 +0000
+++ test/test_model.js 2013-10-23 03:34:59 +0000
@@ -867,6 +867,52 @@
});
+ it('exports non-default options', function() { wordpress- 1', wordpress- 1', er().envExport; equal(result. services. wordpress. options. one, '1'); equal(result. services. wordpress. options. two, '2'); equal(result. services. wordpress. options. three, '3'); equal(result. services. wordpress. options. four, '4'); equal(result. services. wordpress. options. five, true); add({id: 'wordpress', charm: 'precise/ wordpress- 4'}); wordpress- 4'}]); er().envExport; isUndefined( result. services. wordpress. expose) ; getById( 'wordpress' ).set(' exposed' , true); er().envExport; isTrue( result. services. wordpress. expose) ;
+ db.services.add({
+ id: 'wordpress',
+ charm: 'precise/
+ config: {one: '1', two: '2', three: '3', four: '4', five: true},
+ annotations: {'gui-x': 100, 'gui-y': 200}
+ });
+ db.charms.add([{id: 'precise/mysql-1'},
+ {id: 'precise/
+ options: {
+ one: {
+ 'default': ''
+ },
+ two: {
+ 'default': null
+ },
+ three: {
+ 'default': undefined
+ },
+ four: {
+ 'default': '0'
+ },
+ five: {
+ 'default': false
+ }
+ }
+ }
+ ]);
+ var result = db.exportDeploy
+ assert.
+ assert.
+ assert.
+ assert.
+ assert.
+ });
+
+ it('exports exposed flag', function() {
+ db.services.
+ db.charms.add([{id: 'precise/
+ var result = db.exportDeploy
+ assert.
+ db.services.
+ result = db.exportDeploy
+ assert.
+ });
+
});
describe( 'service models', function() {
Index: app/models/ models. js models. js' models. js 2013-10-16 11:55:56 +0000 models. js 2013-10-23 03:34:59 +0000
Y.each( service. get('config' ), function(value, key) { 'default' ] && 'default' ]))) { 'default' ]; isValue( defaultVal) ; isValue( value) && (!hasDefault || value !==
serviceOptions[ key] = value;
serviceDat a.constraints = constraints;
=== modified file 'app/models/
--- app/models/
+++ app/models/
@@ -1168,9 +1168,9 @@
// that are the default value for the charm.
var optionData = charmOptions && charmOptions[key];
- if ((!optionData && value !== undefined) ||
- (optionData && optionData[
- (value !== optionData[
+ var defaultVal = optionData && optionData[
+ var hasDefault = Y.Lang.
+ if (Y.Lang.
defaultVal)) {
}
});
@@ -1190,6 +1190,10 @@
}
+ if (service. get('exposed' )) { get('annotation s');
+ serviceData.expose = true;
+ }
+
// XXX: Only expose position. Currently these are position absolute
// rather than relative.
var anno = service.
Index: test/data/ wp-deployer. yaml wp-deployer. yaml' wp-deployer. yaml 2013-10-10 17:00:09 +0000 wp-deployer. yaml 2013-10-23 05:17:56 +0000
"block- size": "5"
"dataset- size": "80%"
"ha- bindiface" : eth0
"ha- mcastport" : "5411"
"max- connections" : "-1"
"wp- content" : ""
annotations:
=== modified file 'test/data/
--- test/data/
+++ test/data/
@@ -9,8 +9,6 @@
flavor: distro
- 'gui-x': 50
- 'gui-y': 50
@@ -31,13 +29,12 @@
num_units: 2
options:
debug: "no"
- engine: nginx
- tuning: single
+ engine: apache
"gui-x": 510
"gui-y": 184
- exposed: true
+ expose: true
relations:
- - "wordpress:db"
- "mysql:db"
Index: app/store/ env/fakebackend .js env/fakebackend .js' env/fakebackend .js 2013-10-15 19:33:04 +0000 env/fakebackend .js 2013-10-23 05:17:56 +0000
=== modified file 'app/store/
--- app/store/
+++ app/store/
@@ -1368,9 +1368,9 @@
var seen = [];
/**
- Helper to build out an inheritence chain
+ Helper to build out an inheritance chain
- @method setupinheritance unitCount) {
serviceDat a.unitCount = serviceData. num_units || 1; options) { options; options;
servicePromi ses.push(
self.promiseDep loy(serviceData .charm, serviceData));
+ @method setupInheritance
@param {Object} base object currently being inspected.
@param {Array} baseList chain of ancestors to later inherit.
@param {Object} bundleData import data used to resolve ancestors.
@@ -1497,6 +1497,10 @@
if (!serviceData.
}
+ if (serviceData.
+ serviceData.config = serviceData.
+ delete serviceData.
+ }
});
@@ -1530,7 +1534,7 @@
}
// Expose exposed) { expose) {
self. expose( serviceId) ;
- if (serviceData.
+ if (serviceData.
}