omf_rc 6.0.0.pre.8 → 6.0.0.pre.9

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 (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
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'em/minitest/spec'
3
3
  require 'omf_rc/resource_factory'
4
+ require 'blather'
4
5
 
5
6
  include OmfRc::ResourceProxy
6
7
 
@@ -31,12 +32,16 @@ end
31
32
 
32
33
  describe AbstractResource do
33
34
  before do
34
- @node = OmfRc::ResourceFactory.new(:node, { hrn: 'default_node' })
35
+ @xmpp = MiniTest::Mock.new
36
+ @xmpp.expect(:subscribe, true, [Array])
37
+ OmfCommon.stub :comm, @xmpp do
38
+ @node = OmfRc::ResourceFactory.new(:node, { hrn: 'default_node' }, { create_children_resources: true })
39
+ end
35
40
  end
36
41
 
37
42
  describe "when intialised" do
38
43
  it "must convert configuration hash into instance methods, and assign the values" do
39
- @node.type.must_equal 'node'
44
+ @node.type.must_equal :node
40
45
  end
41
46
 
42
47
  it "must have an unique id generated" do
@@ -48,23 +53,36 @@ describe AbstractResource do
48
53
  @node.property.bob = "test"
49
54
  @node.property.bob.must_equal "test"
50
55
  end
56
+
57
+ it "must be able to access creation options" do
58
+ @node.creation_opts[:create_children_resources].must_equal true
59
+ end
51
60
  end
52
61
 
53
62
  describe "when asked to create another resource" do
54
63
  it "must return the newly created resource" do
55
- @node.create(:interface).must_be_kind_of AbstractResource
64
+ OmfCommon.stub :comm, @xmpp do
65
+ @xmpp.expect(:subscribe, true, [String])
66
+ @node.create(:interface).must_be_kind_of AbstractResource
67
+ end
56
68
  end
57
69
 
58
70
  it "must add the resource to its created resource list" do
59
- child = @node.create(:wifi, { hrn: 'default_wifi' })
60
- @node.children.must_include child
61
- @node.request_child_resources.find { |v| v.uid == child.uid }.name.must_equal 'default_wifi'
71
+ OmfCommon.stub :comm, @xmpp do
72
+ @xmpp.expect(:subscribe, true, [Array])
73
+ child = @node.create(:wifi, { hrn: 'default_wifi' })
74
+ @node.children.must_include child
75
+ @node.request_child_resources.find { |v| v.uid == child.uid }.name.must_equal 'default_wifi'
76
+ end
62
77
  end
63
78
  end
64
79
 
65
80
  describe "when destroyed" do
66
81
  it "must destroy itself together with any resources created by it" do
67
- @node.comm.stub :delete_topic, nil do
82
+ skip
83
+ OmfCommon.stub :comm, @xmpp do
84
+ @xmpp.expect(:delete_topic, nil)
85
+ @xmpp.expect(:subscribe, true, [Array])
68
86
  child = @node.create(:wifi, { hrn: 'default_wifi' })
69
87
  @node.children.wont_be_empty
70
88
  @node.release(child.uid)
@@ -88,35 +106,38 @@ describe AbstractResource do
88
106
  end
89
107
 
90
108
  describe "when interacted with communication layer" do
91
- include EM::MiniTest::Spec
109
+ #include EM::MiniTest::Spec
92
110
 
93
111
  before do
94
- @client = Blather::Client.new
95
- @stream = MiniTest::Mock.new
96
- @stream.expect(:send, true, [Blather::Stanza])
97
- @client.post_init @stream, Blather::JID.new('n@d/r')
98
- @xmpp = Class.new { include OmfCommon::DSL::Xmpp }.new
112
+ #@client = Blather::Client.new
113
+ #@stream = MiniTest::Mock.new
114
+ #@stream.expect(:send, true, [Blather::Stanza])
115
+ #@client.post_init @stream, Blather::JID.new('n@d/r')
116
+ #@xmpp = OmfCommon::Comm::XMPP::Communicator.new
99
117
  end
100
118
 
101
119
  it "must be able to send inform message" do
102
- @node.comm.stub :publish, proc { |inform_to, message| message.valid?.must_equal true} do
103
- @node.inform(:created, resource_id: 'bob', context_id: 'id', inform_to: 'topic')
104
- @node.inform(:released, resource_id: 'bob', context_id: 'id', inform_to: 'topic')
105
- @node.inform(:status, status: { key: 'value' }, context_id: 'id', inform_to: 'topic')
106
- @node.inform(:created, resource_id: 'bob', context_id: 'id', inform_to: 'topic')
120
+ skip
121
+ # FIXME
122
+ @xmpp.stub :publish, proc { |replyto, message| message.valid?.must_equal true} do
123
+ @node.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
124
+ @node.inform(:released, res_id: 'bob', cid: 'id', replyto: 'topic')
125
+ @node.inform(:status, status: { key: 'value' }, cid: 'id', replyto: 'topic')
126
+ @node.inform(:creation_ok, res_id: 'bob', cid: 'id', replyto: 'topic')
107
127
  @node.inform(:warn, 'going to fail')
108
128
  @node.inform(:error, 'failed')
109
129
  @node.inform(:warn, Exception.new('going to fail'))
110
130
  @node.inform(:error, Exception.new('failed'))
111
- @node.inform(:failed, Exception.new('failed'))
131
+ @node.inform(:creation_failed, Exception.new('failed'))
112
132
  end
113
133
 
114
- lambda { @node.inform(:failed, 'bob') }.must_raise ArgumentError
115
- lambda { @node.inform(:created, 'topic') }.must_raise ArgumentError
134
+ lambda { @node.inform(:creation_failed, 'bob') }.must_raise ArgumentError
135
+ lambda { @node.inform(:creation_ok, 'topic') }.must_raise ArgumentError
116
136
  lambda { @node.inform(:status, 'topic') }.must_raise ArgumentError
117
137
  end
118
138
 
119
139
  it "must be able to connect & disconnect" do
140
+ skip
120
141
  Blather::Client.stub :new, @client do
121
142
  Blather::Stream::Client.stub(:start, @client) do
122
143
  @node = OmfRc::ResourceFactory.new(:node, { hrn: 'default_node', user: 'bob', password: 'pw', server: 'example.com'}, @xmpp)
@@ -133,8 +154,13 @@ describe AbstractResource do
133
154
  it "must try property hash" do
134
155
  @node.property[:bob] = "bob"
135
156
  @node.property[:false] = false
157
+
158
+ @node.methods.must_include :request_bob
159
+ @node.methods.must_include :configure_bob
160
+
136
161
  @node.request_bob.must_equal "bob"
137
162
  @node.request_false.must_equal false
163
+
138
164
  @node.configure_bob("not_bob")
139
165
  @node.request_bob.must_equal "not_bob"
140
166
  proc { @node.request_bobs_cousin }.must_raise OmfRc::UnknownPropertyError
@@ -4,9 +4,13 @@ require 'omf_rc/resource_proxy/application'
4
4
  describe OmfRc::ResourceProxy::Application do
5
5
 
6
6
  before do
7
- @app_test = OmfRc::ResourceFactory.new(:application, { hrn: 'an_application' })
8
- @app_test.comm = MiniTest::Mock.new
9
- @app_test.comm.expect :publish, nil, [String,OmfCommon::Message]
7
+ @xmpp = MiniTest::Mock.new
8
+ @xmpp.expect(:subscribe, true, [Array])
9
+ @xmpp.expect(:publish, true, [String, OmfCommon::Message])
10
+
11
+ OmfCommon.stub :comm, @xmpp do
12
+ @app_test = OmfRc::ResourceFactory.new(:application, { hrn: 'an_application' })
13
+ end
10
14
  end
11
15
 
12
16
  describe "when initialised" do
@@ -16,7 +20,7 @@ describe OmfRc::ResourceProxy::Application do
16
20
  end
17
21
 
18
22
  it "must have its properties set to sensible initial values" do
19
- @app_test.request_state.to_sym.must_equal :stop
23
+ @app_test.request_state.to_sym.must_equal :stopped
20
24
  @app_test.request_tarball_install_path.must_equal '/'
21
25
  @app_test.request_force_tarball_install.must_equal false
22
26
  @app_test.request_installed.must_equal false
@@ -36,14 +40,16 @@ describe OmfRc::ResourceProxy::Application do
36
40
  end
37
41
 
38
42
  it "must be able to configure its environments property" do
39
- # First give it a valid environment property
40
- test_environments = { 'foo' => 123, 'bar_bar' => 'bar_123' }
41
- @app_test.method(:configure_environments).call(test_environments)
42
- # Then give it an invalid one, which it should ignore
43
- @app_test.method(:configure_environments).call(nil)
44
- @app_test.property.environments.must_be_kind_of Hash
45
- @app_test.property.environments['foo'].must_equal 123
46
- @app_test.property.environments['bar_bar'].must_equal 'bar_123'
43
+ OmfCommon.stub :comm, @xmpp do
44
+ # First give it a valid environment property
45
+ test_environments = { 'foo' => 123, 'bar_bar' => 'bar_123' }
46
+ @app_test.method(:configure_environments).call(test_environments)
47
+ # Then give it an invalid one, which it should ignore
48
+ @app_test.method(:configure_environments).call(nil)
49
+ @app_test.property.environments.must_be_kind_of Hash
50
+ @app_test.property.environments['foo'].must_equal 123
51
+ @app_test.property.environments['bar_bar'].must_equal 'bar_123'
52
+ end
47
53
  end
48
54
 
49
55
  it "must be able to configure its available OML measurement points" do
@@ -65,8 +71,8 @@ describe OmfRc::ResourceProxy::Application do
65
71
  # Then give it a couple of invalid ones, which it should ignore
66
72
  @app_test.stub :log_inform_error, nil do
67
73
  @app_test.method(:configure_parameters).call(nil)
68
- @app_test.method(:configure_parameters).call( { :p1 => nil } )
69
- end
74
+ @app_test.method(:configure_parameters).call( { :p1 => nil } )
75
+ end
70
76
  @app_test.property.parameters.must_be_kind_of Hash
71
77
  @app_test.property.parameters[:p1].must_be_kind_of Hash
72
78
  @app_test.property.parameters[:p1][:cmd].must_equal '--foo'
@@ -77,7 +83,7 @@ describe OmfRc::ResourceProxy::Application do
77
83
  old_params = { :p1 => { :cmd => '--foo', :default => 'old_foo'} }
78
84
  @app_test.property.parameters = old_params
79
85
  new_params = { :p1 => { :default => 'new_foo', :value => 'val_foo'},
80
- :p2 => { :cmd => 'bar', :default => 'bar_bar'} }
86
+ :p2 => { :cmd => 'bar', :default => 'bar_bar'} }
81
87
  @app_test.method(:configure_parameters).call(new_params)
