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.
Files changed (43) hide show
  1. data/bin/install_omf_rc +79 -0
  2. data/bin/omf_rc +52 -36
  3. data/config/config.yml +8 -0
  4. data/init/debian +51 -0
  5. data/init/fedora +54 -0
  6. data/init/run_omf_rc.sh +62 -0
  7. data/init/ubuntu +12 -0
  8. data/lib/omf_rc/omf_error.rb +5 -5
  9. data/lib/omf_rc/resource_factory.rb +7 -11
  10. data/lib/omf_rc/resource_proxy/abstract_resource.rb +327 -228
  11. data/lib/omf_rc/resource_proxy/application.rb +61 -56
  12. data/lib/omf_rc/resource_proxy/net.rb +2 -2
  13. data/lib/omf_rc/resource_proxy/node.rb +11 -2
  14. data/lib/omf_rc/resource_proxy/virtual_machine.rb +1 -1
  15. data/lib/omf_rc/resource_proxy/wlan.rb +2 -0
  16. data/lib/omf_rc/resource_proxy_dsl.rb +22 -1
  17. data/lib/omf_rc/util/common_tools.rb +2 -4
  18. data/lib/omf_rc/util/hostapd.rb +4 -3
  19. data/lib/omf_rc/util/ip.rb +8 -5
  20. data/lib/omf_rc/util/iw.rb +18 -8
  21. data/lib/omf_rc/util/sysfs.rb +14 -0
  22. data/lib/omf_rc/util/vmbuilder.rb +1 -1
  23. data/lib/omf_rc/util/wpa.rb +4 -3
  24. data/lib/omf_rc/version.rb +1 -1
  25. data/lib/omf_rc.rb +3 -1
  26. data/omf_rc.gemspec +4 -2
  27. data/test/omf_rc/message_process_error_spec.rb +3 -3
  28. data/test/omf_rc/resource_factory_spec.rb +14 -7
  29. data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +47 -21
  30. data/test/omf_rc/resource_proxy/application_spec.rb +156 -119
  31. data/test/omf_rc/resource_proxy/mock_spec.rb +6 -1
  32. data/test/omf_rc/resource_proxy/node_spec.rb +32 -12
  33. data/test/omf_rc/resource_proxy_dsl_spec.rb +31 -19
  34. data/test/omf_rc/util/common_tools_spec.rb +8 -11
  35. data/test/omf_rc/util/ip_spec.rb +7 -1
  36. data/test/omf_rc/util/iw_spec.rb +18 -13
  37. data/test/omf_rc/util/mock_spec.rb +6 -1
  38. data/test/omf_rc/util/mod_spec.rb +17 -10
  39. data/test/test_helper.rb +3 -0
  40. metadata +51 -48
  41. data/config/omf_rc.yml +0 -70
  42. data/lib/omf_rc/resource_proxy/openflow_slice.rb +0 -79
  43. 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
- # (stop, run, pause, install)
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 => :stop
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
- res.property.state = :stop if event_type.to_s.include?('DONE')
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
- inform_to: m,
145
- status: { status_type: 'APP_EVENT',
146
- event: event_type.to_s.upcase,
147
- app: app_id,
148
- msg: msg,
149
- seq: res.property.event_sequence,
150
- uid: res.uid }
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
- # stop, run, pause, install. The semantic of each states are:
219
+ # stopped, running, paused, installing. The semantic of each states are:
219
220
  #
220
- # - stop: the initial state for an Application RP, and the final state for
221
- # an applicaiton RP, for which the application instance finished
222
- # its execution or its installation
223
- # - run: upon entering in this state, a new instance of the application is
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 'pause' or 'stop' state.
227
- # - pause: upon entering this state, the currently running instance of this
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! The default
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 'run' state.
233
- # - install: upon entering in this state, a new installation of the
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 finished. The
236
- # Application RP can only enter this state from a previous 'stop'
237
- # state, and can only enter a 'stop' state once the installation
238
- # is finished.
239
- # Supported install methods are: Tarball, Ubuntu, and Fedora
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 :install then res.switch_to_install
246
- when :stop then res.switch_to_stop
247
- when :run then res.switch_to_run
248
- when :pause then res.switch_to_pause
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 'install' state
258
+ # Swich this Application RP into the 'installing' state
254
259
  # (see the description of configure :state)
255
260
  #
256
- work('switch_to_install') do |res|
257
- if res.property.state.to_sym == :stop
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 = :install
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 = :stop unless installing
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 STOP state. Cannot switch to INSTALL state!"
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 'stop' state
286
+ # Swich this Application RP into the 'stopped' state
282
287
  # (see the description of configure :state)
