# -*- coding: utf-8 -*-
# $Id: Backend.py 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
#
import traceback
import logging
# local imports
"""
Backend is the basic class of all backends. It implements an
XMLRPC server, which is waiting for test jobs.
Backend implementations should be derived from this class by implementing
the _process_execute method and defining their own input and test schema.
"""
# resourcestring
#ERROR_AUTH_FAILED = "Authorization failed"
# set in subclasses !!
schema = None
testSchema = None
"""
@params dict with all parameters which must be set for a backend
"""
try:
# set version from backend's version.txt
# write warn message, but do nothing else
#assert self.version != '', 'A valid version is required for this backend.'
# we use current machine’s IP address
self.url = 'http://%s:%d' % (socket.gethostbyname(socket.gethostname()), self.port) #(self.host, self.port))
'A input schema is required for this backend'
assert self.testSchema != None, \
'A test schema is required for this backend'
"Backend requires a correct 'spooler' option"
#assert self.auth and type(self.auth) == type({}), \
"Backend requires a correct 'auth' option"
# set spoolerID to None; it will be set if backend was successfully
# registered to a spooler
self._spoolerId = None
"""
"""
#self._server.register_function(self.getId)
#self._server.register_function(self.getName)
"""Registers the backend using the given spooler data.
"""
try:
return True
except Exception, e:
return False
"""
@see: AbstractServer._manageBeforeStop()
"""
try:
#traceback.print_exc()
#traceback.print_exc()
# -- public methods used by backendctl -------------------------------------
# xmlrpc
"""
Shutting down the backend. This method is called from spooler or
another client. Authentication is required.
@return: a tuple
"""
#return (-210, self.ERROR_AUTH_FAILED)
msg = "No such backend '%s' at '%s:%d'" % \
# start a new thread to stop the backend but let this method some time
# to return a value to the spooler or other calling client
"""
Returns a dictionary with some status information about
this backend. In case the authentication fails, a
AuthorizationFailedException will be raised.
@param: auth authorization information
@return: a dictionary with backendId, name, version, host, and port infos
"""
# FIXME: dirty hack!
#return(-210, self.ERROR_AUTH_FAILED)
msg = "No such backend '%s' at '%s:%d'" % \
return {
}
"""
Return the input schema defined for this backend.
@return: the input schema as string
"""
# FIXME: add authentification
"""
Return the test schema defined for this backend.
@return: the test schema as string
"""
# FIXME: add authentification
"""
Returns a dictionary where keys are the field names and the values
are all the properties defined by the input schema.
"""
# FIXME: add authentification
result = {}
#log.debug('Processing field: %s' % field)
#log.debug("Return value: %s" % result)
return result
"""
Returns a dictionary where keys are the ids and the values are the
label of all definied tests in testSchema.
"""
# FIXME: add authentification
result = {}
return result
"""
Call _process_execute which executes the job.
@param: authdata: authorization information
@param: jobdata: all relevant job data
@return: a dictionary with at least result value and message
"""
# check authentication
#return(-210, self.ERROR_AUTH_FAILED)
# create a test job with the given data
try:
# start testing
except Exception, e:
# -- methodes which must be overwritten in subclasses ---------------------
"""
Executes a test job with the given test data. This method must be
overridden in subclasses.
@param: job: a BackendJob object with all relevant test data
@return: a BackendResult object with at least result value and message
"""
raise NotImplementedError("Method 'process_execute' must be "
"implemented by subclass")
# -- internal or private methodes (used or overwritten in subclasses) -----
"""
@return: a list of test specifications depending on the ids given
in the job data
"""
result = []
#log.debug('job: %s' % job.getData())
# user has selected one or more tests
#else:
# # not tests selected by the user, taking all available
# result = self.testSchema.fields()
#log.debug('Following tests will be used %s: ' % result)
return result
"""
Checks the authorization information.
@return: True if given authorization data is valid, otherwise False.
"""
#return True
if self._spoolerId == None:
return False
return False
return True
return True
return False