82
88
  @app_test.property.parameters[:p1][:cmd].must_equal '--foo'
83
89
  @app_test.property.parameters[:p1][:default].must_equal 'new_foo'
@@ -88,14 +94,14 @@ describe OmfRc::ResourceProxy::Application do
88
94
 
89
95
  it "must be able to validate the correct type of a defined parameter" do
90
96
  test_params = { :p1 => { :type => 'String', :default => 'foo', :value => 'bar'},
91
- :p2 => { :type => 'Numeric', :default => 123, :value => 456},
92
- :p3 => { :type => 'Boolean', :default => true, :value => false},
93
- :p4 => { :type => 'Boolean'},
94
- :p5 => { :type => 'Boolean', :default => false},
95
- :p6 => { :type => 'Boolean', :value => true},
96
- :p7 => { :type => 'Numeric'},
97
- :p8 => { :type => 'Numeric', :default => 123},
98
- :p9 => { :type => 'Numeric', :value => 123} }
97
+ :p2 => { :type => 'Numeric', :default => 123, :value => 456},
98
+ :p3 => { :type => 'Boolean', :default => true, :value => false},
99
+ :p4 => { :type => 'Boolean'},
100
+ :p5 => { :type => 'Boolean', :default => false},
101
+ :p6 => { :type => 'Boolean', :value => true},
102
+ :p7 => { :type => 'Numeric'},
103
+ :p8 => { :type => 'Numeric', :default => 123},
104
+ :p9 => { :type => 'Numeric', :value => 123} }
99
105
  @app_test.method(:configure_parameters).call(test_params)
