knife-cloud 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,140 +0,0 @@
1
- #
2
- # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
3
- # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
4
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
5
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
-
20
- require 'spec_helper'
21
- require 'chef/knife/cloud/list_resource_command'
22
- require 'support/shared_examples_for_command'
23
- require 'excon/errors'
24
-
25
- describe Chef::Knife::Cloud::ResourceListCommand do
26
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::ResourceListCommand.new
27
-
28
- let (:instance) {Chef::Knife::Cloud::ResourceListCommand.new}
29
- let (:resources) {[ TestResource.new({:id => "resource-1", :os => "ubuntu"}),
30
- TestResource.new({:id => "resource-2", :os => "windows"})]}
31
-
32
- context "Basic tests:" do
33
- it "raises exception to override #query_resource method" do
34
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
35
- expect {instance.run}.to raise_error(Chef::Exceptions::Override, "You must override query_resource in #{instance.to_s} to return resources.")
36
- end
37
-
38
- it "responds to #list method" do
39
- allow(instance).to receive(:query_resource)
40
- expect(instance).to respond_to(:list)
41
- end
42
-
43
- context "responds to #list method" do
44
- let(:test_resource) { "test" }
45
- before(:each) do
46
- expect(instance.ui).to receive(:fatal)
47
- instance.config[:format] = "summary"
48
- end
49
-
50
- it "handle generic exception" do
51
- allow(test_resource).to receive(:sort_by).and_raise StandardError
52
- expect {instance.list(test_resource)}.to raise_error(StandardError)
53
- end
54
-
55
- it "handle Excon::Errors::BadRequest exception." do
56
- allow(test_resource).to receive(:sort_by).and_raise Excon::Errors::BadRequest.new("excon error message")
57
- expect {instance.list(test_resource)}.to raise_error(Excon::Errors::BadRequest)
58
- end
59
- end
60
- end
61
-
62
- context "Without columns_with_info parameter in #list:" do
63
- before do
64
- allow(instance).to receive(:query_resource).and_return(resources)
65
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
66
- allow(instance).to receive(:puts)
67
- instance.config[:format] = "summary"
68
- end
69
-
70
- it "lists resources in json format when columns_with_info parameter is empty" do
71
- expect(instance).to receive(:puts).with(resources[0].to_json)
72
- expect(instance).to receive(:puts).with(resources[1].to_json)
73
- expect(instance).to receive(:puts).with("\n").twice
74
- instance.run
75
- end
76
- end
77
-
78
- context "With columns_with_info parameter in #list:" do
79
- context "#value_callback not specified in columns_with_info" do
80
- before do
81
- class Derived < Chef::Knife::Cloud::ResourceListCommand
82
- attr_accessor :resource_filters
83
- def before_exec_command
84
- @columns_with_info = [ { :key => 'id', :label => 'Instance ID' },
85
- { :key => 'os', :label => 'Operating system' } ]
86
- end
87
- end
88
-
89
- @derived_instance = Derived.new
90
- allow(@derived_instance).to receive(:query_resource).and_return(resources)
91
- allow(@derived_instance).to receive(:puts)
92
- allow(@derived_instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
93
- @derived_instance.config[:format] = "summary"
94
- end
95
-
96
- it "lists all resources" do
97
- expect(@derived_instance.ui).to receive(:list).with(["Instance ID", "Operating system", "resource-1", "ubuntu", "resource-2", "windows"], :uneven_columns_across, 2)
98
- @derived_instance.run
99
- end
100
-
101
- it "excludes resource when filter is specified" do
102
- @derived_instance.resource_filters = [{:attribute => 'id', :regex => /^resource-1$/}]
103
- expect(@derived_instance.ui).to receive(:list).with(["Instance ID", "Operating system", "resource-2", "windows"], :uneven_columns_across, 2)
104
- @derived_instance.run
105
- end
106
-
107
- it "lists all resources when disable filter" do
108
- @derived_instance.config[:disable_filter] = true
109
- @derived_instance.resource_filters = [{:attribute => 'id', :regex => /^resource-1$/}]
110
- expect(@derived_instance.ui).to receive(:list).with(["Instance ID", "Operating system", "resource-1", "ubuntu", "resource-2", "windows"], :uneven_columns_across, 2)
111
- @derived_instance.run
112
- end
113
- end
114
- context "#value_callback specified in columns_with_info" do
115
- before do
116
- class Derived < Chef::Knife::Cloud::ResourceListCommand
117
- attr_accessor :resource_filters
118
- def before_exec_command
119
- @columns_with_info = [ { :key => 'id', :label => 'Instance ID' },
120
- { :key => 'os', :label => 'Operating system', :value_callback => method(:format_os) } ]
121
- end
122
- def format_os(os)
123
- (os == 'ubuntu') ? "ubuntu - operating system with Linux kernel" : os
124
- end
125
- end
126
-
127
- @derived_instance = Derived.new
128
- allow(@derived_instance).to receive(:query_resource).and_return(resources)
129
- allow(@derived_instance).to receive(:puts)
130
- allow(@derived_instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
131
- @derived_instance.config[:format] = "summary"
132
- end
133
-
134
- it "lists formatted list of resources" do
135
- expect(@derived_instance.ui).to receive(:list).with(["Instance ID", "Operating system", "resource-1", "ubuntu - operating system with Linux kernel", "resource-2", "windows"], :uneven_columns_across, 2)
136
- @derived_instance.run
137
- end
138
- end
139
- end
140
- end
@@ -1,198 +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 'support/shared_examples_for_command'
20
- require 'support/shared_examples_for_servercreatecommand'
21
- require 'net/ssh'
22
- require 'chef/knife/cloud/server/create_options'
23
-
24
- describe Chef::Knife::Cloud::ServerCreateCommand do
25
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::ServerCreateCommand.new
26
- it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, Chef::Knife::Cloud::ServerCreateCommand.new
27
-
28
- describe "#validate_params!" do
29
- before(:each) do
30
- @instance = Chef::Knife::Cloud::ServerCreateCommand.new
31
- allow(@instance.ui).to receive(:error)
32
- Chef::Config[:knife][:bootstrap_protocol] = "ssh"
33
- Chef::Config[:knife][:identity_file] = "identity_file"
34
- Chef::Config[:knife][:ssh_password] = "ssh_password"
35
- Chef::Config[:knife][:chef_node_name] = "chef_node_name"
36
- Chef::Config[:knife][:winrm_password] = "winrm_password"
37
- end
38
- after(:all) do
39
- Chef::Config[:knife].delete(:bootstrap_protocol)
40
- Chef::Config[:knife].delete(:identity_file)
41
- Chef::Config[:knife].delete(:chef_node_name)
42
- Chef::Config[:knife].delete(:ssh_password)
43
- Chef::Config[:knife].delete(:winrm_password)
44
- end
45
-
46
- it "run sucessfully on all params exist" do
47
- expect { @instance.validate_params! }.to_not raise_error
48
- expect(@instance.config[:chef_node_name]).to eq(Chef::Config[:knife][:chef_node_name])
49
- end
50
-
51
- context "when bootstrap_protocol ssh" do
52
- it "raise error on ssh_password and identity_file are missing" do
53
- Chef::Config[:knife].delete(:identity_file)
54
- Chef::Config[:knife].delete(:ssh_password)
55
- expect { @instance.validate_params! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You must provide either Identity file or SSH Password..")
56
- end
57
- end
58
-
59
- context "when bootstrap_protocol winrm" do
60
- it "raise error on winrm_password is missing" do
61
- Chef::Config[:knife][:bootstrap_protocol] = "winrm"
62
- Chef::Config[:knife].delete(:winrm_password)
63
- expect { @instance.validate_params! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You must provide Winrm Password..")
64
- end
65
- end
66
- end
67
-
68
- describe "#after_exec_command" do
69
- it "calls bootstrap" do
70
- instance = Chef::Knife::Cloud::ServerCreateCommand.new
71
- expect(instance).to receive(:bootstrap)
72
- instance.after_exec_command
73
- end
74
-
75
- it "delete server on bootstrap failure" do
76
- instance = Chef::Knife::Cloud::ServerCreateCommand.new
77
- instance.service = Chef::Knife::Cloud::Service.new
78
- allow(instance).to receive(:raise)
79
- allow(instance.ui).to receive(:fatal)
80
- instance.config[:delete_server_on_failure] = true
81
- allow(instance).to receive(:bootstrap).and_raise(Chef::Knife::Cloud::CloudExceptions::BootstrapError)
82
- expect(instance.service).to receive(:delete_server_dependencies)
83
- expect(instance.service).to receive(:delete_server_on_failure)
84
- instance.after_exec_command
85
- end
86
-
87
- # Currently the RangeError is occured when image_os_type is set to linux and bootstrap-protocol is set to ssh before windows server bootstrap.
88
- it "raise error message when bootstrap fails due to image_os_type not exist" do
89
- instance = Chef::Knife::Cloud::ServerCreateCommand.new
90
- instance.service = Chef::Knife::Cloud::Service.new
91
- allow(instance.ui).to receive(:fatal)
92
- instance.config[:delete_server_on_failure] = true
93
- allow(instance).to receive(:bootstrap).and_raise(RangeError)
94
- expect(instance.service).to receive(:delete_server_dependencies)
95
- expect(instance.service).to receive(:delete_server_on_failure)
96
- expect { instance.after_exec_command }.to raise_error(RangeError, "Check if --bootstrap-protocol and --image-os-type is correct. RangeError")
97
- end
98
- end
99
-
100
- describe "#set_default_config" do
101
- it "set valid image os type" do
102
- instance = Chef::Knife::Cloud::ServerCreateCommand.new
103
- instance.config[:bootstrap_protocol] = 'winrm'
104
- instance.set_default_config
105
- expect(instance.config[:image_os_type]).to eq('windows')
106
- end
107
- end
108
-
109
- class ServerCreate < Chef::Knife::Cloud::ServerCreateCommand
110
- include Chef::Knife::Cloud::ServerCreateOptions
111
- end
112
-
113
- describe "#bootstrap options" do
114
-
115
- it "set chef config knife options" do
116
- instance = ServerCreate.new
117
- bootstrap_url = "bootstrap_url"
118
- bootstrap_install_command = "bootstrap_install_command"
119
- bootstrap_wget_options = "bootstrap_wget_options"
120
- bootstrap_curl_options = "bootstrap_curl_options"
121
- bootstrap_no_proxy = "bootstrap_no_proxy"
122
-
123
- instance.options[:bootstrap_url][:proc].call bootstrap_url
124
- expect(Chef::Config[:knife][:bootstrap_url]).to eq(bootstrap_url)
125
-
126
- instance.options[:bootstrap_install_command][:proc].call bootstrap_install_command
127
- expect(Chef::Config[:knife][:bootstrap_install_command]).to eq(bootstrap_install_command)
128
-
129
- instance.options[:bootstrap_wget_options][:proc].call bootstrap_wget_options
130
- expect(Chef::Config[:knife][:bootstrap_wget_options]).to eq(bootstrap_wget_options)
131
-
132
- instance.options[:bootstrap_curl_options][:proc].call bootstrap_curl_options
133
- expect(Chef::Config[:knife][:bootstrap_curl_options]).to eq(bootstrap_curl_options)
134
-
135
- instance.options[:bootstrap_no_proxy][:proc].call bootstrap_no_proxy
136
- expect(Chef::Config[:knife][:bootstrap_no_proxy]).to eq(bootstrap_no_proxy)
137
-
138
- expect(instance.options[:auth_timeout][:default]).to eq(25)
139
- end
140
- end
141
-
142
- describe "#before_bootstrap" do
143
-
144
- before(:all) { @instance = ServerCreate.new }
145
-
146
- context "bootstrap_protocol shh" do
147
- before {@instance.config[:bootstrap_protocol] = "ssh"}
148
-
149
- it "set ssh_user value by using -x option for ssh bootstrap protocol or linux image" do
150
- # Currently -x option set config[:winrm_user]
151
- # default value of config[:ssh_user] is root
152
- @instance.config[:winrm_user] = "ubuntu"
153
- @instance.config[:ssh_user] = "root"
154
-
155
- @instance.before_bootstrap
156
- expect(@instance.config[:ssh_user]).to eq("ubuntu")
157
- end
158
-
159
- it "set ssh_password value by using -P option for ssh bootstrap protocol or linux image" do
160
- # Currently -P option set config[:winrm_password]
161
- # default value of config[:ssh_password] is nil
162
- @instance.config[:winrm_password] = "winrm_password"
163
- @instance.config[:ssh_password] = nil
164
-
165
- @instance.before_bootstrap
166
- expect(@instance.config[:ssh_password]).to eq("winrm_password")
167
- end
168
-
169
- it "set ssh_port value by using -p option for ssh bootstrap protocol or linux image" do
170
- # Currently -p option set config[:winrm_port]
171
- # default value of config[:ssh_port] is 22
172
- @instance.config[:winrm_port] = "1234"
173
- @instance.config[:ssh_port] = "22"
174
-
175
- @instance.before_bootstrap
176
- expect(@instance.config[:ssh_port]).to eq("1234")
177
- end
178
-
179
- it "set identity_file value by using -i option for ssh bootstrap protocol or linux image" do
180
- # Currently -i option set config[:kerberos_keytab_file]
181
- # default value of config[:identity_file] is nil
182
- @instance.config[:kerberos_keytab_file] = "kerberos_keytab_file"
183
- @instance.config[:identity_file] = nil
184
-
185
- @instance.before_bootstrap
186
- expect(@instance.config[:identity_file]).to eq("kerberos_keytab_file")
187
- end
188
- end
189
-
190
- context "bootstrap_protocol winrm" do
191
- it "skip ssh_override_winrm" do
192
- @instance.config[:bootstrap_protocol] = "winrm"
193
- expect(@instance).to_not receive(:ssh_override_winrm)
194
- @instance.before_bootstrap
195
- end
196
- end
197
- end
198
- end
@@ -1,25 +0,0 @@
1
- #
2
- # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
3
- # Copyright:: Copyright (c) 2013 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 'support/shared_examples_for_command'
20
- require 'support/shared_examples_for_serverdeletecommand'
21
-
22
- describe Chef::Knife::Cloud::ServerDeleteCommand do
23
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::ServerDeleteCommand.new
24
- it_behaves_like Chef::Knife::Cloud::ServerDeleteCommand, Chef::Knife::Cloud::ServerDeleteCommand.new
25
- end
@@ -1,119 +0,0 @@
1
- #
2
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
3
- # Author:: Prabhu Das (<prabhu.das@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 'support/shared_examples_for_command'
21
- require 'chef/knife/cloud/server/list_command'
22
- require 'chef/node'
23
-
24
- describe Chef::Knife::Cloud::ServerListCommand do
25
- it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::ServerListCommand.new
26
-
27
- describe "#before_exec_command" do
28
- it "set chef data columns info on chef data options" do
29
- instance = Chef::Knife::Cloud::ServerListCommand.new
30
- instance.config[:chef_data] = true
31
- expect(Chef::Node).to receive(:list).with(true)
32
- expect(instance.before_exec_command).to include({:label => "Chef Node Name", :key => "name"})
33
- end
34
-
35
- it "set chef data columns info on chef-data and chef-node-attribute options" do
36
- chef_node_attribute = "platform_family"
37
- instance = Chef::Knife::Cloud::ServerListCommand.new
38
- instance.config[:chef_data] = true
39
- instance.config[:chef_node_attribute] = chef_node_attribute
40
- expect(Chef::Node).to receive(:list).with(true)
41
- expect(instance.before_exec_command).to include({:label => chef_node_attribute, :key => chef_node_attribute})
42
- end
43
-
44
- it "not set chef data columns info if chef-data option is not set" do
45
- instance = Chef::Knife::Cloud::ServerListCommand.new
46
- expect(Chef::Node).to_not receive(:list).with(true)
47
- expect(instance.before_exec_command).to be(nil)
48
- end
49
-
50
- it "not set chef data columns info on chef-node-attribute option set but chef-data option is not set" do
51
- instance = Chef::Knife::Cloud::ServerListCommand.new
52
- instance.config[:chef_node_attribute] = "platform_family"
53
- expect(Chef::Node).to_not receive(:list).with(true)
54
- expect(instance.before_exec_command).to be(nil)
55
- end
56
- end
57
-
58
- describe "#get_resource_col_val" do
59
- let (:resources) {[ TestResource.new({:id => "server-1", :name => "server-1", :os => "ubuntu"})]}
60
- before do
61
- class DerivedServerList < Chef::Knife::Cloud::ServerListCommand
62
- attr_accessor :node
63
- def before_exec_command
64
- @columns_with_info = [ { :key => 'id', :label => 'Instance ID' }, {:label => 'Environment', :key => 'chef_environment'}, {:label => 'platform_family', :key => 'platform_family'} ]
65
- @chef_data_col_info = [ {:label => 'Environment', :key => 'chef_environment'}, {:label => 'platform_family', :key => 'platform_family'} ]
66
- @node = TestResource.new({:id => "server-1", :name => "server-1",
67
- :chef_environment => "_default", :platform_family => "debian"})
68
- @node.define_singleton_method(:attribute?) do |attribute|
69
- end
70
- @node_list = {"server-1" => @node}
71
- end
72
- end
73
- @derived_instance = DerivedServerList.new
74
- @derived_instance.config[:chef_data] = true
75
- @derived_instance.config[:chef_node_attribute] = "platform_family"
76
- @derived_instance.before_exec_command
77
- @derived_instance.service = double Chef::Knife::Cloud::Service.new
78
- allow(@derived_instance.service).to receive(:get_server_name).with(resources.first).and_return("server-1")
79
- end
80
-
81
- it "return columns_with_info values" do
82
- expect(@derived_instance.node).to receive(:attribute?).with("platform_family").and_return(true)
83
- expect(@derived_instance.get_resource_col_val(resources.first)).to eq(["server-1", "_default", "debian"])
84
- end
85
-
86
- it "raise error on invalide chef_node_attribute" do
87
- allow(@derived_instance.ui).to receive(:error)
88
- expect(@derived_instance.node).to receive(:attribute?).with("platform_family").and_return(false)
89
- expect { @derived_instance.get_resource_col_val(resources.first) }.to raise_error(Chef::Knife::Cloud::CloudExceptions::CloudAPIException, "The Node does not have a platform_family attribute.")
90
- end
91
- end
92
-
93
- describe "#format_server_state" do
94
- before(:each) do
95
- @instance = Chef::Knife::Cloud::ServerListCommand.new
96
- end
97
-
98
- %w{ shutting-down terminated stopping stopped error shutoff }.each do |state|
99
- it "set state color red on server state is in #{state}" do
100
- expect(@instance.ui).to receive(:color).with(state, :red)
101
- @instance.format_server_state(state)
102
- end
103
- end
104
-
105
- %w{ pending build paused suspended hard_reboot }.each do |state|
106
- it "set state color yellow on server state is in #{state}" do
107
- expect(@instance.ui).to receive(:color).with(state, :yellow)
108
- @instance.format_server_state(state)
109
- end
110
- end
111
-
112
- %w{ running }.each do |state|
113
- it "set state color green on server state is #{state}" do
114
- expect(@instance.ui).to receive(:color).with(state, :green)
115
- @instance.format_server_state(state)
116
- end
117
- end
118
- end
119
- end