Ejemplo n.º 1
0
def readSessionInfo(sessionID):
    iscsi_session = getIscsiSessionPath(sessionID)
    iscsi_connection = getIscsiConnectionPath(sessionID)

    if not os.path.isdir(iscsi_session) or not os.path.isdir(iscsi_connection):
        raise OSError(errno.ENOENT, "No such session")

    iqn = sysfs.read(os.path.join(iscsi_session, "targetname"), default="")
    iface = sysfs.read(os.path.join(iscsi_session, "ifacename"), default="")
    tpgt = sysfs.read_int(os.path.join(iscsi_session, "tpgt"))
    username = sysfs.read(os.path.join(iscsi_session, "username"), default="")
    password = sysfs.read_password(os.path.join(iscsi_session, "password"),
                                   default="")
    ip = sysfs.read(os.path.join(iscsi_connection, "persistent_address"),
                    default="")
    port = sysfs.read_int(os.path.join(iscsi_connection, "persistent_port"))

    # iscsi_host is available only when the session exists.
    iscsi_host = getIscsiHostPath(sessionID)
    netdev = sysfs.read(os.path.join(iscsi_host, "netdev"), default="")
    if netdev in ["<NULL>", "(null)"]:
        netdev = None

    iface = IscsiInterface(iface, netIfaceName=netdev)
    portal = IscsiPortal(ip, port)
    target = IscsiTarget(portal, tpgt, iqn)

    # NOTE: ChapCredentials must match the way we initialize username and
    # password when receiving request from engine in
    # hsm._connectionDict2ConnectionInfo().
    # iscsi reports empty user/password as "<NULL>" (RHEL5) or "(null)"
    # (RHEL6);  empty values are stored as None.

    if username in ["<NULL>", "(null)", ""]:
        username = None
    if password.value in ["<NULL>", "(null)", ""]:
        password = None
    cred = None
    if username or password:
        cred = ChapCredentials(username, password)

    return IscsiSession(sessionID, iface, target, cred)
Ejemplo n.º 2
0
 def test_read_str_error(self):
     with self.assertRaises(EnvironmentError):
         sysfs.read(os.getcwd())
Ejemplo n.º 3
0
 def test_read_str_missing_default(self):
     self.assertEqual(sysfs.read("/no/such/path", "default"), "default")
Ejemplo n.º 4
0
 def test_read_str_missing_no_default(self):
     with self.assertRaises(EnvironmentError):
         sysfs.read("/no/such/path")
Ejemplo n.º 5
0
 def test_read_str(self):
     with temporaryPath(data=b"value") as path:
         self.assertEqual(sysfs.read(path), "value")
Ejemplo n.º 6
0
 def test_read_str_strip(self):
     with temporaryPath(data=b" \t\n1\n2\n\t ") as path:
         self.assertEqual(sysfs.read(path), "1\n2")
Ejemplo n.º 7
0
 def test_read_str_error(self):
     with self.assertRaises(EnvironmentError):
         sysfs.read(os.getcwd())
Ejemplo n.º 8
0
 def test_read_str_missing_no_default(self):
     with self.assertRaises(EnvironmentError):
         sysfs.read("/no/such/path")
Ejemplo n.º 9
0
 def test_read_str_missing_default(self):
     self.assertEqual(sysfs.read("/no/such/path", "default"), "default")
Ejemplo n.º 10
0
 def test_read_str_strip(self):
     with temporaryPath(data=b" \t\n1\n2\n\t ") as path:
         self.assertEqual(sysfs.read(path), "1\n2")
Ejemplo n.º 11
0
 def test_read_str(self):
     with temporaryPath(data=b"value") as path:
         self.assertEqual(sysfs.read(path), "value")