100
106
  @app_test.property.parameters[:p1][:default].must_be_kind_of String
101
107
  @app_test.property.parameters[:p1][:value].must_be_kind_of String
@@ -115,12 +121,12 @@ describe OmfRc::ResourceProxy::Application do
115
121
 
116
122
  it "must be able to detect incorrect type setting for a defined parameter, and DO NOT update the parameter in that case" do
117
123
  old_params = { :p1 => { :type => 'String', :value => 'foo'},
118
- :p2 => { :type => 'Numeric', :default => 123, :value => 456 },
119
- :p3 => { :type => 'Boolean', :default => true, :value => true} }
124
+ :p2 => { :type => 'Numeric', :default => 123, :value => 456 },
125
+ :p3 => { :type => 'Boolean', :default => true, :value => true} }
120
126
  @app_test.property.parameters = old_params
121
127
  new_params = { :p1 => { :type => 'String', :value => true},
122
- :p2 => { :type => 'Numeric', :default => 456, :value => '456' },
123
- :p3 => { :type => 'Boolean', :default => 123, :value => false} }
128
+ :p2 => { :type => 'Numeric', :default => 456, :value => '456' },
129
+ :p3 => { :type => 'Boolean', :default => 123, :value => false} }
124
130
  @app_test.stub :log_inform_error, nil do
