Beispiel #1
0
    def test_eq_subclass(self):
        class Subclass(iscsi.ChapCredentials):
            pass

        c1 = iscsi.ChapCredentials("username", protected("password"))
        c2 = Subclass("username", protected("password"))
        self.assertFalse(c1 == c2, "%s should not equal %s" % (c1, c2))
Beispiel #2
0
    def test_subclass_different_hash(self):
        class Subclass(iscsi.ChapCredentials):
            pass

        c1 = iscsi.ChapCredentials("username", protected("password"))
        c2 = Subclass("username", protected("password"))
        self.assertNotEqual(hash(c1), hash(c2))
Beispiel #3
0
 def test_eq_different(self, user1, user2, pass1, pass2):
     c1 = iscsi.ChapCredentials(user1, protected(pass1))
     c2 = iscsi.ChapCredentials(user2, protected(pass2))
     self.assertFalse(c1 == c2, "%s should not equal %s" % (c1, c2))
Beispiel #4
0
 def test_eq_equal(self, username, password):
     c1 = iscsi.ChapCredentials(username, protected(password))
     c2 = iscsi.ChapCredentials(username, protected(password))
     self.assertTrue(c1 == c2, "%s should equal %s" % (c1, c2))
Beispiel #5
0
 def test_not_equal_different_hash(self, user1, user2, pass1, pass2):
     c1 = iscsi.ChapCredentials(user1, protected(pass1))
     c2 = iscsi.ChapCredentials(user2, protected(pass2))
     self.assertNotEqual(hash(c1), hash(c2))
Beispiel #6
0
 def test_equal_same_hash(self, username, password):
     c1 = iscsi.ChapCredentials(username, protected(password))
     c2 = iscsi.ChapCredentials(username, protected(password))
     self.assertEqual(hash(c1), hash(c2))
Beispiel #7
0
def _connectionDict2ConnectionInfo(conTypeId, conDict):
    def getIntParam(optDict, key, default):
        res = optDict.get(key, default)
        if res is None:
            return res

        try:
            return int(res)
        except ValueError:
            raise se.InvalidParameterException(key, res)

    # FIXME: Remove when nfs_mount_options is no longer supported.  This is
    # in the compatibility layer so that the NFSConnection class stays clean.
    # Engine options have precendence, so use deprecated nfs_mount_options
    # only if engine passed nothing (indicated by default params of 'None').
    def tryDeprecatedNfsParams(conDict):
        if (conDict.get('protocol_version',
                        None), conDict.get('retrans', None),
                conDict.get('timeout', None)) == (None, None, None):
            conf_options = config.get('irs',
                                      'nfs_mount_options').replace(' ', '')
            if (frozenset(conf_options.split(',')) != frozenset(
                    NFSConnection.DEFAULT_OPTIONS)):
                logging.warning(
                    "Using deprecated nfs_mount_options from"
                    " vdsm.conf to mount %s: %s",
                    conDict.get('connection', '(unknown)'), conf_options)
                return PosixFsConnectionParameters(
                    conDict["id"], conDict.get('connection', None), 'nfs',
                    conf_options)
        return None

    typeName = CON_TYPE_ID_2_CON_TYPE[conTypeId]
    if typeName == 'localfs':
        params = LocaFsConnectionParameters(conDict["id"],
                                            conDict.get('connection', None))
    elif typeName == 'nfs':
        params = tryDeprecatedNfsParams(conDict)
        if params is not None:
            # Hack to support vdsm.conf nfs_mount_options
            typeName = 'posixfs'
        else:
            version = conDict.get('protocol_version', "3")
            version = str(version)
            if version == "auto":
                version = None

            params = NfsConnectionParameters(
                conDict["id"], conDict.get('connection', None),
                getIntParam(conDict, 'retrans', None),
                getIntParam(conDict, 'timeout', None), version,
                conDict.get('mnt_options', None))
    elif typeName == 'posixfs':
        params = PosixFsConnectionParameters(conDict["id"],
                                             conDict.get('connection', None),
                                             conDict.get('vfs_type', None),
                                             conDict.get('mnt_options', None))
    elif typeName == 'glusterfs':
        params = GlusterFsConnectionParameters(
            conDict["id"], conDict.get('connection', None),
            conDict.get('vfs_type', None), conDict.get('mnt_options', None))
    elif typeName == 'iscsi':
        portal = iscsi.IscsiPortal(conDict.get('connection', None),
                                   int(conDict.get('port', None)))
        tpgt = int(conDict.get('tpgt', iscsi.DEFAULT_TPGT))

        target = iscsi.IscsiTarget(portal, tpgt, conDict.get('iqn', None))

        iface = iscsi.resolveIscsiIface(conDict.get('ifaceName', None),
                                        conDict.get('initiatorName', None),
                                        conDict.get('netIfaceName', None))

        # NOTE: ChapCredentials must match the way we initialize username and
        # password when reading session info in iscsi.readSessionInfo(). Empty
        # or missing username or password are stored as None.

        username = conDict.get('user')
        if not username:
            username = None
        password = conDict.get('password')
        if not getattr(password, "value", None):
            password = None
        cred = None
        if username or password:
            cred = iscsi.ChapCredentials(username, password)

        params = IscsiConnectionParameters(conDict["id"], target, iface, cred)
    elif typeName == 'fcp':
        params = FcpConnectionParameters(conDict["id"])
    else:
        raise se.StorageServerActionError()

    return ConnectionInfo(typeName, params)