knife-openstack 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/chef/knife/cloud/openstack_server_create_options.rb +16 -1
- data/lib/chef/knife/cloud/openstack_service.rb +14 -2
- data/lib/chef/knife/cloud/openstack_service_options.rb +17 -1
- data/lib/chef/knife/openstack_flavor_list.rb +16 -2
- data/lib/chef/knife/openstack_floating_ip_allocate.rb +16 -2
- data/lib/chef/knife/openstack_floating_ip_associate.rb +17 -3
- data/lib/chef/knife/openstack_floating_ip_disassociate.rb +17 -3
- data/lib/chef/knife/openstack_floating_ip_list.rb +16 -2
- data/lib/chef/knife/openstack_floating_ip_release.rb +14 -2
- data/lib/chef/knife/openstack_group_list.rb +18 -1
- data/lib/chef/knife/openstack_helpers.rb +17 -1
- data/lib/chef/knife/openstack_image_list.rb +16 -2
- data/lib/chef/knife/openstack_network_list.rb +16 -2
- data/lib/chef/knife/openstack_server_create.rb +3 -4
- data/lib/chef/knife/openstack_server_delete.rb +14 -2
- data/lib/chef/knife/openstack_server_list.rb +3 -4
- data/lib/chef/knife/openstack_server_show.rb +1 -2
- data/lib/chef/knife/openstack_volume_list.rb +4 -4
- data/lib/knife-openstack/version.rb +2 -2
- metadata +8 -207
- data/.github/ISSUE_TEMPLATE.md +0 -21
- data/.gitignore +0 -32
- data/.travis.yml +0 -18
- data/CHANGELOG.md +0 -339
- data/CONTRIBUTING.MD +0 -164
- data/Gemfile +0 -5
- data/README.md +0 -179
- data/Rakefile +0 -29
- data/knife-openstack.gemspec +0 -41
- data/spec/functional/flavor_list_func_spec.rb +0 -47
- data/spec/functional/floating_ip_list_func_spec.rb +0 -48
- data/spec/functional/group_list_func_spec.rb +0 -65
- data/spec/functional/image_list_func_spec.rb +0 -53
- data/spec/functional/network_list_func_spec.rb +0 -46
- data/spec/functional/server_create_func_spec.rb +0 -118
- data/spec/functional/server_delete_func_spec.rb +0 -84
- data/spec/functional/server_list_func_spec.rb +0 -98
- data/spec/functional/server_show_func_spec.rb +0 -46
- data/spec/functional/volume_list_func_spec.rb +0 -46
- data/spec/integration/cleanup.rb +0 -89
- data/spec/integration/config/environment.yml.sample +0 -13
- data/spec/integration/openstack_spec.rb +0 -649
- data/spec/spec_context.rb +0 -56
- data/spec/spec_helper.rb +0 -128
- data/spec/unit/openstack_flavor_list_spec.rb +0 -30
- data/spec/unit/openstack_floating_ip_allocate_spec.rb +0 -56
- data/spec/unit/openstack_floating_ip_associate_spec.rb +0 -40
- data/spec/unit/openstack_floating_ip_disassociate_spec.rb +0 -39
- data/spec/unit/openstack_floating_ip_list_spec.rb +0 -27
- data/spec/unit/openstack_floating_ip_release_spec.rb +0 -49
- data/spec/unit/openstack_group_list_spec.rb +0 -44
- data/spec/unit/openstack_image_list_spec.rb +0 -32
- data/spec/unit/openstack_network_list_spec.rb +0 -39
- data/spec/unit/openstack_server_create_spec.rb +0 -449
- data/spec/unit/openstack_server_delete_spec.rb +0 -43
- data/spec/unit/openstack_server_list_spec.rb +0 -32
- data/spec/unit/openstack_server_show_spec.rb +0 -42
- data/spec/unit/openstack_service_spec.rb +0 -128
- data/spec/unit/openstack_volume_list_spec.rb +0 -30
@@ -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
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Ameya Varade (<ameya.varade@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_server_show"
|
21
|
-
require "chef/knife/cloud/openstack_service"
|
22
|
-
|
23
|
-
describe Chef::Knife::Cloud::OpenstackServerShow do
|
24
|
-
context "functionality" do
|
25
|
-
before do
|
26
|
-
@instance = Chef::Knife::Cloud::OpenstackServerShow.new
|
27
|
-
Chef::Config[:knife][:instance_id] = "instance_id"
|
28
|
-
@openstack_service = Chef::Knife::Cloud::OpenstackService.new
|
29
|
-
allow(@openstack_service).to receive(:msg_pair)
|
30
|
-
allow(@openstack_service).to receive(:print)
|
31
|
-
allow_message_expectations_on_nil
|
32
|
-
server = Object.new
|
33
|
-
conn = Object.new
|
34
|
-
conn.define_singleton_method(:servers) {}
|
35
|
-
allow(@openstack_service).to receive(:connection).and_return(conn)
|
36
|
-
expect(@openstack_service.connection.servers).to receive(:get).and_return(server)
|
37
|
-
allow(@instance).to receive(:create_service_instance).and_return(@openstack_service)
|
38
|
-
allow(@instance).to receive(:validate!)
|
39
|
-
expect(@openstack_service).to receive(:server_summary)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "runs server show successfully" do
|
43
|
-
@instance.run
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,46 +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_volume_list"
|
22
|
-
require "chef/knife/cloud/openstack_service"
|
23
|
-
require "support/shared_examples_for_command"
|
24
|
-
|
25
|
-
describe Chef::Knife::Cloud::OpenstackVolumeList do
|
26
|
-
let (:instance) { Chef::Knife::Cloud::OpenstackVolumeList.new }
|
27
|
-
|
28
|
-
context "functionality" do
|
29
|
-
before do
|
30
|
-
resources = [TestResource.new(id: "volume-1", name: "big-disk-volume", status: "available", size: 1024, description: "This is the big disk"),
|
31
|
-
TestResource.new(id: "volume-2", name: "little-disk-volume", status: "in-use", size: 8, description: "This is the little disk"),
|
32
|
-
]
|
33
|
-
allow(instance).to receive(:query_resource).and_return(resources)
|
34
|
-
allow(instance).to receive(:puts)
|
35
|
-
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
|
36
|
-
allow(instance).to receive(:validate!)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "lists formatted list of resources" do
|
40
|
-
expect(instance.ui).to receive(:list).with(["Name", "ID", "Status", "Size", "Description",
|
41
|
-
"big-disk-volume", "volume-1", "available", "1024 GB", "This is the big disk",
|
42
|
-
"little-disk-volume", "volume-2", "in-use", "8 GB", "This is the little disk"], :uneven_columns_across, 5)
|
43
|
-
instance.run
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/integration/cleanup.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright: Copyright (c) 2013-2014 Chef Software, Inc.
|
3
|
-
# License: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
18
|
-
|
19
|
-
require "mixlib/shellout"
|
20
|
-
|
21
|
-
module CleanupTestResources
|
22
|
-
def self.validate_params
|
23
|
-
unset_env_var = []
|
24
|
-
|
25
|
-
# OPENSTACK_USERNAME, OPENSTACK_PASSWORD and OPENSTACK_AUTH_URL are mandatory params to run knife openstack commands.
|
26
|
-
%w{OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL}.each do |os_env_var|
|
27
|
-
unset_env_var << os_env_var if ENV[os_env_var].nil?
|
28
|
-
end
|
29
|
-
|
30
|
-
err_msg = "\nPlease set #{unset_env_var.join(', ')} environment"
|
31
|
-
err_msg = err_msg + (unset_env_var.length > 1 ? " variables " : " variable ") + "to cleanup test resources."
|
32
|
-
unless unset_env_var.empty?
|
33
|
-
puts err_msg
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Use Mixlib::ShellOut to run knife openstack commands.
|
39
|
-
def self.run(command_line)
|
40
|
-
shell_out = Mixlib::ShellOut.new("#{command_line}")
|
41
|
-
shell_out.timeout = 3000
|
42
|
-
shell_out.run_command
|
43
|
-
shell_out
|
44
|
-
end
|
45
|
-
|
46
|
-
# Use knife openstack to delete servers.
|
47
|
-
def self.cleanup_resources
|
48
|
-
delete_resources = []
|
49
|
-
|
50
|
-
# Openstack credentials use during knife openstack command run.
|
51
|
-
openstack_creds = "--openstack-username '#{ENV['OPENSTACK_USERNAME']}' --openstack-password '#{ENV['OPENSTACK_PASSWORD']}' --openstack-api-endpoint #{ENV['OPENSTACK_AUTH_URL']}"
|
52
|
-
|
53
|
-
# List all servers in openstack using knife openstack server list command.
|
54
|
-
list_command = "knife openstack server list #{openstack_creds}"
|
55
|
-
list_output = run(list_command)
|
56
|
-
|
57
|
-
# Check command exitstatus. Non zero exitstatus indicates command execution fails.
|
58
|
-
if list_output.exitstatus != 0
|
59
|
-
puts "Cleanup Test Resources failed. Please check Openstack user name, password and auth url are correct. Error: #{list_output.stderr}."
|
60
|
-
exit list_output.exitstatus
|
61
|
-
else
|
62
|
-
servers = list_output.stdout
|
63
|
-
end
|
64
|
-
|
65
|
-
# We use "os-integration-test-<platform>-<randomNumber>" pattern for server name during integration tests run. So use "os-integration-test-" pattern to find out servers created during integration tests run.
|
66
|
-
servers.each_line do |line|
|
67
|
-
if line.include?("os-integration-test-") || (line.include?("openstack-") && line.include?("opscode-ci-ssh"))
|
68
|
-
# Extract and add instance id of server to delete_resources list.
|
69
|
-
delete_resources << { "id" => line.split(" ").first, "name" => line.split(" ")[1] }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Delete servers
|
74
|
-
delete_resources.each do |resource|
|
75
|
-
delete_command = "knife openstack server delete #{resource['id']} #{openstack_creds} --yes"
|
76
|
-
delete_output = run(delete_command)
|
77
|
-
|
78
|
-
# check command exitstatus. Non zero exitstatus indicates command execution fails.
|
79
|
-
if delete_output.exitstatus != 0
|
80
|
-
puts "Unable to delete server #{resource['name']}: #{resource['id']}. Error: #{delete_output.stderr}."
|
81
|
-
else
|
82
|
-
puts "Deleted server #{resource['name']}: #{resource['id']}."
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
CleanupTestResources.validate_params
|
89
|
-
CleanupTestResources.cleanup_resources
|