125
131
  @app_test.method(:configure_parameters).call(new_params)
126
132
  end
@@ -134,11 +140,11 @@ describe OmfRc::ResourceProxy::Application do
134
140
  it "must update any valid dynamic parameter with the given value" do
135
141
  # set the parameter as dynamic
136
142
  params1 = { :p1 => { :cmd => '--foo', :default => 'old_foo', :dynamic => true},
137
- :p2 => { :cmd => '--notcalled', :dynamic => false} }
143
+ :p2 => { :cmd => '--notcalled', :dynamic => false} }
138
144
  @app_test.method(:configure_parameters).call(params1)
139
145
  # then update it
140
146
  params2 = { :p1 => { :value => 'bar'} , :p2 => { :value => 'abc'} }
141
- @app_test.property.state = :run
147
+ @app_test.property.state = :running
142
148
  class ExecApp
143
149
  def initialize(app_id, res, cmd_line, err_out_map); end
144
150
  def ExecApp.[](id); return ExecApp.new(nil,nil,nil,nil) end
@@ -151,40 +157,63 @@ describe OmfRc::ResourceProxy::Application do
151
157
 
152
158
  describe "when receiving an event from a running application instance" do
153
159
  it "must publish an INFORM message to relay that event" do
154
- @app_test.on_app_event('STDOUT', 'app_instance_id', 'Some text here').must_be_nil
155
- assert @app_test.comm.verify
160
+ @app_test.stub :inform, true do
161
+ @app_test.on_app_event('STDOUT', 'app_instance_id', 'Some text here').must_be_nil
162
+ end
156
163
  end
157
164
 
158
165
  it "must increments its event_sequence after publishig that INFORM message" do
159
- i = @app_test.property.event_sequence
160
- @app_test.on_app_event('STDOUT', 'app_instance_id', 'Some text here')
161
- @app_test.property.event_sequence.must_equal i+1
166
+ OmfCommon.stub :comm, @xmpp do
167
+ @app_test.stub :inform, true do
168
+ i = @app_test.property.event_sequence
169
+ @app_test.on_app_event('STDOUT', 'app_instance_id', 'Some text here')
170
+ @app_test.property.event_sequence.must_equal i+1
171
+ end
172
+ end
162
173
  end
163
174
 
