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.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_distribution.rb +2 -2
  4. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_options.rb +115 -133
  5. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_protocol.rb +6 -6
  6. data/lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb +11 -12
  7. data/lib/chef/knife/cloud/chefbootstrap/ssh_bootstrap_protocol.rb +49 -54
  8. data/lib/chef/knife/cloud/chefbootstrap/unix_distribution.rb +3 -3
  9. data/lib/chef/knife/cloud/chefbootstrap/windows_distribution.rb +3 -3
  10. data/lib/chef/knife/cloud/chefbootstrap/winrm_bootstrap_protocol.rb +11 -12
  11. data/lib/chef/knife/cloud/command.rb +24 -27
  12. data/lib/chef/knife/cloud/exceptions.rb +1 -2
  13. data/lib/chef/knife/cloud/fog/options.rb +8 -8
  14. data/lib/chef/knife/cloud/fog/service.rb +54 -60
  15. data/lib/chef/knife/cloud/helpers.rb +2 -3
  16. data/lib/chef/knife/cloud/list_resource_command.rb +6 -7
  17. data/lib/chef/knife/cloud/list_resource_options.rb +5 -5
  18. data/lib/chef/knife/cloud/server/create_command.rb +30 -35
  19. data/lib/chef/knife/cloud/server/create_options.rb +33 -34
  20. data/lib/chef/knife/cloud/server/delete_command.rb +12 -15
  21. data/lib/chef/knife/cloud/server/delete_options.rb +7 -8
  22. data/lib/chef/knife/cloud/server/list_command.rb +22 -22
  23. data/lib/chef/knife/cloud/server/list_options.rb +9 -10
  24. data/lib/chef/knife/cloud/server/options.rb +7 -7
  25. data/lib/chef/knife/cloud/server/show_command.rb +5 -5
  26. data/lib/chef/knife/cloud/server/show_options.rb +5 -6
  27. data/lib/chef/knife/cloud/service.rb +12 -13
  28. data/lib/knife-cloud/version.rb +2 -2
  29. data/lib/test/fixtures/knife.rb +3 -3
  30. data/lib/test/fixtures/validation.pem +27 -0
  31. data/lib/test/knife-utils/helper.rb +11 -11
  32. data/lib/test/knife-utils/knife_test_utils.rb +4 -4
  33. data/lib/test/knife-utils/matchers.rb +3 -3
  34. data/lib/test/knife-utils/test_bed.rb +38 -38
  35. data/lib/test/templates/windows-chef-client-msi.erb +3 -4
  36. data/lib/test/templates/windows-shell.erb +2 -2
  37. metadata +12 -152
  38. data/.gitignore +0 -33
  39. data/.travis.yml +0 -6
  40. data/CHANGELOG.md +0 -133
  41. data/CONTRIBUTING.md +0 -5
  42. data/Gemfile +0 -9
  43. data/README.md +0 -421
  44. data/Rakefile +0 -35
  45. data/ci.gemfile +0 -18
  46. data/knife-cloud.gemspec +0 -26
  47. data/spec/resource_spec_helper.rb +0 -49
  48. data/spec/server_command_common_spec_helper.rb +0 -48
  49. data/spec/spec_helper.rb +0 -25
  50. data/spec/support/shared_examples_for_command.rb +0 -35
  51. data/spec/support/shared_examples_for_servercreatecommand.rb +0 -144
  52. data/spec/support/shared_examples_for_serverdeletecommand.rb +0 -77
  53. data/spec/support/shared_examples_for_service.rb +0 -85
  54. data/spec/unit/bootstrap_protocol_spec.rb +0 -98
  55. data/spec/unit/bootstrapper_spec.rb +0 -171
  56. data/spec/unit/cloud_command_spec.rb +0 -35
  57. data/spec/unit/command_spec.rb +0 -49
  58. data/spec/unit/fog_service_spec.rb +0 -163
  59. data/spec/unit/list_resource_command_spec.rb +0 -140
  60. data/spec/unit/server_create_command_spec.rb +0 -198
  61. data/spec/unit/server_delete_command_spec.rb +0 -25
  62. data/spec/unit/server_list_command_spec.rb +0 -119
  63. data/spec/unit/server_show_command_spec.rb +0 -64
  64. data/spec/unit/service_spec.rb +0 -46
  65. data/spec/unit/ssh_bootstrap_protocol_spec.rb +0 -116
  66. data/spec/unit/unix_distribution_spec.rb +0 -37
  67. data/spec/unit/windows_distribution_spec.rb +0 -37
  68. data/spec/unit/winrm_bootstrap_protocol_spec.rb +0 -108
