Update app config to use --reset as string var #6429

Merged
merged 1 commit into from Oct 11, 2016

Conversation

Projects
None yet
4 participants
Contributor

reedobrien commented Oct 11, 2016

This also allows simultaneous set/reset as with model-defaults and
model-config.

Refs: config command collapse spec https://goo.gl/yqrrPI

QA:

  1. Run all unit tests and they pass
  2. With an lxd cloud like (see Faster LXD for details on apt-http proxy and other items, or don't use them)
  3. juju bootstrap reed/lxd-app-config lxdtest
  4. juju deploy haproxy && juju deploy wordpress && juju deploy mysql && juju add-relation haproxy wordpress && juju add-relation wordpress mysql && juju expose haproxy
  5. juju config wordpress
verify output is [like this](http://paste.ubuntu.com/23156363/)
  1. juju config wordpress debug=yes

  2. juju config wordpress debug

    "yes"

  3. juju config wordpress --reset debug

  4. juju config wordpress debug

    "no"

  5. save the contents of the mysql settings to a file with `juju config mysql --format=yaml > mysql.yaml. It should look like this.
    11 Edit the file like this

  6. juju config mysql --file mysql.yaml

  7. for v in size type; do juju config mysql query-cache-$v;done

    1.2345679e+08
    "ON"

  8. juju config mysql --reset query-cache-size,query-cache-type

  9. for v in size type; do juju config mysql query-cache-$v;done

    0
    "OFF"

  10. juju config mysql query-cache-size=123456789 query-cache-type=DEMAND

  11. for v in size type; do juju config mysql query-cache-$v;done

    1.2345679e+08
    "ON"

  12. juju config mysql query-cache-size

    1.2345679e+08

  13. juju config mysql --reset query-cache-size

  14. juju config mysql query-cache-size

    0

  15. juju config mysql query-cache-type

DEMAND
  1. juju config mysql --reset query-cache-type

  2. juju config mysql query-cache-type

    "OFF"

  3. juju config mysql --reset

    error: flag needs an argument: --reset

  4. juju config mysql foo bar

    error: can only retrieve a single value, or all values

  5. juju kill-controller reed/lxd-app-config -y

Only a handful of comments.

@@ -66,7 +66,8 @@ type configCommand struct {
applicationName string
configFile cmd.FileVar
keys []string
- reset bool
+ reset []string // Holds the keys to be reset until parsed.
@perrito666

perrito666 Oct 11, 2016

Contributor

that comment is a doc, just put it on top of the field

// reset holds the keys..
reset []string
@reedobrien

reedobrien Oct 11, 2016

Contributor

That makes fmt indent all the variables after comments at different levels... plus it is unexported, just a note.

     applicationName string
     configFile      cmd.FileVar
     keys            []string
     // Holds the keys to be reset until parsed.
     reset []string
     // Holds the keys to be reset once parsed.
     resetKeys []string
     useFile   bool
     values    attributes

instead of

     applicationName string
     configFile      cmd.FileVar
     keys            []string
     reset           []string // Holds the keys to be reset until parsed.
     resetKeys       []string // Holds the keys to be reset once parsed.
     useFile         bool
     values          attributes
cmd/juju/application/config.go
- if len(args) == 0 {
- return errors.New("no configuration options specified")
+// parseResetKeys splits the keys provided to --reset after trimming any
+// leading or trailing comma. It then verifies that we haven't incorrectly
@perrito666

perrito666 Oct 11, 2016

Contributor

nitpick, this comment seems to be getting too much into implementation.

@reedobrien

reedobrien Oct 11, 2016

Contributor

simplified.

+ resetKeys = append(resetKeys, keys...)
+ }
+ for _, k := range resetKeys {
+ if strings.Contains(k, "=") {
@perrito666

perrito666 Oct 11, 2016

Contributor

This check can be done before the splitting and trimming.

@reedobrien

reedobrien Oct 11, 2016

Contributor

This is a good point. We could fail faster and there wouldn't be any loss of fidelity in the error message. However, a PR with this has already landed. I'd say if you think it is important enough we should open a bug and update all three items that now use --reset a,b,c.

cmd/juju/application/config.go
// Run implements the cmd.Command interface.
func (c *configCommand) Run(ctx *cmd.Context) error {
client, err := c.getAPI()
if err != nil {
return errors.Trace(err)
}
defer client.Close()
+ if len(c.resetKeys) > 0 {
+ err := c.resetConfig(client, ctx)
@perrito666

perrito666 Oct 11, 2016

Contributor

nit, you can if err:= blah; err != nil

@reedobrien

reedobrien Oct 11, 2016

Contributor

I can go either way... but OK. Changed.

cmd/juju/application/config.go
+ }
+ nv, err := readValue(ctx, v[1:])
+ if err != nil {
+ return nil, err
@perrito666

perrito666 Oct 11, 2016

Contributor

Trace?

@reedobrien

reedobrien Oct 11, 2016

Contributor

I just moved that below where it was used because that is someone else's nit:) I didn't read through the existing code carefully though. Nice catch -- fixed :)

@@ -169,7 +169,19 @@ func (s *configCommandSuite) TestSetCommandInit(c *gc.C) {
// --reset and no config name provided
err = coretesting.InitCommand(application.NewConfigCommandForTest(s.fake), []string{"application", "--reset"})
- c.Assert(err, gc.ErrorMatches, "no configuration options specified")
+ c.Assert(err, gc.ErrorMatches, "flag needs an argument: --reset")
@perrito666

perrito666 Oct 11, 2016

Contributor

I might be mistaken but I believe the "can only retrieve one or all... " path is not tested.

@reedobrien

reedobrien Oct 11, 2016

Contributor

Line 110. I kept the existing test style here, which is a bit different than the other two places where this collapse is happening (and these came from three different commands, too: get, set, unset). Once it lands and it is decided we are going to keep it, we can make a pass at refactoring the three suites to be more congruous.

@reedobrien

reedobrien Oct 12, 2016

Contributor

fixed...

reedobrien added a commit to reedobrien/juju that referenced this pull request Oct 11, 2016

reedobrien added a commit to reedobrien/juju that referenced this pull request Oct 11, 2016

Update app config to use --reset as string var
This also allows simultaneous set/reset as with model-defaults and
model-config.

Refs: config command collapse spec https://goo.gl/yqrrPI
Contributor

reedobrien commented Oct 11, 2016

$$merge$$

Contributor

jujubot commented Oct 11, 2016

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

@jujubot jujubot merged commit 5444b45 into juju:master Oct 11, 2016

@reedobrien reedobrien deleted the reedobrien:feature/app-config-reset-as-string branch Oct 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment