base.runDetect(parent, detectionState)
# Assuming the base class check was successful, check this class
# If we've previosly checked this class, don't do it again
- if str(cls) in detectionState['checked']:
- if detectionState['checked'][str(cls)]:
+ if str(cls) in detectionState.checked.keys():
+ if detectionState.checked[str(cls)]:
# This has previously passed the test of a non-leaf OS class, so return None
return None
else:
except OSNotDetected, e:
xenrt.TEC().logverbose("OS is not %s - %s" % (str(cls), e.msg))
# If we can't detect this OS, raise an exception to terminate the hierarchy
- detectionState['checked'][str(cls)] = False
+ detectionState.checked[str(cls)] = False
raise
else:
- detectionState['checked'][str(cls)] = True
+ detectionState.checked[str(cls)] = True
return ret
return o(distro, parent, password)
raise xenrt.XRTError("No class found for distro %s" % distro)
+class DetectionState(object):
+ def __init__(self, password):
+ self.checked = {}
+ self.password = password
+
def osFromExisting(parent, password=None):
- detectionState = {"checked": {}, "password": password}
+ detectionState = DetectionState(password)
for o in oslist:
try:
ret = o.runDetect(parent, detectionState)
except OSNotDetected:
continue
else:
- xenrt.xrtAssert(ret)
+ xenrt.xrtAssert(ret, "No object returned for detected OS")
return ret
raise xenrt.XRTError("Could not determine OS")
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testdeb", parent, detectionState['password'])
+ obj=cls("testdeb", parent, detectionState.password)
if not obj.execSSH("test -e /etc/debian_version", retval="code") == 0:
raise OSNotDetected("OS is not debian")
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testdeb", parent, detectionState['password'])
+ obj=cls("testdeb", parent, detectionState.password)
isUbuntu = obj.execSSH("grep Ubuntu /etc/lsb-release", retval="code") == 0
if isUbuntu:
raise OSNotDetected("OS is Ubuntu")
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testdeb", parent, detectionState['password'])
+ obj=cls("testdeb", parent, detectionState.password)
isUbuntu = obj.execSSH("grep Ubuntu /etc/lsb-release", retval="code") == 0
if not isUbuntu:
raise OSNotDetected("OS is not Ubuntu")
@classmethod
def detect(cls, parent, detectionState):
- obj = cls("testlin", parent, detectionState['password'])
+ obj = cls("testlin", parent, detectionState.password)
try:
sock = socket.socket()
sock.settimeout(10)
except Exception, e:
raise OSNotDetected("OS appears not to have SSH: %s" % str(e))
else:
- detectionState['password'] = obj.password
+ detectionState.password = obj.password
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testrhel", parent, detectionState['password'])
+ obj=cls("testrhel", parent, detectionState.password)
if obj.execSSH("test -e /etc/xensource-inventory", retval="code") == 0:
raise OSNotDetected("OS is XenServer")
if not obj.execSSH("test -e /etc/redhat-release", retval="code") == 0:
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testrhel", parent, detectionState['password'])
+ obj=cls("testrhel", parent, detectionState.password)
if obj.execSSH("test -e /etc/centos-release", retval="code") == 0:
raise OSNotDetected("OS is CentOS")
if obj.execSSH("test -e /etc/oracle-release", retval="code") == 0:
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testcentos", parent, detectionState['password'])
+ obj=cls("testcentos", parent, detectionState.password)
if obj.execSSH("test -e /etc/centos-release", retval="code") != 0:
raise OSNotDetected("OS is not CentOS")
distro = obj.execSSH("cat /etc/centos-release | "
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testoel", parent, detectionState['password'])
+ obj=cls("testoel", parent, detectionState.password)
if obj.execSSH("test -e /etc/oracle-release", retval="code") != 0:
raise OSNotDetected("OS is not Oracle Linux")
distro = obj.execSSH("cat /etc/oracle-release | "
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testsuse", parent, detectionState['password'])
+ obj=cls("testsuse", parent, detectionState.password)
if not obj.execSSH("test -e /etc/SuSE-release", retval="code") == 0:
raise OSNotDetected("OS is not SuSE based")
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("testsuse", parent, detectionState['password'])
+ obj=cls("testsuse", parent, detectionState.password)
release = obj.execSSH("cat /etc/SuSE-release")
releaseMatch = re.search("VERSION = (\d+)", release)
@classmethod
def detect(cls, parent, detectionState):
- obj=cls("XSDom0", parent, detectionState['password'])
+ obj=cls("XSDom0", parent, detectionState.password)
if obj.execSSH("test -e /etc/xensource-inventory", retval="code") == 0:
return cls("XSDom0", parent, obj.password)
raise OSNotDetected("OS is not XenServer")