Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(212)

Issue 96730043: Support constraints vocabs (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 12 months ago by wallyworld
Modified:
9 years, 11 months ago
Reviewers:
jameinel, mp+216968
Visibility:
Public.

Description

Support constraints vocabs Add support to constraints validation for vocabs for each attribute. eg arch and instance-type can only have well defined values for each provider. The vocab check is part of constraints validation. https://code.launchpad.net/~wallyworld/juju-core/constraints-vocab/+merge/216968 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+389 lines, -84 lines) Patch
A [revision details] View 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/juju/bootstrap.go View 1 chunk +4 lines, -1 line 0 comments Download
M constraints/constraints.go View 3 chunks +9 lines, -9 lines 2 comments Download
M constraints/constraints_test.go View 1 chunk +44 lines, -18 lines 0 comments Download
M constraints/export_test.go View 1 chunk +1 line, -1 line 0 comments Download
M constraints/validation.go View 6 chunks +95 lines, -8 lines 4 comments Download
M constraints/validation_test.go View 3 chunks +46 lines, -0 lines 0 comments Download
M environs/interface.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/statepolicy.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/azure/environ.go View 1 chunk +12 lines, -2 lines 0 comments Download
M provider/azure/environ_test.go View 3 chunks +17 lines, -4 lines 0 comments Download
M provider/dummy/environs.go View 1 chunk +2 lines, -2 lines 0 comments Download
M provider/ec2/ec2.go View 1 chunk +12 lines, -2 lines 0 comments Download
M provider/ec2/local_test.go View 1 chunk +19 lines, -5 lines 0 comments Download
M provider/joyent/environ_instance.go View 1 chunk +16 lines, -2 lines 0 comments Download
M provider/joyent/local_test.go View 1 chunk +14 lines, -1 line 0 comments Download
M provider/local/environ.go View 1 chunk +7 lines, -2 lines 0 comments Download
M provider/local/environ_test.go View 1 chunk +22 lines, -2 lines 0 comments Download
M provider/maas/environ.go View 1 chunk +7 lines, -2 lines 0 comments Download
M provider/maas/environ_test.go View 2 chunks +0 lines, -12 lines 0 comments Download
M provider/maas/environ_whitebox_test.go View 1 chunk +19 lines, -0 lines 0 comments Download
M provider/manual/environ.go View 1 chunk +2 lines, -2 lines 0 comments Download
M provider/manual/environ_test.go View 1 chunk +2 lines, -1 line 0 comments Download
M provider/openstack/local_test.go View 1 chunk +18 lines, -4 lines 0 comments Download
M provider/openstack/provider.go View 1 chunk +17 lines, -2 lines 0 comments Download

Messages

Total messages: 3
wallyworld
Please take a look.
9 years, 12 months ago (2014-04-24 02:27:16 UTC) #1
jameinel
I had a couple comments about the RegisterVocabulary function, but otherwise I think this LGTM. ...
9 years, 12 months ago (2014-04-24 04:58:16 UTC) #2
wallyworld
9 years, 12 months ago (2014-04-24 07:16:12 UTC) #3
https://codereview.appspot.com/96730043/diff/1/constraints/constraints.go
File constraints/constraints.go (right):

https://codereview.appspot.com/96730043/diff/1/constraints/constraints.go#new...
constraints/constraints.go:226: if attrTag == value {
On 2014/04/24 04:58:16, jameinel wrote:
> If values is a map, why would we iterate it in order to do the comparison?
> 
> Shouldn't we just do:
> 
> _, ok := values[attrTag]
> return ok

bah, it used to be a slice. bad refactoring. fixed.

https://codereview.appspot.com/96730043/diff/1/constraints/validation.go
File constraints/validation.go (right):

https://codereview.appspot.com/96730043/diff/1/constraints/validation.go#newc...
constraints/validation.go:87: valuesSlice = []interface{}{v}
On 2014/04/24 04:58:16, jameinel wrote:
> This seems really too loose that we allow:
> 
> RegisterVocabulary("attr", "foo")
> as well as
> RegisterVocabulary("attr", []string{"foo"})
> 
> Shouldn't we just error if TypeOf(v) != Slice or Array?
> Actually, a better syntax might be
> 
> RegisterVocabulary(attributeName string, allowedValues ...interface{})
> 
> That lets you do:
> RegisterVocabulary("attr", "foo")
> RegisterVocabulary("attr", "foo", "bar")
> and
> attrs = []string{"foo", "bar"} // read from somewhere else
> RegisterVocabulary("attr", attrs...)

Sadly this doesn't work because Go still treats on as []interface{} and the
other as []string, and so it won't compile:

eg

validator.RegisterVocabulary(constraints.Arch, supportedArches...)

cannot use supportedArches (type []string) as type []interface {} in function
argument

So I'll raise an error if the values param is not a slice/array.

> 
> I think that gives us the best flexibility and it still ensures that
> allowedValues is always a slice.
> Actually, I think it eliminates your need for all the reflection code
> completely, since all that is doing is turning a typed slice into a
> []interface{}, and I'm pretty sure the ... notation is going to be doing the
> work for us.
> 

I still need some reflection code to handle that the constraints values
themselves might be a slice eg mass tags. But I've reworked it on my local copy
to be cleaner.

https://codereview.appspot.com/96730043/diff/1/constraints/validation.go#newc...
constraints/validation.go:165: return int64(reflect.ValueOf(v).Uint())
On 2014/04/24 04:58:16, jameinel wrote:
> This is a little bit dangerous for Uint64. Can you actually do a range check
so
> we don't overflow? I realize there is a problem that you don't have a way to
> signal an error, but even a panic() is probably better than silently turning
> 2**64-1 (0xFFFFFFFFFFFFFFFF) into -1.
> 
> Actually, we could potentially cast it into a Float64 on overflow, though that
> won't let you do exact comparison (I think).

I thought about it but didn't think any of our constraints values could or would
be that big. Do we really think we'll encounter an overflow setting cpu-power or
cpu-cores or mem in MB etc?
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b