<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 6:08 PM, Mark McLoughlin <span dir="ltr"><<a href="mailto:markmc@redhat.com" target="_blank">markmc@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nikola,<br>
<div class="im"><br>
On Mon, 2013-11-11 at 12:44 +0100, Nikola Đipanov wrote:<br>
> Hey all,<br>
><br>
> During the summit session on the the VMWare driver roadmap, a topic of<br>
> validating the passed configuration prior to starting services came up<br>
> (see [1] for more detail on how it's connected to that specific topic).<br>
><br>
> Several ideas were thrown around during the session mostly documented in<br>
> [1].<br>
><br>
> There are a few more cases when something like this could be useful (see<br>
> bug [2] and related patch [3]), and I was wondering if a slightly<br>
> different approach might be useful. For example use an already existing<br>
> validation hook in the service class [4] to call into a validation<br>
> framework that will potentially stop the service with proper<br>
> logging/notifications. The obvious benefit would be that there is no<br>
> pre-run required from the user, and the danger of running a<br>
> misconfigured stack is smaller.<br>
<br>
</div>One thing worth trying would be to encode the validation rules in the<br>
config option declaration.<br>
<br>
Some rules could be straightforward, like:<br>
<br>
opts = [<br>
  StrOpt('foo_url',<br>
         validate_rule=cfg.MatchesRegexp('(git|http)://')),<br>
]<br>
<br>
but the rule you describe is more complex e.g.<br>
<br>
def validate_proxy_url(conf, group, key, value):<br>
    if not conf.vnc_enabled:<br>
        return<br>
    if conf.ssl_only and value.startswith("http://"):<br>
        raise ValueError('ssl_only option detected, but ...')<br>
<br>
opts = [<br>
  StrOpt('novncproxy_base_url',<br>
         validate_rule=validate_proxy_url),<br>
  ...<br>
]<br>
<br>
I'm not sure I love this yet, but it's worth experimenting with.<br></blockquote><div><br></div><div>One thing to keep in mind with the move to calling register_opt() at runtime instead of import time is the service may run for a little while before it reaches the point in the code where the option validation code is triggered. So I like the idea, but we may want a shortcut for validation.</div>
<div><br></div><div>We could add a small app to oslo.config that will load the options in the same way the conf generator and doc tool will, but then also read the configuration file and perform the validation. Another benefit of a separate tool is it could produce a full list of warnings and errors, rather than having the service stop on each bad value.</div>
<div><br></div><div>Doug</div><div><br></div></div></div></div>