00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 import sys, os
00038
00039 class WGTestStation(object):
00040 """
00041 Container class for WG test station configuration to operate qual system
00042 """
00043 def __init__(self):
00044 self._power_board = None
00045 self._breaker0 = False
00046 self._breaker1 = False
00047 self._breaker2 = False
00048
00049 self._gui_host = None
00050 self._test_host = None
00051
00052 self._envs = {}
00053
00054 def set_envs(self):
00055 """
00056 Set any environment variables specific to machine.
00057 """
00058 for k, v in self._envs.iteritems():
00059 os.environ[k] = v
00060
00061
00062 @property
00063 def gui_host(self): return self._gui_host
00064 @property
00065 def test_host(self): return self._test_host
00066
00067
00068 @property
00069 def powerboard(self):
00070 if self._power_board:
00071 return self._power_board
00072 return '0000'
00073 @property
00074 def breaker0(self): return self._breaker0
00075 @property
00076 def breaker1(self): return self._breaker1
00077 @property
00078 def breaker2(self): return self._breaker2
00079
00080 def xmlLoad(self, xmlDoc):
00081 """
00082 Load machine configuration from XML.
00083 Required parameters:
00084 "gui" - GUI machine. Must be full machine name
00085 "host" - Remote host name
00086 Optional:
00087 "powerboard" - SN of power board
00088 "breaker[0-2]" - Bool, to enable power breaker
00089 "env" - Tag <env name="FOO" value="bar" />
00090
00091 @param xmlDoc XML :
00092 """
00093 if not xmlDoc.attributes.has_key('gui'):
00094 print >> sys.stderr, "Unable to find attribute \"gui\" in XML doc for test station. XML: %s" % str(xmlDoc)
00095 return False
00096 self._gui_host = xmlDoc.attributes['gui'].value
00097
00098 if not xmlDoc.attributes.has_key('host'):
00099 print >> sys.stderr, "Unable to find attribute \"host\" in XML doc for test station. XML: %s" % str(xmlDoc)
00100 return False
00101 self._test_host = xmlDoc.attributes['host'].value
00102
00103 if xmlDoc.attributes.has_key('powerboard'):
00104 self._power_board = xmlDoc.attributes['powerboard'].value
00105 if not len(self._power_board) == 4 and unicode(self._power_board).isnumeric():
00106 print >> sys.stderr, "Power board entry is invalid. Must be four digits. Ex: \"1001\""
00107 return False
00108
00109 if self._power_board and xmlDoc.attributes.has_key('breaker0'):
00110 self._breaker0 = xmlDoc.attributes['breaker0'].value.lower() == 'true'
00111
00112 if self._power_board and xmlDoc.attributes.has_key('breaker1'):
00113 self._breaker1 = xmlDoc.attributes['breaker1'].value.lower() == 'true'
00114
00115 if self._power_board and xmlDoc.attributes.has_key('breaker2'):
00116 self._breaker2 = xmlDoc.attributes['breaker2'].value.lower() == 'true'
00117
00118 envs_xml = xmlDoc.getElementsByTagName('env')
00119 for env_xml in envs_xml:
00120 name = env_xml.attributes['name'].value
00121 value = env_xml.attributs['value'].value
00122
00123 self._envs[name] = value
00124
00125 return True
00126