Commit b8028dcf authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Replace frozenset with compat.UniqueFrozenset



This is not a trivial s/frozenset/compat.UniqueFrozenset/, but rather
only replaces “frozenset” where appropriate. Most of the places are
“static” information that doesn't change after the module has been
loaded.

Some docstrings and code formatting (e.g. empty lines) issues are
addressed as well. Some lines got too long and were wrapped.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a30a6178
......@@ -68,7 +68,7 @@ from ganeti import ht
_BOOT_ID_PATH = "/proc/sys/kernel/random/boot_id"
_ALLOWED_CLEAN_DIRS = frozenset([
_ALLOWED_CLEAN_DIRS = compat.UniqueFrozenset([
pathutils.DATA_DIR,
pathutils.JOB_QUEUE_ARCHIVE_DIR,
pathutils.QUEUE_DIR,
......
......@@ -120,7 +120,7 @@ def _GetForbiddenFileStoragePaths():
paths.update(map(lambda s: "%s/%s" % (prefix, s),
["bin", "lib", "lib32", "lib64", "sbin"]))
return frozenset(map(os.path.normpath, paths))
return compat.UniqueFrozenset(map(os.path.normpath, paths))
def _ComputeWrongFileStoragePaths(paths,
......@@ -503,8 +503,8 @@ class LogicalVolume(BlockDev):
"""
_VALID_NAME_RE = re.compile("^[a-zA-Z0-9+_.-]*$")
_INVALID_NAMES = frozenset([".", "..", "snapshot", "pvmove"])
_INVALID_SUBSTRINGS = frozenset(["_mlog", "_mimage"])
_INVALID_NAMES = compat.UniqueFrozenset([".", "..", "snapshot", "pvmove"])
_INVALID_SUBSTRINGS = compat.UniqueFrozenset(["_mlog", "_mimage"])
def __init__(self, unique_id, children, size, params):
"""Attaches to a LV device.
......@@ -958,7 +958,7 @@ class DRBD8Status(object):
CS_SYNCTARGET = "SyncTarget"
CS_PAUSEDSYNCS = "PausedSyncS"
CS_PAUSEDSYNCT = "PausedSyncT"
CSET_SYNC = frozenset([
CSET_SYNC = compat.UniqueFrozenset([
CS_WFREPORTPARAMS,
CS_STARTINGSYNCS,
CS_STARTINGSYNCT,
......
......@@ -666,7 +666,7 @@ def check_maybefloat(option, opt, value): # pylint: disable=W0613
OPT_COMPL_INST_ADD_NODES,
OPT_COMPL_ONE_NODEGROUP) = range(100, 108)
OPT_COMPL_ALL = frozenset([
OPT_COMPL_ALL = compat.UniqueFrozenset([
OPT_COMPL_MANY_NODES,
OPT_COMPL_ONE_NODE,
OPT_COMPL_ONE_INSTANCE,
......
......@@ -432,7 +432,12 @@ def TestJobqueue(opts, _):
TM_MULTISUCCESS,
TM_FAIL,
TM_PARTFAIL) = range(4)
TM_ALL = frozenset([TM_SUCCESS, TM_MULTISUCCESS, TM_FAIL, TM_PARTFAIL])
TM_ALL = compat.UniqueFrozenset([
TM_SUCCESS,
TM_MULTISUCCESS,
TM_FAIL,
TM_PARTFAIL,
])
for mode in TM_ALL:
test_messages = [
......
......@@ -28,14 +28,14 @@ from ganeti.cli import *
from ganeti import constants
from ganeti import opcodes
from ganeti import utils
from ganeti import compat
from cStringIO import StringIO
#: default list of fields for L{ListGroups}
_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy", "ndparams"]
_ENV_OVERRIDE = frozenset(["list"])
_ENV_OVERRIDE = compat.UniqueFrozenset(["list"])
def AddGroup(opts, args):
......
......@@ -53,21 +53,19 @@ _EXPAND_NODES_SEC_BY_TAGS = "nodes-sec-by-tags"
_EXPAND_INSTANCES = "instances"
_EXPAND_INSTANCES_BY_TAGS = "instances-by-tags"
_EXPAND_NODES_TAGS_MODES = frozenset([
_EXPAND_NODES_TAGS_MODES = compat.UniqueFrozenset([
_EXPAND_NODES_BOTH_BY_TAGS,
_EXPAND_NODES_PRI_BY_TAGS,
_EXPAND_NODES_SEC_BY_TAGS,
])
#: default list of options for L{ListInstances}
_LIST_DEF_FIELDS = [
"name", "hypervisor", "os", "pnode", "status", "oper_ram",
]
_MISSING = object()
_ENV_OVERRIDE = frozenset(["list"])
_ENV_OVERRIDE = compat.UniqueFrozenset(["list"])
_INST_DATA_VAL = ht.TListOf(ht.TDict)
......
......@@ -39,6 +39,7 @@ from ganeti import errors
from ganeti import netutils
from ganeti import pathutils
from ganeti import ssh
from ganeti import compat
from cStringIO import StringIO
from ganeti import confd
......@@ -106,13 +107,12 @@ _REPAIRABLE_STORAGE_TYPES = \
_MODIFIABLE_STORAGE_TYPES = constants.MODIFIABLE_STORAGE_FIELDS.keys()
_OOB_COMMAND_ASK = compat.UniqueFrozenset([
constants.OOB_POWER_OFF,
constants.OOB_POWER_CYCLE,
])
_OOB_COMMAND_ASK = frozenset([constants.OOB_POWER_OFF,
constants.OOB_POWER_CYCLE])
_ENV_OVERRIDE = frozenset(["list"])
_ENV_OVERRIDE = compat.UniqueFrozenset(["list"])
NONODE_SETUP_OPT = cli_option("--no-node-setup", default=True,
action="store_false", dest="node_setup",
......
......@@ -7288,7 +7288,7 @@ class LUInstanceRecreateDisks(LogicalUnit):
HTYPE = constants.HTYPE_INSTANCE
REQ_BGL = False
 
_MODIFYABLE = frozenset([
_MODIFYABLE = compat.UniqueFrozenset([
constants.IDISK_SIZE,
constants.IDISK_MODE,
])
......
......@@ -406,7 +406,7 @@ UPCALL_REPLY = 1
# UPCALL_EXPIRE: internal library request expire
# has only salt, type, orig_request and extra_args
UPCALL_EXPIRE = 2
CONFD_UPCALL_TYPES = frozenset([
CONFD_UPCALL_TYPES = compat.UniqueFrozenset([
UPCALL_REPLY,
UPCALL_EXPIRE,
])
......
This diff is collapsed.
......@@ -19,7 +19,11 @@
# 02110-1301, USA.
"""Ganeti exception handling"""
"""Ganeti exception handling.
"""
from ganeti import compat
# OpPrereqError failure types
......@@ -55,7 +59,7 @@ ECODE_FAULT = "internal_error"
ECODE_ENVIRON = "environment_error"
#: List of all failure types
ECODE_ALL = frozenset([
ECODE_ALL = compat.UniqueFrozenset([
ECODE_RESOLVER,
ECODE_NORES,
ECODE_TEMP_NORES,
......
......@@ -36,6 +36,7 @@ from ganeti import constants
from ganeti import errors
from ganeti import utils
from ganeti import netutils
from ganeti import compat
#: Used to recognize point at which socat(1) starts to listen on its socket.
......@@ -56,7 +57,7 @@ SOCAT_LOG_WARNING = "W"
SOCAT_LOG_ERROR = "E"
SOCAT_LOG_FATAL = "F"
SOCAT_LOG_IGNORE = frozenset([
SOCAT_LOG_IGNORE = compat.UniqueFrozenset([
SOCAT_LOG_DEBUG,
SOCAT_LOG_INFO,
SOCAT_LOG_NOTICE,
......@@ -93,7 +94,8 @@ SOCAT_OPTION_MAXLEN = 400
PROG_DD,
PROG_DD_PID,
PROG_EXP_SIZE) = range(1, 6)
PROG_ALL = frozenset([
PROG_ALL = compat.UniqueFrozenset([
PROG_OTHER,
PROG_SOCAT,
PROG_DD,
......
......@@ -56,7 +56,7 @@ _LOCK_ACQUIRE_MIN_TIMEOUT = (1.0 / 1000)
_LS_ACQUIRE_ALL,
_LS_ACQUIRE_OPPORTUNISTIC) = range(1, 4)
_LS_ACQUIRE_MODES = frozenset([
_LS_ACQUIRE_MODES = compat.UniqueFrozenset([
_LS_ACQUIRE_EXACT,
_LS_ACQUIRE_ALL,
_LS_ACQUIRE_OPPORTUNISTIC,
......@@ -1599,7 +1599,7 @@ LEVELS = [
]
# Lock levels which are modifiable
LEVELS_MOD = frozenset([
LEVELS_MOD = compat.UniqueFrozenset([
LEVEL_NODE_RES,
LEVEL_NODE,
LEVEL_NODEGROUP,
......
......@@ -35,6 +35,7 @@ import time
import errno
import logging
from ganeti import compat
from ganeti import serializer
from ganeti import constants
from ganeti import errors
......@@ -71,7 +72,7 @@ REQ_SET_DRAIN_FLAG = "SetDrainFlag"
REQ_SET_WATCHER_PAUSE = "SetWatcherPause"
#: List of all LUXI requests
REQ_ALL = frozenset([
REQ_ALL = compat.UniqueFrozenset([
REQ_ARCHIVE_JOB,
REQ_AUTO_ARCHIVE_JOBS,
REQ_CANCEL_JOB,
......
......@@ -50,12 +50,12 @@ _LU_PREFIX = "LU"
#: LU classes which don't need to acquire the node allocation lock
#: (L{locking.NAL}) when they acquire all node or node resource locks
_NODE_ALLOC_WHITELIST = frozenset()
_NODE_ALLOC_WHITELIST = frozenset([])
#: LU classes which don't need to acquire the node allocation lock
#: (L{locking.NAL}) in the same mode (shared/exclusive) as the node
#: or node resource locks
_NODE_ALLOC_MODE_WHITELIST = frozenset([
_NODE_ALLOC_MODE_WHITELIST = compat.UniqueFrozenset([
cmdlib.LUBackupExport,
cmdlib.LUBackupRemove,
cmdlib.LUOobCommand,
......
......@@ -24,6 +24,7 @@
"""
from ganeti import _autoconf
from ganeti import compat
from ganeti import vcluster
......@@ -130,7 +131,7 @@ JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
ALL_CERT_FILES = frozenset([
ALL_CERT_FILES = compat.UniqueFrozenset([
NODED_CERT_FILE,
RAPI_CERT_FILE,
SPICE_CERT_FILE,
......
......@@ -137,7 +137,12 @@ _FS_UNAVAIL = object()
_FS_OFFLINE = object()
#: List of all special status
_FS_ALL = frozenset([_FS_UNKNOWN, _FS_NODATA, _FS_UNAVAIL, _FS_OFFLINE])
_FS_ALL = compat.UniqueFrozenset([
_FS_UNKNOWN,
_FS_NODATA,
_FS_UNAVAIL,
_FS_OFFLINE,
])
#: VType to QFT mapping
_VTToQFT = {
......
#
#
# Copyright (C) 2007, 2008 Google Inc.
# Copyright (C) 2007, 2008, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -20,10 +20,13 @@
"""Ganeti RAPI module"""
from ganeti import compat
RAPI_ACCESS_WRITE = "write"
RAPI_ACCESS_READ = "read"
RAPI_ACCESS_ALL = frozenset([
RAPI_ACCESS_ALL = compat.UniqueFrozenset([
RAPI_ACCESS_WRITE,
RAPI_ACCESS_READ,
])
......@@ -42,7 +42,7 @@ from ganeti import pathutils
_DEFAULT = object()
#: Supported HTTP methods
_SUPPORTED_METHODS = frozenset([
_SUPPORTED_METHODS = compat.UniqueFrozenset([
http.HTTP_DELETE,
http.HTTP_GET,
http.HTTP_POST,
......
......@@ -155,7 +155,7 @@ _NODE_MIGRATE_REQV1 = "node-migrate-reqv1"
# Feature string for node evacuation with LU-generated jobs
_NODE_EVAC_RES1 = "node-evac-res1"
ALL_FEATURES = frozenset([
ALL_FEATURES = compat.UniqueFrozenset([
_INST_CREATE_REQV1,
_INST_REINSTALL_REQV1,
_NODE_MIGRATE_REQV1,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment