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,307 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/common"
|
3
|
+
require 'omf-sfa/am/am_manager'
|
4
|
+
require 'omf-sfa/resource'
|
5
|
+
require "rspec/expectations"
|
6
|
+
require 'omf_common/lobject'
|
7
|
+
require 'omf_common/load_yaml'
|
8
|
+
|
9
|
+
include OMF::SFA::AM
|
10
|
+
|
11
|
+
def init_logger
|
12
|
+
OMF::Common::Loggable.init_log 'am_manager', :searchPath => File.join(File.dirname(__FILE__), 'am_manager')
|
13
|
+
@config = OMF::Common::YAML.load('omf-sfa-am', :path => [File.dirname(__FILE__) + '/../../etc/omf-sfa'])[:omf_sfa_am]
|
14
|
+
end
|
15
|
+
|
16
|
+
describe AMManager do
|
17
|
+
|
18
|
+
init_logger
|
19
|
+
|
20
|
+
before :all do
|
21
|
+
init_dm
|
22
|
+
end
|
23
|
+
|
24
|
+
let (:scheduler) do
|
25
|
+
scheduler = double('scheduler')
|
26
|
+
scheduler.stub(:get_nil_account).and_return(nil)
|
27
|
+
scheduler
|
28
|
+
end
|
29
|
+
|
30
|
+
let (:manager) { AMManager.new(scheduler) }
|
31
|
+
|
32
|
+
context 'instance' do
|
33
|
+
it 'can create an AM Manager' do
|
34
|
+
manager
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can create an AM Manager' do
|
38
|
+
r = OMF::SFA::Resource::OResource.new(:name => 'r')
|
39
|
+
manager.manage_resource(r)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'account' do
|
44
|
+
let(:auth) { double('authorizer') }
|
45
|
+
|
46
|
+
before :each do
|
47
|
+
DataMapper.auto_migrate! # reset database
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'can create account' do
|
51
|
+
auth.should_receive(:can_create_account?)#.with("02134")
|
52
|
+
account = manager.find_or_create_account({:name => 'a'}, auth)
|
53
|
+
account.should be_a(OMF::SFA::Resource::OAccount)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can find created account' do
|
57
|
+
auth.should_receive(:can_create_account?)
|
58
|
+
a1 = manager.find_or_create_account({:name => 'a'}, auth)
|
59
|
+
|
60
|
+
auth.should_receive(:can_view_account?).with(kind_of(OMF::SFA::Resource::OAccount))
|
61
|
+
a2 = manager.find_or_create_account({:name => 'a'}, auth)
|
62
|
+
a1.should == a2
|
63
|
+
|
64
|
+
auth.should_receive(:can_view_account?).with(kind_of(OMF::SFA::Resource::OAccount))
|
65
|
+
a3 = manager.find_account({:name => 'a'}, auth)
|
66
|
+
a1.should == a3
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'throws exception when looking for non-exisiting account' do
|
70
|
+
lambda do
|
71
|
+
manager.find_account({:name => 'a'}, auth)
|
72
|
+
end.should raise_error(UnavailableResourceException)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'can request all accounts visible to a user' do
|
76
|
+
manager.find_all_accounts(auth).should == []
|
77
|
+
|
78
|
+
auth.should_receive(:can_create_account?)
|
79
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
80
|
+
|
81
|
+
auth.should_receive(:can_view_account?)
|
82
|
+
manager.find_all_accounts(auth).should == [a1]
|
83
|
+
|
84
|
+
auth.should_receive(:can_create_account?)
|
85
|
+
a2 = manager.find_or_create_account({:name => 'a2'}, auth)
|
86
|
+
|
87
|
+
auth.should_receive(:can_view_account?).exactly(2).times
|
88
|
+
manager.find_all_accounts(auth).should == [a1, a2]
|
89
|
+
|
90
|
+
auth.should_receive(:can_view_account?).exactly(2).times.and_raise(InsufficientPrivilegesException)
|
91
|
+
manager.find_all_accounts(auth).should == []
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'can request accounts which are active' do
|
95
|
+
auth.should_receive(:can_create_account?)
|
96
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
97
|
+
|
98
|
+
auth.should_receive(:can_view_account?)
|
99
|
+
a2 = manager.find_active_account({:name => 'a1'}, auth)
|
100
|
+
a2.should_not be_nil
|
101
|
+
|
102
|
+
# Expire account
|
103
|
+
a2.valid_until = Time.now - 100
|
104
|
+
a2.save
|
105
|
+
auth.should_receive(:can_view_account?)
|
106
|
+
lambda do
|
107
|
+
manager.find_active_account({:name => 'a1'}, auth)
|
108
|
+
end.should raise_error(UnavailableResourceException)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'can renew accounts' do
|
112
|
+
auth.should_receive(:can_create_account?)
|
113
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
114
|
+
|
115
|
+
time = Time.now + 100
|
116
|
+
auth.should_receive(:can_view_account?)
|
117
|
+
auth.should_receive(:can_renew_account?).with(a1, time)
|
118
|
+
a2 = manager.renew_account_until({:name => 'a1'}, time, auth)
|
119
|
+
a2.should == a1
|
120
|
+
a2.valid_until.should == time
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'can close account' do
|
124
|
+
auth.should_receive(:can_create_account?)
|
125
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
126
|
+
a1.active?.should be_true
|
127
|
+
a1.closed?.should be_false
|
128
|
+
|
129
|
+
auth.should_receive(:can_view_account?)
|
130
|
+
auth.should_receive(:can_close_account?).with(a1)
|
131
|
+
a2 = manager.close_account({:name => 'a1'}, auth)
|
132
|
+
a2.reload
|
133
|
+
a2.active?.should be_false
|
134
|
+
a2.closed?.should be_true
|
135
|
+
end
|
136
|
+
end # context - account
|
137
|
+
|
138
|
+
context 'lease' do
|
139
|
+
|
140
|
+
let(:auth) { double('authorizer') }
|
141
|
+
|
142
|
+
before :each do
|
143
|
+
DataMapper.auto_migrate! # reset database
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'can create lease' do
|
147
|
+
auth.should_receive(:can_create_lease?)
|
148
|
+
lease = manager.find_or_create_lease({:name => 'l1'}, {:valid_from => Time.now, :valid_until => Time.now + 100}, auth)
|
149
|
+
lease.should be_a(OMF::SFA::Resource::OLease)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'can find created lease' do
|
153
|
+
auth.should_receive(:can_create_lease?)
|
154
|
+
a1 = manager.find_or_create_lease({:name => 'l1'}, {}, auth)
|
155
|
+
|
156
|
+
auth.should_receive(:can_view_lease?).with(kind_of(OMF::SFA::Resource::OLease))
|
157
|
+
a2 = manager.find_or_create_lease({:name => 'l1'}, {}, auth)
|
158
|
+
a1.should == a2
|
159
|
+
|
160
|
+
auth.should_receive(:can_view_lease?).with(kind_of(OMF::SFA::Resource::OLease))
|
161
|
+
a3 = manager.find_lease({:name => 'l1'}, auth)
|
162
|
+
a1.should == a3
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'throws exception when looking for non-exisiting lease' do
|
166
|
+
lambda do
|
167
|
+
manager.find_lease({:name => 'l1'}, auth)
|
168
|
+
end.should raise_error(UnavailableResourceException)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "can request all user's leases" do
|
172
|
+
|
173
|
+
auth.should_receive(:can_create_account?)
|
174
|
+
a1 = manager.find_or_create_account({:name => 'a1'}, auth)
|
175
|
+
|
176
|
+
manager.find_all_leases_for_account(a1, auth).should == []
|
177
|
+
|
178
|
+
auth.should_receive(:can_create_lease?)
|
179
|
+
l1 = manager.find_or_create_lease({:name => 'l1', :account => a1}, {}, auth)
|
180
|
+
|
181
|
+
auth.should_receive(:can_view_lease?)
|
182
|
+
manager.find_all_leases_for_account(a1, auth).should == [l1]
|
183
|
+
|
184
|
+
auth.should_receive(:can_create_lease?)
|
185
|
+
l2 = manager.find_or_create_lease({:name => 'l2', :account => a1}, {}, auth)
|
186
|
+
|
187
|
+
auth.should_receive(:can_view_lease?).exactly(2).times
|
188
|
+
manager.find_all_leases_for_account(a1, auth).should == [l1, l2]
|
189
|
+
|
190
|
+
auth.should_receive(:can_view_lease?).exactly(2).times.and_raise(InsufficientPrivilegesException)
|
191
|
+
manager.find_all_leases_for_account(a1, auth).should == []
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'can modify leases' do
|
195
|
+
auth.should_receive(:can_create_lease?)
|
196
|
+
l1 = manager.find_or_create_lease({:name => 'l1'}, {}, auth)
|
197
|
+
|
198
|
+
valid_from = 1338847200
|
199
|
+
valid_until = 1338850800
|
200
|
+
auth.should_receive(:can_modify_lease?).with(l1)
|
201
|
+
l2 = manager.modify_lease({:valid_from => valid_from, :valid_until => valid_until}, l1, auth)
|
202
|
+
l2.should == l1.reload
|
203
|
+
l2.valid_from.should == valid_from
|
204
|
+
l2.valid_until.should == valid_until
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'can release a lease' do
|
208
|
+
auth.should_receive(:can_create_lease?)
|
209
|
+
l1 = manager.find_or_create_lease({:name => 'l1'}, {}, auth)
|
210
|
+
|
211
|
+
auth.should_receive(:can_release_lease?).with(l1)
|
212
|
+
manager.release_lease(l1, auth)#.should be_true
|
213
|
+
end
|
214
|
+
|
215
|
+
end # context - lease
|
216
|
+
|
217
|
+
context 'resource' do
|
218
|
+
let(:account) { OMF::SFA::Resource::OAccount.new(:name => 'a') }
|
219
|
+
let(:auth) do
|
220
|
+
auth = double('authorizer')
|
221
|
+
auth.stub(:account) { account }
|
222
|
+
auth
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
before :each do
|
227
|
+
DataMapper.auto_migrate! # reset database
|
228
|
+
@r1 = OMF::SFA::Resource::OResource.new(:name => 'r1')
|
229
|
+
@r2 = OMF::SFA::Resource::OResource.new(:name => 'r2')
|
230
|
+
manager.manage_resources([@r1, @r2])
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'find single resource belonging to anyone' do
|
234
|
+
auth.should_receive(:can_view_resource?).with(kind_of(OMF::SFA::Resource::OResource))
|
235
|
+
r = manager.find_resource({:name => 'r1'}, auth)
|
236
|
+
r.should be_a(OMF::SFA::Resource::OResource)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'find single resource belonging to account' do
|
240
|
+
account = OMF::SFA::Resource::OAccount.new(:name => 'a')
|
241
|
+
auth.stub(:account) { account }
|
242
|
+
|
243
|
+
# resources belong to nil account, so they shouldn't be found
|
244
|
+
lambda do
|
245
|
+
manager.find_resource_for_account({:name => 'r1'}, auth)
|
246
|
+
end.should raise_error(UnknownResourceException)
|
247
|
+
|
248
|
+
# now, assign them to this account
|
249
|
+
@r1.account = account
|
250
|
+
@r1.save
|
251
|
+
auth.should_receive(:can_view_resource?).with(@r1)
|
252
|
+
r = manager.find_resource_for_account({:name => 'r1'}, auth)
|
253
|
+
r.should == @r1
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'will create resource if not already available for the account' do
|
257
|
+
account = OMF::SFA::Resource::OAccount.create(:name => 'a')
|
258
|
+
auth.stub(:account) { account }
|
259
|
+
|
260
|
+
vr = OMF::SFA::Resource::OResource.create(:name => 'v1')
|
261
|
+
vr.should be_a(OMF::SFA::Resource::OResource)
|
262
|
+
scheduler.stub(:create_resource).and_return(vr)
|
263
|
+
scheduler.create_resource().should == vr
|
264
|
+
|
265
|
+
descr = {:name => 'v1'}
|
266
|
+
auth.should_receive(:can_create_resource?) #.with(descr, 'oresource')
|
267
|
+
#auth.should_receive(:can_view_resource?)
|
268
|
+
r = manager.find_or_create_resource_for_account(descr, 'oresource', auth)
|
269
|
+
r.should == vr
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'will create resource from rspec' do
|
273
|
+
rspec = %{
|
274
|
+
<rspec xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:omf="http://schema.mytestbed.net/sfa/rspec/1" type="request">
|
275
|
+
<node component_id="urn:publicid:IDN+openlab+node+node1" component_name="node1">
|
276
|
+
</node>
|
277
|
+
</rspec>
|
278
|
+
}
|
279
|
+
req = Nokogiri.XML(rspec)
|
280
|
+
|
281
|
+
#vr = OMF::SFA::Resource::Node.new(:name => 'vn')
|
282
|
+
# vr.stub(:group?).and_return(false)
|
283
|
+
# vr.stub(:save)
|
284
|
+
# vr.should_receive(:create_from_xml)
|
285
|
+
scheduler.stub(:create_resource) do |resource_descr, type_to_create, authorizer|
|
286
|
+
resource_descr[:name].should == 'node1'
|
287
|
+
authorizer.should == auth
|
288
|
+
OMF::SFA::Resource::Node.new(resource_descr)
|
289
|
+
end
|
290
|
+
auth.should_receive(:can_create_resource?).with({:name => 'node1', :account => account}, anything)
|
291
|
+
#auth.should_receive(:can_view_resource?)
|
292
|
+
r = manager.update_resources_from_rspec(req.root, false, auth)
|
293
|
+
r.first.should be_instance_of(OMF::SFA::Resource::Node)
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'will release a resource' do
|
297
|
+
auth.should_receive(:can_release_resource?).with(@r1)
|
298
|
+
|
299
|
+
scheduler.stub(:release_resource) do |resource, authorizer|
|
300
|
+
resource.destroy
|
301
|
+
end
|
302
|
+
manager.release_resource(@r1, auth)
|
303
|
+
end
|
304
|
+
|
305
|
+
end # context - resource
|
306
|
+
|
307
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/common"
|
3
|
+
require 'omf-sfa/am/am_manager'
|
4
|
+
require 'omf-sfa/am/am_scheduler'
|
5
|
+
require 'omf-sfa/resource'
|
6
|
+
|
7
|
+
include OMF::SFA::AM
|
8
|
+
|
9
|
+
describe AMScheduler do
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
init_dm
|
13
|
+
end
|
14
|
+
|
15
|
+
let (:manager) { double('manager') }
|
16
|
+
|
17
|
+
let (:scheduler) { AMScheduler.new }
|
18
|
+
|
19
|
+
context 'instance' do
|
20
|
+
it 'can create a scheduler' do
|
21
|
+
scheduler
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'resource' do
|
26
|
+
|
27
|
+
# reset database
|
28
|
+
before :each do
|
29
|
+
DataMapper.auto_migrate!
|
30
|
+
end
|
31
|
+
|
32
|
+
let (:lease) { OMF::SFA::Resource::OLease.new(:name => 'l1') }
|
33
|
+
|
34
|
+
let (:account) { OMF::SFA::Resource::OAccount.new(:name => 'a') }
|
35
|
+
|
36
|
+
let (:auth) do
|
37
|
+
auth = double('authorizer')
|
38
|
+
auth.stub(:account) { account }
|
39
|
+
auth
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can create a resource' do
|
43
|
+
r = scheduler.create_resource({ :name => 'node1', :lease => lease, :account => account }, 'node', auth)
|
44
|
+
r.should be_kind_of(OMF::SFA::Resource::Node)
|
45
|
+
r.name.should be_eql('node1')
|
46
|
+
r.account.should be_equal(account)
|
47
|
+
r.leases.first.should be_equal(lease)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'can release a resource' do
|
51
|
+
r = scheduler.create_resource({ :name => 'node1', :lease => lease, :account => account }, 'node', auth)
|
52
|
+
r = scheduler.release_resource(r, auth)
|
53
|
+
r.should be_true
|
54
|
+
OMF::SFA::Resource::Node.all.should be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/am/common.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource'
|
3
|
+
|
4
|
+
def init_dm
|
5
|
+
# setup database
|
6
|
+
DataMapper::Logger.new($stdout, :info)
|
7
|
+
#DataMapper::Logger.new(STDOUT, :debug)
|
8
|
+
|
9
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
10
|
+
#DataMapper.setup(:default, 'sqlite:///tmp/am_test.db')
|
11
|
+
DataMapper::Model.raise_on_save_failure = true
|
12
|
+
DataMapper.finalize
|
13
|
+
|
14
|
+
require 'dm-migrations'
|
15
|
+
DataMapper.auto_migrate!
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_sfa_xml(resource, expected)
|
19
|
+
doc = resource.to_sfa_xml()
|
20
|
+
|
21
|
+
expected = format expected, 'xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:omf="http://schema.mytestbed.net/sfa/rspec/1"'
|
22
|
+
exp = Nokogiri.XML(expected)
|
23
|
+
doc.should be_equivalent_to(exp)
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module OMF
|
4
|
+
module SFA
|
5
|
+
module Resource; end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def init_dm
|
10
|
+
# setup database
|
11
|
+
DataMapper::Logger.new($stdout, :info)
|
12
|
+
#DataMapper::Logger.new(STDOUT, :debug)
|
13
|
+
|
14
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
15
|
+
DataMapper::Model.raise_on_save_failure = true
|
16
|
+
DataMapper.finalize
|
17
|
+
|
18
|
+
require 'dm-migrations'
|
19
|
+
DataMapper.auto_migrate!
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_sfa_xml(resource, expected)
|
23
|
+
# doc = Nokogiri::XML::Document.new
|
24
|
+
# resource.to_sfa_xml(doc)
|
25
|
+
|
26
|
+
doc = resource.to_sfa_xml()
|
27
|
+
|
28
|
+
expected = format expected, 'xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:omf="http://schema.mytestbed.net/sfa/rspec/1"'
|
29
|
+
exp = Nokogiri.XML(expected)
|
30
|
+
doc.should be_equivalent_to(exp)
|
31
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'equivalent-xml'
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/common"
|
4
|
+
require 'omf-sfa/resource/ocomponent'
|
5
|
+
require 'omf-sfa/resource/ogroup'
|
6
|
+
require 'omf-sfa/resource/node'
|
7
|
+
|
8
|
+
|
9
|
+
include OMF::SFA::Resource
|
10
|
+
|
11
|
+
describe Node do
|
12
|
+
before :all do
|
13
|
+
init_dm
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can create a node' do
|
17
|
+
Node.create()
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can serialize a simple node' do
|
21
|
+
n = Node.create(:name => 'n1')
|
22
|
+
assert_sfa_xml n, %{
|
23
|
+
<node %s
|
24
|
+
id="#{n.uuid}"
|
25
|
+
omf:href="/resources/#{n.uuid}"
|
26
|
+
component_id="urn:publicid:IDN+mytestbed.net+node+#{n.uuid}"
|
27
|
+
component_manager_id="authority+am"
|
28
|
+
component_name="n1">
|
29
|
+
<available now="true"/>
|
30
|
+
</node>
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can have an interface' do
|
35
|
+
n = Node.create(:name => 'n1')
|
36
|
+
n.interfaces << (if1 = Interface.create(:name => 'if1'))
|
37
|
+
|
38
|
+
assert_sfa_xml n, %{
|
39
|
+
<node %s
|
40
|
+
id="#{n.uuid}"
|
41
|
+
omf:href="/resources/#{n.uuid}"
|
42
|
+
component_id="urn:publicid:IDN+mytestbed.net+node+#{n.uuid}"
|
43
|
+
component_manager_id="authority+am"
|
44
|
+
component_name="n1">
|
45
|
+
<available now="true"/>
|
46
|
+
<interface
|
47
|
+
id="#{if1.uuid}"
|
48
|
+
omf:href="/resources/#{if1.uuid}"
|
49
|
+
component_id="urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}"
|
50
|
+
component_manager_id="authority+am"
|
51
|
+
component_name="if1"
|
52
|
+
/>
|
53
|
+
</node>
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can have multiples interface' do
|
58
|
+
n = Node.create(:name => 'n1')
|
59
|
+
n.interfaces << (if1 = Interface.create(:name => 'if1'))
|
60
|
+
n.interfaces << (if2 = Interface.create(:name => 'if2'))
|
61
|
+
|
62
|
+
n.to_sfa_hash().should == {
|
63
|
+
"href" => "/resources/#{n.uuid}", "uuid" => n.uuid.to_s, "sfa_class" => "node",
|
64
|
+
"component_name" => "n1", "component_manager_id" => "authority+am",
|
65
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+node+#{n.uuid}",
|
66
|
+
"available" => "true",
|
67
|
+
"interfaces" => [{
|
68
|
+
"href" => "/resources/#{if1.uuid}",
|
69
|
+
"uuid" => if1.uuid.to_s,
|
70
|
+
"sfa_class" => "interface",
|
71
|
+
"component_name" => "if1",
|
72
|
+
"component_manager_id" => "authority+am",
|
73
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}",
|
74
|
+
}, {
|
75
|
+
"href" => "/resources/#{if2.uuid}",
|
76
|
+
"uuid" => if2.uuid.to_s,
|
77
|
+
"sfa_class" => "interface",
|
78
|
+
"component_name" => "if2",
|
79
|
+
"component_manager_id" => "authority+am",
|
80
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+interface+#{if2.uuid}",
|
81
|
+
}]
|
82
|
+
}
|
83
|
+
|
84
|
+
assert_sfa_xml n, %{
|
85
|
+
<node %s
|
86
|
+
id="#{n.uuid}"
|
87
|
+
omf:href="/resources/#{n.uuid}"
|
88
|
+
component_id="urn:publicid:IDN+mytestbed.net+node+#{n.uuid}"
|
89
|
+
component_manager_id="authority+am"
|
90
|
+
component_name="n1">
|
91
|
+
<available now="true"/>
|
92
|
+
<interface
|
93
|
+
id="#{if1.uuid}"
|
94
|
+
omf:href="/resources/#{if1.uuid}"
|
95
|
+
component_id="urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}"
|
96
|
+
component_manager_id="authority+am"
|
97
|
+
component_name="if1"
|
98
|
+
/>
|
99
|
+
<interface
|
100
|
+
id="#{if2.uuid}"
|
101
|
+
omf:href="/resources/#{if2.uuid}"
|
102
|
+
component_id="urn:publicid:IDN+mytestbed.net+interface+#{if2.uuid}"
|
103
|
+
component_manager_id="authority+am"
|
104
|
+
component_name="if2"
|
105
|
+
/>
|
106
|
+
</node>
|
107
|
+
}
|
108
|
+
# doc = Nokogiri::XML::Document.new
|
109
|
+
# n.to_sfa_xml(doc)
|
110
|
+
#
|
111
|
+
# exp = Nokogiri.XML(%{
|
112
|
+
# <node
|
113
|
+
# id="#{n.sfa_id}"
|
114
|
+
# component_id="urn:publicid:IDN+mytestbed.net+node+n1"
|
115
|
+
# component_manager_id="authority+am"
|
116
|
+
# component_name="n1">
|
117
|
+
# <available now="true"/>
|
118
|
+
# <interface_ref component_id="urn:publicid:IDN+mytestbed.net+interface+if1"/>
|
119
|
+
# <interface_ref component_id="urn:publicid:IDN+mytestbed.net+interface+if2"/>
|
120
|
+
# </node>})
|
121
|
+
# doc.should be_equivalent_to(exp)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'can have multiples identical interface' do
|
125
|
+
n = Node.create(:name => 'n1')
|
126
|
+
n.interfaces << (if1 = Interface.create(:name => 'if1'))
|
127
|
+
n.interfaces << if1
|
128
|
+
|
129
|
+
n.to_sfa_hash().should == {
|
130
|
+
"href" => "/resources/#{n.uuid}", "uuid" => n.uuid.to_s, "sfa_class" => "node",
|
131
|
+
"component_name" => "n1", "component_manager_id" => "authority+am",
|
132
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+node+#{n.uuid}",
|
133
|
+
"available" => "true",
|
134
|
+
"interfaces" => [{
|
135
|
+
"href" => "/resources/#{if1.uuid}",
|
136
|
+
"uuid" => if1.uuid.to_s,
|
137
|
+
"sfa_class" => "interface",
|
138
|
+
"component_name" => "if1",
|
139
|
+
"component_manager_id" => "authority+am",
|
140
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}",
|
141
|
+
}, {
|
142
|
+
"component_name" => "if1",
|
143
|
+
"href" => "/resources/#{if1.uuid}",
|
144
|
+
"uuid" => if1.uuid.to_s
|
145
|
+
}]
|
146
|
+
}
|
147
|
+
|
148
|
+
assert_sfa_xml n, %{
|
149
|
+
<node %s
|
150
|
+
id="#{n.uuid}"
|
151
|
+
omf:href="/resources/#{n.uuid}"
|
152
|
+
component_id="urn:publicid:IDN+mytestbed.net+node+#{n.uuid}"
|
153
|
+
component_manager_id="authority+am"
|
154
|
+
component_name="n1">
|
155
|
+
<available now="true"/>
|
156
|
+
<interface
|
157
|
+
id="#{if1.uuid}"
|
158
|
+
omf:href="/resources/#{if1.uuid}"
|
159
|
+
component_id="urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}"
|
160
|
+
component_manager_id="authority+am"
|
161
|
+
component_name="if1"
|
162
|
+
/>
|
163
|
+
<interface_ref
|
164
|
+
id_ref="#{if1.uuid}"
|
165
|
+
component_id="urn:publicid:IDN+mytestbed.net+interface+#{if1.uuid}"
|
166
|
+
/>
|
167
|
+
</node>
|
168
|
+
}
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/common"
|
2
|
+
require 'omf-sfa/resource/oaccount'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
include OMF::SFA::Resource
|
6
|
+
|
7
|
+
class R < OResource
|
8
|
+
end
|
9
|
+
|
10
|
+
describe OAccount do
|
11
|
+
before :all do
|
12
|
+
init_dm
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can create an account' do
|
16
|
+
a = OAccount.create()
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can create an account with a urn' do
|
20
|
+
#a = OAccount.create(:urn => "urn:foo")
|
21
|
+
a = OAccount.first_or_create(:urn => "urn:publicid:IDN+omf:test+account+1")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can create an account with a urn if it doesnt exist yet' do
|
25
|
+
a = OAccount.first_or_create(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+5d9d-4fb:127.0.0.1%3A8000")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'will return nil if no account found' do
|
29
|
+
a = OAccount.first(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+test")
|
30
|
+
a.should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can create and find by urn' do
|
34
|
+
|
35
|
+
init_dm
|
36
|
+
|
37
|
+
a = OAccount.create(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+5d9d-4fb:127.0.0.1%3A8000")
|
38
|
+
b = OAccount.create(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+__test__")
|
39
|
+
|
40
|
+
aa = OAccount.first(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+5d9d-4fb:127.0.0.1%3A8000")
|
41
|
+
bb = OAccount.first(:urn => "urn:publicid:IDN+geni:gpo:gcf+slice+__test__")
|
42
|
+
|
43
|
+
a.should == aa
|
44
|
+
b.should == bb
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can create and find by a name' do
|
48
|
+
a = OAccount.create(:name => 'fooBar')
|
49
|
+
b = OAccount.first(:name => 'fooBar')
|
50
|
+
a.should == b
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'resources have a NULL default account' do
|
54
|
+
r = R.create()
|
55
|
+
r.account.should == nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'resources can have an account' do
|
59
|
+
a = OAccount.create()
|
60
|
+
r = R.create(:account => a)
|
61
|
+
r.reload.account.should == a
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'resources can have an account which then can be nulled' do
|
65
|
+
a = OAccount.create()
|
66
|
+
r = R.create(:account => a)
|
67
|
+
r.account = nil
|
68
|
+
r.save
|
69
|
+
r.reload.account.should == nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'is is active when valid' do
|
73
|
+
a = OAccount.create()
|
74
|
+
#a.save
|
75
|
+
a.reload
|
76
|
+
a.active?.should == true
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'is is no longer active after valid_until' do
|
80
|
+
a = OAccount.create(:valid_until => Time.now - 1)
|
81
|
+
a.active?.should == false
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'has Time oproperties' do
|
85
|
+
a = OAccount.create(:valid_until => Time.now + 200)
|
86
|
+
a.valid_until.should be_a_kind_of(Time)
|
87
|
+
|
88
|
+
a.valid_until = Time.now + 100
|
89
|
+
a.valid_until.should be_a_kind_of(Time)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|