On Fri, Sep 9, 2011 at 13:14, Michael Hanselmann <[email protected]> wrote:
> Also add unittests.
> ---
>  lib/rapi/rlib2.py                  |   13 +------
>  test/ganeti.rapi.rlib2_unittest.py |   60 
> +++++++++++++++++++++++++++++++++++-
>  2 files changed, 61 insertions(+), 12 deletions(-)
>
> diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
> index e969c38..e450923 100644
> --- a/lib/rapi/rlib2.py
> +++ b/lib/rapi/rlib2.py
> @@ -240,20 +240,11 @@ class R_2_redist_config(baserlib.ResourceBase):
>     return self.SubmitJob([opcodes.OpClusterRedistConf()])
>
>
> -class R_2_cluster_modify(baserlib.ResourceBase):
> +class R_2_cluster_modify(baserlib.OpcodeResource):
>   """/2/modify resource.
>
>   """
> -  def PUT(self):
> -    """Modifies cluster parameters.
> -
> -    @return: a job id
> -
> -    """
> -    op = baserlib.FillOpcode(opcodes.OpClusterSetParams, self.request_body,
> -                             None)
> -
> -    return self.SubmitJob([op])
> +  PUT_OPCODE = opcodes.OpClusterSetParams
>
>
>  class R_2_jobs(baserlib.ResourceBase):
> diff --git a/test/ganeti.rapi.rlib2_unittest.py 
> b/test/ganeti.rapi.rlib2_unittest.py
> index 5b0f22d..15917fc 100755
> --- a/test/ganeti.rapi.rlib2_unittest.py
> +++ b/test/ganeti.rapi.rlib2_unittest.py
> @@ -25,7 +25,8 @@
>
>
>  import unittest
> -import tempfile
> +import itertools
> +import random
>
>  from ganeti import constants
>  from ganeti import opcodes
> @@ -55,6 +56,33 @@ def _CreateHandler(cls, items, queryargs, body_data, 
> client_cls):
>              _client_cls=client_cls)
>
>
> +class _FakeClient:
> +  def __init__(self):
> +    self._jobs = []
> +
> +  def GetNextSubmittedJob(self):
> +    return self._jobs.pop(0)
> +
> +  def SubmitJob(self, ops):
> +    job_id = str(1 + int(random.random() * 1000000))
> +    self._jobs.append((job_id, ops))
> +    return job_id
> +
> +
> +class _FakeClientFactory:
> +  def __init__(self, cls):
> +    self._client_cls = cls
> +    self._clients = []
> +
> +  def GetNextClient(self):
> +    return self._clients.pop(0)
> +
> +  def __call__(self):
> +    cl = self._client_cls()
> +    self._clients.append(cl)
> +    return cl

Is there a specific need for this factory? From what I see it's just
that you get the same instance back as used in SubmitJob. How about
just adding a __call__ method to the FakeClient returning itself?

Otherwise, LGTM

René

Reply via email to