airbnb/stemcell — pull request #36 by nelgau (2013-11-11 03:23:46+00:00)
Title: Chef-like role metadata merge, clarify other merges, add specs

TL;DR Martin ran into an issue with Stemcell on Thursday that I promised to fix promptly: role metadata was not using the expected Chef-style attribute merge. This is an obvious oversight that is corrected in this pull request. I also took the opportunity to add tests and clarify the behavior of options from `stemcell.json` and the command line.

This pull request has an agenda of three items:

* Fix Martin's issue with attribute merge behavior.
* Clarify the merge behavior of options from `stemcell.json` and the command line.
* Add a test suite for `MetadataSource` and its supporting classes.

So... I goofed when I wrote `launch.rb`. It's painfully obvious that it should have used Chef's internal deep merge (hash deep merge, treating array values as sets; see [this file](https://github.com/opscode/chef/blob/master/lib/chef/mixin/deep_merge.rb)). I used a simple merge by mistake (on [this line](https://github.com/airbnb/stemcell/blob/master/lib/stemcell/metadata_source.rb#L119)). Very silly and highly regrettable. This bit Martin on Thursday. I've fixed it in [this commit](https://github.com/airbnb/stemcell/commit/5bfeef77525f2d3ba90a65f0944ebcdaea50f789).

I did a minor rework of the merge semantics for sources as well, removing the sequence of deep merges (see [this commit](https://github.com/airbnb/stemcell/commit/153cffdd0c440bbfd2c23dc4ab6f3112647a4e67)). The defaults from `stemcell.json` were intended to provide missing values, not compose additively with the role metadata. Similarly, I think that options passed from the command line should replace, not extend, any values in the role metadata. Let me know if I've nutraged you with this choice. I'm happy to argue for this point.

I double-checked that this wouldn't affect `ec2admin`, but only by inspection.

### Testing

This was tested by launching a `monorail-titanitc-resque-worker-overflow` with a `tags` override attribute.

/cc @martinrhoads @igor47 @patrickviet @jtai