cmd/juju/user: refactor login command #7136

Merged
merged 1 commit into from Mar 23, 2017

Conversation

Projects
None yet
8 participants
Owner

rogpeppe commented Mar 22, 2017

We integrate the two kinds of login, so local user login
is orthogonal to whether you're logging into a public controller.

Logging into a controller is now idempotent - no message
will be printed unless the account or controller have changed.

The -u (--user) flag now takes the username as its argument,
so the argument to juju login is always now the controller domain.

Also add a few tests for existing untested behaviour and integrate
the two login test suites (but left them in two separate files for now
so that the diff looks better).

To QA, try "juju login" with as many different combinations as possible.

LGTM

cmd/juju/user/login.go
- defer api.Close()
- mm := modelmanager.NewClient(api)
+ listModels = func(c api.Connection, userName string) ([]apibase.UserModel, error) {
+ mm := modelmanager.NewClient(c)
cmd/juju/user/login.go
- if ctl.ControllerUUID == controllerDetails.ControllerUUID {
- // TODO(rogpeppe) lp#1614010 Succeed but override the account details in this case?
- return errors.Errorf("controller is already registered as %q", name)
+var errAlreadyLoggedIn = errors.Errorf(`already logged in
@mhilton

mhilton Mar 22, 2017

Member

It seems to me that there's something icky about having this sort of formatting embedded in an error.

@rogpeppe

rogpeppe Mar 22, 2017

Owner

Yes, but... alternative suggestions?

@nskaggs

nskaggs Mar 22, 2017

Owner

Might it be possible to be clearer to users who are used to the 'controller already registered as' to be more explicit that the user is already logged into the controller in question, and it's available to them? Perhaps just adding the controller name / location to this message?

@rogpeppe

rogpeppe Mar 23, 2017

Owner

The error that's printed already mentions the controller name. I made it mention the user name too.

Looks good. I've left some suggestions for better error messages. I fell that end users will not understand the wording of what's there now.

- fset.BoolVar(&c.forceUser, "u", false, "log into the current controller as a local user")
- fset.BoolVar(&c.forceUser, "user", false, "")
+ fset.StringVar(&c.username, "u", "", "log in as this local user")
+ fset.StringVar(&c.username, "user", "", "")
@wallyworld

wallyworld Mar 23, 2017

Owner

probably should have a description here too, making the distinction that this flag is used to specify a local user

@rogpeppe

rogpeppe Mar 23, 2017

Owner

As they both refer to the same variable, they're treated as aliases and the same description is used for both (taken from the shortest flag as per the gnuflag docs).

cmd/juju/user/login.go
+ } else if controllerDetails == nil {
+ // No controller found and no domain specified - we
+ // have no idea where we should be logging in.
+ return errors.Errorf("domain not specified and controller does not exist")
@wallyworld

wallyworld Mar 23, 2017

Owner

the end user has no idea what a domain is.
can we use the term "host name" or something?
".. and controller does not exist" is also not clear.
what about "... and there is no current controller registered" or something like that

@rogpeppe

rogpeppe Mar 23, 2017

Owner

Unfortunately, "host name" isn't accurate either, as it can refer to one of the publicly defined controller aliases. "no current controller registered" isn't quite right either, as when the -c flag is specified we might not be talking about the current controller. I'll try to think of something else.

@rogpeppe

rogpeppe Mar 23, 2017

Owner

I made some changes...

+ // The domain we're trying to log into doesn't match the
+ // existing controller.
+ return errors.Errorf(`
+controller at %q does not match existing controller.
@wallyworld

wallyworld Mar 23, 2017

Owner

An end user would not really grok this message I don't think.
How about something like

Connection details for controller %q have changed.
You can remove the outdated controller details using
"juju unregister %s".
To login to a different controller, use the -c flag to specify another name"

urosj approved these changes Mar 23, 2017

The error messages are clearer now, ty.

Owner

rogpeppe commented Mar 23, 2017

$$merge$$

Contributor

jujubot commented Mar 23, 2017

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

Owner

rogpeppe commented Mar 23, 2017

$$merge$$

Contributor

jujubot commented Mar 23, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10546

Member

anastasiamac commented Mar 23, 2017

$$merge$$

Maybe unrelated failure on windows: FAIL: :243: UpgradeCharmStoreResourceSuite.SetUpTest

Contributor

jujubot commented Mar 23, 2017

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

Contributor

jujubot commented Mar 23, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10548

Member

anastasiamac commented Mar 23, 2017

$$merge$$

and this time because:
FAIL: state_test.go:197: StateSuite.TestNoModelDocs
...

[LOG] 0:00.151 DEBUG juju.mongo dialled mongodb server at "127.0.0.1:43363"
state_test.go:199:
c.Assert(s.State.EnsureModelRemoved(), gc.ErrorMatches,
fmt.Sprintf(found documents for model with uuid %s: \d+ constraints doc, \d+ leases doc, \d+ modelusers doc, \d+ settings doc, \d+ statuses doc, s.State.ModelUUID()))
... error string = "found documents for model with uuid 7bfe98b6-7282-48d4-8e37-9b90fb3da4f1: 1 constraints doc, 1 modelusers doc, 1 settings doc, 1 statuses doc"
... regex string = "found documents for model with uuid 7bfe98b6-7282-48d4-8e37-9b90fb3da4f1: \d+ constraints doc, \d+ leases doc, \d+ modelusers doc, \d+ settings doc, \d+ statuses doc"

cmd/juju/user: refactor login command
We integrate the two kinds of login, so local user login
is orthogonal to whether you're logging into a public controller.

Logging into a controller is now idempotent - no message
will be printed unless the account or controller have changed.

The -u (--user) flag now takes the username as its argument,
so the argument to juju login is always now the controller domain.

Also add a few tests for existing untested behaviour and integrate
the two login test suites (but left them in two separate files for now
so that the diff looks better).
Owner

rogpeppe commented Mar 23, 2017

$$merge$$

Contributor

jujubot commented Mar 23, 2017

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

@jujubot jujubot merged commit 012eebe into juju:develop Mar 23, 2017

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