torpedo 1.0.19 → 2.1.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.
- data/CHANGELOG +9 -0
- data/LICENSE.txt +2 -1
- data/README.md +3 -3
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/bin/torpedo +0 -1
- data/lib/torpedo.rb +131 -22
- data/lib/torpedo/cleanup.rb +74 -0
- data/lib/torpedo/compute/flavors.rb +22 -22
- data/lib/torpedo/compute/helper.rb +79 -85
- data/lib/torpedo/compute/images.rb +23 -23
- data/lib/torpedo/compute/keypairs.rb +36 -0
- data/lib/torpedo/compute/limits.rb +15 -10
- data/lib/torpedo/compute/servers.rb +458 -382
- data/lib/torpedo/metering/helper.rb +43 -0
- data/lib/torpedo/metering/meters.rb +67 -0
- data/lib/torpedo/net_util.rb +66 -0
- data/lib/torpedo/orchestration/helper.rb +43 -0
- data/lib/torpedo/orchestration/stacks.rb +117 -0
- data/lib/torpedo/orchestration/test_server.hot +31 -0
- data/lib/torpedo/volume/helper.rb +43 -0
- data/lib/torpedo/volume/volumes.rb +114 -0
- data/torpedo.gemspec +30 -19
- metadata +44 -18
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
* Wed Oct 2 2013 Dan Prince <dprince@redhat.com> - 2.0.0
|
2
|
+
-Switch from openstack-compute to fog.
|
3
|
+
-Add 'network_namespace' option which can be used when testing
|
4
|
+
Neutron namespaces.
|
5
|
+
-Add support for volumes.
|
6
|
+
-Add support for keypairs.
|
7
|
+
-Add support for metering.
|
8
|
+
-Add support for orchestration.
|
9
|
+
|
1
10
|
* Thu Feb 14 2013 Dan Prince <dprince@redhat.com> - 1.0.19
|
2
11
|
-Added NETWORK_LABEL option. (defaults to 'public')
|
3
12
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Installation
|
|
11
11
|
|
12
12
|
1. Install the Gem.
|
13
13
|
2. Create the torpedo.conf file in your HOME directory.
|
14
|
-
3. Source
|
14
|
+
3. Source the rc file for your OpenStack account (keystone credentials, etc).
|
15
15
|
|
16
16
|
```bash
|
17
17
|
gem install torpedo
|
@@ -54,7 +54,7 @@ Installation
|
|
54
54
|
#keyname: test
|
55
55
|
EOF_CAT
|
56
56
|
|
57
|
-
source $PATH_TO_YOUR/
|
57
|
+
source $PATH_TO_YOUR/openstackrc
|
58
58
|
```
|
59
59
|
|
60
60
|
Examples
|
@@ -108,4 +108,4 @@ Payload
|
|
108
108
|
|
109
109
|
License
|
110
110
|
-------
|
111
|
-
Copyright (c) 2011-
|
111
|
+
Copyright (c) 2011-2013 Dan Prince. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -19,13 +19,14 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.homepage = "http://github.com/dprince/torpedo"
|
20
20
|
gem.license = "MIT"
|
21
21
|
gem.summary = %Q{Fire when ready. Fast Ruby integration tests for OpenStack.}
|
22
|
-
gem.description = %Q{Fast integration tests OpenStack
|
23
|
-
gem.email = "
|
22
|
+
gem.description = %Q{Fast integration tests for OpenStack.}
|
23
|
+
gem.email = "dprince@redhat.com"
|
24
24
|
gem.authors = ["Dan Prince"]
|
25
25
|
# dependencies defined in Gemfile
|
26
|
-
gem.add_dependency 'thor'
|
27
|
-
gem.add_dependency '
|
28
|
-
gem.add_dependency
|
26
|
+
gem.add_dependency 'thor'
|
27
|
+
gem.add_dependency 'test-unit'
|
28
|
+
gem.add_dependency 'fog'
|
29
|
+
gem.add_dependency 'net-ssh'
|
29
30
|
end
|
30
31
|
Jeweler::RubygemsDotOrgTasks.new
|
31
32
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
2.1.0
|
data/bin/torpedo
CHANGED
data/lib/torpedo.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'torpedo/config'
|
3
3
|
|
4
|
+
if RUBY_VERSION =~ /^1.9.*/ then
|
5
|
+
gem 'test-unit'
|
6
|
+
end
|
7
|
+
require 'test/unit'
|
8
|
+
require 'test/unit/ui/console/testrunner'
|
9
|
+
|
4
10
|
configs = Torpedo::Config.load_configs
|
5
11
|
|
6
12
|
SSH_TIMEOUT=(configs['ssh_timeout'] || 30).to_i
|
@@ -9,6 +15,7 @@ PING_TIMEOUT=(configs['ping_timeout'] || 60).to_i
|
|
9
15
|
TEST_PING=configs.fetch('test_ping', true)
|
10
16
|
SERVER_BUILD_TIMEOUT=(configs['server_build_timeout'] || 60).to_i
|
11
17
|
NETWORK_LABEL=(configs['network_label'] || 'public')
|
18
|
+
NETWORK_NAMESPACE=configs['network_namespace']
|
12
19
|
SLEEP_AFTER_IMAGE_CREATE=(configs['sleep_after_image_create'] || 0).to_i
|
13
20
|
SSH_PRIVATE_KEY=configs['ssh_private_key'] || ENV['HOME'] + "/.ssh/id_rsa"
|
14
21
|
SSH_PUBLIC_KEY=configs['ssh_public_key'] || ENV['HOME'] + "/.ssh/id_rsa.pub"
|
@@ -24,8 +31,8 @@ TEST_IP_TYPE=configs['test_ip_type'] || 4
|
|
24
31
|
TEST_LIMITS=configs.fetch('test_limits', true)
|
25
32
|
CLEAN_UP_SERVERS=configs.fetch('clean_up_servers', true)
|
26
33
|
CLEAN_UP_IMAGES=configs.fetch('clean_up_images', true)
|
27
|
-
|
28
|
-
|
34
|
+
CLEAN_UP_KEYPAIRS=configs.fetch('clean_up_keypairs', true)
|
35
|
+
KEYPAIR_ENABLED = configs.fetch('keypairs', false)
|
29
36
|
|
30
37
|
IMAGE_REF=configs['image_ref']
|
31
38
|
IMAGE_NAME=configs['image_name']
|
@@ -36,58 +43,160 @@ FLAVOR_NAME=configs['flavor_name']
|
|
36
43
|
FLAVOR_REF_RESIZE=configs['flavor_ref_resize']
|
37
44
|
FLAVOR_NAME_RESIZE=configs['flavor_name_resize']
|
38
45
|
|
39
|
-
|
46
|
+
#volume opts
|
47
|
+
volume_opts=configs['volumes'] || {}
|
48
|
+
VOLUME_ENABLED = volume_opts.fetch('enabled', false)
|
49
|
+
VOLUME_BUILD_TIMEOUT = (volume_opts['build_timeout'] || 120).to_i
|
50
|
+
TEST_VOLUME_SNAPSHOTS = volume_opts.fetch('test_snapshots', false)
|
51
|
+
CLEAN_UP_VOLUMES = volume_opts.fetch('cleanup', true)
|
52
|
+
|
53
|
+
#metering opts
|
54
|
+
metering_opts=configs['metering'] || {}
|
55
|
+
METERING_ENABLED = metering_opts.fetch('enabled', false)
|
56
|
+
METERING_SAMPLE_TIMEOUT = (metering_opts['sample_timeout'] || 360).to_i
|
57
|
+
|
58
|
+
#orchestration opts
|
59
|
+
orchestration_opts=configs['orchestration'] || {}
|
60
|
+
ORCHESTRATION_ENABLED = orchestration_opts.fetch('enabled', false)
|
61
|
+
STACK_CREATE_TIMEOUT = (orchestration_opts['stack_create_timeout'] || 120).to_i
|
62
|
+
CLEAN_UP_STACKS = orchestration_opts.fetch('cleanup', true)
|
40
63
|
|
41
|
-
|
64
|
+
FOG_VERSION=configs['fog_version']
|
42
65
|
|
66
|
+
TORPEDO_TEST_SUITE = Test::Unit::TestSuite.new("Torpedo")
|
43
67
|
module Torpedo
|
44
|
-
|
68
|
+
|
69
|
+
class TorpedoTests
|
70
|
+
def self.suite
|
71
|
+
return TORPEDO_TEST_SUITE
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Tasks < Thor
|
45
76
|
|
46
77
|
desc "flavors", "Run flavors tests for the OSAPI."
|
47
78
|
def flavors
|
48
79
|
require 'torpedo/compute/flavors'
|
80
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Flavors.suite
|
81
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
49
82
|
end
|
50
83
|
|
51
84
|
desc "limits", "Run limits tests for the OSAPI."
|
52
85
|
def limits
|
53
86
|
require 'torpedo/compute/limits'
|
87
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Limits.suite
|
88
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
54
89
|
end
|
55
90
|
|
56
91
|
desc "images", "Run images tests for the OSAPI."
|
57
92
|
def images
|
58
93
|
require 'torpedo/compute/images'
|
94
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Images.suite
|
95
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
59
96
|
end
|
60
97
|
|
61
98
|
desc "servers", "Run servers tests for the OSAPI."
|
62
99
|
def servers
|
100
|
+
require 'torpedo/volume/volumes'
|
101
|
+
require 'torpedo/compute/keypairs'
|
63
102
|
require 'torpedo/compute/servers'
|
103
|
+
require 'torpedo/metering/meters'
|
104
|
+
require 'torpedo/cleanup'
|
105
|
+
if VOLUME_ENABLED
|
106
|
+
TORPEDO_TEST_SUITE << Torpedo::Volume::Volumes.suite
|
107
|
+
end
|
108
|
+
if KEYPAIR_ENABLED
|
109
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Keypairs.suite
|
110
|
+
end
|
111
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Servers.suite
|
112
|
+
if METERING_ENABLED
|
113
|
+
TORPEDO_TEST_SUITE << Torpedo::Metering::Meters.suite
|
114
|
+
end
|
115
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
116
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
64
117
|
end
|
65
118
|
|
66
|
-
desc "
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
119
|
+
desc "keypairs", "Run keypair tests for the OSAPI."
|
120
|
+
def keypairs
|
121
|
+
require 'torpedo/compute/keypairs'
|
122
|
+
require 'torpedo/cleanup'
|
123
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Keypairs.suite
|
124
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
125
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
126
|
+
end
|
127
|
+
|
128
|
+
desc "volumes", "Run volume tests for the OSAPI."
|
129
|
+
def volumes
|
130
|
+
require 'torpedo/volume/volumes'
|
131
|
+
require 'torpedo/cleanup'
|
132
|
+
TORPEDO_TEST_SUITE << Torpedo::Volume::Volumes.suite
|
133
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
134
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "orchestration", "Run orchestration tests for the OSAPI."
|
138
|
+
def orchestration
|
139
|
+
require 'torpedo/compute/keypairs'
|
140
|
+
require 'torpedo/orchestration/stacks'
|
141
|
+
require 'torpedo/cleanup'
|
142
|
+
if KEYPAIR_ENABLED
|
143
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Keypairs.suite
|
82
144
|
end
|
145
|
+
TORPEDO_TEST_SUITE << Torpedo::Orchestration::Stacks.suite
|
146
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
147
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
148
|
+
end
|
149
|
+
|
150
|
+
desc "cleanup", "Clean up servers, images, volumes, etc."
|
151
|
+
def cleanup
|
152
|
+
require 'torpedo/cleanup'
|
153
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
154
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
83
155
|
end
|
84
156
|
|
85
157
|
desc "all", "Run all tests."
|
86
158
|
def all
|
159
|
+
require 'torpedo/compute/keypairs'
|
160
|
+
require 'torpedo/orchestration/stacks'
|
87
161
|
require 'torpedo/compute/flavors'
|
88
162
|
require 'torpedo/compute/limits'
|
89
163
|
require 'torpedo/compute/images'
|
164
|
+
require 'torpedo/volume/volumes'
|
90
165
|
require 'torpedo/compute/servers'
|
166
|
+
require 'torpedo/metering/meters'
|
167
|
+
require 'torpedo/cleanup'
|
168
|
+
if KEYPAIR_ENABLED
|
169
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Keypairs.suite
|
170
|
+
end
|
171
|
+
if ORCHESTRATION_ENABLED
|
172
|
+
TORPEDO_TEST_SUITE << Torpedo::Orchestration::Stacks.suite
|
173
|
+
end
|
174
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Flavors.suite
|
175
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Limits.suite
|
176
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Images.suite
|
177
|
+
if VOLUME_ENABLED
|
178
|
+
TORPEDO_TEST_SUITE << Torpedo::Volume::Volumes.suite
|
179
|
+
end
|
180
|
+
TORPEDO_TEST_SUITE << Torpedo::Compute::Servers.suite
|
181
|
+
if METERING_ENABLED
|
182
|
+
TORPEDO_TEST_SUITE << Torpedo::Metering::Meters.suite
|
183
|
+
end
|
184
|
+
TORPEDO_TEST_SUITE << Torpedo::Cleanup.suite
|
185
|
+
exit Test::Unit::UI::Console::TestRunner.run(TorpedoTests).passed?
|
186
|
+
end
|
187
|
+
|
188
|
+
desc "ssh", "Test ssh connectivity on a server."
|
189
|
+
method_options :ip_address => :string
|
190
|
+
method_options :test_command => :string
|
191
|
+
method_options :test_output => :string
|
192
|
+
method_options :admin_password => :string
|
193
|
+
def ssh(options=(options or {}))
|
194
|
+
require 'torpedo/net_util'
|
195
|
+
if Torpedo::NetUtil.ssh_test(options[:ip_address], nil, options[:test_command], options[:test_output], options[:admin_password]) then
|
196
|
+
exit 0
|
197
|
+
else
|
198
|
+
exit 1
|
199
|
+
end
|
91
200
|
end
|
92
201
|
|
93
202
|
desc "fire", "Fire away! (alias for all)"
|
@@ -95,5 +204,5 @@ class Tasks < Thor
|
|
95
204
|
invoke :all
|
96
205
|
end
|
97
206
|
|
98
|
-
end
|
207
|
+
end
|
99
208
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'torpedo'
|
2
|
+
require 'torpedo/compute/helper'
|
3
|
+
require 'torpedo/volume/helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Torpedo
|
7
|
+
|
8
|
+
class Cleanup < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_999_cleanup
|
11
|
+
if ORCHESTRATION_ENABLED and CLEAN_UP_STACKS then
|
12
|
+
orchestration_conn = Torpedo::Orchestration::Helper::get_connection
|
13
|
+
orchestration_conn.stacks.each do |stack|
|
14
|
+
stack = orchestration_conn.stacks.get(stack.id)
|
15
|
+
if stack.stack_name == 'torpedo'
|
16
|
+
#puts 'Deleting torpedo stack'
|
17
|
+
assert(stack.destroy)
|
18
|
+
# We wait for the stack to be deleted here to avoid pulling
|
19
|
+
# the rug on heat (and causing a potential log ERROR)
|
20
|
+
begin
|
21
|
+
timeout(STACK_CREATE_TIMEOUT) do
|
22
|
+
until orchestration_conn.stacks.get(stack.id).nil? do
|
23
|
+
sleep(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue Timeout::Error => te
|
27
|
+
fail('Timeout deleting stack.')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
compute_conn = Torpedo::Compute::Helper::get_connection
|
34
|
+
if CLEAN_UP_SERVERS
|
35
|
+
compute_conn.servers.each do |server|
|
36
|
+
server = compute_conn.servers.get(server.id)
|
37
|
+
if server.name == 'torpedo'
|
38
|
+
#puts 'Deleting torpedo server'
|
39
|
+
assert(server.destroy)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if CLEAN_UP_IMAGES
|
44
|
+
compute_conn.images.each do |image|
|
45
|
+
image = compute_conn.images.get(image.id)
|
46
|
+
if image.name == 'torpedo'
|
47
|
+
#puts 'Deleting torpedo image'
|
48
|
+
assert(image.destroy)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if KEYPAIR_ENABLED and CLEAN_UP_KEYPAIRS then
|
53
|
+
compute_conn.key_pairs.each do |key_pair|
|
54
|
+
key_pair = compute_conn.key_pairs.get(key_pair.name)
|
55
|
+
if key_pair.name == 'torpedo'
|
56
|
+
#puts 'Deleting torpedo key_pair'
|
57
|
+
assert(key_pair.destroy)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
if VOLUME_ENABLED and CLEAN_UP_VOLUMES then
|
62
|
+
volume_conn = Torpedo::Volume::Helper::get_connection
|
63
|
+
volume_conn.volumes.each do |volume|
|
64
|
+
volume = volume_conn.volumes.get(volume.id)
|
65
|
+
if volume.display_name == 'torpedo'
|
66
|
+
#puts 'Deleting torpedo volume'
|
67
|
+
assert(volume.destroy)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
3
|
module Torpedo
|
4
|
-
module Compute
|
5
|
-
class Flavors < Test::Unit::TestCase
|
4
|
+
module Compute
|
5
|
+
class Flavors < Test::Unit::TestCase
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def setup
|
8
|
+
@conn=Helper::get_connection
|
9
|
+
end
|
10
10
|
|
11
|
-
|
11
|
+
def test_list
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
@conn.flavors.each do |flavor|
|
14
|
+
assert_not_nil(flavor.id)
|
15
|
+
assert_not_nil(flavor.name)
|
16
|
+
assert_not_nil(flavor.ram)
|
17
|
+
assert_not_nil(flavor.disk)
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
end
|
21
21
|
|
22
|
-
|
22
|
+
def test_get
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
flavor = @conn.flavors.get(1)
|
25
|
+
assert_not_nil(flavor.id)
|
26
|
+
assert_not_nil(flavor.name)
|
27
|
+
assert_not_nil(flavor.ram)
|
28
|
+
assert_not_nil(flavor.disk)
|
29
29
|
|
30
|
-
|
30
|
+
end
|
31
31
|
|
32
|
-
end
|
33
|
-
end
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|
@@ -2,112 +2,106 @@ if RUBY_VERSION =~ /^1.9.*/ then
|
|
2
2
|
gem 'test-unit'
|
3
3
|
end
|
4
4
|
require 'test/unit'
|
5
|
-
if
|
6
|
-
gem '
|
5
|
+
if FOG_VERSION
|
6
|
+
gem 'fog', FOG_VERSION
|
7
7
|
end
|
8
|
-
require '
|
8
|
+
require 'fog'
|
9
9
|
|
10
10
|
module Torpedo
|
11
|
-
module Compute
|
12
|
-
module Helper
|
11
|
+
module Compute
|
12
|
+
module Helper
|
13
13
|
|
14
|
-
|
15
|
-
debug = false
|
16
|
-
if ENV['DEBUG'] and ENV['DEBUG'] == 'true' then
|
17
|
-
debug = true
|
18
|
-
end
|
19
|
-
|
20
|
-
auth_method = 'password'
|
21
|
-
if ENV['NOVA_RAX_AUTH'] and ENV['NOVA_RAX_AUTH'] == '1' then
|
22
|
-
auth_method = 'rax-kskey'
|
23
|
-
end
|
14
|
+
def self.get_connection
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
authtenant = ENV['NOVA_PROJECT_ID'] || ENV['OS_TENANT_NAME']
|
29
|
-
region = ENV['NOVA_REGION_NAME'] || ENV['OS_AUTH_REGION']
|
30
|
-
service_type = ENV['NOVA_SERVICE_TYPE'] || "compute"
|
31
|
-
service_name = ENV['NOVA_SERVICE_NAME'] #nil by default
|
32
|
-
|
33
|
-
OpenStack::Compute::Connection.new(
|
34
|
-
:username => username,
|
35
|
-
:api_key => api_key,
|
36
|
-
:auth_url => auth_url,
|
37
|
-
:region => region,
|
38
|
-
:authtenant => authtenant,
|
39
|
-
:is_debug => debug,
|
40
|
-
:auth_method => auth_method,
|
41
|
-
:service_name => service_name,
|
42
|
-
:service_type => service_type
|
43
|
-
)
|
44
|
-
|
45
|
-
end
|
16
|
+
if ENV['DEBUG'] and ENV['DEBUG'] == 'true' then
|
17
|
+
ENV['EXCON_DEBUG'] = 'true'
|
18
|
+
end
|
46
19
|
|
47
|
-
|
20
|
+
auth_url = ENV['NOVA_URL'] || ENV['OS_AUTH_URL']
|
21
|
+
api_key = ENV['NOVA_API_KEY'] || ENV['OS_PASSWORD']
|
22
|
+
username = ENV['NOVA_USERNAME'] || ENV['OS_USERNAME']
|
23
|
+
authtenant = ENV['NOVA_PROJECT_ID'] || ENV['OS_TENANT_NAME']
|
24
|
+
region = ENV['NOVA_REGION_NAME'] || ENV['OS_AUTH_REGION']
|
25
|
+
service_type = ENV['NOVA_SERVICE_TYPE'] || "compute"
|
26
|
+
service_name = ENV['NOVA_SERVICE_NAME'] #nil by default
|
27
|
+
|
28
|
+
Fog::Compute.new(
|
29
|
+
:provider => :openstack,
|
30
|
+
:openstack_auth_url => auth_url+'/tokens',
|
31
|
+
:openstack_username => username,
|
32
|
+
:openstack_tenant => authtenant,
|
33
|
+
:openstack_api_key => api_key,
|
34
|
+
:openstack_region => region,
|
35
|
+
:openstack_service_type => service_type,
|
36
|
+
:openstack_service_name => service_name
|
37
|
+
)
|
48
38
|
|
49
|
-
|
50
|
-
image_name = IMAGE_NAME
|
39
|
+
end
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
def self.get_image_ref(conn)
|
42
|
+
|
43
|
+
image_ref = IMAGE_REF
|
44
|
+
image_name = IMAGE_NAME
|
45
|
+
|
46
|
+
if image_name and not image_name.empty? then
|
47
|
+
images = conn.images.each do |image|
|
48
|
+
if image.name == image_name then
|
49
|
+
image_ref = image.id
|
50
|
+
end
|
51
|
+
end
|
52
|
+
elsif image_ref.nil? or image_ref.empty? then
|
53
|
+
#take the last image if IMAGE_REF and or IMAGE_NAME aren't set
|
54
|
+
images = conn.images
|
55
|
+
raise "Image list is empty." if images.empty?
|
56
|
+
image_ref = images.last.id.to_s
|
56
57
|
end
|
57
|
-
end
|
58
|
-
elsif image_ref.nil? or image_ref.empty? then
|
59
|
-
#take the last image if IMAGE_REF and or IMAGE_NAME aren't set
|
60
|
-
images = conn.images
|
61
|
-
raise "Image list is empty." if images.empty?
|
62
|
-
image_ref = images.last[:id].to_s
|
63
|
-
end
|
64
58
|
|
65
|
-
|
59
|
+
image_ref
|
66
60
|
|
67
|
-
|
61
|
+
end
|
68
62
|
|
69
|
-
|
63
|
+
def self.get_flavor_ref(conn)
|
70
64
|
|
71
|
-
|
72
|
-
|
65
|
+
flavor_ref = FLAVOR_REF
|
66
|
+
flavor_name = FLAVOR_NAME
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
if flavor_name and not flavor_name.empty? then
|
69
|
+
flavors = conn.flavors.each do |flavor|
|
70
|
+
if flavor.name == flavor_name then
|
71
|
+
flavor_ref = flavor.id
|
72
|
+
end
|
73
|
+
end
|
74
|
+
elsif not flavor_ref or flavor_ref.to_s.empty? then
|
75
|
+
# default to 2 (m1.small) if FLAVOR_REF and or FLAVOR_NAME aren't set
|
76
|
+
flavor_ref = 2
|
78
77
|
end
|
79
|
-
end
|
80
|
-
elsif not flavor_ref or flavor_ref.to_s.empty? then
|
81
|
-
# default to 2 (m1.small) if FLAVOR_REF and or FLAVOR_NAME aren't set
|
82
|
-
flavor_ref = 2
|
83
|
-
end
|
84
78
|
|
85
|
-
|
79
|
+
flavor_ref.to_s
|
86
80
|
|
87
|
-
|
81
|
+
end
|
88
82
|
|
89
|
-
|
90
|
-
|
83
|
+
#flavor ref used for resize
|
84
|
+
def self.get_flavor_ref_resize(conn)
|
85
|
+
|
86
|
+
flavor_ref_resize = FLAVOR_REF_RESIZE
|
87
|
+
flavor_name_resize = FLAVOR_NAME_RESIZE
|
88
|
+
|
89
|
+
if flavor_name_resize and not flavor_name_resize.empty? then
|
90
|
+
flavors = conn.flavors.each do |flavor|
|
91
|
+
if flavor.name == flavor_name_resize then
|
92
|
+
flavor_ref_resize = flavor.id
|
93
|
+
end
|
94
|
+
end
|
95
|
+
elsif not flavor_ref_resize or flavor_ref_resize.to_s.empty? then
|
96
|
+
# if no flavor ref is specified for resize add one to it
|
97
|
+
flavor_ref = Helper.get_flavor_ref(conn)
|
98
|
+
flavor_ref_resize = flavor_ref.to_i + 1
|
99
|
+
end
|
91
100
|
|
92
|
-
|
93
|
-
flavor_name_resize = FLAVOR_NAME_RESIZE
|
101
|
+
flavor_ref_resize.to_s
|
94
102
|
|
95
|
-
if flavor_name_resize and not flavor_name_resize.empty? then
|
96
|
-
flavors = conn.flavors.each do |flavor|
|
97
|
-
if flavor[:name] == flavor_name_resize then
|
98
|
-
flavor_ref_resize = flavor[:id]
|
99
|
-
end
|
100
103
|
end
|
101
|
-
elsif not flavor_ref_resize or flavor_ref_resize.to_s.empty? then
|
102
|
-
# if no flavor ref is specified for resize add one to it
|
103
|
-
flavor_ref = Helper.get_flavor_ref(conn)
|
104
|
-
flavor_ref_resize = flavor_ref.to_i + 1
|
105
|
-
end
|
106
|
-
|
107
|
-
flavor_ref_resize.to_s
|
108
104
|
|
105
|
+
end
|
109
106
|
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
113
107
|
end
|