omf_rc 6.1.1 → 6.1.2.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDc2ZGUxY2Y1M2IzM2RjNGNkYmFhZmZjYjFmZWJkZjUzNGI5NDU5ZA==
5
- data.tar.gz: !binary |-
6
- MTliNjA1NmMxNWEzNzc0Mjc4NTBiZjAzZGMzZjQwZTQ4NTk0OWNjMg==
2
+ SHA1:
3
+ metadata.gz: 58d8f4886473d854c19c6fc5bdee608b74f552a3
4
+ data.tar.gz: 7a7a1c8bc9efc0b6332a8d61b898081adeece4b5
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjA3MTIxNjlkZDdiYTI1OGM0ZjY3ZmVhNjAxYzEwMzJhZDYyMDhjYThlYTU4
10
- NTRjNTg4ZDlhZDhmZTQ4ZGRmN2I2YzQ5NzVkMDJhNGFhMjJlODExZTA4YmUw
11
- NTkzYzViZjQzNGVhNzVjMTNjMDNiMWI1NTEzY2ZlMmRhZmM4MWM=
12
- data.tar.gz: !binary |-
13
- MDk2NGU3M2JlYWI3ZTlhNmRmY2VlMGEwZThmYzJjY2FhNmYzMzViODczNjU0
14
- MmY0OTI5ZGJlOWVlY2FiZDE2NDI2YmMxY2MyZTMxZTJiNzQxZDRjNTExZmMz
15
- Yzc1NDdmNDg5MTU2YjMzZGEwNDU3ZWE2NTY5NDM3ODQ5YTQ3ZTQ=
6
+ metadata.gz: b1db665f420503a10073d7d580239ceaad24d80bba3b1abf18962554d34d39b6db1391489513c9f866f95321ca52c83499839c43b5b3af121ebc87c72d149d87
7
+ data.tar.gz: a7dde85adcbcae4a048ac43b87c5282a0776bac9ce37b349d3a041a545ca395dcf64b63b36d63d60ab8b9db24a6555599a28c7fc08a26ad89d4fc690a7666119
@@ -24,3 +24,20 @@ class OmfRc::UnknownPropertyError < NoMethodError
24
24
  super(msg)
25
25
  end
26
26
  end
27
+
28
+ # Customised errors for resource controller (Proposing)
29
+ #
30
+ class OmfRc::Error < StandardError; end
31
+
32
+ class OmfRc::Error
33
+ class UnknownProperty < OmfRc::Error; end
34
+ # Try to create a resource with type not known to resource controller
35
+ class UnknownResourceType < OmfRc::Error; end
36
+ # Try to access a child resource provided by identifier but can not be found
37
+ class UnknownChildResource < OmfRc::Error; end
38
+ # Ask a parent to create a child but failed due to parent's proxy definition
39
+ class InvalidResourceTypeToCreate < OmfRc::Error; end
40
+ # Try to access a property but access specified in proxy definition would not allow.
41
+ # e.g. configure when its init_only
42
+ class PropertyAccessDenied < OmfRc::Error; end
43
+ end
@@ -90,7 +90,7 @@ class OmfRc::ResourceProxy::AbstractResource
90
90
  @@defaults[resource_type.to_sym] = defaults
91
91
  end
92
92
 
93
- attr_accessor :uid, :hrn, :type, :property, :certificate
93
+ attr_accessor :uid, :hrn, :type, :property, :certificate, :state
94
94
  attr_reader :opts, :children, :membership, :creation_opts, :membership_topics, :topics
95
95
 
96
96
  # Initialisation
@@ -367,7 +367,7 @@ class OmfRc::ResourceProxy::AbstractResource
367
367
  #
368
368
  # @!macro group_configure
369
369
 
370
- # Make resource part of the group topic, it will overwrite existing membership array
370
+ # Make resource part of the group topic, it will alter existing membership array
371
371
  #
372
372
  # @param [String|Array|Hash] args name of group topic/topics
373
373
  #
@@ -381,12 +381,17 @@ class OmfRc::ResourceProxy::AbstractResource
381
381
  #
382
382
  # # Leave a single group or multiple groups
383
383
  # { leave: ["group_1", "group_2"] } or { leave: "group_1" }
384
+ #
385
+ # # Leave all groups except a selection of specific ones
386
+ # { only: ["group_1", "group_2"] } or { only: "group_1" }
387
+ #
384
388
  def configure_membership(*args)
385
389
  case args[0]
386
390
  when Symbol, String, Array
387
391
  new_membership = [args[0]].flatten.compact
388
392
  when Hash
