diff options
author | John Keiser <jkeiser@opscode.com> | 2013-06-12 09:00:16 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-06-12 09:00:16 -0700 |
commit | de4d8e66be3dee3ccd9ac027e6332e0eb37f532e (patch) | |
tree | a5e0a5446eb8ce58430ec25e4ed556a1ec8fc864 | |
parent | 74a8fb235aca3891e9e46630ce5db0a4230947ef (diff) | |
download | chef-de4d8e66be3dee3ccd9ac027e6332e0eb37f532e.tar.gz |
CHEF-4233: get rid of extra chef_type/data_bag keys added to data bag in knife upload
13 files changed, 54 insertions, 28 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index bd8226b92f..c1c5a81e04 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -36,11 +36,7 @@ class Chef "Reading and writing data to #{chef_fs.fs_description}" end - def chef_fs - @chef_fs.call - end - - MEMORY_PATHS = %w(sandboxes file_store) + attr_reader :chef_fs def create_dir(path, name, *options) if use_memory_store?(path) diff --git a/lib/chef/chef_fs/data_handler/acl_data_handler.rb b/lib/chef/chef_fs/data_handler/acl_data_handler.rb index 64fed7cac6..5ce4e335f4 100644 --- a/lib/chef/chef_fs/data_handler/acl_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/acl_data_handler.rb @@ -6,7 +6,7 @@ class Chef class AclDataHandler < DataHandlerBase def normalize(node, entry) # Normalize the order of the keys for easier reading - result = super(node, { + result = normalize_hash(node, { 'create' => {}, 'read' => {}, 'update' => {}, @@ -14,7 +14,7 @@ class Chef 'grant' => {} }) result.keys.each do |key| - result[key] = super(result[key], { 'actors' => [], 'groups' => [] }) + result[key] = normalize_hash(result[key], { 'actors' => [], 'groups' => [] }) result[key]['actors'] = result[key]['actors'].sort result[key]['groups'] = result[key]['groups'].sort end diff --git a/lib/chef/chef_fs/data_handler/client_data_handler.rb b/lib/chef/chef_fs/data_handler/client_data_handler.rb index a92e486782..2db3fa897f 100644 --- a/lib/chef/chef_fs/data_handler/client_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/client_data_handler.rb @@ -17,7 +17,7 @@ class Chef if entry.org defaults['orgname'] = entry.org end - result = super(client, defaults) + result = normalize_hash(client, defaults) # You can NOT send json_class, or it will fail result.delete('json_class') result diff --git a/lib/chef/chef_fs/data_handler/container_data_handler.rb b/lib/chef/chef_fs/data_handler/container_data_handler.rb index 714f83824a..8b108bcf73 100644 --- a/lib/chef/chef_fs/data_handler/container_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/container_data_handler.rb @@ -5,7 +5,7 @@ class Chef module DataHandler class ContainerDataHandler < DataHandlerBase def normalize(container, entry) - super(container, { + normalize_hash(container, { 'containername' => remove_dot_json(entry.name), 'containerpath' => remove_dot_json(entry.name) }) diff --git a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb index d0333db48f..d2e2a3ef6c 100644 --- a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb @@ -8,7 +8,7 @@ class Chef def normalize(cookbook, entry) version = entry.name name = entry.parent.name - result = super(cookbook, { + result = normalize_hash(cookbook, { 'name' => "#{name}-#{version}", 'version' => version, 'cookbook_name' => name, @@ -17,7 +17,7 @@ class Chef 'frozen?' => false, 'metadata' => {} }) - result['metadata'] = super(result['metadata'], { + result['metadata'] = normalize_hash(result['metadata'], { 'version' => version, 'name' => name }) diff --git a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb index 1f466ec5ac..240a42756d 100644 --- a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb @@ -10,16 +10,17 @@ class Chef if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data'] data_bag_item = data_bag_item['raw_data'] end - # chef_type and data_bag only come back from PUT and POST, but we'll - # normalize them in in case someone is comparing with those results. - super(data_bag_item, { - 'chef_type' => 'data_bag_item', - 'data_bag' => entry.parent.name, + # chef_type and data_bag come back in PUT and POST results, but we don't + # use those in knife-essentials. + normalize_hash(data_bag_item, { 'id' => remove_dot_json(entry.name) }) end def normalize_for_post(data_bag_item, entry) + if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data'] + data_bag_item = data_bag_item['raw_data'] + end { "name" => "data_bag_item_#{entry.parent.name}_#{remove_dot_json(entry.name)}", "json_class" => "Chef::DataBagItem", diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb index 11e5bae31c..a9bbc0bf1b 100644 --- a/lib/chef/chef_fs/data_handler/data_handler_base.rb +++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb @@ -27,7 +27,7 @@ class Chef normalize({}, entry) end - def normalize(object, defaults) + def normalize_hash(object, defaults) # Make a normalized result in the specified order for diffing result = {} defaults.each_pair do |key, default| diff --git a/lib/chef/chef_fs/data_handler/environment_data_handler.rb b/lib/chef/chef_fs/data_handler/environment_data_handler.rb index 6b13615968..9da10ebfa5 100644 --- a/lib/chef/chef_fs/data_handler/environment_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/environment_data_handler.rb @@ -6,7 +6,7 @@ class Chef module DataHandler class EnvironmentDataHandler < DataHandlerBase def normalize(environment, entry) - super(environment, { + normalize_hash(environment, { 'name' => remove_dot_json(entry.name), 'description' => '', 'cookbook_versions' => {}, diff --git a/lib/chef/chef_fs/data_handler/group_data_handler.rb b/lib/chef/chef_fs/data_handler/group_data_handler.rb index b27bf87c50..619822fe70 100644 --- a/lib/chef/chef_fs/data_handler/group_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/group_data_handler.rb @@ -16,7 +16,7 @@ class Chef if entry.org defaults['orgname'] = entry.org end - result = super(group, defaults) + result = normalize_hash(group, defaults) if result['actors'] && result['actors'].sort.uniq == (result['users'] + result['clients']).sort.uniq result.delete('actors') end diff --git a/lib/chef/chef_fs/data_handler/node_data_handler.rb b/lib/chef/chef_fs/data_handler/node_data_handler.rb index 13e60e4fc1..f2c97c734f 100644 --- a/lib/chef/chef_fs/data_handler/node_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/node_data_handler.rb @@ -6,7 +6,7 @@ class Chef module DataHandler class NodeDataHandler < DataHandlerBase def normalize(node, entry) - result = super(node, { + result = normalize_hash(node, { 'name' => remove_dot_json(entry.name), 'json_class' => 'Chef::Node', 'chef_type' => 'node', diff --git a/lib/chef/chef_fs/data_handler/role_data_handler.rb b/lib/chef/chef_fs/data_handler/role_data_handler.rb index c803449862..bc1c076280 100644 --- a/lib/chef/chef_fs/data_handler/role_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/role_data_handler.rb @@ -6,7 +6,7 @@ class Chef module DataHandler class RoleDataHandler < DataHandlerBase def normalize(role, entry) - result = super(role, { + result = normalize_hash(role, { 'name' => remove_dot_json(entry.name), 'description' => '', 'json_class' => 'Chef::Role', diff --git a/lib/chef/chef_fs/data_handler/user_data_handler.rb b/lib/chef/chef_fs/data_handler/user_data_handler.rb index 7bbb87645b..66a780690a 100644 --- a/lib/chef/chef_fs/data_handler/user_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/user_data_handler.rb @@ -5,7 +5,7 @@ class Chef module DataHandler class UserDataHandler < DataHandlerBase def normalize(user, entry) - super(user, { + normalize_hash(user, { 'name' => remove_dot_json(entry.name), 'admin' => false, 'json_class' => 'Chef::WebUIUser', diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 3bc8f6e622..c699dc2a56 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -1,6 +1,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/upload' require 'chef/knife/diff' +require 'chef/knife/raw' describe 'knife upload' do extend IntegrationSupport @@ -209,8 +210,36 @@ EOM end end - # Test upload of an item when the other end doesn't even have the container when_the_chef_server 'is empty' do + when_the_repository 'has a data bag item' do + file 'data_bags/x/y.json', { 'foo' => 'bar' } + it 'knife upload of the data bag uploads only the values in the data bag item and no other' do + knife('upload /data_bags/x/y.json').should_succeed <<EOM +Created /data_bags/x +Created /data_bags/x/y.json +EOM + knife('diff --name-status /data_bags').should_succeed <<EOM +EOM + JSON.parse(knife('raw /data/x/y').stdout, :create_additions => false).keys.should == [ 'id', 'foo' ] + end + end + + when_the_repository 'has a data bag item with keys chef_type and data_bag' do + file 'data_bags/x/y.json', { 'chef_type' => 'aaa', 'data_bag' => 'bbb' } + it 'upload preserves chef_type and data_bag' do + knife('upload /data_bags/x/y.json').should_succeed <<EOM +Created /data_bags/x +Created /data_bags/x/y.json +EOM + knife('diff --name-status /data_bags').should_succeed '' + result = JSON.parse(knife('raw /data/x/y').stdout, :create_additions => false) + result.keys.should == [ 'id', 'chef_type', 'data_bag' ] + result['chef_type'].should == 'aaa' + result['data_bag'].should == 'bbb' + end + end + + # Test upload of an item when the other end doesn't even have the container when_the_repository 'has two data bag items' do file 'data_bags/x/y.json', {} file 'data_bags/x/z.json', {} @@ -566,10 +595,10 @@ D\t/roles/x.json D\t/users/admin.json D\t/users/x.json EOM - end + end - it 'knife upload --purge deletes everything' do - knife('upload --purge /').should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") + it 'knife upload --purge deletes everything' do + knife('upload --purge /').should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") Deleted extra entry /clients/chef-validator.json (purge is on) Deleted extra entry /clients/chef-webui.json (purge is on) Deleted extra entry /clients/x.json (purge is on) @@ -581,10 +610,10 @@ Deleted extra entry /roles/x.json (purge is on) Deleted extra entry /users/admin.json (purge is on) Deleted extra entry /users/x.json (purge is on) EOM - knife('diff --name-status /').should_succeed <<EOM + knife('diff --name-status /').should_succeed <<EOM D\t/environments/_default.json EOM - end + end end when_the_repository 'has an identical copy of each thing' do |