knife-cloud 1.2.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/lib/chef/knife/cloud/chefbootstrap/bootstrap_distribution.rb +2 -2
- data/lib/chef/knife/cloud/chefbootstrap/bootstrap_options.rb +115 -133
- data/lib/chef/knife/cloud/chefbootstrap/bootstrap_protocol.rb +6 -6
- data/lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb +11 -12
- data/lib/chef/knife/cloud/chefbootstrap/ssh_bootstrap_protocol.rb +49 -54
- data/lib/chef/knife/cloud/chefbootstrap/unix_distribution.rb +3 -3
- data/lib/chef/knife/cloud/chefbootstrap/windows_distribution.rb +3 -3
- data/lib/chef/knife/cloud/chefbootstrap/winrm_bootstrap_protocol.rb +11 -12
- data/lib/chef/knife/cloud/command.rb +24 -27
- data/lib/chef/knife/cloud/exceptions.rb +1 -2
- data/lib/chef/knife/cloud/fog/options.rb +8 -8
- data/lib/chef/knife/cloud/fog/service.rb +54 -60
- data/lib/chef/knife/cloud/helpers.rb +2 -3
- data/lib/chef/knife/cloud/list_resource_command.rb +6 -7
- data/lib/chef/knife/cloud/list_resource_options.rb +5 -5
- data/lib/chef/knife/cloud/server/create_command.rb +30 -35
- data/lib/chef/knife/cloud/server/create_options.rb +33 -34
- data/lib/chef/knife/cloud/server/delete_command.rb +12 -15
- data/lib/chef/knife/cloud/server/delete_options.rb +7 -8
- data/lib/chef/knife/cloud/server/list_command.rb +22 -22
- data/lib/chef/knife/cloud/server/list_options.rb +9 -10
- data/lib/chef/knife/cloud/server/options.rb +7 -7
- data/lib/chef/knife/cloud/server/show_command.rb +5 -5
- data/lib/chef/knife/cloud/server/show_options.rb +5 -6
- data/lib/chef/knife/cloud/service.rb +12 -13
- data/lib/knife-cloud/version.rb +2 -2
- data/lib/test/fixtures/knife.rb +3 -3
- data/lib/test/fixtures/validation.pem +27 -0
- data/lib/test/knife-utils/helper.rb +11 -11
- data/lib/test/knife-utils/knife_test_utils.rb +4 -4
- data/lib/test/knife-utils/matchers.rb +3 -3
- data/lib/test/knife-utils/test_bed.rb +38 -38
- data/lib/test/templates/windows-chef-client-msi.erb +3 -4
- data/lib/test/templates/windows-shell.erb +2 -2
- metadata +12 -152
- data/.gitignore +0 -33
- data/.travis.yml +0 -6
- data/CHANGELOG.md +0 -133
- data/CONTRIBUTING.md +0 -5
- data/Gemfile +0 -9
- data/README.md +0 -421
- data/Rakefile +0 -35
- data/ci.gemfile +0 -18
- data/knife-cloud.gemspec +0 -26
- data/spec/resource_spec_helper.rb +0 -49
- data/spec/server_command_common_spec_helper.rb +0 -48
- data/spec/spec_helper.rb +0 -25
- data/spec/support/shared_examples_for_command.rb +0 -35
- data/spec/support/shared_examples_for_servercreatecommand.rb +0 -144
- data/spec/support/shared_examples_for_serverdeletecommand.rb +0 -77
- data/spec/support/shared_examples_for_service.rb +0 -85
- data/spec/unit/bootstrap_protocol_spec.rb +0 -98
- data/spec/unit/bootstrapper_spec.rb +0 -171
- data/spec/unit/cloud_command_spec.rb +0 -35
- data/spec/unit/command_spec.rb +0 -49
- data/spec/unit/fog_service_spec.rb +0 -163
- data/spec/unit/list_resource_command_spec.rb +0 -140
- data/spec/unit/server_create_command_spec.rb +0 -198
- data/spec/unit/server_delete_command_spec.rb +0 -25
- data/spec/unit/server_list_command_spec.rb +0 -119
- data/spec/unit/server_show_command_spec.rb +0 -64
- data/spec/unit/service_spec.rb +0 -46
- data/spec/unit/ssh_bootstrap_protocol_spec.rb +0 -116
- data/spec/unit/unix_distribution_spec.rb +0 -37
- data/spec/unit/windows_distribution_spec.rb +0 -37
- data/spec/unit/winrm_bootstrap_protocol_spec.rb +0 -108
data/Rakefile
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
|
2
|
-
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
3
|
-
|
4
|
-
require 'bundler'
|
5
|
-
Bundler::GemHelper.install_tasks
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubygems/package_task'
|
9
|
-
|
10
|
-
task default: :all
|
11
|
-
task all: [:spec, :uninstall, :install]
|
12
|
-
|
13
|
-
# Packaging
|
14
|
-
GEM_NAME = 'knife-cloud'.freeze
|
15
|
-
require File.dirname(__FILE__) + '/lib/knife-cloud/version'
|
16
|
-
spec = eval(File.read('knife-cloud.gemspec'))
|
17
|
-
Gem::PackageTask.new(spec) do |pkg|
|
18
|
-
pkg.gem_spec = spec
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "uninstall #{GEM_NAME}-#{Knife::Cloud::VERSION}.gem from system..."
|
22
|
-
task :uninstall do
|
23
|
-
sh %(gem uninstall #{GEM_NAME} -x -v #{Knife::Cloud::VERSION} )
|
24
|
-
end
|
25
|
-
|
26
|
-
# rspec
|
27
|
-
begin
|
28
|
-
require 'rspec/core/rake_task'
|
29
|
-
desc 'Run all specs in spec directory'
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
31
|
-
t.pattern = 'spec/unit/**/*_spec.rb'
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
|
35
|
-
end
|
data/ci.gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in knife-cloud.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
if ENV['CHEF_VERSION'] == 'master'
|
7
|
-
gem 'chef', github: 'chef/chef'
|
8
|
-
elsif ENV['CHEF_VERSION'] == '< 12'
|
9
|
-
gem 'ohai', '7.4.1'
|
10
|
-
gem 'chef', ENV['CHEF_VERSION']
|
11
|
-
else
|
12
|
-
gem 'chef', ENV['CHEF_VERSION']
|
13
|
-
end
|
14
|
-
|
15
|
-
group :development do
|
16
|
-
gem 'rake'
|
17
|
-
gem 'knife-windows'
|
18
|
-
end
|
data/knife-cloud.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
-
require 'knife-cloud/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = 'knife-cloud'
|
7
|
-
s.version = Knife::Cloud::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
10
|
-
s.authors = ['Kaustubh Deorukhkar', 'Ameya Varade']
|
11
|
-
s.email = ['dev@chef.io']
|
12
|
-
s.homepage = 'https://github.com/chef/knife-cloud'
|
13
|
-
s.summary = 'knife-cloud plugin'
|
14
|
-
s.description = s.summary
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
-
s.require_paths = %w(lib spec)
|
20
|
-
|
21
|
-
s.add_dependency 'knife-windows', '>= 0.5.14'
|
22
|
-
s.add_dependency 'chef', '>= 0.10.10'
|
23
|
-
s.add_dependency 'mixlib-shellout'
|
24
|
-
|
25
|
-
%w(rspec-core rspec-expectations rspec-mocks rspec_junit_formatter fog rubocop).each { |gem| s.add_development_dependency gem }
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
3
|
-
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
19
|
-
require 'json'
|
20
|
-
|
21
|
-
# Creates a resource class that can dynamically add attributes to
|
22
|
-
# instances and set the values
|
23
|
-
module JSONModule
|
24
|
-
def to_json
|
25
|
-
hash = {}
|
26
|
-
self.instance_variables.each do |var|
|
27
|
-
hash[var] = self.instance_variable_get var
|
28
|
-
end
|
29
|
-
hash.to_json
|
30
|
-
end
|
31
|
-
def from_json! string
|
32
|
-
JSON.load(string).each do |var, val|
|
33
|
-
self.instance_variable_set var, val
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class TestResource
|
39
|
-
include JSONModule
|
40
|
-
def initialize(*args)
|
41
|
-
args.each do |arg|
|
42
|
-
arg.each do |key, value|
|
43
|
-
add_attribute = "class << self; attr_accessor :#{key}; end"
|
44
|
-
eval(add_attribute)
|
45
|
-
eval("@#{key} = value")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
3
|
-
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
19
|
-
|
20
|
-
# Common helper methods used accrossed knife plugin during Integration testing.
|
21
|
-
#
|
22
|
-
# run_cmd_check_status_and_output: It checks knife plugin command exitstatus(i.e '0' = succeed and '1' = fails)
|
23
|
-
# and also checks command output(i.e stdout or stderr)
|
24
|
-
#
|
25
|
-
# run_cmd_check_stdout: It checks commands stdout.
|
26
|
-
#
|
27
|
-
# server_create_common_bfr_aftr: Its contains common before and after blocks used for server create
|
28
|
-
|
29
|
-
def run_cmd_check_status_and_output(expected_status = "succeed", expected_result = nil)
|
30
|
-
it do
|
31
|
-
match_status("should #{expected_status}")
|
32
|
-
expect(cmd_output).to include(expected_result) if expected_result
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def run_cmd_check_stdout(expected_result)
|
37
|
-
it { match_stdout(/#{expected_result}/) }
|
38
|
-
end
|
39
|
-
|
40
|
-
def server_create_common_bfr_aftr(platform = "linux")
|
41
|
-
before { create_node_name(platform) }
|
42
|
-
after { run(delete_instance_cmd("#{cmd_output}")) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def rm_known_host
|
46
|
-
known_hosts = File.expand_path("~") + "/.ssh/known_hosts"
|
47
|
-
FileUtils.rm_rf(known_hosts)
|
48
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
3
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
4
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
20
|
-
require 'json'
|
21
|
-
require 'chef/knife/cloud/exceptions'
|
22
|
-
require 'chef/exceptions'
|
23
|
-
require 'chef/config'
|
24
|
-
require 'resource_spec_helper'
|
25
|
-
require 'server_command_common_spec_helper'
|
@@ -1,35 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
|
3
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
4
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
require 'chef/knife/cloud/command'
|
20
|
-
require 'chef/knife/cloud/service'
|
21
|
-
|
22
|
-
shared_examples_for Chef::Knife::Cloud::Command do |instance|
|
23
|
-
it "runs with correct method calls" do
|
24
|
-
allow(instance).to receive(:execute_command)
|
25
|
-
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
|
26
|
-
expect(instance).to receive(:set_default_config).ordered
|
27
|
-
expect(instance).to receive(:validate!).ordered
|
28
|
-
expect(instance).to receive(:validate_params!).ordered
|
29
|
-
expect(instance).to receive(:create_service_instance).ordered
|
30
|
-
expect(instance).to receive(:before_exec_command).ordered
|
31
|
-
expect(instance).to receive(:execute_command).ordered
|
32
|
-
expect(instance).to receive(:after_exec_command).ordered
|
33
|
-
instance.run
|
34
|
-
end
|
35
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
|
3
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
4
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
require 'spec_helper'
|
20
|
-
require 'chef/knife/cloud/server/create_command'
|
21
|
-
|
22
|
-
def get_mock_resource(id)
|
23
|
-
obj = Object.new
|
24
|
-
allow(obj).to receive(:id).and_return(id)
|
25
|
-
obj
|
26
|
-
end
|
27
|
-
|
28
|
-
shared_examples_for Chef::Knife::Cloud::ServerCreateCommand do |instance|
|
29
|
-
before do
|
30
|
-
instance.service = double
|
31
|
-
allow(instance.ui).to receive(:fatal)
|
32
|
-
|
33
|
-
allow(instance.service).to receive(:get_image).and_return(get_mock_resource('image_id'))
|
34
|
-
|
35
|
-
allow(instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor_id'))
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#before_exec_command" do
|
39
|
-
it "calls create_server_dependencies" do
|
40
|
-
expect(instance.service).to receive(:create_server_dependencies)
|
41
|
-
instance.before_exec_command
|
42
|
-
end
|
43
|
-
it "delete_server_dependencies on any error" do
|
44
|
-
allow(instance).to receive(:execute_command)
|
45
|
-
allow(instance).to receive(:after_exec_command)
|
46
|
-
allow(instance).to receive(:validate!)
|
47
|
-
allow(instance).to receive(:validate_params!)
|
48
|
-
instance.service = Chef::Knife::Cloud::Service.new
|
49
|
-
allow(instance).to receive(:create_service_instance).and_return(instance.service)
|
50
|
-
allow(instance.service).to receive(:get_image).and_return(get_mock_resource('image_id'))
|
51
|
-
allow(instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor_id'))
|
52
|
-
allow(instance.service).to receive(:create_server_dependencies).and_raise(Chef::Knife::Cloud::CloudExceptions::ServerCreateDependenciesError)
|
53
|
-
expect(instance.service).to receive(:delete_server_dependencies)
|
54
|
-
expect(instance.service).to_not receive(:delete_server_on_failure)
|
55
|
-
expect(instance).to receive(:exit)
|
56
|
-
instance.run
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#execute_command" do
|
61
|
-
it "calls create_server" do
|
62
|
-
expect(instance.service).to receive(:create_server).and_return(true)
|
63
|
-
expect(instance.service).to receive(:server_summary)
|
64
|
-
instance.execute_command
|
65
|
-
end
|
66
|
-
|
67
|
-
it "delete_server_dependencies on any error" do
|
68
|
-
allow(instance).to receive(:before_exec_command)
|
69
|
-
allow(instance).to receive(:after_exec_command)
|
70
|
-
allow(instance).to receive(:validate!)
|
71
|
-
allow(instance).to receive(:validate_params!)
|
72
|
-
instance.service = Chef::Knife::Cloud::Service.new
|
73
|
-
allow(instance).to receive(:create_service_instance).and_return(instance.service)
|
74
|
-
allow(instance.service).to receive(:create_server).and_raise(Chef::Knife::Cloud::CloudExceptions::ServerCreateError)
|
75
|
-
expect(instance.service).to receive(:delete_server_dependencies)
|
76
|
-
expect(instance.service).to_not receive(:delete_server_on_failure)
|
77
|
-
expect(instance).to receive(:exit)
|
78
|
-
instance.run
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#bootstrap" do
|
83
|
-
it "execute with correct method calls" do
|
84
|
-
@bootstrap = Object.new
|
85
|
-
allow(@bootstrap).to receive(:bootstrap)
|
86
|
-
allow(instance.ui).to receive(:info)
|
87
|
-
allow(Chef::Knife::Cloud::Bootstrapper).to receive(:new).and_return(@bootstrap)
|
88
|
-
expect(instance).to receive(:before_bootstrap).ordered
|
89
|
-
expect(instance).to receive(:after_bootstrap).ordered
|
90
|
-
instance.bootstrap
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#after_bootstrap" do
|
95
|
-
it "display server summary" do
|
96
|
-
expect(instance.service).to receive(:server_summary)
|
97
|
-
instance.after_bootstrap
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#get_node_name" do
|
102
|
-
it "auto generates chef_node_name" do
|
103
|
-
instance.config[:bootstrap_protocol] = 'ssh'
|
104
|
-
instance.config[:ssh_password] = 'password'
|
105
|
-
instance.config[:image_os_type] = 'linux'
|
106
|
-
instance.config[:chef_node_name_prefix] = 'os'
|
107
|
-
expect(instance).to receive(:get_node_name).and_call_original
|
108
|
-
instance.validate_params!
|
109
|
-
expect(instance.config[:chef_node_name]).to be =~ /os-*/
|
110
|
-
end
|
111
|
-
|
112
|
-
it "auto generates unique chef_node_name" do
|
113
|
-
node_names = []
|
114
|
-
instance.config[:bootstrap_protocol] = 'ssh'
|
115
|
-
instance.config[:ssh_password] = 'password'
|
116
|
-
instance.config[:image_os_type] = 'linux'
|
117
|
-
instance.config[:chef_node_name_prefix] = 'os'
|
118
|
-
5.times do
|
119
|
-
instance.config[:chef_node_name] = nil
|
120
|
-
instance.validate_params!
|
121
|
-
expect(node_names).to_not include(instance.config[:chef_node_name])
|
122
|
-
node_names.push(instance.config[:chef_node_name])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#cleanup_on_failure" do
|
128
|
-
it "delete server dependencies on delete_server_on_failure set" do
|
129
|
-
instance.config[:delete_server_on_failure] = true
|
130
|
-
instance.service = Chef::Knife::Cloud::Service.new
|
131
|
-
expect(instance.service).to receive(:delete_server_dependencies)
|
132
|
-
expect(instance.service).to receive(:delete_server_on_failure)
|
133
|
-
instance.cleanup_on_failure
|
134
|
-
end
|
135
|
-
|
136
|
-
it "don't delete server dependencies on delete_server_on_failure option is missing" do
|
137
|
-
instance.config[:delete_server_on_failure] = false
|
138
|
-
Chef::Config[:knife].delete(:delete_server_on_failure)
|
139
|
-
expect(instance.service).to_not receive(:delete_server_dependencies)
|
140
|
-
expect(instance.service).to_not receive(:delete_server_on_failure)
|
141
|
-
instance.cleanup_on_failure
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
|
3
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
4
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
require 'chef/knife/cloud/server/delete_command'
|
20
|
-
|
21
|
-
shared_examples_for Chef::Knife::Cloud::ServerDeleteCommand do |instance|
|
22
|
-
describe "#delete_from_chef" do
|
23
|
-
it "expects chef warning message when purge option is disabled" do
|
24
|
-
server_name = "testserver"
|
25
|
-
expect(instance.ui).to receive(:warn).with("Corresponding node and client for the #{server_name} server were not deleted and remain registered with the Chef Server")
|
26
|
-
instance.delete_from_chef(server_name)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "deletes chef node and client when purge option is enabled" do
|
30
|
-
instance.config[:purge] = true
|
31
|
-
server_name = "testserver"
|
32
|
-
expect(instance).to receive(:destroy_item).with(Chef::Node, server_name, "node").ordered
|
33
|
-
expect(instance).to receive(:destroy_item).with(Chef::ApiClient, server_name, "client").ordered
|
34
|
-
instance.delete_from_chef(server_name)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "deletes chef node specified with node-name option overriding the instance server_name" do
|
38
|
-
instance.config[:purge] = true
|
39
|
-
server_name = "testserver"
|
40
|
-
chef_node_name = "testnode"
|
41
|
-
instance.config[:chef_node_name] = chef_node_name
|
42
|
-
expect(instance).to receive(:destroy_item).with(Chef::Node, chef_node_name, "node").ordered
|
43
|
-
expect(instance).to receive(:destroy_item).with(Chef::ApiClient, chef_node_name, "client").ordered
|
44
|
-
instance.delete_from_chef(chef_node_name)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#execute_command" do
|
49
|
-
it "execute with correct method calls" do
|
50
|
-
instance::name_args = ["testserver"]
|
51
|
-
instance.service = double
|
52
|
-
expect(instance.service).to receive(:delete_server).ordered
|
53
|
-
expect(instance).to receive(:delete_from_chef).ordered
|
54
|
-
instance.execute_command
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#destroy_item" do
|
59
|
-
it "destroy chef node" do
|
60
|
-
node_name = "testnode"
|
61
|
-
test_obj = Object.new
|
62
|
-
allow(Chef::Node).to receive(:load).and_return(test_obj)
|
63
|
-
allow(test_obj).to receive(:destroy)
|
64
|
-
expect(instance.ui).to receive(:warn).with("Deleted node #{node_name}")
|
65
|
-
instance.destroy_item(Chef::Node, node_name, "node")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "destroy chef client" do
|
69
|
-
client_name = "testclient"
|
70
|
-
test_obj = Object.new
|
71
|
-
allow(Chef::ApiClient).to receive(:load).and_return(test_obj)
|
72
|
-
allow(test_obj).to receive(:destroy)
|
73
|
-
expect(instance.ui).to receive(:warn).with("Deleted client #{client_name}")
|
74
|
-
instance.destroy_item(Chef::ApiClient, client_name, "client")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|