389
393
  leave_membership = [args[0][:leave]].flatten.compact
394
+ only_membership = [args[0][:only]].flatten.compact
390
395
  end
391
396
 
392
397
  new_membership && new_membership.each do |new_m|
@@ -422,6 +427,11 @@ class OmfRc::ResourceProxy::AbstractResource
422
427
  end
423
428
  end
424
429
 
430
+ unless only_membership.nil? || only_membership.empty?
431
+ configure_membership({ leave: @membership })
432
+ configure_membership(only_membership)
433
+ end
434
+
425
435
  @membership
426
436
  end
427
437
 
@@ -554,14 +564,27 @@ class OmfRc::ResourceProxy::AbstractResource
554
564
  # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
555
565
  # @param [OmfCommon::Message] response initialised FRCP INFORM message object
556
566
  def handle_configure_message(message, obj, response)
557
- message.each_property do |key, value|
558
- method_name = "#{message.operation.to_s}_#{key}"
559
- p_value = message[key]
567
+ conf_properties = message.properties
568
+ conf_result = Hashie::Mash.new
569
+
570
+ call_hook(:pre_configure, obj, conf_properties, conf_result)
571
+
572
+ if obj.respond_to?(:configure_all)
573
+ obj.configure_all(conf_properties, conf_result)
574
+ else
575
+ conf_properties.each do |key, value|
576
+ method_name = "configure_#{key}"
577
+ conf_result[key] = obj.__send__(method_name, value)
578
+ end
579
+ end
580
+
581
+ call_hook(:post_configure, obj, conf_properties, conf_result)
560
582
 
583
+ conf_result.each do |key, value|
561
584
  if namespaced_property?(key)
562
- response[key, namespace] = obj.__send__(method_name, p_value)
585
+ response[key, namespace] = value
563
586
  else
564
- response[key] = obj.__send__(method_name, p_value)
587
+ response[key] = value
565
588
  end
566
589
  end
567
590
  end
@@ -41,22 +41,52 @@ module OmfRc::ResourceProxy::Wlan
41
41
  # @!macro prop
42
42
  property :phy
43
43
 
44
+ property :timer
45
+
44
46
  # @!endgroup
45
47
 
46
48
  # @!macro group_hook
47
- #
49
+ hook :before_ready do |device|
50
+ device.property.timer = OmfCommon.el.every(5) do |timer|
51
+ wlan_state = device.request_state
52
+ if wlan_state == 'UP'
53
+ device.inform(:status, { state: wlan_state })
54
+ timer.cancel
55
+ end
56
+ end
57
+ end
58
+
48
59
  # Stop hostapd or wpa instances before releasing wifi device
49
60
  # @!macro hook
50
61
  # @!method before_release
51
62
  hook :before_release do |device|
63
+ device.property.timer.cancel
64
+
52
65
  case device.property.mode.to_sym
53
66
  when :master
54
67
  device.stop_hostapd
55
68
  when :managed
56
69
  device.stop_wpa
57
70
  end
58
- #TODO need to remove all virtual interfaces of that phy device
59
- #device.remove_all_interfaces
71
+ device.interface_down
60
72
  end
61
73
  # @!endgroup
74
+
75
+
76
+ configure_all do |res, conf_props, conf_result|
77
+ # Make sure to set up wifi mode first
78
+ if (mode = conf_props.delete(:mode))
79
+ res.configure_mode(mode)
80
+ end
81
+
82
+ # Then if everything goes well, configure the ip address
83
+ if (ip_addr = conf_props.delete(:ip_addr))
84
+ res.configure_ip_addr(ip_addr)
85
+ end
86
+
87
+ conf_result[:ip_addr] = res.request_ip_addr
88
+ conf_result[:state] = res.request_state
89
+
90
+ conf_props.each { |k, v| conf_result[k] = res.__send__("configure_#{k}", v) }
91
+ end
62
92
  end
@@ -23,6 +23,10 @@ module OmfRc::ResourceProxyDSL
23
23
  context.send(hook_name, *params) if context.respond_to? hook_name
24
24
  end
25
25
 
26
+ def hook_defined?(hook_name, context)
27
+ context.respond_to? hook_name
28
+ end
29
+
26
30
  # When this module included, methods defined under ClassMethods will be available in resource definition files
27
31
  #
28
32
  def self.included(base)
@@ -220,6 +224,29 @@ module OmfRc::ResourceProxyDSL
220
224
  end
221
225
  end
222
226
 
