Remove @local from local users #6388

Merged
merged 1 commit into from Oct 6, 2016

Conversation

Projects
None yet
4 participants
Owner

wallyworld commented Oct 6, 2016

Fixes: https://bugs.launchpad.net/juju/+bug/1596605
Fixes: https://bugs.launchpad.net/juju/+bug/1603841

Local users now no longer use the "@Local" suffix.

There's lots of small changes and a few larger ones. The many, many small changes are to stop calling user.Canonical() and instead use user.Id(). The Canonical() method no longer exists.

The larger change is the addition of upgrade steps. Database fields written with user@local need to be upgraded. The local client yaml files are also migrated. Note that there was a bunch of old upgrade code still present which was removed, and also some missing upgrade tests which were added.

QA: bootstrap from a beta. Upgrade juju. Check the machine log to ensure upgrades steps were run. Ensure that the local yaml files are updated. Do a db-dump and check the relevant fields. Ensure that Juju commands still work and existing permissions are still in place.
Also check that you can use an updated client with a rc2 server without upgrading. Ran various commands to grant and show permissions, deployed a charm etc.

Nothing glaring, will have to come back to this later. Have you tested that the updated client still works with an rc2 server without upgrading?

@@ -62,37 +82,3 @@ func ParseAccounts(data []byte) (map[string]AccountDetails, error) {
type accountsCollection struct {
ControllerAccounts map[string]AccountDetails `yaml:"controllers"`
}
-
-// TODO(axw) 2016-07-14 #1603841
@axw

axw Oct 6, 2016

Member

Please add "fixes ..." to the PR, and mark fix committed when this lands. I've just assigned it to you.

jujuclient/validation.go
@@ -88,7 +82,7 @@ func validateUser(name string) error {
}
func validateUserTag(tag names.UserTag) error {
- if tag.Id() != tag.Canonical() {
+ if tag.Id() != tag.Id() {
@axw

axw Oct 6, 2016

Member

Heh :)
Just drop this.

@wallyworld

wallyworld Oct 6, 2016

Owner

doh!
fixed

migration/precheck.go
@@ -163,15 +163,15 @@ func TargetPrecheck(backend PrecheckBackend, modelInfo coremigration.ModelInfo)
if err != nil {
return errors.Annotate(err, "retrieving models")
}
- canonicalOwner := modelInfo.Owner.Canonical()
+ canonicalOwner := modelInfo.Owner.Id()
@axw

axw Oct 6, 2016

Member

s/canonicalOwner/owner/?
or perhaps just use modelInfo.Owner.Id() inline below

Generally ok (mammoth effort!) but would like issues considered before approving.

)
var upgradesLogger = loggo.GetLogger("juju.state.upgrade")
-func AddPreferredAddressesToMachines(st *State) error {
@mjs

mjs Oct 6, 2016

Contributor

Thanks for noticing and removing all the old state upgrade funcs

state/upgrades.go
+ newId := id
+
+ // Take a copy of the current doc fields.
+ newDoc := make(bson.M)
@mjs

mjs Oct 6, 2016

Contributor

Using bson.M instead of bson.D will rearrange field ordering which makes me nervous. See https://bugs.launchpad.net/juju-core/+bug/1451674

We had helpers in this file in 1.25 do make reading and updating bson.D based documents easier. See: https://github.com/juju/juju/blame/1.25/state/upgrades.go#L1188

upgrades/operations.go
@@ -18,7 +18,7 @@ import (
// (below).
var stateUpgradeOperations = func() []Operation {
steps := []Operation{
- upgradeToVersion{version.MustParse("2.0.0"), []Step{}},
+ upgradeToVersion{version.MustParse("2.0.1"), stateStepsFor20()},
@mjs

mjs Oct 6, 2016

Contributor

Is this really supposed to be 2.0.1?

@wallyworld

wallyworld Oct 6, 2016

Owner

nope, oops.

upgrades/steps_20_test.go
@@ -24,6 +24,20 @@ type steps20Suite struct {
var _ = gc.Suite(&steps20Suite{})
+func (s *steps20Suite) TestStateStepsFor20(c *gc.C) {
@mjs

mjs Oct 6, 2016

Contributor

Consider doing this differently as per IRC discussion

axw approved these changes Oct 6, 2016

LGTM with a handful of small changes. Thank you.

apiserver/cloud/cloud.go
@@ -54,7 +54,7 @@ func NewCloudAPI(backend Backend, authorizer facade.Authorizer) (*CloudAPI, erro
if !ok {
return false
}
- return isAdmin || userTag.Canonical() == authUser.Canonical()
+ return isAdmin || userTag.Id() == authUser.Id()
@axw

axw Oct 6, 2016

Member

we should be able to just do userTag==authUser now (woohoo, thank you!)

apiserver/modelmanager/modelmanager.go
return nil
}
// We can't just compare the UserTags themselves as the provider part
// may be unset, and gets replaced with 'local'. We must compare against
// the Canonical value of the user tag.
- if m.apiUser.Canonical() == user.Canonical() {
+ if m.apiUser.Id() == user.Id() {
@axw

axw Oct 6, 2016

Member

m.apiUser == user

apiserver/modelmanager/modelmanager.go
@@ -245,7 +245,7 @@ func (m *ModelManagerAPI) CreateModel(args params.ModelCreateArgs) (params.Model
return result, errors.Trace(err)
}
} else {
- if ownerTag.Canonical() == controllerModel.Owner().Canonical() {
+ if ownerTag.Id() == controllerModel.Owner().Id() {
@axw

axw Oct 6, 2016

Member

ownerTag == controllerModel.Owner()

migration/precheck.go
for _, model := range models {
// If the model is importing then it's probably left behind
// from a previous migration attempt. It will be removed
// before the next import.
if model.UUID() == modelInfo.UUID && model.MigrationMode() != state.MigrationModeImporting {
return errors.Errorf("model with same UUID already exists (%s)", modelInfo.UUID)
}
- if model.Name() == modelInfo.Name && model.Owner().Canonical() == canonicalOwner {
+ if model.Name() == modelInfo.Name && model.Owner().Id() == modelInfo.Owner.Id() {
@axw

axw Oct 6, 2016

Member

model.Owner() == modelInfo.Owner

state/modeluser_test.go
c.Assert(modelUser.DisplayName, gc.Equals, user.DisplayName())
c.Assert(modelUser.Access, gc.Equals, permission.WriteAccess)
- c.Assert(modelUser.CreatedBy.Id(), gc.Equals, "createdby@local")
+ c.Assert(modelUser.CreatedBy.Id(), gc.Equals, "createdbycmdCredentialSuite")
@axw

axw Oct 6, 2016

Member

accidental sed?

state/modeluser_test.go
c.Assert(modelUser.DisplayName, gc.Equals, user.DisplayName())
c.Assert(modelUser.Access, gc.Equals, permission.WriteAccess)
- c.Assert(modelUser.CreatedBy.Id(), gc.Equals, "createdby@local")
+ c.Assert(modelUser.CreatedBy.Id(), gc.Equals, "createdbycmdCredentialSuite")
@axw

axw Oct 6, 2016

Member

and here?

state/upgrades.go
+ isId := field == "_id"
+ fieldVal, err := readBsonDField(doc, field)
+ if err != nil {
+ continue
@axw

axw Oct 6, 2016

Member

it's a bit alarming to ignore the error. can we either check for NotFound specifically, or otherwise change readBsonField to return a bool instead of an error?

Owner

wallyworld commented Oct 6, 2016

$$merge$$

Contributor

jujubot commented Oct 6, 2016

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

Contributor

jujubot commented Oct 6, 2016

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

Owner

wallyworld commented Oct 6, 2016

$$merge$$

Contributor

jujubot commented Oct 6, 2016

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

Contributor

jujubot commented Oct 6, 2016

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

Owner

wallyworld commented Oct 6, 2016

$$merge$$

Contributor

jujubot commented Oct 6, 2016

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

@jujubot jujubot merged commit 5fbbf92 into juju:master Oct 6, 2016

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