@@ -1,85 +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/service'
20
-
21
- shared_examples_for Chef::Knife::Cloud::Service do |instance|
22
-
23
- describe "#connection" do
24
- it "creates a connection to fog service." do
25
- expect(instance).to receive(:add_api_endpoint)
26
- expect(Fog::Compute).to receive(:new)
27
- instance.connection
28
- end
29
- end
30
-
31
- describe "#delete_server" do
32
- it "deletes the server." do
33
- server = double()
34
- allow(instance).to receive(:puts)
35
- allow(instance).to receive_message_chain(:connection, :servers, :get).and_return(server)
36
- expect(server).to receive(:name).ordered
37
- expect(server).to receive(:id).ordered
38
- allow(instance).to receive_message_chain(:ui, :confirm)
39
- expect(server).to receive(:destroy).ordered
40
- instance.delete_server(:server_name)
41
- end
42
-
43
- it "throws error message when the server cannot be located." do
44
- server_name = "invalid_server_name"
45
- error_message = "Could not locate server '#{server_name}'."
46
- allow(instance).to receive_message_chain(:connection, :servers, :get).and_return(nil)
47
- allow(instance).to receive_message_chain(:ui, :error).with(error_message)
48
- expect { instance.delete_server(server_name) }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerDeleteError)
49
- end
50
- end
51
-
52
- describe "#create_server" do
53
- before do
54
- allow(instance).to receive(:puts)
55
- allow(instance).to receive(:print)
56
- end
57
-
58
- it "creates the server." do
59
- server = double()
60
- allow(instance).to receive_message_chain(:connection, :servers, :create).and_return(server)
61
- allow(instance).to receive_message_chain(:ui, :color)
62
- expect(server).to receive(:wait_for)
63
- instance.create_server({:server_create_timeout => 600})
64
- end
65
- end
66
-
67
- describe "#get_server" do
68
- it "return server." do
69
- server = double()
70
- allow(instance).to receive_message_chain(:connection, :servers, :create).and_return(server)
71
- expect(instance.connection.servers).to receive(:get)
72
- instance.get_server("instance_id")
73
- end
74
- end
75
-
76
- describe "#server_summary" do
77
- it "show server details." do
78
- server = double()
79
- instance.ui = double()
80
- expect(instance.ui).to receive(:list)
81
- expect(server).to receive(:id)
82
- instance.server_summary(server, [{:label => 'Instance ID', :key => 'id'}])
83
- end
84
- end
85
- end
@@ -1,98 +0,0 @@
1
- #
2
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
3
- # Copyright:: Copyright (c) 2013-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
- require 'spec_helper'
19
- require 'chef/knife/cloud/chefbootstrap/bootstrap_protocol'
20
- require 'chef/knife/bootstrap'
21
-
22
- describe Chef::Knife::Cloud::BootstrapProtocol do
23
- before do
24
- @config = {:bootstrap_protocol => 'ssh'}
25
- @instance = Chef::Knife::Cloud::BootstrapProtocol.new(@config)
26
- end
27
-
28
- context "BootstrapProtocol initializer" do
29
- it "asks for compulsory properties while creating @instance" do
30
- expect {Chef::Knife::Cloud::BootstrapProtocol.new}.to raise_error(ArgumentError)
31
- end
32
-
33
- it "creating @instance" do
34
- expect {Chef::Knife::Cloud::BootstrapProtocol.new(@config)}.to_not raise_error
35
- expect(Chef::Knife::Cloud::BootstrapProtocol.new(@config).class).to eq(Chef::Knife::Cloud::BootstrapProtocol)
36
- end
37
- end
38
-
39
- describe "#send_bootstrap_command" do
40
- it "execute with correct method calls" do
41
- @instance.bootstrap = double()
42
- expect(@instance).to receive(:wait_for_server_ready).ordered
43
- expect(@instance).to receive(:init_bootstrap_options).ordered
44
- expect(@instance.bootstrap).to receive(:run)
45
- @instance.send_bootstrap_command
46
- end
47
- end
48
-
49
- describe "#init_bootstrap_options" do
50
- it "set correct bootstrap config" do
51
- @config[:bootstrap_ip_address] = "127.0.0.1"
52
- @config[:chef_node_name] = "testnode"
53
- @config[:environment] = "_default"
54
- @config[:first_boot_attributes] = "{\"foo\":\"bar\"}"
55
- @config[:secret] = "secret"
56
- @config[:secret_file] = "secret_file"
57
- @config[:template_file] = "../template_file"
58
- @config[:bootstrap_vault_file] = "/foo/bar/baz"
59
- @config[:bootstrap_vault_json] = '{ "vault": "item1" }'
60
- @config[:bootstrap_vault_item] = { 'vault' => 'item1' }
61
- @config[:bootstrap_template] = "../template_file"
62
- @config[:node_ssl_verify_mode] = "none"
63
- @config[:node_verify_api_cert] = true
64
- @config[:bootstrap_url] = "https://www.chef.io/chef/install.sh"
65
- @config[:bootstrap_install_command] = "curl -l https://www.chef.io/chef/install.sh | sudo bash -s --"
66
- @config[:bootstrap_wget_options] = "-e use_proxy=yes -e http://myproxy.com:8080"
67
- @config[:bootstrap_curl_options] = "--proxy http://myproxy.com:8080"
68
- @config[:use_sudo_password] = "true"
69
- @config[:msi_url] = "https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi"
70
- @config[:session_timeout] = "42"
71
- @config[:install_as_service] = "true"
72
- allow(@config).to receive(:locate_config_value).and_return({})
73
- @instance.bootstrap = Chef::Knife::Bootstrap.new
74
- @instance.init_bootstrap_options
75
- expect(@instance.bootstrap.name_args).to eq([@config[:bootstrap_ip_address]])
76
- expect(@instance.bootstrap.config[:chef_node_name]).to eq(@config[:chef_node_name])
77
- expect(@instance.bootstrap.config[:environment]).to eq(@config[:environment])
78
- expect(@instance.bootstrap.config[:first_boot_attributes]).to eq(@config[:first_boot_attributes])
79
- expect(@instance.bootstrap.config[:secret]).to eq(@config[:secret])
80
- expect(@instance.bootstrap.config[:secret_file]).to eq(@config[:secret_file])
81
- expect(@instance.bootstrap.config[:template_file]).to eq(@config[:template_file])
82
- expect(@instance.bootstrap.config[:bootstrap_vault_file]).to eq(@config[:bootstrap_vault_file])
83
- expect(@instance.bootstrap.config[:bootstrap_vault_json]).to eq(@config[:bootstrap_vault_json])
84
- expect(@instance.bootstrap.config[:bootstrap_vault_item]).to eq(@config[:bootstrap_vault_item])
85
- expect(@instance.bootstrap.config[:bootstrap_template]).to eq(@config[:bootstrap_template])
86
- expect(@instance.bootstrap.config[:node_ssl_verify_mode]).to eq(@config[:node_ssl_verify_mode])
87
- expect(@instance.bootstrap.config[:node_verify_api_cert]).to eq(@config[:node_verify_api_cert])
88
- expect(@instance.bootstrap.config[:bootstrap_url]).to eq(@config[:bootstrap_url])
89
- expect(@instance.bootstrap.config[:bootstrap_install_command]).to eq(@config[:bootstrap_install_command])
90
- expect(@instance.bootstrap.config[:bootstrap_wget_options]).to eq(@config[:bootstrap_wget_options])
91
- expect(@instance.bootstrap.config[:bootstrap_curl_options]).to eq(@config[:bootstrap_curl_options])
92
- expect(@instance.bootstrap.config[:use_sudo_password]).to eq(@config[:use_sudo_password])
93
- expect(@instance.bootstrap.config[:msi_url]).to eq(@config[:msi_url])
94
- expect(@instance.bootstrap.config[:install_as_service]).to eq(@config[:install_as_service])
95
- expect(@instance.bootstrap.config[:session_timeout]).to eq(@config[:session_timeout])
96
- end
97
- end
98
- end
@@ -1,171 +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
- require 'spec_helper'
20
- require 'chef/knife/cloud/chefbootstrap/bootstrapper'
21
- require 'chef/knife/bootstrap_windows_ssh'
22
-
23
- describe Chef::Knife::Cloud::Bootstrapper do
24
- before(:each) do
25
- @config = {:bootstrap_protocol => 'ssh'}
26
- @instance = Chef::Knife::Cloud::Bootstrapper.new(@config)
27
- end
28
-
29
- context "Bootstrapper initializer" do
30
- it "asks for compulsory properties while creating instance" do
31
- expect {Chef::Knife::Cloud::Bootstrapper.new}.to raise_error(ArgumentError)
32
- end
33
-
34
- it "creating instance" do
35
- expect {Chef::Knife::Cloud::Bootstrapper.new(@config)}.to_not raise_error
36
- expect(Chef::Knife::Cloud::Bootstrapper.new(@config).class).to eq(Chef::Knife::Cloud::Bootstrapper)
37
- end
38
- end
39
-
40
- describe "#bootstrap Linux machine with ssh" do
41
- it "executes with correct method calls" do
42
- @ssh_bootstrap_protocol = Chef::Knife::Cloud::SshBootstrapProtocol.new(@config)
43
- allow(@instance).to receive(:create_bootstrap_protocol).and_return(@ssh_bootstrap_protocol)
44
- @unix_distribution = Chef::Knife::Cloud::UnixDistribution.new(@config)
45
- expect(@instance).to receive(:create_bootstrap_protocol).ordered
46
- allow(@instance).to receive(:create_bootstrap_distribution).and_return(@unix_distribution)
47
- expect(@ssh_bootstrap_protocol).to receive(:send_bootstrap_command).ordered
48
- @instance.bootstrap
49
- end
50
- end
51
-
52
- describe "#bootstrap Windows machine with winrm" do
53
- it "executes with correct method calls" do
54
- @winrm_bootstrap_protocol = Chef::Knife::Cloud::WinrmBootstrapProtocol.new(@config)
55
- allow(@instance).to receive(:create_bootstrap_protocol).and_return(@winrm_bootstrap_protocol)
56
- @windows_distribution = Chef::Knife::Cloud::WindowsDistribution.new(@config)
57
- expect(@instance).to receive(:create_bootstrap_protocol).ordered
58
- allow(@instance).to receive(:create_bootstrap_distribution).and_return(@windows_distribution)
59
- expect(@winrm_bootstrap_protocol).to receive(:send_bootstrap_command).ordered
60
- @instance.bootstrap
61
- end
62
- end
63
-
64
- describe "#create_bootstrap_distribution" do
65
- context "when image_os_type set to windows" do
66
- before(:each) do
67
- @config[:image_os_type] = "windows"
68
- end
69
-
70
- it "instantiates Windows Distribution class." do
71
- expect(Chef::Knife::Cloud::WindowsDistribution).to receive(:new).with(@config)
72
- @instance.create_bootstrap_distribution
73
- end
74
-
75
- it "doesn't instantiate Unix Distribution class." do
76
- expect(Chef::Knife::Cloud::UnixDistribution).to_not receive(:new)
77
- @instance.create_bootstrap_distribution
78
- end
79
-
80
- end
81
-
82
- context "when image_os_type set to linux" do
83
- before(:each) do
84
- @config[:image_os_type] = "linux"
85
- end
86
-
87
- it "instantiates Unix Distribution class." do
88
- expect(Chef::Knife::Cloud::UnixDistribution).to receive(:new).with(@config)
89
- @instance.create_bootstrap_distribution
90
- end
91
-
92
- it "doesn't instantiate Windows Distribution class." do
93
- expect(Chef::Knife::Cloud::WindowsDistribution).to_not receive(:new)
94
- @instance.create_bootstrap_distribution
95
- end
96
- end
97
-
98
- context "when image_os_type set to invalid" do
99
- before(:each) do
100
- @config[:image_os_type] = "invalid"
101
- end
102
-
103
- it "raise bootstrap error" do
104
- ui = double()
105
- expect(@instance).to receive(:ui).and_return(ui)
106
- allow(ui).to receive(:fatal)
107
- expect { @instance.create_bootstrap_distribution }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, "Invalid bootstrap distribution. image_os_type should be either windows or linux.")
108
- end
109
- end
110
- end
111
-
112
-
113
- describe "#create_bootstrap_protocol" do
114
- context "when bootstrap_protocol set to ssh" do
115
- before(:each) do
116
- @config[:bootstrap_protocol] = "ssh"
117
- end
118
-
119
- it "instantiates SshBootstrapProtocol class." do
120
- expect(Chef::Knife::Cloud::SshBootstrapProtocol).to receive(:new)
121
- @instance.create_bootstrap_protocol
122
- end
123
-
124
- it "doesn't instantiate Windows Distribution class." do
125
- expect(Chef::Knife::Cloud::WinrmBootstrapProtocol).to_not receive(:new)
126
- @instance.create_bootstrap_protocol
127
- end
128
-
129
- end
130
-
131
- context "when bootstrap_protocol set to winrm" do
132
- before(:each) do
133
- @config[:bootstrap_protocol] = "winrm"
134
- end
135
-
136
- it "instantiates WinrmBootstrapProtocol class." do
137
- expect(Chef::Knife::Cloud::WinrmBootstrapProtocol).to receive(:new)
138
- @instance.create_bootstrap_protocol
139
- end
140
-
141
- it "doesn't instantiate SshBootstrapProtocol class." do
142
- expect(Chef::Knife::Cloud::SshBootstrapProtocol).to_not receive(:new)
143
- @instance.create_bootstrap_protocol
144
- end
145
- end
146
-
147
- context "when bootstrap_protocol set to nil." do
148
- before do
149
- @config[:bootstrap_protocol] = nil
150
- end
151
-
152
- it "instantiates SshBootstrapProtocol class." do
153
- expect(Chef::Knife::Cloud::SshBootstrapProtocol).to receive(:new)
154
- @instance.create_bootstrap_protocol
155
- end
156
- end
157
-
158
- context "when bootstrap_protocol set to invalid." do
159
- before do
160
- @config[:bootstrap_protocol] = "invalid"
161
- end
162
-
163
- it "instantiates SshBootstrapProtocol class." do
164
- ui = double()
165
- expect(@instance).to receive(:ui).and_return(ui)
166
- allow(ui).to receive(:fatal)
167
- expect { @instance.create_bootstrap_protocol }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, "Invalid bootstrap protocol.")
168
- end
169
- end
170
- end
171
- end
@@ -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 File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
20
- require 'support/shared_examples_for_command'
21
-
22
- describe Chef::Knife::Cloud::Command do
23
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::Command.new
24
-
25
- let (:instance) { Chef::Knife::Cloud::Command.new }
26
-
27
- it "overrides execute_command" do
28
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
29
- expect {instance.run}.to raise_error(Chef::Exceptions::Override, "You must override execute_command in #{instance.to_s}")
30
- end
31
-
32
- it { expect {instance.run}.to raise_error(Chef::Exceptions::Override, "You must override create_service_instance in #{instance.to_s} to create cloud specific service") }
33
-
34
- end
35
-
@@ -1,49 +0,0 @@
1
- #
2
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
3
- # Copyright:: Copyright (c) 2013-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
- require 'support/shared_examples_for_command'
19
-
20
- describe Chef::Knife::Cloud::Command do
21
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::Command.new
22
-
23
- describe "validate!" do
24
- before(:each) do
25
- # Here following options are used as a test data.
26
- Chef::Config[:knife][:cloud_provider_username] = "cloud_provider_username"
27
- Chef::Config[:knife][:cloud_provider_password] = "cloud_provider_password"
28
- Chef::Config[:knife][:cloud_provider_auth_url] = "cloud_provider_auth_url"
29
- @instance = Chef::Knife::Cloud::Command.new
30
- allow(@instance.ui).to receive(:error)
31
- end
32
-
33
- after(:all) do
34
- Chef::Config[:knife].delete(:cloud_provider_username)
35
- Chef::Config[:knife].delete(:cloud_provider_password)
36
- Chef::Config[:knife].delete(:cloud_provider_auth_url)
37
- end
38
-
39
- it "execute with success" do
40
- expect { @instance.validate!(:cloud_provider_username, :cloud_provider_password, :cloud_provider_auth_url) }.to_not raise_error
41
- end
42
-
43
- it "raise_error on any mandatory option is missing" do
44
- # delete cloud_provide_username option.
45
- Chef::Config[:knife].delete(:cloud_provider_username)
46
- expect { @instance.validate!(:cloud_provider_username, :cloud_provider_password, :cloud_provider_auth_url) }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You did not provide a valid 'Cloud Provider Username' value..")
47
- end
48
- end
49
- end
@@ -1,163 +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
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
20
- require 'chef/knife/cloud/fog/service'
21
- require 'support/shared_examples_for_service'
22
-
23
- describe Chef::Knife::Cloud::FogService do
24
-
25
- it_behaves_like Chef::Knife::Cloud::Service, Chef::Knife::Cloud::FogService.new
26
-
27
- let (:instance) { Chef::Knife::Cloud::FogService.new({:auth_params => {:provider => 'Any Cloud Provider'}}) }
28
-
29
- context "connection" do
30
- before do
31
- allow(instance).to receive(:exit)
32
- end
33
-
34
- it "creates a connection to fog service with the provided auth params." do
35
- expect(instance).to receive(:add_api_endpoint)
36
- expect(Fog::Compute).to receive(:new).with({:provider => 'Any Cloud Provider'})
37
- instance.connection
38
- end
39
- end
40
-
41
- context "network" do
42
- it "creates a connection to fog network with the provided auth params." do
43
- expect(Fog::Network).to receive(:new).with({:provider => 'Any Cloud Provider'})
44
- instance.network
45
- end
46
-
47
- context "connection to fog" do
48
- before do
49
- allow(instance).to receive(:exit)
50
- allow(instance).to receive(:ui).and_return(Object.new)
51
- expect(instance.ui).to receive(:fatal)
52
- end
53
-
54
- it "handles Unauthorized exception." do
55
- expect(Fog::Network).to receive(:new).with({:provider => 'Any Cloud Provider'}).and_raise Excon::Errors::Unauthorized.new("Unauthorized")
56
- expect {instance.network}.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServiceConnectionError)
57
- end
58
-
59
- it "handles SocketError or any other connection exception." do
60
- socket_error = Excon::Errors::SocketError.new(Exception.new "Mock Error")
61
- expect(Fog::Network).to receive(:new).with({:provider => 'Any Cloud Provider'}).and_raise socket_error
62
- expect {instance.network}.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServiceConnectionError)
63
- end
64
-
65
- it "handles NetworkNotFoundError exception." do
66
- expect(Fog::Network).to receive(:new).with({:provider => 'Any Cloud Provider'}).and_raise Fog::Errors::NotFound.new("NotFound")
67
- expect {instance.network}.to raise_error(Chef::Knife::Cloud::CloudExceptions::NetworkNotFoundError)
68
- end
69
- end
70
- end
71
-
72
- context "add_custom_attributes" do
73
- before(:each) do
74
- Chef::Config[:knife][:custom_attributes] = [{"state"=>"Inactive"}]
75
- @server_def = {:name=>"vm-1", :image_ref=>"123",:flavor_ref=>"2", :key_name=>"key"}
76
- instance.add_custom_attributes(@server_def)
77
- end
78
-
79
- it "adds the custom attributes provided to server_def" do
80
- expect(@server_def.include?(:state)).to be true
81
- end
82
-
83
- it "sets the provided attributes with supplied values" do
84
- expect(@server_def[:state] == "Inactive").to be true
85
- end
86
- end
87
-
88
- ["servers", "images", "networks"].each do |resource_type|
89
- resource = case resource_type
90
- when "networks"
91
- :network
92
- else
93
- :connection
94
- end
95
- context "list #{resource_type}" do
96
-
97
- it "lists #{resource_type} of the current cloud service provider account." do
98
- allow(instance).to receive_message_chain(resource.to_sym, "#{resource_type}".to_sym, :all)
99
- instance.method("list_#{resource_type}").call
100
- end
101
-
102
- it "handles Excon::Errors::BadRequest exception." do
103
- allow(instance).to receive(:ui).and_return(Object.new)
104
- allow(instance.ui).to receive(:fatal)
105
- allow(instance).to receive_message_chain(resource.to_sym, "#{resource_type}".to_sym, :all).and_raise Excon::Errors::BadRequest.new("Invalid Resource")
106
- expect {instance.method("list_#{resource_type}").call}.to raise_error(Chef::Knife::Cloud::CloudExceptions::CloudAPIException)
107
- end
108
- end
109
- end
110
-
111
- context "#delete_server" do
112
- before(:each) do
113
- @server = TestResource.new({:id => "test-server1"})
114
- @server.define_singleton_method(:destroy){}
115
- end
116
-
117
- it "delete instance successfully" do
118
- server_name = "test-server1"
119
- instance.ui = double
120
- expect(instance).to receive(:get_server).and_return(@server)
121
- expect(instance).to receive(:get_server_name).and_return(server_name)
122
- expect(instance).to receive(:msg_pair).with("Instance Name", server_name)
123
- expect(instance).to receive(:msg_pair).with("Instance ID", @server.id)
124
- expect(instance.ui).to receive(:confirm)
125
- expect(@server).to receive(:destroy)
126
- instance.delete_server(server_name)
127
- end
128
-
129
- it "raise_error on non existence server delete " do
130
- server_name = "test-server1"
131
- instance.ui = double
132
- error_message = "Could not locate server '#{server_name}'."
133
- expect(instance).to receive(:get_server).and_return(nil)
134
- expect(instance.ui).to receive(:error).with(error_message)
135
- expect { instance.delete_server(server_name) }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerDeleteError, error_message)
136
- end
137
- end
138
-
139
- context '#release_address' do
140
- before(:each) do
141
- allow(instance).to receive(:add_api_endpoint)
142
- allow(Fog::Compute).to receive(:new).with({:provider => 'Any Cloud Provider'})
143
- end
144
-
145
- it 'releases address successfully' do
146
- address_id = 'test-addres-id'
147
- @address = TestResource.new('body' => { 'floating_ip' =>
148
- { 'instance_id' => nil,
149
- 'ip' => '127.0.0.1',
150
- 'fixed_ip' => nil,
151
- 'id' => 'test-addres-id',
152
- 'pool' => 'public-110'
153
- }
154
- })
155
- instance.ui = double
156
- expect(instance).to receive(:get_address).and_return(@address)
157
- expect(instance).to receive(:msg_pair).with('IP address', '127.0.0.1')
158
- expect(instance.ui).to receive(:confirm)
159
- allow(instance.connection).to receive(:release_address)
160
- instance.release_address(address_id)
161
- end
162
- end
163
- end