crowbar/barclamp-crowbar — pull request #613 by vuntz (2013-07-18 08:59:46+00:00)
Title: Add rake tasks for migration of data bags

There are two new tasks:

- crowbar:schema_migrate -- this migrates data bags to the current
revision of the schema
- crowbar:schema_migrate_prod -- this is a convenience wrapper task to
call crowbar:schema_migrate with the production environment

By default, this will migrate data bags for all barclamps. It's possible
to restrict this to one or several barclamps:
rake crowbar:schema_migrate_prod[nova]
rake crowbar:schema_migrate_prod[keystone nova]

The migration works the following way:

- it supports upgrades and downgrades.

- schema supporting migration must have a schema_revision root
int attribute; the template will contain the version of the schema
revision in this attribute.

- there are migration scripts in
/opt/dell/chef/data_bags/crowbar/migrate/$barclamp/. The scripts
must be named $rev_$somedescription.rb; the filename can have
0 (001_foobar.rb will work as well as 1_foobar.rb). There can be
multiple scripts per revision; they will be executed by alphabetical
order (or reverse alphabetical order in case of downgrades).

- a script can provide two functions (they are optional):
- an upgrade function
- a downgrade function
The functions must take as parameters:
- the attributes of the template
- the deployment information of the template
- the attributes of the proposal
- the deployment information of the proposal
The functions must return:
- the updated attributes of the proposal
- the updated deployment information of the proposal

As an example, for nova, we could have
/opt/dell/chef/data_bags/crowbar/migrate/nova/001_add_vuntz_attribute.rb
with the following content:

def upgrade ta, td, a, d
a['nova']['vuntz'] = ta['nova']['vuntz']
return a, d
end

def downgrade ta, td, a, d
a['nova'].delete('vuntz')
return a, d
end