<div dir="ltr">Doug,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 9:49 PM, Doug Hellmann <span dir="ltr"><<a href="mailto:doug.hellmann@dreamhost.com" target="_blank">doug.hellmann@dreamhost.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">

<div><div class="h5">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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><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></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. </div></div>

</div></div></blockquote><div><br></div><div>We implement similar approach in Rubick [1]. Collector script generates configuration schema from code [2], while generator script [3] allows to have different versions of configuration schema:</div>

<div><br></div><div>[1] <a href="https://github.com/MirantisLabs/rubick/tree/master/rubick/schemas">https://github.com/MirantisLabs/rubick/tree/master/rubick/schemas</a></div><div>[2] <a href="https://github.com/MirantisLabs/rubick/blob/master/rubick/schemas/collector.py#L189">https://github.com/MirantisLabs/rubick/blob/master/rubick/schemas/collector.py#L189</a></div>

<div>[3] <a href="https://github.com/MirantisLabs/rubick/blob/master/rubick/schemas/generator.py">https://github.com/MirantisLabs/rubick/blob/master/rubick/schemas/generator.py</a></div><div><br></div><div>I think it would be useful to discuss pros and cons of contributing parts of this code to oslo.config.</div>

<div><br></div><div>--</div><div>Best regards,</div><div>Oleg Gelbukh</div><div>Mirantis Labs</div></div></div></div>