summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-08-26 16:49:47 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-08-26 16:49:47 -0700
commit8e2071173eab890a0d52197f4da52e7ff39c8c8b (patch)
treecf75f21d24201408e4f1361329cb09945004b83f /lib
parent49777324414dace31aec1473d92fe75f97a5ef18 (diff)
downloadchef-zero-8e2071173eab890a0d52197f4da52e7ff39c8c8b.tar.gz
Fix invite and org membership rspec data loading
Diffstat (limited to 'lib')
-rw-r--r--lib/chef_zero/rspec.rb2
-rw-r--r--lib/chef_zero/server.rb19
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb
index 6a78a78..6a3429b 100644
--- a/lib/chef_zero/rspec.rb
+++ b/lib/chef_zero/rspec.rb
@@ -261,7 +261,7 @@ module ChefZero
end
def current_org
- @current_org || 'chef'
+ @current_org || ChefZero::RSpec.server.options[:single_org] || nil
end
def with_object_path(object_path)
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index e4c5aab..7bb232a 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -356,7 +356,13 @@ module ChefZero
# }
# }
# }
- def load_data(contents, org_name = 'chef')
+ def load_data(contents, org_name = nil)
+ passed_org = !!org_name
+ org_name ||= options[:single_org]
+ if org_name.nil? && contents.keys != [ 'users' ]
+ raise "Must pass an org name to load_data or run in single_org mode"
+ end
+
%w(clients containers environments groups nodes roles sandboxes).each do |data_type|
if contents[data_type]
dejsonize_children(contents[data_type]).each_pair do |name, data|
@@ -364,6 +370,7 @@ module ChefZero
end
end
end
+
if contents['users']
dejsonize_children(contents['users']).each_pair do |name, data|
if options[:osc_compat]
@@ -371,7 +378,9 @@ module ChefZero
else
# Create the user and put them in the org
data_store.set(['users', name], data, :create)
- data_store.set(['organizations', org_name, 'users', name], '{}', :create)
+ if org_name
+ data_store.set(['organizations', org_name, 'users', name], '{}', :create)
+ end
end
end
end
@@ -381,11 +390,13 @@ module ChefZero
data_store.set(['organizations', org_name, 'users', name], '{}', :create)
end
end
+
if contents['invites']
contents['invites'].each do |name|
- data_store.set(['organizations', org_name, 'association_requests', "#{current_org}-#{username}"], '{}', :create)
+ data_store.set(['organizations', org_name, 'association_requests', name], '{}', :create)
end
end
+
if contents['acls']
dejsonize_children(contents['acls']).each do |path, acl|
path = [ 'organizations', org_name ] + path.split('/')
@@ -393,6 +404,7 @@ module ChefZero
ChefZero::RSpec.server.data_store.set(path, acl)
end
end
+
if contents['data']
contents['data'].each_pair do |key, data_bag|
data_store.create_dir(['organizations', org_name, 'data'], key, :recursive)
@@ -401,6 +413,7 @@ module ChefZero
end
end
end
+
if contents['cookbooks']
contents['cookbooks'].each_pair do |name_version, cookbook|
if name_version =~ /(.+)-(\d+\.\d+\.\d+)$/