164
- it "must switch its state to 'stop' if the event is of a type 'DONE'" do
165
- @app_test.on_app_event('DONE.OK', 'app_instance_id', 'Some text here')
166
- @app_test.request_state.to_sym.must_equal :stop
175
+ it "must switch its state to :completed if the event is of a type 'DONE' and the application is not installing itself" do
176
+ OmfCommon.stub :comm, @xmpp do
177
+ @app_test.stub :inform, true do
178
+ @app_test.on_app_event('DONE.OK', 'app_instance_id', 'Some text here')
179
+ @app_test.request_state.to_sym.must_equal :completed
180
+ end
181
+ end
182
+ OmfCommon.stub :comm, @xmpp do
183
+ @app_test.stub :inform, true do
184
+ @app_test.on_app_event('DONE.ERROR', 'app_instance_id', 'Some text here')
185
+ @app_test.request_state.to_sym.must_equal :completed
186
+ end
187
+ end
167
188
  end
168
189
 
169
- it "must set installed property to true if the event is 'DONE.OK' and the app_id's suffix is '_INSTALL'" do
170
- @app_test.on_app_event('DONE.OK', 'app_instance_id_INSTALL', 'Some text here')
171
- @app_test.request_state.to_sym.must_equal :stop
172
- @app_test.request_installed.must_equal true
190
+ it "must set installed property to true if the event is 'DONE.OK' and the application was installing itself" do
191
+ OmfCommon.stub :comm, @xmpp do
192
+ @app_test.stub :inform, true do
193
+ @app_test.on_app_event('DONE.OK', 'app_instance_id_INSTALL', 'Some text here')
194
+ @app_test.request_state.to_sym.must_equal :stopped
195
+ @app_test.request_installed.must_equal true
196
+ end
197
+ end
173
198
  end
174
199
  end
175
200
 
176
- describe "when configuring its state property to :install" do
177
- it "must do nothing if its original state is not :stop" do
178
- @app_test.property.state = :run
179
- @app_test.method(:configure_state).call(:install)
180
- @app_test.property.state.must_equal :run
201
+ describe "when configuring its state property to :installing" do
202
+ it "must do nothing if its original state is not :stopped" do
203
+ OmfCommon.stub :comm, @xmpp do
204
+ @app_test.property.state = :running
205
+ @app_test.method(:configure_state).call(:installing)
206
+ @app_test.property.state.must_equal :running
207
+ end
181
208
  end
182
209
 
183
- it "must do nothing if its original state is :stop and it is already installed" do
184
- @app_test.property.state = :stop
185
- @app_test.property.installed = true
186
- @app_test.method(:configure_state).call(:install)
187
- @app_test.property.state.must_equal :stop
210
+ it "must do nothing if its original state is :stopped and it is already installed" do
211
+ OmfCommon.stub :comm, @xmpp do
212
+ @app_test.property.state = :stopped
213
+ @app_test.property.installed = true
214
+ @app_test.method(:configure_state).call(:installing)
215
+ @app_test.property.state.must_equal :stopped
216
+ end
188
217
  end
189
218
 
190
219
  it "must use the tarball install method if it does not know its OS platform or if force_tarball_install is set" do
@@ -197,19 +226,19 @@ describe OmfRc::ResourceProxy::Application do
197
226
  end
198
227
  def call_configure
199
228
  @app_test.stub :install_tarball, @stub_tarball_tasks do
200
- @app_test.method(:configure_state).call(:install).must_equal :install
229
+ @app_test.method(:configure_state).call(:installing).must_equal :installing
201
230
  @did_call_install_tarball.must_equal true
202
231
  end
203
232
  end
204
233
  # Unknown Platform...
205
234
  @did_call_install_tarball = false
206
- @app_test.property.state = :stop
235
+ @app_test.property.state = :stopped
207
236
  @app_test.property.installed = false
208
237
  @app_test.property.platform = :unknown
209
238
  call_configure
210
239
  # Force Install Tarball...
211
240
  @did_call_install_tarball = false
212
- @app_test.property.state = :stop
241
+ @app_test.property.state = :stopped
213
242
  @app_test.property.installed = false
214
243
  @app_test.property.platform = :ubuntu
215
244
  @app_test.property.force_tarball_install = true
@@ -218,7 +247,7 @@ describe OmfRc::ResourceProxy::Application do
218
247
 
219
248
  it "must use the ubuntu install method if its OS platform is ubuntu" do
