knife-openstack 1.3.2.pre → 1.3.2.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/Rakefile +7 -28
- data/knife-openstack.gemspec +16 -16
- data/lib/chef/knife/cloud/openstack_server_create_options.rb +44 -44
- data/lib/chef/knife/cloud/openstack_service.rb +27 -31
- data/lib/chef/knife/cloud/openstack_service_options.rb +25 -26
- data/lib/chef/knife/openstack_flavor_list.rb +9 -10
- data/lib/chef/knife/openstack_floating_ip_allocate.rb +4 -4
- data/lib/chef/knife/openstack_floating_ip_associate.rb +5 -5
- data/lib/chef/knife/openstack_floating_ip_disassociate.rb +4 -4
- data/lib/chef/knife/openstack_group_list.rb +9 -11
- data/lib/chef/knife/openstack_helpers.rb +14 -2
- data/lib/chef/knife/openstack_image_list.rb +14 -15
- data/lib/chef/knife/openstack_network_list.rb +8 -9
- data/lib/chef/knife/openstack_server_create.rb +81 -84
- data/lib/chef/knife/openstack_server_delete.rb +25 -26
- data/lib/chef/knife/openstack_server_list.rb +13 -19
- data/lib/chef/knife/openstack_server_show.rb +11 -12
- data/lib/chef/knife/openstack_volume_list.rb +10 -12
- data/lib/knife-openstack/version.rb +1 -1
- data/spec/functional/flavor_list_func_spec.rb +11 -11
- data/spec/functional/floating_ip_list_func_spec.rb +11 -11
- data/spec/functional/group_list_func_spec.rb +27 -31
- data/spec/functional/image_list_func_spec.rb +14 -14
- data/spec/functional/network_list_func_spec.rb +10 -10
- data/spec/functional/server_create_func_spec.rb +23 -24
- data/spec/functional/server_delete_func_spec.rb +16 -17
- data/spec/functional/server_list_func_spec.rb +39 -39
- data/spec/functional/server_show_func_spec.rb +4 -5
- data/spec/functional/volume_list_func_spec.rb +9 -9
- data/spec/integration/cleanup.rb +8 -11
- data/spec/integration/openstack_spec.rb +377 -347
- data/spec/spec_context.rb +10 -10
- data/spec/spec_helper.rb +23 -27
- data/spec/unit/openstack_flavor_list_spec.rb +1 -1
- data/spec/unit/openstack_floating_ip_allocate_spec.rb +2 -3
- data/spec/unit/openstack_floating_ip_associate_spec.rb +2 -2
- data/spec/unit/openstack_floating_ip_disassociate_spec.rb +3 -3
- data/spec/unit/openstack_floating_ip_release_spec.rb +1 -1
- data/spec/unit/openstack_group_list_spec.rb +7 -7
- data/spec/unit/openstack_image_list_spec.rb +2 -2
- data/spec/unit/openstack_network_list_spec.rb +4 -4
- data/spec/unit/openstack_server_create_spec.rb +117 -118
- data/spec/unit/openstack_server_delete_spec.rb +4 -4
- data/spec/unit/openstack_server_list_spec.rb +2 -2
- data/spec/unit/openstack_server_show_spec.rb +6 -6
- data/spec/unit/openstack_service_spec.rb +20 -20
- data/spec/unit/openstack_volume_list_spec.rb +1 -1
- metadata +30 -2
@@ -22,16 +22,15 @@ require 'chef/knife/openstack_server_delete'
|
|
22
22
|
require 'chef/knife/cloud/openstack_service'
|
23
23
|
|
24
24
|
describe Chef::Knife::Cloud::OpenstackServerDelete do
|
25
|
-
|
26
25
|
before do
|
27
26
|
@openstack_connection = double(Fog::Compute::OpenStack)
|
28
27
|
@chef_node = double(Chef::Node)
|
29
28
|
@chef_client = double(Chef::ApiClient)
|
30
29
|
@knife_openstack_delete = Chef::Knife::Cloud::OpenstackServerDelete.new
|
31
30
|
{
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
31
|
+
openstack_username: 'openstack_username',
|
32
|
+
openstack_password: 'openstack_password',
|
33
|
+
openstack_auth_url: 'openstack_auth_url'
|
35
34
|
}.each do |key, value|
|
36
35
|
Chef::Config[:knife][key] = value
|
37
36
|
end
|
@@ -41,16 +40,16 @@ describe Chef::Knife::Cloud::OpenstackServerDelete do
|
|
41
40
|
allow(@knife_openstack_delete).to receive(:create_service_instance).and_return(@openstack_service)
|
42
41
|
allow(@knife_openstack_delete.ui).to receive(:warn)
|
43
42
|
allow(@knife_openstack_delete.ui).to receive(:confirm)
|
44
|
-
@openstack_servers = double
|
45
|
-
@running_openstack_server = double
|
46
|
-
@openstack_server_attribs = { :
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
'public' => [{'addr' => '75.101.253.10'}],
|
52
|
-
'private' => [{'addr' => '10.251.75.20'}]
|
53
|
-
|
43
|
+
@openstack_servers = double
|
44
|
+
@running_openstack_server = double
|
45
|
+
@openstack_server_attribs = { name: 'Mock Server',
|
46
|
+
id: 'id-123456',
|
47
|
+
flavor: 'flavor_id',
|
48
|
+
image: 'image_id',
|
49
|
+
addresses: {
|
50
|
+
'public' => [{ 'addr' => '75.101.253.10' }],
|
51
|
+
'private' => [{ 'addr' => '10.251.75.20' }]
|
52
|
+
}
|
54
53
|
}
|
55
54
|
|
56
55
|
@openstack_server_attribs.each_pair do |attrib, value|
|
@@ -59,8 +58,8 @@ describe Chef::Knife::Cloud::OpenstackServerDelete do
|
|
59
58
|
@knife_openstack_delete.name_args = ['test001']
|
60
59
|
end
|
61
60
|
|
62
|
-
describe
|
63
|
-
it
|
61
|
+
describe 'run' do
|
62
|
+
it 'deletes an OpenStack instance.' do
|
64
63
|
expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server)
|
65
64
|
expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers)
|
66
65
|
expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection)
|
@@ -68,7 +67,7 @@ describe Chef::Knife::Cloud::OpenstackServerDelete do
|
|
68
67
|
@knife_openstack_delete.run
|
69
68
|
end
|
70
69
|
|
71
|
-
it
|
70
|
+
it 'deletes the instance along with the node and client on the chef-server when --purge is given as an option.' do
|
72
71
|
@knife_openstack_delete.config[:purge] = true
|
73
72
|
expect(Chef::Node).to receive(:load).and_return(@chef_node)
|
74
73
|
expect(@chef_node).to receive(:destroy)
|
@@ -23,72 +23,72 @@ require 'chef/knife/openstack_server_list'
|
|
23
23
|
require 'chef/knife/cloud/openstack_service'
|
24
24
|
|
25
25
|
describe Chef::Knife::Cloud::OpenstackServerList do
|
26
|
-
let (:instance) {Chef::Knife::Cloud::OpenstackServerList.new}
|
26
|
+
let (:instance) { Chef::Knife::Cloud::OpenstackServerList.new }
|
27
27
|
|
28
|
-
context
|
28
|
+
context 'functionality' do
|
29
29
|
before do
|
30
|
-
@resources = [
|
31
|
-
|
32
|
-
|
30
|
+
@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'),
|
31
|
+
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'),
|
32
|
+
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')
|
33
33
|
]
|
34
34
|
allow(instance).to receive(:query_resource).and_return(@resources)
|
35
35
|
allow(instance).to receive(:puts)
|
36
36
|
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::FogService.new)
|
37
37
|
allow(instance).to receive(:validate!)
|
38
|
-
instance.config[:format] =
|
38
|
+
instance.config[:format] = 'summary'
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
expect(instance.ui).to receive(:list).with([
|
43
|
-
|
44
|
-
|
41
|
+
it 'lists formatted list of resources' do
|
42
|
+
expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Public IP', 'Private IP', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone',
|
43
|
+
'ubuntu01', 'resource-1', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone',
|
44
|
+
'windows2008', 'resource-2', '172.31.6.132', nil, 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', 'windows2008', 'resource-3-err', nil, nil, 'id2', 'image2', 'keypair', 'ERROR', 'test zone'], :uneven_columns_across, 9)
|
45
45
|
instance.run
|
46
46
|
end
|
47
47
|
|
48
|
-
context
|
48
|
+
context 'when chef-data and chef-node-attribute set' do
|
49
49
|
before(:each) do
|
50
|
-
@resources.push(TestResource.new(
|
51
|
-
@node = TestResource.new(
|
52
|
-
allow(Chef::Node).to receive(:list).and_return(
|
50
|
+
@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'))
|
51
|
+
@node = TestResource.new(id: 'server-4', name: 'server-4', chef_environment: '_default', fqdn: 'testfqdnnode.us', run_list: [], tags: [], platform: 'ubuntu', platform_family: 'debian')
|
52
|
+
allow(Chef::Node).to receive(:list).and_return('server-4' => @node)
|
53
53
|
instance.config[:chef_data] = true
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
expect(instance.ui).to receive(:list).with([
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
it 'lists formatted list of resources on chef data option set' do
|
57
|
+
expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Public IP', 'Private IP', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', 'Chef Node Name', 'Environment', 'FQDN', 'Runlist', 'Tags', 'Platform',
|
58
|
+
'server-4', 'server-4', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', 'server-4', '_default', 'testfqdnnode.us', '[]', '[]', 'ubuntu',
|
59
|
+
'ubuntu01', 'resource-1', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '',
|
60
|
+
'windows2008', 'resource-2', '172.31.6.132', nil, 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '',
|
61
|
+
'windows2008', 'resource-3-err', nil, nil, 'id2', 'image2', 'keypair', 'ERROR', 'test zone', '', '', '', '', '', ''], :uneven_columns_across, 15)
|
62
62
|
instance.run
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
instance.config[:chef_node_attribute] =
|
67
|
-
expect(@node).to receive(:attribute?).with(
|
68
|
-
expect(instance.ui).to receive(:list).with([
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
it 'lists formatted list of resources on chef-data and chef-node-attribute option set' do
|
66
|
+
instance.config[:chef_node_attribute] = 'platform_family'
|
67
|
+
expect(@node).to receive(:attribute?).with('platform_family').and_return(true)
|
68
|
+
expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Public IP', 'Private IP', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', 'Chef Node Name', 'Environment', 'FQDN', 'Runlist', 'Tags', 'Platform', 'platform_family',
|
69
|
+
'server-4', 'server-4', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', 'server-4', '_default', 'testfqdnnode.us', '[]', '[]', 'ubuntu', 'debian',
|
70
|
+
'ubuntu01', 'resource-1', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', '',
|
71
|
+
'windows2008', 'resource-2', '172.31.6.132', nil, 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', '',
|
72
|
+
'windows2008', 'resource-3-err', nil, nil, 'id2', 'image2', 'keypair', 'ERROR', 'test zone', '', '', '', '', '', '', ''], :uneven_columns_across, 16)
|
73
73
|
instance.run
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
instance.config[:chef_node_attribute] =
|
76
|
+
it 'raise error on invalid chef-node-attribute set' do
|
77
|
+
instance.config[:chef_node_attribute] = 'invalid_attribute'
|
78
78
|
expect(instance.ui).to receive(:fatal)
|
79
|
-
expect(@node).to receive(:attribute?).with(
|
80
|
-
expect(instance.ui).to receive(:error).with(
|
79
|
+
expect(@node).to receive(:attribute?).with('invalid_attribute').and_return(false)
|
80
|
+
expect(instance.ui).to receive(:error).with('The Node does not have a invalid_attribute attribute.')
|
81
81
|
expect { instance.run }.to raise_error
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'not display chef-data on chef-node-attribute set but chef-data option missing' do
|
85
85
|
instance.config[:chef_data] = false
|
86
|
-
instance.config[:chef_node_attribute] =
|
87
|
-
expect(instance.ui).to receive(:list).with([
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
instance.config[:chef_node_attribute] = 'platform_family'
|
87
|
+
expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Public IP', 'Private IP', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone',
|
88
|
+
'server-4', 'server-4', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone',
|
89
|
+
'ubuntu01', 'resource-1', '172.31.6.132', '172.31.6.133', '1', 'image1', 'keypair', 'ACTIVE', 'test zone',
|
90
|
+
'windows2008', 'resource-2', '172.31.6.132', nil, 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone',
|
91
|
+
'windows2008', 'resource-3-err', nil, nil, 'id2', 'image2', 'keypair', 'ERROR', 'test zone'], :uneven_columns_across, 9)
|
92
92
|
instance.run
|
93
93
|
end
|
94
94
|
end
|
@@ -20,18 +20,17 @@ require 'chef/knife/openstack_server_show'
|
|
20
20
|
require 'chef/knife/cloud/openstack_service'
|
21
21
|
|
22
22
|
describe Chef::Knife::Cloud::OpenstackServerShow do
|
23
|
-
|
24
|
-
context "functionality" do
|
23
|
+
context 'functionality' do
|
25
24
|
before do
|
26
25
|
@instance = Chef::Knife::Cloud::OpenstackServerShow.new
|
27
|
-
Chef::Config[:knife][:instance_id] =
|
26
|
+
Chef::Config[:knife][:instance_id] = 'instance_id'
|
28
27
|
@openstack_service = Chef::Knife::Cloud::OpenstackService.new
|
29
28
|
allow(@openstack_service).to receive(:msg_pair)
|
30
29
|
allow(@openstack_service).to receive(:print)
|
31
30
|
allow_message_expectations_on_nil
|
32
31
|
server = Object.new
|
33
32
|
conn = Object.new
|
34
|
-
conn.define_singleton_method(:servers){
|
33
|
+
conn.define_singleton_method(:servers) {}
|
35
34
|
allow(@openstack_service).to receive(:connection).and_return(conn)
|
36
35
|
expect(@openstack_service.connection.servers).to receive(:get).and_return(server)
|
37
36
|
allow(@instance).to receive(:create_service_instance).and_return(@openstack_service)
|
@@ -39,7 +38,7 @@ describe Chef::Knife::Cloud::OpenstackServerShow do
|
|
39
38
|
expect(@openstack_service).to receive(:server_summary)
|
40
39
|
end
|
41
40
|
|
42
|
-
it
|
41
|
+
it 'runs server show successfully' do
|
43
42
|
@instance.run
|
44
43
|
end
|
45
44
|
end
|
@@ -22,23 +22,23 @@ require 'chef/knife/cloud/openstack_service'
|
|
22
22
|
require 'support/shared_examples_for_command'
|
23
23
|
|
24
24
|
describe Chef::Knife::Cloud::OpenstackVolumeList do
|
25
|
-
let (:instance) {Chef::Knife::Cloud::OpenstackVolumeList.new}
|
25
|
+
let (:instance) { Chef::Knife::Cloud::OpenstackVolumeList.new }
|
26
26
|
|
27
|
-
context
|
27
|
+
context 'functionality' do
|
28
28
|
before do
|
29
|
-
resources = [
|
30
|
-
|
31
|
-
|
29
|
+
resources = [TestResource.new(id: 'volume-1', name: 'big-disk-volume', status: 'available', size: 1024, description: 'This is the big disk'),
|
30
|
+
TestResource.new(id: 'volume-2', name: 'little-disk-volume', status: 'in-use', size: 8, description: 'This is the little disk')
|
31
|
+
]
|
32
32
|
allow(instance).to receive(:query_resource).and_return(resources)
|
33
33
|
allow(instance).to receive(:puts)
|
34
34
|
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
|
35
35
|
allow(instance).to receive(:validate!)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
expect(instance.ui).to receive(:list).with([
|
40
|
-
|
41
|
-
|
38
|
+
it 'lists formatted list of resources' do
|
39
|
+
expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Status', 'Size', 'Description',
|
40
|
+
'big-disk-volume', 'volume-1', 'available', '1024 GB', 'This is the big disk',
|
41
|
+
'little-disk-volume', 'volume-2', 'in-use', '8 GB', 'This is the little disk'], :uneven_columns_across, 5)
|
42
42
|
instance.run
|
43
43
|
end
|
44
44
|
end
|
data/spec/integration/cleanup.rb
CHANGED
@@ -23,14 +23,12 @@ module CleanupTestResources
|
|
23
23
|
|
24
24
|
# OPENSTACK_USERNAME, OPENSTACK_PASSWORD and OPENSTACK_AUTH_URL are mandatory params to run knife openstack commands.
|
25
25
|
%w(OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL).each do |os_env_var|
|
26
|
-
if ENV[os_env_var].nil?
|
27
|
-
unset_env_var << os_env_var
|
28
|
-
end
|
26
|
+
unset_env_var << os_env_var if ENV[os_env_var].nil?
|
29
27
|
end
|
30
28
|
|
31
29
|
err_msg = "\nPlease set #{unset_env_var.join(', ')} environment"
|
32
|
-
err_msg = err_msg + (
|
33
|
-
|
30
|
+
err_msg = err_msg + (unset_env_var.length > 1 ? ' variables ' : ' variable ') + 'to cleanup test resources.'
|
31
|
+
unless unset_env_var.empty?
|
34
32
|
puts err_msg
|
35
33
|
exit 1
|
36
34
|
end
|
@@ -38,15 +36,14 @@ module CleanupTestResources
|
|
38
36
|
|
39
37
|
# Use Mixlib::ShellOut to run knife openstack commands.
|
40
38
|
def self.run(command_line)
|
41
|
-
shell_out = Mixlib::ShellOut.new("#{command_line}")
|
39
|
+
shell_out = Mixlib::ShellOut.new("#{command_line}")
|
42
40
|
shell_out.timeout = 3000
|
43
41
|
shell_out.run_command
|
44
|
-
|
42
|
+
shell_out
|
45
43
|
end
|
46
44
|
|
47
45
|
# Use knife openstack to delete servers.
|
48
46
|
def self.cleanup_resources
|
49
|
-
|
50
47
|
delete_resources = []
|
51
48
|
|
52
49
|
# Openstack credentials use during knife openstack command run.
|
@@ -66,9 +63,9 @@ module CleanupTestResources
|
|
66
63
|
|
67
64
|
# 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.
|
68
65
|
servers.each_line do |line|
|
69
|
-
if line.include?(
|
66
|
+
if line.include?('os-integration-test-') || (line.include?('openstack-') && line.include?('opscode-ci-ssh'))
|
70
67
|
# Extract and add instance id of server to delete_resources list.
|
71
|
-
delete_resources << {
|
68
|
+
delete_resources << { 'id' => line.split(' ').first, 'name' => line.split(' ')[1] }
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
@@ -88,4 +85,4 @@ module CleanupTestResources
|
|
88
85
|
end
|
89
86
|
|
90
87
|
CleanupTestResources.validate_params
|
91
|
-
CleanupTestResources.cleanup_resources
|
88
|
+
CleanupTestResources.cleanup_resources
|
@@ -21,40 +21,40 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
21
21
|
|
22
22
|
def append_openstack_creds(is_list_cmd = false)
|
23
23
|
openstack_creds_cmd = " --openstack-username '#{ENV['OPENSTACK_USERNAME']}' --openstack-password '#{ENV['OPENSTACK_PASSWORD']}' --openstack-api-endpoint #{ENV['OPENSTACK_AUTH_URL']}"
|
24
|
-
openstack_creds_cmd
|
25
|
-
|
26
|
-
openstack_creds_cmd
|
24
|
+
openstack_creds_cmd += " -c #{temp_dir}/knife.rb"
|
25
|
+
unless is_list_cmd
|
26
|
+
openstack_creds_cmd += " --openstack-tenant #{ENV['OPENSTACK_TENANT']}"
|
27
27
|
end
|
28
28
|
openstack_creds_cmd
|
29
29
|
end
|
30
30
|
|
31
31
|
def append_openstack_creds_for_windows
|
32
|
-
openstack_creds_cmd = " --openstack-username '#{ENV['OPENSTACK_USERNAME']}' --openstack-password '#{ENV['OPENSTACK_PASSWORD']}' --openstack-api-endpoint #{ENV['OPENSTACK_AUTH_URL']} "
|
33
|
-
openstack_creds_cmd
|
34
|
-
openstack_creds_cmd
|
32
|
+
openstack_creds_cmd = " --openstack-username '#{ENV['OPENSTACK_USERNAME']}' --openstack-password '#{ENV['OPENSTACK_PASSWORD']}' --openstack-api-endpoint #{ENV['OPENSTACK_AUTH_URL']} "
|
33
|
+
openstack_creds_cmd += " -c #{temp_dir}/knife.rb"
|
34
|
+
openstack_creds_cmd += " --openstack-tenant #{ENV['OPENSTACK_TENANT']}"
|
35
35
|
openstack_creds_cmd
|
36
36
|
end
|
37
37
|
|
38
38
|
def get_ssh_credentials
|
39
|
-
" --ssh-user #{@os_ssh_user}"
|
39
|
+
" --ssh-user #{@os_ssh_user}"\
|
40
40
|
" --openstack-ssh-key-id #{@openstack_key_pair}"
|
41
41
|
end
|
42
42
|
|
43
43
|
def get_ssh_credentials_for_windows_image
|
44
|
-
" --ssh-user #{@os_windows_ssh_user}"
|
45
|
-
" --ssh-password #{@os_windows_ssh_password}"
|
44
|
+
" --ssh-user #{@os_windows_ssh_user}"\
|
45
|
+
" --ssh-password #{@os_windows_ssh_password}"\
|
46
46
|
" --openstack-ssh-key-id #{@openstack_key_pair}"
|
47
47
|
end
|
48
48
|
|
49
49
|
def get_winrm_credentials
|
50
|
-
" --winrm-user #{@os_winrm_user}"
|
51
|
-
" --winrm-password #{@os_winrm_password}"
|
50
|
+
" --winrm-user #{@os_winrm_user}"\
|
51
|
+
" --winrm-password #{@os_winrm_password}"\
|
52
52
|
" --openstack-ssh-key-id #{@openstack_key_pair}"
|
53
53
|
end
|
54
54
|
|
55
55
|
# get openstack active instance_id for knife openstack show command run
|
56
56
|
def get_active_instance_id
|
57
|
-
server_list_output = run(
|
57
|
+
server_list_output = run('knife openstack server list ' + append_openstack_creds(is_list_cmd = true))
|
58
58
|
# Check command exitstatus. Non zero exitstatus indicates command execution fails.
|
59
59
|
if server_list_output.exitstatus != 0
|
60
60
|
puts "Please check Openstack user name, password and auth url are correct. Error: #{list_output.stderr}."
|
@@ -62,17 +62,17 @@ def get_active_instance_id
|
|
62
62
|
else
|
63
63
|
servers = server_list_output.stdout
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
servers.each_line do |line|
|
67
|
-
if line.include?(
|
68
|
-
instance_id = line.split(
|
67
|
+
if line.include?('ACTIVE')
|
68
|
+
instance_id = line.split(' ').first
|
69
69
|
return instance_id
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
false
|
73
73
|
end
|
74
74
|
|
75
|
-
describe 'knife-openstack integration test'
|
75
|
+
describe 'knife-openstack integration test', if: is_config_present do
|
76
76
|
include KnifeTestBed
|
77
77
|
include RSpec::KnifeTestUtils
|
78
78
|
|
@@ -88,61 +88,61 @@ describe 'knife-openstack integration test' , :if => is_config_present do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
describe 'display help for command' do
|
91
|
-
%w
|
91
|
+
%w(flavor\ list server\ create server\ delete server\ list group\ list image\ list network\ list ).each do |command|
|
92
92
|
context "when --help option used with #{command} command" do
|
93
93
|
let(:command) { "knife openstack #{command} --help" }
|
94
|
-
run_cmd_check_stdout(
|
94
|
+
run_cmd_check_stdout('--help')
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
describe 'display server list' do
|
100
100
|
context 'when standard options specified' do
|
101
|
-
let(:command) {
|
102
|
-
run_cmd_check_status_and_output(
|
101
|
+
let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) }
|
102
|
+
run_cmd_check_status_and_output('succeed', 'Instance ID')
|
103
103
|
end
|
104
104
|
|
105
105
|
context 'when --chef-data CLI option specified' do
|
106
|
-
let(:command) {
|
107
|
-
it {skip('setup a chef-zero on workspace node')}
|
106
|
+
let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data' }
|
107
|
+
it { skip('setup a chef-zero on workspace node') }
|
108
108
|
end
|
109
109
|
|
110
110
|
context 'when --chef-data and valid --chef-node-attribute CLI option specified' do
|
111
|
-
let(:command) {
|
112
|
-
it {skip('setup a chef-zero on workspace node')}
|
111
|
+
let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data --chef-node-attribute platform_family' }
|
112
|
+
it { skip('setup a chef-zero on workspace node') }
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'when --chef-data and In valid --chef-node-attribute CLI option specified' do
|
116
|
-
let(:command) {
|
117
|
-
it {skip('setup a chef-zero on workspace node')}
|
118
|
-
end
|
116
|
+
let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data --chef-node-attribute invalid' }
|
117
|
+
it { skip('setup a chef-zero on workspace node') }
|
118
|
+
end
|
119
119
|
end
|
120
120
|
|
121
121
|
describe 'display flavor list' do
|
122
122
|
context 'when standard options specified' do
|
123
|
-
let(:command) {
|
124
|
-
run_cmd_check_status_and_output(
|
123
|
+
let(:command) { 'knife openstack flavor list' + append_openstack_creds(is_list_cmd = true) }
|
124
|
+
run_cmd_check_status_and_output('succeed', 'ID')
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
describe 'display image list' do
|
129
129
|
context 'when standard options specified' do
|
130
|
-
let(:command) {
|
131
|
-
run_cmd_check_status_and_output(
|
130
|
+
let(:command) { 'knife openstack image list' + append_openstack_creds(is_list_cmd = true) }
|
131
|
+
run_cmd_check_status_and_output('succeed', 'ID')
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
describe 'display group list' do
|
136
136
|
context 'when standard options specified' do
|
137
|
-
let(:command) {
|
138
|
-
run_cmd_check_status_and_output(
|
137
|
+
let(:command) { 'knife openstack group list' + append_openstack_creds(is_list_cmd = true) }
|
138
|
+
run_cmd_check_status_and_output('succeed', 'Name')
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe 'display network list' do
|
143
143
|
context 'when standard options specified' do
|
144
|
-
let(:command) {
|
145
|
-
it {skip 'Chef openstack setup not support this functionality'}
|
144
|
+
let(:command) { 'knife openstack network list' + append_openstack_creds(is_list_cmd = true) }
|
145
|
+
it { skip 'Chef openstack setup not support this functionality' }
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -152,268 +152,285 @@ describe 'knife-openstack integration test' , :if => is_config_present do
|
|
152
152
|
@instance_id = get_active_instance_id
|
153
153
|
end
|
154
154
|
let(:command) { "knife openstack server show #{@instance_id}" + append_openstack_creds(is_list_cmd = true) }
|
155
|
-
run_cmd_check_status_and_output(
|
155
|
+
run_cmd_check_status_and_output('succeed', 'Instance ID')
|
156
156
|
end
|
157
157
|
|
158
158
|
context 'with invalid instance_id' do
|
159
|
-
let(:command) {
|
160
|
-
|
161
|
-
run_cmd_check_status_and_output(
|
159
|
+
let(:command) { 'knife openstack server show invalid_instance_id' + append_openstack_creds(is_list_cmd = true) }
|
160
|
+
|
161
|
+
run_cmd_check_status_and_output('fail', "ERROR: Server doesn't exists for this invalid_instance_id instance id")
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
describe 'create and bootstrap Linux Server'
|
166
|
-
before(:each) {rm_known_host}
|
165
|
+
describe 'create and bootstrap Linux Server' do
|
166
|
+
before(:each) { rm_known_host }
|
167
167
|
context 'when standard options specified' do
|
168
|
-
cmd_out =
|
168
|
+
cmd_out = ''
|
169
169
|
|
170
|
-
before(:each) { create_node_name(
|
170
|
+
before(:each) { create_node_name('linux') }
|
171
171
|
|
172
172
|
after { cmd_out = "#{cmd_output}" }
|
173
173
|
|
174
|
-
let(:command) {
|
175
|
-
|
176
|
-
"
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
174
|
+
let(:command) {
|
175
|
+
"knife openstack server create -N #{@name_node}"\
|
176
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
177
|
+
' --template-file ' + get_linux_template_file_path +
|
178
|
+
' --server-url http://localhost:8889' \
|
179
|
+
' --yes --server-create-timeout 1800' +
|
180
|
+
get_ssh_credentials +
|
181
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
182
|
+
}
|
182
183
|
|
183
|
-
run_cmd_check_status_and_output(
|
184
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
184
185
|
|
185
|
-
context
|
186
|
+
context 'delete server after create' do
|
186
187
|
let(:command) { delete_instance_cmd(cmd_out) }
|
187
|
-
run_cmd_check_status_and_output(
|
188
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
192
|
context 'when standard options and chef node name prefix is default value(i.e openstack)' do
|
192
|
-
let(:command) {
|
193
|
-
|
194
|
-
"
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
193
|
+
let(:command) {
|
194
|
+
'knife openstack server create '\
|
195
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
196
|
+
' --template-file ' + get_linux_template_file_path +
|
197
|
+
' --server-url http://localhost:8889' \
|
198
|
+
' --yes --server-create-timeout 1800' +
|
199
|
+
get_ssh_credentials +
|
200
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
201
|
+
}
|
200
202
|
|
201
203
|
after { run(delete_instance_cmd("#{cmd_output}")) }
|
202
204
|
|
203
|
-
run_cmd_check_status_and_output(
|
205
|
+
run_cmd_check_status_and_output('succeed', 'Bootstrapping Chef on')
|
204
206
|
end
|
205
207
|
|
206
208
|
context 'when standard options and chef node name prefix is user specified value' do
|
207
|
-
let(:command) {
|
208
|
-
|
209
|
-
"
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
209
|
+
let(:command) {
|
210
|
+
'knife openstack server create '\
|
211
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
212
|
+
' --template-file ' + get_linux_template_file_path +
|
213
|
+
' --server-url http://localhost:8889' \
|
214
|
+
' --yes --server-create-timeout 1800' \
|
215
|
+
' --chef-node-name-prefix os-integration-test-' +
|
216
|
+
get_ssh_credentials +
|
217
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
218
|
+
}
|
216
219
|
|
217
220
|
after { run(delete_instance_cmd("#{cmd_output}")) }
|
218
221
|
|
219
|
-
run_cmd_check_status_and_output(
|
222
|
+
run_cmd_check_status_and_output('succeed', 'os-integration-test-')
|
220
223
|
end
|
221
224
|
|
222
225
|
context 'when standard options and delete-server-on-failure specified' do
|
223
|
-
nodename =
|
224
|
-
before(:each) { create_node_name(
|
226
|
+
nodename = ''
|
227
|
+
before(:each) { create_node_name('linux') }
|
225
228
|
|
226
229
|
after { nodename = @name_node }
|
227
230
|
|
228
|
-
let(:command) {
|
229
|
-
|
230
|
-
"
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
231
|
+
let(:command) {
|
232
|
+
"knife openstack server create -N #{@name_node}"\
|
233
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
234
|
+
' --template-file ' + get_linux_template_file_path +
|
235
|
+
' --server-url http://localhost:8889' \
|
236
|
+
' --yes --server-create-timeout 1800' \
|
237
|
+
' --delete-server-on-failure' +
|
238
|
+
get_ssh_credentials +
|
239
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
240
|
+
}
|
241
|
+
|
242
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
243
|
+
|
244
|
+
context 'delete server by using name after create' do
|
245
|
+
let(:command) { "knife openstack server delete #{nodename} " + append_openstack_creds(is_list_cmd = true) + ' --yes' }
|
246
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
243
247
|
end
|
244
248
|
end
|
245
249
|
|
246
250
|
context 'when delete-server-on-failure specified and bootstrap fails' do
|
247
|
-
before(:each) { create_node_name(
|
248
|
-
|
249
|
-
let(:command) {
|
250
|
-
|
251
|
-
"
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
251
|
+
before(:each) { create_node_name('linux') }
|
252
|
+
|
253
|
+
let(:command) {
|
254
|
+
"knife openstack server create -N #{@name_node}"\
|
255
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
256
|
+
' --template-file ' + get_linux_template_file_path +
|
257
|
+
' --server-url http://localhost:8889' \
|
258
|
+
' --yes --server-create-timeout 1800' \
|
259
|
+
' --delete-server-on-failure' +
|
260
|
+
get_ssh_credentials +
|
261
|
+
" --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + ' --sudo'
|
262
|
+
}
|
263
|
+
|
264
|
+
run_cmd_check_status_and_output('fail', 'FATAL: Authentication Failed during bootstrapping')
|
260
265
|
end
|
261
266
|
|
262
267
|
context 'when openstack credentials not specified' do
|
263
|
-
before(:each) { create_node_name(
|
264
|
-
|
265
|
-
let(:command) {
|
266
|
-
|
267
|
-
"
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
268
|
+
before(:each) { create_node_name('linux') }
|
269
|
+
|
270
|
+
let(:command) {
|
271
|
+
"knife openstack server create -N #{@name_node}"\
|
272
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
273
|
+
' --template-file ' + get_linux_template_file_path +
|
274
|
+
' --server-url http://localhost:8889' \
|
275
|
+
' --yes --server-create-timeout 1800' +
|
276
|
+
get_ssh_credentials +
|
277
|
+
" --identity-file #{temp_dir}/openstack.pem --sudo"
|
278
|
+
}
|
272
279
|
|
273
|
-
run_cmd_check_status_and_output(
|
280
|
+
run_cmd_check_status_and_output('fail', "ERROR: You did not provide a valid 'Openstack Username' value")
|
274
281
|
end
|
275
282
|
|
276
283
|
context 'when ssh-password and identity-file parameters not specified' do
|
277
|
-
before(:each) { create_node_name(
|
278
|
-
|
279
|
-
let(:command) {
|
280
|
-
|
281
|
-
"
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
284
|
+
before(:each) { create_node_name('linux') }
|
285
|
+
|
286
|
+
let(:command) {
|
287
|
+
"knife openstack server create -N #{@name_node}"\
|
288
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
289
|
+
' --template-file ' + get_linux_template_file_path +
|
290
|
+
' --server-url http://localhost:8889' \
|
291
|
+
' --yes' +
|
292
|
+
append_openstack_creds + ' --sudo'
|
293
|
+
}
|
294
|
+
|
295
|
+
it { skip 'Chef openstack setup not support this functionality.' }
|
287
296
|
end
|
288
297
|
|
289
298
|
context 'when standard options and invalid openstack security group specified' do
|
290
|
-
before(:each) { create_node_name(
|
291
|
-
|
292
|
-
let(:command) {
|
293
|
-
|
294
|
-
"
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
299
|
+
before(:each) { create_node_name('linux') }
|
300
|
+
|
301
|
+
let(:command) {
|
302
|
+
"knife openstack server create -N #{@name_node}"\
|
303
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
304
|
+
' --template-file ' + get_linux_template_file_path +
|
305
|
+
' --server-url http://localhost:8889' \
|
306
|
+
' --yes' +
|
307
|
+
get_ssh_credentials +
|
308
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
309
|
+
' --openstack-groups invalid-invalid-1212' + append_openstack_creds + ' --sudo'
|
310
|
+
}
|
311
|
+
|
312
|
+
run_cmd_check_status_and_output('fail', 'Security group invalid-invalid-1212 not found')
|
303
313
|
end
|
304
314
|
|
305
315
|
context 'when standard options and invalid image id specified' do
|
306
|
-
before(:each) { create_node_name(
|
316
|
+
before(:each) { create_node_name('linux') }
|
307
317
|
|
308
|
-
let(:command) {
|
309
|
-
|
310
|
-
"
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
318
|
+
let(:command) {
|
319
|
+
"knife openstack server create -N #{@name_node}"\
|
320
|
+
" -I #{SecureRandom.hex(18)} -f #{@os_linux_flavor} "\
|
321
|
+
' --template-file ' + get_linux_template_file_path +
|
322
|
+
' --server-url http://localhost:8889' \
|
323
|
+
' --yes' +
|
324
|
+
get_ssh_credentials +
|
325
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
326
|
+
}
|
316
327
|
|
317
|
-
run_cmd_check_status_and_output(
|
328
|
+
run_cmd_check_status_and_output('fail', 'ERROR: You have not provided a valid image ID. Please note the options for this value are -I or --image')
|
318
329
|
end
|
319
330
|
|
320
331
|
context 'when standard options and invalid flavor id specified' do
|
321
|
-
before(:each) { create_node_name(
|
322
|
-
|
323
|
-
let(:command) {
|
324
|
-
|
325
|
-
"
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
332
|
+
before(:each) { create_node_name('linux') }
|
333
|
+
|
334
|
+
let(:command) {
|
335
|
+
"knife openstack server create -N #{@name_node}"\
|
336
|
+
" -I #{@os_linux_image} -f #{@os_invalid_flavor} "\
|
337
|
+
' --template-file ' + get_linux_template_file_path +
|
338
|
+
' --server-url http://localhost:8889' \
|
339
|
+
' --yes' +
|
340
|
+
get_ssh_credentials +
|
341
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
342
|
+
}
|
343
|
+
|
344
|
+
run_cmd_check_status_and_output('fail', 'ERROR: You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor')
|
333
345
|
end
|
334
346
|
|
335
347
|
context 'when standard options and invalid floating ip specified' do
|
336
|
-
before(:each) { create_node_name(
|
337
|
-
|
338
|
-
let(:command) {
|
339
|
-
|
340
|
-
"
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
+
before(:each) { create_node_name('linux') }
|
349
|
+
|
350
|
+
let(:command) {
|
351
|
+
"knife openstack server create -N #{@name_node}"\
|
352
|
+
" -I #{@os_linux_image} --openstack-floating-ip #{@os_invalid_floating_ip} "\
|
353
|
+
' --template-file ' + get_linux_template_file_path +
|
354
|
+
' --server-url http://localhost:8889' \
|
355
|
+
' --yes' +
|
356
|
+
get_ssh_credentials +
|
357
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
358
|
+
}
|
359
|
+
|
360
|
+
run_cmd_check_status_and_output('fail', 'ERROR: You have either requested an invalid floating IP address or none are available')
|
348
361
|
end
|
349
362
|
|
350
363
|
context 'when invalid key_pair specified' do
|
351
|
-
before(:each) { create_node_name(
|
364
|
+
before(:each) { create_node_name('linux') }
|
352
365
|
|
353
|
-
let(:command) {
|
354
|
-
|
355
|
-
"
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
366
|
+
let(:command) {
|
367
|
+
"knife openstack server create -N #{@name_node}"\
|
368
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
369
|
+
' --template-file ' + get_linux_template_file_path +
|
370
|
+
' --server-url http://localhost:8889' \
|
371
|
+
' --yes' \
|
372
|
+
" --ssh-user #{@os_ssh_user}"\
|
373
|
+
" --openstack-ssh-key-id #{SecureRandom.hex(6)}"\
|
374
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
375
|
+
}
|
362
376
|
|
363
|
-
run_cmd_check_status_and_output(
|
377
|
+
run_cmd_check_status_and_output('fail', 'Invalid key_name provided')
|
364
378
|
end
|
365
379
|
|
366
380
|
context 'when incorrect openstack private_key.pem file is used' do
|
367
381
|
server_create_common_bfr_aftr
|
368
382
|
|
369
|
-
let(:command) {
|
370
|
-
|
371
|
-
"
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
383
|
+
let(:command) {
|
384
|
+
"knife openstack server create -N #{@name_node}"\
|
385
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
386
|
+
' --template-file ' + get_linux_template_file_path +
|
387
|
+
' --server-url http://localhost:8889' \
|
388
|
+
' --yes' \
|
389
|
+
" --ssh-user #{@os_ssh_user}"\
|
390
|
+
" --openstack-ssh-key-id #{@openstack_key_pair}"\
|
391
|
+
" --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + ' --sudo'
|
392
|
+
}
|
378
393
|
|
379
|
-
run_cmd_check_status_and_output(
|
394
|
+
run_cmd_check_status_and_output('fail', 'FATAL: Authentication Failed during bootstrapping')
|
380
395
|
end
|
381
396
|
|
382
397
|
context 'when standard options and --openstack-private-network option specified' do
|
383
398
|
server_create_common_bfr_aftr
|
384
399
|
|
385
|
-
let(:command) {
|
386
|
-
|
387
|
-
"
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
400
|
+
let(:command) {
|
401
|
+
"knife openstack server create -N #{@name_node}"\
|
402
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
403
|
+
' --template-file ' + get_linux_template_file_path +
|
404
|
+
' --server-url http://localhost:8889' \
|
405
|
+
' --yes' +
|
406
|
+
get_ssh_credentials +
|
407
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
408
|
+
' --openstack-private-network' + append_openstack_creds + ' --sudo'
|
409
|
+
}
|
410
|
+
|
411
|
+
it { skip 'not yet supported' }
|
396
412
|
end
|
397
413
|
|
398
414
|
context 'when standard options and --openstack-floating-ip option specified' do
|
399
415
|
server_create_common_bfr_aftr
|
400
416
|
|
401
|
-
let(:command) {
|
402
|
-
|
403
|
-
"
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
417
|
+
let(:command) {
|
418
|
+
"knife openstack server create -N #{@name_node}"\
|
419
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
420
|
+
' --template-file ' + get_linux_template_file_path +
|
421
|
+
' --server-url http://localhost:8889' \
|
422
|
+
' --yes' +
|
423
|
+
get_ssh_credentials +
|
424
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
425
|
+
' --openstack-floating-ip' + append_openstack_creds + ' --sudo'
|
426
|
+
}
|
410
427
|
|
411
|
-
it {skip 'empty floating ip pool'}
|
428
|
+
it { skip 'empty floating ip pool' }
|
412
429
|
end
|
413
430
|
|
414
431
|
context 'when standard options and user data specified' do
|
415
|
-
before(:each) do
|
416
|
-
create_node_name(
|
432
|
+
before(:each) do
|
433
|
+
create_node_name('linux')
|
417
434
|
@user_data_file = create_sh_user_data_file
|
418
435
|
end
|
419
436
|
|
@@ -424,195 +441,208 @@ describe 'knife-openstack integration test' , :if => is_config_present do
|
|
424
441
|
run(delete_instance_cmd("#{cmd_output}"))
|
425
442
|
end
|
426
443
|
|
427
|
-
let(:command) {
|
428
|
-
|
429
|
-
"
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
444
|
+
let(:command) {
|
445
|
+
"knife openstack server create -N #{@name_node}"\
|
446
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
447
|
+
' --template-file ' + get_linux_template_file_path +
|
448
|
+
' --server-url http://localhost:8889' \
|
449
|
+
' --yes --server-create-timeout 1800' +
|
450
|
+
get_ssh_credentials +
|
451
|
+
" --identity-file #{temp_dir}/openstack.pem" \
|
452
|
+
" --user-data #{@user_data_file.path}" +
|
453
|
+
append_openstack_creds + ' --sudo -VV'
|
454
|
+
}
|
436
455
|
|
437
|
-
run_cmd_check_status_and_output(
|
456
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
438
457
|
end
|
439
458
|
|
440
459
|
context 'when standard options and no network option specified' do
|
441
460
|
server_create_common_bfr_aftr
|
442
461
|
|
443
|
-
let(:command) {
|
444
|
-
|
445
|
-
"
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
462
|
+
let(:command) {
|
463
|
+
"knife openstack server create -N #{@name_node}"\
|
464
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
465
|
+
' --template-file ' + get_linux_template_file_path +
|
466
|
+
' --server-url http://localhost:8889' \
|
467
|
+
' --yes --server-create-timeout 1800' \
|
468
|
+
' --no-network' +
|
469
|
+
get_ssh_credentials +
|
470
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
471
|
+
}
|
452
472
|
|
453
|
-
run_cmd_check_status_and_output(
|
473
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
454
474
|
end
|
455
475
|
|
456
476
|
context 'when standard options and openstack endpoint type option is specified' do
|
457
477
|
server_create_common_bfr_aftr
|
458
478
|
|
459
|
-
let(:command) {
|
460
|
-
|
461
|
-
"
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
479
|
+
let(:command) {
|
480
|
+
"knife openstack server create -N #{@name_node}"\
|
481
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
482
|
+
' --template-file ' + get_linux_template_file_path +
|
483
|
+
' --server-url http://localhost:8889' \
|
484
|
+
' --yes --server-create-timeout 1800' \
|
485
|
+
' --openstack-endpoint-type publicURL' +
|
486
|
+
get_ssh_credentials +
|
487
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
488
|
+
}
|
468
489
|
|
469
|
-
run_cmd_check_status_and_output(
|
490
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
470
491
|
end
|
471
492
|
|
472
493
|
context 'when standard options and openstack metadata option is specified' do
|
473
494
|
server_create_common_bfr_aftr
|
474
495
|
|
475
|
-
let(:command) {
|
476
|
-
|
477
|
-
"
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
496
|
+
let(:command) {
|
497
|
+
"knife openstack server create -N #{@name_node}"\
|
498
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
499
|
+
' --template-file ' + get_linux_template_file_path +
|
500
|
+
' --server-url http://localhost:8889' \
|
501
|
+
' --yes --server-create-timeout 1800' \
|
502
|
+
" --metadata testdataone='testmetadata'" +
|
503
|
+
get_ssh_credentials +
|
504
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
505
|
+
" --metadata testdatatwo='testmetadata'" +
|
506
|
+
append_openstack_creds + ' --sudo'
|
507
|
+
}
|
485
508
|
|
486
|
-
run_cmd_check_status_and_output(
|
509
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
487
510
|
end
|
488
511
|
|
489
512
|
context 'when standard options and openstack network-ids option is specified' do
|
490
513
|
server_create_common_bfr_aftr
|
491
514
|
|
492
|
-
let(:command) {
|
493
|
-
|
494
|
-
"
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
515
|
+
let(:command) {
|
516
|
+
"knife openstack server create -N #{@name_node}"\
|
517
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
518
|
+
' --template-file ' + get_linux_template_file_path +
|
519
|
+
' --server-url http://localhost:8889' \
|
520
|
+
' --yes --server-create-timeout 1800' \
|
521
|
+
" --network-ids #{@os_network_ids} " +
|
522
|
+
get_ssh_credentials +
|
523
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
524
|
+
}
|
501
525
|
|
502
|
-
it {skip 'Chef openstack setup not support this functionality'}
|
526
|
+
it { skip 'Chef openstack setup not support this functionality' }
|
503
527
|
end
|
504
528
|
|
505
529
|
context 'when standard options and openstack availability-zone option is specified' do
|
506
530
|
server_create_common_bfr_aftr
|
507
531
|
|
508
|
-
let(:command) {
|
509
|
-
|
510
|
-
"
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
532
|
+
let(:command) {
|
533
|
+
"knife openstack server create -N #{@name_node}"\
|
534
|
+
" -I #{@os_linux_image} -f #{@os_linux_flavor} "\
|
535
|
+
' --template-file ' + get_linux_template_file_path +
|
536
|
+
' --server-url http://localhost:8889' \
|
537
|
+
' --yes --server-create-timeout 1800' \
|
538
|
+
" --availability-zone #{@os_availability_zone} " +
|
539
|
+
get_ssh_credentials +
|
540
|
+
" --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo'
|
541
|
+
}
|
517
542
|
|
518
|
-
it {skip 'Chef openstack setup not support this functionality'}
|
543
|
+
it { skip 'Chef openstack setup not support this functionality' }
|
519
544
|
end
|
520
545
|
end
|
521
546
|
|
522
|
-
describe 'create and bootstrap Windows Server'
|
523
|
-
before(:each) {rm_known_host}
|
524
|
-
|
547
|
+
describe 'create and bootstrap Windows Server' do
|
548
|
+
before(:each) { rm_known_host }
|
549
|
+
|
525
550
|
context 'when standard options specified' do
|
526
|
-
cmd_out =
|
527
|
-
|
528
|
-
before(:each) { create_node_name(
|
529
|
-
|
530
|
-
let(:command) {
|
531
|
-
|
532
|
-
" -
|
533
|
-
"
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
551
|
+
cmd_out = ''
|
552
|
+
|
553
|
+
before(:each) { create_node_name('windows') }
|
554
|
+
|
555
|
+
let(:command) {
|
556
|
+
"knife openstack server create -N #{@name_node}" \
|
557
|
+
" -I #{@os_windows_image} " \
|
558
|
+
" -f #{@os_windows_flavor} " \
|
559
|
+
' --template-file ' + get_windows_msi_template_file_path +
|
560
|
+
' --server-url http://localhost:8889' \
|
561
|
+
' --bootstrap-protocol winrm' \
|
562
|
+
' --yes --server-create-timeout 1800' +
|
563
|
+
get_winrm_credentials + append_openstack_creds_for_windows
|
564
|
+
}
|
565
|
+
|
540
566
|
after { cmd_out = "#{cmd_output}" }
|
541
567
|
|
542
|
-
run_cmd_check_status_and_output(
|
568
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
543
569
|
|
544
|
-
context
|
570
|
+
context 'delete server after create' do
|
545
571
|
let(:command) { delete_instance_cmd(cmd_out) }
|
546
|
-
run_cmd_check_status_and_output(
|
572
|
+
run_cmd_check_status_and_output('succeed')
|
547
573
|
end
|
548
574
|
end
|
549
575
|
|
550
576
|
context 'when invalid winrm user specified' do
|
551
|
-
server_create_common_bfr_aftr(
|
552
|
-
|
553
|
-
let(:command) {
|
554
|
-
|
555
|
-
" -
|
556
|
-
"
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
577
|
+
server_create_common_bfr_aftr('windows')
|
578
|
+
|
579
|
+
let(:command) {
|
580
|
+
"knife openstack server create -N #{@name_node}" \
|
581
|
+
" -I #{@os_windows_image} " \
|
582
|
+
" -f #{@os_windows_flavor} " \
|
583
|
+
' --template-file ' + get_windows_msi_template_file_path +
|
584
|
+
' --server-url http://localhost:8889' \
|
585
|
+
' --bootstrap-protocol winrm' \
|
586
|
+
' --yes --server-create-timeout 1800' \
|
587
|
+
" --winrm-user #{SecureRandom.hex(6)}"\
|
588
|
+
" --winrm-password #{@os_winrm_password}" +
|
589
|
+
append_openstack_creds_for_windows
|
590
|
+
}
|
591
|
+
it { skip 'Fails due to OC-9708 bug in knife-windows.' }
|
564
592
|
end
|
565
593
|
|
566
594
|
context 'when invalid winrm password specified' do
|
567
|
-
server_create_common_bfr_aftr(
|
595
|
+
server_create_common_bfr_aftr('windows')
|
568
596
|
|
569
|
-
let(:command) {
|
570
|
-
|
571
|
-
" -
|
572
|
-
"
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
597
|
+
let(:command) {
|
598
|
+
"knife openstack server create -N #{@name_node}" \
|
599
|
+
" -I #{@os_windows_image} " \
|
600
|
+
" -f #{@os_windows_flavor} " \
|
601
|
+
' --template-file ' + get_windows_msi_template_file_path +
|
602
|
+
' --server-url http://localhost:8889' \
|
603
|
+
' --bootstrap-protocol winrm' \
|
604
|
+
' --yes --server-create-timeout 1800' \
|
605
|
+
" --winrm-user #{@os_winrm_user}"\
|
606
|
+
" --winrm-password #{SecureRandom.hex(6)}" +
|
607
|
+
append_openstack_creds_for_windows
|
608
|
+
}
|
609
|
+
after(:each) { run(delete_instance_cmd("#{cmd_output}")) }
|
580
610
|
|
581
|
-
it { skip
|
611
|
+
it { skip 'Fails due to OC-9708 bug in knife-windows.' }
|
582
612
|
end
|
583
613
|
|
584
614
|
context 'when standard options ssh bootstrap and valid image-os-type protocol specified' do
|
585
|
-
server_create_common_bfr_aftr(
|
615
|
+
server_create_common_bfr_aftr('windows')
|
586
616
|
|
587
|
-
let(:command) {
|
588
|
-
|
589
|
-
" -
|
590
|
-
"
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
617
|
+
let(:command) {
|
618
|
+
"knife openstack server create -N #{@name_node}"\
|
619
|
+
" -I #{@os_windows_ssh_image}"\
|
620
|
+
" -f #{@os_windows_flavor} "\
|
621
|
+
' --template-file ' + get_windows_msi_template_file_path +
|
622
|
+
' --server-url http://localhost:8889' \
|
623
|
+
' --yes --server-create-timeout 1800' \
|
624
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
625
|
+
" --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + ' --image-os-type windows'
|
626
|
+
}
|
597
627
|
|
598
|
-
run_cmd_check_status_and_output(
|
628
|
+
run_cmd_check_status_and_output('succeed', "#{@name_node}")
|
599
629
|
end
|
600
630
|
|
601
631
|
context 'when standard options ssh bootstrap and invalid image-os-type protocol specified' do
|
602
|
-
before(:each) { create_node_name(
|
632
|
+
before(:each) { create_node_name('windows') }
|
603
633
|
|
604
|
-
let(:command) {
|
605
|
-
|
606
|
-
" -
|
607
|
-
"
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
634
|
+
let(:command) {
|
635
|
+
"knife openstack server create -N #{@name_node}"\
|
636
|
+
" -I #{@os_windows_ssh_image}"\
|
637
|
+
" -f #{@os_windows_flavor} "\
|
638
|
+
' --template-file ' + get_windows_msi_template_file_path +
|
639
|
+
' --server-url http://localhost:8889' \
|
640
|
+
' --yes --server-create-timeout 1800' \
|
641
|
+
" --identity-file #{temp_dir}/openstack.pem"\
|
642
|
+
" --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + ' --image-os-type invalid'
|
643
|
+
}
|
614
644
|
|
615
|
-
run_cmd_check_status_and_output(
|
645
|
+
run_cmd_check_status_and_output('fail', 'ERROR: You must provide --image-os-type option [windows/linux]')
|
616
646
|
end
|
617
647
|
end
|
618
|
-
end
|
648
|
+
end
|