omf_rc 6.0.2.pre.2 → 6.0.2

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.
Files changed (46) hide show
  1. data/bin/omf_rc +19 -11
  2. data/config/config.yml +0 -5
  3. data/config/config_with_authentication.yml.example +1 -1
  4. data/lib/omf_rc/deferred_process.rb +5 -0
  5. data/lib/omf_rc/omf_error.rb +5 -0
  6. data/lib/omf_rc/resource_factory.rb +17 -5
  7. data/lib/omf_rc/resource_proxy/abstract_resource.rb +186 -85
  8. data/lib/omf_rc/resource_proxy/application.rb +77 -53
  9. data/lib/omf_rc/resource_proxy/net.rb +29 -2
  10. data/lib/omf_rc/resource_proxy/node.rb +53 -2
  11. data/lib/omf_rc/resource_proxy/virtual_machine.rb +5 -0
  12. data/lib/omf_rc/resource_proxy/virtual_machine_factory.rb +5 -0
  13. data/lib/omf_rc/resource_proxy/wlan.rb +41 -2
  14. data/lib/omf_rc/resource_proxy_dsl.rb +68 -8
  15. data/lib/omf_rc/util/common_tools.rb +5 -0
  16. data/lib/omf_rc/util/hostapd.rb +13 -0
  17. data/lib/omf_rc/util/ip.rb +39 -0
  18. data/lib/omf_rc/util/iw.rb +115 -39
  19. data/lib/omf_rc/util/libvirt.rb +5 -0
  20. data/lib/omf_rc/util/mod.rb +20 -1
  21. data/lib/omf_rc/util/openflow_tools.rb +5 -0
  22. data/lib/omf_rc/util/package.rb +5 -0
  23. data/lib/omf_rc/util/platform_tools.rb +5 -0
  24. data/lib/omf_rc/util/sysfs.rb +23 -3
  25. data/lib/omf_rc/util/vmbuilder.rb +5 -0
  26. data/lib/omf_rc/util/wpa.rb +12 -0
  27. data/lib/omf_rc/version.rb +6 -1
  28. data/lib/omf_rc.rb +5 -0
  29. data/omf_rc.gemspec +2 -1
  30. data/test/omf_rc/deferred_process_spec.rb +5 -0
  31. data/test/omf_rc/message_process_error_spec.rb +5 -0
  32. data/test/omf_rc/resource_factory_spec.rb +8 -6
  33. data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +151 -89
  34. data/test/omf_rc/resource_proxy/application_spec.rb +10 -11
  35. data/test/omf_rc/resource_proxy/node_spec.rb +6 -1
  36. data/test/omf_rc/resource_proxy_dsl_spec.rb +31 -6
  37. data/test/omf_rc/util/common_tools_spec.rb +6 -1
  38. data/test/omf_rc/util/ip_spec.rb +9 -3
  39. data/test/omf_rc/util/iw_spec.rb +16 -6
  40. data/test/omf_rc/util/mod_spec.rb +8 -3
  41. data/test/test_helper.rb +6 -0
  42. metadata +26 -13
  43. data/lib/omf_rc/resource_proxy/mock.rb +0 -16
  44. data/lib/omf_rc/util/mock.rb +0 -22
  45. data/test/omf_rc/resource_proxy/mock_spec.rb +0 -20
  46. data/test/omf_rc/util/mock_spec.rb +0 -31
@@ -1,108 +1,135 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'em/minitest/spec'
3
8
  require 'omf_rc/resource_factory'
4
- require 'blather'
5
9
 
6
10
  include OmfRc::ResourceProxy
7
11
 
8
12
  module OmfRc::ResourceProxy
9
- module Node
13
+ module Parent
10
14
  include OmfRc::ResourceProxyDSL
11
- register_proxy :node
12
-
13
- request :name
14
- configure :name
15
- end
15
+ register_proxy :parent
16
16
 
17
- module Interface
18
- include OmfRc::ResourceProxyDSL
19
- register_proxy :interface
17
+ request :test_exception do
18
+ raise StandardError
19
+ end
20
20
  end
21
21
 
22
- module Wifi
22
+ module Child
23
23
  include OmfRc::ResourceProxyDSL
24
- register_proxy :wifi
24
+ register_proxy :child, create_by: :parent
25
+ property :p1
25
26
  end
26
27
 
27
- module Mock
28
+ module RandomResource
28
29
  include OmfRc::ResourceProxyDSL
