Skip to content
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

Merged

Conversation

reedobrien
Copy link
Contributor

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:

  1. Run all unit tests and all pass.
  2. juju bootstrap reed/aws/us-west-1 --build-agent

    bootstrap a controller with settings similar to

    http://paste.ubuntu.com/23080517/

  3. juju model-defaults --reset no-proxy

    verify the controller val was reset

  4. juju model-defaults --reset no-proxy us-east-1

    verify it was reset in us-east-1.

  5. juju model-defaults us-west-2 no-proxy=west-2 agent-stream=foobar

    verify both items were set on us-west-2

  6. juju model-defaults us-west-2 no-proxy=west-updated --reset agent-stream

    verify no-proxy was changed and agent-stream reset

  7. juju model-defaults awstest/us-east-1 no-proxy=https://foo-east

    verify us-east-1 is set again

  8. juju model-defaults no-proxy=https://local

    be sure the controller default was set again.

  9. juju model-defaults us-east-2 no-proxy=foo
    error: invalid region specified: "us-east-2" # verify this error.
    ... Do other things to try breaking it.

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
Copy link
Contributor

@axw axw left a 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"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d?

Copy link
Contributor

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
Copy link
Contributor

@axw axw Sep 23, 2016

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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:
Copy link
Contributor

@axw axw Sep 23, 2016

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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?
Copy link
Contributor

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)
}

Copy link
Contributor Author

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"`,
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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)
}
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
}

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking

Copy link
Contributor Author

@reedobrien reedobrien left a 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.
Copy link
Contributor Author

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.
Copy link
Contributor Author

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:
Copy link
Contributor Author

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.
Copy link
Contributor Author

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?
Copy link
Contributor Author

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{}
Copy link
Contributor Author

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) {
}

Copy link
Contributor Author

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"`,
Copy link
Contributor Author

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)
}
Copy link
Contributor Author

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.
Copy link
Contributor Author

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
Copy link
Contributor

@axw axw left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/the a/a/

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor Author

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.

@reedobrien
Copy link
Contributor Author

@axw @wallyworld ready for another look.

@reedobrien
Copy link
Contributor Author

$$merge$$

Thanks @axw

@jujubot
Copy link
Collaborator

jujubot commented Oct 6, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit d7a9d78 into juju:master Oct 7, 2016
@reedobrien reedobrien deleted the feature/add-region-to-model-defaults-cli branch October 7, 2016 00:47
@reedobrien reedobrien restored the feature/add-region-to-model-defaults-cli branch October 12, 2016 23:57
@reedobrien reedobrien deleted the feature/add-region-to-model-defaults-cli branch October 20, 2016 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants