omf_rc 6.0.3 → 6.0.4.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/omf_rc +30 -18
- data/bin/plc_trigger_omf_rc +80 -0
- data/lib/omf_rc/omf_error.rb +2 -0
- data/lib/omf_rc/resource_factory.rb +3 -14
- data/lib/omf_rc/resource_proxy/abstract_resource.rb +88 -56
- data/lib/omf_rc/resource_proxy/application.rb +1 -1
- data/lib/omf_rc/util/common_tools.rb +4 -5
- data/lib/omf_rc/util/ip.rb +1 -1
- data/lib/omf_rc/version.rb +1 -1
- data/omf_rc.gemspec +1 -1
- data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +30 -92
- data/test/omf_rc/resource_proxy/node_spec.rb +22 -26
- data/test/omf_rc/resource_proxy_dsl_spec.rb +37 -44
- data/test/omf_rc/util/common_tools_spec.rb +10 -9
- data/test/omf_rc/util/ip_spec.rb +8 -6
- data/test/omf_rc/util/iw_spec.rb +7 -5
- data/test/omf_rc/util/mod_spec.rb +19 -17
- data/test/test_helper.rb +43 -0
- metadata +11 -28
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGNiZjU5MGViODBjNTc1MDU0MDE3Y2ZmMzY0ZTA0YjQwMWY2MThkMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTFiYTZiYzQ0MzZiNjM1NDI1YTlhOTQ0MGZlZTEwYWUwMDlmNjU2MA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzFhMDI5ZTk5Zjg0YzY3NjI5YzIzMDNiMDYyNDFiYjc4YjIyNzkyNjk4NWNh
|
10
|
+
MjYwM2NmMzc3MzJmMTU5NDFkMzA0MTE0N2VhMTM4NjViZTMzY2JlZTE3OWMz
|
11
|
+
Y2ExOGE4ZmI5ZjI4YmYyYjgwOTY0M2UxZjNmOTdlN2YyMGE2OGM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGQ1OTExNjE5NjYwZjUxNTU4Njc2ZWNlOWVmODViZThlNThiMTNlN2YzOTZj
|
14
|
+
MWE2MjZmMDJmZjZjMDVhMzEwNGU3ZGVkNDEwMTM3Mzk5NzliZGRkNTU0OGE5
|
15
|
+
ODAzZGZhMmE4YjZhY2UxNzBhYjUwZWJkNzJhZjdkZWJmZmQzM2E=
|
data/bin/omf_rc
CHANGED
@@ -28,6 +28,10 @@ begin
|
|
28
28
|
options[:advanced_configfile] = file
|
29
29
|
end
|
30
30
|
|
31
|
+
opts.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
|
32
|
+
options[:logging_configfile] = file
|
33
|
+
end
|
34
|
+
|
31
35
|
opts.on("-u URI", "Communication URI (xmpp://user:password@domain)") do |uri|
|
32
36
|
options[:uri] = uri
|
33
37
|
end
|
@@ -87,23 +91,6 @@ unless common_options[:communication] && common_options[:communication][:url]
|
|
87
91
|
exit(1)
|
88
92
|
end
|
89
93
|
|
90
|
-
if options[:add_default_factories] != false
|
91
|
-
OmfRc::ResourceFactory.load_default_resource_proxies
|
92
|
-
end
|
93
|
-
|
94
|
-
if options[:factories]
|
95
|
-
options[:factories].each do |f|
|
96
|
-
if (req = f[:require])
|
97
|
-
begin
|
98
|
-
info "Try to load resource module '#{req}'"
|
99
|
-
require(req)
|
100
|
-
rescue LoadError => e
|
101
|
-
error e.message
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
94
|
if options[:auth]
|
108
95
|
if File.exist?(options[:auth][:entity_cert]) && File.exist?(options[:auth][:entity_key])
|
109
96
|
entity = OmfCommon::Auth::Certificate.create_from_x509(File.read(options[:auth][:entity_cert]),
|
@@ -114,6 +101,27 @@ end
|
|
114
101
|
common_options[:communication][:auth] = {} if entity
|
115
102
|
|
116
103
|
OmfCommon.init(options[:environment].to_sym, common_options) do |el|
|
104
|
+
# Load a customised logging set up if provided
|
105
|
+
OmfCommon.load_logging_config(options[:logging_configfile])
|
106
|
+
|
107
|
+
# Load extensions
|
108
|
+
if options[:add_default_factories] != false
|
109
|
+
OmfRc::ResourceFactory.load_default_resource_proxies
|
110
|
+
end
|
111
|
+
|
112
|
+
if options[:factories]
|
113
|
+
options[:factories].each do |f|
|
114
|
+
if (req = f[:require])
|
115
|
+
begin
|
116
|
+
info "Try to load resource module '#{req}'"
|
117
|
+
require(req)
|
118
|
+
rescue LoadError => e
|
119
|
+
error e.message
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
117
125
|
info "Starting OMF Resource Controller version '#{gem_version}'"
|
118
126
|
|
119
127
|
OmfCommon.comm.on_connected do |comm|
|
@@ -126,9 +134,12 @@ OmfCommon.init(options[:environment].to_sym, common_options) do |el|
|
|
126
134
|
|
127
135
|
options[:resources].each do |res_opts|
|
128
136
|
rtype = res_opts.delete(:type)
|
137
|
+
res_creation_opts = res_opts.delete(:creation_opts)
|
138
|
+
res_creation_opts ||= res_opts.delete(:create_opts)
|
139
|
+
res_creation_opts ||= {}
|
129
140
|
res_opts[:certificate] = entity if entity
|
130
141
|
begin
|
131
|
-
OmfRc::ResourceFactory.create(rtype, res_opts)
|
142
|
+
OmfRc::ResourceFactory.create(rtype, res_opts, res_creation_opts)
|
132
143
|
rescue => e
|
133
144
|
error "#{e.message}\n#{e.backtrace.join("\n")}"
|
134
145
|
end
|
@@ -137,3 +148,4 @@ OmfCommon.init(options[:environment].to_sym, common_options) do |el|
|
|
137
148
|
end
|
138
149
|
end
|
139
150
|
info "Stopping OMF Resource Controller version '#{gem_version}'"
|
151
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2013 National ICT Australia Limited (NICTA).
|
4
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
5
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
6
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
7
|
+
|
8
|
+
# This script is intended to be run by the PLE Node Manager:
|
9
|
+
# 1) after initial slice creation
|
10
|
+
# 2) after slice renewal
|
11
|
+
# to fetch the client, root and intermediate certificates for the OMF RC
|
12
|
+
|
13
|
+
require 'yaml'
|
14
|
+
|
15
|
+
curl="curl -s -m30"
|
16
|
+
|
17
|
+
puts "Running OMF PLE trigger script"
|
18
|
+
|
19
|
+
raise "Please use Ruby 1.9.3 or higher" if RUBY_VERSION < "1.9.3"
|
20
|
+
raise "You must run this script as root" unless Process.uid==0
|
21
|
+
raise "You must switch to gemset 'omf' and install the 'omf_rc' gem" unless system("which install_omf_rc > /dev/null")
|
22
|
+
|
23
|
+
def check_cert(file, text)
|
24
|
+
raise "Failed to #{text} (#{file})" unless File.exists?(file) and File.size?(file) > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
config_file = "/etc/omf_rc/config.yml"
|
28
|
+
init_script = "/etc/init.d/omf_rc"
|
29
|
+
csr = "/tmp/request.csr"
|
30
|
+
cert_server = "http://srv.mytestbed.net:4567/ple/"
|
31
|
+
|
32
|
+
# parse config file
|
33
|
+
raise "could not find #{config_file}" unless File.exists?(config_file)
|
34
|
+
config = YAML.load_file(config_file)
|
35
|
+
host = config[:hostname]
|
36
|
+
slice = config[:slicename]
|
37
|
+
raise "could not determine host name" unless host
|
38
|
+
raise "could not determine slice name" unless slice
|
39
|
+
root_cert_dir = config[:auth][:root_cert_dir]
|
40
|
+
entity_cert = config[:auth][:entity_cert]
|
41
|
+
entity_key = config[:auth][:entity_key]
|
42
|
+
raise ":root_cert_dir missing in config file" unless root_cert_dir
|
43
|
+
raise ":entity_cert missing in config file" unless entity_cert
|
44
|
+
raise "cannot find private key at #{entity_key}" unless File.exists?(entity_key)
|
45
|
+
Dir.mkdir(root_cert_dir) unless File.directory?(root_cert_dir)
|
46
|
+
|
47
|
+
# stop the RC
|
48
|
+
system "#{init_script} stop" if File.exists?(init_script)
|
49
|
+
system "sleep 2; pkill -f /bin/omf_rc"
|
50
|
+
|
51
|
+
# create CSR
|
52
|
+
puts "Generating CSR"
|
53
|
+
system "openssl req -subj /CN=#{slice}%#{host} -new -key #{entity_key} -out #{csr}"
|
54
|
+
check_cert(csr, "generate CSR")
|
55
|
+
|
56
|
+
# fetch client cert
|
57
|
+
puts "Fetching client cert"
|
58
|
+
system "#{curl} -F \"csr=@#{csr}\" -F \"slice=#{slice}\" -F \"resource=#{host}\" #{cert_server}resource/cert -o #{entity_cert}"
|
59
|
+
check_cert(entity_cert, "fetch client cert")
|
60
|
+
|
61
|
+
# fetch root cert
|
62
|
+
puts "Fetching root cert"
|
63
|
+
root_cert = "#{root_cert_dir}/root.crt"
|
64
|
+
system "#{curl} #{cert_server}root/cert -o #{root_cert}"
|
65
|
+
check_cert(root_cert, "fetch root cert")
|
66
|
+
|
67
|
+
# fetch intermediate cert
|
68
|
+
puts "Fetching intermediate cert"
|
69
|
+
intermediate_cert = "#{root_cert_dir}/intermediate.crt"
|
70
|
+
system "#{curl} #{cert_server}intermediate/cert -o #{intermediate_cert}"
|
71
|
+
check_cert(intermediate_cert, "fetch intermediate cert")
|
72
|
+
|
73
|
+
# install the init script if it doesn't exist yet
|
74
|
+
puts "Installing OMF init script"
|
75
|
+
system "install_omf_rc -i" unless File.exists?(init_script)
|
76
|
+
|
77
|
+
# start the RC
|
78
|
+
system "#{init_script} start"
|
79
|
+
|
80
|
+
puts "OMF PLE trigger script operation finished"
|
data/lib/omf_rc/omf_error.rb
CHANGED
@@ -26,21 +26,10 @@ class OmfRc::ResourceFactory
|
|
26
26
|
unless @@proxy_list.include?(type)
|
27
27
|
raise ArgumentError, "Resource type not found: #{type.to_s}" unless @@proxy_list.include?(type)
|
28
28
|
end
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
resource = OmfRc::ResourceProxy::AbstractResource.new(type, opts, creation_opts, &creation_callback)
|
33
|
-
# Extend newly created resource with proxy module
|
34
|
-
resource.extend(emodule)
|
35
|
-
|
36
|
-
# Initiate property hash
|
37
|
-
resource.methods.each do |m|
|
38
|
-
resource.__send__(m) if m =~ /default_property_(.+)/
|
29
|
+
# Create a new instance of abstract resource and return it
|
30
|
+
OmfRc::ResourceProxy::AbstractResource.new(type, opts, creation_opts) do |res|
|
31
|
+
creation_callback.call(res) if creation_callback
|
39
32
|
end
|
40
|
-
# Execute resource before_ready hook if any
|
41
|
-
call_hook(:before_ready, resource)
|
42
|
-
|
43
|
-
resource
|
44
33
|
end
|
45
34
|
|
46
35
|
alias :new :create
|
@@ -79,8 +79,8 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
79
79
|
create_children_resources: true
|
80
80
|
}
|
81
81
|
|
82
|
-
attr_accessor :uid, :hrn, :type, :
|
83
|
-
attr_reader :opts, :children, :membership, :creation_opts, :membership_topics
|
82
|
+
attr_accessor :uid, :hrn, :type, :property, :certificate
|
83
|
+
attr_reader :opts, :children, :membership, :creation_opts, :membership_topics, :topics
|
84
84
|
|
85
85
|
# Initialisation
|
86
86
|
#
|
@@ -89,7 +89,6 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
89
89
|
# @param [Hash] opts options to be initialised
|
90
90
|
# @option opts [String] :uid Unique identifier
|
91
91
|
# @option opts [String] :hrn Human readable name
|
92
|
-
# @option opts [Hash] :property A hash for keeping internal state
|
93
92
|
# @option opts [Hash] :instrument A hash for keeping instrumentation-related state
|
94
93
|
# @option opts [OmfCommon::Auth::Certificate] :certificate The certificate for this resource
|
95
94
|
#
|
@@ -104,15 +103,15 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
104
103
|
@creation_opts = Hashie::Mash.new(DEFAULT_CREATION_OPTS.merge(creation_opts))
|
105
104
|
|
106
105
|
@type = type
|
107
|
-
@uid = (@opts.uid || SecureRandom.uuid).to_s
|
108
|
-
@hrn = @opts.hrn
|
106
|
+
@uid = (@opts.delete(:uid) || SecureRandom.uuid).to_s
|
107
|
+
@hrn = @opts.delete(:hrn)
|
108
|
+
@hrn = @hrn.to_s if @hrn
|
109
109
|
|
110
|
-
@children
|
110
|
+
@children = []
|
111
111
|
@membership = []
|
112
112
|
@topics = []
|
113
|
-
@membership_topics
|
114
|
-
|
115
|
-
@property = Hashie::Mash.new(@opts.property)
|
113
|
+
@membership_topics = {}
|
114
|
+
@property = Hashie::Mash.new
|
116
115
|
|
117
116
|
OmfCommon.comm.subscribe(@uid) do |t|
|
118
117
|
@topics << t
|
@@ -121,40 +120,66 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
121
120
|
warn "Could not create topic '#{uid}', will shutdown, trying to clean up old topics. Please start it again once it has been shutdown."
|
122
121
|
OmfCommon.comm.disconnect()
|
123
122
|
else
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
123
|
+
begin
|
124
|
+
# Setup authentication related properties
|
125
|
+
if (@certificate = @opts.delete(:certificate))
|
126
|
+
OmfCommon::Auth::CertificateStore.instance.register(@certificate, t.address)
|
127
|
+
else
|
128
|
+
if (pcert = @opts.delete(:parent_certificate))
|
129
|
+
@certificate = pcert.create_for(resource_address, @type, t.address)
|
130
|
+
end
|
129
131
|
end
|
130
|
-
end
|
131
|
-
|
132
|
-
creation_callback.call(self) if creation_callback
|
133
|
-
|
134
|
-
copts = { src: self.resource_address }
|
135
|
-
copts[:cert] = @certificate.to_pem_compact if @certificate
|
136
|
-
|
137
|
-
cprops = @property.reject { |k| [:parent_certificate, :parent].include?(k.to_sym) }
|
138
|
-
cprops[:res_id] = self.resource_address
|
139
132
|
|
140
|
-
|
133
|
+
# Extend resource with Resource Module, can be obtained from Factory
|
134
|
+
emodule = OmfRc::ResourceFactory.proxy_list[@type].proxy_module || "OmfRc::ResourceProxy::#{@type.camelize}".constantize
|
135
|
+
self.extend(emodule)
|
136
|
+
# Initiate property hash with default property values
|
137
|
+
self.methods.each do |m|
|
138
|
+
self.__send__(m) if m =~ /default_property_(.+)/
|
139
|
+
end
|
140
|
+
# Bootstrap initial configure, this should handle membership too
|
141
|
+
init_configure(self, @opts)
|
142
|
+
# Execute resource before_ready hook if any
|
143
|
+
call_hook :before_ready, self
|
144
|
+
|
145
|
+
# Prepare init :creation_ok message
|
146
|
+
copts = { src: self.resource_address }
|
147
|
+
copts[:cert] = @certificate.to_pem_compact if @certificate
|
148
|
+
cprops = @property
|
149
|
+
cprops[:res_id] = self.resource_address
|
150
|
+
add_prop_status_to_response(self, @opts.keys, cprops)
|
151
|
+
|
152
|
+
# Then send inform message to itself, with all resource options' current values.
|
153
|
+
t.inform(:creation_ok, cprops, copts) unless creation_opts[:suppress_create_message]
|
154
|
+
|
155
|
+
t.on_message(@uid) do |imsg|
|
156
|
+
process_omf_message(imsg, t)
|
157
|
+
end
|
141
158
|
|
142
|
-
|
143
|
-
|
159
|
+
creation_callback.call(self) if creation_callback
|
160
|
+
rescue => e
|
161
|
+
error "Encountered exception: #{e.message}, returning ERROR message"
|
162
|
+
debug e.backtrace.join("\n")
|
163
|
+
t.inform(:creation_failed,
|
164
|
+
{ reason: e.message },
|
165
|
+
{ src: self.resource_address })
|
144
166
|
end
|
145
167
|
end
|
146
168
|
end
|
147
|
-
|
169
|
+
end
|
170
|
+
|
171
|
+
# Return resource' pubsub topic it has subscribed.
|
172
|
+
def resource_topic
|
173
|
+
if @topics.empty?
|
174
|
+
raise TopicNotSubscribedError, "Resource '#{@uid}' has not subscribed to any topics"
|
175
|
+
end
|
176
|
+
@topics[0]
|
148
177
|
end
|
149
178
|
|
150
179
|
# Return the public 'routable' address for this resource or nil if not known yet.
|
151
180
|
#
|
152
|
-
def resource_address
|
153
|
-
|
154
|
-
t.address
|
155
|
-
else
|
156
|
-
nil # TODO: should we raise Excaption
|
157
|
-
end
|
181
|
+
def resource_address
|
182
|
+
resource_topic.address
|
158
183
|
end
|
159
184
|
|
160
185
|
# Get binding of current object, used for ERB eval
|
@@ -183,9 +208,6 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
183
208
|
|
184
209
|
new_resource = OmfRc::ResourceFactory.create(type.to_sym, opts, creation_opts, &creation_callback)
|
185
210
|
|
186
|
-
new_props = opts.reject { |k| [:type, :name, :uid, :hrn, :property, :instrument].include?(k.to_sym) }
|
187
|
-
init_configure(new_resource, new_props)
|
188
|
-
|
189
211
|
call_hook(:after_create, self, new_resource)
|
190
212
|
|
191
213
|
self.synchronize do
|
@@ -442,13 +464,8 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
442
464
|
response[:res_id] = new_obj.resource_address
|
443
465
|
response[:uid] = new_obj.uid
|
444
466
|
|
445
|
-
|
446
|
-
|
447
|
-
response[key] = new_obj.__send__("request_#{key}")
|
448
|
-
elsif new_obj.respond_to? key
|
449
|
-
response[key] = new_obj.__send__(key)
|
450
|
-
end
|
451
|
-
end
|
467
|
+
# Getting property status, for preparing inform msg
|
468
|
+
add_prop_status_to_response(new_obj, msg_props.keys, response)
|
452
469
|
|
453
470
|
if (cred = new_obj.certificate)
|
454
471
|
response[:cert] = cred.to_pem_compact
|
@@ -531,13 +548,7 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
531
548
|
warn "INFORM message delayed as resource's address is not known yet"
|
532
549
|
return
|
533
550
|
end
|
534
|
-
if topic == :ALL
|
535
|
-
inform(itype, inform_data)
|
536
|
-
membership_topics.each {|m| inform(itype, inform_data, m[1])}
|
537
|
-
return
|
538
|
-
end
|
539
551
|
|
540
|
-
topic ||= @topics.first
|
541
552
|
if inform_data.is_a? Hash
|
542
553
|
inform_data = Hashie::Mash.new(inform_data) if inform_data.class == Hash
|
543
554
|
#idata = inform_data.dup
|
@@ -552,12 +563,11 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
552
563
|
|
553
564
|
message.itype = itype
|
554
565
|
unless itype == :released
|
555
|
-
#message[:uid] ||= self.uid
|
556
|
-
#message[:type] ||= self.type
|
557
566
|
message[:hrn] ||= self.hrn if self.hrn
|
558
567
|
end
|
559
568
|
|
560
|
-
|
569
|
+
# Just send to all topics, including group membership
|
570
|
+
(membership_topics.map { |mt| mt[1] } + @topics).each { |t| t.publish(message) }
|
561
571
|
|
562
572
|
OmfRc::ResourceProxy::MPPublished.inject(Time.now.to_f,
|
563
573
|
self.uid, replyto, inform_message.mid) if OmfCommon::Measure.enabled?
|
@@ -569,12 +579,17 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
569
579
|
|
570
580
|
def inform_error(reason)
|
571
581
|
error reason
|
572
|
-
inform :error, {reason: reason}
|
582
|
+
inform :error, { reason: reason }
|
583
|
+
end
|
584
|
+
|
585
|
+
def inform_creation_failed(reason)
|
586
|
+
error reason
|
587
|
+
inform :creation_failed, { reason: reason }
|
573
588
|
end
|
574
589
|
|
575
590
|
def inform_warn(reason)
|
576
591
|
warn reason
|
577
|
-
inform :warn, {reason: reason}
|
592
|
+
inform :warn, { reason: reason }
|
578
593
|
end
|
579
594
|
|
580
595
|
# Return a hash describing a reference to this object
|
@@ -591,11 +606,12 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
591
606
|
# @param [String] name of the topic
|
592
607
|
# @return [Array<OmfRc::ResourceProxy::AbstractResource>]
|
593
608
|
def objects_by_topic(name)
|
594
|
-
if name == uid || membership.include?(name)
|
609
|
+
if name == uid || membership.any? { |m| m.include?(name) }
|
595
610
|
objs = [self]
|
596
611
|
else
|
597
|
-
objs = children.find_all { |v| v.uid == name || v.membership.include?(name)}
|
612
|
+
objs = children.find_all { |v| v.uid == name || v.membership.any? { |m| m.include?(name) } }
|
598
613
|
end
|
614
|
+
objs
|
599
615
|
end
|
600
616
|
|
601
617
|
# Retrieve replyto address
|
@@ -644,4 +660,20 @@ class OmfRc::ResourceProxy::AbstractResource
|
|
644
660
|
|
645
661
|
call_hook(:after_initial_configured, res_ctx)
|
646
662
|
end
|
663
|
+
|
664
|
+
# Getting property status, adding them to inform message
|
665
|
+
#
|
666
|
+
# @param [OmfRc::ResourceProxy::AbstractResource] res_ctx resource object it applies to
|
667
|
+
# @param [Array] msg_props a set of property names coming via configure/create message
|
668
|
+
def add_prop_status_to_response(res_ctx, msg_props, response)
|
669
|
+
msg_props.each do |p|
|
670
|
+
# Property can either be defined as 'request' API call
|
671
|
+
# or just an internal variable, e.g. uid, hrn, etc.
|
672
|
+
if res_ctx.respond_to? "request_#{p}"
|
673
|
+
response[p] = res_ctx.__send__("request_#{p}")
|
674
|
+
elsif res_ctx.respond_to? p
|
675
|
+
response[p] = res_ctx.__send__(p)
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
647
679
|
end
|
@@ -475,7 +475,7 @@ module OmfRc::ResourceProxy::Application
|
|
475
475
|
# @return [String] the full command line
|
476
476
|
# @!macro work
|
477
477
|
work('build_command_line') do |res|
|
478
|
-
cmd_line = "env -i " # Start with a 'clean'
|
478
|
+
cmd_line = "env -i " # Start with a 'clean' environment
|
479
479
|
res.property.environments.each do |e,v|
|
480
480
|
val = v.kind_of?(String) ? "'#{v}'" : v
|
481
481
|
cmd_line += "#{e.to_s.upcase}=#{val} "
|
@@ -41,11 +41,10 @@ module OmfRc::Util::CommonTools
|
|
41
41
|
#
|
42
42
|
%w(error warn).each do |type|
|
43
43
|
work("log_inform_#{type}") do |res, msg|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
)
|
44
|
+
res.send(type, msg, res.uid)
|
45
|
+
res.topics.first.inform(type.to_sym,
|
46
|
+
{ reason: msg },
|
47
|
+
{ src: res.resource_address })
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
data/lib/omf_rc/util/ip.rb
CHANGED
@@ -45,7 +45,7 @@ module OmfRc::Util::Ip
|
|
45
45
|
# @!method configure_ip_addr
|
46
46
|
configure :ip_addr do |resource, value|
|
47
47
|
if value.nil? || value.split('/')[1].nil?
|
48
|
-
raise ArgumentError, "You need to provide
|
48
|
+
raise ArgumentError, "You need to provide a netmask with the IP address, e.g. #{value}/24. Got #{value}."
|
49
49
|
end
|
50
50
|
# Remove all ip addrs associated with the device
|
51
51
|
resource.flush_ip_addrs
|
data/lib/omf_rc/version.rb
CHANGED
data/omf_rc.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency "em-minitest-spec", "~> 1.1.1"
|
26
26
|
s.add_development_dependency "pry"
|
27
27
|
s.add_development_dependency "simplecov"
|
28
|
-
s.add_runtime_dependency "omf_common", "~> 6.0.
|
28
|
+
s.add_runtime_dependency "omf_common", "~> 6.0.4.pre.1"
|
29
29
|
s.add_runtime_dependency "cocaine", "~> 0.3.0"
|
30
30
|
s.add_runtime_dependency "mocha"
|
31
31
|
end
|
@@ -14,6 +14,7 @@ module OmfRc::ResourceProxy
|
|
14
14
|
include OmfRc::ResourceProxyDSL
|
15
15
|
register_proxy :parent
|
16
16
|
|
17
|
+
property :p0
|
17
18
|
request :test_exception do
|
18
19
|
raise StandardError
|
19
20
|
end
|
@@ -33,45 +34,13 @@ end
|
|
33
34
|
|
34
35
|
describe AbstractResource do
|
35
36
|
before do
|
36
|
-
|
37
|
-
|
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
|
61
|
-
end
|
62
|
-
|
63
|
-
OmfCommon.stubs(:comm).returns(@comm)
|
37
|
+
mock_comm_in_res_proxy
|
38
|
+
mock_topics_in_res_proxy(resources: [:parent, :child], default: :child)
|
64
39
|
@parent = OmfRc::ResourceFactory.create(:parent, { uid: :parent, hrn: 'default_node' }, { create_children_resources: true })
|
65
40
|
end
|
66
41
|
|
67
42
|
after do
|
68
|
-
|
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)
|
74
|
-
end
|
43
|
+
unmock_comm_in_res_proxy
|
75
44
|
@parent = nil
|
76
45
|
end
|
77
46
|
|
@@ -80,6 +49,12 @@ describe AbstractResource do
|
|
80
49
|
OmfRc::ResourceFactory.create(:parent).uid.must_match /.{8}-.{4}-.{4}-.{4}-.{12}/
|
81
50
|
end
|
82
51
|
|
52
|
+
it "must be able to initialise properties" do
|
53
|
+
p = OmfRc::ResourceFactory.create(:parent, { p0: 'bob', uid: 'unique' })
|
54
|
+
p.request_p0.must_equal 'bob'
|
55
|
+
p.request_uid.must_equal 'unique'
|
56
|
+
end
|
57
|
+
|
83
58
|
it "must be able to keep state inside 'property' instnace variable" do
|
84
59
|
@parent.property.bob = "test"
|
85
60
|
@parent.property.bob.must_equal "test"
|
@@ -90,9 +65,9 @@ describe AbstractResource do
|
|
90
65
|
end
|
91
66
|
|
92
67
|
it "must returned all the properties can be requested & configured" do
|
93
|
-
@parent.request_available_properties.configure.must_equal [:membership]
|
68
|
+
@parent.request_available_properties.configure.must_equal [:p0, :membership]
|
94
69
|
@parent.request_available_properties.request.must_equal(
|
95
|
-
[:test_exception, :supported_children_type, :uid, :type, :hrn, :name, :membership, :child_resources]
|
70
|
+
[:p0, :test_exception, :supported_children_type, :uid, :type, :hrn, :name, :membership, :child_resources]
|
96
71
|
)
|
97
72
|
end
|
98
73
|
|
@@ -134,66 +109,29 @@ describe AbstractResource do
|
|
134
109
|
end
|
135
110
|
|
136
111
|
describe "when interacted with communication layer" do
|
137
|
-
#include EM::MiniTest::Spec
|
138
|
-
|
139
|
-
before do
|
140
|
-
#@client = Blather::Client.new
|
141
|
-
#@stream = MiniTest::Mock.new
|
142
|
-
#@stream.expect(:send, true, [Blather::Stanza])
|
143
|
-
#@client.post_init @stream, Blather::JID.new('n@d/r')
|
144
|
-
#@xmpp = OmfCommon::Comm::XMPP::Communicator.new
|
145
|
-
end
|
146
|
-
|
147
112
|
it "must be able to send inform message" do
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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'))
|
160
|
-
end
|
161
|
-
|
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
|
165
|
-
end
|
166
|
-
|
167
|
-
it "must be able to connect & disconnect" do
|
168
|
-
skip
|
169
|
-
Blather::Client.stub :new, @client do
|
170
|
-
Blather::Stream::Client.stub(:start, @client) do
|
171
|
-
@parent = OmfRc::ResourceFactory.create(:node, { hrn: 'default_node', user: 'bob', password: 'pw', server: 'example.com'}, @xmpp)
|
172
|
-
@client.stub(:connected?, true) do
|
173
|
-
@parent.connect
|
174
|
-
@parent.comm.conn_info.must_equal({proto: :xmpp, user: 'bob', doamin: 'example.com'})
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
113
|
+
@parent.inform(:creation_ok, res_id: 'bob')
|
114
|
+
@parent.inform(:released, res_id: 'bob')
|
115
|
+
|
116
|
+
@parent.inform_status(key: 'value')
|
117
|
+
@parent.inform_warn('going to fail')
|
118
|
+
@parent.inform_error('failed')
|
119
|
+
@parent.inform_creation_failed('failed')
|
178
120
|
end
|
179
121
|
end
|
180
122
|
|
181
|
-
describe "when request/configure property not pre-defined in proxy" do
|
182
|
-
it "must try property hash" do
|
183
|
-
skip
|
123
|
+
describe "when request/configure property not pre-defined in proxy (adhoc)" do
|
124
|
+
it "must try property hash for internal usage" do
|
184
125
|
@parent.property[:bob] = "bob"
|
185
|
-
@parent.property[:
|
186
|
-
|
187
|
-
@parent.
|
188
|
-
|
189
|
-
|
190
|
-
@parent.request_bob.must_equal "bob"
|
191
|
-
@parent.request_false.must_equal false
|
126
|
+
@parent.property[:boolean] = false
|
127
|
+
@parent.property.bob.must_equal "bob"
|
128
|
+
@parent.property.boolean.must_equal false
|
129
|
+
end
|
192
130
|
|
193
|
-
|
194
|
-
@parent.
|
195
|
-
|
196
|
-
proc { @parent.
|
131
|
+
it "wont create request/configure method for such property" do
|
132
|
+
@parent.methods.wont_include :request_bob
|
133
|
+
@parent.methods.wont_include :configure_bob
|
134
|
+
proc { @parent.request_bob }.must_raise NoMethodError
|
197
135
|
end
|
198
136
|
end
|
199
137
|
|
@@ -209,7 +147,7 @@ describe AbstractResource do
|
|
209
147
|
@parent.process_omf_message(@request_msg, @topics[:parent])
|
210
148
|
end
|
211
149
|
|
212
|
-
it "must
|
150
|
+
it "must rescue exception if occurred" do
|
213
151
|
@parent.process_omf_message(OmfCommon::Message.create(:request, { test_exception: nil }), @topics[:parent])
|
214
152
|
end
|
215
153
|
|
@@ -8,12 +8,14 @@ require 'omf_rc/resource_proxy/node'
|
|
8
8
|
|
9
9
|
describe OmfRc::ResourceProxy::Node do
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
11
|
+
mock_comm_in_res_proxy
|
12
|
+
mock_topics_in_res_proxy(resources: [:n0, :app_test], default: :n0)
|
13
|
+
@node = OmfRc::ResourceFactory.create(:node, { uid: :n0, hrn: 'node_test'})
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
after do
|
17
|
+
unmock_comm_in_res_proxy
|
18
|
+
@node = nil
|
17
19
|
end
|
18
20
|
|
19
21
|
describe "when included in the resource instance" do
|
@@ -46,32 +48,26 @@ describe OmfRc::ResourceProxy::Node do
|
|
46
48
|
end
|
47
49
|
|
48
50
|
it "must provide a list of created applications" do
|
49
|
-
|
50
|
-
@xmpp.expect(:subscribe, true, [String])
|
51
|
-
@node.create(:application, { :uid => 'app_test', :hrn => 'app_test' })
|
51
|
+
@node.create(:application, { uid: 'app_test', hrn: 'app_test' })
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
53
|
+
@node.request_applications.must_equal [
|
54
|
+
{ name: 'app_test', type: :application, uid: 'app_test' }
|
55
|
+
]
|
57
56
|
end
|
58
57
|
|
59
58
|
it "must provide a list of created interfaces" do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@node.
|
66
|
-
|
67
|
-
@node.create(:wlan, { :uid => 'wlan0', :if_name => 'wlan0' })
|
68
|
-
@node.create(:net, { :uid => 'eth0', :if_name => 'eth0' })
|
59
|
+
devices = [
|
60
|
+
{ name: 'eth0', driver: 'e1000e', category: 'net', proxy: 'net' },
|
61
|
+
{ name: 'phy0', driver: 'iwlwifi', category: 'net', subcategory: 'wlan', proxy: 'wlan' }
|
62
|
+
]
|
63
|
+
@node.stub :request_devices, devices do
|
64
|
+
@node.create(:wlan, { :uid => 'wlan0', :if_name => 'wlan0' })
|
65
|
+
@node.create(:net, { :uid => 'eth0', :if_name => 'eth0' })
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
67
|
+
@node.request_interfaces.must_equal [
|
68
|
+
{ name: 'eth0', type: :net, uid: 'eth0' },
|
69
|
+
{ name: 'wlan0', type: :wlan, uid: 'wlan0' }
|
70
|
+
]
|
75
71
|
end
|
76
72
|
end
|
77
73
|
end
|
@@ -8,8 +8,8 @@ require 'omf_rc/resource_proxy_dsl'
|
|
8
8
|
|
9
9
|
describe OmfRc::ResourceProxyDSL do
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
11
|
+
mock_comm_in_res_proxy
|
12
|
+
mock_topics_in_res_proxy(resources: [:mp0, :mrp0, :up0])
|
13
13
|
|
14
14
|
module OmfRc::Util::MockUtility
|
15
15
|
include OmfRc::ResourceProxyDSL
|
@@ -71,31 +71,33 @@ describe OmfRc::ResourceProxyDSL do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
after do
|
75
|
+
unmock_comm_in_res_proxy
|
76
|
+
end
|
77
|
+
|
74
78
|
describe "when included by modules to define resource proxy functionalities" do
|
75
79
|
it "must be able to register the modules" do
|
76
80
|
OmfRc::ResourceFactory.proxy_list.must_include :mock_proxy
|
77
81
|
end
|
78
82
|
|
79
83
|
it "must be able to define methods" do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
+
%w(configure_alpha request_alpha bravo).each do |m|
|
85
|
+
OmfRc::Util::MockUtility.method_defined?(m.to_sym).must_equal true
|
86
|
+
end
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
%w(configure_alpha request_alpha before_ready before_release bravo).each do |m|
|
89
|
+
OmfRc::ResourceProxy::MockProxy.method_defined?(m.to_sym).must_equal true
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
mock_proxy.bravo("something", "something else").must_equal "something"
|
97
|
-
mock_proxy.request_zulu(country: 'uk').must_equal "You called zulu with: country"
|
92
|
+
mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy, uid: :mp0)
|
93
|
+
mock_proxy.request_alpha.must_equal mock_proxy.uid
|
94
|
+
mock_proxy.request_delta.must_equal "printing"
|
95
|
+
mock_proxy.request_charlie.must_equal "working on printing"
|
96
|
+
mock_proxy.bravo("magic", "second parameter") do |v|
|
97
|
+
v.must_equal "working on magic"
|
98
98
|
end
|
99
|
+
mock_proxy.bravo("something", "something else").must_equal "something"
|
100
|
+
mock_proxy.request_zulu(country: 'uk').must_equal "You called zulu with: country"
|
99
101
|
end
|
100
102
|
|
101
103
|
it "must be able to include utility" do
|
@@ -116,39 +118,30 @@ describe OmfRc::ResourceProxyDSL do
|
|
116
118
|
end
|
117
119
|
|
118
120
|
it "must check new proxy's create_by option when ask a proxy create a new proxy" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
2.times { @xmpp.expect(:subscribe, true, [String]) }
|
123
|
-
OmfRc::ResourceFactory.create(:mock_root_proxy).create(:useless_proxy)
|
124
|
-
2.times { @xmpp.expect(:subscribe, true, [String]) }
|
125
|
-
lambda { OmfRc::ResourceFactory.create(:useless_proxy).create(:mock_proxy) }.must_raise StandardError
|
126
|
-
end
|
121
|
+
OmfRc::ResourceFactory.create(:mock_root_proxy, uid: :mrp0).create(:mock_proxy, uid: :mp0)
|
122
|
+
OmfRc::ResourceFactory.create(:mock_root_proxy, uid: :mrp0).create(:useless_proxy, uid: :up0)
|
123
|
+
lambda { OmfRc::ResourceFactory.create(:useless_proxy, uid: :mrp0).create(:mock_proxy, uid: :mp0) }.must_raise StandardError
|
127
124
|
end
|
128
125
|
|
129
126
|
it "must be able to define property with default vlaue" do
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
mock_proxy.request_mock_prop.must_equal 2
|
136
|
-
end
|
127
|
+
mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy, uid: :mp0)
|
128
|
+
mock_proxy.property.mock_prop.must_equal 1
|
129
|
+
mock_proxy.request_mock_prop.must_equal 1
|
130
|
+
mock_proxy.configure_mock_prop(2)
|
131
|
+
mock_proxy.request_mock_prop.must_equal 2
|
137
132
|
end
|
138
133
|
|
139
134
|
|
140
135
|
it "must define associate methods when access option given to property definition" do
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
lambda { mock_proxy.configure_init_only_prop }.must_raise NoMethodError
|
151
|
-
end
|
136
|
+
mock_proxy = OmfRc::ResourceFactory.create(:mock_proxy, uid: :mp0)
|
137
|
+
# Ready only
|
138
|
+
mock_proxy.request_read_only_prop.must_equal 1
|
139
|
+
lambda { mock_proxy.init_read_only_prop }.must_raise NoMethodError
|
140
|
+
lambda { mock_proxy.configure_read_only_prop }.must_raise NoMethodError
|
141
|
+
# Init only
|
142
|
+
mock_proxy.request_init_only_prop.must_equal 1
|
143
|
+
lambda { mock_proxy.init_init_only_prop }.must_raise NoMethodError
|
144
|
+
lambda { mock_proxy.configure_init_only_prop }.must_raise NoMethodError
|
152
145
|
end
|
153
146
|
end
|
154
147
|
end
|
@@ -7,7 +7,7 @@ require 'test_helper'
|
|
7
7
|
require 'omf_rc/util/common_tools'
|
8
8
|
|
9
9
|
describe OmfRc::Util::CommonTools do
|
10
|
-
|
10
|
+
|
11
11
|
describe "when included in the resource proxy" do
|
12
12
|
before do
|
13
13
|
module OmfRc::ResourceProxy::Test
|
@@ -15,18 +15,19 @@ describe OmfRc::Util::CommonTools do
|
|
15
15
|
register_proxy :test
|
16
16
|
utility :common_tools
|
17
17
|
end
|
18
|
+
mock_comm_in_res_proxy
|
19
|
+
mock_topics_in_res_proxy(resources: [:t0])
|
20
|
+
@test = OmfRc::ResourceFactory.create(:test, uid: :t0)
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
after do
|
24
|
+
unmock_comm_in_res_proxy
|
25
|
+
@test = nil
|
21
26
|
end
|
22
27
|
|
23
28
|
it "must be able to log and inform error/warn messages" do
|
24
|
-
|
25
|
-
|
26
|
-
2.times { @xmpp.expect(:publish, true, [String, OmfCommon::Message]) }
|
27
|
-
@test.log_inform_error "bob"
|
28
|
-
@test.log_inform_warn "bob"
|
29
|
-
end
|
29
|
+
@test.log_inform_error "bob"
|
30
|
+
@test.log_inform_warn "bob"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
data/test/omf_rc/util/ip_spec.rb
CHANGED
@@ -17,14 +17,16 @@ describe OmfRc::Util::Ip do
|
|
17
17
|
utility :ip
|
18
18
|
end
|
19
19
|
|
20
|
-
@xmpp = MiniTest::Mock.new
|
21
|
-
@xmpp.expect(:subscribe, true, [String])
|
22
|
-
|
23
20
|
@command = MiniTest::Mock.new
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
mock_comm_in_res_proxy
|
23
|
+
mock_topics_in_res_proxy(resources: [:w00])
|
24
|
+
@wlan00 = OmfRc::ResourceFactory.create(:ip_test, uid: :w00, hrn: 'wlan00')
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
unmock_comm_in_res_proxy
|
29
|
+
@wlan00 = nil
|
28
30
|
end
|
29
31
|
|
30
32
|
it "must provide features defined in proxy" do
|
data/test/omf_rc/util/iw_spec.rb
CHANGED
@@ -29,12 +29,14 @@ Cocaine::CommandLine.stub(:new, @command) do
|
|
29
29
|
property :phy
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
mock_comm_in_res_proxy
|
33
|
+
mock_topics_in_res_proxy(resources: [:w00])
|
34
|
+
@wlan00 = OmfRc::ResourceFactory.create(:iw_test, uid: :w00, hrn: 'wlan00', phy: 'phy00', if_name: 'wlan1')
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
after do
|
38
|
+
unmock_comm_in_res_proxy
|
39
|
+
@wlan00 = nil
|
38
40
|
end
|
39
41
|
|
40
42
|
it "must provide features defined in proxy" do
|
@@ -15,30 +15,32 @@ describe OmfRc::Util::Mod do
|
|
15
15
|
utility :mod
|
16
16
|
end
|
17
17
|
@command = MiniTest::Mock.new
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
mock_comm_in_res_proxy
|
20
|
+
mock_topics_in_res_proxy(resources: [:mt0])
|
21
|
+
@mod_test = OmfRc::ResourceFactory.create(:mod_test, uid: :mt0)
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
unmock_comm_in_res_proxy
|
26
|
+
@mod_test = nil
|
20
27
|
end
|
21
28
|
|
22
29
|
it "will find out a list of modules" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
OmfRc::ResourceFactory.create(:mod_test).request_modules.wont_include "Module"
|
30
|
-
@command.verify
|
31
|
-
end
|
30
|
+
Cocaine::CommandLine.stub(:new, @command) do
|
31
|
+
@command.expect(:run, fixture("lsmod"))
|
32
|
+
@mod_test.request_modules.must_include "kvm"
|
33
|
+
@command.expect(:run, fixture("lsmod"))
|
34
|
+
@mod_test.request_modules.wont_include "Module"
|
35
|
+
@command.verify
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
39
|
it "could load a module" do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@command.verify
|
41
|
-
end
|
40
|
+
Cocaine::CommandLine.stub(:new, @command) do
|
41
|
+
@command.expect(:run, true)
|
42
|
+
@mod_test.configure_load_module(name: 'magic_module').must_equal "magic_module loaded"
|
43
|
+
@command.verify
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
data/test/test_helper.rb
CHANGED
@@ -25,5 +25,48 @@ def fixture(name)
|
|
25
25
|
File.read("#{FIXTURE_DIR}/#{name.to_s}")
|
26
26
|
end
|
27
27
|
|
28
|
+
def mock_comm_in_res_proxy
|
29
|
+
@comm = mock
|
30
|
+
|
31
|
+
[:inform, :publish, :unsubscribe].each do |m_name|
|
32
|
+
OmfCommon::Comm::Topic.any_instance.stubs(m_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
@comm.class_eval do
|
36
|
+
define_method(:subscribe) do |*args, &block|
|
37
|
+
block.call(self.create_topic("xmpp://localhost/#{args[0]}"))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
OmfCommon.stubs(:comm).returns(@comm)
|
42
|
+
end
|
43
|
+
|
44
|
+
def mock_topics_in_res_proxy(options)
|
45
|
+
@topics = {}.tap do |hash|
|
46
|
+
options[:resources].each do |r|
|
47
|
+
hash[r] = OmfCommon::Comm::Topic.create(:parent)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if (default_r = options[:default]) && options[:resources].include?(default_r)
|
52
|
+
# Return default topic unless specified
|
53
|
+
@comm.stubs(:create_topic).returns(@topics[default_r])
|
54
|
+
end
|
55
|
+
options[:resources].each do |t_name|
|
56
|
+
@topics[t_name].stubs(:address).returns("xmpp://localhost/#{t_name.to_s}")
|
57
|
+
@comm.stubs(:create_topic).with("xmpp://localhost/#{t_name}").returns(@topics[t_name])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def unmock_comm_in_res_proxy
|
62
|
+
@comm.class_eval do
|
63
|
+
undef_method(:subscribe)
|
64
|
+
end
|
65
|
+
OmfCommon.unstub(:comm)
|
66
|
+
[:inform, :publish, :unsubscribe].each do |m_name|
|
67
|
+
OmfCommon::Comm::Topic.any_instance.unstub(m_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
28
71
|
OmfCommon::Message.init(type: :xml)
|
29
72
|
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_rc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
5
|
-
prerelease:
|
4
|
+
version: 6.0.4.pre.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- NICTA
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: em-minitest-spec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pry
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,23 +69,20 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: omf_common
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version: 6.0.
|
75
|
+
version: 6.0.4.pre.1
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ~>
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version: 6.0.
|
82
|
+
version: 6.0.4.pre.1
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: cocaine
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ~>
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ~>
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -110,7 +97,6 @@ dependencies:
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: mocha
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
101
|
- - ! '>='
|
116
102
|
- !ruby/object:Gem::Version
|
@@ -118,7 +104,6 @@ dependencies:
|
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
108
|
- - ! '>='
|
124
109
|
- !ruby/object:Gem::Version
|
@@ -130,6 +115,7 @@ email:
|
|
130
115
|
executables:
|
131
116
|
- install_omf_rc
|
132
117
|
- omf_rc
|
118
|
+
- plc_trigger_omf_rc
|
133
119
|
extensions: []
|
134
120
|
extra_rdoc_files: []
|
135
121
|
files:
|
@@ -138,6 +124,7 @@ files:
|
|
138
124
|
- Rakefile
|
139
125
|
- bin/install_omf_rc
|
140
126
|
- bin/omf_rc
|
127
|
+
- bin/plc_trigger_omf_rc
|
141
128
|
- config/config.yml
|
142
129
|
- config/config_with_authentication.yml.example
|
143
130
|
- config/config_with_extensions.yml.example
|
@@ -200,29 +187,25 @@ files:
|
|
200
187
|
homepage: http://omf.mytestbed.net
|
201
188
|
licenses:
|
202
189
|
- MIT
|
190
|
+
metadata: {}
|
203
191
|
post_install_message:
|
204
192
|
rdoc_options: []
|
205
193
|
require_paths:
|
206
194
|
- lib
|
207
195
|
required_ruby_version: !ruby/object:Gem::Requirement
|
208
|
-
none: false
|
209
196
|
requirements:
|
210
197
|
- - ! '>='
|
211
198
|
- !ruby/object:Gem::Version
|
212
199
|
version: 1.9.3
|
213
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
-
none: false
|
215
201
|
requirements:
|
216
|
-
- - ! '
|
202
|
+
- - ! '>'
|
217
203
|
- !ruby/object:Gem::Version
|
218
|
-
version:
|
219
|
-
segments:
|
220
|
-
- 0
|
221
|
-
hash: 4426195785601747847
|
204
|
+
version: 1.3.1
|
222
205
|
requirements: []
|
223
206
|
rubyforge_project: omf_rc
|
224
|
-
rubygems_version:
|
207
|
+
rubygems_version: 2.0.7
|
225
208
|
signing_key:
|
226
|
-
specification_version:
|
209
|
+
specification_version: 4
|
227
210
|
summary: OMF resource controller
|
228
211
|
test_files: []
|