29
- register_proxy :mock
30
+ register_proxy :random_resource, create_by: :nobody
30
31
  end
31
32
  end
32
33
 
33
34
  describe AbstractResource do
34
35
  before do
35
- @xmpp = MiniTest::Mock.new
36
- @xmpp.expect(:subscribe, true, [String])
37
- OmfCommon.stub :comm, @xmpp do
38
- @node = OmfRc::ResourceFactory.new(:node, { hrn: 'default_node' }, { create_children_resources: true })
36
+ # Things we need to mock
37
+ # * communicator
38
+ # * topic
39
+ # * calling communicator callbacks
40
+ @comm = mock
41
+ @topics = {
42
+ parent: OmfCommon::Comm::Topic.create(:parent),
43
+ child: OmfCommon::Comm::Topic.create(:child)
44
+ }
45
+ [:inform, :publish, :unsubscribe].each do |m_name|
46
+ OmfCommon::Comm::Topic.any_instance.stubs(m_name)
47
+ end
48
+
49
+ # Return child topic by default unless specified
50
+ @comm.stubs(:create_topic).returns(@topics[:child])
51
+
52
+ [:parent, :child].each do |t_name|
53
+ @topics[t_name].stubs(:address).returns("xmpp://localhost/#{t_name.to_s}")
54
+ @comm.stubs(:create_topic).with("xmpp://localhost/#{t_name}").returns(@topics[t_name])
55
+ end
56
+
57
+ @comm.class_eval do
58
+ define_method(:subscribe) do |*args, &block|
59
+ block.call(self.create_topic("xmpp://localhost/#{args[0]}"))
60
+ end
39
61
  end
62
+
63
+ OmfCommon.stubs(:comm).returns(@comm)
64
+ @parent = OmfRc::ResourceFactory.create(:parent, { uid: :parent, hrn: 'default_node' }, { create_children_resources: true })
40
65
  end
41
66
 
42
- describe "when intialised" do
43
- it "must convert configuration hash into instance methods, and assign the values" do
44
- @node.type.must_equal :node
67
+ after do
68
+ @comm.class_eval do
69
+ undef_method(:subscribe)
70
+ end
71
+ OmfCommon.unstub(:comm)
72
+ [:inform, :publish, :unsubscribe].each do |m_name|
73
+ OmfCommon::Comm::Topic.any_instance.unstub(m_name)
45
74
  end
75
+ @parent = nil
76
+ end
46
77
 
47
- it "must have an unique id generated" do
48
- @node.uid.must_match /.{8}-.{4}-.{4}-.{4}-.{12}/
49
- @node.request_uid.must_match /.{8}-.{4}-.{4}-.{4}-.{12}/
78
+ describe "when created itself (bootstrap)" do
79
+ it "must have an unique id generated if not given" do
80
+ OmfRc::ResourceFactory.create(:parent).uid.must_match /.{8}-.{4}-.{4}-.{4}-.{12}/
50
81
  end
51
82
 
52
- it "could keep state inside 'property' instnace variable" do
53
- @node.property.bob = "test"
54
- @node.property.bob.must_equal "test"
83
+ it "must be able to keep state inside 'property' instnace variable" do
84
+ @parent.property.bob = "test"
85
+ @parent.property.bob.must_equal "test"
55
86
  end
56
87
 
57
88
  it "must be able to access creation options" do
58
- @node.creation_opts[:create_children_resources].must_equal true
89
+ @parent.creation_opts[:create_children_resources].must_equal true
59
90
  end
60
- end
61
91
 
62
- describe "when asked to create another resource" do
63
- it "must return the newly created resource" do
64
- OmfCommon.stub :comm, @xmpp do
65
- @xmpp.expect(:subscribe, true, [String])
66
- @node.create(:interface).must_be_kind_of AbstractResource
67
- end
92
+ it "must returned all the properties can be requested & configured" do
93
+ @parent.request_available_properties.configure.must_equal [:membership]
94
+ @parent.request_available_properties.request.must_equal(
95
+ [:test_exception, :supported_children_type, :uid, :type, :hrn, :name, :membership, :child_resources]
96
+ )
68
97
  end
69
98
 
