openstack_activeresource 0.4.0 → 0.5.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/Gemfile +11 -10
- data/Gemfile.lock +14 -13
- data/LICENSE.txt +1 -0
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/hot_fixes.rb +3 -1
- data/lib/open_stack/base.rb +2 -2
- data/lib/open_stack/keystone/admin.rb +0 -1
- data/lib/open_stack/keystone/admin/role.rb +5 -0
- data/lib/open_stack/keystone/admin/tenant.rb +3 -4
- data/lib/open_stack/keystone/admin/user.rb +26 -6
- data/lib/open_stack/keystone/public/auth.rb +4 -4
- data/lib/open_stack/keystone/public/tenant.rb +1 -2
- data/lib/open_stack/nova/compute/base.rb +2 -0
- data/lib/open_stack/nova/compute/base_detail.rb +1 -1
- data/lib/open_stack/nova/compute/flavor.rb +53 -8
- data/lib/open_stack/nova/compute/floating_ip.rb +1 -1
- data/lib/open_stack/nova/compute/key_pair.rb +1 -1
- data/lib/open_stack/nova/compute/security_group.rb +3 -3
- data/lib/open_stack/nova/compute/server.rb +1 -2
- data/lib/open_stack/nova/compute/simple_tenant_usage.rb +1 -1
- data/lib/open_stack/nova/compute/volume_attachment.rb +3 -4
- data/lib/open_stack/nova/volume/volume.rb +1 -1
- data/openstack_activeresource.gemspec +18 -19
- data/test/helper.rb +3 -1
- data/test/test_configuration-sample.yml +1 -0
- data/test/test_keystone_authentications.rb +1 -6
- data/test/test_keystone_tenants.rb +58 -7
- data/test/test_keystone_users_and_roles.rb +168 -0
- data/test/test_nova_flavors.rb +64 -6
- data/test/test_nova_floating_ips.rb +1 -6
- data/test/test_nova_images.rb +0 -5
- data/test/test_nova_keypairs.rb +0 -5
- data/test/test_nova_quota_sets.rb +0 -5
- data/test/test_nova_security_groups.rb +16 -5
- data/test/test_nova_servers.rb +0 -5
- data/test/test_simple_tenant_usages.rb +0 -5
- data/test/utils.rb +8 -0
- metadata +21 -22
- data/lib/open_stack/keystone/admin/user_role.rb +0 -45
- data/test/test_keystone_users.rb +0 -29
@@ -127,8 +127,7 @@ module OpenStack
|
|
127
127
|
end
|
128
128
|
|
129
129
|
# Overloads ActiveRecord::encode method
|
130
|
-
def encode(options={})
|
131
|
-
# Custom encoding to deal with openstack API
|
130
|
+
def encode(options={}) # :nodoc: Custom encoding to deal with openstack API
|
132
131
|
to_encode = {
|
133
132
|
:server => {
|
134
133
|
:name => name,
|
@@ -26,7 +26,7 @@ module OpenStack
|
|
26
26
|
class VolumeAttachment < Base
|
27
27
|
self.element_name = "volumeAttachment"
|
28
28
|
self.collection_name = "os-volume_attachments"
|
29
|
-
self.site = superclass.site
|
29
|
+
self.site = "#{superclass.site}/servers/:server_id"
|
30
30
|
|
31
31
|
schema do
|
32
32
|
attribute :device, :string
|
@@ -42,7 +42,7 @@ module OpenStack
|
|
42
42
|
validates :server,
|
43
43
|
:presence => true
|
44
44
|
|
45
|
-
def initialize(attributes = {}, persisted = false)
|
45
|
+
def initialize(attributes = {}, persisted = false) # :notnew:
|
46
46
|
attributes = attributes.with_indifferent_access
|
47
47
|
new_attributes = {
|
48
48
|
:device => attributes[:device],
|
@@ -68,8 +68,7 @@ module OpenStack
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Overloads ActiveRecord::encode method
|
71
|
-
def encode(options={})
|
72
|
-
# Custom encoding to deal with openstack API
|
71
|
+
def encode(options={}) # :nodoc: Custom encoding to deal with openstack API
|
73
72
|
to_encode = {
|
74
73
|
VolumeAttachment.element_name => {
|
75
74
|
:device => device,
|
@@ -51,7 +51,7 @@ module OpenStack
|
|
51
51
|
:presence => true,
|
52
52
|
:numericality => {:greater_than_or_equal_to => 1, :only_integer => true, :allow_blank => true}
|
53
53
|
|
54
|
-
def initialize(attributes = {}, persisted = false)
|
54
|
+
def initialize(attributes = {}, persisted = false) # :notnew:
|
55
55
|
attributes = attributes.with_indifferent_access
|
56
56
|
new_attributes = {
|
57
57
|
:id => attributes[:id],
|
@@ -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.5.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-
|
12
|
+
s.date = "2013-03-06"
|
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 = [
|
@@ -38,7 +38,6 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/open_stack/keystone/admin/role.rb",
|
39
39
|
"lib/open_stack/keystone/admin/tenant.rb",
|
40
40
|
"lib/open_stack/keystone/admin/user.rb",
|
41
|
-
"lib/open_stack/keystone/admin/user_role.rb",
|
42
41
|
"lib/open_stack/keystone/public.rb",
|
43
42
|
"lib/open_stack/keystone/public/auth.rb",
|
44
43
|
"lib/open_stack/keystone/public/base.rb",
|
@@ -68,7 +67,7 @@ Gem::Specification.new do |s|
|
|
68
67
|
"test/test_configuration-sample.yml",
|
69
68
|
"test/test_keystone_authentications.rb",
|
70
69
|
"test/test_keystone_tenants.rb",
|
71
|
-
"test/
|
70
|
+
"test/test_keystone_users_and_roles.rb",
|
72
71
|
"test/test_nova_flavors.rb",
|
73
72
|
"test/test_nova_floating_ips.rb",
|
74
73
|
"test/test_nova_images.rb",
|
@@ -89,36 +88,36 @@ Gem::Specification.new do |s|
|
|
89
88
|
s.specification_version = 3
|
90
89
|
|
91
90
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
92
|
-
s.add_runtime_dependency(%q<activemodel>, ["~> 3.2.
|
93
|
-
s.add_runtime_dependency(%q<activeresource>, ["~> 3.2.
|
91
|
+
s.add_runtime_dependency(%q<activemodel>, ["~> 3.2.12"])
|
92
|
+
s.add_runtime_dependency(%q<activeresource>, ["~> 3.2.12"])
|
94
93
|
s.add_runtime_dependency(%q<oj>, ["~> 1.2.9"])
|
95
|
-
s.add_runtime_dependency(%q<bundler>, ["~> 1.2.0"])
|
96
|
-
s.add_runtime_dependency(%q<shoulda>, [">= 0"])
|
97
|
-
s.add_runtime_dependency(%q<rdoc>, ["~> 3.12"])
|
98
|
-
s.add_runtime_dependency(%q<jeweler>, ["~> 1.8.4"])
|
99
|
-
s.add_runtime_dependency(%q<simplecov>, [">= 0"])
|
100
94
|
s.add_runtime_dependency(%q<json>, ["~> 1.7.7"])
|
95
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
96
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
97
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
98
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
99
|
+
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
101
100
|
else
|
102
|
-
s.add_dependency(%q<activemodel>, ["~> 3.2.
|
103
|
-
s.add_dependency(%q<activeresource>, ["~> 3.2.
|
101
|
+
s.add_dependency(%q<activemodel>, ["~> 3.2.12"])
|
102
|
+
s.add_dependency(%q<activeresource>, ["~> 3.2.12"])
|
104
103
|
s.add_dependency(%q<oj>, ["~> 1.2.9"])
|
105
|
-
s.add_dependency(%q<
|
104
|
+
s.add_dependency(%q<json>, ["~> 1.7.7"])
|
106
105
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
107
106
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
108
107
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
109
108
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
110
|
-
s.add_dependency(%q<
|
109
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
111
110
|
end
|
112
111
|
else
|
113
|
-
s.add_dependency(%q<activemodel>, ["~> 3.2.
|
114
|
-
s.add_dependency(%q<activeresource>, ["~> 3.2.
|
112
|
+
s.add_dependency(%q<activemodel>, ["~> 3.2.12"])
|
113
|
+
s.add_dependency(%q<activeresource>, ["~> 3.2.12"])
|
115
114
|
s.add_dependency(%q<oj>, ["~> 1.2.9"])
|
116
|
-
s.add_dependency(%q<
|
115
|
+
s.add_dependency(%q<json>, ["~> 1.7.7"])
|
117
116
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
118
117
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
119
118
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
120
119
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
121
|
-
s.add_dependency(%q<
|
120
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
data/test/helper.rb
CHANGED
@@ -12,7 +12,6 @@ require 'shoulda'
|
|
12
12
|
|
13
13
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
14
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'openstack_activeresource'
|
16
15
|
|
17
16
|
class Test::Unit::TestCase
|
18
17
|
end
|
@@ -28,5 +27,8 @@ unless File.exist? "#{test_path}/test_configuration.yml"
|
|
28
27
|
"\n****"
|
29
28
|
end
|
30
29
|
|
30
|
+
require 'openstack_activeresource'
|
31
|
+
require 'utils'
|
32
|
+
|
31
33
|
TEST_CONFIG = (YAML.load_file("#{test_path}/test_configuration.yml")['test_configuration']).with_indifferent_access
|
32
34
|
|
@@ -1,12 +1,7 @@
|
|
1
|
-
lib_path = File.expand_path('../../lib', __FILE__)
|
2
|
-
$:.unshift(lib_path)
|
3
|
-
|
4
1
|
test_path = File.expand_path('..', __FILE__)
|
5
2
|
$:.unshift(test_path)
|
6
3
|
|
7
4
|
require 'helper'
|
8
|
-
require 'openstack_activeresource'
|
9
|
-
require 'utils'
|
10
5
|
|
11
6
|
class TestOpenStackActiveResource < Test::Unit::TestCase
|
12
7
|
include OpenstackTestUtils
|
@@ -15,7 +10,7 @@ class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
15
10
|
|
16
11
|
# Authentication
|
17
12
|
|
18
|
-
def
|
13
|
+
def test_10_authentications
|
19
14
|
OpenStack::Keystone::Public::Base.site = TEST_CONFIG[:public_base_site]
|
20
15
|
|
21
16
|
# User auth
|
@@ -1,23 +1,32 @@
|
|
1
|
-
lib_path = File.expand_path('../../lib', __FILE__)
|
2
|
-
$:.unshift(lib_path)
|
3
|
-
|
4
1
|
test_path = File.expand_path('..', __FILE__)
|
5
2
|
$:.unshift(test_path)
|
6
3
|
|
7
4
|
require 'helper'
|
8
|
-
require 'openstack_activeresource'
|
9
|
-
require 'utils'
|
10
5
|
|
11
6
|
class TestOpenStackActiveResource < Test::Unit::TestCase
|
12
7
|
include OpenstackTestUtils
|
13
8
|
|
14
|
-
|
9
|
+
TENANT_NAME = "__test__tenant__"
|
10
|
+
|
11
|
+
def test_10_tenant_create
|
12
|
+
return unless admin_test_possible?
|
13
|
+
|
14
|
+
auth_admin
|
15
|
+
|
16
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot create tenant" do
|
17
|
+
new_tenant = OpenStack::Keystone::Admin::Tenant.create :name => TENANT_NAME, :enabled => true, :description => "Test tenant"
|
18
|
+
|
19
|
+
assert_not_nil new_tenant.id, "Cannot create tenant: #{active_resource_errors_to_s(new_tenant)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_20_tenant_list
|
15
24
|
return unless admin_test_possible?
|
16
25
|
|
17
26
|
auth_admin
|
18
27
|
|
19
28
|
assert_nothing_raised ActiveResource::ClientError, "Cannot list tenants" do
|
20
|
-
tenants = OpenStack::Keystone::
|
29
|
+
tenants = OpenStack::Keystone::Admin::Tenant.all
|
21
30
|
|
22
31
|
assert_block("No tenants?") do
|
23
32
|
!tenants.empty?
|
@@ -26,4 +35,46 @@ class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
26
35
|
|
27
36
|
end
|
28
37
|
|
38
|
+
def test_30_tenant_get
|
39
|
+
return unless admin_test_possible?
|
40
|
+
|
41
|
+
auth_admin
|
42
|
+
|
43
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot retrieve tenant '#{TEST_CONFIG[:user_tenant_id]}'" do
|
44
|
+
tenant = OpenStack::Keystone::Admin::Tenant.find TEST_CONFIG[:user_tenant_id]
|
45
|
+
assert_not_nil tenant, "Cannot retrieve tenant '#{TEST_CONFIG[:user_tenant_id]}'"
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_raises ActiveResource::ResourceNotFound, "Tenant retrieval broken!" do
|
49
|
+
OpenStack::Keystone::Admin::Tenant.find 1
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_40_tenant_update
|
55
|
+
return unless admin_test_possible?
|
56
|
+
|
57
|
+
auth_admin
|
58
|
+
|
59
|
+
tenant = OpenStack::Keystone::Admin::Tenant.find_by_name TENANT_NAME
|
60
|
+
|
61
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot update tenant '#{tenant.id}'" do
|
62
|
+
tenant.update_attributes :enabled => false
|
63
|
+
tenant.save
|
64
|
+
assert_true tenant.save, "Failed to update server '#{tenant.id}': #{active_resource_errors_to_s(tenant)}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_50_tenant_destroy
|
69
|
+
return unless admin_test_possible?
|
70
|
+
|
71
|
+
auth_admin
|
72
|
+
|
73
|
+
tenant = OpenStack::Keystone::Admin::Tenant.find_by_name TENANT_NAME
|
74
|
+
|
75
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot destroy tenant '#{tenant.id}'" do
|
76
|
+
tenant.destroy
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
29
80
|
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
test_path = File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift(test_path)
|
3
|
+
|
4
|
+
require 'helper'
|
5
|
+
|
6
|
+
class TestOpenStackActiveResource < Test::Unit::TestCase
|
7
|
+
include OpenstackTestUtils
|
8
|
+
|
9
|
+
USER_NAME="__test_user__"
|
10
|
+
|
11
|
+
def test_10_user_create
|
12
|
+
return unless admin_test_possible?
|
13
|
+
|
14
|
+
auth_admin
|
15
|
+
|
16
|
+
tenant = OpenStack::Keystone::Admin::Tenant.find(TEST_CONFIG[:user_tenant_id])
|
17
|
+
assert_not_nil tenant, "Cannot retrieve tenant"
|
18
|
+
|
19
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot create user" do
|
20
|
+
new_user = OpenStack::Keystone::Admin::User.create :name => USER_NAME,
|
21
|
+
:password => "test_password_123",
|
22
|
+
:email => "fake@pretend.test",
|
23
|
+
:enabled => false,
|
24
|
+
:tenant => tenant
|
25
|
+
|
26
|
+
assert_not_nil new_user.id, "Cannot create user: #{active_resource_errors_to_s(new_user)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_20_user_list
|
32
|
+
return unless admin_test_possible?
|
33
|
+
|
34
|
+
auth_admin
|
35
|
+
|
36
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list users" do
|
37
|
+
users = OpenStack::Keystone::Admin::User.all
|
38
|
+
|
39
|
+
assert_block("No users?") do
|
40
|
+
!users.nil? && !users.empty?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_30_user_get
|
47
|
+
return unless admin_test_possible?
|
48
|
+
|
49
|
+
auth_admin
|
50
|
+
|
51
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot retrieve user" do
|
52
|
+
user = OpenStack::Keystone::Admin::User.find_by_name USER_NAME
|
53
|
+
assert_not_nil user, "Cannot retrieve user by name"
|
54
|
+
|
55
|
+
user = OpenStack::Keystone::Admin::User.find user.id
|
56
|
+
assert_not_nil user, "Cannot retrieve user by id"
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_raises ActiveResource::ResourceNotFound, "User retrieval broken!" do
|
61
|
+
OpenStack::Keystone::Admin::User.find 1
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_40_user_update
|
67
|
+
return unless admin_test_possible?
|
68
|
+
|
69
|
+
auth_admin
|
70
|
+
|
71
|
+
user = OpenStack::Keystone::Admin::User.find_by_name USER_NAME
|
72
|
+
assert_not_nil user, "Cannot retrieve user by name"
|
73
|
+
|
74
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot update user" do
|
75
|
+
user.update_attributes :email => "fake2@pretend.test"
|
76
|
+
assert_true user.save, "Failed to update server '#{user.id}': #{active_resource_errors_to_s(user)}"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_50_role_list
|
82
|
+
return unless admin_test_possible?
|
83
|
+
|
84
|
+
auth_admin
|
85
|
+
|
86
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list roles" do
|
87
|
+
roles = OpenStack::Keystone::Admin::Role.all
|
88
|
+
|
89
|
+
assert_block("No roles?") do
|
90
|
+
!roles.nil? && !roles.empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_60_role_get
|
97
|
+
return unless admin_test_possible?
|
98
|
+
|
99
|
+
auth_admin
|
100
|
+
|
101
|
+
role = OpenStack::Keystone::Admin::Role.find_by_name TEST_CONFIG[:default_role_name]
|
102
|
+
assert_not_nil role, "Cannot retrieve role by name"
|
103
|
+
|
104
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot retrieve role" do
|
105
|
+
role = OpenStack::Keystone::Admin::Role.find role.id
|
106
|
+
assert_not_nil role, "Cannot retrieve role by id"
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
assert_raises ActiveResource::ResourceNotFound, "Role retrieval broken!" do
|
111
|
+
OpenStack::Keystone::Admin::Role.find 1
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_70_user_role_add
|
117
|
+
return unless admin_test_possible?
|
118
|
+
|
119
|
+
auth_admin
|
120
|
+
|
121
|
+
user = OpenStack::Keystone::Admin::User.find_by_name USER_NAME
|
122
|
+
assert_not_nil user, "Cannot retrieve user by name"
|
123
|
+
|
124
|
+
role = OpenStack::Keystone::Admin::Role.find_by_name TEST_CONFIG[:default_role_name]
|
125
|
+
assert_not_nil role, "Cannot retrieve role by name"
|
126
|
+
|
127
|
+
tenant = OpenStack::Keystone::Admin::Tenant.find(TEST_CONFIG[:user_tenant_id])
|
128
|
+
assert_not_nil tenant, "Cannot retrieve tenant"
|
129
|
+
|
130
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list user roles" do
|
131
|
+
tenant.add_role_to_user role, user
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_80_user_role_list
|
136
|
+
return unless admin_test_possible?
|
137
|
+
|
138
|
+
auth_admin
|
139
|
+
|
140
|
+
user = OpenStack::Keystone::Admin::User.find_by_name USER_NAME
|
141
|
+
assert_not_nil user, "Cannot retrieve user by name"
|
142
|
+
|
143
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot list user roles" do
|
144
|
+
roles = user.roles
|
145
|
+
|
146
|
+
assert_not_nil roles
|
147
|
+
assert_block("No user roles?") do
|
148
|
+
!roles.empty?
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_90_user_destroy
|
155
|
+
return unless admin_test_possible?
|
156
|
+
|
157
|
+
auth_admin
|
158
|
+
|
159
|
+
user = OpenStack::Keystone::Admin::User.find_by_name USER_NAME
|
160
|
+
assert_not_nil user, "Cannot retrieve user by name"
|
161
|
+
|
162
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot destroy user" do
|
163
|
+
user.destroy
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
data/test/test_nova_flavors.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
|
-
lib_path = File.expand_path('../../lib', __FILE__)
|
2
|
-
$:.unshift(lib_path)
|
3
|
-
|
4
1
|
test_path = File.expand_path('..', __FILE__)
|
5
2
|
$:.unshift(test_path)
|
6
3
|
|
7
4
|
require 'helper'
|
8
|
-
require 'openstack_activeresource'
|
9
|
-
require 'utils'
|
10
5
|
|
11
6
|
class TestOpenStackActiveResource < Test::Unit::TestCase
|
12
7
|
include OpenstackTestUtils
|
13
8
|
|
14
|
-
|
9
|
+
FLAVOR_NAME="__test__flavor__"
|
10
|
+
|
11
|
+
|
12
|
+
def test_10_flavor_create
|
13
|
+
return unless admin_test_possible?
|
14
|
+
|
15
|
+
auth_admin
|
16
|
+
|
17
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot create flavors" do
|
18
|
+
new_flavor = OpenStack::Nova::Compute::Flavor.create :name => FLAVOR_NAME,
|
19
|
+
:ram => 1,
|
20
|
+
:disk => 10,
|
21
|
+
:swap => 1,
|
22
|
+
:vcpus => 1,
|
23
|
+
:ephemeral_disk => 1,
|
24
|
+
:rxtx_factor => 1,
|
25
|
+
:is_public => false
|
26
|
+
|
27
|
+
assert_not_nil new_flavor.id, "Cannot create flavor: #{active_resource_errors_to_s(new_flavor)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_20_flavor_list
|
15
33
|
auth_user
|
16
34
|
|
17
35
|
assert_nothing_raised ActiveResource::ClientError, "Cannot list flavors" do
|
@@ -23,4 +41,44 @@ class TestOpenStackActiveResource < Test::Unit::TestCase
|
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
44
|
+
def test_20_flavor_get
|
45
|
+
auth_user
|
46
|
+
|
47
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot get flavors" do
|
48
|
+
flavor = OpenStack::Nova::Compute::Flavor.first
|
49
|
+
assert_not_nil flavor, "Cannot retrieve flavor"
|
50
|
+
end
|
51
|
+
|
52
|
+
return unless admin_test_possible?
|
53
|
+
|
54
|
+
auth_admin
|
55
|
+
|
56
|
+
flavor = OpenStack::Nova::Compute::Flavor.find_by_name FLAVOR_NAME
|
57
|
+
assert_not_nil flavor, "Cannot retrieve flavor by name"
|
58
|
+
|
59
|
+
assert_nothing_raised ActiveResource::ResourceNotFound, "Cannot get flavor '#{flavor.id}'" do
|
60
|
+
flavor = OpenStack::Nova::Compute::Flavor.find flavor.id
|
61
|
+
assert_not_nil flavor, "Cannot retrieve flavor"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_30_flavor_update
|
67
|
+
# Flavor cannot be updated!
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_40_flavor_destroy
|
71
|
+
return unless admin_test_possible?
|
72
|
+
|
73
|
+
auth_admin
|
74
|
+
|
75
|
+
flavor = OpenStack::Nova::Compute::Flavor.find_by_name FLAVOR_NAME
|
76
|
+
assert_not_nil flavor, "Cannot retrieve flavor by name"
|
77
|
+
|
78
|
+
assert_nothing_raised ActiveResource::ClientError, "Cannot destroy flavor '#{flavor.id}'" do
|
79
|
+
flavor.destroy
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
26
84
|
end
|