Class: TDriver::SUTFactory
Class Method Summary collapse
-
.connected_suts ⇒ Object
TODO: document me.
-
.disconnect_sut(sut_attributes) ⇒ Object
TODO: document me.
-
.make(sut_attributes) ⇒ Object
Function to create the actual SUT objects based on the ‘sut’ attribute.
- .reboot_sut(sut_attributes) ⇒ Object
-
.reset ⇒ Object
Create/reset hash to store sut ids for all current suts.
Class Method Details
.connected_suts ⇒ Object
TODO: document me
159 160 161 162 163 |
# File 'lib/tdriver/base/sut/factory.rb', line 159 def self.connected_suts @_sut_list end |
.disconnect_sut(sut_attributes) ⇒ Object
TODO: document me
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tdriver/base/sut/factory.rb', line 134 def self.disconnect_sut( sut_attributes ) sut_id = retrieve_sut_id_from_hash( sut_attributes ) raise RuntimeError, "Unable disconnect SUT due to #{ sut_id.to_s } is not connected" unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ] @_sut_list[ sut_id ][ :sut ].disconnect @_sut_list[ sut_id ][ :is_connected ] = false end |
.make(sut_attributes) ⇒ Object
Function to create the actual SUT objects based on the ‘sut’ attribute.
params
- sut_type
-
sut_type - sut type, supportes all types defined by SUTFactory constants
- id
-
id - unique identifier for identifying particular SUT from each other. Is propagated to proper initializers.
returns
- return
-
SUT object
- raise
- ArgumentError
-
<name> not defined in TDriver parameters XML
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/tdriver/base/sut/factory.rb', line 173 def self.make( sut_attributes ) sut_id = retrieve_sut_id_from_hash( sut_attributes ) sut_id = get_mapped_sut( sut_id ) if mapped_sut?( sut_id ) # if sut is already connected, return existing sut return get_sut_from_list( sut_id ) if sut_exists?( sut_id ) # retrieve sut from parameters sut = $parameters[ sut_id, nil ] # raise exception if sut was not found raise ArgumentError, "#{ sut_id.to_s } not defined in TDriver parameters XML" if sut.nil? # retrieve sut type from parameters sut_type = sut[ :type, nil ] # raise exception if sut type was not found raise RuntimeError, "SUT parameter type not defined for #{ sut_id.to_s } in TDriver parameters/templates XML" if sut_type.nil? sut_type_symbol = sut_type.downcase.to_sym # retrieve plugin name that implements given sut sut_plugin = sut[ :sut_plugin, nil ] # retrieve enviroment value from sut, use '*' as default sut_env = sut[ :env, '*' ] # verify that sut plugin is defined in sut configuration raise RuntimeError, "SUT parameter 'sut_plugin' not defined for #{ sut_id.to_s } (#{ sut_type.to_s })" if sut_plugin.nil? # flag to determine that should exception be raised; allow one retry, then set flag to true if error still occures raise_exception = false begin # verify that sut plugin is registered if TDriver::PluginService.plugin_registered?( sut_plugin, :sut ) # create sut object created_sut = TDriver::PluginService.call_plugin_method( sut_plugin, :make_sut, sut_id ) else # raise error if sut was not registered raise NotImplementedError, "No plugin implementation found for SUT type: #{ sut_type }" end rescue Exception => exception # if sut was not registered, try to load it TDriver::PluginService.load_plugin( sut_plugin ) if exception.kind_of?( NotImplementedError ) if !raise_exception raise_exception = true retry else # still errors, raise original exception raise exception end end # store SUT type to sut object created_sut.instance_variable_set( :@ui_type, sut_type ) # store SUT UI version to sut object created_sut.instance_variable_set( :@ui_version, $parameters[ sut_id ][ :version, nil ] ) # store SUT input type to sut object created_sut.instance_variable_set( :@input, $parameters[ sut_id ][ :input_type, nil ] ) # retrieve list of optional extension plugins @extension_plugins = $parameters[ sut_id ][ :extension_plugins, "" ].split( ";" ) # load optional extension plugins if @extension_plugins.count > 0 @extension_plugins.each{ | plugin_name | raise_exception = false begin # verify that extension plugin is registered unless TDriver::PluginService.plugin_registered?( plugin_name, :extension ) # raise error if sut was not registered raise NotImplementedError, "Extension plugin not found #{ plugin_name }" end rescue Exception => exception # if sut was not registered, try to load it TDriver::PluginService.load_plugin( plugin_name ) if exception.kind_of?( NotImplementedError ) if !raise_exception raise_exception = true retry else # still errors, raise original exception raise exception end end } end # apply sut generic behaviours TDriver::BehaviourFactory.apply_behaviour( :object => created_sut, :object_type => [ 'sut' ], :sut_type => [ '*', created_sut.ui_type ], :input_type => [ '*', created_sut.input.to_s ], :env => [ '*', *sut_env.to_s.split(";") ], :version => [ '*', created_sut.ui_version.to_s ] ) @_sut_list[ sut_id ] = { :sut => created_sut, :is_connected => true } created_sut end |
.reboot_sut(sut_attributes) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/tdriver/base/sut/factory.rb', line 146 def self.reboot_sut( sut_attributes ) sut_id = retrieve_sut_id_from_hash( sut_attributes ) raise RuntimeError, "Unable to reboot SUT due to #{ sut_id.to_s } is not connected" unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ] @_sut_list[ sut_id ][ :sut ].reboot disconnect_sut( sut_id ) end |
.reset ⇒ Object
Create/reset hash to store sut ids for all current suts
127 128 129 130 131 |
# File 'lib/tdriver/base/sut/factory.rb', line 127 def self.reset @_sut_list = {} end |