70
- it "must add the resource to its created resource list" do
71
- skip
72
- OmfCommon.stub :comm, @xmpp do
73
- @xmpp.expect(:subscribe, true, [String])
74
- child = @node.create(:wifi, { hrn: 'default_wifi' })
75
- @node.children.must_include child
76
- @node.request_child_resources.find { |v| v.uid == child.uid }.name.must_equal 'default_wifi'
77
- end
99
+ it "must return types of child resources it can create" do
100
+ @parent.request_supported_children_type.must_include :child
78
101
  end
79
- end
80
102
 
81
- describe "when destroyed" do
82
- it "must destroy itself together with any resources created by it" do
83
- skip
84
- OmfCommon.stub :comm, @xmpp do
85
- @xmpp.expect(:delete_topic, nil)
86
- @xmpp.expect(:subscribe, true, [String])
87
- child = @node.create(:wifi, { hrn: 'default_wifi' })
88
- @node.children.wont_be_empty
89
- @node.release(child.uid)
90
- @node.children.must_be_empty
91
- end
103
+ it "must be able to query core properties" do
104
+ @parent.request_type.must_equal :parent
105
+ @parent.request_name.must_equal 'default_node'
106
+ @parent.request_hrn.must_equal 'default_node'
107
+ @parent.request_membership.must_equal []
108
+ end
109
+
110
+ it "must be able to configure membership (join group)" do
111
+ @parent.configure_membership(:test_group)
112
+ @parent.request_membership.must_include :test_group
92
113
  end
93
114
  end
94
115
 
95
- describe "when asked for the funcitonalities it supports" do
96
- it "must returned all the properties can be requested & configured" do
97
- @node.request_available_properties.must_be_kind_of Hashie::Mash
98
- @node.request_available_properties.configure.must_include :name
99
- @node.request_available_properties.request.must_include :name
116
+ describe "when parent asked to create child resource" do
117
+ it "must return the newly created resource add the resource to its created resource list" do
118
+ child = @parent.create(:child)
119
+ @parent.children.must_include child
120
+ @parent.request_child_resources.must_include({ uid: child.uid, address: child.resource_address })
100
121
  end
101
122
 
102
- it "must be able to request and configure some common properties" do
103
- @node.request_hrn.must_equal 'default_node'
104
- @node.configure_hrn('bob')
105
- @node.request_hrn.must_equal 'bob'
123
+ it "must raise error if child is not designed to be created by parent" do
124
+ lambda { @parent.create(:random_resource) }.must_raise StandardError
125
+ end
126
+ end
127
+
128
+ describe "when parent asked to release child resource" do
129
+ it "must release the child resource" do
130
+ child = @parent.create(:child)
131
+ @parent.release(child.uid).must_equal child
132
+ @parent.children.must_be_empty
106
133
  end
107
134
  end
108
135
 
@@ -121,30 +148,30 @@ describe AbstractResource do
121
148
  skip
122
149
  # FIXME
123
150
  @xmpp.stub :publish, proc { |replyto, message| message.valid?.must_equal true} do
124
- @node.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
125
- @node.inform(:released, res_id: 'bob', cid: 'id', replyto: 'topic')
126
- @node.inform(:status, status: { key: 'value' }, cid: 'id', replyto: 'topic')
127
- @node.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
128
- @node.inform(:warn, 'going to fail')
129
- @node.inform(:error, 'failed')
130
- @node.inform(:warn, Exception.new('going to fail'))
131
- @node.inform(:error, Exception.new('failed'))
132
- @node.inform(:creation_failed, Exception.new('failed'))
151
+ @parent.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
152
+ @parent.inform(:released, res_id: 'bob', cid: 'id', replyto: 'topic')
153
+ @parent.inform(:status, status: { key: 'value' }, cid: 'id', replyto: 'topic')
154
+ @parent.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
155
+ @parent.inform(:warn, 'going to fail')
156
+ @parent.inform(:error, 'failed')
157
+ @parent.inform(:warn, Exception.new('going to fail'))
158
+ @parent.inform(:error, Exception.new('failed'))
159
+ @parent.inform(:creation_failed, Exception.new('failed'))
133
160
  end
134
161
 
135
- lambda { @node.inform(:creation_failed, 'bob') }.must_raise ArgumentError
136
- lambda { @node.inform(:creation_ok, 'topic') }.must_raise ArgumentError
137
- lambda { @node.inform(:status, 'topic') }.must_raise ArgumentError
162
+ lambda { @parent.inform(:creation_failed, 'bob') }.must_raise ArgumentError
163
+ lambda { @parent.inform(:creation_ok, 'topic') }.must_raise ArgumentError
164
+ lambda { @parent.inform(:status, 'topic') }.must_raise ArgumentError
138
165
  end