220
249
  @did_call_install_ubuntu = false
221
- @app_test.property.state = :stop
250
+ @app_test.property.state = :stopped
222
251
  @app_test.property.installed = false
223
252
  @app_test.property.platform = :ubuntu
224
253
  @app_test.property.pkg_ubuntu = 'foo'
@@ -227,14 +256,14 @@ describe OmfRc::ResourceProxy::Application do
227
256
  @did_call_install_ubuntu = true
228
257
  end
229
258
  @app_test.stub :install_ubuntu, @stub_ubuntu_tasks do
230
- @app_test.method(:configure_state).call(:install).must_equal :install
259
+ @app_test.method(:configure_state).call(:installing).must_equal :installing
231
260
  @did_call_install_ubuntu.must_equal true
232
261
  end
233
262
  end
234
263
 
235
264
  it "must use the fedora install method if its OS platform is fedora" do
236
265
  @did_call_install_fedora = false
237
- @app_test.property.state = :stop
266
+ @app_test.property.state = :stopped
238
267
  @app_test.property.installed = false
239
268
  @app_test.property.platform = :fedora
240
269
  @app_test.property.pkg_fedora = 'foo'
@@ -243,32 +272,38 @@ describe OmfRc::ResourceProxy::Application do
243
272
  @did_call_install_fedora = true
244
273
  end
245
274
  @app_test.stub :install_fedora, @stub_fedora_tasks do
246
- @app_test.method(:configure_state).call(:install).must_equal :install
275
+ @app_test.method(:configure_state).call(:installing).must_equal :installing
247
276
  @did_call_install_fedora.must_equal true
248
277
  end
249
278
  end
250
279
  end
251
280
 
252
- describe "when configuring its state property to :run" do
253
- it "must do nothing if its original state is :install" do
254
- @app_test.property.state = :install
255
- @app_test.method(:configure_state).call(:run)
256
- @app_test.property.state.must_equal :install
281
+ describe "when configuring its state property to :running" do
282
+ it "must do nothing if its original state is :installing" do
283
+ OmfCommon.stub :comm, @xmpp do
284
+ @app_test.property.state = :installing
285
+ @app_test.method(:configure_state).call(:running)
286
+ @app_test.property.state.must_equal :installing
287
+ end
257
288
  end
258
289
 
259
- it "must get back to the :run state if its original state is :pause" do
260
- @app_test.property.state = :pause
261
- @app_test.method(:configure_state).call(:run)
262
- @app_test.property.state.must_equal :run
290
+ it "must get back to the :running state if its original state is :paused" do
291
+ OmfCommon.stub :comm, @xmpp do
292
+ @app_test.property.state = :paused
293
+ @app_test.method(:configure_state).call(:running)
294
+ @app_test.property.state.must_equal :running
295
+ end
263
296
  end
264
297
 
265
298
  it "must do nothing if its binary path is not set" do
266
- @app_test.property.state = :stop
267
- @app_test.method(:configure_state).call(:run)
268
- @app_test.property.state.must_equal :stop
299
+ OmfCommon.stub :comm, @xmpp do
300
+ @app_test.property.state = :stopped
301
+ @app_test.method(:configure_state).call(:running)
302
+ @app_test.property.state.must_equal :stopped
303
+ end
269
304
  end
270
305
 
271
- it "must start an app using ExecApp and a correct command line if its original state is :stop" do
306
+ it "must start an app using ExecApp and a correct command line if its original state is :stopped" do
272
307
  class ExecApp
273
308
  def initialize(app_id, res, cmd_line, err_out_map)
274
309
  app_id.must_equal "an_application"
@@ -277,18 +312,18 @@ describe OmfRc::ResourceProxy::Application do
277
312
  err_out_map.must_equal false
278
313
  end
279
314
  end
280
- @app_test.property.state = :stop
315
+ @app_test.property.state = :stopped
281
316
  @app_test.property.binary_path = "my_cmd"
282
317
  test_env = { 'foo' => 123, 'bar_bar' => 'bar_123' }
