summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Chisamore <schisamo@opscode.com>2012-10-29 18:30:10 -0400
committerSeth Chisamore <schisamo@opscode.com>2012-10-30 09:47:38 -0400
commit8366c2259a62c02cee2137a869cb401b578bada0 (patch)
tree4b929d5421f514b477aaa82d98516f82f1e62045
parent912c453607bb90cc370fc6e2463c45bb6e85435e (diff)
downloadchef-8366c2259a62c02cee2137a869cb401b578bada0.tar.gz
[OC-3564] remove CouchDB related code \m/
This code was only used by Chef server components and has been succeeded by Erchef (w/ YesSQL).
-rw-r--r--chef/lib/chef/api_client.rb71
-rw-r--r--chef/lib/chef/config.rb9
-rw-r--r--chef/lib/chef/cookbook_version.rb223
-rw-r--r--chef/lib/chef/couchdb.rb246
-rw-r--r--chef/lib/chef/data_bag.rb93
-rw-r--r--chef/lib/chef/data_bag_item.rb64
-rw-r--r--chef/lib/chef/environment.rb178
-rw-r--r--chef/lib/chef/exceptions.rb3
-rw-r--r--chef/lib/chef/node.rb151
-rw-r--r--chef/lib/chef/role.rb94
-rw-r--r--chef/lib/chef/run_list.rb2
-rw-r--r--chef/lib/chef/run_list/run_list_expansion.rb15
-rw-r--r--chef/spec/unit/client_spec.rb13
-rw-r--r--chef/spec/unit/cookbook_version_spec.rb61
-rw-r--r--chef/spec/unit/couchdb_spec.rb274
-rw-r--r--chef/spec/unit/environment_spec.rb130
-rw-r--r--chef/spec/unit/exceptions_spec.rb5
-rw-r--r--chef/spec/unit/knife/ssh_spec.rb6
-rw-r--r--chef/spec/unit/lwrp_spec.rb6
-rw-r--r--chef/spec/unit/node_spec.rb76
-rw-r--r--chef/spec/unit/provider/ohai_spec.rb4
-rw-r--r--chef/spec/unit/run_list_spec.rb7
22 files changed, 28 insertions, 1703 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb
index b3b51bc41d..da05939c24 100644
--- a/chef/lib/chef/api_client.rb
+++ b/chef/lib/chef/api_client.rb
@@ -20,7 +20,6 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -31,43 +30,12 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "client") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "client") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
-
# Create a new Chef::ApiClient object.
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@public_key = nil
@private_key = nil
- @couchdb_rev = nil
- @couchdb_id = nil
@admin = false
- @couchdb = (couchdb || Chef::CouchDB.new)
end
# Gets or sets the client name.
@@ -130,7 +98,6 @@ class Chef
'json_class' => self.class.name,
"chef_type" => "client"
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -146,19 +113,9 @@ class Chef
client.name(o["name"] || o["clientname"])
client.public_key(o["public_key"])
client.admin(o["admin"])
- client.couchdb_rev = o["_rev"]
- client.couchdb_id = o["_id"]
client
end
- # List all the Chef::ApiClient objects in the CouchDB. If inflate is set
- # to true, you will get the full list of all ApiClients, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("clients", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -172,14 +129,6 @@ class Chef
end
end
- # Load a client by name from CouchDB
- #
- # @params [String] The name of the client to load
- # @return [Chef::ApiClient] The resulting Chef::ApiClient object
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("client", name)
- end
-
# Load a client by name via the API
def self.load(name)
response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{name}")
@@ -192,24 +141,11 @@ class Chef
end
end
- # Remove this client from the CouchDB
- #
- # @params [String] The name of the client to delete
- # @return [Chef::ApiClient] The last version of the object
- def cdb_destroy
- @couchdb.delete("client", @name, @couchdb_rev)
- end
-
# Remove this client via the REST API
def destroy
Chef::REST.new(Chef::Config[:chef_server_url]).delete_rest("clients/#{@name}")
end
- # Save this client to the CouchDB
- def cdb_save
- @couchdb_rev = @couchdb.store("client", @name, self)["rev"]
- end
-
# Save this client via the REST API, returns a hash including the private key
def save(new_key=false, validation=false)
if validation
@@ -235,11 +171,6 @@ class Chef
Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("clients", self)
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb ||= Chef::CouchDB.new).create_design_document("clients", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"client[#{@name}]"
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index b60427ca57..61c8806a66 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -130,8 +130,6 @@ class Chef
# Used when OpenID authentication is enabled in the Web UI
authorized_openid_identifiers nil
authorized_openid_providers nil
- openid_cstore_couchdb false
- openid_cstore_path "/var/chef/openid/cstore"
# The number of times the client should retry when registering with the server
client_registration_retries 5
@@ -150,11 +148,6 @@ class Chef
# Where cookbook files are stored on the server (by content checksum)
checksum_path "/var/chef/checksums"
- # CouchDB database name to use
- couchdb_database "chef"
-
- couchdb_url "http://localhost:5984"
-
# Where chef's cache files should be stored
file_cache_path platform_specific_path("/var/chef/cache")
@@ -211,7 +204,7 @@ class Chef
client_fork false
enable_reporting true
enable_reporting_url_fatals false
-
+
# Set these to enable SSL authentication / mutual-authentication
# with the server
ssl_client_cert nil
diff --git a/chef/lib/chef/cookbook_version.rb b/chef/lib/chef/cookbook_version.rb
index 24f2c546f0..0e11174a07 100644
--- a/chef/lib/chef/cookbook_version.rb
+++ b/chef/lib/chef/cookbook_version.rb
@@ -42,135 +42,6 @@ class Chef
COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
- DESIGN_DOCUMENT = {
- "version" => 8,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "all_with_version" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, doc.version);
- }
- }
- EOJS
- },
- "all_with_version_and_deps" => {
- "map" => <<-JS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, {version: doc.version, deps: doc.metadata.dependencies});
- }
- }
- JS
- },
- "all_latest_version" => {
- "map" => %q@
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, doc.version);
- }
- }
- @,
- "reduce" => %q@
- function(keys, values, rereduce) {
- var result = null;
-
- for (var idx in values) {
- var value = values[idx];
-
- if (idx == 0) {
- result = value;
- continue;
- }
-
- var valueParts = value.split('.').map(function(v) { return parseInt(v); });
- var resultParts = result.split('.').map(function(v) { return parseInt(v); });
-
- if (valueParts[0] != resultParts[0]) {
- if (valueParts[0] > resultParts[0]) {
- result = value;
- }
- }
- else if (valueParts[1] != resultParts[1]) {
- if (valueParts[1] > resultParts[1]) {
- result = value;
- }
- }
- else if (valueParts[2] != resultParts[2]) {
- if (valueParts[2] > resultParts[2]) {
- result = value;
- }
- }
- }
- return result;
- }
- @
- },
- "all_latest_version_by_id" => {
- "map" => %q@
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, {version: doc.version, id:doc._id});
- }
- }
- @,
- "reduce" => %q@
- function(keys, values, rereduce) {
- var result = null;
-
- for (var idx in values) {
- var value = values[idx];
-
- if (idx == 0) {
- result = value;
- continue;
- }
-
- var valueParts = value.version.split('.').map(function(v) { return parseInt(v); });
- var resultParts = result.version.split('.').map(function(v) { return parseInt(v); });
-
- if (valueParts[0] != resultParts[0]) {
- if (valueParts[0] > resultParts[0]) {
- result = value;
- }
- }
- else if (valueParts[1] != resultParts[1]) {
- if (valueParts[1] > resultParts[1]) {
- result = value;
- }
- }
- else if (valueParts[2] != resultParts[2]) {
- if (valueParts[2] > resultParts[2]) {
- result = value;
- }
- }
- }
- return result;
- }
- @
- },
- }
- }
-
attr_accessor :root_dir
attr_accessor :definition_filenames
attr_accessor :template_filenames
@@ -183,10 +54,6 @@ class Chef
attr_accessor :metadata
attr_accessor :metadata_filenames
attr_accessor :status
- attr_accessor :couchdb_rev
- attr_accessor :couchdb
-
- attr_reader :couchdb_id
# attribute_filenames also has a setter that has non-default
# functionality.
@@ -325,7 +192,7 @@ class Chef
#
# === Returns
# object<Chef::CookbookVersion>:: Duh. :)
- def initialize(name, couchdb=nil)
+ def initialize(name)
@name = name
@frozen = false
@attribute_filenames = Array.new
@@ -340,9 +207,6 @@ class Chef
@metadata_filenames = Array.new
@root_dir = nil
@root_filenames = Array.new
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- @couchdb_rev = nil
@status = :ready
@manifest = nil
@file_vendor = nil
@@ -685,7 +549,6 @@ class Chef
result = manifest.dup
result['frozen?'] = frozen_version?
result['chef_type'] = 'cookbook_version'
- result["_rev"] = couchdb_rev if couchdb_rev
result.to_hash
end
@@ -697,14 +560,6 @@ class Chef
def self.json_create(o)
cookbook_version = new(o["cookbook_name"])
- if o.has_key?('_rev')
- cookbook_version.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- o.delete("_rev")
- end
- if o.has_key?("_id")
- cookbook_version.couchdb_id = o["_id"] if o.has_key?("_id")
- o.delete("_id")
- end
# We want the Chef::Cookbook::Metadata object to always be inflated
cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
cookbook_version.manifest = o
@@ -811,82 +666,6 @@ class Chef
chef_server_rest.get_rest('cookbooks/_latest')
end
- ##
- # Couchdb
- ##
-
- def self.cdb_by_name(cookbook_name, couchdb=nil)
- cdb = (couchdb || Chef::CouchDB.new)
- options = { :startkey => cookbook_name, :endkey => cookbook_name }
- rs = cdb.get_view("cookbooks", "all_with_version", options)
- rs["rows"].inject({}) { |memo, row| memo.has_key?(row["key"]) ? memo[row["key"]] << row["value"] : memo[row["key"]] = [ row["value"] ]; memo }
- end
-
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("cookbooks", DESIGN_DOCUMENT)
- end
-
- def self.cdb_list_latest(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- if inflate
- doc_ids = cdb_list_latest_ids.map {|i|i["id"]}
- couchdb.bulk_get(doc_ids)
- else
- results = couchdb.get_view("cookbooks", "all_latest_version", :group=>true)["rows"]
- results.inject({}) { |mapped, row| mapped[row["key"]] = row["value"]; mapped}
- end
- end
-
- def self.cdb_list_latest_ids(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- results = couchdb.get_view("cookbooks", "all_latest_version_by_id", :group=>true)["rows"]
- results.map { |name_and_id| name_and_id["value"]}
- end
-
- def self.cdb_list(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- if inflate
- couchdb.list("cookbooks", true)["rows"].collect{|r| r["value"]}
- else
- # If you modify this, please make sure the desc sorted order on the versions doesn't get broken.
- couchdb.get_view("cookbooks", "all_with_version")["rows"].inject({}) { |mapped, row| mapped[row["key"]]||=Array.new; mapped[row["key"]].push(Chef::Version.new(row["value"])); mapped[row["key"]].sort!.reverse!; mapped}
- end
- end
-
- def self.cdb_load(name, version='latest', couchdb=nil)
- cdb = couchdb || Chef::CouchDB.new
- if version == "latest" || version == "_latest"
- rs = cdb.get_view("cookbooks", "all_latest_version", :key => name, :descending => true, :group => true, :reduce => true)["rows"].first
- cdb.load("cookbook_version", "#{rs["key"]}-#{rs["value"]}")
- else
- cdb.load("cookbook_version", "#{name}-#{version}")
- end
- end
-
- def cdb_destroy
- (couchdb || Chef::CouchDB.new).delete("cookbook_version", full_name, couchdb_rev)
- end
-
- # Runs on Chef Server (API); deletes the cookbook from couchdb and also destroys associated
- # checksum documents
- def purge
- checksums.keys.each do |checksum|
- begin
- Chef::Checksum.cdb_load(checksum, couchdb).purge
- rescue Chef::Exceptions::CouchDBNotFound
- end
- end
- cdb_destroy
- end
-
- def cdb_save
- @couchdb_rev = couchdb.store("cookbook_version", full_name, self)["rev"]
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
- end
-
def <=>(o)
raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
# FIXME: can we change the interface to the Metadata class such
diff --git a/chef/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb
deleted file mode 100644
index 71ee196462..0000000000
--- a/chef/lib/chef/couchdb.rb
+++ /dev/null
@@ -1,246 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'chef/mixin/params_validate'
-require 'chef/config'
-require 'chef/rest'
-require 'chef/log'
-require 'digest/sha2'
-require 'chef/json_compat'
-
-# We want to fail on create if uuidtools isn't installed
-begin
- require 'uuidtools'
-rescue LoadError
-end
-
-class Chef
- class CouchDB
- include Chef::Mixin::ParamsValidate
-
- def initialize(url=nil, db=Chef::Config[:couchdb_database])
- url ||= Chef::Config[:couchdb_url]
- @db = db
- @rest = Chef::REST.new(url, nil, nil)
- end
-
- def couchdb_database(args=nil)
- @db = args || @db
- end
-
- def create_id_map
- create_design_document(
- "id_map",
- {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "name_to_id" => {
- "map" => <<-EOJS
- function(doc) {
- emit([ doc.chef_type, doc.name], doc._id);
- }
- EOJS
- },
- "id_to_name" => {
- "map" => <<-EOJS
- function(doc) {
- emit(doc._id, [ doc.chef_type, doc.name ]);
- }
- EOJS
- }
- }
- }
- )
- end
-
- def create_db(check_for_existing=true)
- @database_list = @rest.get_rest("_all_dbs")
- if !check_for_existing || !@database_list.any? { |db| db == couchdb_database }
- response = @rest.put_rest(couchdb_database, Hash.new)
- end
- couchdb_database
- end
-
- def create_design_document(name, data)
- to_update = true
- begin
- old_doc = @rest.get_rest("#{couchdb_database}/_design/#{name}")
- if data["version"] != old_doc["version"]
- data["_rev"] = old_doc["_rev"]
- Chef::Log.debug("Updating #{name} views")
- else
- to_update = false
- end
- rescue
- Chef::Log.debug("Creating #{name} views for the first time because: #{$!}")
- end
- if to_update
- @rest.put_rest("#{couchdb_database}/_design%2F#{name}", data)
- end
- true
- end
-
- # Save the object to Couch. Add to index if the object supports it.
- def store(obj_type, name, object)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- :object => object,
- },
- {
- :object => { :respond_to => :to_json },
- }
- )
- rows = get_view("id_map", "name_to_id", :key => [ obj_type, name ])["rows"]
- uuid = rows.empty? ? UUIDTools::UUID.random_create.to_s : rows.first.fetch("id")
-
- db_put_response = @rest.put_rest("#{couchdb_database}/#{uuid}", object)
-
- if object.respond_to?(:add_to_index)
- Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for addition.")
- object.add_to_index(:database => couchdb_database, :id => uuid, :type => obj_type)
- end
-
- db_put_response
- end
-
- def load(obj_type, name)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- doc = find_by_name(obj_type, name)
- doc.couchdb = self if doc.respond_to?(:couchdb)
- doc
- end
-
- def delete(obj_type, name, rev=nil)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- del_id = nil
- object, uuid = find_by_name(obj_type, name, true)
- unless rev
- if object.respond_to?(:couchdb_rev)
- rev = object.couchdb_rev
- else
- rev = object['_rev']
- end
- end
- response = @rest.delete_rest("#{couchdb_database}/#{uuid}?rev=#{rev}")
- response.couchdb = self if response.respond_to?(:couchdb=)
-
- if object.respond_to?(:delete_from_index)
- Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for deletion..")
- object.delete_from_index(:database => couchdb_database, :id => uuid, :type => obj_type)
- end
-
- response
- end
-
- def list(view, inflate=false)
- validate(
- {
- :view => view,
- },
- {
- :view => { :kind_of => String }
- }
- )
- if inflate
- r = @rest.get_rest(view_uri(view, "all"))
- r["rows"].each { |i| i["value"].couchdb = self if i["value"].respond_to?(:couchdb=) }
- r
- else
- r = @rest.get_rest(view_uri(view, "all_id"))
- end
- r
- end
-
- def has_key?(obj_type, name)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- begin
- find_by_name(obj_type, name)
- true
- rescue
- false
- end
- end
-
- def find_by_name(obj_type, name, with_id=false)
- r = get_view("id_map", "name_to_id", :key => [ obj_type, name ], :include_docs => true)
- if r["rows"].length == 0
- raise Chef::Exceptions::CouchDBNotFound, "Cannot find #{obj_type} #{name} in CouchDB!"
- end
- if with_id
- [ r["rows"][0]["doc"], r["rows"][0]["id"] ]
- else
- r["rows"][0]["doc"]
- end
- end
-
- def get_view(design, view, options={})
- view_string = view_uri(design, view)
- view_string << "?" if options.length != 0
- view_string << options.map { |k,v| "#{k}=#{URI.escape(v.to_json)}"}.join('&')
- @rest.get_rest(view_string)
- end
-
- def bulk_get(*to_fetch)
- response = @rest.post_rest("#{couchdb_database}/_all_docs?include_docs=true", { "keys" => to_fetch.flatten })
- response["rows"].collect { |r| r["doc"] }
- end
-
- def view_uri(design, view)
- "#{couchdb_database}/_design/#{design}/_view/#{view}"
- end
-
- def server_stats
- @rest.get_rest('/')
- end
-
- def db_stats
- @rest.get_rest("/#{@db}")
- end
-
- end
-end
diff --git a/chef/lib/chef/data_bag.rb b/chef/lib/chef/data_bag.rb
index e270dde062..9ce6215b20 100644
--- a/chef/lib/chef/data_bag.rb
+++ b/chef/lib/chef/data_bag.rb
@@ -21,7 +21,6 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/data_bag_item'
require 'chef/mash'
require 'chef/json_compat'
@@ -34,54 +33,15 @@ class Chef
VALID_NAME = /^[\-[:alnum:]_]+$/
- DESIGN_DOCUMENT = {
- "version" => 2,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "entries" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.data_bag, doc.raw_data.id);
- }
- }
- EOJS
- }
- }
- }
-
def self.validate_name!(name)
unless name =~ VALID_NAME
raise Exceptions::InvalidDataBagName, "DataBags must have a name matching #{VALID_NAME.inspect}, you gave #{name.inspect}"
end
end
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
-
# Create a new Chef::DataBag
- def initialize(couchdb=nil)
+ def initialize
@name = ''
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = (couchdb || Chef::CouchDB.new)
end
def name(arg=nil)
@@ -98,7 +58,6 @@ class Chef
'json_class' => self.class.name,
"chef_type" => "data_bag",
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -119,19 +78,9 @@ class Chef
def self.json_create(o)
bag = new
bag.name(o["name"])
- bag.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- bag.couchdb_id = o["_id"] if o.has_key?("_id")
bag
end
- # List all the Chef::DataBag objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Roles, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("data_bags", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
# Can't search for all data bags like other objects, fall back to N+1 :(
@@ -144,11 +93,6 @@ class Chef
end
end
- # Load a Data Bag by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("data_bag", name)
- end
-
# Load a Data Bag by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(name)
if Chef::Config[:solo]
@@ -166,27 +110,10 @@ class Chef
end
end
- # Remove this Data Bag from CouchDB
- def cdb_destroy
- removed = @couchdb.delete("data_bag", @name, @couchdb_rev)
- rs = @couchdb.get_view("data_bags", "entries", :include_docs => true, :startkey => @name, :endkey => @name)
- rs["rows"].each do |row|
- row["doc"].couchdb = couchdb
- row["doc"].cdb_destroy
- end
- removed
- end
-
def destroy
chef_server_rest.delete_rest("data/#{@name}")
end
- # Save this Data Bag to the CouchDB
- def cdb_save
- results = @couchdb.store("data_bag", @name, self)
- @couchdb_rev = results["rev"]
- end
-
# Save the Data Bag via RESTful API
def save
begin
@@ -208,24 +135,6 @@ class Chef
self
end
- # List all the items in this Bag from CouchDB
- # The self.load method does this through the REST API
- def list(inflate=false)
- rs = nil
- if inflate
- rs = @couchdb.get_view("data_bags", "entries", :include_docs => true, :startkey => @name, :endkey => @name)
- rs["rows"].collect { |r| r["doc"] }
- else
- rs = @couchdb.get_view("data_bags", "entries", :startkey => @name, :endkey => @name)
- rs["rows"].collect { |r| r["value"] }
- end
- end
-
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("data_bags", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"data_bag[#{@name}]"
diff --git a/chef/lib/chef/data_bag_item.rb b/chef/lib/chef/data_bag_item.rb
index 170c7d9ad0..3528ba724a 100644
--- a/chef/lib/chef/data_bag_item.rb
+++ b/chef/lib/chef/data_bag_item.rb
@@ -23,7 +23,6 @@ require 'forwardable'
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/data_bag'
require 'chef/mash'
require 'chef/json_compat'
@@ -38,31 +37,6 @@ class Chef
VALID_ID = /^[\-[:alnum:]_]+$/
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
def self.validate_id!(id_str)
if id_str.nil? || ( id_str !~ VALID_ID )
raise Exceptions::InvalidDataBagItemID, "Data Bag items must have an id matching #{VALID_ID.inspect}, you gave: #{id_str.inspect}"
@@ -72,16 +46,12 @@ class Chef
# Define all Hash's instance methods as delegating to @raw_data
def_delegators(:@raw_data, *(Hash.instance_methods - Object.instance_methods))
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
attr_reader :raw_data
# Create a new Chef::DataBagItem
- def initialize(couchdb=nil)
- @couchdb_rev = nil
- @couchdb_id = nil
+ def initialize
@data_bag = nil
@raw_data = Mash.new
- @couchdb = couchdb || Chef::CouchDB.new
end
def chef_server_rest
@@ -136,7 +106,6 @@ class Chef
result = self.raw_data
result["chef_type"] = "data_bag_item"
result["data_bag"] = self.data_bag
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -149,7 +118,6 @@ class Chef
"data_bag" => self.data_bag,
"raw_data" => self.raw_data
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result.to_json(*a)
end
@@ -167,23 +135,11 @@ class Chef
o.delete("chef_type")
o.delete("json_class")
o.delete("name")
- if o.has_key?("_rev")
- bag_item.couchdb_rev = o["_rev"]
- o.delete("_rev")
- end
- if o.has_key?("_id")
- bag_item.couchdb_id = o["_id"]
- o.delete("_id")
- end
+
bag_item.raw_data = Mash.new(o["raw_data"])
bag_item
end
- # Load a Data Bag Item by name from CouchDB
- def self.cdb_load(data_bag, name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("data_bag_item", object_name(data_bag, name))
- end
-
# Load a Data Bag Item by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(data_bag, name)
if Chef::Config[:solo]
@@ -202,21 +158,10 @@ class Chef
end
end
- # Remove this Data Bag Item from CouchDB
- def cdb_destroy
- Chef::Log.debug "Destroying data bag item: #{self.inspect}"
- @couchdb.delete("data_bag_item", object_name, @couchdb_rev)
- end
-
def destroy(data_bag=data_bag, databag_item=name)
chef_server_rest.delete_rest("data/#{data_bag}/#{databag_item}")
end
- # Save this Data Bag Item to CouchDB
- def cdb_save
- @couchdb_rev = @couchdb.store("data_bag_item", object_name, self)["rev"]
- end
-
# Save this Data Bag Item via RESTful API
def save(item_id=@raw_data['id'])
r = chef_server_rest
@@ -239,11 +184,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("data_bag_items", DESIGN_DOCUMENT)
- end
-
def ==(other)
other.respond_to?(:to_hash) &&
other.respond_to?(:data_bag) &&
diff --git a/chef/lib/chef/environment.rb b/chef/lib/chef/environment.rb
index 745b5bb55f..00cc253083 100644
--- a/chef/lib/chef/environment.rb
+++ b/chef/lib/chef/environment.rb
@@ -22,7 +22,6 @@ require 'chef/config'
require 'chef/mash'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/version_constraint'
class Chef
@@ -35,47 +34,12 @@ class Chef
COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze
- attr_accessor :couchdb, :couchdb_rev
- attr_reader :couchdb_id
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "environment") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "environment") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@description = ''
@default_attributes = Mash.new
@override_attributes = Mash.new
@cookbook_versions = Hash.new
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
end
def chef_server_rest
@@ -160,7 +124,6 @@ class Chef
"default_attributes" => @default_attributes,
"override_attributes" => @override_attributes
}
- result["_rev"] = couchdb_rev if couchdb_rev
result
end
@@ -257,17 +220,9 @@ class Chef
environment.cookbook_versions(o["cookbook_versions"])
environment.default_attributes(o["default_attributes"])
environment.override_attributes(o["override_attributes"])
- environment.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- environment.couchdb_id = o["_id"] if o.has_key?("_id")
environment
end
- def self.cdb_list(inflate=false, couchdb=nil)
- es = (couchdb || Chef::CouchDB.new).list("environments", inflate)
- lookup = (inflate ? "value" : "key")
- es["rows"].collect { |e| e[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -280,34 +235,14 @@ class Chef
end
end
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("environment", name)
- end
-
def self.load(name)
chef_server_rest.get_rest("environments/#{name}")
end
- def self.exists?(name, couchdb)
- begin
- self.cdb_load(name, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
- def cdb_destroy
- couchdb.delete("environment", @name, couchdb_rev)
- end
-
def destroy
chef_server_rest.delete_rest("environments/#{@name}")
end
- def cdb_save
- self.couchdb_rev = couchdb.store("environment", @name, self)["rev"]
- end
-
def save
begin
chef_server_rest.put_rest("environments/#{@name}", self)
@@ -323,106 +258,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("environments", DESIGN_DOCUMENT)
- end
-
- # Loads the set of Chef::CookbookVersion objects available to a given environment
- # === Returns
- # Hash
- # i.e.
- # {
- # "cookbook_name" => [ Chef::CookbookVersion ... ] ## the array of CookbookVersions is sorted highest to lowest
- # }
- #
- # There will be a key for every cookbook. If no CookbookVersions
- # are available for the specified environment the value will be an
- # empty list.
- #
- def self.cdb_load_filtered_cookbook_versions(name, couchdb=nil)
- version_constraints = cdb_load(name, couchdb).cookbook_versions.inject({}) {|res, (k,v)| res[k] = Chef::VersionConstraint.new(v); res}
-
- # inject all cookbooks into the hash while filtering out restricted versions, then sort the individual arrays
- cookbook_list = Chef::CookbookVersion.cdb_list(true, couchdb)
-
- filtered_list = cookbook_list.inject({}) do |res, cookbook|
- # FIXME: should cookbook.version return a Chef::Version?
- version = Chef::Version.new(cookbook.version)
- requirement_satisfied = version_constraints.has_key?(cookbook.name) ? version_constraints[cookbook.name].include?(version) : true
- # we want a key for every cookbook, even if no versions are available
- res[cookbook.name] ||= []
- res[cookbook.name] << cookbook if requirement_satisfied
- res
- end
-
- sorted_list = filtered_list.inject({}) do |res, (cookbook_name, versions)|
- res[cookbook_name] = versions.sort.reverse
- res
- end
-
- sorted_list
- end
-
- # Like +cdb_load_filtered_cookbook_versions+, loads the set of
- # cookbooks available in a given environment. The difference is that
- # this method will load Chef::MinimalCookbookVersion objects that
- # contain only the information necessary for solving a cookbook
- # collection for a given run list. The user of this method must call
- # Chef::MinimalCookbookVersion.load_full_versions_of() after solving
- # the cookbook collection to get the full objects.
- # === Returns
- # Hash
- # i.e.
- # {
- # "cookbook_name" => [ Chef::CookbookVersion ... ] ## the array of CookbookVersions is sorted highest to lowest
- # }
- #
- # There will be a key for every cookbook. If no CookbookVersions
- # are available for the specified environment the value will be an
- # empty list.
- def self.cdb_minimal_filtered_versions(name, couchdb=nil)
- version_constraints = cdb_load(name, couchdb).cookbook_versions.inject({}) {|res, (k,v)| res[k] = Chef::VersionConstraint.new(v); res}
-
- # inject all cookbooks into the hash while filtering out restricted versions, then sort the individual arrays
- cookbook_list = Chef::MinimalCookbookVersion.load_all(couchdb)
-
- filtered_list = cookbook_list.inject({}) do |res, cookbook|
- # FIXME: should cookbook.version return a Chef::Version?
- version = Chef::Version.new(cookbook.version)
- requirement_satisfied = version_constraints.has_key?(cookbook.name) ? version_constraints[cookbook.name].include?(version) : true
- # we want a key for every cookbook, even if no versions are available
- res[cookbook.name] ||= []
- res[cookbook.name] << cookbook if requirement_satisfied
- res
- end
-
- sorted_list = filtered_list.inject({}) do |res, (cookbook_name, versions)|
- res[cookbook_name] = versions.sort.reverse
- res
- end
-
- sorted_list
- end
-
- def self.cdb_load_filtered_recipe_list(name, couchdb=nil)
- cdb_load_filtered_cookbook_versions(name, couchdb).map do |cb_name, cb|
- if cb.empty? # no available versions
- [] # empty list elided with flatten
- else
- latest_version = cb.first
- latest_version.recipe_filenames_by_name.keys.map do |recipe|
- case recipe
- when DEFAULT
- cb_name
- else
- "#{cb_name}::#{recipe}"
- end
- end
- end
- end.flatten
- end
-
def self.load_filtered_recipe_list(environment)
chef_server_rest.get_rest("environments/#{environment}/recipes")
end
@@ -448,16 +283,5 @@ class Chef
end
end
- def self.create_default_environment(couchdb=nil)
- couchdb = couchdb || Chef::CouchDB.new
- begin
- Chef::Environment.cdb_load('_default', couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- env = Chef::Environment.new(couchdb)
- env.name '_default'
- env.description 'The default Chef environment'
- env.cdb_save
- end
- end
end
end
diff --git a/chef/lib/chef/exceptions.rb b/chef/lib/chef/exceptions.rb
index c5d213f8b3..87802639d3 100644
--- a/chef/lib/chef/exceptions.rb
+++ b/chef/lib/chef/exceptions.rb
@@ -54,7 +54,6 @@ class Chef
class Group < RuntimeError; end
class Link < RuntimeError; end
class Mount < RuntimeError; end
- class CouchDBNotFound < RuntimeError; end
class PrivateKeyMissing < RuntimeError; end
class CannotWritePrivateKey < RuntimeError; end
class RoleNotFound < RuntimeError; end
@@ -112,7 +111,7 @@ class Chef
# File operation attempted but no permissions to perform it
class InsufficientPermissions < RuntimeError; end
-
+
# Ifconfig failed
class Ifconfig < RuntimeError; end
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index 8efa43e149..92a2374bce 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -28,7 +28,6 @@ require 'chef/mixin/from_file'
require 'chef/mixin/deep_merge'
require 'chef/dsl/include_attribute'
require 'chef/environment'
-require 'chef/couchdb'
require 'chef/rest'
require 'chef/run_list'
require 'chef/node/attribute'
@@ -43,8 +42,7 @@ class Chef
def_delegators :attributes, :keys, :each_key, :each_value, :key?, :has_key?
- attr_accessor :recipe_list, :couchdb, :couchdb_rev, :run_state, :run_list
- attr_reader :couchdb_id
+ attr_accessor :recipe_list, :run_state, :run_list
attr_accessor :run_context
@@ -54,101 +52,8 @@ class Chef
include Chef::Mixin::CheckHelper
include Chef::Mixin::ParamsValidate
- DESIGN_DOCUMENT = {
- "version" => 11,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "status" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- var to_emit = { "name": doc.name, "chef_environment": doc.chef_environment };
- if (doc["attributes"]["fqdn"]) {
- to_emit["fqdn"] = doc["attributes"]["fqdn"];
- } else {
- to_emit["fqdn"] = "Undefined";
- }
- if (doc["attributes"]["ipaddress"]) {
- to_emit["ipaddress"] = doc["attributes"]["ipaddress"];
- } else {
- to_emit["ipaddress"] = "Undefined";
- }
- if (doc["attributes"]["ohai_time"]) {
- to_emit["ohai_time"] = doc["attributes"]["ohai_time"];
- } else {
- to_emit["ohai_time"] = "Undefined";
- }
- if (doc["attributes"]["uptime"]) {
- to_emit["uptime"] = doc["attributes"]["uptime"];
- } else {
- to_emit["uptime"] = "Undefined";
- }
- if (doc["attributes"]["platform"]) {
- to_emit["platform"] = doc["attributes"]["platform"];
- } else {
- to_emit["platform"] = "Undefined";
- }
- if (doc["attributes"]["platform_version"]) {
- to_emit["platform_version"] = doc["attributes"]["platform_version"];
- } else {
- to_emit["platform_version"] = "Undefined";
- }
- if (doc["run_list"]) {
- to_emit["run_list"] = doc["run_list"];
- } else {
- to_emit["run_list"] = "Undefined";
- }
- emit(doc.name, to_emit);
- }
- }
- EOJS
- },
- "by_run_list" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- if (doc['run_list']) {
- for (var i=0; i < doc.run_list.length; i++) {
- emit(doc['run_list'][i], doc.name);
- }
- }
- }
- }
- EOJS
- },
- "by_environment" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- var env = (doc['chef_environment'] == null ? "_default" : doc['chef_environment']);
- emit(env, doc.name);
- }
- }
- EOJS
- }
- },
- }
-
# Create a new Chef::Node object.
- def initialize(couchdb=nil)
+ def initialize
@name = nil
@chef_environment = '_default'
@@ -156,17 +61,9 @@ class Chef
@attributes = Chef::Node::Attribute.new({}, {}, {}, {})
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
-
@run_state = {}
end
- def couchdb_id=(value)
- @couchdb_id = value
- end
-
# Used by DSL
def node
self
@@ -467,7 +364,6 @@ class Chef
#Render correctly for run_list items so malformed json does not result
"run_list" => run_list.run_list.map { |item| item.to_s }
}
- result["_rev"] = couchdb_rev if couchdb_rev
result.to_json(*a)
end
@@ -499,16 +395,9 @@ class Chef
else
o["recipes"].each { |r| node.recipes << r }
end
- node.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- node.couchdb_id = o["_id"] if o.has_key?("_id")
node
end
- def self.cdb_list_by_environment(environment, inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).get_view("nodes", "by_environment", :include_docs => inflate, :startkey => environment, :endkey => environment)
- inflate ? rs["rows"].collect {|r| r["doc"]} : rs["rows"].collect {|r| r["value"]}
- end
-
def self.list_by_environment(environment, inflate=false)
if inflate
response = Hash.new
@@ -519,14 +408,6 @@ class Chef
end
end
- # List all the Chef::Node objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Nodes, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs =(couchdb || Chef::CouchDB.new).list("nodes", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -539,19 +420,6 @@ class Chef
end
end
- # Load a node by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("node", name)
- end
-
- def self.exists?(nodename, couchdb)
- begin
- self.cdb_load(nodename, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
def self.find_or_create(node_name)
load(node_name)
rescue Net::HTTPServerException => e
@@ -572,21 +440,11 @@ class Chef
Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
end
- # Remove this node from the CouchDB
- def cdb_destroy
- couchdb.delete("node", name, couchdb_rev)
- end
-
# Remove this node via the REST API
def destroy
chef_server_rest.delete_rest("nodes/#{name}")
end
- # Save this node to the CouchDB
- def cdb_save
- @couchdb_rev = couchdb.store("node", name, self)["rev"]
- end
-
# Save this node via the REST API
def save
# Try PUT. If the node doesn't yet exist, PUT will return 404,
@@ -610,11 +468,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("nodes", DESIGN_DOCUMENT)
- end
-
def to_s
"node[#{name}]"
end
diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb
index 79b71c3995..78bbfadb88 100644
--- a/chef/lib/chef/role.rb
+++ b/chef/lib/chef/role.rb
@@ -21,7 +21,6 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/run_list'
require 'chef/mash'
require 'chef/json_compat'
@@ -33,48 +32,13 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- DESIGN_DOCUMENT = {
- "version" => 6,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "role") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "role") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- attr_accessor :couchdb_rev, :couchdb
- attr_reader :couchdb_id
-
# Create a new Chef::Role object.
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@description = ''
@default_attributes = Mash.new
@override_attributes = Mash.new
@env_run_lists = {"_default" => Chef::RunList.new}
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
end
def chef_server_rest
@@ -174,7 +138,6 @@ class Chef
accumulator
end
}
- result["_rev"] = couchdb_rev if couchdb_rev
result
end
@@ -211,19 +174,9 @@ class Chef
end
role.env_run_lists(env_run_list_hash)
- role.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- role.couchdb_id = o["_id"] if o.has_key?("_id")
role
end
- # List all the Chef::Role objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Roles, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("roles", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
# Get the list of all roles from the API.
def self.list(inflate=false)
if inflate
@@ -237,24 +190,11 @@ class Chef
end
end
- # Load a role by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("role", name)
- end
-
# Load a role by name from the API
def self.load(name)
chef_server_rest.get_rest("roles/#{name}")
end
- def self.exists?(rolename, couchdb)
- begin
- self.cdb_load(rolename, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
def environment(env_name)
chef_server_rest.get_rest("roles/#{@name}/environments/#{env_name}")
end
@@ -263,21 +203,11 @@ class Chef
chef_server_rest.get_rest("roles/#{@name}/environments")
end
- # Remove this role from the CouchDB
- def cdb_destroy
- couchdb.delete("role", @name, couchdb_rev)
- end
-
# Remove this role via the REST API
def destroy
chef_server_rest.delete_rest("roles/#{@name}")
end
- # Save this role to the CouchDB
- def cdb_save
- self.couchdb_rev = couchdb.store("role", @name, self)["rev"]
- end
-
# Save this role via the REST API
def save
begin
@@ -295,11 +225,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("roles", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"role[#{@name}]"
@@ -324,22 +249,5 @@ class Chef
end
end
- # Sync all the json roles with couchdb from disk
- def self.sync_from_disk_to_couchdb
- Dir[File.join(Chef::Config[:role_path], "*.json")].each do |role_file|
- short_name = File.basename(role_file, ".json")
- Chef::Log.warn("Loading #{short_name}")
- r = Chef::Role.from_disk(short_name, "json")
- begin
- couch_role = Chef::Role.cdb_load(short_name)
- r.couchdb_rev = couch_role.couchdb_rev
- Chef::Log.debug("Replacing role #{short_name} with data from #{role_file}")
- rescue Chef::Exceptions::CouchDBNotFound
- Chef::Log.debug("Creating role #{short_name} with data from #{role_file}")
- end
- r.cdb_save
- end
- end
-
end
end
diff --git a/chef/lib/chef/run_list.rb b/chef/lib/chef/run_list.rb
index 1e4bdd255a..684c5e19fc 100644
--- a/chef/lib/chef/run_list.rb
+++ b/chef/lib/chef/run_list.rb
@@ -155,8 +155,6 @@ class Chef
RunListExpansionFromDisk.new(environment, @run_list_items)
when 'server'
RunListExpansionFromAPI.new(environment, @run_list_items, opts[:rest])
- when 'couchdb'
- RunListExpansionFromCouchDB.new(environment, @run_list_items, opts[:couchdb])
end
end
diff --git a/chef/lib/chef/run_list/run_list_expansion.rb b/chef/lib/chef/run_list/run_list_expansion.rb
index 690eb3392b..7b8108a2d4 100644
--- a/chef/lib/chef/run_list/run_list_expansion.rb
+++ b/chef/lib/chef/run_list/run_list_expansion.rb
@@ -21,7 +21,6 @@ require 'chef/mash'
require 'chef/mixin/deep_merge'
require 'chef/role'
-require 'chef/couchdb'
require 'chef/rest'
class Chef
@@ -188,19 +187,5 @@ class Chef
end
end
- # Expand a run list from couchdb. Used in chef-server-api
- class RunListExpansionFromCouchDB < RunListExpansion
-
- def couchdb
- source
- end
-
- def fetch_role(name, included_by)
- Chef::Role.cdb_load(name, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- role_not_found(name, included_by)
- end
-
- end
end
end
diff --git a/chef/spec/unit/client_spec.rb b/chef/spec/unit/client_spec.rb
index e8a75b7009..9d0c88dad1 100644
--- a/chef/spec/unit/client_spec.rb
+++ b/chef/spec/unit/client_spec.rb
@@ -41,7 +41,7 @@ shared_examples_for Chef::Client do
ohai_data.stub!(:data).and_return(ohai_data)
Ohai::System.stub!(:new).and_return(ohai_data)
- @node = Chef::Node.new(@hostname)
+ @node = Chef::Node.new
@node.name(@fqdn)
@node.chef_environment("_default")
@@ -90,7 +90,7 @@ shared_examples_for Chef::Client do
Chef::REST.should_receive(:new).with(Chef::Config[:client_url], Chef::Config[:validation_client_name], Chef::Config[:validation_key]).exactly(1).and_return(mock_chef_rest_for_client)
mock_chef_rest_for_client.should_receive(:register).with(@fqdn, Chef::Config[:client_key]).exactly(1).and_return(true)
# Client.register will then turn around create another
-
+
# Chef::REST object, this time with the client key it got from the
# previous step.
Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url], @fqdn, Chef::Config[:client_key]).exactly(1).and_return(mock_chef_rest_for_node)
@@ -139,7 +139,6 @@ shared_examples_for Chef::Client do
res.replace(string)
end
pipe_sim.should_receive(:gets).and_return(res)
- Chef::CouchDB.should_receive(:new).and_return(nil)
IO.should_receive(:pipe).and_return([pipe_sim, pipe_sim])
IO.should_receive(:select).and_return(true)
end
@@ -151,7 +150,7 @@ shared_examples_for Chef::Client do
block.call
end
end
-
+
# This is what we're testing.
@client.run
@@ -160,7 +159,7 @@ shared_examples_for Chef::Client do
@node.automatic_attrs[:platform_version].should == "example-platform-1.0"
end
end
-
+
describe "when notifying other objects of the status of the chef run" do
before do
Chef::Client.clear_notifications
@@ -235,7 +234,7 @@ shared_examples_for Chef::Client do
describe "when a run list override is provided" do
before do
- @node = Chef::Node.new(@hostname)
+ @node = Chef::Node.new
@node.name(@fqdn)
@node.chef_environment("_default")
@node.automatic_attrs[:platform] = "example-platform"
@@ -265,7 +264,7 @@ shared_examples_for Chef::Client do
@node.should_receive(:save).and_return(nil)
@client.build_node
-
+
@node[:roles].should_not be_nil
@node[:roles].should eql(['test_role'])
@node[:recipes].should eql(['cookbook1'])
diff --git a/chef/spec/unit/cookbook_version_spec.rb b/chef/spec/unit/cookbook_version_spec.rb
index 29b994059e..85e1db1fae 100644
--- a/chef/spec/unit/cookbook_version_spec.rb
+++ b/chef/spec/unit/cookbook_version_spec.rb
@@ -20,8 +20,7 @@ require 'spec_helper'
describe Chef::CookbookVersion do
describe "when first created" do
before do
- @couchdb_driver = Chef::CouchDB.new
- @cookbook_version = Chef::CookbookVersion.new("tatft", @couchdb_driver)
+ @cookbook_version = Chef::CookbookVersion.new("tatft")
end
it "has a name" do
@@ -69,14 +68,6 @@ describe Chef::CookbookVersion do
@cookbook_version.should be_frozen_version
end
- it "has no couchdb id" do
- @cookbook_version.couchdb_id.should be_nil
- end
-
- it "has the couchdb driver it was given on create" do
- @cookbook_version.couchdb.should equal(@couchdb_driver)
- end
-
it "is \"ready\"" do
# WTF is this? what are the valid states? and why aren't they set with encapsulating methods?
# [Dan 15-Jul-2010]
@@ -313,54 +304,4 @@ describe Chef::CookbookVersion do
end
- describe "when deleting in the database" do
- before do
- @couchdb_driver = Chef::CouchDB.new
- @cookbook_version = Chef::CookbookVersion.new("tatft", @couchdb_driver)
- @cookbook_version.version = "1.2.3"
- @couchdb_rev = "_123456789"
- @cookbook_version.couchdb_rev = @couchdb_rev
- end
-
- it "deletes its document from couchdb" do
- @couchdb_driver.should_receive(:delete).with("cookbook_version", "tatft-1.2.3", @couchdb_rev)
- @cookbook_version.cdb_destroy
- end
-
- it "deletes associated checksum objects when purged" do
- checksums = {"12345" => "/tmp/foo", "23456" => "/tmp/bar", "34567" => "/tmp/baz"}
- @cookbook_version.stub!(:checksums).and_return(checksums)
-
- chksum_docs = checksums.map do |md5, path|
- cksum_doc = mock("Chef::Checksum for #{md5} at #{path}")
- Chef::Checksum.should_receive(:cdb_load).with(md5, @couchdb_driver).and_return(cksum_doc)
- cksum_doc.should_receive(:purge)
- cksum_doc
- end
-
- @cookbook_version.should_receive(:cdb_destroy)
- @cookbook_version.purge
- end
-
- it "successfully purges when associated checksum objects are missing" do
- checksums = {"12345" => "/tmp/foo", "23456" => "/tmp/bar", "34567" => "/tmp/baz"}
-
- chksum_docs = checksums.map do |md5, path|
- cksum_doc = mock("Chef::Checksum for #{md5} at #{path}")
- Chef::Checksum.should_receive(:cdb_load).with(md5, @couchdb_driver).and_return(cksum_doc)
- cksum_doc.should_receive(:purge)
- cksum_doc
- end
-
- missing_checksum = {"99999" => "/tmp/qux"}
- Chef::Checksum.should_receive(:cdb_load).with("99999", @couchdb_driver).and_raise(Chef::Exceptions::CouchDBNotFound)
-
- @cookbook_version.stub!(:checksums).and_return(checksums.merge(missing_checksum))
-
- @cookbook_version.should_receive(:cdb_destroy)
- lambda {@cookbook_version.purge}.should_not raise_error
- end
-
- end
-
end
diff --git a/chef/spec/unit/couchdb_spec.rb b/chef/spec/unit/couchdb_spec.rb
deleted file mode 100644
index 480dd61980..0000000000
--- a/chef/spec/unit/couchdb_spec.rb
+++ /dev/null
@@ -1,274 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'spec_helper'
-
-describe Chef::CouchDB do
- before(:each) do
- Chef::Config[:couchdb_database] = "chef"
- @rest = mock("Chef::REST")
- @rest.stub!(:run_request).and_return({"couchdb" => "Welcome", "version" =>"0.9.0"})
- @rest.stub!(:url).and_return("http://localhost:5984")
- Chef::REST.stub!(:new).and_return(@rest)
- @couchdb = Chef::CouchDB.new
- end
-
- describe "new" do
- it "should create a new Chef::REST object from the default url" do
- old_url = Chef::Config[:couchdb_url]
- Chef::Config[:couchdb_url] = "http://monkey"
- Chef::REST.should_receive(:new).with("http://monkey", nil, nil)
- Chef::CouchDB.new
- Chef::Config[:couchdb_url] = old_url
- end
-
- it "should create a new Chef::REST object from a provided url" do
- Chef::REST.should_receive(:new).with("http://monkeypants", nil, nil)
- Chef::CouchDB.new("http://monkeypants")
- end
- end
-
- describe "create_db" do
- before(:each) do
- @couchdb.stub!(:create_design_document).and_return(true)
- end
-
- it "should get a list of current databases" do
- @rest.should_receive(:get_rest).and_return(["chef"])
- @couchdb.create_db
- end
-
- it "should create the chef database if it does not exist" do
- @rest.stub!(:get_rest).and_return([])
- @rest.should_receive(:put_rest).with("chef", {}).and_return(true)
- @couchdb.create_db
- end
-
- it "should not create the chef database if it does exist" do
- @rest.stub!(:get_rest).and_return(["chef"])
- @rest.should_not_receive(:put_rest)
- @couchdb.create_db
- end
-
- it "should return 'chef'" do
- @rest.should_receive(:get_rest).with("_all_dbs").and_return(%w{chef})
- @couchdb.create_db.should eql("chef")
- end
- end
-
- describe "create_design_document" do
- before(:each) do
- @mock_design = {
- "version" => 1,
- "_rev" => 1
- }
- @mock_data = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- }
- }
- @rest.stub!(:get_rest).and_return(@mock_design)
- @rest.stub!(:put_rest).and_return(true)
- @couchdb.stub!(:create_db).and_return(true)
- end
-
- def do_create_design_document
- @couchdb.create_design_document("bob", @mock_data)
- end
-
- it "should fetch the existing design document" do
- @rest.should_receive(:get_rest).with("chef/_design/bob")
- do_create_design_document
- end
-
- it "should populate the _rev in the new design if the versions dont match" do
- @mock_data["version"] = 2
- do_create_design_document
- @mock_data["_rev"].should eql(1)
- end
-
- it "should create the view if it requires updating" do
- @mock_data["version"] = 2
- @rest.should_receive(:put_rest).with("chef/_design%2Fbob", @mock_data)
- do_create_design_document
- end
-
- it "should not create the view if it does not require updating" do
- @mock_data["version"] = 1
- @rest.should_not_receive(:put_rest)
- do_create_design_document
- end
- end
-
- describe "store" do
- before(:each) do
- @mock_results = {
- "rows" => [
- "id" => 'a0934635-e111-45d9-8223-cb58e1c9434c'
- ]
- }
- @couchdb.stub!(:get_view).with("id_map", "name_to_id", :key => [ "node", "bob" ]).and_return(@mock_results)
- end
-
- it "should put the object into couchdb with a pre-existing GUID" do
- item_to_store = {}
- item_to_store.should_receive(:add_to_index)
- @rest.should_receive(:put_rest).with("chef/#{@mock_results["rows"][0]["id"]}", item_to_store).and_return(true)
- @couchdb.store("node", "bob", item_to_store)
- end
-
- it "should put the object into couchdb with a new GUID" do
- @mock_results = { "rows" => [] }
- item_to_store = {}
- item_to_store.should_receive(:add_to_index).with(:database => "chef", :id => "aaaaaaaa-xxxx-xxxx-xxxx-xxxxxxxxxxx", :type => "node")
- @couchdb.stub!(:get_view).with("id_map", "name_to_id", :key => [ "node", "bob" ]).and_return(@mock_results)
- UUIDTools::UUID.stub!(:random_create).and_return("aaaaaaaa-xxxx-xxxx-xxxx-xxxxxxxxxxx")
- @rest.should_receive(:put_rest).with("chef/aaaaaaaa-xxxx-xxxx-xxxx-xxxxxxxxxxx", item_to_store).and_return(true)
- @couchdb.store("node", "bob", item_to_store)
- end
-
- end
-
- describe "when fetching the database status" do
- it "gets couchdb's version string'" do
- @rest.should_receive(:get_rest).with('/').and_return({"couchdb" => "Welcome","version" => "1.0.1"})
- @couchdb.server_stats.should == {"couchdb" => "Welcome","version" => "1.0.1"}
- end
-
- it "gets database stats" do
- db_stats = {"db_name" => "opscode_account","doc_count" => 206,"doc_del_count" => 1,"update_seq" => 208,"purge_seq" => 0,
- "compact_running" => false,"disk_size" => 122969,"instance_start_time" => "1298070021394804","disk_format_version" => 5,"committed_update_seq" => 208}
- @rest.should_receive(:get_rest).with('/chef').and_return(db_stats)
- @couchdb.db_stats.should == db_stats
- end
-
- end
-
- describe "load" do
- before(:each) do
- @mock_node = Chef::Node.new()
- @mock_node.name("bob")
- @couchdb.stub!(:find_by_name).with("node", "bob").and_return(@mock_node)
- end
-
- it "should load the object from couchdb" do
- @couchdb.load("node", "bob").should eql(@mock_node)
- end
- end
-
- describe "delete" do
- before(:each) do
- @mock_current = {
- "version" => 1,
- "_rev" => 1
- }
- @rest.stub!(:get_rest).and_return(@mock_current)
- @rest.stub!(:delete_rest).and_return(true)
- @node = Chef::Node.new()
- @node.name("bob")
- @node.couchdb_rev = 15
- @couchdb.stub!(:find_by_name).with("node", "bob", true).and_return([ @node, "ax" ])
- end
-
- def do_delete(rev=nil)
- @couchdb.delete("node", "bob", rev)
- end
-
- it "should remove the object from couchdb with a specific revision" do
- @node.should_receive(:delete_from_index)
- @rest.should_receive(:delete_rest).with("chef/ax?rev=1")
- do_delete(1)
- end
-
- it "should remove the object from couchdb based on the couchdb_rev of the current obj" do
- @node.should_receive(:delete_from_index)
- @rest.should_receive(:delete_rest).with("chef/ax?rev=15")
- do_delete
- end
- end
-
- describe "list" do
- before(:each) do
- Chef::Config.stub!(:[]).with(:couchdb_database).and_return("chef")
- @mock_response = {"rows" => []}
- end
-
- describe "on couchdb 0.9+" do
- before do
- Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.9)
- end
-
- it "should get the view for all objects if inflate is true" do
- @rest.should_receive(:get_rest).with("chef/_design/node/_view/all").and_return(@mock_response)
- @couchdb.list("node", true)
- end
-
- it "should get the view for just the object id's if inflate is false" do
- @rest.should_receive(:get_rest).with("chef/_design/node/_view/all_id").and_return(@mock_response)
- @couchdb.list("node", false)
- end
- end
- end
-
- describe "has_key?" do
- it "should return true if the object exists" do
- @couchdb.stub!(:find_by_name).with("node", "bob").and_return(true)
- @couchdb.has_key?("node", "bob").should eql(true)
- end
-
- it "should return false if the object does not exist" do
- @couchdb.stub!(:find_by_name).and_raise(Chef::Exceptions::CouchDBNotFound)
- @couchdb.has_key?("node", "bob").should eql(false)
- end
- end
-
- describe "get_view" do
- it "should construct a call to the view for the proper design document" do
- @rest.should_receive(:get_rest).with("chef/_design/nodes/_view/mastodon")
- @couchdb.get_view("nodes", "mastodon")
- end
-
- it "should allow arguments to the view" do
- @rest.should_receive(:get_rest).with("chef/_design/nodes/_view/mastodon?startkey=%22dont%20stay%22")
- @couchdb.get_view("nodes", "mastodon", :startkey => "dont stay")
- end
-
- end
-
- describe "view_uri" do
- it "should output an appropriately formed view URI" do
- @couchdb.should_receive(:view_uri).with("nodes", "all").and_return("chef/_design/nodes/_view/all")
- @couchdb.view_uri("nodes", "all")
- end
- end
-
-end
-
-
-
-
diff --git a/chef/spec/unit/environment_spec.rb b/chef/spec/unit/environment_spec.rb
index 7b0a835e8c..97f0c3395e 100644
--- a/chef/spec/unit/environment_spec.rb
+++ b/chef/spec/unit/environment_spec.rb
@@ -235,107 +235,6 @@ describe Chef::Environment do
end
end
- describe "when listing the available cookbooks filtered by policy" do
- before(:each) do
- @environment.name "prod"
- @environment.cookbook_versions({
- "apt" => "= 1.0.0",
- "apache2" => "= 2.0.0"
- })
- Chef::Environment.stub!(:cdb_load).and_return @environment
-
- @all_cookbooks = []
- @all_cookbooks << begin
- cv = Chef::CookbookVersion.new("apt")
- cv.version = "1.0.0"
- cv.recipe_filenames = ["default.rb", "only-in-1-0.rb"]
- cv
- end
- @all_cookbooks << begin
- cv = Chef::CookbookVersion.new("apt")
- cv.version = "1.1.0"
- cv.recipe_filenames = ["default.rb", "only-in-1-1.rb"]
- cv
- end
- @all_cookbooks << begin
- cv = Chef::CookbookVersion.new("apache2")
- cv.version = "2.0.0"
- cv.recipe_filenames = ["default.rb", "mod_ssl.rb"]
- cv
- end
- @all_cookbooks << begin
- cv = Chef::CookbookVersion.new("god")
- cv.version = "4.2.0"
- cv.recipe_filenames = ["default.rb"]
- cv
- end
- Chef::CookbookVersion.stub!(:cdb_list).and_return @all_cookbooks
- end
-
- it "should load the environment" do
- Chef::Environment.should_receive(:cdb_load).with("prod", nil)
- Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- end
-
- it "should handle cookbooks with no available version" do
- @environment.cookbook_versions({
- "apt" => "> 999.0.0",
- "apache2" => "= 2.0.0"
- })
- Chef::Environment.should_receive(:cdb_load).with("prod", nil)
- recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod")
- # order doesn't matter
- recipes.should =~ ["god", "apache2", "apache2::mod_ssl"]
- end
-
-
- it "should load all the cookbook versions" do
- Chef::CookbookVersion.should_receive(:cdb_list)
- Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod")
- recipes.should =~ ["apache2", "apache2::mod_ssl", "apt",
- "apt::only-in-1-0", "god"]
- end
-
- it "should load all the cookbook versions with no policy" do
- @environment.cookbook_versions({})
- Chef::CookbookVersion.should_receive(:cdb_list)
- Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod")
- recipes.should =~ ["apache2", "apache2::mod_ssl", "apt",
- "apt::only-in-1-1", "god"]
- end
-
- it "should restrict the cookbook versions, as specified in the environment" do
- res = Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- res["apt"].detect {|cb| cb.version == "1.0.0"}.should_not == nil
- res["apache2"].detect {|cb| cb.version == "2.0.0"}.should_not == nil
- res["god"].detect {|cb| cb.version == "4.2.0"}.should_not == nil
- end
-
- it "should produce correct results, regardless of the cookbook order in couch" do
- # a bug present before the environments feature defaulted to the last CookbookVersion
- # object for a cookbook as returned from couchdb when fetching cookbooks for a node
- # this is a regression test
- @all_cookbooks << begin
- cv = Chef::CookbookVersion.new("god")
- cv.version = "0.0.1"
- cv
- end
- res = Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- res["apt"].detect {|cb| cb.version == "1.0.0"}.should_not == nil
- res["apache2"].detect {|cb| cb.version == "2.0.0"}.should_not == nil
- res["god"].detect {|cb| cb.version == "4.2.0"}.should_not == nil
- end
-
- it "should return all versions of a cookbook that meet the version requirement" do
- @environment.cookbook "apt", ">= 1.0.0"
- res = Chef::Environment.cdb_load_filtered_cookbook_versions("prod")
- res["apt"].detect {|cb| cb.version == "1.0.0"}.should_not == nil
- res["apt"].detect {|cb| cb.version == "1.1.0"}.should_not == nil
- end
- end
-
describe "self.validate_cookbook_versions" do
before(:each) do
@cookbook_versions = {
@@ -376,35 +275,6 @@ describe Chef::Environment do
end
end
- describe "self.create_default_environment" do
- it "should check if the '_default' environment exists" do
- @couchdb = Chef::CouchDB.new
- Chef::CouchDB.stub!(:new).and_return @couchdb
- Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new)
- Chef::Environment.create_default_environment
- end
-
- it "should not re-create the environment if it exists" do
- @couchdb = Chef::CouchDB.new
- Chef::CouchDB.stub!(:new).and_return @couchdb
- Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new).and_return true
- Chef::Environment.should_not_receive(:new)
- Chef::Environment.create_default_environment
- end
-
- it "should create the environment if it doesn't exist" do
- @env = Chef::Environment.new
- @env.stub!(:cdb_save).and_return true
- @couchdb = Chef::CouchDB.new
- Chef::Environment.stub!(:new).and_return @env
- Chef::CouchDB.stub!(:new).and_return @couchdb
-
- Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new).and_raise(Chef::Exceptions::CouchDBNotFound)
- Chef::Environment.should_receive(:new)
- Chef::Environment.create_default_environment
- end
- end
-
describe "when updating from a parameter hash" do
before do
@environment = Chef::Environment.new
diff --git a/chef/spec/unit/exceptions_spec.rb b/chef/spec/unit/exceptions_spec.rb
index fe920fd817..a979d2f6b9 100644
--- a/chef/spec/unit/exceptions_spec.rb
+++ b/chef/spec/unit/exceptions_spec.rb
@@ -8,9 +8,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,7 +40,6 @@ describe Chef::Exceptions do
Chef::Exceptions::Group => RuntimeError,
Chef::Exceptions::Link => RuntimeError,
Chef::Exceptions::Mount => RuntimeError,
- Chef::Exceptions::CouchDBNotFound => RuntimeError,
Chef::Exceptions::PrivateKeyMissing => RuntimeError,
Chef::Exceptions::CannotWritePrivateKey => RuntimeError,
Chef::Exceptions::RoleNotFound => RuntimeError,
diff --git a/chef/spec/unit/knife/ssh_spec.rb b/chef/spec/unit/knife/ssh_spec.rb
index a4853e11cc..6e90a87f01 100644
--- a/chef/spec/unit/knife/ssh_spec.rb
+++ b/chef/spec/unit/knife/ssh_spec.rb
@@ -36,10 +36,10 @@ describe Chef::Knife::Ssh do
@knife = Chef::Knife::Ssh.new
@knife.config.clear
@knife.config[:attribute] = "fqdn"
- @node_foo = Chef::Node.new('foo')
+ @node_foo = Chef::Node.new
@node_foo.automatic_attrs[:fqdn] = "foo.example.org"
@node_foo.automatic_attrs[:ipaddress] = "10.0.0.1"
- @node_bar = Chef::Node.new('bar')
+ @node_bar = Chef::Node.new
@node_bar.automatic_attrs[:fqdn] = "bar.example.org"
@node_bar.automatic_attrs[:ipaddress] = "10.0.0.2"
end
@@ -64,7 +64,7 @@ describe Chef::Knife::Ssh do
@knife.should_receive(:session_from_list).with(['10.0.0.1', '10.0.0.2'])
@knife.configure_session
end
-
+
it "returns an array of the attributes specified on the command line even when a config value is set" do
@knife.config[:attribute] = "config_file" # this value will be the config file
@knife.config[:override_attribute] = "ipaddress" # this is the value of the command line via #configure_attribute
diff --git a/chef/spec/unit/lwrp_spec.rb b/chef/spec/unit/lwrp_spec.rb
index 76834cf182..da2278e547 100644
--- a/chef/spec/unit/lwrp_spec.rb
+++ b/chef/spec/unit/lwrp_spec.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -94,7 +94,7 @@ describe "LWRP" do
end
it "should have access to the run context and node during class definition" do
- node = Chef::Node.new(nil)
+ node = Chef::Node.new
node.normal[:penguin_name] = "jackass"
run_context = Chef::RunContext.new(node, Chef::CookbookCollection.new, @events)
diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb
index 4577d5098b..b6f63c9651 100644
--- a/chef/spec/unit/node_spec.rb
+++ b/chef/spec/unit/node_spec.rb
@@ -681,80 +681,4 @@ describe Chef::Node do
end
end
- describe "acting as a CouchDB-backed model" do
- before(:each) do
- @couchdb = Chef::CouchDB.new
- @mock_couch = mock('couch mock')
- end
-
- describe "list" do
- before(:each) do
- @mock_couch.stub!(:list).and_return(
- { "rows" => [ { "value" => "a", "key" => "avenue" } ] }
- )
- Chef::CouchDB.stub!(:new).and_return(@mock_couch)
- end
-
- it "should retrieve a list of nodes from CouchDB" do
- Chef::Node.cdb_list.should eql(["avenue"])
- end
-
- it "should return just the ids if inflate is false" do
- Chef::Node.cdb_list(false).should eql(["avenue"])
- end
-
- it "should return the full objects if inflate is true" do
- Chef::Node.cdb_list(true).should eql(["a"])
- end
- end
-
- describe "when loading a given node" do
- it "should load a node from couchdb by name" do
- @couchdb.should_receive(:load).with("node", "coffee").and_return(true)
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
- Chef::Node.cdb_load("coffee")
- end
- end
-
- describe "when destroying a Node" do
- it "should delete this node from couchdb" do
- @couchdb.should_receive(:delete).with("node", "bob", 1).and_return(true)
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
- node = Chef::Node.new
- node.name "bob"
- node.couchdb_rev = 1
- node.cdb_destroy
- end
- end
-
- describe "when saving a Node" do
- before(:each) do
- @couchdb.stub!(:store).and_return({ "rev" => 33 })
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
- @node = Chef::Node.new
- @node.name "bob"
- @node.couchdb_rev = 1
- end
-
- it "should save the node to couchdb" do
- @couchdb.should_receive(:store).with("node", "bob", @node).and_return({ "rev" => 33 })
- @node.cdb_save
- end
-
- it "should store the new couchdb_rev" do
- @node.cdb_save
- @node.couchdb_rev.should eql(33)
- end
- end
-
- describe "create_design_document" do
- it "should create our design document" do
- @couchdb.should_receive(:create_design_document).with("nodes", Chef::Node::DESIGN_DOCUMENT)
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
- Chef::Node.create_design_document
- end
- end
-
- end
-
end
diff --git a/chef/spec/unit/provider/ohai_spec.rb b/chef/spec/unit/provider/ohai_spec.rb
index c86ad288eb..8402c92e97 100644
--- a/chef/spec/unit/provider/ohai_spec.rb
+++ b/chef/spec/unit/provider/ohai_spec.rb
@@ -34,7 +34,7 @@ describe Chef::Provider::Ohai do
:platform => @platform,
:platform_version => @platform_version,
:data => {
- :origdata => "somevalue"
+ :origdata => "somevalue"
},
:data2 => {
:origdata => "somevalue",
@@ -49,7 +49,7 @@ describe Chef::Provider::Ohai do
Chef::Platform.stub!(:find_platform_and_version).and_return({ "platform" => @platform,
"platform_version" => @platform_version})
# Fake node with a dummy save
- @node = Chef::Node.new(@hostname)
+ @node = Chef::Node.new
@node.name(@fqdn)
@node.stub!(:save).and_return(@node)
@events = Chef::EventDispatch::Dispatcher.new
diff --git a/chef/spec/unit/run_list_spec.rb b/chef/spec/unit/run_list_spec.rb
index e51ced588a..f18f21a82b 100644
--- a/chef/spec/unit/run_list_spec.rb
+++ b/chef/spec/unit/run_list_spec.rb
@@ -248,13 +248,6 @@ describe Chef::RunList do
end
- describe "from couchdb" do
- it "should load the role from couchdb" do
- Chef::Role.should_receive(:cdb_load).and_return(@role)
- @run_list.expand("_default", "couchdb")
- end
- end
-
it "should return the list of expanded recipes" do
expansion = @run_list.expand("_default")
expansion.recipes[0].should == "one"