Use query client when neccessary for group queries
authorHelga Velroyen <helgav@google.com>
Thu, 21 Nov 2013 08:42:01 +0000 (09:42 +0100)
committerHelga Velroyen <helgav@google.com>
Tue, 26 Nov 2013 09:13:22 +0000 (10:13 +0100)
This patch makes code use the query client for group
queries where necessary in order to remove the python
queries soon.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>

lib/client/gnt_cluster.py
lib/client/gnt_network.py
lib/client/gnt_node.py
lib/watcher/__init__.py
test/py/cmdlib/group_unittest.py
test/py/ganeti.client.gnt_cluster_unittest.py

index 53cd46c..3a141f1 100644 (file)
@@ -1523,7 +1523,7 @@ def _EpoOff(opts, node_list, inst_map):
     return constants.EXIT_FAILURE
 
 
-def Epo(opts, args, cl=None, qcl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
+def Epo(opts, args, qcl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
         _confirm_fn=ConfirmOperation,
         _stdout_fn=ToStdout, _stderr_fn=ToStderr):
   """EPO operations.
@@ -1542,15 +1542,13 @@ def Epo(opts, args, cl=None, qcl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
     _stderr_fn("Arguments in combination with --all are not allowed")
     return constants.EXIT_FAILURE
 
-  if cl is None:
-    cl = GetClient()
   if qcl is None:
     # Query client
     qcl = GetClient(query=True)
 
   if opts.groups:
     node_query_list = \
-      itertools.chain(*cl.QueryGroups(args, ["node_list"], False))
+      itertools.chain(*qcl.QueryGroups(args, ["node_list"], False))
   else:
     node_query_list = args
 
index 40f9c5b..c4c142f 100644 (file)
@@ -111,9 +111,10 @@ def ConnectNetwork(opts, args):
 
   """
   cl = GetClient()
+  qcl = GetClient(query=True)
 
   (network, mode, link) = args[:3]
-  groups = _GetDefaultGroups(cl, args[3:])
+  groups = _GetDefaultGroups(qcl, args[3:])
 
   # TODO: Change logic to support "--submit"
   for group in groups:
@@ -136,9 +137,10 @@ def DisconnectNetwork(opts, args):
 
   """
   cl = GetClient()
+  qcl = GetClient(query=True)
 
   (network, ) = args[:1]
-  groups = _GetDefaultGroups(cl, args[1:])
+  groups = _GetDefaultGroups(qcl, args[1:])
 
   # TODO: Change logic to support "--submit"
   for group in groups:
index 68fcdbd..ada6a7a 100644 (file)
@@ -241,8 +241,8 @@ def AddNode(opts, args):
   try:
     # Passing [] to QueryGroups means query the default group:
     node_groups = [opts.nodegroup] if opts.nodegroup is not None else []
-    output = cl.QueryGroups(names=node_groups, fields=["ndp/ssh_port"],
-                            use_locking=False)
+    output = query_cl.QueryGroups(names=node_groups, fields=["ndp/ssh_port"],
+                                  use_locking=False)
     (ssh_port, ) = output[0]
   except (errors.OpPrereqError, errors.OpExecError):
     pass
index f63d1be..b7297c8 100644 (file)
@@ -614,6 +614,7 @@ def _GlobalWatcher(opts):
 
   try:
     client = GetLuxiClient(True)
+    query_client = GetLuxiClient(True, query=True)
   except NotMasterError:
     # Don't proceed on non-master nodes
     return constants.EXIT_SUCCESS
@@ -637,7 +638,7 @@ def _GlobalWatcher(opts):
   _ArchiveJobs(client, opts.job_age)
 
   # Spawn child processes for all node groups
-  _StartGroupChildren(client, opts.wait_children)
+  _StartGroupChildren(query_client, opts.wait_children)
 
   return constants.EXIT_SUCCESS
 
index d654ca1..499c709 100644 (file)
@@ -176,43 +176,6 @@ class TestLUGroupAssignNodes(CmdlibTestCase):
     self.assertEqual(set(["inst3c"]), set(prev))
 
 
-class TestLUGroupQuery(CmdlibTestCase):
-  def setUp(self):
-    super(TestLUGroupQuery, self).setUp()
-    self.fields = query._BuildGroupFields().keys()
-
-  def testInvalidGroupName(self):
-    op = opcodes.OpGroupQuery(names=["does_not_exist"],
-                              output_fields=self.fields)
-
-    self.ExecOpCodeExpectOpPrereqError(op, "Some groups do not exist")
-
-  def testQueryAllGroups(self):
-    op = opcodes.OpGroupQuery(output_fields=self.fields)
-
-    self.ExecOpCode(op)
-
-    self.mcpu.assertLogIsEmpty()
-
-  def testQueryGroupsByNameAndUuid(self):
-    group1 = self.cfg.AddNewNodeGroup()
-    group2 = self.cfg.AddNewNodeGroup()
-
-    node1 = self.cfg.AddNewNode(group=group1)
-    node2 = self.cfg.AddNewNode(group=group1)
-    self.cfg.AddNewInstance(disk_template=constants.DT_DRBD8,
-                            primary_node=node1,
-                            secondary_node=node2)
-    self.cfg.AddNewInstance(primary_node=node2)
-
-    op = opcodes.OpGroupQuery(names=[group1.name, group2.uuid],
-                              output_fields=self.fields)
-
-    self.ExecOpCode(op)
-
-    self.mcpu.assertLogIsEmpty()
-
-
 class TestLUGroupSetParams(CmdlibTestCase):
   def testNoModifications(self):
     op = opcodes.OpGroupSetParams(group_name=self.group.name)
index c4b3593..b2ce012 100755 (executable)
@@ -182,7 +182,7 @@ class TestEpo(unittest.TestCase):
     return self._OFF_EXITCODE
 
   def _Test(self, *args, **kwargs):
-    defaults = dict(cl=NotImplemented, _on_fn=NotImplemented,
+    defaults = dict(qcl=NotImplemented, _on_fn=NotImplemented,
                     _off_fn=NotImplemented,
                     _stdout_fn=lambda *args: None,
                     _stderr_fn=lambda *args: None)
@@ -216,7 +216,7 @@ class TestEpo(unittest.TestCase):
 
       off_fn = compat.partial(self._Off, ["node1.example.com"])
 
-      result = self._Test(opts, [], cl=client, qcl=client, _off_fn=off_fn,
+      result = self._Test(opts, [], qcl=client, _off_fn=off_fn,
                           _confirm_fn=confirm_fn)
       if force or confirm_result:
         self.assertEqual(result, self._OFF_EXITCODE)
@@ -246,7 +246,7 @@ class TestEpo(unittest.TestCase):
         self.assertFalse(inst_map)
         return self._ON_EXITCODE
 
-      result = self._Test(opts, [], cl=client, qcl=client, _on_fn=_On,
+      result = self._Test(opts, [], qcl=client, _on_fn=_On,
                           _confirm_fn=self._ConfirmForce)
       self.assertEqual(result, self._ON_EXITCODE)
 
@@ -256,8 +256,7 @@ class TestEpo(unittest.TestCase):
     client = _ClientForEpo(NotImplemented, [
       ("node1.example.com", True, [], [], True, False),
       ])
-    result = self._Test(opts, [], cl=client, qcl=client,
-                        _confirm_fn=self._ConfirmForce)
+    result = self._Test(opts, [], qcl=client, _confirm_fn=self._ConfirmForce)
     self.assertEqual(result, constants.EXIT_FAILURE)