283
318
  test_params = { :p1 => { :type => 'String', :mandatory => true, :cmd => '-param1', :default => 'foo', :value => 'bar', :order => 2},
284
- :p2 => { :type => 'Numeric', :mandatory => true, :default => 123, :order => 1 },
285
- :p3 => { :type => 'Boolean', :cmd => 'p3', :default => false, :value => true},
286
- :p4 => { :type => 'String', :default => 'hi', :value => 'hello'},
287
- :p5 => { :type => 'Numeric', :default => 456}, }
319
+ :p2 => { :type => 'Numeric', :mandatory => true, :default => 123, :order => 1 },
320
+ :p3 => { :type => 'Boolean', :cmd => 'p3', :default => false, :value => true},
321
+ :p4 => { :type => 'String', :default => 'hi', :value => 'hello'},
322
+ :p5 => { :type => 'Numeric', :default => 456}, }
288
323
  @app_test.method(:configure_environments).call(test_env)
289
324
  @app_test.method(:configure_parameters).call(test_params)
290
- @app_test.method(:configure_state).call(:run)
291
- @app_test.property.state.must_equal :run
325
+ @app_test.method(:configure_state).call(:running)
326
+ @app_test.property.state.must_equal :running
292
327
  end
293
328
 
294
329
  it "must start an app with OML command line options when use_oml parameter is set" do
@@ -297,14 +332,14 @@ describe OmfRc::ResourceProxy::Application do
297
332
  cmd_line.must_equal "env -i my_cmd --oml-config /tmp/bar.xml --oml-log-level 1 --oml-log-file foo "
298
333
  end
299
334
  end
300
- @app_test.property.state = :stop
335
+ @app_test.property.state = :stopped
301
336
  @app_test.property.binary_path = "my_cmd"
302
337
  @app_test.property.use_oml = true
303
338
  @app_test.property.oml_loglevel = 1
304
339
  @app_test.property.oml_logfile = "foo"
305
340
  @app_test.property.oml_configfile = "/tmp/bar.xml"
306
- File.stub(:exist?, true) { @app_test.method(:configure_state).call(:run) }
307
- @app_test.property.state.must_equal :run
341
+ File.stub(:exist?, true) { @app_test.method(:configure_state).call(:running) }
342
+ @app_test.property.state.must_equal :running
308
343
  end
309
344
 
310
345
  it "must start an app using its own built OML config when use_oml and oml parameters are set" do
@@ -315,61 +350,63 @@ describe OmfRc::ResourceProxy::Application do
315
350
  File.delete(xml_file)
316
351
  end
317
352
  end
318
- @app_test.property.state = :stop
353
+ @app_test.property.state = :stopped
319
354
  @app_test.property.binary_path = "my_cmd"
320
355
  @app_test.property.use_oml = true
321
356
  @app_test.property.oml = eval(fixture('oml.hash'))
322
- @app_test.method(:configure_state).call(:run)
323
- @app_test.property.state.must_equal :run
357
+ @app_test.method(:configure_state).call(:running)
358
+ @app_test.property.state.must_equal :running
324
359
  end
325
360
 
326
361
  it "must not use any oml options if use_oml is set but both oml or oml_config are not set" do
327
- class ExecApp
328
- def initialize(app_id, res, cmd_line, err_out_map)
329
- cmd_line.must_equal "env -i my_cmd "
362
+ OmfCommon.stub :comm, @xmpp do
363
+ class ExecApp
364
+ def initialize(app_id, res, cmd_line, err_out_map)
365
+ cmd_line.must_equal "env -i my_cmd "
366
+ end
330
367
  end
368
+ @app_test.property.state = :stopped
369
+ @app_test.property.binary_path = "my_cmd"
370
+ @app_test.property.use_oml = true
371
+ @app_test.method(:configure_state).call(:running)
372
+ @app_test.property.state.must_equal :running
331
373
  end
332
- @app_test.property.state = :stop
333
- @app_test.property.binary_path = "my_cmd"
334
- @app_test.property.use_oml = true
335
- @app_test.method(:configure_state).call(:run)
336
- @app_test.property.state.must_equal :run
337
374
  end
338
375
 
339
376
  end
340
377
 
