def testMultiSomeOffline(self): nodes = dict(("node%s-uuid" % i, objects.Node(name="node%s.example.com" % i, offline=((i % 3) == 0), primary_ip="192.0.2.%s" % i, uuid="node%s-uuid" % i)) for i in range(1, 255)) # Resolve no names self.assertEqual( rpc._NodeConfigResolver(NotImplemented, lambda: nodes, [], None), []) # Offline, online and unknown hosts self.assertEqual( rpc._NodeConfigResolver(NotImplemented, lambda: nodes, [ "node3-uuid", "node92-uuid", "node54-uuid", "unknown.example.com", ], None), [ ("node3.example.com", rpc._OFFLINE, "node3-uuid"), ("node92.example.com", "192.0.2.92", "node92-uuid"), ("node54.example.com", rpc._OFFLINE, "node54-uuid"), ("unknown.example.com", "unknown.example.com", "unknown.example.com"), ])
def testMultiSomeOffline(self): nodes = dict(("node%s-uuid" % i, objects.Node(name="node%s.example.com" % i, offline=((i % 3) == 0), primary_ip="192.0.2.%s" % i, uuid="node%s-uuid" % i)) for i in range(1, 255)) # Resolve no names self.assertEqual(rpc._NodeConfigResolver(NotImplemented, lambda: nodes, [], None), []) # Offline, online and unknown hosts self.assertEqual(rpc._NodeConfigResolver(NotImplemented, lambda: nodes, ["node3-uuid", "node92-uuid", "node54-uuid", "unknown.example.com",], None), [ ("node3.example.com", rpc._OFFLINE, "node3-uuid"), ("node92.example.com", "192.0.2.92", "node92-uuid"), ("node54.example.com", rpc._OFFLINE, "node54-uuid"), ("unknown.example.com", "unknown.example.com", "unknown.example.com"), ])
def testSingleOfflineWithAcceptOffline(self): fn = self._GetSingleOfflineNode assert fn("node100-uuid").offline self.assertEqual( rpc._NodeConfigResolver(fn, NotImplemented, ["node100-uuid"], rpc_defs.ACCEPT_OFFLINE_NODE), [("node100.example.com", "192.0.2.100", "node100-uuid")]) for i in [False, True, "", "Hello", 0, 1]: self.assertRaises(AssertionError, rpc._NodeConfigResolver, fn, NotImplemented, ["node100.example.com"], i)
def testSingleOfflineWithAcceptOffline(self): fn = self._GetSingleOfflineNode assert fn("node100-uuid").offline self.assertEqual(rpc._NodeConfigResolver(fn, NotImplemented, ["node100-uuid"], rpc_defs.ACCEPT_OFFLINE_NODE), [("node100.example.com", "192.0.2.100", "node100-uuid")]) for i in [False, True, "", "Hello", 0, 1]: self.assertRaises(AssertionError, rpc._NodeConfigResolver, fn, NotImplemented, ["node100.example.com"], i)
def testMultiEmpty(self): self.assertEqual( rpc._NodeConfigResolver(NotImplemented, lambda: {}, [], None), [])
def testUnknownSingleNode(self): self.assertEqual( rpc._NodeConfigResolver(lambda _: None, NotImplemented, ["node110.example.com"], None), [("node110.example.com", "node110.example.com", "node110.example.com")])
def testSingleOffline(self): self.assertEqual( rpc._NodeConfigResolver(self._GetSingleOfflineNode, NotImplemented, ["node100-uuid"], None), [("node100.example.com", rpc._OFFLINE, "node100-uuid")])
def testSingleOnline(self): self.assertEqual( rpc._NodeConfigResolver(self._GetSingleOnlineNode, NotImplemented, ["node90-uuid"], None), [("node90.example.com", "192.0.2.90", "node90-uuid")])
def testMultiEmpty(self): self.assertEqual(rpc._NodeConfigResolver(NotImplemented, lambda: {}, [], None), [])
def testUnknownSingleNode(self): self.assertEqual(rpc._NodeConfigResolver(lambda _: None, NotImplemented, ["node110.example.com"], None), [("node110.example.com", "node110.example.com", "node110.example.com")])
def testSingleOffline(self): self.assertEqual(rpc._NodeConfigResolver(self._GetSingleOfflineNode, NotImplemented, ["node100-uuid"], None), [("node100.example.com", rpc._OFFLINE, "node100-uuid")])
def testSingleOnline(self): self.assertEqual(rpc._NodeConfigResolver(self._GetSingleOnlineNode, NotImplemented, ["node90-uuid"], None), [("node90.example.com", "192.0.2.90", "node90-uuid")])