139
166
 
140
167
  it "must be able to connect & disconnect" do
141
168
  skip
142
169
  Blather::Client.stub :new, @client do
143
170
  Blather::Stream::Client.stub(:start, @client) do
144
- @node = OmfRc::ResourceFactory.new(:node, { hrn: 'default_node', user: 'bob', password: 'pw', server: 'example.com'}, @xmpp)
171
+ @parent = OmfRc::ResourceFactory.create(:node, { hrn: 'default_node', user: 'bob', password: 'pw', server: 'example.com'}, @xmpp)
145
172
  @client.stub(:connected?, true) do
146
- @node.connect
147
- @node.comm.conn_info.must_equal({proto: :xmpp, user: 'bob', doamin: 'example.com'})
173
+ @parent.connect
174
+ @parent.comm.conn_info.must_equal({proto: :xmpp, user: 'bob', doamin: 'example.com'})
148
175
  end
149
176
  end
150
177
  end
@@ -154,19 +181,54 @@ describe AbstractResource do
154
181
  describe "when request/configure property not pre-defined in proxy" do
155
182
  it "must try property hash" do
156
183
  skip
157
- @node.property[:bob] = "bob"
158
- @node.property[:false] = false
184
+ @parent.property[:bob] = "bob"
185
+ @parent.property[:false] = false
159
186
 
160
- @node.methods.must_include :request_bob
161
- @node.methods.must_include :configure_bob
187
+ @parent.methods.must_include :request_bob
188
+ @parent.methods.must_include :configure_bob
162
189
 
163
- @node.request_bob.must_equal "bob"
164
- @node.request_false.must_equal false
190
+ @parent.request_bob.must_equal "bob"
191
+ @parent.request_false.must_equal false
192
+
193
+ @parent.configure_bob("not_bob")
194
+ @parent.request_bob.must_equal "not_bob"
195
+ proc { @parent.request_bobs_cousin }.must_raise OmfRc::UnknownPropertyError
196
+ proc { @parent.bobs_cousin }.must_raise NoMethodError
197
+ end
198
+ end
199
+
200
+ describe "when FRCP incoming messages received" do
201
+ before do
202
+ @create_msg = OmfCommon::Message.create(:create, { uid: 'child_001', type: :child, p1: 'p1_value' })
203
+ @configure_msg = OmfCommon::Message.create(:configure, { p1: 'p1_value' })
204
+ @request_msg = OmfCommon::Message.create(:request, { name: nil })
205
+ @release_msg = OmfCommon::Message.create(:release, {}, { res_id: 'child_001' })
206
+ end
207
+
208
+ it "must accept FRCP messages" do
209
+ @parent.process_omf_message(@request_msg, @topics[:parent])
210
+ end
211
+
212
+ it "must resuce exception if occured" do
213
+ @parent.process_omf_message(OmfCommon::Message.create(:request, { test_exception: nil }), @topics[:parent])
214
+ end
215
+
216
+ it "must handle CREATE/RELEASE message" do
217
+ @parent.handle_message(@create_msg, @parent)
218
+ @parent.request_child_resources.must_include({ uid: 'child_001', address: 'xmpp://localhost/child' })
219
+
220
+ @parent.handle_message(@release_msg, @parent)
221
+ @parent.request_child_resources.wont_include({ uid: 'child_001', address: 'xmpp://localhost/child' })
222
+ end
223
+
224
+ it "must handle REQUEST message" do
225
+ @parent.handle_message(@request_msg, @parent.create(:child))
226
+ end
165
227
 
166
- @node.configure_bob("not_bob")
167
- @node.request_bob.must_equal "not_bob"
168
- proc { @node.request_bobs_cousin }.must_raise OmfRc::UnknownPropertyError
169
- proc { @node.bobs_cousin }.must_raise NoMethodError
228
+ it "must handle CONFIGURE message" do
229
+ c = @parent.create(:child)
230
+ @parent.handle_message(@configure_msg, c)
231
+ c.request_p1.must_equal 'p1_value'
170
232
  end
171
233
  end
172
234
  end
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'omf_rc/resource_proxy/application'
3
8
 
