Commit 890ea4ce authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rpc._NodeConfigResolver: Support resolving offline nodes

This is needed to powercycle a node marked offline.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent fce5efd1
......@@ -285,7 +285,7 @@ class _StaticResolver:
return zip(hosts, self._addresses)
def _CheckConfigNode(name, node):
def _CheckConfigNode(name, node, accept_offline_node):
"""Checks if a node is online.
@type name: string
......@@ -297,24 +297,29 @@ def _CheckConfigNode(name, node):
if node is None:
# Depend on DNS for name resolution
ip = name
elif node.offline:
elif node.offline and not accept_offline_node:
ip = node.primary_ip
return (name, ip)
def _NodeConfigResolver(single_node_fn, all_nodes_fn, hosts, _):
def _NodeConfigResolver(single_node_fn, all_nodes_fn, hosts, opts):
"""Calculate node addresses using configuration.
accept_offline_node = (opts is rpc_defs.ACCEPT_OFFLINE_NODE)
assert accept_offline_node or opts is None, "Unknown option"
# Special case for single-host lookups
if len(hosts) == 1:
(name, ) = hosts
return [_CheckConfigNode(name, single_node_fn(name))]
return [_CheckConfigNode(name, single_node_fn(name), accept_offline_node)]
all_nodes = all_nodes_fn()
return [_CheckConfigNode(name, all_nodes.get(name, None))
return [_CheckConfigNode(name, all_nodes.get(name, None),
for name in hosts]
......@@ -58,6 +58,8 @@ TMO_1DAY = 86400
SINGLE = "single-node"
MULTI = "multi-node"
# Constants for encoding/decoding
......@@ -28,6 +28,7 @@ import unittest
from ganeti import constants
from ganeti import compat
from ganeti import rpc
from ganeti import rpc_defs
from ganeti import http
from ganeti import errors
from ganeti import serializer
......@@ -397,6 +398,17 @@ class TestNodeConfigResolver(unittest.TestCase):
[""], None),
[("", rpc._OFFLINE)])
def testSingleOfflineWithAcceptOffline(self):
fn = self._GetSingleOfflineNode
assert fn("").offline
self.assertEqual(rpc._NodeConfigResolver(fn, NotImplemented,
[("", "")])
for i in [False, True, "", "Hello", 0, 1]:
self.assertRaises(AssertionError, rpc._NodeConfigResolver,
fn, NotImplemented, [""], i)
def testUnknownSingleNode(self):
self.assertEqual(rpc._NodeConfigResolver(lambda _: None, NotImplemented,
[""], None),
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