Commit b8028dcf authored by Michael Hanselmann's avatar Michael Hanselmann

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,
......
......@@ -30,6 +30,7 @@ import sys
import errno
import logging
from ganeti import compat
from ganeti import errors
from ganeti import constants
from ganeti import utils
......@@ -40,7 +41,7 @@ from ganeti import pathutils
SSCONF_LOCK_TIMEOUT = 10
#: Valid ssconf keys
_VALID_KEYS = frozenset([
_VALID_KEYS = compat.UniqueFrozenset([
constants.SS_CLUSTER_NAME,
constants.SS_CLUSTER_TAGS,
constants.SS_FILE_STORAGE_DIR,
......
......@@ -35,13 +35,14 @@ from ganeti import ssconf
from ganeti import utils
from ganeti import cli
from ganeti import pathutils
from ganeti import compat
(DIR,
FILE,
QUEUE_DIR) = range(1, 4)
ALL_TYPES = frozenset([
ALL_TYPES = compat.UniqueFrozenset([
DIR,
FILE,
QUEUE_DIR,
......
......@@ -39,7 +39,7 @@ _ROOTDIR_ENVNAME = "GANETI_ROOTDIR"
_HOSTNAME_ENVNAME = "GANETI_HOSTNAME"
#: List of paths which shouldn't be virtualized
_VPATH_WHITELIST = frozenset([
_VPATH_WHITELIST = compat.UniqueFrozenset([
ETC_HOSTS,
])
......
......@@ -59,10 +59,10 @@ from ganeti.watcher import state
MAXTRIES = 5
BAD_STATES = frozenset([
BAD_STATES = compat.UniqueFrozenset([
constants.INSTST_ERRORDOWN,
])
HELPLESS_STATES = frozenset([
HELPLESS_STATES = compat.UniqueFrozenset([
constants.INSTST_NODEDOWN,
constants.INSTST_NODEOFFLINE,
])
......
......@@ -104,13 +104,13 @@ NODE_FIELDS = ("name", "dtotal", "dfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt", "tags")
GROUP_FIELDS = frozenset([
GROUP_FIELDS = compat.UniqueFrozenset([
"name", "uuid",
"alloc_policy",
"node_cnt", "node_list",
])
JOB_FIELDS = frozenset([
JOB_FIELDS = compat.UniqueFrozenset([
"id", "ops", "status", "summary",
"opstatus", "opresult", "oplog",
"received_ts", "start_ts", "end_ts",
......
......@@ -43,7 +43,7 @@ import testutils
VALID_URI_RE = re.compile(r"^[-/a-z0-9]*$")
RAPI_OPCODE_EXCLUDE = frozenset([
RAPI_OPCODE_EXCLUDE = compat.UniqueFrozenset([
# Not yet implemented
opcodes.OpBackupQuery,
opcodes.OpBackupRemove,
......@@ -89,7 +89,7 @@ def _ReadDocFile(filename):
class TestHooksDocs(unittest.TestCase):
HOOK_PATH_OK = frozenset([
HOOK_PATH_OK = compat.UniqueFrozenset([
"master-ip-turnup",
"master-ip-turndown",
])
......@@ -223,7 +223,7 @@ class TestRapiDocs(unittest.TestCase):
prevline = line
prefix_exception = frozenset(["/", "/version", "/2"])
prefix_exception = compat.UniqueFrozenset(["/", "/version", "/2"])
undocumented = []
used_uris = []
......
......@@ -25,6 +25,7 @@
import unittest
import itertools
from ganeti import compat
from ganeti import mcpu
from ganeti import opcodes
from ganeti import cmdlib
......@@ -38,7 +39,7 @@ from ganeti.constants import \
import testutils
REQ_BGL_WHITELIST = frozenset([
REQ_BGL_WHITELIST = compat.UniqueFrozenset([
opcodes.OpClusterActivateMasterIp,
opcodes.OpClusterDeactivateMasterIp,
opcodes.OpClusterDestroy,
......
......@@ -37,7 +37,7 @@ import testutils
#: Unless an opcode is included in the following list it must have a result
#: check of some sort
MISSING_RESULT_CHECK = frozenset([
MISSING_RESULT_CHECK = compat.UniqueFrozenset([
opcodes.OpTestAllocator,
opcodes.OpTestDelay,
opcodes.OpTestDummy,
......
......@@ -37,7 +37,7 @@ import ganeti.rapi.client
import testutils
KNOWN_UNUSED_LUXI = frozenset([
KNOWN_UNUSED_LUXI = compat.UniqueFrozenset([
luxi.REQ_SUBMIT_MANY_JOBS,
luxi.REQ_ARCHIVE_JOB,
luxi.REQ_AUTO_ARCHIVE_JOBS,
......
......@@ -41,6 +41,7 @@ from ganeti import errors
from ganeti import ssh
from ganeti import utils
from ganeti import pathutils
from ganeti import compat
_GROUPS_MERGE = "merge"
......@@ -134,7 +135,7 @@ class Merger(object):
"""Handling the merge.
"""
RUNNING_STATUSES = frozenset([
RUNNING_STATUSES = compat.UniqueFrozenset([
constants.INSTST_RUNNING,
constants.INSTST_ERRORUP,
])
......
......@@ -68,7 +68,7 @@ SUPPORTED_TYPES = [
]
#: Excluded filesystem types
EXCLUDED_FS = frozenset([
EXCLUDED_FS = compat.UniqueFrozenset([
"nfs",
"nfs4",
"autofs",
......
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