@@ -10,7 +15,7 @@ describe OmfRc::ResourceProxy::Application do
10
15
  @xmpp.expect(:publish, true, [String, OmfCommon::Message])
11
16
 
12
17
  OmfCommon.stub :comm, @xmpp do
13
- @app_test = OmfRc::ResourceFactory.new(:application, { hrn: 'an_application' })
18
+ @app_test = OmfRc::ResourceFactory.create(:application, { hrn: 'an_application' })
14
19
  end
15
20
  end
16
21
 
@@ -186,27 +191,21 @@ describe OmfRc::ResourceProxy::Application do
186
191
  end
187
192
  end
188
193
 
189
- it "must switch its state to :completed if the event is of a type 'DONE' and the application is not installing itself" do
194
+ it "must switch its state to :completed if the event is of a type 'EXIT' and the application is not installing itself" do
190
195
  skip
191
196
  OmfCommon.stub :comm, @xmpp do
192
197
  @app_test.stub :inform, true do
193
- @app_test.on_app_event('DONE.OK', 'app_instance_id', 'Some text here')
194
- @app_test.request_state.to_sym.must_equal :completed
195
- end
196
- end
197
- OmfCommon.stub :comm, @xmpp do
198
- @app_test.stub :inform, true do
199
- @app_test.on_app_event('DONE.ERROR', 'app_instance_id', 'Some text here')
198
+ @app_test.on_app_event('EXIT', 'app_instance_id', 'Some text here')
200
199
  @app_test.request_state.to_sym.must_equal :completed
201
200
  end
202
201
  end
203
202
  end
204
203
 
205
- it "must set installed property to true if the event is 'DONE.OK' and the application was installing itself" do
204
+ it "must set installed property to true if the event is 'EXIT' and the application was installing itself" do
206
205
  skip
207
206
  OmfCommon.stub :comm, @xmpp do
208
207
  @app_test.stub :inform, true do
209
- @app_test.on_app_event('DONE.OK', 'app_instance_id_INSTALL', 'Some text here')
208
+ @app_test.on_app_event('EXIT', 'app_instance_id_INSTALL', 'Some text here')
210
209
  @app_test.request_state.to_sym.must_equal :stopped
211
210
  @app_test.request_installed.must_equal true
212
211
  end
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'omf_rc/resource_proxy/node'
3
8
 
@@ -7,7 +12,7 @@ describe OmfRc::ResourceProxy::Node do
7
12
  @xmpp.expect(:subscribe, true, [String])
8
13
 
9
14
  OmfCommon.stub :comm, @xmpp do
10
- @node = OmfRc::ResourceFactory.new(:node, hrn: 'node_test')
15
+ @node = OmfRc::ResourceFactory.create(:node, hrn: 'node_test')
11
16
  end
12
17
  end
13
18
 
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'omf_rc/resource_proxy_dsl'
3
8
 
@@ -9,7 +14,9 @@ describe OmfRc::ResourceProxyDSL do
9
14
  module OmfRc::Util::MockUtility
10
15
  include OmfRc::ResourceProxyDSL
11
16
 
12
- property :mock_prop, :default => 1
17
+ property :mock_prop, default: 1
18
+ property :read_only_prop, default: 1, access: :read_only
19
+ property :init_only_prop, default: 1, access: :init_only
13
20
 
14
21
  configure :alpha
15
22
 
@@ -79,7 +86,7 @@ describe OmfRc::ResourceProxyDSL do
79
86
  OmfRc::ResourceProxy::MockProxy.method_defined?(m.to_sym).must_equal true
80
87
  end
81
88
 
82
- mock_proxy = OmfRc::ResourceFactory.new(:mock_proxy)
89
+ mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy)
83
90
  mock_proxy.request_alpha.must_equal mock_proxy.uid
84
91
  mock_proxy.request_delta.must_equal "printing"
85
92
  mock_proxy.request_charlie.must_equal "working on printing"
@@ -111,18 +118,36 @@ describe OmfRc::ResourceProxyDSL do
111
118
  it "must check new proxy's create_by option when ask a proxy create a new proxy" do
112
119
  OmfCommon.stub :comm, @xmpp do
113
120
  @xmpp.expect(:subscribe, true, [String])
114
- OmfRc::ResourceFactory.new(:mock_root_proxy).create(:mock_proxy)
121
+ OmfRc::ResourceFactory.create(:mock_root_proxy).create(:mock_proxy)
115
122
  2.times { @xmpp.expect(:subscribe, true, [String]) }
116
- OmfRc::ResourceFactory.new(:mock_root_proxy).create(:useless_proxy)
123
+ OmfRc::ResourceFactory.create(:mock_root_proxy).create(:useless_proxy)
117
124
  2.times { @xmpp.expect(:subscribe, true, [String]) }
118
- lambda { OmfRc::ResourceFactory.new(:useless_proxy).create(:mock_proxy) }.must_raise StandardError
125
+ lambda { OmfRc::ResourceFactory.create(:useless_proxy).create(:mock_proxy) }.must_raise StandardError
119
126
  end
120
127
  end
121
128
 
122
129
  it "must be able to define property with default vlaue" do
123
130
  OmfCommon.stub :comm, @xmpp do
124
- mock_proxy = OmfRc::ResourceFactory.new(:mock_proxy)
131
+ mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy)
125
132
  mock_proxy.property.mock_prop.must_equal 1
133
+ mock_proxy.request_mock_prop.must_equal 1
134
+ mock_proxy.configure_mock_prop(2)
135
+ mock_proxy.request_mock_prop.must_equal 2
136
+ end
137
+ end
138
+
139
+
140
+ it "must define associate methods when access option given to property definition" do
141
+ OmfCommon.stub :comm, @xmpp do
142
+ mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy)
143
+ # Ready only
144
+ mock_proxy.request_read_only_prop.must_equal 1
145
+ lambda { mock_proxy.init_read_only_prop }.must_raise NoMethodError
146
+ lambda { mock_proxy.configure_read_only_prop }.must_raise NoMethodError
147
+ # Init only
148
+ mock_proxy.request_init_only_prop.must_equal 1
149
+ lambda { mock_proxy.init_init_only_prop }.must_raise NoMethodError
150
+ lambda { mock_proxy.configure_init_only_prop }.must_raise NoMethodError
126
151
  end
127
152
  end
128
153
  end
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'omf_rc/util/common_tools'
3
8
 
@@ -17,7 +22,7 @@ describe OmfRc::Util::CommonTools do
17
22
 
18
23
  it "must be able to log and inform error/warn messages" do
19
24
  OmfCommon.stub :comm, @xmpp do
20
- @test = OmfRc::ResourceFactory.new(:test)
25
+ @test = OmfRc::ResourceFactory.create(:test)
21
26
  2.times { @xmpp.expect(:publish, true, [String, OmfCommon::Message]) }
22
27
  @test.log_inform_error "bob"
23
28
  @test.log_inform_warn "bob"
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'minitest/mock'
2
7
  require 'test_helper'
3
8
 
@@ -18,7 +23,7 @@ describe OmfRc::Util::Ip do
18
23
  @command = MiniTest::Mock.new
19
24
 
20
25
  OmfCommon.stub :comm, @xmpp do
21
- @wlan00 = OmfRc::ResourceFactory.new(:ip_test, hrn: 'wlan00')
26
+ @wlan00 = OmfRc::ResourceFactory.create(:ip_test, hrn: 'wlan00')
22
27
  end
23
28
  end
24
29
 
@@ -44,8 +49,9 @@ describe OmfRc::Util::Ip do
44
49
  end
45
50
  end
46
51
 
47
- it "could configure the device's prorperty" do
48
- lambda { @wlan00.configure_ip_addr("192.168.1.124/24") }.must_raise Cocaine::ExitStatusError
52
+ it "could configure the device's property" do
53
+ # cdw: disabled this call since it actually tried to run "ip" on my system !?
54
+ # lambda { @wlan00.configure_ip_addr("192.168.1.124/24") }.must_raise Cocaine::ExitStatusError
49
55
  Cocaine::CommandLine.stub(:new, @command) do
50
56
  3.times do
51
57
  @command.expect(:run, "")
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'minitest/mock'
2
7
  require 'test_helper'
3
8
  require 'cocaine'
@@ -15,15 +20,20 @@ Cocaine::CommandLine.stub(:new, @command) do
15
20
 
16
21
  module OmfRc::ResourceProxy::IwTest
17
22
  include OmfRc::ResourceProxyDSL
23
+
18
24
  register_proxy :iw_test
25
+
19
26
  utility :iw
27
+
28
+ property :if_name
29
+ property :phy
20
30
  end
21
31
 
22
32
  @xmpp = MiniTest::Mock.new
