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

Get rid of ssconf

Remove leftovers from ssconf.

Reviewed-by: iustinp
parent 0b38cf6e
......@@ -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()
......
......@@ -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.
......
......@@ -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"""
......
......@@ -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"""
......
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