]> xenbits.xensource.com Git - xenrt-citrix/xenrt.git/commitdiff
Change detectionstate to be a class
authorJohn Dilley <john.dilley@citrix.com>
Thu, 29 Oct 2015 15:59:12 +0000 (15:59 +0000)
committerJohn Dilley <john.dilley@citrix.com>
Thu, 29 Oct 2015 15:59:12 +0000 (15:59 +0000)
exec/xenrt/lib/opsys/__init__.py
exec/xenrt/lib/opsys/debian.py
exec/xenrt/lib/opsys/linux.py
exec/xenrt/lib/opsys/rhel.py
exec/xenrt/lib/opsys/sles.py
exec/xenrt/lib/opsys/xs.py

index 089e4395d180a5821e65e9d87f43c2d17e8f44e3..4d2b9902d0431cc4e5e25042d13798a55e5a497c 100644 (file)
@@ -69,8 +69,8 @@ class OS(object):
             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:
@@ -82,10 +82,10 @@ class OS(object):
             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
         
 
@@ -117,15 +117,20 @@ def osFactory(distro, parent, password=None):
                 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")
 
index e4093081ca382d9a9b514095b820ca372248dc62..d64bb382ca124f69dffb5c5cacd66400b9d006f4 100644 (file)
@@ -176,7 +176,7 @@ class DebianBasedLinux(LinuxOS):
 
     @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")
 
@@ -207,7 +207,7 @@ class DebianLinux(DebianBasedLinux):
 
     @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")
@@ -243,7 +243,7 @@ class UbuntuLinux(DebianBasedLinux):
 
     @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")
index edf689ca442e2644281f0e47e2b7b8d7f966a5f9..ccd53e33a0ebee96d6da45dcd02b64aa939fbd42 100644 (file)
@@ -173,7 +173,7 @@ class LinuxOS(OS):
     
     @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)
@@ -183,4 +183,4 @@ class LinuxOS(OS):
         except Exception, e:
             raise OSNotDetected("OS appears not to have SSH: %s" % str(e))
         else:
-            detectionState['password'] = obj.password
+            detectionState.password = obj.password
index c34a8b556f8958f152cf725997cef03a165fb597..e5235a2d29ae89053563c45dc81f7cee9ee824cb 100644 (file)
@@ -172,7 +172,7 @@ class RHELBasedLinux(LinuxOS):
 
     @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:
@@ -198,7 +198,7 @@ class RHELLinux(RHELBasedLinux):
     
     @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:
@@ -238,7 +238,7 @@ class CentOSLinux(RHELBasedLinux):
 
     @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 | "
@@ -278,7 +278,7 @@ class OELLinux(RHELBasedLinux):
 
     @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 | "
index 72d8e960ea52114547603abf1bb13b154cc00c98..e0e3d2fd52368073dc5965b3c940319f185b042d 100644 (file)
@@ -163,7 +163,7 @@ class SLESBasedLinux(LinuxOS):
 
     @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")
 
@@ -186,7 +186,7 @@ class SLESLinux(SLESBasedLinux):
 
     @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)
index f7203bcfd9bee322af9e478b3ca79cd1afe433f5..486a6a5314d76184350e46fa7ebf39194a7b51d5 100644 (file)
@@ -28,7 +28,7 @@ class XSDom0(LinuxOS):
 
     @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")