341
- describe "when configuring its state property to :pause" do
342
- it "must do nothing if its original state is :stop or :install" do
343
- @app_test.property.state = :stop
344
- @app_test.method(:configure_state).call(:pause)
345
- @app_test.property.state.must_equal :stop
346
- @app_test.property.state = :install
347
- @app_test.method(:configure_state).call(:pause)
348
- @app_test.property.state.must_equal :install
378
+ describe "when configuring its state property to :paused" do
379
+ it "must do nothing if its original state is :stopped or :installing" do
380
+ @app_test.property.state = :stopped
381
+ @app_test.method(:configure_state).call(:paused)
382
+ @app_test.property.state.must_equal :stopped
383
+ @app_test.property.state = :installing
384
+ @app_test.method(:configure_state).call(:paused)
385
+ @app_test.property.state.must_equal :installing
349
386
  end
350
387
 
351
- it "must do switch its state to :pause if its original state is :run or :pause" do
352
- @app_test.property.state = :run
353
- @app_test.method(:configure_state).call(:pause)
354
- @app_test.property.state.must_equal :pause
355
- @app_test.property.state = :pause
356
- @app_test.method(:configure_state).call(:pause)
357
- @app_test.property.state.must_equal :pause
388
+ it "must do switch its state to :paused if its original state is :running or :paused" do
389
+ @app_test.property.state = :running
390
+ @app_test.method(:configure_state).call(:paused)
391
+ @app_test.property.state.must_equal :paused
392
+ @app_test.property.state = :paused
393
+ @app_test.method(:configure_state).call(:paused)
394
+ @app_test.property.state.must_equal :paused
358
395
  end
359
396
  end
360
397
 
361
- describe "when configuring its state property to :stop" do
362
- it "must do nothing if its original state is :stop or :install" do
363
- @app_test.property.state = :stop
364
- @app_test.method(:configure_state).call(:pause)
365
- @app_test.property.state.must_equal :stop
366
- @app_test.property.state = :install
367
- @app_test.method(:configure_state).call(:pause)
368
- @app_test.property.state.must_equal :install
398
+ describe "when configuring its state property to :stopped" do
399
+ it "must do nothing if its original state is :stopped or :installing" do
400
+ @app_test.property.state = :stopped
401
+ @app_test.method(:configure_state).call(:paused)
402
+ @app_test.property.state.must_equal :stopped
403
+ @app_test.property.state = :installing
404
+ @app_test.method(:configure_state).call(:paused)
405
+ @app_test.property.state.must_equal :installing
369
406
  end
370
407
 
371
- it "must stop its running application if its original state is :run or :pause" do
372
- @app_test.property.state = :run
408
+ it "must stop its running application if its original state is :running or :paused" do
409
+ @app_test.property.state = :running
373
410
  class ExecApp
374
411
  def initialize(app_id, res, cmd_line, err_out_map); end
375
412
  def ExecApp.[](id); return ExecApp.new(nil,nil,nil,nil) end
@@ -377,8 +414,8 @@ describe OmfRc::ResourceProxy::Application do
377
414
  def signal(sig); sig.must_equal 'TERM' end
378
415
  def kill(sig); sig.must_equal 'KILL' end
379
416
  end
380
- @app_test.method(:configure_state).call(:stop)
381
- @app_test.property.state.must_equal :stop
417
+ @app_test.method(:configure_state).call(:stopped)
418
+ @app_test.property.state.must_equal :completed
382
419
  end
383
420
  end
384
421
 
@@ -3,7 +3,12 @@ require 'omf_rc/resource_proxy/mock'
3
3
 
4
4
  describe OmfRc::ResourceProxy::Mock do
5
5
  before do
6
- @mock = OmfRc::ResourceFactory.new(:mock, hrn: 'mock_test')
6
+ @xmpp = MiniTest::Mock.new
7
+ @xmpp.expect(:subscribe, true, [Array])
8
+
9
+ OmfCommon.stub :comm, @xmpp do
10
+ @mock = OmfRc::ResourceFactory.new(:mock, hrn: 'mock_test')
11
+ end
7
12
  end
8
13
 
9
14
  describe "when included in the resource instance" do