23
33
  @xmpp.expect(:subscribe, true, [String])
24
34
 
25
35
  OmfCommon.stub :comm, @xmpp do
26
- @wlan00 = OmfRc::ResourceFactory.new(:iw_test, hrn: 'wlan00', property: { phy: 'phy00', if_name: 'wlan1' })
36
+ @wlan00 = OmfRc::ResourceFactory.create(:iw_test, hrn: 'wlan00', property: { phy: 'phy00', if_name: 'wlan1' })
27
37
  end
28
38
  end
29
39
 
@@ -49,7 +59,7 @@ Cocaine::CommandLine.stub(:new, @command) do
49
59
  end
50
60
  end
51
61
 
52
- it "could configure the device's prorperty" do
62
+ it "could configure the device's property" do
53
63
  Cocaine::CommandLine.stub(:new, @command) do
54
64
  @command.expect(:run, true)
55
65
  @wlan00.configure_power_save(true)
@@ -59,14 +69,14 @@ Cocaine::CommandLine.stub(:new, @command) do
59
69
 
60
70
  it "must could initialise wpa config/pid file path" do
61
71
  @wlan00.init_ap_conf_pid
62
- @wlan00.property.ap_conf.must_match /tmp\/hostapd\.wlan1.+\.conf/
63
- @wlan00.property.ap_pid.must_match /tmp\/hostapd\.wlan1.+\.pid/
72
+ @wlan00.property.ap_conf.must_match /\/hostapd\.wlan1.+\.conf/
73
+ @wlan00.property.ap_pid.must_match /\/hostapd\.wlan1.+\.pid/
64
74
  end
65
75
 
66
76
  it "must could initialise wpa config/pid file path" do
67
77
  @wlan00.init_wpa_conf_pid
68
- @wlan00.property.wpa_conf.must_match /tmp\/wpa\.wlan1.+\.conf/
69
- @wlan00.property.wpa_pid.must_match /tmp\/wpa\.wlan1.+\.pid/
78
+ @wlan00.property.wpa_conf.must_match /\/wpa\.wlan1.+\.conf/
79
+ @wlan00.property.wpa_pid.must_match /\/wpa\.wlan1.+\.pid/
70
80
  end
71
81
 
72
82
  it "could delete current interface" do
@@ -1,3 +1,8 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'test_helper'
2
7
  require 'omf_rc/util/mod'
3
8
 
@@ -18,10 +23,10 @@ describe OmfRc::Util::Mod do
18
23
  OmfCommon.stub :comm, @xmpp do
19
24
  Cocaine::CommandLine.stub(:new, @command) do
20
25
  @command.expect(:run, fixture("lsmod"))
21
- OmfRc::ResourceFactory.new(:mod_test).request_modules.must_include "kvm"
26
+ OmfRc::ResourceFactory.create(:mod_test).request_modules.must_include "kvm"
22
27
  @command.expect(:run, fixture("lsmod"))
23
28
  @xmpp.expect(:subscribe, true, [String])
24
- OmfRc::ResourceFactory.new(:mod_test).request_modules.wont_include "Module"
29
+ OmfRc::ResourceFactory.create(:mod_test).request_modules.wont_include "Module"
25
30
  @command.verify
26
31
  end
27
32
  end
@@ -31,7 +36,7 @@ describe OmfRc::Util::Mod do
31
36
  OmfCommon.stub :comm, @xmpp do
32
37
  Cocaine::CommandLine.stub(:new, @command) do
33
38
  @command.expect(:run, true)
34
- OmfRc::ResourceFactory.new(:mod_test).configure_load_module(name: 'magic_module').must_equal "magic_module loaded"
39
+ OmfRc::ResourceFactory.create(:mod_test).configure_load_module(name: 'magic_module').must_equal "magic_module loaded"
35
40
  @command.verify
36
41
  end
37
42
  end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,15 @@
1
+ # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
+ # This software may be used and distributed solely under the terms of the MIT license (License).
3
+ # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
+ # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
+
1
6
  require 'simplecov'
2
7
  SimpleCov.start { add_filter "/test" }
3
8
 
4
9
  gem 'minitest'
5
10
  require 'minitest/autorun'
6
11
  require 'minitest/pride'
12
+ require 'mocha/setup'
7
13
 
8
14
  require 'omf_rc'
9
15
  require 'omf_rc/resource_factory'