227
+ # Configure multiple properties when operations need to be completed in order, or the all operations are transactional
228
+ #
229
+ # @example
230
+ #
231
+ # configure_all do |resource, configure_properties, result|
232
+ # # Execute property one first, and make sure it is successful before attending property two
233
+ # if resource.some_operation(configure_properties[:property_one])
234
+ # if resource.other_operation(configure_properties[:property_two])
235
+ # result[:property_one] = 'GOOD'
236
+ # result[:property_two] = 'GREAT'
237
+ # else
238
+ # raise "Some errors"
239
+ # end
240
+ # else
241
+ # raise "Some errors"
242
+ # end
243
+ # end
244
+ def configure_all(&register_block)
245
+ define_method("configure_all") do |*args, &block|
246
+ register_block.call(self, *args, block) if register_block
247
+ end
248
+ end
249
+
223
250
  # Register a property that could be requested
224
251
  #
225
252
  # @param (see #configure)
@@ -365,10 +392,10 @@ module OmfRc::ResourceProxyDSL
365
392
  #
366
393
  # @example
367
394
  # # Read-only property, i.e. could not be modified through FRCP protocol
368
- # property :bob, default: 1, access: :configure
395
+ # property :bob, default: 1, access: :read_only
369
396
  #
370
397
  # # Read & Write property, i.e. could be modified through FRCP protocol
371
- # property :bob, default: 1, access: :read_only
398
+ # property :bob, default: 1, access: :configure
372
399
  #
373
400
  # # Read & could be modified ONLY through FRCP CREATE message
374
401
  # property :bob, default: 1, access: :init_only
data/lib/omf_rc/runner.rb CHANGED
@@ -8,12 +8,6 @@ module OmfRc
8
8
  # in decreasing priority through the command line, configuration
9
9
  # file and default settings (see @def_opts).
10
10
  #
11
- # For historic reasons and to make this implementation more interesting
12
- # there are two different config file formats. A 'normal' one inherited from
13
- # earlier version of OMF, and an 'advanced' one which is identical to the
14
- # format accepted by OmfCommon.init(). To maintain some level of sanity,
15
- # only one configuration file is accepted.
16
- #
17
11
  # Having said that, there is one exception and that relates to the 'oml'
18
12
  # configuration which is stripped out first and handed to the OML4R library
19
13
  # during command line parsing.
@@ -35,17 +29,12 @@ module OmfRc
35
29
  environment: 'production',
36
30
  resources: [ { type: :node, uid: @node_id }],
37
31
  factories: {},
38
- communication: { url: "xmpp://#{@node_id}-#{Process.pid}:#{@node_id}-#{Process.pid}@localhost" },
32
+ communication: { url: "amqp://localhost" },
33
+ logging: {},
39
34
  add_default_factories: true,
40
35
  )
41
36
 
42
- @gopts = Mash.new(
43
- config_file: nil,
44
- adv_config_file: nil,
45
- logging_configfile: nil,
46
- environment: nil
47
- )
48
-
37
+ @gopts = Mash.new
49
38
  @opts = Mash.new
50
39
 
51
40
  @omlopts = {appName: @executable_name}
@@ -64,9 +53,14 @@ module OmfRc
64
53
 
65
54
  Signal.trap("SIGINT") do
66
55
  # TODO: Should release resources first
67
- info "Stopping ..."
68
- OmfCommon.comm.disconnect
69
- OmfCommon.eventloop.stop
56
+
57
+ # Workaround to EM issue under ruby v2
58
+ # https://github.com/eventmachine/eventmachine/issues/418
59
+ el.after(0) do
60
+ info "Stopping ..."
61
+ OmfCommon.comm.disconnect
62
+ el.stop
63
+ end
70
64
  end
71
65
 
72
66
  # Load extensions
@@ -121,7 +115,7 @@ module OmfRc
121
115
  end
122
116
 
123
117
  def parse_config_files()
124
- config_file = @gopts[:config_file]
118
+ config_file = @gopts.delete(:config_file)
125
119
 
126
120
  if config_file.nil?
127
121
  puts "You must specify a config file"
@@ -139,11 +133,15 @@ module OmfRc
139
133
  when :uid
140
134
  @opts[:resources][0][:type] = :node
141
135
  @opts[:resources][0][:uid] = v
136
+ when :debug
137
+ @opts[:logging][:level] = 'debug' if v
142
138
  else
143
139
  @opts[k] = v
144
140
  end
145
141
  end
146
142
 
143
+ @opts.merge!(@gopts)
144
+
147
145
  @omlopts.merge(@opts[:instrumentation] || {}) { |k, v1, v2| v1 } # merge in place as OML may hold @omlopts
148
146
  end
149
147
  end
@@ -159,10 +157,6 @@ module OmfRc
159
157
  @gopts[:config_file] = file