283
288
  #
284
- work('switch_to_stop') do |res|
285
- if res.property.state == :run || res.property.state == :pause
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 = :stop
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 'run' state
314
+ # Swich this Application RP into the 'running' state
310
315
  # (see the description of configure :state)
311
316
  #
312
- work('switch_to_run') do |res|
313
- if res.property.state == :stop
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 = :run
328
+ res.property.state = :running
324
329
  end
325
- elsif res.property.state == :pause
330
+ elsif res.property.state == :paused
326
331
  # resume this paused app
327
- res.property.state = :run
332
+ res.property.state = :running
328
333
  # do more things here...
329
- elsif res.property.state == :install
330
- # cannot run as we are still installing
331
- res.log_inform_warn "Still in INSTALL state. Cannot switch to RUN state!"
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 'pause' state
340
+ # Swich this Application RP into the 'paused' state
336
341
  # (see the description of configure :state)
337
342
  #
338
- work('switch_to_pause') do |res|
339
- if res.property.state == :run
343
+ work('switch_to_paused') do |res|
344
+ if res.property.state == :running
340
345
  # pause this app
341
- res.property.state = :pause
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 == :run
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
 
@@ -1,8 +1,8 @@
1
1
  module OmfRc::ResourceProxy::Net
2
2
  include OmfRc::ResourceProxyDSL
3
-
3
+
4
4
  register_proxy :net
5
-
5
+ property :if_name, :default => "eth0"
6
6
  utility :ip
7
7
  utility :sysfs
8
8
  end
@@ -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 == 'net' || v.type == 'wlan' }.map do |v|
15
- { name: v.hrn, type: v.type, uid: v.uid }
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("inform_type") == 'STATUS') && m.read_property('ready')
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
@@ -8,6 +8,8 @@ module OmfRc::ResourceProxy::Wlan
8
8
  utility :iw
9
9
  utility :sysfs
10
10
 
11
+ property :if_name, :default => "wlan0"
12
+
11
13
  hook :before_release do |device|
12
14
  case device.property.mode.to_sym
13
15
  when :master
@@ -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
- res.comm.publish(
40
+ OmfCommon.comm.publish(
41
41
  res.uid,
42
- OmfCommon::Message.inform(type.upcase) do |message|
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
@@ -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 = "/tmp/hostapd.#{device.hrn}.conf"
12
- device.property.ap_pid = "/tmp/hostapd.#{device.hrn}.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.hrn}\nssid=#{device.property.essid}\nchannel=#{device.property.channel}\n"
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
@@ -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.hrn).run
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.hrn).run
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.hrn
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.hrn).run
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.hrn).run
37
+ :device => resource.property.if_name).run
35
38
  end
36
39
  end
@@ -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.hrn,
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.hrn)
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.hrn)
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 :delele_interface do |device|
63
- CommandLine.new("iw", "dev :dev del", :dev => device.hrn).run
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.hrn,
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.hrn.to_s,
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.delele_interface rescue logger.warn "Interface #{device.hrn} not found"
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
 
@@ -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 --pre --no-ri --no-rdoc
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
@@ -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 = "/tmp/wpa.#{device.hrn}.conf"
12
- device.property.wpa_pid = "/tmp/wpa.#{device.hrn}.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.hrn,
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
@@ -1,3 +1,3 @@
1
1
  module OmfRc
2
- VERSION = "6.0.0.pre.8"
2
+ VERSION = "6.0.0.pre.9"
3
3
  end
data/lib/omf_rc.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'omf_common'
2
- require "omf_rc/version"
2
+ require 'omf_rc/version'
3
3
 
4
4
  module OmfRc
5
5
  module ResourceProxy; end
6
6
  module Util; end
7
7
  end
8
+
9
+ require 'omf_rc/resource_factory'
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 = "https://www.mytestbed.net"
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('test_context_id', 'inform_to_address', 'error_messsage')
6
- mpe.context_id.must_equal 'test_context_id'
7
- mpe.inform_to.must_equal 'inform_to_address'
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
- OmfRc::ResourceFactory.load_default_resource_proxies
13
- mock = OmfRc::ResourceFactory.new(:mock)
14
- mock.must_be_kind_of OmfRc::ResourceProxy::AbstractResource
15
- mock.must_respond_to :request_nothing
16
- mock.request_nothing.must_equal mock.uid
17
- mock.must_respond_to :configure_nothing
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.load_addtional_resource_proxies("non_exist_folder")
30
+ OmfRc::ResourceFactory.load_additional_resource_proxies("non_exist_folder")
24
31
  end.must_raise LoadError
25
32
  end
26
33
  end