From c259ce6498ad36aef9cbcd61866af42c85ac2126 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 1 Oct 2008 17:37:29 +0000 Subject: [PATCH] Get rid of ssconf Remove leftovers from ssconf. Reviewed-by: iustinp --- lib/bootstrap.py | 10 -- lib/ssconf.py | 167 ---------------------------------- test/ganeti.hooks_unittest.py | 5 +- test/mocks.py | 7 -- 4 files changed, 2 insertions(+), 187 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index ae9aad9b2..43a7f4f40 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -196,16 +196,6 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge, raise errors.OpPrereqError("Init.d script '%s' missing or not" " executable." % constants.NODE_INITD_SCRIPT) - # set up the simple store - ss = ssconf.WritableSimpleStore() - ss.SetKey(ss.SS_HYPERVISOR, hypervisor_type) - ss.SetKey(ss.SS_MASTER_NODE, hostname.name) - ss.SetKey(ss.SS_MASTER_IP, clustername.ip) - ss.SetKey(ss.SS_MASTER_NETDEV, master_netdev) - ss.SetKey(ss.SS_CLUSTER_NAME, clustername.name) - ss.SetKey(ss.SS_FILE_STORAGE_DIR, file_storage_dir) - ss.SetKey(ss.SS_CONFIG_VERSION, constants.CONFIG_VERSION) - # set up the inter-node password and certificate _InitGanetiServerSetup() diff --git a/lib/ssconf.py b/lib/ssconf.py index cbd26e2c8..f9024f1d2 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -35,173 +35,6 @@ from ganeti import utils from ganeti import serializer -class SimpleStore: - """Interface to static cluster data. - - This is different that the config.ConfigWriter class in that it - holds data that is (mostly) constant after the cluster - initialization. Its purpose is to allow limited customization of - things which would otherwise normally live in constants.py. Note - that this data cannot live in ConfigWriter as that is available only - on the master node, and our data must be readable by both the master - and the nodes. - - Other particularities of the datastore: - - keys are restricted to predefined values - - values are small (<4k) - - some keys are handled specially (read from the system) - - """ - _SS_FILEPREFIX = "ssconf_" - SS_HYPERVISOR = "hypervisor" - SS_NODED_PASS = "node_pass" - SS_MASTER_NODE = "master_node" - SS_MASTER_IP = "master_ip" - SS_MASTER_NETDEV = "master_netdev" - SS_CLUSTER_NAME = "cluster_name" - SS_FILE_STORAGE_DIR = "file_storage_dir" - SS_CONFIG_VERSION = "config_version" - _VALID_KEYS = (SS_HYPERVISOR, SS_NODED_PASS, SS_MASTER_NODE, SS_MASTER_IP, - SS_MASTER_NETDEV, SS_CLUSTER_NAME, SS_FILE_STORAGE_DIR, - SS_CONFIG_VERSION) - _MAX_SIZE = 4096 - - def __init__(self, cfg_location=None): - if cfg_location is None: - self._cfg_dir = constants.DATA_DIR - else: - self._cfg_dir = cfg_location - - def KeyToFilename(self, key): - """Convert a given key into filename. - - """ - if key not in self._VALID_KEYS: - raise errors.ProgrammerError("Invalid key requested from SSConf: '%s'" - % str(key)) - - filename = self._cfg_dir + '/' + self._SS_FILEPREFIX + key - return filename - - def _ReadFile(self, key): - """Generic routine to read keys. - - This will read the file which holds the value requested. Errors - will be changed into ConfigurationErrors. - - """ - filename = self.KeyToFilename(key) - try: - fh = file(filename, 'r') - try: - data = fh.readline(self._MAX_SIZE) - data = data.rstrip('\n') - finally: - fh.close() - except EnvironmentError, err: - raise errors.ConfigurationError("Can't read from the ssconf file:" - " '%s'" % str(err)) - return data - - def GetNodeDaemonPort(self): - """Get the node daemon port for this cluster. - - Note that this routine does not read a ganeti-specific file, but - instead uses socket.getservbyname to allow pre-customization of - this parameter outside of ganeti. - - """ - try: - port = socket.getservbyname("ganeti-noded", "tcp") - except socket.error: - port = constants.DEFAULT_NODED_PORT - - return port - - def GetHypervisorType(self): - """Get the hypervisor type for this cluster. - - """ - return self._ReadFile(self.SS_HYPERVISOR) - - def GetNodeDaemonPassword(self): - """Get the node password for this cluster. - - """ - return self._ReadFile(self.SS_NODED_PASS) - - def GetMasterNode(self): - """Get the hostname of the master node for this cluster. - - """ - return self._ReadFile(self.SS_MASTER_NODE) - - def GetMasterIP(self): - """Get the IP of the master node for this cluster. - - """ - return self._ReadFile(self.SS_MASTER_IP) - - def GetMasterNetdev(self): - """Get the netdev to which we'll add the master ip. - - """ - return self._ReadFile(self.SS_MASTER_NETDEV) - - def GetClusterName(self): - """Get the cluster name. - - """ - return self._ReadFile(self.SS_CLUSTER_NAME) - - def GetFileStorageDir(self): - """Get the file storage dir. - - """ - return self._ReadFile(self.SS_FILE_STORAGE_DIR) - - def GetConfigVersion(self): - """Get the configuration version. - - """ - value = self._ReadFile(self.SS_CONFIG_VERSION) - try: - return int(value) - except (ValueError, TypeError), err: - raise errors.ConfigurationError("Failed to convert config version %s to" - " int: '%s'" % (value, str(err))) - - def GetFileList(self): - """Return the list of all config files. - - This is used for computing node replication data. - - """ - return [self.KeyToFilename(key) for key in self._VALID_KEYS] - - -class WritableSimpleStore(SimpleStore): - """This is a read/write interface to SimpleStore, which is used rarely, when - values need to be changed. Since WriteFile handles updates in an atomic way - it should be fine to use two WritableSimpleStore at the same time, but in - the future we might want to put additional protection for this class. - - A WritableSimpleStore cannot be used to update system-dependent values. - - """ - - def SetKey(self, key, value): - """Set the value of a key. - - This should be used only when adding a node to a cluster, or in other - infrequent operations such as cluster-rename or master-failover. - - """ - file_name = self.KeyToFilename(key) - utils.WriteFile(file_name, data="%s\n" % str(value), - uid=0, gid=0, mode=0400) - - class SimpleConfigReader: """Simple class to read configuration file. diff --git a/test/ganeti.hooks_unittest.py b/test/ganeti.hooks_unittest.py index 001810733..2f5f8b0a2 100755 --- a/test/ganeti.hooks_unittest.py +++ b/test/ganeti.hooks_unittest.py @@ -36,7 +36,7 @@ from ganeti import constants from ganeti import cmdlib from ganeti.constants import HKR_SUCCESS, HKR_FAIL, HKR_SKIP -from mocks import FakeConfig, FakeSStore, FakeProc, FakeContext +from mocks import FakeConfig, FakeProc, FakeContext class FakeLU(cmdlib.LogicalUnit): HPATH = "test" @@ -226,10 +226,9 @@ class TestHooksMaster(unittest.TestCase): for node_name in node_list]) def setUp(self): - self.sstore = FakeSStore() self.op = opcodes.OpCode() self.context = FakeContext() - self.lu = FakeLU(None, self.op, self.context, self.sstore) + self.lu = FakeLU(None, self.op, self.context) def testTotalFalse(self): """Test complete rpc failure""" diff --git a/test/mocks.py b/test/mocks.py index dfc1b112b..bea8dd399 100644 --- a/test/mocks.py +++ b/test/mocks.py @@ -55,13 +55,6 @@ class FakeConfig: return utils.HostInfo().name -class FakeSStore: - """Fake simplestore object""" - - def GetMasterNode(self): - return utils.HostInfo().name - - class FakeProc: """Fake processor object""" -- GitLab