diff --git a/lib/backend.py b/lib/backend.py index 9184cf7c407a7f9323a96b9af16a425c5487c744..5c8227c9c06462b216493a485bc9ea046ae1c00f 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -49,7 +49,7 @@ def _GetConfig(): def _GetSshRunner(): - return ssh.SshRunner() + return ssh.SshRunner(_GetConfig()) def _CleanDirectory(path, exclude=[]): diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 5102a0401ce61cd4991cfee64179fa12999a0681..ca1735803d1c17c0b16cae9d2ef32797d61e2d9d 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -243,7 +243,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge, cfg = config.ConfigWriter() cfg.InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config) - ssh.WriteKnownHostsFile(cfg, ss, constants.SSH_KNOWN_HOSTS_FILE) + ssh.WriteKnownHostsFile(cfg, constants.SSH_KNOWN_HOSTS_FILE) # start the master ip # TODO: Review rpc call from bootstrap @@ -274,8 +274,9 @@ def SetupNodeDaemon(node, ssh_key_check): node: fully qualified domain name for the new node """ + cfg = ssconf.SimpleConfigReader() + sshrunner = ssh.SshRunner(cfg) ss = ssconf.SimpleStore() - sshrunner = ssh.SshRunner(ss) gntpass = ss.GetNodeDaemonPassword() if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass): raise errors.OpExecError("ganeti password corruption detected") diff --git a/lib/cmdlib.py b/lib/cmdlib.py index cb57d9e1be83fb043291075d3fa783596c5b782e..240bc7feec23c08a9f347dbac74da924f2d0b082 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -111,7 +111,7 @@ class LogicalUnit(object): """ if not self.__ssh: - self.__ssh = ssh.SshRunner(self.sstore) + self.__ssh = ssh.SshRunner(self.cfg) return self.__ssh ssh = property(fget=__GetSSH) diff --git a/lib/ssh.py b/lib/ssh.py index 7d314e237f5966835279e063ea7d4821a81109a0..c9cc1806f5d9713e65ff87d0ee3f3e981d9820af 100644 --- a/lib/ssh.py +++ b/lib/ssh.py @@ -30,7 +30,6 @@ from ganeti import logger from ganeti import utils from ganeti import errors from ganeti import constants -from ganeti import ssconf def GetUserFiles(user, mkdir=False): @@ -72,11 +71,8 @@ class SshRunner: """Wrapper for SSH commands. """ - def __init__(self, sstore=None): - if sstore is None: - self.sstore = ssconf.SimpleStore() - else: - self.sstore = sstore + def __init__(self, cfg): + self.cfg = cfg def _BuildSshOptions(self, batch, ask_key, use_cluster_key, strict_host_check): @@ -88,7 +84,7 @@ class SshRunner: ] if use_cluster_key: - options.append("-oHostKeyAlias=%s" % self.sstore.GetClusterName()) + options.append("-oHostKeyAlias=%s" % self.cfg.GetClusterName()) # TODO: Too many boolean options, maybe convert them to more descriptive # constants. @@ -224,10 +220,10 @@ class SshRunner: return True, "host matches" -def WriteKnownHostsFile(cfg, sstore, file_name): +def WriteKnownHostsFile(cfg, file_name): """Writes the cluster-wide equally known_hosts file. """ utils.WriteFile(file_name, mode=0700, - data="%s ssh-rsa %s\n" % (sstore.GetClusterName(), + data="%s ssh-rsa %s\n" % (cfg.GetClusterName(), cfg.GetHostKey())) diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 31e64259c6afbd2a07085f1727c3994064ca4deb..6e40f6d8bd45ef5d161e9648c03fdbdc165283e6 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -161,6 +161,9 @@ def ClusterCopyFile(opts, args): nodes - list containing the name of target nodes; if empty, all nodes """ + # TODO: Query master + cfg = ssconf.SimpleConfigReader() + filename = args[0] if not os.path.exists(filename): raise errors.OpPrereqError("No such filename '%s'" % filename) @@ -169,7 +172,7 @@ def ClusterCopyFile(opts, args): op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) results = [row[0] for row in SubmitOpCode(op) if row[0] != myname] - srun = ssh.SshRunner() + srun = ssh.SshRunner(cfg) for node in results: if not srun.CopyFileToNode(node, filename): print >> sys.stderr, ("Copy of file %s to node %s failed" % @@ -188,14 +191,18 @@ def RunClusterCommand(opts, args): nodes: list containing the name of target nodes; if empty, all nodes """ + # TODO: Query master + cfg = ssconf.SimpleConfigReader() + command = " ".join(args) op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) nodes = [row[0] for row in SubmitOpCode(op)] sstore = ssconf.SimpleStore() master_node = sstore.GetMasterNode() - srun = ssh.SshRunner(sstore=sstore) + srun = ssh.SshRunner(cfg) + # Make sure master node is at list end if master_node in nodes: nodes.remove(master_node) nodes.append(master_node) diff --git a/test/ganeti.ssh_unittest.py b/test/ganeti.ssh_unittest.py index ac5821e76f99c089b254d7a16c952b4847092821..2121355be7ec51b5e4ca5e052bbeb71473515fc7 100755 --- a/test/ganeti.ssh_unittest.py +++ b/test/ganeti.ssh_unittest.py @@ -41,10 +41,9 @@ class TestKnownHosts(testutils.GanetiTestCase): def test(self): cfg = mocks.FakeConfig() - sstore = mocks.FakeSStore() - ssh.WriteKnownHostsFile(cfg, sstore, self.tmpfile.name) + ssh.WriteKnownHostsFile(cfg, self.tmpfile.name) self.assertFileContent(self.tmpfile.name, - "%s ssh-rsa %s\n" % (sstore.GetClusterName(), + "%s ssh-rsa %s\n" % (cfg.GetClusterName(), mocks.FAKE_CLUSTER_KEY)) diff --git a/test/mocks.py b/test/mocks.py index c611285564bd08eae5a0653ff92bcda3a0ed686a..dfc1b112b39a1b0409e41bb82c47d04cca2684fe 100644 --- a/test/mocks.py +++ b/test/mocks.py @@ -58,9 +58,6 @@ class FakeConfig: class FakeSStore: """Fake simplestore object""" - def GetClusterName(self): - return "test.cluster" - def GetMasterNode(self): return utils.HostInfo().name