diff options
author | Seth Chisamore <schisamo@opscode.com> | 2012-10-29 16:44:22 -0400 |
---|---|---|
committer | Seth Chisamore <schisamo@opscode.com> | 2012-10-30 09:47:38 -0400 |
commit | 912c453607bb90cc370fc6e2463c45bb6e85435e (patch) | |
tree | 6f8442ee932cbb3d0110d9af8830102fc0058ee6 | |
parent | 76fe50c1cb06898322aee548e4e962d36e864702 (diff) | |
download | chef-912c453607bb90cc370fc6e2463c45bb6e85435e.tar.gz |
[OC-3564] remove Chef::CheckSum and Chef::Sandbox
These classes were only used by Chef server components and have been
succeeded by Erchef.
-rw-r--r-- | chef/lib/chef/checksum.rb | 167 | ||||
-rw-r--r-- | chef/lib/chef/cookbook_uploader.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/cookbook_version.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/sandbox.rb | 152 | ||||
-rw-r--r-- | chef/spec/unit/checksum_spec.rb | 94 |
5 files changed, 0 insertions, 415 deletions
diff --git a/chef/lib/chef/checksum.rb b/chef/lib/chef/checksum.rb deleted file mode 100644 index fc1931174b..0000000000 --- a/chef/lib/chef/checksum.rb +++ /dev/null @@ -1,167 +0,0 @@ -# -# Author:: Tim Hinderliter (<tim@opscode.com>) -# Copyright:: Copyright (c) 2010 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/log' -require 'chef/checksum/storage' -require 'uuidtools' - -class Chef - # == Chef::Checksum - # Checksum for an individual file; e.g., used for sandbox/cookbook uploading - # to track which files the system already manages. - class Checksum - attr_accessor :checksum, :create_time - attr_accessor :couchdb_id, :couchdb_rev - - attr_reader :storage - - # When a Checksum commits a sandboxed file to its final home in the checksum - # repo, this attribute will have the original on-disk path where the file - # was stored; it will be used if the commit is reverted to restore the sandbox - # to the pre-commit state. - attr_reader :original_committed_file_location - - DESIGN_DOCUMENT = { - "version" => 1, - "language" => "javascript", - "views" => { - "all" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "checksum") { - emit(doc.checksum, doc); - } - } - EOJS - }, - } - } - - # Creates a new Chef::Checksum object. - # === Arguments - # checksum::: the MD5 content hash of the file - # couchdb::: An instance of Chef::CouchDB - # - # === Returns - # object<Chef::Checksum>:: Duh. :) - def initialize(checksum=nil, couchdb=nil) - @create_time = Time.now.iso8601 - @checksum = checksum - @original_committed_file_location = nil - @storage = Storage::Filesystem.new(Chef::Config.checksum_path, checksum) - end - - def to_json(*a) - result = { - :checksum => checksum, - :create_time => create_time, - :json_class => self.class.name, - :chef_type => 'checksum', - - # For Chef::CouchDB (id_to_name, name_to_id) - :name => checksum - } - result.to_json(*a) - end - - def self.json_create(o) - checksum = new(o['checksum']) - checksum.create_time = o['create_time'] - - if o.has_key?('_rev') - checksum.couchdb_rev = o["_rev"] - o.delete("_rev") - end - if o.has_key?("_id") - checksum.couchdb_id = o["_id"] - o.delete("_id") - end - checksum - end - - # Moves the given +sandbox_file+ into the checksum repo using the path - # given by +file_location+ and saves the Checksum to the database - def commit_sandbox_file(sandbox_file) - @original_committed_file_location = sandbox_file - Chef::Log.info("Commiting sandbox file: move #{sandbox_file} to #{@storage}") - @storage.commit(sandbox_file) - cdb_save - end - - # Moves the checksum file back to its pre-commit location and deletes - # the checksum object from the database, effectively undoing +commit_sandbox_file+. - # Raises Chef::Exceptions::IllegalChecksumRevert if the original file location - # is unknown, which is will be the case if commit_sandbox_file was not - # previously called - def revert_sandbox_file_commit - unless original_committed_file_location - raise Chef::Exceptions::IllegalChecksumRevert, "Checksum #{self.inspect} cannot be reverted because the original sandbox file location is not known" - end - - Chef::Log.warn("Reverting sandbox file commit: moving #{@storage} back to #{original_committed_file_location}") - @storage.revert(original_committed_file_location) - cdb_destroy - end - - # Removes the on-disk file backing this checksum object, then removes it - # from the database - def purge - purge_file - cdb_destroy - end - - ## - # Couchdb - ## - - def self.create_design_document(couchdb=nil) - (couchdb || Chef::CouchDB.new).create_design_document("checksums", DESIGN_DOCUMENT) - end - - def self.cdb_list(inflate=false, couchdb=nil) - rs = (couchdb || Chef::CouchDB.new).list("checksums", inflate) - lookup = (inflate ? "value" : "key") - rs["rows"].collect { |r| r[lookup] } - end - - def self.cdb_all_checksums(couchdb = nil) - rs = (couchdb || Chef::CouchDB.new).list("checksums", true) - rs["rows"].inject({}) { |hash_result, r| hash_result[r['key']] = 1; hash_result } - end - - def self.cdb_load(checksum, couchdb=nil) - # Probably want to look for a view here at some point - (couchdb || Chef::CouchDB.new).load("checksum", checksum) - end - - def cdb_destroy(couchdb=nil) - (couchdb || Chef::CouchDB.new).delete("checksum", checksum, @couchdb_rev) - end - - def cdb_save(couchdb=nil) - @couchdb_rev = (couchdb || Chef::CouchDB.new).store("checksum", checksum, self)["rev"] - end - - - private - - def purge_file - @storage.purge - end - - end -end diff --git a/chef/lib/chef/cookbook_uploader.rb b/chef/lib/chef/cookbook_uploader.rb index 351a239bb8..8dd50ac043 100644 --- a/chef/lib/chef/cookbook_uploader.rb +++ b/chef/lib/chef/cookbook_uploader.rb @@ -4,7 +4,6 @@ require 'rest_client' require 'chef/exceptions' require 'chef/knife/cookbook_metadata' require 'chef/checksum_cache' -require 'chef/sandbox' require 'chef/cookbook_version' require 'chef/cookbook/syntax_check' require 'chef/cookbook/file_system_file_vendor' diff --git a/chef/lib/chef/cookbook_version.rb b/chef/lib/chef/cookbook_version.rb index d87de04380..24f2c546f0 100644 --- a/chef/lib/chef/cookbook_version.rb +++ b/chef/lib/chef/cookbook_version.rb @@ -24,7 +24,6 @@ require 'chef/node' require 'chef/resource_definition_list' require 'chef/recipe' require 'chef/cookbook/file_vendor' -require 'chef/checksum' require 'chef/cookbook/metadata' require 'chef/version_class' diff --git a/chef/lib/chef/sandbox.rb b/chef/lib/chef/sandbox.rb deleted file mode 100644 index 9522594c20..0000000000 --- a/chef/lib/chef/sandbox.rb +++ /dev/null @@ -1,152 +0,0 @@ -# -# Author:: Tim Hinderliter (<tim@opscode.com>) -# Copyright:: Copyright (c) 2010 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/log' -require 'uuidtools' - -class Chef - class Sandbox - attr_accessor :is_completed, :create_time - alias_method :is_completed?, :is_completed - attr_reader :guid - - alias :name :guid - - attr_accessor :couchdb, :couchdb_id, :couchdb_rev - - # list of checksum ids - attr_accessor :checksums - - DESIGN_DOCUMENT = { - "version" => 1, - "language" => "javascript", - "views" => { - "all" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "sandbox") { - emit(doc.guid, doc); - } - } - EOJS - }, - "all_id" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "sandbox") { - emit(doc.guid, doc.guid); - } - } - EOJS - }, - "all_incomplete" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "sandbox" && !doc.is_completed) { - emit(doc.guid, doc.guid); - } - } - EOJS - }, - "all_completed" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "sandbox" && doc.is_completed) { - emit(doc.guid, doc.guid); - } - } - EOJS - }, - } - } - - # Creates a new Chef::Sandbox object. - # - # === Returns - # object<Chef::Sandbox>:: Duh. :) - def initialize(guid=nil, couchdb=nil) - @guid = guid || UUIDTools::UUID.random_create.to_s.gsub(/\-/,'').downcase - @is_completed = false - @create_time = Time.now.iso8601 - @checksums = Array.new - end - - def include?(checksum) - @checksums.include?(checksum) - end - - alias :member? :include? - - def to_json(*a) - result = { - :guid => guid, - :name => name, # same as guid, used for id_map - :checksums => checksums, - :create_time => create_time, - :is_completed => is_completed, - :json_class => self.class.name, - :chef_type => 'sandbox' - } - result["_rev"] = @couchdb_rev if @couchdb_rev - result.to_json(*a) - end - - def self.json_create(o) - sandbox = new(o['guid']) - sandbox.checksums = o['checksums'] - sandbox.create_time = o['create_time'] - sandbox.is_completed = o['is_completed'] - if o.has_key?('_rev') - sandbox.couchdb_rev = o["_rev"] - o.delete("_rev") - end - if o.has_key?("_id") - sandbox.couchdb_id = o["_id"] - o.delete("_id") - end - sandbox - end - - ## - # Couchdb - ## - - def self.create_design_document(couchdb=nil) - (couchdb || Chef::CouchDB.new).create_design_document("sandboxes", DESIGN_DOCUMENT) - end - - def self.cdb_list(inflate=false, couchdb=nil) - rs = (couchdb || Chef::CouchDB.new).list("sandboxes", inflate) - lookup = (inflate ? "value" : "key") - rs["rows"].collect { |r| r[lookup] } - end - - def self.cdb_load(guid, couchdb=nil) - # Probably want to look for a view here at some point - (couchdb || Chef::CouchDB.new).load("sandbox", guid) - end - - def cdb_destroy - (couchdb || Chef::CouchDB.new).delete("sandbox", guid, @couchdb_rev) - end - - def cdb_save(couchdb=nil) - @couchdb_rev = (couchdb || Chef::CouchDB.new).store("sandbox", guid, self)["rev"] - end - - end -end diff --git a/chef/spec/unit/checksum_spec.rb b/chef/spec/unit/checksum_spec.rb deleted file mode 100644 index aad559cf3d..0000000000 --- a/chef/spec/unit/checksum_spec.rb +++ /dev/null @@ -1,94 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@opscode.com>) -# Copyright:: Copyright (c) 2010 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' -require 'chef/checksum' - -describe Chef::Checksum do - - before do - Chef::Log.logger = Logger.new(StringIO.new) - - @now = Time.now - - Time.stub!(:now).and_return(@now) - - @checksum_of_the_file = "3fafecfb15585ede6b840158cbc2f399" - @checksum = Chef::Checksum.new(@checksum_of_the_file) - end - - it "has no original committed file location" do - @checksum.original_committed_file_location.should be_nil - end - - it "has the MD5 checksum of the file it represents" do - @checksum.checksum.should == @checksum_of_the_file - end - - it "stores the time it was created" do - @checksum.create_time.should == @now.iso8601 - end - - it "commits a sandbox file from a given location to the checksum repo location" do - @checksum.storage.should_receive(:commit).with("/tmp/arbitrary_file_location") - @checksum.should_receive(:cdb_save) - @checksum.commit_sandbox_file("/tmp/arbitrary_file_location") - @checksum.original_committed_file_location.should == "/tmp/arbitrary_file_location" - end - - it "reverts committing a sandbox file" do - @checksum.storage.should_receive(:commit).with("/tmp/arbitrary_file_location") - @checksum.should_receive(:cdb_save) - @checksum.commit_sandbox_file("/tmp/arbitrary_file_location") - @checksum.original_committed_file_location.should == "/tmp/arbitrary_file_location" - - @checksum.storage.should_receive(:revert).with("/tmp/arbitrary_file_location") - @checksum.should_receive(:cdb_destroy) - @checksum.revert_sandbox_file_commit - end - - it "raises an error when trying to revert a checksum that was not previously committed" do - lambda {@checksum.revert_sandbox_file_commit}.should raise_error(Chef::Exceptions::IllegalChecksumRevert) - end - - it "deletes the file and its document from couchdb" do - @checksum.should_receive(:cdb_destroy) - @checksum.storage.should_receive(:purge) - @checksum.purge - end - - describe "when converted to json" do - before do - @checksum_as_json = @checksum.to_json - @checksum_as_hash_from_json = Chef::JSONCompat.from_json(@checksum_as_json, :create_additions => false) - end - - it "contains the file's MD5 checksum" do - @checksum_as_hash_from_json["checksum"].should == @checksum_of_the_file - end - - it "contains the creation time" do - @checksum_as_hash_from_json["create_time"].should == @now.iso8601 - end - - it "uses the file's MD5 checksum for its 'name' property" do - @checksum_as_hash_from_json["name"].should == @checksum_of_the_file - end - end - -end |