omf_sfa 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +6 -0
- data/README.md +211 -0
- data/Rakefile +23 -0
- data/bin/parse_rspec.rb +167 -0
- data/etc/omf-sfa/omf-sfa-am.yaml +12 -0
- data/examples/exogeni5nodemanifest.rspec +105 -0
- data/examples/instageni5nodemanifest.rspec +150 -0
- data/lib/omf-sfa/am/am-rest/REST_API.md +301 -0
- data/lib/omf-sfa/am/am-rest/account_handler.rb +145 -0
- data/lib/omf-sfa/am/am-rest/am_rest_server.rb +255 -0
- data/lib/omf-sfa/am/am-rest/api_template.html +48 -0
- data/lib/omf-sfa/am/am-rest/config.ru +110 -0
- data/lib/omf-sfa/am/am-rest/resource_handler.rb +178 -0
- data/lib/omf-sfa/am/am-rest/rest_handler.rb +573 -0
- data/lib/omf-sfa/am/am-rest/session_authenticator.rb +130 -0
- data/lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb +60 -0
- data/lib/omf-sfa/am/am-rpc/am_authorizer.rb +161 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_api.rb +450 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_service.rb +402 -0
- data/lib/omf-sfa/am/am_liaison.rb +93 -0
- data/lib/omf-sfa/am/am_manager.rb +859 -0
- data/lib/omf-sfa/am/am_runner.rb +108 -0
- data/lib/omf-sfa/am/am_scheduler.rb +146 -0
- data/lib/omf-sfa/am/am_server.rb +194 -0
- data/lib/omf-sfa/am/config.ru +122 -0
- data/lib/omf-sfa/am/credential.rb +145 -0
- data/lib/omf-sfa/am/default_authorizer.rb +44 -0
- data/lib/omf-sfa/am/privilege_credential.rb +76 -0
- data/lib/omf-sfa/am/signature.rb +37 -0
- data/lib/omf-sfa/am/user_credential.rb +56 -0
- data/lib/omf-sfa/am.rb +7 -0
- data/lib/omf-sfa/model/abstract_prop_description.rb +87 -0
- data/lib/omf-sfa/model/model_class_description.rb +145 -0
- data/lib/omf-sfa/model/model_data_prop_description.rb +28 -0
- data/lib/omf-sfa/model/model_obj_prop_description.rb +49 -0
- data/lib/omf-sfa/model/ontology.rb +169 -0
- data/lib/omf-sfa/resource/README.md +24 -0
- data/lib/omf-sfa/resource/channel.rb +49 -0
- data/lib/omf-sfa/resource/comp_group.rb +41 -0
- data/lib/omf-sfa/resource/component_lease.rb +10 -0
- data/lib/omf-sfa/resource/constants.rb +24 -0
- data/lib/omf-sfa/resource/group_component.rb +35 -0
- data/lib/omf-sfa/resource/group_membership.rb +17 -0
- data/lib/omf-sfa/resource/gurn.rb +187 -0
- data/lib/omf-sfa/resource/interface.rb +78 -0
- data/lib/omf-sfa/resource/ip.rb +48 -0
- data/lib/omf-sfa/resource/link.rb +29 -0
- data/lib/omf-sfa/resource/node.rb +75 -0
- data/lib/omf-sfa/resource/oaccount.rb +94 -0
- data/lib/omf-sfa/resource/ocomponent.rb +134 -0
- data/lib/omf-sfa/resource/ogroup.rb +106 -0
- data/lib/omf-sfa/resource/olease.rb +61 -0
- data/lib/omf-sfa/resource/oproperty.rb +178 -0
- data/lib/omf-sfa/resource/oreference.rb +15 -0
- data/lib/omf-sfa/resource/oresource.rb +491 -0
- data/lib/omf-sfa/resource/project.rb +28 -0
- data/lib/omf-sfa/resource/project_membership.rb +13 -0
- data/lib/omf-sfa/resource/sfa_base.rb +544 -0
- data/lib/omf-sfa/resource/user.rb +25 -0
- data/lib/omf-sfa/resource.rb +20 -0
- data/lib/omf-sfa/util/create_sample_testbed.rb +68 -0
- data/lib/omf-sfa/util/load_from_sfa_xml.rb +65 -0
- data/lib/omf-sfa/version.rb +4 -0
- data/lib/omf_sfa.rb +5 -0
- data/omf_sfa.gemspec +46 -0
- data/owl/README +3 -0
- data/owl/ben-6509.rdf +1377 -0
- data/owl/ben-dell.rdf +586 -0
- data/owl/ben-dtn.rdf +1698 -0
- data/owl/ben.rdf +1335 -0
- data/owl/collections.owl +309 -0
- data/owl/compute.owl +1486 -0
- data/owl/domain.owl +444 -0
- data/owl/dtn.owl +1165 -0
- data/owl/ec2.owl +385 -0
- data/owl/ethernet.owl +466 -0
- data/owl/eucalyptus.owl +431 -0
- data/owl/id-mp-Request1.rdf +247 -0
- data/owl/itu-grid.owl +147 -0
- data/owl/kansei.owl +511 -0
- data/owl/layer.owl +645 -0
- data/owl/location.owl +117 -0
- data/owl/mass.rdf +608 -0
- data/owl/nlr.rdf +901 -0
- data/owl/orca.owl +181 -0
- data/owl/planetlab.owl +124 -0
- data/owl/protogeni.owl +467 -0
- data/owl/request-6509-2.rdf +150 -0
- data/owl/request-6509-3.rdf +158 -0
- data/owl/request-6509.rdf +199 -0
- data/owl/request.owl +222 -0
- data/owl/storage.owl +511 -0
- data/owl/topology.owl +608 -0
- data/schema/rspec-v3/ad-common.xsd +269 -0
- data/schema/rspec-v3/ad-reservation.rnc +12 -0
- data/schema/rspec-v3/ad-reservation.rng +28 -0
- data/schema/rspec-v3/ad-reservation.xsd +13 -0
- data/schema/rspec-v3/ad.rnc +151 -0
- data/schema/rspec-v3/ad.xsd +77 -0
- data/schema/rspec-v3/any-extension-schema.xsd +38 -0
- data/schema/rspec-v3/any-extension.rnc +30 -0
- data/schema/rspec-v3/common.rnc +185 -0
- data/schema/rspec-v3/manifest-common.xsd +244 -0
- data/schema/rspec-v3/manifest-request.xsd +95 -0
- data/schema/rspec-v3/manifest.rnc +62 -0
- data/schema/rspec-v3/manifest.xsd +34 -0
- data/schema/rspec-v3/request-common.xsd +219 -0
- data/schema/rspec-v3/request-reservation.rnc +12 -0
- data/schema/rspec-v3/request-reservation.xsd +13 -0
- data/schema/rspec-v3/request.rnc +118 -0
- data/schema/rspec-v3/request.xsd +94 -0
- data/share/assets/css/default.css +147 -0
- data/share/assets/css/rest_api.css +0 -0
- data/share/assets/network.html +28 -0
- data/share/assets/network.js +82 -0
- data/spec/am/am-rest/common.rb +29 -0
- data/spec/am/am-rest/resource_group_handler_XspecX.rb +97 -0
- data/spec/am/am-rest/resource_handler_spec.rb +204 -0
- data/spec/am/am-rpc/sfa_methods_spec.rb +150 -0
- data/spec/am/am_manager_spec.rb +307 -0
- data/spec/am/am_scheduler_spec.rb +57 -0
- data/spec/am/common.rb +24 -0
- data/spec/resource/common.rb +31 -0
- data/spec/resource/node_spec.rb +171 -0
- data/spec/resource/oaccount_spec.rb +92 -0
- data/spec/resource/ocomponent_spec.rb +225 -0
- data/spec/resource/ogroup_spec.rb +93 -0
- data/spec/resource/oresource_spec.rb +208 -0
- data/spec/resource_and_leases_spec.rb +377 -0
- data/test/OLD_FILES/assertion1.xml +117 -0
- data/test/OLD_FILES/greeter_spec.rb +15 -0
- data/test/OLD_FILES/mongo_test.rb +45 -0
- data/test/OLD_FILES/req-sfa-2.xml +6 -0
- data/test/OLD_FILES/req-sfa-g.xml +8 -0
- data/test/OLD_FILES/req-sfa-g2.xml +10 -0
- data/test/OLD_FILES/req-sfa-g3.xml +14 -0
- data/test/OLD_FILES/req-sfa.xml +6 -0
- data/test/OLD_FILES/req1.xml +22 -0
- data/test/OLD_FILES/req1b.xml +15 -0
- data/test/OLD_FILES/rspec-test.xml +1867 -0
- data/test/OLD_FILES/test.rb +67 -0
- data/test/OLD_FILES/test2.rb +32 -0
- data/test/am/am_manager_rspec_tests.rb +378 -0
- data/test/am/am_manager_tests.rb +518 -0
- data/test/am/am_scheduler_tests.rb +173 -0
- data/test/resource/olease_test.rb +74 -0
- data/test/sfa_requests/request.xml +5 -0
- data/test/sfa_requests/request1.xml +5 -0
- data/test/sfa_requests/request2.xml +5 -0
- data/test/sfa_requests/request3.xml +5 -0
- metadata +601 -0
@@ -0,0 +1,518 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest' # ensures you're using the gem, and not the built in MT
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/pride'
|
5
|
+
require 'omf-sfa/am/am_manager'
|
6
|
+
require 'dm-migrations'
|
7
|
+
require 'omf_common/load_yaml'
|
8
|
+
require 'active_support/inflector'
|
9
|
+
|
10
|
+
include OMF::SFA::AM
|
11
|
+
|
12
|
+
def init_dm
|
13
|
+
# setup database
|
14
|
+
DataMapper::Logger.new($stdout, :info)
|
15
|
+
|
16
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
17
|
+
#DataMapper.setup(:default, 'sqlite:///tmp/am_test.db')
|
18
|
+
DataMapper::Model.raise_on_save_failure = true
|
19
|
+
DataMapper.finalize
|
20
|
+
|
21
|
+
DataMapper.auto_migrate!
|
22
|
+
end
|
23
|
+
|
24
|
+
def init_logger
|
25
|
+
OMF::Base::Loggable.init_log 'am_manager', :searchPath => File.join(File.dirname(__FILE__), 'am_manager')
|
26
|
+
@config = OMF::Base::YAML.load('omf-sfa-am', :path => [File.dirname(__FILE__) + '/../../etc/omf-sfa'])[:omf_sfa_am]
|
27
|
+
end
|
28
|
+
|
29
|
+
describe AMManager do
|
30
|
+
|
31
|
+
init_logger
|
32
|
+
|
33
|
+
init_dm
|
34
|
+
|
35
|
+
before do
|
36
|
+
DataMapper.auto_migrate! # reset database
|
37
|
+
end
|
38
|
+
|
39
|
+
let (:scheduler) do
|
40
|
+
scheduler = Class.new do
|
41
|
+
def self.get_nil_account
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
def self.create_resource(resource_descr, type_to_create, oproperties, auth)
|
45
|
+
resource_descr[:resource_type] = type_to_create
|
46
|
+
resource_descr[:account] = auth.account
|
47
|
+
type = type_to_create.camelize
|
48
|
+
resource = eval("OMF::SFA::Resource::#{type}").create(resource_descr)
|
49
|
+
if type_to_create.eql?('OLease')
|
50
|
+
resource.valid_from = oproperties[:valid_from]
|
51
|
+
resource.valid_until = oproperties[:valid_until]
|
52
|
+
resource.save
|
53
|
+
end
|
54
|
+
return resource
|
55
|
+
end
|
56
|
+
def self.release_resource(resource, authorizer)
|
57
|
+
resource.destroy
|
58
|
+
end
|
59
|
+
end
|
60
|
+
scheduler
|
61
|
+
end
|
62
|
+
|
63
|
+
let (:manager) { AMManager.new(scheduler) }
|
64
|
+
|
65
|
+
describe 'instance' do
|
66
|
+
it 'can create an AM Manager' do
|
67
|
+
manager
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'can manage a resource' do
|
71
|
+
r = OMF::SFA::Resource::OResource.create(:name => 'r')
|
72
|
+
manager.manage_resource(r)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'account' do
|
77
|
+
let(:auth) { MiniTest::Mock.new }
|
78
|
+
|
79
|
+
before do
|
80
|
+
DataMapper.auto_migrate! # reset database
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'can create account' do
|
84
|
+
auth.expect(:can_create_account?, true)
|
85
|
+
account = manager.find_or_create_account({:name => 'a'}, auth)
|
86
|
+
account.must_be_instance_of(OMF::SFA::Resource::OAccount)
|
87
|
+
auth.verify
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'can find created account' do
|
91
|
+
auth.expect(:can_create_account?, true)
|
92
|
+
a1 = manager.find_or_create_account({:name => 'a'}, auth)
|
93
|
+
|
94
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
95
|
+
a2 = manager.find_or_create_account({:name => 'a'}, auth)
|
96
|
+
a1.must_equal a2
|
97
|
+
|
98
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
99
|
+
a3 = manager.find_account({:name => 'a'}, auth)
|
100
|
+
a1.must_equal a3
|
101
|
+
auth.verify
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'throws exception when looking for non-exisiting account' do
|
105
|
+
lambda do
|
106
|
+
manager.find_account({:name => 'a'}, auth)
|
107
|
+
end.must_raise(UnavailableResourceException)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'can request all accounts visible to a user' do
|
111
|
+
manager.find_all_accounts(auth).must_be_empty
|
112
|
+
|
113
|
+
auth.expect(:can_create_account?, true)
|
114
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
115
|
+
|
116
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
117
|
+
manager.find_all_accounts(auth).must_equal [a1]
|
118
|
+
|
119
|
+
auth.expect(:can_create_account?, true)
|
120
|
+
a2 = manager.find_or_create_account({:name => 'a2'}, auth)
|
121
|
+
|
122
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
123
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
124
|
+
|
125
|
+
manager.find_all_accounts(auth).must_equal [a1, a2]
|
126
|
+
auth.verify
|
127
|
+
|
128
|
+
def auth.can_view_account?(account)
|
129
|
+
raise InsufficientPrivilegesException
|
130
|
+
end
|
131
|
+
manager.find_all_accounts(auth).must_be_empty
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'can request accounts which are active' do
|
136
|
+
auth.expect(:can_create_account?, true)
|
137
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
138
|
+
|
139
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
140
|
+
a2 = manager.find_active_account({:name => 'a1'}, auth)
|
141
|
+
a2.wont_be_nil
|
142
|
+
|
143
|
+
# Expire account
|
144
|
+
a2.valid_until = Time.now - 100
|
145
|
+
a2.save
|
146
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
147
|
+
lambda do
|
148
|
+
manager.find_active_account({:name => 'a1'}, auth)
|
149
|
+
end.must_raise(UnavailableResourceException)
|
150
|
+
auth.verify
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'can renew accounts' do
|
154
|
+
auth.expect(:can_create_account?, true)
|
155
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
156
|
+
|
157
|
+
time = Time.now + 100
|
158
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
159
|
+
auth.expect(:can_renew_account?, true, [a1, time])
|
160
|
+
a2 = manager.renew_account_until({:name => 'a1'}, time, auth)
|
161
|
+
|
162
|
+
# we convert the time to INT in order to round up fractional seconds
|
163
|
+
# more info: http://stackoverflow.com/questions/8763050/how-to-compare-time-in-ruby
|
164
|
+
time1 = Time.at(a2.valid_until.to_i)
|
165
|
+
time2 = Time.at(time.to_i)
|
166
|
+
time1.must_equal time2
|
167
|
+
|
168
|
+
auth.verify
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'can close account' do
|
172
|
+
auth.expect(:can_create_account?, true)
|
173
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
174
|
+
a1.active?.must_equal true
|
175
|
+
a1.closed?.must_equal false
|
176
|
+
|
177
|
+
auth.expect(:can_view_account?, true, [OMF::SFA::Resource::OAccount])
|
178
|
+
auth.expect(:can_close_account?, true, [a1])
|
179
|
+
a2 = manager.close_account({:name => 'a1'}, auth)
|
180
|
+
a2.reload
|
181
|
+
a2.active?.must_equal false
|
182
|
+
a2.closed?.must_equal true
|
183
|
+
auth.verify
|
184
|
+
end
|
185
|
+
end #account
|
186
|
+
|
187
|
+
describe 'users' do
|
188
|
+
|
189
|
+
before do
|
190
|
+
DataMapper.auto_migrate! # reset database
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'can create a user' do
|
194
|
+
u = manager.find_or_create_user({:urn => 'urn:publicid:IDN+topdomain:subdomain+user+pi'})
|
195
|
+
u.must_be_instance_of(OMF::SFA::Resource::User)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'can find an already created user' do
|
199
|
+
user_descr = {:urn => 'urn:publicid:IDN+topdomain:subdomain+user+pi'}
|
200
|
+
u1 = OMF::SFA::Resource::User.create(user_descr)
|
201
|
+
u2 = manager.find_or_create_user(user_descr)
|
202
|
+
u1.must_equal u2
|
203
|
+
|
204
|
+
u2 = manager.find_user(user_descr)
|
205
|
+
u1.must_equal u2
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'throws an exception when looking for a non existing user' do
|
209
|
+
lambda do
|
210
|
+
manager.find_user({:urn => 'urn:publicid:IDN+topdomain:subdomain+user+pi'})
|
211
|
+
end.must_raise(UnavailableResourceException)
|
212
|
+
end
|
213
|
+
|
214
|
+
end #users
|
215
|
+
|
216
|
+
describe 'lease' do
|
217
|
+
|
218
|
+
let(:auth) { MiniTest::Mock.new }
|
219
|
+
|
220
|
+
lease_oproperties = {:valid_from => Time.now, :valid_until => Time.now + 100}
|
221
|
+
|
222
|
+
account = OMF::SFA::Resource::OAccount.first_or_create(:name => 'a1')
|
223
|
+
|
224
|
+
before do
|
225
|
+
DataMapper.auto_migrate! # reset database
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'can create lease' do
|
229
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
230
|
+
auth.expect(:account, account)
|
231
|
+
lease = manager.find_or_create_lease({:name => 'l1'}, lease_oproperties, auth)
|
232
|
+
lease.must_be_instance_of(OMF::SFA::Resource::OLease)
|
233
|
+
auth.verify
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'can find created lease' do
|
237
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
238
|
+
auth.expect(:account, account)
|
239
|
+
a1 = manager.find_or_create_lease({:name => 'l1'}, lease_oproperties, auth)
|
240
|
+
|
241
|
+
auth.expect(:can_view_lease?, true, [OMF::SFA::Resource::OLease])
|
242
|
+
a2 = manager.find_or_create_lease({:name => 'l1'}, lease_oproperties, auth)
|
243
|
+
a1.must_equal a2
|
244
|
+
|
245
|
+
auth.expect(:can_view_lease?, true, [OMF::SFA::Resource::OLease])
|
246
|
+
a3 = manager.find_lease({:name => 'l1'}, {}, auth)
|
247
|
+
a1.must_equal a3
|
248
|
+
auth.verify
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'throws exception when looking for non-exisiting lease' do
|
252
|
+
lambda do
|
253
|
+
manager.find_lease({:name => 'l1'}, {}, auth)
|
254
|
+
end.must_raise(UnavailableResourceException)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "can request all user's leases" do
|
258
|
+
OMF::SFA::Resource::OLease.create({:name => "another_user's_lease"})
|
259
|
+
|
260
|
+
auth.expect(:can_create_account?, true)
|
261
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
262
|
+
auth.expect(:account, a1)
|
263
|
+
|
264
|
+
manager.find_all_leases_for_account(a1, auth).must_be_empty
|
265
|
+
|
266
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
267
|
+
l1 = manager.find_or_create_lease({:name => 'l1', :account => a1}, lease_oproperties, auth)
|
268
|
+
|
269
|
+
auth.expect(:can_view_lease?, true, [OMF::SFA::Resource::OLease])
|
270
|
+
manager.find_all_leases_for_account(a1, auth).must_equal [l1]
|
271
|
+
|
272
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
273
|
+
auth.expect(:account, a1)
|
274
|
+
l2 = manager.find_or_create_lease({:name => 'l2', :account => a1}, lease_oproperties, auth)
|
275
|
+
|
276
|
+
auth.expect(:can_view_lease?, true, [OMF::SFA::Resource::OLease])
|
277
|
+
auth.expect(:can_view_lease?, true, [OMF::SFA::Resource::OLease])
|
278
|
+
manager.find_all_leases_for_account(a1, auth).must_equal [l1, l2]
|
279
|
+
|
280
|
+
def auth.can_view_lease?(lease)
|
281
|
+
raise InsufficientPrivilegesException
|
282
|
+
end
|
283
|
+
manager.find_all_leases_for_account(a1, auth).must_be_empty
|
284
|
+
auth.verify
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'can modify leases' do
|
288
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
289
|
+
auth.expect(:account, account)
|
290
|
+
l1 = manager.find_or_create_lease({:name => 'l1'}, lease_oproperties, auth)
|
291
|
+
auth.verify
|
292
|
+
|
293
|
+
valid_from = Time.now + 1000
|
294
|
+
valid_until = valid_from + 1000
|
295
|
+
auth.expect(:can_modify_lease?, true, [l1])
|
296
|
+
l2 = manager.modify_lease({:valid_from => valid_from, :valid_until => valid_until}, l1, auth)
|
297
|
+
auth.verify
|
298
|
+
l2.must_equal l1.reload
|
299
|
+
|
300
|
+
# more info on comparing time objects here: http://stackoverflow.com/questions/8763050/how-to-compare-time-in-ruby
|
301
|
+
time1 = Time.at(l2.valid_from.to_i)
|
302
|
+
time1.must_equal Time.at(valid_from.to_i)
|
303
|
+
|
304
|
+
time1 = Time.at(l2.valid_until.to_i)
|
305
|
+
time1.must_equal Time.at(valid_until.to_i)
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'can release a lease' do
|
309
|
+
auth.expect(:can_create_resource?, true, [Hash, 'OLease'])
|
310
|
+
auth.expect(:account, account)
|
311
|
+
l1 = manager.find_or_create_lease({:name => 'l1'}, lease_oproperties, auth)
|
312
|
+
auth.verify
|
313
|
+
|
314
|
+
auth.expect(:can_release_lease?, true, [l1])
|
315
|
+
manager.release_lease(l1, auth)
|
316
|
+
auth.verify
|
317
|
+
l1.reload
|
318
|
+
l1.cancelled?.must_equal true
|
319
|
+
end
|
320
|
+
|
321
|
+
end #lease
|
322
|
+
|
323
|
+
describe 'resource' do
|
324
|
+
|
325
|
+
account = OMF::SFA::Resource::OAccount.create(:name => 'a')
|
326
|
+
|
327
|
+
auth = Minitest::Mock.new
|
328
|
+
|
329
|
+
before do
|
330
|
+
DataMapper.auto_migrate! # reset database
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'finds single resource belonging to anyone through its name (Hash)' do
|
334
|
+
r1 = OMF::SFA::Resource::OResource.create(:name => 'r1')
|
335
|
+
manager.manage_resources([r1])
|
336
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
337
|
+
r = manager.find_resource({:name => 'r1'}, auth)
|
338
|
+
auth.verify
|
339
|
+
r.must_be_instance_of(OMF::SFA::Resource::OResource)
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'finds single resource belonging to anyone through its name (String)' do
|
343
|
+
r1 = OMF::SFA::Resource::OResource.create(:name =>'r1')
|
344
|
+
manager.manage_resources([r1])
|
345
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
346
|
+
r = manager.find_resource('r1', auth)
|
347
|
+
auth.verify
|
348
|
+
r.must_be_instance_of(OMF::SFA::Resource::OResource)
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'finds a resource through its instance' do
|
352
|
+
r1 = OMF::SFA::Resource::Node.create(:name => 'r1')
|
353
|
+
manager.manage_resources([r1])
|
354
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::Node])
|
355
|
+
r = manager.find_resource(r1, auth)
|
356
|
+
auth.verify
|
357
|
+
r.must_be_instance_of(OMF::SFA::Resource::Node)
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'finds a resource through its uuid' do
|
361
|
+
r1 = OMF::SFA::Resource::OResource.create(:uuid => '759ae077-2fda-4d02-8921-ab0235a09920')
|
362
|
+
manager.manage_resources([r1])
|
363
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
364
|
+
r = manager.find_resource('759ae077-2fda-4d02-8921-ab0235a09920', auth)
|
365
|
+
auth.verify
|
366
|
+
r.must_be_instance_of(OMF::SFA::Resource::OResource)
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'throws an exception for unknown resource description' do
|
370
|
+
lambda do
|
371
|
+
manager.find_resource(nil, auth)
|
372
|
+
end.must_raise(FormatException)
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'throws an exception when looking for a non existing resource' do
|
376
|
+
lambda do
|
377
|
+
manager.find_resource('r1', auth)
|
378
|
+
end.must_raise(UnknownResourceException)
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'throws an exception when is not privileged to view the resource' do
|
382
|
+
authorizerr = Minitest::Mock.new
|
383
|
+
r1 = OMF::SFA::Resource::OResource.create(:name =>'r1')
|
384
|
+
manager.manage_resources([r1])
|
385
|
+
|
386
|
+
def authorizerr.can_view_resource?(*args)
|
387
|
+
raise InsufficientPrivilegesException.new
|
388
|
+
end
|
389
|
+
|
390
|
+
lambda do
|
391
|
+
manager.find_resource('r1', authorizerr)
|
392
|
+
end.must_raise(InsufficientPrivilegesException)
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'finds single resource belonging to an account' do
|
396
|
+
r1 = OMF::SFA::Resource::OResource.create(:name => 'r1')
|
397
|
+
manager.manage_resources([r1])
|
398
|
+
|
399
|
+
auth.expect(:account, account)
|
400
|
+
lambda do
|
401
|
+
manager.find_resource_for_account({:name => 'r1'}, auth)
|
402
|
+
end.must_raise(UnknownResourceException)
|
403
|
+
auth.verify
|
404
|
+
|
405
|
+
# now, assign it to this account
|
406
|
+
r1.account = account
|
407
|
+
r1.save
|
408
|
+
auth.expect(:account, account)
|
409
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
410
|
+
r = manager.find_resource_for_account({:name => 'r1'}, auth)
|
411
|
+
auth.verify
|
412
|
+
r.must_equal r1
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'will find all the resources of an account' do
|
416
|
+
r1 = OMF::SFA::Resource::OResource.create({:name => 'r1', :account => account})
|
417
|
+
r2 = OMF::SFA::Resource::OResource.create({:name => 'r2', :account => account})
|
418
|
+
r3 = OMF::SFA::Resource::OResource.create({:name => 'r3'})
|
419
|
+
|
420
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
421
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
422
|
+
r = manager.find_all_resources_for_account(account, auth)
|
423
|
+
r.must_equal [r1, r2]
|
424
|
+
auth.verify
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'will find all the components of an account' do
|
428
|
+
r1 = OMF::SFA::Resource::OComponent.create({:name => 'r1', :account => account})
|
429
|
+
r2 = OMF::SFA::Resource::Node.create({:name => 'r2', :account => account})
|
430
|
+
r3 = OMF::SFA::Resource::OResource.create({:name => 'r3', :account => account})
|
431
|
+
r4 = OMF::SFA::Resource::OComponent.create({:name => 'r4'})
|
432
|
+
|
433
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
434
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
435
|
+
r = manager.find_all_components_for_account(account, auth)
|
436
|
+
r.must_equal [r1, r2]
|
437
|
+
auth.verify
|
438
|
+
end
|
439
|
+
|
440
|
+
it 'will create a resource' do
|
441
|
+
resource_descr = {:name => 'r1'}
|
442
|
+
type_to_create = 'node'
|
443
|
+
auth.expect(:account, account)
|
444
|
+
auth.expect(:can_create_resource?, true, [Hash, String])
|
445
|
+
r = manager.find_or_create_resource(resource_descr, type_to_create, {}, auth)
|
446
|
+
auth.verify
|
447
|
+
r.must_equal OMF::SFA::Resource::Node.first(:name => 'r1')
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'will find an already created resource' do
|
451
|
+
resource_descr = {:name => 'r1'}
|
452
|
+
r1 = OMF::SFA::Resource::OResource.create(resource_descr)
|
453
|
+
type_to_create = 'node'
|
454
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OResource])
|
455
|
+
r = manager.find_or_create_resource(resource_descr, type_to_create, {}, auth)
|
456
|
+
auth.verify
|
457
|
+
r.must_equal r1
|
458
|
+
end
|
459
|
+
|
460
|
+
it 'will create a resource if not already available for the account' do
|
461
|
+
auth.expect(:account, account)
|
462
|
+
auth.expect(:account, account)
|
463
|
+
auth.expect(:can_create_resource?, true, [Hash, String])
|
464
|
+
descr = {:name => 'v1'}
|
465
|
+
r = manager.find_or_create_resource_for_account(descr, 'o_resource', {}, auth)
|
466
|
+
auth.verify
|
467
|
+
vr = OMF::SFA::Resource::OResource.first({:name => 'v1', :account => account})
|
468
|
+
r.must_equal vr
|
469
|
+
end
|
470
|
+
|
471
|
+
it 'will create resource from rspec' do
|
472
|
+
rspec = %{
|
473
|
+
<rspec xmlns="http://www.geni.net/resources/rspec/3" xmlns:omf="http://nitlab.inf.uth.gr/schema/sfa/rspec/1" type="request">
|
474
|
+
<node component_id="urn:publicid:IDN+openlab+node+node1" component_name="node1" client_id="omf">
|
475
|
+
</node>
|
476
|
+
</rspec>
|
477
|
+
}
|
478
|
+
req = Nokogiri.XML(rspec)
|
479
|
+
|
480
|
+
auth.expect(:can_create_resource?, true, [Hash, String])
|
481
|
+
auth.expect(:account, account)
|
482
|
+
auth.expect(:account, account)
|
483
|
+
r = manager.update_resources_from_rspec(req.root, false, auth)
|
484
|
+
auth.verify
|
485
|
+
r.first.must_equal OMF::SFA::Resource::Node.first(:name => 'node1')
|
486
|
+
end
|
487
|
+
|
488
|
+
it 'will release a resource' do
|
489
|
+
r1 = OMF::SFA::Resource::OResource.create(:name => 'r1')
|
490
|
+
manager.manage_resources([r1])
|
491
|
+
auth.expect(:can_release_resource?, true, [r1])
|
492
|
+
|
493
|
+
manager.release_resource(r1, auth)
|
494
|
+
auth.verify
|
495
|
+
OMF::SFA::Resource::OResource.first(:name => 'r1').must_be_nil
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'will release all components of an account' do
|
499
|
+
OMF::SFA::Resource::OResource.create({:name => 'r1', :account => account})
|
500
|
+
OMF::SFA::Resource::Node.create({:name => 'n1', :account => account})
|
501
|
+
OMF::SFA::Resource::Node.create({:name => 'n2'})
|
502
|
+
OMF::SFA::Resource::OComponent.create({:name => 'c1', :account => account})
|
503
|
+
|
504
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::Node])
|
505
|
+
auth.expect(:can_view_resource?, true, [OMF::SFA::Resource::OComponent])
|
506
|
+
auth.expect(:can_release_resource?, true, [OMF::SFA::Resource::Node])
|
507
|
+
auth.expect(:can_release_resource?, true, [OMF::SFA::Resource::OComponent])
|
508
|
+
manager.release_all_components_for_account(account, auth)
|
509
|
+
OMF::SFA::Resource::OResource.first({:account => account}).wont_be_nil
|
510
|
+
OMF::SFA::Resource::Node.first({:account => account}).must_be_nil
|
511
|
+
OMF::SFA::Resource::OComponent.first({:account => account}).must_be_nil
|
512
|
+
OMF::SFA::Resource::Node.first({:name => 'n2'}).wont_be_nil
|
513
|
+
auth.verify
|
514
|
+
end
|
515
|
+
|
516
|
+
end #resource
|
517
|
+
|
518
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest' # ensures you're using the gem, and not the built in MT
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/pride'
|
5
|
+
require 'omf-sfa/am/am_scheduler'
|
6
|
+
require 'dm-migrations'
|
7
|
+
require 'omf_common/load_yaml'
|
8
|
+
require 'active_support/inflector'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
include OMF::SFA::AM
|
12
|
+
|
13
|
+
def init_dm
|
14
|
+
# setup database
|
15
|
+
DataMapper::Logger.new($stdout, :info)
|
16
|
+
|
17
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
18
|
+
#DataMapper.setup(:default, 'sqlite://~/am_test.db')
|
19
|
+
DataMapper::Model.raise_on_save_failure = true
|
20
|
+
DataMapper.finalize
|
21
|
+
|
22
|
+
DataMapper.auto_migrate!
|
23
|
+
end
|
24
|
+
|
25
|
+
def init_logger
|
26
|
+
OMF::Base::Loggable.init_log 'am_scheduler', :searchPath => File.join(File.dirname(__FILE__), 'am_scheduler')
|
27
|
+
@config = OMF::Base::YAML.load('omf-sfa-am', :path => [File.dirname(__FILE__) + '/../../etc/omf-sfa'])[:omf_sfa_am]
|
28
|
+
end
|
29
|
+
|
30
|
+
describe AMScheduler do
|
31
|
+
|
32
|
+
init_logger
|
33
|
+
|
34
|
+
init_dm
|
35
|
+
|
36
|
+
before do
|
37
|
+
DataMapper.auto_migrate! # reset database
|
38
|
+
end
|
39
|
+
|
40
|
+
#let (:scheduler) { scheduler = AMScheduler.new() }
|
41
|
+
scheduler = AMScheduler.new()
|
42
|
+
|
43
|
+
describe 'instance' do
|
44
|
+
it 'can initialize itself' do
|
45
|
+
scheduler.must_be_instance_of(AMScheduler)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can return the default account' do
|
49
|
+
a = scheduler.get_nil_account()
|
50
|
+
a.must_be_instance_of(OMF::SFA::Resource::OAccount)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'resources' do
|
55
|
+
|
56
|
+
a = scheduler.get_nil_account()
|
57
|
+
account = OMF::SFA::Resource::OAccount.create({:name => 'a1'})
|
58
|
+
|
59
|
+
it 'can create a node' do
|
60
|
+
r = OMF::SFA::Resource::Node.create({:name => 'r1', :account => a})
|
61
|
+
|
62
|
+
authorizer = MiniTest::Mock.new
|
63
|
+
authorizer.expect(:account, account)
|
64
|
+
|
65
|
+
res = scheduler.create_resource({:name => 'r1', :account => account}, 'node', {}, authorizer)
|
66
|
+
res.must_be_instance_of(OMF::SFA::Resource::Node)
|
67
|
+
res.account.must_equal(account)
|
68
|
+
res.provides.must_be_empty
|
69
|
+
res.provided_by.must_equal(r)
|
70
|
+
|
71
|
+
r1 = OMF::SFA::Resource::Node.first({:name => 'r1', :account => a})
|
72
|
+
r1.must_equal(r)
|
73
|
+
r1.provides.must_include(res)
|
74
|
+
|
75
|
+
authorizer.verify
|
76
|
+
#time = Time.now
|
77
|
+
#l1 = scheduler.create_resource({:name => 'l1'}, 'OLease', {:valid_from => time, :valid_until => (time + 100)}, authorizer)
|
78
|
+
#l1 = OMF::SFA::Resource::OLease.create({:name => 'l1', :valid_from => time, :valid_until => (time + 100)})
|
79
|
+
#o = scheduler.lease_component(l1, res)
|
80
|
+
#puts o.to_json
|
81
|
+
|
82
|
+
#o.leases.each do |l|
|
83
|
+
#puts l.to_json
|
84
|
+
#end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can lease a component' do
|
88
|
+
r = OMF::SFA::Resource::Node.create({:name => 'r1', :account => a})
|
89
|
+
|
90
|
+
authorizer = MiniTest::Mock.new
|
91
|
+
authorizer.expect(:account, account)
|
92
|
+
|
93
|
+
res = scheduler.create_resource({:name => 'r1', :account => account}, 'node', {}, authorizer)
|
94
|
+
res.must_be_instance_of(OMF::SFA::Resource::Node)
|
95
|
+
res.account.must_equal(account)
|
96
|
+
res.provides.must_be_empty
|
97
|
+
res.provided_by.must_equal(r)
|
98
|
+
|
99
|
+
time = Time.now
|
100
|
+
l1 = scheduler.create_resource({:name => 'l1'}, 'OLease', {:valid_from => time, :valid_until => (time + 100)}, authorizer)
|
101
|
+
o = scheduler.lease_component(l1, res)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'cannot lease components on overlapping time' do
|
105
|
+
r = OMF::SFA::Resource::Node.create({:name => 'r1', :account => a})
|
106
|
+
|
107
|
+
authorizer = MiniTest::Mock.new
|
108
|
+
authorizer.expect(:account, account)
|
109
|
+
|
110
|
+
res = scheduler.create_resource({:name => 'r1', :account => account}, 'node', {}, authorizer)
|
111
|
+
res.must_be_instance_of(OMF::SFA::Resource::Node)
|
112
|
+
res.account.must_equal(account)
|
113
|
+
res.provides.must_be_empty
|
114
|
+
res.provided_by.must_equal(r)
|
115
|
+
|
116
|
+
time = Time.now
|
117
|
+
l1 = scheduler.create_resource({:name => 'l1'}, 'OLease', {:valid_from => time, :valid_until => (time + 100) }, authorizer)
|
118
|
+
l2 = scheduler.create_resource({:name => 'l2'}, 'OLease', {:valid_from => time + 400, :valid_until => (time + 500)}, authorizer)
|
119
|
+
l3 = scheduler.create_resource({:name => 'l3'}, 'OLease', {:valid_from => time + 10, :valid_until => (time + 20)}, authorizer)
|
120
|
+
l4 = scheduler.create_resource({:name => 'l4'}, 'OLease', {:valid_from => time - 10, :valid_until => (time + 20)}, authorizer)
|
121
|
+
l5 = scheduler.create_resource({:name => 'l5'}, 'OLease', {:valid_from => time - 410, :valid_until => (time + 490)}, authorizer)
|
122
|
+
|
123
|
+
o1 = scheduler.lease_component(l1, res)
|
124
|
+
o2 = scheduler.lease_component(l2, res)
|
125
|
+
#o3 = scheduler.lease_component(l3, res)
|
126
|
+
proc{o3 = scheduler.lease_component(l3, res)}.must_raise(UnavailableResourceException)
|
127
|
+
proc{o4 = scheduler.lease_component(l4, res)}.must_raise(UnavailableResourceException)
|
128
|
+
end
|
129
|
+
|
130
|
+
it '123 can release a resource' do
|
131
|
+
r = OMF::SFA::Resource::Node.create({:name => 'r1', :account => a})
|
132
|
+
|
133
|
+
authorizer = MiniTest::Mock.new
|
134
|
+
3.times{authorizer.expect(:account, account)}
|
135
|
+
|
136
|
+
time = Time.now
|
137
|
+
r1 = scheduler.create_resource({:name => 'r1', :account => account}, 'node', {}, authorizer)
|
138
|
+
l1 = scheduler.create_resource({:name => 'l1'}, 'OLease', {:valid_from => time, :valid_until => (time + 1000) }, authorizer)
|
139
|
+
l1.status.must_equal("pending")
|
140
|
+
scheduler.lease_component(l1, r1)
|
141
|
+
|
142
|
+
r2 = scheduler.create_resource({:name => 'r1', :account => account}, 'node', {}, authorizer)
|
143
|
+
l2 = scheduler.create_resource({:name => 'l2'}, 'OLease', {:valid_from => time - 1000, :valid_until => (time -100) }, authorizer)
|
144
|
+
l2.status.must_equal("pending")
|
145
|
+
scheduler.lease_component(l2, r2)
|
146
|
+
l1.reload;l2.reload
|
147
|
+
l1.status.must_equal("accepted")
|
148
|
+
l2.status.must_equal("accepted")
|
149
|
+
|
150
|
+
res = scheduler.release_resource(r1, authorizer)
|
151
|
+
res.must_equal(true)
|
152
|
+
res = scheduler.release_resource(r2, authorizer)
|
153
|
+
res.must_equal(true)
|
154
|
+
l1.reload;l2.reload
|
155
|
+
l1.status.must_equal("cancelled")
|
156
|
+
l2.status.must_equal("past")
|
157
|
+
|
158
|
+
r.provides.must_be_empty()
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'can release a resource without leases' do
|
162
|
+
n = OMF::SFA::Resource::Node.create(name: 'n1', account: a)
|
163
|
+
|
164
|
+
authorizer = MiniTest::Mock.new
|
165
|
+
authorizer.expect(:account, account)
|
166
|
+
|
167
|
+
r1 = scheduler.create_resource({:name => 'n1'}, 'node', {}, authorizer)
|
168
|
+
|
169
|
+
res = scheduler.release_resource(r1, authorizer)
|
170
|
+
res.must_equal(true)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|