On Tue, Jun 22, 2010 at 04:00:55PM +0200, Guido Trotter wrote:
> On Wed, Jun 16, 2010 at 5:21 AM, Iustin Pop <[email protected]> wrote:
> > While we only support the 'parameters' check today, the RPC call is
> > generic enough that will be able to support other checks in the future.
> 
> LGTM (with one comment).
> 
> > The backend function will both validate the parameters list (so as to
> > make sure we don't pass in extra parameters that the OS validation
> > doesn't care about) and the parameter values, via the OS verify script.
> > ---
> >  daemons/ganeti-noded |    8 +++++++
> >  lib/backend.py       |   57 
> > ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  lib/cmdlib.py        |   29 +++++++++++++++++++++++++
> >  lib/rpc.py           |   10 ++++++++
> >  4 files changed, 104 insertions(+), 0 deletions(-)
> >
> > diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
> > index 281b061..21227fa 100755
> > --- a/daemons/ganeti-noded
> > +++ b/daemons/ganeti-noded
> > @@ -712,6 +712,14 @@ class NodeHttpServer(http.server.HttpServer):
> >     os_obj = backend.OSFromDisk(name)
> >     return os_obj.ToDict()
> >
> > + �...@staticmethod
> > +  def perspective_os_validate(params):
> > +    """Run a given OS' validation routine.
> > +
> > +    """
> > +    required, name, checks, params = params
> > +    return backend.ValidateOS(required, name, checks, params)
> > +
> >   # hooks -----------------------
> >
> >   @staticmethod
> > diff --git a/lib/backend.py b/lib/backend.py
> > index ba569ae..d3dbe1d 100644
> > --- a/lib/backend.py
> > +++ b/lib/backend.py
> > @@ -2455,6 +2455,63 @@ def ValidateHVParams(hvname, hvparams):
> >     _Fail(str(err), log=False)
> >
> >
> > +def _CheckOSPList(os_obj, parameters):
> > +  """Check whether a list of parameters is supported by the OS.
> > +
> > + �...@type os_obj: L{objects.OS}
> > + �...@param os_obj: OS object to check
> > + �...@type parameters: list
> > + �...@param parameters: the list of parameters to check
> > +
> > +  """
> > +  supported = [v[0] for v in os_obj.supported_parameters]
> > +  delta = frozenset(parameters).difference(supported)
> > +  if delta:
> > +    _Fail("The following parameters are not supported"
> > +          " by the OS %s: %s" % (os_obj.name, utils.CommaJoin(delta)))
> > +
> > +
> > +def ValidateOS(required, osname, checks, osparams):
> > +  """Validate the given OS' parameters.
> > +
> > + �...@type required: boolean
> > + �...@param required: whether absence of the OS should translate into
> > +      failure or not
> > + �...@type osname: string
> > + �...@param osname: the OS to be validated
> > + �...@type checks: list
> > + �...@param checks: list of the checks to run (currently only 'parameters')
> > + �...@type osparams: dict
> > + �...@param osparams: dictionary with OS parameters
> > + �...@rtype: boolean
> > + �...@return: True if the validation passed, or False if the OS was not
> > +      found and L{required} was false
> > +
> > +  """
> > +  name_only = osname.split("+", 1)[0]
> > +  status, tbv = _TryOSFromDisk(name_only, None)
> > +
> > +  if not status:
> > +    if required:
> > +      _Fail(tbv)
> > +    else:
> > +      return False
> > +
> > +  if constants.OS_VALIDATE_PARAMETERS in checks:
> > +    _CheckOSPList(tbv, osparams.keys())
> > +
> 
> Can we please have a list of valid checks and a programmererror if any
> passed check is not in the list?
> Now it's only validate_parameters, but if we're ever growing them it
> might be useful.

Interdiff:

diff --git a/lib/backend.py b/lib/backend.py
index e1a7849..58c789a 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -2490,6 +2490,10 @@ def ValidateOS(required, osname, checks, osparams):
       found and L{required} was false
 
   """
+  if not constants.OS_VALIDATE_CALLS.issuperset(checks):
+    _Fail("Unknown checks required for OS %s: %s", osname,
+          set(checks).difference(constants.OS_VALIDATE_CALLS))
+
   name_only = osname.split("+", 1)[0]
   status, tbv = _TryOSFromDisk(name_only, None)
 
diff --git a/lib/constants.py b/lib/constants.py
index 5f2d9e0..2ce3382 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -459,6 +459,7 @@ OS_VARIANTS_FILE = 'variants.list'
 OS_PARAMETERS_FILE = 'parameters.list'
 
 OS_VALIDATE_PARAMETERS = 'parameters'
+OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
 
 # ssh constants
 SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR

-- 
iustin

Reply via email to