omf_rc 6.0.0.pre.6 → 6.0.0.pre.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/omf_rc +34 -26
- data/config/omf_rc.yml +10 -10
- data/lib/omf_rc/{message_process_error.rb → omf_error.rb} +8 -0
- data/lib/omf_rc/resource_factory.rb +4 -0
- data/lib/omf_rc/resource_proxy/abstract_resource.rb +107 -44
- data/lib/omf_rc/resource_proxy/{generic_application.rb → application.rb} +189 -142
- data/lib/omf_rc/resource_proxy/node.rb +33 -21
- data/lib/omf_rc/resource_proxy_dsl.rb +51 -9
- data/lib/omf_rc/util/iw.rb +10 -6
- data/lib/omf_rc/util/mod.rb +30 -2
- data/lib/omf_rc/util/openflow_tools.rb +8 -8
- data/lib/omf_rc/util/platform_tools.rb +13 -13
- data/lib/omf_rc/version.rb +1 -1
- data/test/fixture/iw/help +6 -6
- data/test/fixture/lsmod +56 -56
- data/test/fixture/oml.hash +30 -0
- data/test/fixture/oml.spec +15 -0
- data/test/fixture/oml.xml +17 -0
- data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +4 -2
- data/test/omf_rc/resource_proxy/{generic_application_spec.rb → application_spec.rb} +73 -34
- data/test/omf_rc/resource_proxy/node_spec.rb +33 -17
- data/test/omf_rc/resource_proxy_dsl_spec.rb +7 -0
- data/test/omf_rc/util/common_tools_spec.rb +1 -1
- data/test/omf_rc/util/mod_spec.rb +9 -3
- metadata +8 -6
@@ -1,35 +1,33 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'omf_rc/resource_proxy/
|
2
|
+
require 'omf_rc/resource_proxy/application'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe OmfRc::ResourceProxy::GenericApplication do
|
4
|
+
describe OmfRc::ResourceProxy::Application do
|
7
5
|
|
8
6
|
before do
|
9
|
-
@app_test = OmfRc::ResourceFactory.new(:
|
7
|
+
@app_test = OmfRc::ResourceFactory.new(:application, { hrn: 'an_application' })
|
10
8
|
@app_test.comm = MiniTest::Mock.new
|
11
9
|
@app_test.comm.expect :publish, nil, [String,OmfCommon::Message]
|
12
10
|
end
|
13
11
|
|
14
12
|
describe "when initialised" do
|
15
13
|
it "must respond to an 'on_app_event' call back" do
|
16
|
-
#OmfRc::ResourceProxy::
|
14
|
+
#OmfRc::ResourceProxy::Application.method_defined?(:on_app_event).must_equal true
|
17
15
|
@app_test.must_respond_to :on_app_event
|
18
16
|
end
|
19
17
|
|
20
18
|
it "must have its properties set to sensible initial values" do
|
21
19
|
@app_test.request_state.to_sym.must_equal :stop
|
22
20
|
@app_test.request_tarball_install_path.must_equal '/'
|
23
|
-
@app_test.request_force_tarball_install.must_equal
|
24
|
-
@app_test.request_installed.must_equal
|
25
|
-
@app_test.request_map_err_to_out.must_equal
|
21
|
+
@app_test.request_force_tarball_install.must_equal false
|
22
|
+
@app_test.request_installed.must_equal false
|
23
|
+
@app_test.request_map_err_to_out.must_equal false
|
26
24
|
end
|
27
25
|
|
28
26
|
it "must be able to configure/request its basic properties" do
|
29
27
|
basic_prop = %w(binary_path pkg_tarball pkg_ubuntu pkg_fedora force_tarball_install map_err_to_out tarball_install_path)
|
30
28
|
basic_prop.each do |p|
|
31
|
-
@app_test.
|
32
|
-
@app_test.
|
29
|
+
@app_test.send("configure_#{p}".to_sym, 'foo')
|
30
|
+
@app_test.send("request_#{p}".to_sym).must_equal 'foo'
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
@@ -47,6 +45,16 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
47
45
|
@app_test.property.environments['foo'].must_equal 123
|
48
46
|
@app_test.property.environments['bar_bar'].must_equal 'bar_123'
|
49
47
|
end
|
48
|
+
|
49
|
+
it "must be able to configure its available OML measurement points" do
|
50
|
+
test_oml_spec = eval(fixture('oml.spec'))
|
51
|
+
@app_test.method(:configure_oml).call(test_oml_spec)
|
52
|
+
@app_test.property.oml.must_be_kind_of Hash
|
53
|
+
@app_test.property.oml.has_key?(:available_mps).must_equal true
|
54
|
+
@app_test.property.oml[:available_mps].length.must_be :> , 0
|
55
|
+
@app_test.property.oml[:available_mps][0].must_be_kind_of Hash
|
56
|
+
@app_test.property.oml[:available_mps][0].has_key?(:mp).must_equal true
|
57
|
+
end
|
50
58
|
end
|
51
59
|
|
52
60
|
describe "when configuring its parameters property" do
|
@@ -78,28 +86,12 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
78
86
|
@app_test.property.parameters[:p2][:default].must_equal 'bar_bar'
|
79
87
|
end
|
80
88
|
|
81
|
-
it "must be able to sanitize its parameters property" do
|
82
|
-
test_params = { :p1 => { :mandatory => 'true', :dynamic => false},
|
83
|
-
:p2 => { :mandatory => true, :dynamic => 'false'},
|
84
|
-
:p3 => { :type => 'Boolean', :default => true, :value => 'false'},
|
85
|
-
:p4 => { :type => 'Boolean', :default => 'true', :value => false} }
|
86
|
-
@app_test.method(:configure_parameters).call(test_params)
|
87
|
-
@app_test.property.parameters[:p1][:mandatory].must_be_kind_of TrueClass
|
88
|
-
@app_test.property.parameters[:p1][:dynamic].must_be_kind_of FalseClass
|
89
|
-
@app_test.property.parameters[:p2][:mandatory].must_be_kind_of TrueClass
|
90
|
-
@app_test.property.parameters[:p2][:dynamic].must_be_kind_of FalseClass
|
91
|
-
@app_test.property.parameters[:p3][:default].must_be_kind_of TrueClass
|
92
|
-
@app_test.property.parameters[:p3][:value].must_be_kind_of FalseClass
|
93
|
-
@app_test.property.parameters[:p4][:default].must_be_kind_of TrueClass
|
94
|
-
@app_test.property.parameters[:p4][:value].must_be_kind_of FalseClass
|
95
|
-
end
|
96
|
-
|
97
89
|
it "must be able to validate the correct type of a defined parameter" do
|
98
90
|
test_params = { :p1 => { :type => 'String', :default => 'foo', :value => 'bar'},
|
99
91
|
:p2 => { :type => 'Numeric', :default => 123, :value => 456},
|
100
|
-
:p3 => { :type => 'Boolean', :default => true, :value =>
|
92
|
+
:p3 => { :type => 'Boolean', :default => true, :value => false},
|
101
93
|
:p4 => { :type => 'Boolean'},
|
102
|
-
:p5 => { :type => 'Boolean', :default =>
|
94
|
+
:p5 => { :type => 'Boolean', :default => false},
|
103
95
|
:p6 => { :type => 'Boolean', :value => true},
|
104
96
|
:p7 => { :type => 'Numeric'},
|
105
97
|
:p8 => { :type => 'Numeric', :default => 123},
|
@@ -110,10 +102,10 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
110
102
|
@app_test.property.parameters[:p2][:default].must_be_kind_of Numeric
|
111
103
|
@app_test.property.parameters[:p2][:value].must_be_kind_of Numeric
|
112
104
|
@app_test.property.parameters[:p3][:default].must_be_kind_of TrueClass
|
113
|
-
@app_test.property.parameters[:p3][:value].must_be_kind_of
|
105
|
+
@app_test.property.parameters[:p3][:value].must_be_kind_of FalseClass
|
114
106
|
@app_test.property.parameters[:p4][:default].must_be_nil
|
115
107
|
@app_test.property.parameters[:p4][:value].must_be_nil
|
116
|
-
@app_test.property.parameters[:p5][:default].must_be_kind_of
|
108
|
+
@app_test.property.parameters[:p5][:default].must_be_kind_of FalseClass
|
117
109
|
@app_test.property.parameters[:p6][:value].must_be_kind_of TrueClass
|
118
110
|
@app_test.property.parameters[:p7][:default].must_be_nil
|
119
111
|
@app_test.property.parameters[:p7][:value].must_be_nil
|
@@ -141,10 +133,11 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
141
133
|
|
142
134
|
it "must update any valid dynamic parameter with the given value" do
|
143
135
|
# set the parameter as dynamic
|
144
|
-
params1 = { :p1 => { :cmd => '--foo', :default => 'old_foo', :dynamic => true}
|
136
|
+
params1 = { :p1 => { :cmd => '--foo', :default => 'old_foo', :dynamic => true},
|
137
|
+
:p2 => { :cmd => '--notcalled', :dynamic => false} }
|
145
138
|
@app_test.method(:configure_parameters).call(params1)
|
146
139
|
# then update it
|
147
|
-
params2 = { :p1 => { :value => 'bar'} }
|
140
|
+
params2 = { :p1 => { :value => 'bar'} , :p2 => { :value => 'abc'} }
|
148
141
|
@app_test.property.state = :run
|
149
142
|
class ExecApp
|
150
143
|
def initialize(app_id, res, cmd_line, err_out_map); end
|
@@ -176,7 +169,7 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
176
169
|
it "must set installed property to true if the event is 'DONE.OK' and the app_id's suffix is '_INSTALL'" do
|
177
170
|
@app_test.on_app_event('DONE.OK', 'app_instance_id_INSTALL', 'Some text here')
|
178
171
|
@app_test.request_state.to_sym.must_equal :stop
|
179
|
-
@app_test.request_installed.must_equal
|
172
|
+
@app_test.request_installed.must_equal true
|
180
173
|
end
|
181
174
|
end
|
182
175
|
|
@@ -297,6 +290,52 @@ describe OmfRc::ResourceProxy::GenericApplication do
|
|
297
290
|
@app_test.method(:configure_state).call(:run)
|
298
291
|
@app_test.property.state.must_equal :run
|
299
292
|
end
|
293
|
+
|
294
|
+
it "must start an app with OML command line options when use_oml parameter is set" do
|
295
|
+
class ExecApp
|
296
|
+
def initialize(app_id, res, cmd_line, err_out_map)
|
297
|
+
cmd_line.must_equal "env -i my_cmd --oml-config /tmp/bar.xml --oml-log-level 1 --oml-log-file foo "
|
298
|
+
end
|
299
|
+
end
|
300
|
+
@app_test.property.state = :stop
|
301
|
+
@app_test.property.binary_path = "my_cmd"
|
302
|
+
@app_test.property.use_oml = true
|
303
|
+
@app_test.property.oml_loglevel = 1
|
304
|
+
@app_test.property.oml_logfile = "foo"
|
305
|
+
@app_test.property.oml_configfile = "/tmp/bar.xml"
|
306
|
+
File.stub(:exist?, true) { @app_test.method(:configure_state).call(:run) }
|
307
|
+
@app_test.property.state.must_equal :run
|
308
|
+
end
|
309
|
+
|
310
|
+
it "must start an app using its own built OML config when use_oml and oml parameters are set" do
|
311
|
+
class ExecApp
|
312
|
+
def initialize(app_id, res, cmd_line, err_out_map)
|
313
|
+
xml_file = cmd_line.split('env -i my_cmd --oml-config ')[1]
|
314
|
+
File.open(xml_file, 'r').read.must_equal fixture('oml.xml')
|
315
|
+
File.delete(xml_file)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
@app_test.property.state = :stop
|
319
|
+
@app_test.property.binary_path = "my_cmd"
|
320
|
+
@app_test.property.use_oml = true
|
321
|
+
@app_test.property.oml = eval(fixture('oml.hash'))
|
322
|
+
@app_test.method(:configure_state).call(:run)
|
323
|
+
@app_test.property.state.must_equal :run
|
324
|
+
end
|
325
|
+
|
326
|
+
it "must not use any oml options if use_oml is set but both oml or oml_config are not set" do
|
327
|
+
class ExecApp
|
328
|
+
def initialize(app_id, res, cmd_line, err_out_map)
|
329
|
+
cmd_line.must_equal "env -i my_cmd "
|
330
|
+
end
|
331
|
+
end
|
332
|
+
@app_test.property.state = :stop
|
333
|
+
@app_test.property.binary_path = "my_cmd"
|
334
|
+
@app_test.property.use_oml = true
|
335
|
+
@app_test.method(:configure_state).call(:run)
|
336
|
+
@app_test.property.state.must_equal :run
|
337
|
+
end
|
338
|
+
|
300
339
|
end
|
301
340
|
|
302
341
|
describe "when configuring its state property to :pause" do
|
@@ -17,25 +17,41 @@ describe OmfRc::ResourceProxy::Node do
|
|
17
17
|
{ name: 'phy0', driver: 'iwlwifi', category: 'net', subcategory: 'wlan', proxy: 'wlan' }
|
18
18
|
]
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
["#{sys_dir}/net/eth0"]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
Dir.stub :glob, glob_proc do
|
35
|
-
@node.request_devices.must_be_kind_of Array
|
36
|
-
@node.request_devices.must_equal devices
|
20
|
+
glob_proc = proc do |pattern|
|
21
|
+
sys_dir = "#{File.dirname(__FILE__)}/../../fixture/sys/class"
|
22
|
+
case pattern
|
23
|
+
when "/sys/class/net"
|
24
|
+
["#{sys_dir}/net"]
|
25
|
+
when "/sys/class/ieee80211"
|
26
|
+
["#{sys_dir}/ieee80211"]
|
27
|
+
when "/sys/class/ieee80211/*"
|
28
|
+
["#{sys_dir}/ieee80211/phy0"]
|
29
|
+
when "/sys/class/net/eth*"
|
30
|
+
["#{sys_dir}/net/eth0"]
|
37
31
|
end
|
38
32
|
end
|
33
|
+
Dir.stub :glob, glob_proc do
|
34
|
+
@node.request_devices.must_be_kind_of Array
|
35
|
+
@node.request_devices.must_equal devices
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "must provide a list of created applications" do
|
40
|
+
@node.create(:application, { :uid => 'app_test', :hrn => 'app_test' })
|
41
|
+
|
42
|
+
@node.request_applications.must_equal [
|
43
|
+
{ name: 'app_test', type: 'application', uid: 'app_test' }
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "must provide a list of created interfaces" do
|
48
|
+
@node.create(:wlan, { :uid => 'wlan0', :hrn => 'wlan0' })
|
49
|
+
@node.create(:net, { :uid => 'eth0', :hrn => 'eth0' })
|
50
|
+
|
51
|
+
@node.request_interfaces.must_equal [
|
52
|
+
{ name: 'eth0', type: 'net', uid: 'eth0' },
|
53
|
+
{ name: 'wlan0', type: 'wlan', uid: 'wlan0' }
|
54
|
+
]
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
@@ -6,6 +6,8 @@ describe OmfRc::ResourceProxyDSL do
|
|
6
6
|
module OmfRc::Util::MockUtility
|
7
7
|
include OmfRc::ResourceProxyDSL
|
8
8
|
|
9
|
+
property :mock_prop, :default => 1
|
10
|
+
|
9
11
|
configure :alpha
|
10
12
|
|
11
13
|
request :alpha do |resource|
|
@@ -106,5 +108,10 @@ describe OmfRc::ResourceProxyDSL do
|
|
106
108
|
OmfRc::ResourceFactory.new(:mock_root_proxy).create(:useless_proxy)
|
107
109
|
lambda { OmfRc::ResourceFactory.new(:useless_proxy).create(:mock_proxy) }.must_raise StandardError
|
108
110
|
end
|
111
|
+
|
112
|
+
it "must be able to define property with default vlaue" do
|
113
|
+
mock_proxy = OmfRc::ResourceFactory.new(:mock_proxy)
|
114
|
+
mock_proxy.property.mock_prop.must_equal 1
|
115
|
+
end
|
109
116
|
end
|
110
117
|
end
|
@@ -9,18 +9,24 @@ describe OmfRc::Util::Mod do
|
|
9
9
|
register_proxy :mod_test
|
10
10
|
utility :mod
|
11
11
|
end
|
12
|
+
@command = MiniTest::Mock.new
|
12
13
|
end
|
13
14
|
|
14
15
|
it "will find out a list of modules" do
|
15
|
-
|
16
|
+
Cocaine::CommandLine.stub(:new, @command) do
|
17
|
+
@command.expect(:run, fixture("lsmod"))
|
16
18
|
OmfRc::ResourceFactory.new(:mod_test).request_modules.must_include "kvm"
|
19
|
+
@command.expect(:run, fixture("lsmod"))
|
17
20
|
OmfRc::ResourceFactory.new(:mod_test).request_modules.wont_include "Module"
|
21
|
+
@command.verify
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
it "could load a module" do
|
22
|
-
|
23
|
-
|
26
|
+
Cocaine::CommandLine.stub(:new, @command) do
|
27
|
+
@command.expect(:run, true)
|
28
|
+
OmfRc::ResourceFactory.new(:mod_test).configure_load_module(name: 'magic_module').must_equal "magic_module loaded"
|
29
|
+
@command.verify
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_rc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.pre.
|
4
|
+
version: 6.0.0.pre.7
|
5
5
|
prerelease: 6
|
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: 2012-10-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -107,10 +107,10 @@ files:
|
|
107
107
|
- config/omf_rc.yml
|
108
108
|
- lib/omf_rc.rb
|
109
109
|
- lib/omf_rc/deferred_process.rb
|
110
|
-
- lib/omf_rc/
|
110
|
+
- lib/omf_rc/omf_error.rb
|
111
111
|
- lib/omf_rc/resource_factory.rb
|
112
112
|
- lib/omf_rc/resource_proxy/abstract_resource.rb
|
113
|
-
- lib/omf_rc/resource_proxy/
|
113
|
+
- lib/omf_rc/resource_proxy/application.rb
|
114
114
|
- lib/omf_rc/resource_proxy/mock.rb
|
115
115
|
- lib/omf_rc/resource_proxy/net.rb
|
116
116
|
- lib/omf_rc/resource_proxy/node.rb
|
@@ -135,6 +135,9 @@ files:
|
|
135
135
|
- test/fixture/iw/info
|
136
136
|
- test/fixture/iw/link
|
137
137
|
- test/fixture/lsmod
|
138
|
+
- test/fixture/oml.hash
|
139
|
+
- test/fixture/oml.spec
|
140
|
+
- test/fixture/oml.xml
|
138
141
|
- test/fixture/sys/class/ieee80211/phy0/device/uevent
|
139
142
|
- test/fixture/sys/class/ieee80211/phy0/uevent
|
140
143
|
- test/fixture/sys/class/net/eth0/device/uevent
|
@@ -145,7 +148,7 @@ files:
|
|
145
148
|
- test/omf_rc/message_process_error_spec.rb
|
146
149
|
- test/omf_rc/resource_factory_spec.rb
|
147
150
|
- test/omf_rc/resource_proxy/abstract_resource_spec.rb
|
148
|
-
- test/omf_rc/resource_proxy/
|
151
|
+
- test/omf_rc/resource_proxy/application_spec.rb
|
149
152
|
- test/omf_rc/resource_proxy/mock_spec.rb
|
150
153
|
- test/omf_rc/resource_proxy/node_spec.rb
|
151
154
|
- test/omf_rc/resource_proxy_dsl_spec.rb
|
@@ -180,4 +183,3 @@ signing_key:
|
|
180
183
|
specification_version: 3
|
181
184
|
summary: OMF resource controller
|
182
185
|
test_files: []
|
183
|
-
has_rdoc:
|