knife-openstack 2.0.1 → 4.0.0

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 (60) hide show
  1. checksums.yaml +5 -5
  2. data/lib/chef/knife/cloud/openstack_server_create_options.rb +64 -51
  3. data/lib/chef/knife/cloud/openstack_service.rb +33 -17
  4. data/lib/chef/knife/cloud/openstack_service_options.rb +34 -24
  5. data/lib/chef/knife/openstack_flavor_list.rb +18 -4
  6. data/lib/chef/knife/openstack_floating_ip_allocate.rb +22 -9
  7. data/lib/chef/knife/openstack_floating_ip_associate.rb +24 -12
  8. data/lib/chef/knife/openstack_floating_ip_disassociate.rb +25 -12
  9. data/lib/chef/knife/openstack_floating_ip_list.rb +18 -4
  10. data/lib/chef/knife/openstack_floating_ip_release.rb +16 -4
  11. data/lib/chef/knife/openstack_group_list.rb +21 -4
  12. data/lib/chef/knife/openstack_helpers.rb +20 -4
  13. data/lib/chef/knife/openstack_image_list.rb +22 -8
  14. data/lib/chef/knife/openstack_network_list.rb +18 -4
  15. data/lib/chef/knife/openstack_server_create.rb +36 -35
  16. data/lib/chef/knife/openstack_server_delete.rb +17 -5
  17. data/lib/chef/knife/openstack_server_list.rb +5 -6
  18. data/lib/chef/knife/openstack_server_show.rb +4 -5
  19. data/lib/chef/knife/openstack_volume_list.rb +10 -9
  20. data/lib/knife-openstack/version.rb +2 -2
  21. metadata +17 -91
  22. data/.github/ISSUE_TEMPLATE.md +0 -21
  23. data/.gitignore +0 -32
  24. data/.travis.yml +0 -10
  25. data/CHANGELOG.md +0 -335
  26. data/CONTRIBUTING.MD +0 -164
  27. data/Gemfile +0 -21
  28. data/README.md +0 -179
  29. data/Rakefile +0 -27
  30. data/knife-openstack.gemspec +0 -30
  31. data/spec/functional/flavor_list_func_spec.rb +0 -47
  32. data/spec/functional/floating_ip_list_func_spec.rb +0 -48
  33. data/spec/functional/group_list_func_spec.rb +0 -65
  34. data/spec/functional/image_list_func_spec.rb +0 -53
  35. data/spec/functional/network_list_func_spec.rb +0 -46
  36. data/spec/functional/server_create_func_spec.rb +0 -118
  37. data/spec/functional/server_delete_func_spec.rb +0 -84
  38. data/spec/functional/server_list_func_spec.rb +0 -98
  39. data/spec/functional/server_show_func_spec.rb +0 -46
  40. data/spec/functional/volume_list_func_spec.rb +0 -46
  41. data/spec/integration/cleanup.rb +0 -89
  42. data/spec/integration/config/environment.yml.sample +0 -13
  43. data/spec/integration/openstack_spec.rb +0 -649
  44. data/spec/spec_context.rb +0 -56
  45. data/spec/spec_helper.rb +0 -128
  46. data/spec/unit/openstack_flavor_list_spec.rb +0 -30
  47. data/spec/unit/openstack_floating_ip_allocate_spec.rb +0 -56
  48. data/spec/unit/openstack_floating_ip_associate_spec.rb +0 -40
  49. data/spec/unit/openstack_floating_ip_disassociate_spec.rb +0 -39
  50. data/spec/unit/openstack_floating_ip_list_spec.rb +0 -27
  51. data/spec/unit/openstack_floating_ip_release_spec.rb +0 -49
  52. data/spec/unit/openstack_group_list_spec.rb +0 -44
  53. data/spec/unit/openstack_image_list_spec.rb +0 -32
  54. data/spec/unit/openstack_network_list_spec.rb +0 -39
  55. data/spec/unit/openstack_server_create_spec.rb +0 -449
  56. data/spec/unit/openstack_server_delete_spec.rb +0 -43
  57. data/spec/unit/openstack_server_list_spec.rb +0 -32
  58. data/spec/unit/openstack_server_show_spec.rb +0 -42
  59. data/spec/unit/openstack_service_spec.rb +0 -128
  60. data/spec/unit/openstack_volume_list_spec.rb +0 -30
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Vasundhara Jagdale (<vasundhara.jagdale@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/openstack_floating_ip_list"
21
- require "chef/knife/cloud/openstack_service"
22
- require "support/shared_examples_for_command"
23
-
24
- describe Chef::Knife::Cloud::OpenstackFloatingIpList do
25
- let (:instance) { Chef::Knife::Cloud::OpenstackFloatingIpList.new }
26
-
27
- context "functionality" do
28
- before do
29
- resources = [TestResource.new("id" => "floatingip1", "instance_id" => "daed9e86-4b69-4242-993a-926a39352783", "ip" => "173.236.251.98", "fixed_ip" => "", "pool" => "test-pool"
30
- ),
31
- TestResource.new("id" => "floatingip2", "instance_id" => "", "ip" => "67.205.60.122", "fixed_ip" => "10.10.10.1", "pool" => "test-pool"
32
- ),
33
- ]
34
- allow(instance).to receive(:query_resource).and_return(resources)
35
- allow(instance).to receive(:puts)
36
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
37
- allow(instance).to receive(:validate!)
38
- instance.config[:format] = "summary"
39
- end
40
-
41
- it "lists formatted list of resources" do
42
- expect(instance.ui).to receive(:list).with(["ID", "Instance ID", "IP Address", "Fixed IP", "Floating IP Pool",
43
- "floatingip1", "daed9e86-4b69-4242-993a-926a39352783", "173.236.251.98", "", "test-pool",
44
- "floatingip2", "", "67.205.60.122", "10.10.10.1", "test-pool"], :uneven_columns_across, 5)
45
- instance.run
46
- end
47
- end
48
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
4
- # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
5
- # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
6
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
7
- # License:: Apache License, Version 2.0
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
-
21
- require "spec_helper"
22
- require "chef/knife/openstack_group_list"
23
- require "chef/knife/cloud/openstack_service"
24
-
25
- describe Chef::Knife::Cloud::OpenstackGroupList do
26
- let (:instance) { Chef::Knife::Cloud::OpenstackGroupList.new }
27
-
28
- context "functionality" do
29
- before do
30
- resources = [TestResource.new("name" => "Unrestricted",
31
- "description" => "All ports open",
32
- "security_group_rules" => [TestResource.new("from_port" => 1,
33
- "group" => {},
34
- "ip_protocol" => "tcp",
35
- "to_port" => 636,
36
- "parent_group_id" => 14,
37
- "ip_range" => { "cidr" => "0.0.0.0/0" },
38
- "id" => 1),
39
- ]),
40
- TestResource.new("name" => "WindowsDomain",
41
- "description" => "Allows common protocols useful in a Windows domain",
42
- "security_group_rules" => [TestResource.new("from_port" => 22,
43
- "group" => {},
44
- "ip_protocol" => "tcp",
45
- "to_port" => 636,
46
- "parent_group_id" => 14,
47
- "ip_range" => { "cidr" => "0.0.0.0/0" },
48
- "id" => 2),
49
- ]),
50
- ]
51
- allow(instance).to receive(:query_resource).and_return(resources)
52
- allow(instance).to receive(:puts)
53
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
54
- allow(instance).to receive(:validate!)
55
- instance.config[:format] = "summary"
56
- end
57
-
58
- it "lists formatted list of resources" do
59
- expect(instance.ui).to receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description",
60
- "Unrestricted", "tcp", "1", "636", "0.0.0.0/0", "All ports open",
61
- "WindowsDomain", "tcp", "22", "636", "0.0.0.0/0", "Allows common protocols useful in a Windows domain"], :uneven_columns_across, 6)
62
- instance.run
63
- end
64
- end
65
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
4
- # Author:: Ameya Varade (<ameya.varade@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/openstack_image_list"
22
- require "chef/knife/cloud/openstack_service"
23
-
24
- describe Chef::Knife::Cloud::OpenstackImageList do
25
- let (:instance) { Chef::Knife::Cloud::OpenstackImageList.new }
26
-
27
- context "functionality" do
28
- before do
29
- resources = [TestResource.new(id: "resource-1", name: "image01", metadata: {}),
30
- TestResource.new(id: "resource-2", name: "initrd", metadata: {}),
31
- ]
32
- allow(instance).to receive(:query_resource).and_return(resources)
33
- allow(instance).to receive(:puts)
34
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
35
- allow(instance).to receive(:validate!)
36
- instance.config[:format] = "summary"
37
- end
38
-
39
- it "displays formatted list of images, filtered by default" do
40
- expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
41
- "image01", "resource-1", "no"], :uneven_columns_across, 3)
42
- instance.run
43
- end
44
-
45
- it "lists all images when disable_filter = true" do
46
- instance.config[:disable_filter] = true
47
- expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
48
- "image01", "resource-1", "no",
49
- "initrd", "resource-2", "no"], :uneven_columns_across, 3)
50
- instance.run
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
4
- # Copyright:: Copyright (c) 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/openstack_network_list"
21
- require "chef/knife/cloud/openstack_service"
22
- require "support/shared_examples_for_command"
23
-
24
- describe Chef::Knife::Cloud::OpenstackNetworkList do
25
- let (:instance) { Chef::Knife::Cloud::OpenstackNetworkList.new }
26
-
27
- context "functionality" do
28
- before do
29
- resources = [TestResource.new(id: "resource-1", name: "external", tenant_id: "1", shared: true),
30
- TestResource.new(id: "resource-2", name: "internal", tenant_id: "2", shared: false),
31
- ]
32
- allow(instance).to receive(:query_resource).and_return(resources)
33
- allow(instance).to receive(:puts)
34
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
35
- allow(instance).to receive(:validate!)
36
- instance.config[:format] = "summary"
37
- end
38
-
39
- it "lists formatted list of network resources" do
40
- expect(instance.ui).to receive(:list).with(["Name", "ID", "Tenant", "Shared",
41
- "external", "resource-1", "1", "true",
42
- "internal", "resource-2", "2", "false"], :uneven_columns_across, 4)
43
- instance.run
44
- end
45
- end
46
- end
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
4
- # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
5
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
6
- # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
7
- # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
8
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
9
- # License:: Apache License, Version 2.0
10
- #
11
- # Licensed under the Apache License, Version 2.0 (the "License");
12
- # you may not use this file except in compliance with the License.
13
- # You may obtain a copy of the License at
14
- #
15
- # http://www.apache.org/licenses/LICENSE-2.0
16
- #
17
- # Unless required by applicable law or agreed to in writing, software
18
- # distributed under the License is distributed on an "AS IS" BASIS,
19
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- # See the License for the specific language governing permissions and
21
- # limitations under the License.
22
-
23
- require File.expand_path("../../spec_helper", __FILE__)
24
-
25
- describe Chef::Knife::Cloud::OpenstackServerCreate do
26
- before do
27
- @knife_openstack_create = Chef::Knife::Cloud::OpenstackServerCreate.new
28
- {
29
- image: "image",
30
- openstack_username: "openstack_username",
31
- openstack_password: "openstack_password",
32
- openstack_auth_url: "openstack_auth_url",
33
- server_create_timeout: 1000,
34
- }.each do |key, value|
35
- Chef::Config[:knife][key] = value
36
- end
37
-
38
- @openstack_service = Chef::Knife::Cloud::OpenstackService.new
39
- allow(@openstack_service).to receive(:msg_pair)
40
- allow(@openstack_service).to receive(:print)
41
- image = Object.new
42
- allow(image).to receive(:id).and_return("image_id")
43
- allow(@openstack_service).to receive(:get_image).and_return(image)
44
- flavor = Object.new
45
- allow(flavor).to receive(:id).and_return("flavor_id")
46
- allow(@openstack_service).to receive(:get_flavor).and_return(flavor)
47
-
48
- allow(@knife_openstack_create).to receive(:create_service_instance).and_return(@openstack_service)
49
- allow(@knife_openstack_create).to receive(:puts)
50
- @new_openstack_server = double
51
-
52
- @openstack_server_attribs = { name: "Mock Server",
53
- id: "id-123456",
54
- key_name: "key_name",
55
- flavor: "flavor_id",
56
- image: "image_id",
57
- addresses: {
58
- "public" => [{ "addr" => "75.101.253.10" }],
59
- "private" => [{ "addr" => "10.251.75.20" }],
60
- },
61
- password: "password",
62
- }
63
-
64
- @openstack_server_attribs.each_pair do |attrib, value|
65
- allow(@new_openstack_server).to receive(attrib).and_return(value)
66
- end
67
- end
68
-
69
- describe "run" do
70
- before(:each) do
71
- allow(@knife_openstack_create).to receive(:validate_params!)
72
- allow(Fog::Compute::OpenStack).to receive_message_chain(:new, :servers, :create).and_return(@new_openstack_server)
73
- @knife_openstack_create.config[:openstack_floating_ip] = "-1"
74
- allow(@new_openstack_server).to receive(:wait_for)
75
- end
76
-
77
- context "for Linux" do
78
- before do
79
- @config = { openstack_floating_ip: "-1", bootstrap_ip_address: "75.101.253.10", ssh_password: "password", hints: { "openstack" => {} } }
80
- @knife_openstack_create.config[:distro] = "chef-full"
81
- @bootstrapper = Chef::Knife::Cloud::Bootstrapper.new(@config)
82
- @ssh_bootstrap_protocol = Chef::Knife::Cloud::SshBootstrapProtocol.new(@config)
83
- @unix_distribution = Chef::Knife::Cloud::UnixDistribution.new(@config)
84
- allow(@ssh_bootstrap_protocol).to receive(:send_bootstrap_command)
85
- end
86
-
87
- it "Creates an OpenStack instance and bootstraps it" do
88
- expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper)
89
- allow(@bootstrapper).to receive(:bootstrap).and_call_original
90
- expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@ssh_bootstrap_protocol)
91
- expect(@bootstrapper).to receive(:create_bootstrap_distribution).and_return(@unix_distribution)
92
- expect(@openstack_service).to receive(:server_summary).exactly(2).times
93
- @knife_openstack_create.run
94
- end
95
- end
96
-
97
- context "for Windows" do
98
- before do
99
- @config = { openstack_floating_ip: "-1", image_os_type: "windows", bootstrap_ip_address: "75.101.253.10", bootstrap_protocol: "winrm", ssh_password: "password", hints: { "openstack" => {} } }
100
- @knife_openstack_create.config[:image_os_type] = "windows"
101
- @knife_openstack_create.config[:bootstrap_protocol] = "winrm"
102
- @knife_openstack_create.config[:distro] = "windows-chef-client-msi"
103
- @bootstrapper = Chef::Knife::Cloud::Bootstrapper.new(@config)
104
- @winrm_bootstrap_protocol = Chef::Knife::Cloud::WinrmBootstrapProtocol.new(@config)
105
- @windows_distribution = Chef::Knife::Cloud::WindowsDistribution.new(@config)
106
- end
107
- it "Creates an OpenStack instance for Windows and bootstraps it" do
108
- expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper)
109
- allow(@bootstrapper).to receive(:bootstrap).and_call_original
110
- expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@winrm_bootstrap_protocol)
111
- expect(@bootstrapper).to receive(:create_bootstrap_distribution).and_return(@windows_distribution)
112
- allow(@winrm_bootstrap_protocol).to receive(:send_bootstrap_command)
113
- expect(@openstack_service).to receive(:server_summary).exactly(2).times
114
- @knife_openstack_create.run
115
- end
116
- end
117
- end
118
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
4
- # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
5
- # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
6
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
7
- # License:: Apache License, Version 2.0
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
-
21
- require File.expand_path("../../spec_helper", __FILE__)
22
- require "chef/knife/openstack_server_delete"
23
- require "chef/knife/cloud/openstack_service"
24
-
25
- describe Chef::Knife::Cloud::OpenstackServerDelete do
26
- before do
27
- @openstack_connection = double(Fog::Compute::OpenStack)
28
- @chef_node = double(Chef::Node)
29
- @chef_client = double(Chef::ApiClient)
30
- @knife_openstack_delete = Chef::Knife::Cloud::OpenstackServerDelete.new
31
- {
32
- openstack_username: "openstack_username",
33
- openstack_password: "openstack_password",
34
- openstack_auth_url: "openstack_auth_url",
35
- }.each do |key, value|
36
- Chef::Config[:knife][key] = value
37
- end
38
-
39
- @openstack_service = Chef::Knife::Cloud::OpenstackService.new
40
- allow(@openstack_service).to receive(:msg_pair)
41
- allow(@knife_openstack_delete).to receive(:create_service_instance).and_return(@openstack_service)
42
- allow(@knife_openstack_delete.ui).to receive(:warn)
43
- allow(@knife_openstack_delete.ui).to receive(:confirm)
44
- @openstack_servers = double
45
- @running_openstack_server = double
46
- @openstack_server_attribs = { name: "Mock Server",
47
- id: "id-123456",
48
- flavor: "flavor_id",
49
- image: "image_id",
50
- addresses: {
51
- "public" => [{ "addr" => "75.101.253.10" }],
52
- "private" => [{ "addr" => "10.251.75.20" }],
53
- },
54
- }
55
-
56
- @openstack_server_attribs.each_pair do |attrib, value|
57
- allow(@running_openstack_server).to receive(attrib).and_return(value)
58
- end
59
- @knife_openstack_delete.name_args = ["test001"]
60
- end
61
-
62
- describe "run" do
63
- it "deletes an OpenStack instance." do
64
- expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server)
65
- expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers)
66
- expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection)
67
- expect(@running_openstack_server).to receive(:destroy)
68
- @knife_openstack_delete.run
69
- end
70
-
71
- it "deletes the instance along with the node and client on the chef-server when --purge is given as an option." do
72
- @knife_openstack_delete.config[:purge] = true
73
- expect(Chef::Node).to receive(:load).and_return(@chef_node)
74
- expect(@chef_node).to receive(:destroy)
75
- expect(Chef::ApiClient).to receive(:load).and_return(@chef_client)
76
- expect(@chef_client).to receive(:destroy)
77
- expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server)
78
- expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers)
79
- expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection)
80
- expect(@running_openstack_server).to receive(:destroy)
81
- @knife_openstack_delete.run
82
- end
83
- end
84
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
4
- # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
5
- # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
6
- # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
7
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
8
- # License:: Apache License, Version 2.0
9
- #
10
- # Licensed under the Apache License, Version 2.0 (the "License");
11
- # you may not use this file except in compliance with the License.
12
- # You may obtain a copy of the License at
13
- #
14
- # http://www.apache.org/licenses/LICENSE-2.0
15
- #
16
- # Unless required by applicable law or agreed to in writing, software
17
- # distributed under the License is distributed on an "AS IS" BASIS,
18
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- # See the License for the specific language governing permissions and
20
- # limitations under the License.
21
-
22
- require "spec_helper"
23
- require "chef/knife/openstack_server_list"
24
- require "chef/knife/cloud/openstack_service"
25
-
26
- describe Chef::Knife::Cloud::OpenstackServerList do
27
- let (:instance) { Chef::Knife::Cloud::OpenstackServerList.new }
28
-
29
- context "functionality" do
30
- before do
31
- @resources = [TestResource.new(id: "resource-1", name: "ubuntu01", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }], "private" => [{ "version" => 4, "addr" => "172.31.6.133" }] }, flavor: { "id" => "1" }, image: { "id" => "image1" }, key_name: "keypair", state: "ACTIVE"),
32
- TestResource.new(id: "resource-2", name: "windows2008", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }] }, flavor: { "id" => "id2" }, image: { "id" => "image2" }, key_name: "keypair", state: "ACTIVE"),
33
- TestResource.new(id: "resource-3-err", name: "windows2008", availability_zone: "test zone", addresses: { "public" => [], "private" => [] }, flavor: { "id" => "id2" }, image: { "id" => "image2" }, key_name: "keypair", state: "ERROR"),
34
- ]
35
- allow(instance).to receive(:query_resource).and_return(@resources)
36
- allow(instance).to receive(:puts)
37
- allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::FogService.new)
38
- allow(instance).to receive(:validate!)
39
- instance.config[:format] = "summary"
40
- end
41
-
42
- it "lists formatted list of resources" do
43
- expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone",
44
- "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone",
45
- "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone",
46
- "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone"], :uneven_columns_across, 8)
47
- instance.run
48
- end
49
-
50
- context "when chef-data and chef-node-attribute set" do
51
- before(:each) do
52
- @resources.push(TestResource.new(id: "server-4", name: "server-4", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }], "private" => [{ "version" => 4, "addr" => "172.31.6.133" }] }, flavor: { "id" => "1" }, image: { "id" => "image1" }, key_name: "keypair", state: "ACTIVE"))
53
- @node = TestResource.new(id: "server-4", name: "server-4", chef_environment: "_default", fqdn: "testfqdnnode.us", run_list: [], tags: [], platform: "ubuntu", platform_family: "debian")
54
- allow(Chef::Node).to receive(:list).and_return("server-4" => @node)
55
- instance.config[:chef_data] = true
56
- end
57
-
58
- it "lists formatted list of resources on chef data option set" do
59
- expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform",
60
- "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu",
61
- "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "",
62
- "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "",
63
- "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", ""], :uneven_columns_across, 14)
64
- instance.run
65
- end
66
-
67
- it "lists formatted list of resources on chef-data and chef-node-attribute option set" do
68
- instance.config[:chef_node_attribute] = "platform_family"
69
- expect(@node).to receive(:attribute?).with("platform_family").and_return(true)
70
- expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "platform_family",
71
- "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", "debian",
72
- "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "",
73
- "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "",
74
- "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", "", ""], :uneven_columns_across, 15)
75
- instance.run
76
- end
77
-
78
- it "raise error on invalid chef-node-attribute set" do
79
- instance.config[:chef_node_attribute] = "invalid_attribute"
80
- expect(instance.ui).to receive(:fatal)
81
- expect(@node).to receive(:attribute?).with("invalid_attribute").and_return(false)
82
- expect(instance.ui).to receive(:error).with("The Node does not have a invalid_attribute attribute.")
83
- expect { instance.run }.to raise_error
84
- end
85
-
86
- it "not display chef-data on chef-node-attribute set but chef-data option missing" do
87
- instance.config[:chef_data] = false
88
- instance.config[:chef_node_attribute] = "platform_family"
89
- expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone",
90
- "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone",
91
- "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone",
92
- "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone",
93
- "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone"], :uneven_columns_across, 8)
94
- instance.run
95
- end
96
- end
97
- end
98
- end