160
158
  end
161
159
 
162
- op.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
163
- @gopts[:adv_config_file] = file
164
- end
165
-
166
160
  op.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
167
161
  @gopts[:logging_configfile] = file
168
162
  end
@@ -31,6 +31,12 @@ module OmfRc::Util::Ip
31
31
  addr = CommandLine.new("ip", "addr show dev :device", :device => resource.property.if_name).run
32
32
  addr && addr.chomp.match(/link\/ether ([\d[a-f][A-F]\:]+)/) && $1
33
33
  end
34
+
35
+ request :state do |device|
36
+ link = CommandLine.new("ip", "link show :device", :device => device.property.if_name).run
37
+ link && link.chomp.match(/state (\w+) /) && $1
38
+ end
39
+
34
40
  # @!endgroup
35
41
 
36
42
  # @!macro group_configure
@@ -66,6 +72,10 @@ module OmfRc::Util::Ip
66
72
  CommandLine.new("ip", "link set :dev up", :dev => resource.property.if_name).run
67
73
  end
68
74
 
75
+ work :interface_down do |device|
76
+ CommandLine.new("ip", "link set :dev down", :dev => device.property.if_name).run
77
+ end
78
+
69
79
  # Remove IP addresses associated with the interface
70
80
  #
71
81
  # @!macro work
@@ -39,7 +39,7 @@ module OmfRc::Util::Wpa
39
39
  work :stop_wpa do |device|
40
40
  begin
41
41
  File.open(device.property.wpa_pid,'r') do |f|
42
- logger.debug "Stopping wpa supplicant at PID: #{device.property.wpa_pid}"
42
+ info "Stopping wpa supplicant at PID: #{device.property.wpa_pid}"
43
43
  CommandLine.new("kill", "-9 :pid", :pid => f.read.chomp).run
44
44
  end
45
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_rc
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 6.1.1
75
+ version: 6.1.2.pre
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 6.1.1
82
+ version: 6.1.2.pre
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: cocaine
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,14 +98,14 @@ dependencies:
98
98
  name: mocha
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Resource controller of OMF, a generic framework for controlling and managing
@@ -201,18 +201,47 @@ require_paths:
201
201
  - lib
202
202
  required_ruby_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
- - - ! '>='
204
+ - - '>='
205
205
  - !ruby/object:Gem::Version
206
206
  version: 1.9.3
207
207
  required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  requirements:
209
- - - ! '>='
209
+ - - '>'
210
210
  - !ruby/object:Gem::Version
211
- version: '0'
211
+ version: 1.3.1
212
212
  requirements: []
213
213
  rubyforge_project: omf_rc
214
- rubygems_version: 2.2.2
214
+ rubygems_version: 2.1.11
215
215
  signing_key:
216
216
  specification_version: 4
217
217
  summary: OMF resource controller
218
- test_files: []
218
+ test_files:
219
+ - test/fixture/ip/addr_show
220
+ - test/fixture/iw/help
221
+ - test/fixture/iw/info
222
+ - test/fixture/iw/link
223
+ - test/fixture/lsmod
224
+ - test/fixture/omf_rc.simple.yml
225
+ - test/fixture/omf_rc.yml
226
+ - test/fixture/oml.hash
227
+ - test/fixture/oml.spec
228
+ - test/fixture/oml.xml
229
+ - test/fixture/sys/class/ieee80211/phy0/device/uevent
230
+ - test/fixture/sys/class/ieee80211/phy0/uevent
231
+ - test/fixture/sys/class/net/eth0/device/uevent
232
+ - test/fixture/sys/class/net/eth0/uevent
233
+ - test/fixture/sys/class/net/wlan0/device/uevent
234
+ - test/fixture/sys/class/net/wlan0/uevent
235
+ - test/omf_rc/deferred_process_spec.rb
236
+ - test/omf_rc/message_process_error_spec.rb
237
+ - test/omf_rc/resource_factory_spec.rb
238
+ - test/omf_rc/resource_proxy/abstract_resource_spec.rb
239
+ - test/omf_rc/resource_proxy/application_spec.rb
240
+ - test/omf_rc/resource_proxy/node_spec.rb
241
+ - test/omf_rc/resource_proxy_dsl_spec.rb
242
+ - test/omf_rc/runner_spec.rb
243
+ - test/omf_rc/util/common_tools_spec.rb
244
+ - test/omf_rc/util/ip_spec.rb
245
+ - test/omf_rc/util/iw_spec.rb
246
+ - test/omf_rc/util/mod_spec.rb
247
+ - test/test_helper.rb