New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/add region to model defaults cli #6308
feature/add region to model defaults cli #6308
Conversation
Also changes --reset to be a stringvar. All tests pass at this point but it needs more tests for the new features. It also adds a lot of command arg scrutiny and tests This was originally part of juju#6269 but has been split from the backend bits here. Addtionally per review in pr juju#6269, updates the reset variable so we can specify it repeatedly and reset all the keys set in all the reset flags. Ensure the cloud is always set, even if we only get the region on the CLI. Finally, create new region settings if they weren't created at bootstrap. Refs: config command collapse spec https://goo.gl/yqrrPI Refs: model-config-tree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation text for model-defaults needs updating.
I feel like the logic for Init could be simplified, e.g. moving some of the validation for mixed positional args earlier, so we can get consistent error messages. The tests are fairly comprehensive, so I could live with that coming later.
@@ -8,12 +8,18 @@ import ( | |||
"sort" | |||
"strings" | |||
|
|||
"gopkg.in/juju/names.v2" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete (the blank) line
key string | ||
resetKeys []string | ||
cloudName, regionName string | ||
// reset holds the contents of the reset flag. It contains a list of comma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is misleading. It's only true until after Init is called, when we call parseResetKeys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll modify it. I am fine with removing many of the comments. I mostly wrote them out to rubber duck the logistics. Maybe they're useful to future readers or maybe confusing.
} | ||
|
||
// Init implements part of the cmd.Command interface. | ||
// Abandon all hope ye who enter here.... | ||
// This needs to parse the a command line invocation as defined in | ||
// https://goo.gl/yqrrPI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should drop the doc reference. It's Canonical-only at the moment, though doesn't seem like it needs to be. It's not really adding anything beyond what you've described here AFAICT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped.
// Abandon all hope ye who enter here.... | ||
// This needs to parse the a command line invocation as defined in | ||
// https://goo.gl/yqrrPI. | ||
// So the following 3 lines are all equivalent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just state that flags may be interspersed, and leave it at that? You've stated "are equivalent" in numerous examples below, where I think saying it once would be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. And reduced the number of examples.
// This needs to parse the a command line invocation as defined in | ||
// https://goo.gl/yqrrPI. | ||
// So the following 3 lines are all equivalent: | ||
// juju model-defaults aws/us-east-1 foo=baz --reset bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also indent the examples to clearly separate from the prose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indented.
} | ||
// allKeys gets the all the set and reset keys to validate. This should get | ||
// caught in Init so maybe we don't need it here too. | ||
// TODO(reviewer) Should we keep this and the init check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's still necessary to check that they're known, but not that they're duplicated. also, the functional literal seems unnecessary? wouldn't the following suffice?
allKeys := c.resetKeys[:]
for k := range c.values {
allKeys = append(allKeys, k)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better thanks.
}, { | ||
description: "test invalid positional args with set", | ||
args: []string{"a=b", "b", "c=d"}, | ||
errorMatch: `expected "key=value", got "b"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really should be getting the same error here and in the test below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that. If the key only is at the end or beginning the user may have thought they were interspersing get and set args, but if the key only is in the middle of set args it's more likely they miss-typed. But that is the problem with many possibilities in a single command:/ The error above IIRC comes from trying to parse the key values with keyvalues.Parse. The error below comes because we knew it was not part of the key values.
Are you saying we should check for the above error and return the below error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying we should check for the above error and return the below error?
I'm thinking we should check for mixed get/set up-front, before we call keyvalues.Parse.
settings, err = createSettings(st, globalSettingsC, key, attrs) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil? no point doing an update with the same values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Thought about it, thanks for the push. Updated.
err = s.State.UpdateModelConfigDefaultValues(attrs, nil, rspec) | ||
c.Assert(err, jc.ErrorIsNil) | ||
|
||
// Then check in another state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking in another mongo session seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and paste testing. Removed.
@@ -95,16 +230,16 @@ func (s *DefaultsCommandSuite) TestDefaultsInit(c *gc.C) { | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add tests that verify that the correct cloud/region are passed through to the API calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't tell if I've started a new review or am commenting on yours.
return errors.New("specifying a region when retrieving defaults for a setting is invalid") | ||
case !regionSpecified && resetSpecified: | ||
// It makes no sense to supply a positional arg that isn't a region if | ||
// we are resetting a region, so we must have gotten an invalid region. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resetting keys in a region...
// already. | ||
return errors.New("cannot retrieve defaults for a key and reset args at the same time") | ||
default: | ||
// This should be unreachable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched (hah) to ifs.
// It doesn't make sense to specify a region unless we are resetting | ||
// values here. | ||
return errors.New("specifying a region when retrieving defaults is invalid") | ||
case regionSpecified && resetSpecified: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh. Thanks.
switch { | ||
case numArgs == 2 && !regionSpecified && resetSpecified: | ||
// It makes no sense to supply a positional arg that isn't a region if | ||
// we are resetting a region, so we must have gotten an invalid region. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resetting keys in a region...
} | ||
// allKeys gets the all the set and reset keys to validate. This should get | ||
// caught in Init so maybe we don't need it here too. | ||
// TODO(reviewer) Should we keep this and the init check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better thanks.
for _, key := range keys() { | ||
|
||
keys := allkeys() | ||
repeats := map[string]int{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
@@ -95,16 +230,16 @@ func (s *DefaultsCommandSuite) TestDefaultsInit(c *gc.C) { | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking
}, { | ||
description: "test invalid positional args with set", | ||
args: []string{"a=b", "b", "c=d"}, | ||
errorMatch: `expected "key=value", got "b"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that. If the key only is at the end or beginning the user may have thought they were interspersing get and set args, but if the key only is in the middle of set args it's more likely they miss-typed. But that is the problem with many possibilities in a single command:/ The error above IIRC comes from trying to parse the key values with keyvalues.Parse. The error below comes because we knew it was not part of the key values.
Are you saying we should check for the above error and return the below error?
settings, err = createSettings(st, globalSettingsC, key, attrs) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Thought about it, thanks for the push. Updated.
err = s.State.UpdateModelConfigDefaultValues(attrs, nil, rspec) | ||
c.Assert(err, jc.ErrorIsNil) | ||
|
||
// Then check in another state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and paste testing. Removed.
Refs: config command collapse spec https://goo.gl/yqrrPI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add those tests and address new issues, then you'll be good to go.
// juju model-defaults aws/us-east-1 foo=baz --reset bar | ||
// juju model-defaults aws/us-east-1 --reset bar foo=baz | ||
// juju model-defaults --reset bar aws/us-east-1 foo=baz | ||
// This needs to parse the a command line invocation to reset and set, or get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the a/a/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
// juju model-defaults aws/us-east-1 foo=baz --reset bar | ||
// | ||
// If aws is the cloud of the current or specified controller -- specified by | ||
// -c somecontroller or -m somecontroller:somemodel -- then the following would |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you cannot use "-m" on a controller command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -292,6 +280,12 @@ func (c *defaultsCommand) parseCloudRegion(args []string) ([]string, error) { | |||
region = cr | |||
} | |||
|
|||
// NB(redir) http://pad.lv/1627162 -- We don't disallow "=" in region |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the format
// TODO(redir) YYYY-MM-DD #1627162
// We don't disallow "=" in region names,
// but probably should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests to show cloud and region are conveys through the call to the api.
Refs: config command collapse spec https://goo.gl/yqrrPI
Refs: config command collapse spec https://goo.gl/yqrrPI
@axw @wallyworld ready for another look. |
Thanks @axw |
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
Also changes --reset to be a stringvar. All tests pass at this point but
it needs more tests for the new features. It also adds a lot of command
arg scrutiny and tests
This was originally part of #6269 but has been split from the backend
bits here. Addtionally per review in pr #6269, updates the reset variable
so we can specify it repeatedly and reset all the keys set in all the
reset flags.
Ensure the cloud is always set, even if we only get the region on the
CLI. Finally, create new region settings if they weren't created at
bootstrap.
Refs: config command collapse spec https://goo.gl/yqrrPI
Refs: model-config-tree
QA:
bootstrap a controller with settings similar to
http://paste.ubuntu.com/23080517/
verify the controller val was reset
verify it was reset in us-east-1.
verify both items were set on us-west-2
verify no-proxy was changed and agent-stream reset
verify us-east-1 is set again
be sure the controller default was set again.
error: invalid region specified: "us-east-2" # verify this error.
... Do other things to try breaking it.