openstack_activeresource 0.3.5 → 0.4.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/Rakefile +8 -0
- data/VERSION +1 -1
- data/lib/open_stack/nova/compute.rb +1 -0
- data/lib/open_stack/nova/compute/quota_set.rb +91 -0
- data/openstack_activeresource.gemspec +15 -3
- data/test/test_keystone_authentications.rb +49 -0
- data/test/test_keystone_tenants.rb +29 -0
- data/test/test_keystone_users.rb +29 -0
- data/test/test_nova_flavors.rb +26 -0
- data/test/test_nova_floating_ips.rb +44 -0
- data/test/test_nova_images.rb +26 -0
- data/test/test_nova_keypairs.rb +48 -0
- data/test/test_nova_quota_sets.rb +70 -0
- data/test/test_nova_security_groups.rb +26 -0
- data/test/test_nova_servers.rb +68 -0
- data/test/test_simple_tenant_usages.rb +27 -0
- data/test/utils.rb +51 -0
- metadata +16 -4
- data/test/test_openstack-activeresource.rb +0 -303
data/Rakefile
CHANGED
|
@@ -42,3 +42,11 @@ Rake::RDocTask.new do |rdoc|
|
|
|
42
42
|
rdoc.rdoc_files.include('README*')
|
|
43
43
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
require 'rake/testtask'
|
|
47
|
+
|
|
48
|
+
Rake::TestTask.new do |t|
|
|
49
|
+
t.libs << "test"
|
|
50
|
+
t.test_files = FileList['test/test*.rb']
|
|
51
|
+
t.verbose = true
|
|
52
|
+
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.4.0
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# This file is part of the OpenStack-ActiveResource
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
module OpenStack
|
|
19
|
+
module Nova
|
|
20
|
+
module Compute
|
|
21
|
+
|
|
22
|
+
# An OpenStack Quota-Set
|
|
23
|
+
#
|
|
24
|
+
# ==== Attributes
|
|
25
|
+
# * +instances+ - Number of permitted instances
|
|
26
|
+
# * +cores+ - Number of instanceable cores
|
|
27
|
+
# * +ram+ - Quantity of instanceable RAM (MBytes)
|
|
28
|
+
# * +floating_ips+ - Number of floating IP
|
|
29
|
+
# * +key_pairs+ - Number of keypairs
|
|
30
|
+
# * +metadata_items+ - Metadata items permitted
|
|
31
|
+
# * +security_groups+ - Number of security groups permitted
|
|
32
|
+
# * +security_group_rules+ - Number of rules per security group permitted
|
|
33
|
+
# * +injected_files+ - Number of injectable files
|
|
34
|
+
# * +injected_file_content_bytes+ - Injected file maximum length
|
|
35
|
+
# * +injected_file_path_bytes+ - Injected file path name maximum length
|
|
36
|
+
class QuotaSet < Base
|
|
37
|
+
self.collection_name = "os-quota-sets"
|
|
38
|
+
|
|
39
|
+
schema do
|
|
40
|
+
attribute :instances, :integer
|
|
41
|
+
attribute :cores, :integer
|
|
42
|
+
attribute :ram, :integer
|
|
43
|
+
attribute :floating_ips, :integer
|
|
44
|
+
attribute :key_pairs, :integer
|
|
45
|
+
attribute :metadata_items, :integer
|
|
46
|
+
attribute :security_groups, :integer
|
|
47
|
+
attribute :security_group_rules, :integer
|
|
48
|
+
attribute :injected_files, :integer
|
|
49
|
+
attribute :injected_file_content_bytes, :integer
|
|
50
|
+
attribute :injected_file_path_bytes, :integer
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
validates :cores,
|
|
54
|
+
:presence => true,
|
|
55
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
56
|
+
validates :floating_ips,
|
|
57
|
+
:presence => true,
|
|
58
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
59
|
+
validates :injected_file_content_bytes,
|
|
60
|
+
:presence => true,
|
|
61
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
62
|
+
validates :injected_file_path_bytes,
|
|
63
|
+
:presence => true,
|
|
64
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
65
|
+
validates :injected_files,
|
|
66
|
+
:presence => true,
|
|
67
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
68
|
+
validates :instances,
|
|
69
|
+
:presence => true,
|
|
70
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
71
|
+
validates :key_pairs,
|
|
72
|
+
:presence => true,
|
|
73
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
74
|
+
validates :metadata_items,
|
|
75
|
+
:presence => true,
|
|
76
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
77
|
+
validates :ram,
|
|
78
|
+
:presence => true,
|
|
79
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
80
|
+
validates :security_group_rules,
|
|
81
|
+
:presence => true,
|
|
82
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
83
|
+
validates :security_groups,
|
|
84
|
+
:presence => true,
|
|
85
|
+
:numericality => {:greater_than_or_equal_to => 1, :allow_blank => true}
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "openstack_activeresource"
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.4.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Davide Guerri"]
|
|
12
|
-
s.date = "2013-02-
|
|
12
|
+
s.date = "2013-02-19"
|
|
13
13
|
s.description = "OpenStack Ruby and RoR bindings implemented with ActiveResource - See also http://www.unicloud.it"
|
|
14
14
|
s.email = "d.guerri@rd.unidata.it"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
|
|
|
53
53
|
"lib/open_stack/nova/compute/image.rb",
|
|
54
54
|
"lib/open_stack/nova/compute/key_pair.rb",
|
|
55
55
|
"lib/open_stack/nova/compute/network.rb",
|
|
56
|
+
"lib/open_stack/nova/compute/quota_set.rb",
|
|
56
57
|
"lib/open_stack/nova/compute/security_group.rb",
|
|
57
58
|
"lib/open_stack/nova/compute/server.rb",
|
|
58
59
|
"lib/open_stack/nova/compute/simple_tenant_usage.rb",
|
|
@@ -65,7 +66,18 @@ Gem::Specification.new do |s|
|
|
|
65
66
|
"test/.gitignore",
|
|
66
67
|
"test/helper.rb",
|
|
67
68
|
"test/test_configuration-sample.yml",
|
|
68
|
-
"test/
|
|
69
|
+
"test/test_keystone_authentications.rb",
|
|
70
|
+
"test/test_keystone_tenants.rb",
|
|
71
|
+
"test/test_keystone_users.rb",
|
|
72
|
+
"test/test_nova_flavors.rb",
|
|
73
|
+
"test/test_nova_floating_ips.rb",
|
|
74
|
+
"test/test_nova_images.rb",
|
|
75
|
+
"test/test_nova_keypairs.rb",
|
|
76
|
+
"test/test_nova_quota_sets.rb",
|
|
77
|
+
"test/test_nova_security_groups.rb",
|
|
78
|
+
"test/test_nova_servers.rb",
|
|
79
|
+
"test/test_simple_tenant_usages.rb",
|
|
80
|
+
"test/utils.rb"
|
|
69
81
|
]
|
|
70
82
|
s.homepage = "https://github.com/Unidata-SpA/openstack_activeresource"
|
|
71
83
|
s.licenses = ["GPLv3"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
# Keystone
|
|
15
|
+
|
|
16
|
+
# Authentication
|
|
17
|
+
|
|
18
|
+
def test_authentications
|
|
19
|
+
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
20
|
+
|
|
21
|
+
# User auth
|
|
22
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot authenticate as user" do
|
|
23
|
+
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:user_username],
|
|
24
|
+
:password => TEST_CONFIG[:user_password],
|
|
25
|
+
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
26
|
+
|
|
27
|
+
assert_not_nil auth.token, "Cannot authenticate as user"
|
|
28
|
+
|
|
29
|
+
auth = OpenStack::Keystone::Public::Auth.create :username => "baduser",
|
|
30
|
+
:password => "badpassword",
|
|
31
|
+
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
32
|
+
|
|
33
|
+
assert_nil auth.token, "Authentication seems broken!"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Admin auth
|
|
37
|
+
return unless admin_test_possible?
|
|
38
|
+
|
|
39
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot authenticate as admin" do
|
|
40
|
+
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:admin_username],
|
|
41
|
+
:password => TEST_CONFIG[:admin_password],
|
|
42
|
+
:tenant_id => TEST_CONFIG[:admin_tenant_id]
|
|
43
|
+
|
|
44
|
+
assert_not_nil auth.token, "Cannot authenticate as admin"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_list_tenant
|
|
15
|
+
return unless admin_test_possible?
|
|
16
|
+
|
|
17
|
+
auth_admin
|
|
18
|
+
|
|
19
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list tenants" do
|
|
20
|
+
tenants = OpenStack::Keystone::Public::Tenant.all
|
|
21
|
+
|
|
22
|
+
assert_block("No tenants?") do
|
|
23
|
+
!tenants.empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_list_users
|
|
15
|
+
return unless admin_test_possible?
|
|
16
|
+
|
|
17
|
+
auth_admin
|
|
18
|
+
|
|
19
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list users" do
|
|
20
|
+
users = OpenStack::Keystone::Admin::User.all
|
|
21
|
+
|
|
22
|
+
assert_block("No users?") do
|
|
23
|
+
!users.nil? && !users.empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_list_flavor
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list flavors" do
|
|
18
|
+
flavors = OpenStack::Nova::Compute::Flavor.all
|
|
19
|
+
|
|
20
|
+
assert_block("No flavors?") do
|
|
21
|
+
!flavors.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_floating_ip_list
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list floating IP" do
|
|
18
|
+
floating_ips = OpenStack::Nova::Compute::FloatingIp.all
|
|
19
|
+
|
|
20
|
+
assert_not_nil floating_ips, "Cannot retrieve key-pairs"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_floating_ip_allocation
|
|
25
|
+
auth_user
|
|
26
|
+
|
|
27
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list floating IP" do
|
|
28
|
+
floating_ip = nil
|
|
29
|
+
OpenStack::Nova::Compute::FloatingIpPool.all.each do |ip_pool|
|
|
30
|
+
begin
|
|
31
|
+
floating_ip = OpenStack::Nova::Compute::FloatingIp.create(:pool => ip_pool.name)
|
|
32
|
+
break
|
|
33
|
+
rescue ActiveResource::ClientError => e
|
|
34
|
+
next # Retry with the next pool
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
assert_not_nil floating_ip, "Failed to allocate a floating IP"
|
|
39
|
+
|
|
40
|
+
floating_ip.destroy
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_list_images
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list images" do
|
|
18
|
+
images = OpenStack::Nova::Compute::Image.all
|
|
19
|
+
|
|
20
|
+
assert_block("No images?") do
|
|
21
|
+
!images.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_keypair_list
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list keypair" do
|
|
18
|
+
keys = OpenStack::Nova::Compute::KeyPair.all
|
|
19
|
+
|
|
20
|
+
assert_not_nil keys, "Cannot retrieve key-pairs"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_keypair_create_destroy
|
|
26
|
+
auth_user
|
|
27
|
+
|
|
28
|
+
keypair_name = '___my_new_keypair'
|
|
29
|
+
key = nil
|
|
30
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot create key pair" do
|
|
31
|
+
key = OpenStack::Nova::Compute::KeyPair.create :name => keypair_name
|
|
32
|
+
end
|
|
33
|
+
assert_not_nil key, "Cannot create key pair"
|
|
34
|
+
|
|
35
|
+
key = nil
|
|
36
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot find keypair '#{keypair_name}'" do
|
|
37
|
+
key = OpenStack::Nova::Compute::KeyPair.find_by_name keypair_name
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
assert_not_nil key, "Cannot find key pair"
|
|
41
|
+
|
|
42
|
+
assert_nothing_raised "Cannot destroy key pair" do
|
|
43
|
+
key.destroy
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_get_quota_set
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot get quota-set as user" do
|
|
18
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
19
|
+
|
|
20
|
+
assert_not_nil quota_set, "Cannot retrieve quota-set as user"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
return unless admin_test_possible?
|
|
24
|
+
|
|
25
|
+
auth_admin
|
|
26
|
+
|
|
27
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot get quota-set as admin" do
|
|
28
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
29
|
+
|
|
30
|
+
assert_not_nil quota_set, "Cannot retrieve quota-set as admin"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_update_quota_set
|
|
35
|
+
auth_user
|
|
36
|
+
|
|
37
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
38
|
+
old_instances = quota_set.instances
|
|
39
|
+
|
|
40
|
+
assert_raises ActiveResource::ForbiddenAccess, "It shouldn't be possible for a generic user to update its quotas!" do
|
|
41
|
+
quota_set.instances = old_instances + 1
|
|
42
|
+
quota_set.save
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
return unless admin_test_possible?
|
|
46
|
+
|
|
47
|
+
auth_admin
|
|
48
|
+
|
|
49
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
50
|
+
old_instances = quota_set.instances
|
|
51
|
+
|
|
52
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot update quota-set" do
|
|
53
|
+
quota_set.instances = old_instances + 1
|
|
54
|
+
assert quota_set.save, "Cannot update quota-set"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
58
|
+
assert quota_set.instances == old_instances + 1, "Quota-set verification failed: not updated"
|
|
59
|
+
|
|
60
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot get quota-set" do
|
|
61
|
+
quota_set.instances = old_instances
|
|
62
|
+
assert quota_set.save, "Cannot update quota-set to its original value"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
quota_set = OpenStack::Nova::Compute::QuotaSet.find TEST_CONFIG[:user_tenant_id]
|
|
66
|
+
assert quota_set.instances == old_instances, "Quota-set verification failed: not updated"
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_list_security_groups
|
|
15
|
+
auth_user
|
|
16
|
+
|
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list security group" do
|
|
18
|
+
security_groups = OpenStack::Nova::Compute::SecurityGroup.all
|
|
19
|
+
|
|
20
|
+
assert_block("No security_groups?") do
|
|
21
|
+
!security_groups.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
# Servers
|
|
15
|
+
|
|
16
|
+
def test_list_server
|
|
17
|
+
auth_user
|
|
18
|
+
|
|
19
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list server" do
|
|
20
|
+
OpenStack::Nova::Compute::Server.all
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_server_create_destroy
|
|
25
|
+
auth_user
|
|
26
|
+
|
|
27
|
+
flavor = OpenStack::Nova::Compute::Flavor.find_by_name TEST_CONFIG[:flavor_name]
|
|
28
|
+
assert_not_nil flavor
|
|
29
|
+
|
|
30
|
+
image = OpenStack::Nova::Compute::Image.find TEST_CONFIG[:image_id]
|
|
31
|
+
assert_not_nil image
|
|
32
|
+
|
|
33
|
+
new_server_id = nil
|
|
34
|
+
assert_nothing_raised ActiveResource::ClientError, "Failed to create a new server" do
|
|
35
|
+
new_server = OpenStack::Nova::Compute::Server.create :name => 'test_server',
|
|
36
|
+
:flavor => flavor,
|
|
37
|
+
:image => image
|
|
38
|
+
assert_not_nil new_server
|
|
39
|
+
new_server_id = new_server.id
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Verify server
|
|
43
|
+
my_server = loop_block(5) do
|
|
44
|
+
begin
|
|
45
|
+
OpenStack::Nova::Compute::Server.find new_server_id
|
|
46
|
+
rescue ActiveResource::ResourceNotFound
|
|
47
|
+
|
|
48
|
+
nil
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
assert_not_nil my_server, "Server not spawned after 5 seconds!?!"
|
|
52
|
+
|
|
53
|
+
# Wait for a network address
|
|
54
|
+
my_address = loop_block(60) do
|
|
55
|
+
my_server = OpenStack::Nova::Compute::Server.find new_server_id
|
|
56
|
+
my_server.addresses.keys.count > 0 ? my_server.addresses : nil
|
|
57
|
+
end
|
|
58
|
+
assert_not_nil my_address, "No address after a minute!"
|
|
59
|
+
|
|
60
|
+
assert_nothing_raised ActiveResource::ClientError, "Problem retrieving the server '#{new_server_id}'" do
|
|
61
|
+
my_server = OpenStack::Nova::Compute::Server.find new_server_id
|
|
62
|
+
my_server.destroy
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
+
$:.unshift(lib_path)
|
|
3
|
+
|
|
4
|
+
test_path = File.expand_path('..', __FILE__)
|
|
5
|
+
$:.unshift(test_path)
|
|
6
|
+
|
|
7
|
+
require 'helper'
|
|
8
|
+
require 'openstack_activeresource'
|
|
9
|
+
require 'utils'
|
|
10
|
+
|
|
11
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
12
|
+
include OpenstackTestUtils
|
|
13
|
+
|
|
14
|
+
def test_simple_tenant_usage
|
|
15
|
+
return unless admin_test_possible?
|
|
16
|
+
|
|
17
|
+
auth_admin
|
|
18
|
+
|
|
19
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot retrieve simple_usages" do
|
|
20
|
+
simple_usages = OpenStack::Nova::Compute::SimpleTenantUsage.find_from_date(:all, 5.days.ago)
|
|
21
|
+
|
|
22
|
+
assert_not_nil simple_usages
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
data/test/utils.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module OpenstackTestUtils
|
|
2
|
+
|
|
3
|
+
private
|
|
4
|
+
|
|
5
|
+
def auth_admin
|
|
6
|
+
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
7
|
+
OpenStack::Keystone::Admin::Base.site = TEST_CONFIG[:public_admin_site]
|
|
8
|
+
|
|
9
|
+
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:admin_username],
|
|
10
|
+
:password => TEST_CONFIG[:admin_password],
|
|
11
|
+
:tenant_id => TEST_CONFIG[:admin_tenant_id]
|
|
12
|
+
|
|
13
|
+
OpenStack::Base.token = auth.token
|
|
14
|
+
OpenStack::Nova::Compute::Base.site = auth.endpoint_for('compute').publicURL
|
|
15
|
+
OpenStack::Nova::Volume::Base.site = auth.endpoint_for('volume').publicURL
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def auth_user
|
|
20
|
+
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
21
|
+
|
|
22
|
+
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:user_username],
|
|
23
|
+
:password => TEST_CONFIG[:user_password],
|
|
24
|
+
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
25
|
+
|
|
26
|
+
OpenStack::Base.token = auth.token
|
|
27
|
+
OpenStack::Nova::Compute::Base.site = auth.endpoint_for('compute').publicURL
|
|
28
|
+
OpenStack::Nova::Volume::Base.site = auth.endpoint_for('volume').publicURL
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def admin_test_possible?
|
|
33
|
+
TEST_CONFIG[:admin_username] and TEST_CONFIG[:admin_password] and TEST_CONFIG[:admin_tenant_id]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def loop_block(seconds=10)
|
|
37
|
+
ret = nil
|
|
38
|
+
if block_given? and seconds > 0
|
|
39
|
+
begin
|
|
40
|
+
ret = yield
|
|
41
|
+
return ret unless ret.nil?
|
|
42
|
+
seconds-=1
|
|
43
|
+
sleep 1
|
|
44
|
+
end while seconds > 0
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
ret
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openstack_activeresource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-02-
|
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activemodel
|
|
@@ -200,6 +200,7 @@ files:
|
|
|
200
200
|
- lib/open_stack/nova/compute/image.rb
|
|
201
201
|
- lib/open_stack/nova/compute/key_pair.rb
|
|
202
202
|
- lib/open_stack/nova/compute/network.rb
|
|
203
|
+
- lib/open_stack/nova/compute/quota_set.rb
|
|
203
204
|
- lib/open_stack/nova/compute/security_group.rb
|
|
204
205
|
- lib/open_stack/nova/compute/server.rb
|
|
205
206
|
- lib/open_stack/nova/compute/simple_tenant_usage.rb
|
|
@@ -212,7 +213,18 @@ files:
|
|
|
212
213
|
- test/.gitignore
|
|
213
214
|
- test/helper.rb
|
|
214
215
|
- test/test_configuration-sample.yml
|
|
215
|
-
- test/
|
|
216
|
+
- test/test_keystone_authentications.rb
|
|
217
|
+
- test/test_keystone_tenants.rb
|
|
218
|
+
- test/test_keystone_users.rb
|
|
219
|
+
- test/test_nova_flavors.rb
|
|
220
|
+
- test/test_nova_floating_ips.rb
|
|
221
|
+
- test/test_nova_images.rb
|
|
222
|
+
- test/test_nova_keypairs.rb
|
|
223
|
+
- test/test_nova_quota_sets.rb
|
|
224
|
+
- test/test_nova_security_groups.rb
|
|
225
|
+
- test/test_nova_servers.rb
|
|
226
|
+
- test/test_simple_tenant_usages.rb
|
|
227
|
+
- test/utils.rb
|
|
216
228
|
homepage: https://github.com/Unidata-SpA/openstack_activeresource
|
|
217
229
|
licenses:
|
|
218
230
|
- GPLv3
|
|
@@ -228,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
228
240
|
version: '0'
|
|
229
241
|
segments:
|
|
230
242
|
- 0
|
|
231
|
-
hash:
|
|
243
|
+
hash: 1700532988989412175
|
|
232
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
245
|
none: false
|
|
234
246
|
requirements:
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
lib_path = File.expand_path('../../lib', __FILE__)
|
|
2
|
-
$:.unshift(lib_path)
|
|
3
|
-
|
|
4
|
-
test_path = File.expand_path('..', __FILE__)
|
|
5
|
-
$:.unshift(test_path)
|
|
6
|
-
|
|
7
|
-
require 'helper'
|
|
8
|
-
require 'openstack_activeresource'
|
|
9
|
-
|
|
10
|
-
class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
11
|
-
|
|
12
|
-
# Keystone
|
|
13
|
-
|
|
14
|
-
# Authentication
|
|
15
|
-
|
|
16
|
-
def test_authentication
|
|
17
|
-
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
18
|
-
|
|
19
|
-
# User auth
|
|
20
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot authenticate as user" do
|
|
21
|
-
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:user_username],
|
|
22
|
-
:password => TEST_CONFIG[:user_password],
|
|
23
|
-
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
24
|
-
|
|
25
|
-
assert_not_nil auth.token, "Cannot authenticate as user"
|
|
26
|
-
|
|
27
|
-
auth = OpenStack::Keystone::Public::Auth.create :username => "baduser",
|
|
28
|
-
:password => "badpassword",
|
|
29
|
-
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
30
|
-
|
|
31
|
-
assert_nil auth.token, "Authentication seems broken!"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Admin auth
|
|
35
|
-
return unless admin_test_possible?
|
|
36
|
-
|
|
37
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot authenticate as admin" do
|
|
38
|
-
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:admin_username],
|
|
39
|
-
:password => TEST_CONFIG[:admin_password],
|
|
40
|
-
:tenant_id => TEST_CONFIG[:admin_tenant_id]
|
|
41
|
-
|
|
42
|
-
assert_not_nil auth.token, "Cannot authenticate as admin"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_list_tenant
|
|
48
|
-
return unless admin_test_possible?
|
|
49
|
-
|
|
50
|
-
auth_admin
|
|
51
|
-
|
|
52
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list tenants" do
|
|
53
|
-
tenants = OpenStack::Keystone::Public::Tenant.all
|
|
54
|
-
|
|
55
|
-
assert_block("No tenants?") do
|
|
56
|
-
!tenants.empty?
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_simple_tenant_usage
|
|
63
|
-
return unless admin_test_possible?
|
|
64
|
-
|
|
65
|
-
auth_admin
|
|
66
|
-
|
|
67
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot retrieve simple_usages" do
|
|
68
|
-
simple_usages = OpenStack::Nova::Compute::SimpleTenantUsage.find_from_date(:all, 5.days.ago)
|
|
69
|
-
|
|
70
|
-
assert_not_nil simple_usages
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_list_users
|
|
76
|
-
return unless admin_test_possible?
|
|
77
|
-
|
|
78
|
-
auth_admin
|
|
79
|
-
|
|
80
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list users" do
|
|
81
|
-
users = OpenStack::Keystone::Admin::User.all
|
|
82
|
-
|
|
83
|
-
assert_block("No users?") do
|
|
84
|
-
!users.nil? && !users.empty?
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Nova
|
|
91
|
-
|
|
92
|
-
## Flavors
|
|
93
|
-
|
|
94
|
-
def test_list_flavor
|
|
95
|
-
auth_user
|
|
96
|
-
|
|
97
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list flavors" do
|
|
98
|
-
flavors = OpenStack::Nova::Compute::Flavor.all
|
|
99
|
-
|
|
100
|
-
assert_block("No flavors?") do
|
|
101
|
-
!flavors.empty?
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# Images
|
|
107
|
-
|
|
108
|
-
def test_list_images
|
|
109
|
-
auth_user
|
|
110
|
-
|
|
111
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list images" do
|
|
112
|
-
images = OpenStack::Nova::Compute::Image.all
|
|
113
|
-
|
|
114
|
-
assert_block("No images?") do
|
|
115
|
-
!images.empty?
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# Security groups
|
|
121
|
-
|
|
122
|
-
def test_list_security_groups
|
|
123
|
-
auth_user
|
|
124
|
-
|
|
125
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list security group" do
|
|
126
|
-
security_groups = OpenStack::Nova::Compute::SecurityGroup.all
|
|
127
|
-
|
|
128
|
-
assert_block("No security_groups?") do
|
|
129
|
-
!security_groups.empty?
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Keypairs
|
|
135
|
-
|
|
136
|
-
def test_keypair_list
|
|
137
|
-
auth_user
|
|
138
|
-
|
|
139
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list keypair" do
|
|
140
|
-
keys = OpenStack::Nova::Compute::KeyPair.all
|
|
141
|
-
|
|
142
|
-
assert_not_nil keys, "Cannot retrieve key-pairs"
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def test_keypair_create_destroy
|
|
148
|
-
auth_user
|
|
149
|
-
|
|
150
|
-
keypair_name = '___my_new_keypair'
|
|
151
|
-
key = nil
|
|
152
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot create key pair" do
|
|
153
|
-
key = OpenStack::Nova::Compute::KeyPair.create :name => keypair_name
|
|
154
|
-
end
|
|
155
|
-
assert_not_nil key, "Cannot create key pair"
|
|
156
|
-
|
|
157
|
-
key = nil
|
|
158
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot find keypair '#{keypair_name}'" do
|
|
159
|
-
key = OpenStack::Nova::Compute::KeyPair.find_by_name keypair_name
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
assert_not_nil key, "Cannot find key pair"
|
|
163
|
-
|
|
164
|
-
assert_nothing_raised "Cannot destroy key pair" do
|
|
165
|
-
key.destroy
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
# Floating IPs
|
|
171
|
-
def test_floating_ip_list
|
|
172
|
-
auth_user
|
|
173
|
-
|
|
174
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list floating IP" do
|
|
175
|
-
floating_ips = OpenStack::Nova::Compute::FloatingIp.all
|
|
176
|
-
|
|
177
|
-
assert_not_nil floating_ips, "Cannot retrieve key-pairs"
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def test_floating_ip_allocation
|
|
182
|
-
auth_user
|
|
183
|
-
|
|
184
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list floating IP" do
|
|
185
|
-
floating_ip = nil
|
|
186
|
-
OpenStack::Nova::Compute::FloatingIpPool.all.each do |ip_pool|
|
|
187
|
-
begin
|
|
188
|
-
floating_ip = OpenStack::Nova::Compute::FloatingIp.create(:pool => ip_pool.name)
|
|
189
|
-
break
|
|
190
|
-
rescue ActiveResource::ClientError => e
|
|
191
|
-
next # Retry with the next pool
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
assert_not_nil floating_ip, "Failed to allocate a floating IP"
|
|
196
|
-
|
|
197
|
-
floating_ip.destroy
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
# Servers
|
|
202
|
-
|
|
203
|
-
def test_list_server
|
|
204
|
-
auth_user
|
|
205
|
-
|
|
206
|
-
assert_nothing_raised ActiveResource::ClientError, "Cannot list server" do
|
|
207
|
-
OpenStack::Nova::Compute::Server.all
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def test_server_create_destroy
|
|
212
|
-
auth_user
|
|
213
|
-
|
|
214
|
-
flavor = OpenStack::Nova::Compute::Flavor.find_by_name TEST_CONFIG[:flavor_name]
|
|
215
|
-
assert_not_nil flavor
|
|
216
|
-
|
|
217
|
-
image = OpenStack::Nova::Compute::Image.find TEST_CONFIG[:image_id]
|
|
218
|
-
assert_not_nil image
|
|
219
|
-
|
|
220
|
-
new_server_id = nil
|
|
221
|
-
assert_nothing_raised ActiveResource::ClientError, "Failed to create a new server" do
|
|
222
|
-
new_server = OpenStack::Nova::Compute::Server.create :name => 'test_server',
|
|
223
|
-
:flavor => flavor,
|
|
224
|
-
:image => image
|
|
225
|
-
assert_not_nil new_server
|
|
226
|
-
new_server_id = new_server.id
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
# Verify server
|
|
230
|
-
my_server = loop_block(5) do
|
|
231
|
-
begin
|
|
232
|
-
OpenStack::Nova::Compute::Server.find new_server_id
|
|
233
|
-
rescue ActiveResource::ResourceNotFound
|
|
234
|
-
|
|
235
|
-
nil
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
assert_not_nil my_server, "Server not spawned after 5 seconds!?!"
|
|
239
|
-
|
|
240
|
-
# Wait for a network address
|
|
241
|
-
my_address = loop_block(60) do
|
|
242
|
-
my_server = OpenStack::Nova::Compute::Server.find new_server_id
|
|
243
|
-
my_server.addresses.keys.count > 0 ? my_server.addresses : nil
|
|
244
|
-
end
|
|
245
|
-
assert_not_nil my_address, "No address after a minute!"
|
|
246
|
-
|
|
247
|
-
assert_nothing_raised ActiveResource::ClientError, "Problem retrieving the server '#{new_server_id}'" do
|
|
248
|
-
my_server = OpenStack::Nova::Compute::Server.find new_server_id
|
|
249
|
-
my_server.destroy
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
private
|
|
255
|
-
|
|
256
|
-
# Utilities
|
|
257
|
-
|
|
258
|
-
def auth_admin
|
|
259
|
-
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
260
|
-
OpenStack::Keystone::Admin::Base.site = TEST_CONFIG[:public_admin_site]
|
|
261
|
-
|
|
262
|
-
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:admin_username],
|
|
263
|
-
:password => TEST_CONFIG[:admin_password],
|
|
264
|
-
:tenant_id => TEST_CONFIG[:admin_tenant_id]
|
|
265
|
-
|
|
266
|
-
OpenStack::Base.token = auth.token
|
|
267
|
-
OpenStack::Nova::Compute::Base.site = auth.endpoint_for('compute').publicURL
|
|
268
|
-
OpenStack::Nova::Volume::Base.site = auth.endpoint_for('volume').publicURL
|
|
269
|
-
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
def auth_user
|
|
273
|
-
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
|
274
|
-
|
|
275
|
-
auth = OpenStack::Keystone::Public::Auth.create :username => TEST_CONFIG[:user_username],
|
|
276
|
-
:password => TEST_CONFIG[:user_password],
|
|
277
|
-
:tenant_id => TEST_CONFIG[:user_tenant_id]
|
|
278
|
-
|
|
279
|
-
OpenStack::Base.token = auth.token
|
|
280
|
-
OpenStack::Nova::Compute::Base.site = auth.endpoint_for('compute').publicURL
|
|
281
|
-
OpenStack::Nova::Volume::Base.site = auth.endpoint_for('volume').publicURL
|
|
282
|
-
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
def admin_test_possible?
|
|
286
|
-
TEST_CONFIG[:admin_username] and TEST_CONFIG[:admin_password] and TEST_CONFIG[:admin_tenant_id]
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
def loop_block(seconds=10)
|
|
290
|
-
ret = nil
|
|
291
|
-
if block_given? and seconds > 0
|
|
292
|
-
begin
|
|
293
|
-
ret = yield
|
|
294
|
-
return ret unless ret.nil?
|
|
295
|
-
seconds-=1
|
|
296
|
-
sleep 1
|
|
297
|
-
end while seconds > 0
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
ret
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
end
|