omf_rc 6.0.0.pre.8 → 6.0.0.pre.9
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/install_omf_rc +79 -0
- data/bin/omf_rc +52 -36
- data/config/config.yml +8 -0
- data/init/debian +51 -0
- data/init/fedora +54 -0
- data/init/run_omf_rc.sh +62 -0
- data/init/ubuntu +12 -0
- data/lib/omf_rc/omf_error.rb +5 -5
- data/lib/omf_rc/resource_factory.rb +7 -11
- data/lib/omf_rc/resource_proxy/abstract_resource.rb +327 -228
- data/lib/omf_rc/resource_proxy/application.rb +61 -56
- data/lib/omf_rc/resource_proxy/net.rb +2 -2
- data/lib/omf_rc/resource_proxy/node.rb +11 -2
- data/lib/omf_rc/resource_proxy/virtual_machine.rb +1 -1
- data/lib/omf_rc/resource_proxy/wlan.rb +2 -0
- data/lib/omf_rc/resource_proxy_dsl.rb +22 -1
- data/lib/omf_rc/util/common_tools.rb +2 -4
- data/lib/omf_rc/util/hostapd.rb +4 -3
- data/lib/omf_rc/util/ip.rb +8 -5
- data/lib/omf_rc/util/iw.rb +18 -8
- data/lib/omf_rc/util/sysfs.rb +14 -0
- data/lib/omf_rc/util/vmbuilder.rb +1 -1
- data/lib/omf_rc/util/wpa.rb +4 -3
- data/lib/omf_rc/version.rb +1 -1
- data/lib/omf_rc.rb +3 -1
- data/omf_rc.gemspec +4 -2
- data/test/omf_rc/message_process_error_spec.rb +3 -3
- data/test/omf_rc/resource_factory_spec.rb +14 -7
- data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +47 -21
- data/test/omf_rc/resource_proxy/application_spec.rb +156 -119
- data/test/omf_rc/resource_proxy/mock_spec.rb +6 -1
- data/test/omf_rc/resource_proxy/node_spec.rb +32 -12
- data/test/omf_rc/resource_proxy_dsl_spec.rb +31 -19
- data/test/omf_rc/util/common_tools_spec.rb +8 -11
- data/test/omf_rc/util/ip_spec.rb +7 -1
- data/test/omf_rc/util/iw_spec.rb +18 -13
- data/test/omf_rc/util/mock_spec.rb +6 -1
- data/test/omf_rc/util/mod_spec.rb +17 -10
- data/test/test_helper.rb +3 -0
- metadata +51 -48
- data/config/omf_rc.yml +0 -70
- data/lib/omf_rc/resource_proxy/openflow_slice.rb +0 -79
- data/lib/omf_rc/resource_proxy/openflow_slice_factory.rb +0 -71
@@ -32,10 +32,10 @@
|
|
32
32
|
# - pkg_ubuntu (String) the name of the Ubuntu package for this app
|
33
33
|
# - pkg_fedora (String) the name of the Fedora package for this app
|
34
34
|
# - state (String) the state of this Application RP
|
35
|
-
# (
|
35
|
+
# (stopped, running, paused, installed, completed)
|
36
36
|
# - installed (Boolean) is this application installed? (default false)
|
37
37
|
# - force_tarball_install (Boolean) if true then force the installation
|
38
|
-
# from tarball even if other distribution-specific installation are
|
38
|
+
# from tarball even if other distribution-specific installation are
|
39
39
|
# available (default false)
|
40
40
|
# - map_err_to_out (Boolean) if true then map StdErr to StdOut for this
|
41
41
|
# app (default false)
|
@@ -107,7 +107,7 @@ module OmfRc::ResourceProxy::Application
|
|
107
107
|
property :force_tarball_install, :default => false
|
108
108
|
property :pkg_ubuntu, :default => nil
|
109
109
|
property :pkg_fedora, :default => nil
|
110
|
-
property :state, :default => :
|
110
|
+
property :state, :default => :stopped
|
111
111
|
property :installed, :default => false
|
112
112
|
property :map_err_to_out, :default => false
|
113
113
|
property :event_sequence, :default => 0
|
@@ -137,18 +137,19 @@ module OmfRc::ResourceProxy::Application
|
|
137
137
|
logger.info "App Event from '#{app_id}' "+
|
138
138
|
"(##{res.property.event_sequence}) - "+
|
139
139
|
"#{event_type}: '#{msg}'"
|
140
|
-
|
140
|
+
if event_type.to_s.include?('DONE')
|
141
|
+
res.property.state = app_id.include?("_INSTALL") ? :stopped : :completed
|
142
|
+
end
|
141
143
|
|
142
144
|
(res.membership + [res.uid]).each do |m|
|
143
145
|
res.inform(:status, {
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
})
|
146
|
+
status_type: 'APP_EVENT',
|
147
|
+
event: event_type.to_s.upcase,
|
148
|
+
app: app_id,
|
149
|
+
msg: msg,
|
150
|
+
seq: res.property.event_sequence,
|
151
|
+
uid: res.uid
|
152
|
+
}, m == res.uid ? nil : res.membership_topics[m])
|
152
153
|
end
|
153
154
|
|
154
155
|
res.property.event_sequence += 1
|
@@ -215,52 +216,56 @@ module OmfRc::ResourceProxy::Application
|
|
215
216
|
end
|
216
217
|
|
217
218
|
# Configure the state of this Application RP. The valid states are
|
218
|
-
#
|
219
|
+
# stopped, running, paused, installing. The semantic of each states are:
|
219
220
|
#
|
220
|
-
# -
|
221
|
-
#
|
222
|
-
# its execution
|
223
|
-
#
|
221
|
+
# - stopped: the initial state for an Application RP
|
222
|
+
# - completed: the final state for an applicaiton RP. When the application
|
223
|
+
# has been executed and its execution is finished, it enters this state.
|
224
|
+
# When the application is completed it cannot change state again
|
225
|
+
# TODO: maybe in future OMF, we could consider allowing an app to be reset?
|
226
|
+
# - running: upon entering in this state, a new instance of the application is
|
224
227
|
# started, the Application RP stays in this state until the
|
225
228
|
# application instance is finished or paused. The Application RP can
|
226
|
-
# only enter this state from a previous
|
227
|
-
# -
|
229
|
+
# only enter this state from a previous paused or stopped state.
|
230
|
+
# - paused: upon entering this state, the currently running instance of this
|
228
231
|
# application should be paused (it is the responsibility of
|
229
|
-
# specialised Application Proxy to ensure that!
|
232
|
+
# specialised Application Proxy to ensure that! This default
|
230
233
|
# Application Proxy does nothing to the application instance when
|
231
234
|
# entering this state). The Application RP can only enter this
|
232
|
-
# state from a previous
|
233
|
-
# -
|
235
|
+
# state from a previous running state.
|
236
|
+
# - installing: upon entering in this state, a new installation of the
|
234
237
|
# application will be performed by the Application RP, which will
|
235
|
-
# stay in this state until the installation is
|
236
|
-
# Application RP can only enter this state from a previous
|
237
|
-
# state
|
238
|
-
# is
|
239
|
-
#
|
238
|
+
# stay in this state until the installation is done. The
|
239
|
+
# Application RP can only enter this state from a previous stopped
|
240
|
+
# state. Furthermore it can only exit this state to enter the stopped state
|
241
|
+
# only when the installatio is done. Supported install methods are: Tarball,
|
242
|
+
# Ubuntu, and Fedora
|
240
243
|
#
|
241
244
|
# @yieldparam [String] value the state to set this app into
|
242
245
|
#
|
243
246
|
configure :state do |res, value|
|
244
247
|
case value.to_s.downcase.to_sym
|
245
|
-
when :
|
246
|
-
when :
|
247
|
-
when :
|
248
|
-
when :
|
248
|
+
when :installing then res.switch_to_installing
|
249
|
+
when :stopped then res.switch_to_stopped
|
250
|
+
when :running then res.switch_to_running
|
251
|
+
when :paused then res.switch_to_paused
|
252
|
+
else
|
253
|
+
res.log_inform_warn "Cannot switch application to unknown state '#{value.to_s}'!"
|
249
254
|
end
|
250
255
|
res.property.state
|
251
256
|
end
|
252
257
|
|
253
|
-
# Swich this Application RP into the '
|
258
|
+
# Swich this Application RP into the 'installing' state
|
254
259
|
# (see the description of configure :state)
|
255
260
|
#
|
256
|
-
work('
|
257
|
-
if res.property.state.to_sym == :
|
261
|
+
work('switch_to_installing') do |res|
|
262
|
+
if res.property.state.to_sym == :stopped
|
258
263
|
if res.property.installed
|
259
264
|
res.log_inform_warn "The application is already installed"
|
260
265
|
else
|
261
266
|
# Select the proper installation method based on the platform
|
262
267
|
# and the value of 'force_tarball_install'
|
263
|
-
res.property.state = :
|
268
|
+
res.property.state = :installing
|
264
269
|
if res.property.force_tarball_install ||
|
265
270
|
(res.property.platform == :unknown)
|
266
271
|
installing = res.install_tarball(res.property.pkg_tarball,
|
@@ -270,19 +275,19 @@ module OmfRc::ResourceProxy::Application
|
|
270
275
|
elsif res.property.platform == :fedora
|
271
276
|
installing = res.install_fedora(res.property.pkg_fedora)
|
272
277
|
end
|
273
|
-
res.property.state = :
|
278
|
+
res.property.state = :stopped unless installing
|
274
279
|
end
|
275
280
|
else
|
276
281
|
# cannot install as we are not stopped
|
277
|
-
res.log_inform_warn "Not in
|
282
|
+
res.log_inform_warn "Not in stopped state. Cannot switch to installing state!"
|
278
283
|
end
|
279
284
|
end
|
280
285
|
|
281
|
-
# Swich this Application RP into the '
|
286
|
+
# Swich this Application RP into the 'stopped' state
|
282
287
|
# (see the description of configure :state)
|
283
288
|
#
|
284
|
-
work('
|
285
|
-
if res.property.state == :
|
289
|
+
work('switch_to_stopped') do |res|
|
290
|
+
if res.property.state == :running || res.property.state == :paused
|
286
291
|
id = res.property.app_id
|
287
292
|
unless ExecApp[id].nil?
|
288
293
|
# stop this app
|
@@ -299,18 +304,18 @@ module OmfRc::ResourceProxy::Application
|
|
299
304
|
# finally, try sending KILL signal
|
300
305
|
ExecApp[id].kill('KILL') unless ExecApp[id].nil?
|
301
306
|
end
|
302
|
-
res.property.state = :
|
307
|
+
res.property.state = :completed
|
303
308
|
rescue => err
|
304
309
|
end
|
305
310
|
end
|
306
311
|
end
|
307
312
|
end
|
308
313
|
|
309
|
-
# Swich this Application RP into the '
|
314
|
+
# Swich this Application RP into the 'running' state
|
310
315
|
# (see the description of configure :state)
|
311
316
|
#
|
312
|
-
work('
|
313
|
-
if res.property.state == :
|
317
|
+
work('switch_to_running') do |res|
|
318
|
+
if res.property.state == :stopped
|
314
319
|
# start a new instance of this app
|
315
320
|
res.property.app_id = res.hrn.nil? ? res.uid : res.hrn
|
316
321
|
# we need at least a defined binary path to run an app...
|
@@ -320,25 +325,25 @@ module OmfRc::ResourceProxy::Application
|
|
320
325
|
ExecApp.new(res.property.app_id, res,
|
321
326
|
res.build_command_line,
|
322
327
|
res.property.map_err_to_out)
|
323
|
-
res.property.state = :
|
328
|
+
res.property.state = :running
|
324
329
|
end
|
325
|
-
elsif res.property.state == :
|
330
|
+
elsif res.property.state == :paused
|
326
331
|
# resume this paused app
|
327
|
-
res.property.state = :
|
332
|
+
res.property.state = :running
|
328
333
|
# do more things here...
|
329
|
-
|
330
|
-
# cannot run as we are still installing
|
331
|
-
res.log_inform_warn "
|
334
|
+
else
|
335
|
+
# cannot run as we are still installing or already completed
|
336
|
+
res.log_inform_warn "Cannot switch to running state as current state is '#{res.property.state}'"
|
332
337
|
end
|
333
338
|
end
|
334
339
|
|
335
|
-
# Swich this Application RP into the '
|
340
|
+
# Swich this Application RP into the 'paused' state
|
336
341
|
# (see the description of configure :state)
|
337
342
|
#
|
338
|
-
work('
|
339
|
-
if res.property.state == :
|
343
|
+
work('switch_to_paused') do |res|
|
344
|
+
if res.property.state == :running
|
340
345
|
# pause this app
|
341
|
-
res.property.state = :
|
346
|
+
res.property.state = :paused
|
342
347
|
# do more things here...
|
343
348
|
end
|
344
349
|
end
|
@@ -354,12 +359,12 @@ module OmfRc::ResourceProxy::Application
|
|
354
359
|
# Only update a parameter if it is dynamic and the application is running
|
355
360
|
dynamic = false
|
356
361
|
dynamic = att[:dynamic] if res.boolean?(att[:dynamic])
|
357
|
-
if dynamic && res.property.state == :
|
362
|
+
if dynamic && res.property.state == :running
|
358
363
|
line = ""
|
359
364
|
line += "#{att[:cmd]} " unless att[:cmd].nil?
|
360
365
|
line += "#{att[:value]}"
|
361
366
|
ExecApp[res.property.app_id].stdin(line)
|
362
|
-
logger.info "Updated parameter #{name} with value #{att[:value].inspect}"
|
367
|
+
logger.info "Updated parameter '#{name}' with value '#{att[:value].inspect}' (stdin: '#{line}')"
|
363
368
|
end
|
364
369
|
end
|
365
370
|
|
@@ -11,8 +11,8 @@ module OmfRc::ResourceProxy::Node
|
|
11
11
|
end
|
12
12
|
|
13
13
|
request :interfaces do |node|
|
14
|
-
node.children.find_all { |v| v.type ==
|
15
|
-
{ name: v.
|
14
|
+
node.children.find_all { |v| v.type == :net || v.type == :wlan }.map do |v|
|
15
|
+
{ name: v.property.if_name, type: v.type, uid: v.uid }
|
16
16
|
end.sort { |x, y| x[:name] <=> y[:name] }
|
17
17
|
end
|
18
18
|
|
@@ -22,4 +22,13 @@ module OmfRc::ResourceProxy::Node
|
|
22
22
|
end.sort { |x, y| x[:name] <=> y[:name] }
|
23
23
|
end
|
24
24
|
|
25
|
+
hook :before_create do |node, type, opts|
|
26
|
+
if type.to_sym == :net
|
27
|
+
net_dev = node.request_devices.find do |v|
|
28
|
+
v[:name] == opts[:if_name]
|
29
|
+
end
|
30
|
+
raise "Device '#{opts[:if_name]}' not found" if net_dev.nil?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
end
|
@@ -95,7 +95,7 @@
|
|
95
95
|
#
|
96
96
|
# # Define a new event to run the VM resource once it is 'ready'
|
97
97
|
# vm_topic.on_message do |m|
|
98
|
-
# if (m.operation == :inform) && (m.read_content("
|
98
|
+
# if (m.operation == :inform) && (m.read_content("itype") == 'STATUS') && m.read_property('ready')
|
99
99
|
# conf_vm_run.publish vm_topic.id
|
100
100
|
# end
|
101
101
|
# end
|
@@ -4,6 +4,8 @@ module OmfRc::ResourceProxyDSL
|
|
4
4
|
PROXY_DIR = "omf_rc/resource_proxy"
|
5
5
|
UTIL_DIR = "omf_rc/util"
|
6
6
|
|
7
|
+
DEF_ACCESS = [:configure, :request]
|
8
|
+
|
7
9
|
def self.included(base)
|
8
10
|
base.extend(ClassMethods)
|
9
11
|
end
|
@@ -35,6 +37,7 @@ module OmfRc::ResourceProxyDSL
|
|
35
37
|
if opts[:create_by] && !opts[:create_by].kind_of?(Array)
|
36
38
|
opts[:create_by] = [opts[:create_by]]
|
37
39
|
end
|
40
|
+
opts[:proxy_module] = self
|
38
41
|
OmfRc::ResourceFactory.register_proxy(name => opts)
|
39
42
|
end
|
40
43
|
|
@@ -90,7 +93,7 @@ module OmfRc::ResourceProxyDSL
|
|
90
93
|
# # * resource: the parent resource itself
|
91
94
|
# # * new_resource: the child resource instance
|
92
95
|
# hook :after_create do |resource, new_resource|
|
93
|
-
# logger.info "#{resource.uid} created #{new_resource.uid}
|
96
|
+
# logger.info "#{resource.uid} created #{new_resource.uid}"
|
94
97
|
# end
|
95
98
|
#
|
96
99
|
# # before_ready hook
|
@@ -325,6 +328,24 @@ module OmfRc::ResourceProxyDSL
|
|
325
328
|
define_method("def_property_#{name}") do |*args, &block|
|
326
329
|
self.property[name] ||= opts[:default]
|
327
330
|
end
|
331
|
+
|
332
|
+
access = opts.access || DEF_ACCESS
|
333
|
+
access.each do |a|
|
334
|
+
case a
|
335
|
+
when :configure
|
336
|
+
define_method("configure_#{name}") do |val|
|
337
|
+
self.property[name] = val
|
338
|
+
end
|
339
|
+
|
340
|
+
when :request
|
341
|
+
define_method("request_#{name}") do
|
342
|
+
self.property[name]
|
343
|
+
end
|
344
|
+
|
345
|
+
else
|
346
|
+
raise "Unnown access type '#{a}'"
|
347
|
+
end
|
348
|
+
end
|
328
349
|
end
|
329
350
|
end
|
330
351
|
end
|
@@ -37,11 +37,9 @@ module OmfRc::Util::CommonTools
|
|
37
37
|
%w(error warn).each do |type|
|
38
38
|
work("log_inform_#{type}") do |res, msg|
|
39
39
|
logger.send(type, msg)
|
40
|
-
|
40
|
+
OmfCommon.comm.publish(
|
41
41
|
res.uid,
|
42
|
-
OmfCommon::Message.inform
|
43
|
-
message.element('reason' , msg)
|
44
|
-
end
|
42
|
+
OmfCommon::Message.create(:inform, nil, { reason: msg, itype: type.upcase })
|
45
43
|
)
|
46
44
|
end
|
47
45
|
end
|
data/lib/omf_rc/util/hostapd.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
require 'cocaine'
|
3
|
+
require 'tempfile'
|
3
4
|
|
4
5
|
module OmfRc::Util::Hostapd
|
5
6
|
include OmfRc::ResourceProxyDSL
|
@@ -8,8 +9,8 @@ module OmfRc::Util::Hostapd
|
|
8
9
|
# Initialise access point conf and pid location
|
9
10
|
#
|
10
11
|
work :init_ap_conf_pid do |device|
|
11
|
-
device.property.ap_conf = "
|
12
|
-
device.property.ap_pid = "
|
12
|
+
device.property.ap_conf = Tempfile.new(["hostapd.#{device.property.if_name}", ".conf"]).path
|
13
|
+
device.property.ap_pid = Tempfile.new(["hostapd.#{device.property.if_name}", ".pid"]).path
|
13
14
|
end
|
14
15
|
# Set up and run a hostapd instance
|
15
16
|
#
|
@@ -17,7 +18,7 @@ module OmfRc::Util::Hostapd
|
|
17
18
|
device.init_ap_conf_pid
|
18
19
|
|
19
20
|
File.open(device.property.ap_conf, "w") do |f|
|
20
|
-
f << "driver=nl80211\ninterface=#{device.
|
21
|
+
f << "driver=nl80211\ninterface=#{device.property.if_name}\nssid=#{device.property.essid}\nchannel=#{device.property.channel}\n"
|
21
22
|
f << "hw_mode=#{device.property.hw_mode}\n" if %w(a b g).include? device.property.hw_mode
|
22
23
|
if device.property.hw_mode == 'n'
|
23
24
|
if device.property.channel.to_i < 15
|
data/lib/omf_rc/util/ip.rb
CHANGED
@@ -5,32 +5,35 @@ module OmfRc::Util::Ip
|
|
5
5
|
include Cocaine
|
6
6
|
|
7
7
|
request :ip_addr do |resource|
|
8
|
-
addr = CommandLine.new("ip", "addr show dev :device", :device => resource.
|
8
|
+
addr = CommandLine.new("ip", "addr show dev :device", :device => resource.property.if_name).run
|
9
9
|
addr && addr.chomp.match(/inet ([[0-9]\:\/\.]+)/) && $1
|
10
10
|
end
|
11
11
|
|
12
12
|
request :mac_addr do |resource|
|
13
|
-
addr = CommandLine.new("ip", "addr show dev :device", :device => resource.
|
13
|
+
addr = CommandLine.new("ip", "addr show dev :device", :device => resource.property.if_name).run
|
14
14
|
addr && addr.chomp.match(/link\/ether ([\d[a-f][A-F]\:]+)/) && $1
|
15
15
|
end
|
16
16
|
|
17
17
|
configure :ip_addr do |resource, value|
|
18
|
+
if value.nil? || value.split('/')[1].nil?
|
19
|
+
raise ArgumentError, "You need to provide an IP address with netmask. E.g. 0.0.0.0/24. Got #{value}."
|
20
|
+
end
|
18
21
|
# Remove all ip addrs associated with the device
|
19
22
|
resource.flush_ip_addrs
|
20
23
|
CommandLine.new("ip", "addr add :ip_address dev :device",
|
21
24
|
:ip_address => value,
|
22
|
-
:device => resource.
|
25
|
+
:device => resource.property.if_name
|
23
26
|
).run
|
24
27
|
resource.interface_up
|
25
28
|
resource.request_ip_addr
|
26
29
|
end
|
27
30
|
|
28
31
|
work :interface_up do |resource|
|
29
|
-
CommandLine.new("ip", "link set :dev up", :dev => resource.
|
32
|
+
CommandLine.new("ip", "link set :dev up", :dev => resource.property.if_name).run
|
30
33
|
end
|
31
34
|
|
32
35
|
work :flush_ip_addrs do |resource|
|
33
36
|
CommandLine.new("ip", "addr flush dev :device",
|
34
|
-
:device => resource.
|
37
|
+
:device => resource.property.if_name).run
|
35
38
|
end
|
36
39
|
end
|
data/lib/omf_rc/util/iw.rb
CHANGED
@@ -14,9 +14,10 @@ module OmfRc::Util::Iw
|
|
14
14
|
#
|
15
15
|
begin
|
16
16
|
CommandLine.new("iw", "help").run.chomp.gsub(/^\t/, '').split("\n").map {|v| v.match(/[phy|dev] <.+> set (\w+) .*/) && $1 }.compact.uniq.each do |p|
|
17
|
+
next if p == 'type'
|
17
18
|
configure p do |device, value|
|
18
19
|
CommandLine.new("iw", "dev :dev set :property :value",
|
19
|
-
:dev => device.
|
20
|
+
:dev => device.property.if_name,
|
20
21
|
:property => p,
|
21
22
|
:value => value).run
|
22
23
|
end
|
@@ -30,7 +31,7 @@ module OmfRc::Util::Iw
|
|
30
31
|
request :link do |device|
|
31
32
|
known_properties = Mash.new
|
32
33
|
|
33
|
-
command = CommandLine.new("iw", "dev :dev link", :dev => device.
|
34
|
+
command = CommandLine.new("iw", "dev :dev link", :dev => device.property.if_name)
|
34
35
|
|
35
36
|
command.run.chomp.gsub(/^\t/, '').split("\n").drop(1).each do |v|
|
36
37
|
v.match(/^(.+):\W*(.+)$/).tap do |m|
|
@@ -46,7 +47,7 @@ module OmfRc::Util::Iw
|
|
46
47
|
request :info do |device|
|
47
48
|
known_properties = Mash.new
|
48
49
|
|
49
|
-
command = CommandLine.new("iw", "dev :dev info", :dev => device.
|
50
|
+
command = CommandLine.new("iw", "dev :dev info", :dev => device.property.if_name)
|
50
51
|
|
51
52
|
command.run.chomp.split("\n").drop(1).each do |v|
|
52
53
|
v.match(/^\W*(.+) (.+)$/).tap do |m|
|
@@ -59,8 +60,8 @@ module OmfRc::Util::Iw
|
|
59
60
|
|
60
61
|
# Delete current interface, clean up
|
61
62
|
#
|
62
|
-
work :
|
63
|
-
CommandLine.new("iw", "dev :dev del", :dev => device.
|
63
|
+
work :delete_interface do |device|
|
64
|
+
CommandLine.new("iw", "dev :dev del", :dev => device.property.if_name).run
|
64
65
|
end
|
65
66
|
|
66
67
|
# Add interface to device
|
@@ -68,7 +69,7 @@ module OmfRc::Util::Iw
|
|
68
69
|
work :add_interface do |device, type|
|
69
70
|
CommandLine.new("iw", "phy :phy interface add :dev type :type",
|
70
71
|
:phy => device.property.phy,
|
71
|
-
:dev => device.
|
72
|
+
:dev => device.property.if_name,
|
72
73
|
:type => type.to_s).run
|
73
74
|
end
|
74
75
|
|
@@ -76,7 +77,7 @@ module OmfRc::Util::Iw
|
|
76
77
|
#
|
77
78
|
work :join_ibss do |device|
|
78
79
|
CommandLine.new("iw", "dev :device ibss join :essid :frequency",
|
79
|
-
:device => device.
|
80
|
+
:device => device.property.if_name.to_s,
|
80
81
|
:essid => device.property.essid.to_s,
|
81
82
|
:frequency => device.property.frequency.to_s).run
|
82
83
|
end
|
@@ -115,9 +116,18 @@ module OmfRc::Util::Iw
|
|
115
116
|
# capture value hash and store internally
|
116
117
|
device.property.update(value)
|
117
118
|
|
119
|
+
if device.property.phy && device.property.phy =~ /^%(\d+)%$/
|
120
|
+
wlan_phy_device = device.request_wlan_devices[$1.to_i]
|
121
|
+
if wlan_phy_device
|
122
|
+
device.property.phy = wlan_phy_device[:name]
|
123
|
+
else
|
124
|
+
raise ArgumentError, "Could not find your wifi device no #{$1.to_i}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
118
128
|
device.validate_iw_properties
|
119
129
|
|
120
|
-
device.
|
130
|
+
device.delete_interface rescue logger.warn "Interface #{device.property.if_name} not found"
|
121
131
|
|
122
132
|
# TODO should just remove all interfaces from physical device, at least make it optional
|
123
133
|
|
data/lib/omf_rc/util/sysfs.rb
CHANGED
@@ -15,6 +15,20 @@ module OmfRc::Util::Sysfs
|
|
15
15
|
device = { name: File.basename(v), driver: driver, category: category }
|
16
16
|
device[:subcategory] = subcategory if subcategory
|
17
17
|
device[:proxy] = proxy if OmfRc::ResourceFactory.proxy_list.include?(proxy.to_sym)
|
18
|
+
File.exist?("#{v}/operstate") && File.open("#{v}/operstate") do |fo|
|
19
|
+
device[:op_state] = (fo.read || '').chomp
|
20
|
+
end
|
21
|
+
# Let's see if the interface is already up
|
22
|
+
# NOTE: THIS MAY NOT BE ROBUST
|
23
|
+
s = `ifconfig #{File.basename(v)}`
|
24
|
+
unless s.empty?
|
25
|
+
if m = s.match(/inet addr:\s*([0-9.]+)/)
|
26
|
+
device[:ip4] = m[1]
|
27
|
+
end
|
28
|
+
if m = s.match(/inet6 addr:\s*([0-9a-f.:\/]+)/)
|
29
|
+
device[:ip6] = m[1]
|
30
|
+
end
|
31
|
+
end
|
18
32
|
devices << device
|
19
33
|
end
|
20
34
|
end
|
@@ -163,7 +163,7 @@ source /usr/local/rvm/scripts/rvm
|
|
163
163
|
command rvm install 1.9.3
|
164
164
|
PATH=$PATH:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/
|
165
165
|
source /usr/local/rvm/environments/ruby-1.9.3-p194
|
166
|
-
gem install omf_rc --
|
166
|
+
gem install omf_rc --no-ri --no-rdoc
|
167
167
|
# HACK
|
168
168
|
# Right now we dont have a Ubuntu startup script for OMF6 RC
|
169
169
|
# Do this quick hack in the meantime
|
data/lib/omf_rc/util/wpa.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
require 'cocaine'
|
3
|
+
require 'tempfile'
|
3
4
|
|
4
5
|
module OmfRc::Util::Wpa
|
5
6
|
include OmfRc::ResourceProxyDSL
|
@@ -8,8 +9,8 @@ module OmfRc::Util::Wpa
|
|
8
9
|
# Initialise wpa related conf and pid location
|
9
10
|
#
|
10
11
|
work :init_wpa_conf_pid do |device|
|
11
|
-
device.property.wpa_conf = "
|
12
|
-
device.property.wpa_pid = "
|
12
|
+
device.property.wpa_conf = Tempfile.new(["wpa.#{device.property.if_name}", ".conf"]).path
|
13
|
+
device.property.wpa_pid = Tempfile.new(["wpa.#{device.property.if_name}", ".pid"]).path
|
13
14
|
end
|
14
15
|
|
15
16
|
work :wpasup do |device|
|
@@ -19,7 +20,7 @@ module OmfRc::Util::Wpa
|
|
19
20
|
f << "network={\n ssid=\"#{device.property.essid}\"\n scan_ssid=1\n key_mgmt=NONE\n}"
|
20
21
|
end
|
21
22
|
CommandLine.new("wpa_supplicant", "-B -P :wpa_pid -i:dev -c:wpa_conf",
|
22
|
-
:dev => device.
|
23
|
+
:dev => device.property.if_name,
|
23
24
|
:wpa_conf => device.property.wpa_conf,
|
24
25
|
:wpa_pid => device.property.wpa_pid).run
|
25
26
|
end
|
data/lib/omf_rc/version.rb
CHANGED
data/lib/omf_rc.rb
CHANGED
data/omf_rc.gemspec
CHANGED
@@ -7,10 +7,12 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = OmfRc::VERSION
|
8
8
|
s.authors = ["NICTA"]
|
9
9
|
s.email = ["omf-user@lists.nicta.com.au"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "http://omf.mytestbed.net"
|
11
11
|
s.summary = %q{OMF resource controller}
|
12
12
|
s.description = %q{Resource controller of OMF, a generic framework for controlling and managing networking testbeds.}
|
13
|
-
|
13
|
+
s.required_ruby_version = '>= 1.9.3'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
14
16
|
s.rubyforge_project = "omf_rc"
|
15
17
|
|
16
18
|
s.files = `git ls-files`.split("\n")
|
@@ -2,9 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe OmfRc::MessageProcessError do
|
4
4
|
it "must be able to initialised" do
|
5
|
-
mpe = OmfRc::MessageProcessError.new('
|
6
|
-
mpe.
|
7
|
-
mpe.
|
5
|
+
mpe = OmfRc::MessageProcessError.new('test_cid', 'replyto_address', 'error_messsage')
|
6
|
+
mpe.cid.must_equal 'test_cid'
|
7
|
+
mpe.replyto.must_equal 'replyto_address'
|
8
8
|
mpe.message.must_equal 'error_messsage'
|
9
9
|
mpe.must_be_kind_of StandardError
|
10
10
|
end
|
@@ -3,24 +3,31 @@ require 'omf_rc/resource_factory'
|
|
3
3
|
|
4
4
|
describe OmfRc::ResourceFactory do
|
5
5
|
describe "when resource proxies loaded" do
|
6
|
+
before do
|
7
|
+
@xmpp = MiniTest::Mock.new
|
8
|
+
@xmpp.expect(:subscribe, true, [String])
|
9
|
+
end
|
10
|
+
|
6
11
|
it "must have list of registered proxies and utilities" do
|
7
12
|
OmfRc::ResourceFactory.load_default_resource_proxies
|
8
13
|
OmfRc::ResourceFactory.proxy_list.must_include :mock
|
9
14
|
end
|
10
15
|
|
11
16
|
it "must be able to create new resource proxy" do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
OmfCommon.stub :comm, @xmpp do
|
18
|
+
OmfRc::ResourceFactory.load_default_resource_proxies
|
19
|
+
mock = OmfRc::ResourceFactory.new(:mock)
|
20
|
+
mock.must_be_kind_of OmfRc::ResourceProxy::AbstractResource
|
21
|
+
mock.must_respond_to :request_nothing
|
22
|
+
mock.request_nothing.must_equal mock.uid
|
23
|
+
mock.must_respond_to :configure_nothing
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
it "must be able to load addtional proxies from local folder" do
|
21
28
|
Dir.stub :[], ["non_exist_folder/test.rb"] do
|
22
29
|
proc do
|
23
|
-
OmfRc::ResourceFactory.
|
30
|
+
OmfRc::ResourceFactory.load_additional_resource_proxies("non_exist_folder")
|
24
31
|
end.must_raise LoadError
|
25
32
|
end
|
26
33
|
end
|