Remove State.GetModel() #7745

Merged
merged 21 commits into from Aug 15, 2017

Conversation

Projects
None yet
4 participants
Contributor

mjs commented Aug 15, 2017

Description of change

These changes remove the GetModel method from state.State. This gets rid of the last remaining problematic way for state.Model instances to be created. Model instances can now only be created using State.Model() which means the State a Model references is now guaranteed to be connected to the same model UUID as the Model. This paves the way for moving more functionality from State onto Model and is a prerequisite for upcoming feature work.

A follow-up PR will clean up the internals of state.Model, taking advantage of the fact that we know a Model's State is now the correct one.

This change has had many positive follow-on effects. More uses of the evil State.ForModel() were removed and the code and tests for some apiserver facades is now significantly cleaner. Some minor inefficiencies have also been dealt with.

QA steps

The areas at risk of breakage as a result of this change are model/controller creation and destruction, and model migrations, so exercise those:

$ juju bootstrap lxd source
# wait...
$ juju bootstrap lxd target
# wait...
$ juju switch source
$ juju add-model foo
$ juju deploy ubuntu
# wait...

# Check for significant errors
$ juju debug-log -m source:foo--replay --no-tail -l ERROR
$ juju debug-log -m source:controller --replay --no-tail -l ERROR

# Migrate
$ juju migrate foo target

# Wait for model to appear on target
$ watch juju status -m target:foo

# Add another unit
$ juju add-unit ubuntu
# wait...

# Check for significant errors
$ juju debug-log -m source:controller --replay --no-tail -l ERROR
$ juju debug-log -m target:controller --replay --no-tail -l ERROR
$ juju debug-log -m target:foo --replay --no-tail -l ERROR

# Destroy controllers
$ juju destroy-controller -y --destroy-all-models source
$ juju destroy-controller -y --destroy-all-models target

Documentation changes

N.A. - internal only

Bug reference

N.A.

mjs added some commits Aug 15, 2017

state: Add State.ModelActive helper
This new method will avoid the need for a State.GetModel call in the
modelworkermanager worker.
state: Add State.ModelExists
This will allow removal of a number of uses of State.GetModel().
apiserver/common: Remove State.GetModel usage
Use State.ModelExists() instead.
apiserver/facades/client/machinemanager: Avoid GetModel usage
Also removed a lot of unnecessary backend methods, and shim and mock
implementation.
apiserver/facades/client/cloud: Removed use of State.GetModel
Also removed unnessary backend interface methods and related mock/shim
implementations.
state: Avoid GetModel in AllWatcher
Was only being used to check for model existance anyway.
state: Avoid GetModel use in annotations
It was being used inefficiently and unnecessarily.
state: Avoid GetModel use in migration imports
GetModel is going away and this code is only doing an existance check.
state/testing: Add a StatePool to StateSuite
This will be useful in a number of tests.
state: Avoid further calls to GetModel
It's about to be removed.

So much lovely red deletions

apiserver/apiserver.go
gone := errors.IsNotFound(err)
dead := err == nil && model.Life() == state.Dead
if err != nil && !gone {
return errors.Trace(err)
}
+ release()
@wallyworld

wallyworld Aug 15, 2017

Owner

At this point, err could be not found. Will release() be valid then? Don't we want to check that err == nil?

@mjs

mjs Aug 15, 2017

Contributor

Good point. Will fix.

apiserver: Correctly handle model release
... when dealing with removed models.

Great! V. minor nits.

c.Assert(err, jc.ErrorIsNil)
- s.checkEnvironmentMatches(c, env.Model, stateEnv)
+ defer release()
@babbageclunk

babbageclunk Aug 15, 2017

Member

Maybe release this earlier? I guess it's just a test.

@mjs

mjs Aug 15, 2017

Contributor

I guess checkEnvironmentMatches doesn't call anything on the model which relies on the DB so calling release here is safe enough... probably not worth it though.

+ if err != nil {
+ return nil, nil, errors.Trace(err)
+ }
+ return m, func() { release() }, nil
@babbageclunk

babbageclunk Aug 15, 2017

Member

can't this just be return m, release, nil?

@mjs

mjs Aug 15, 2017

Contributor

Nope. The release func returned by GetModel is func () bool but the Pool interface simplifies that to func()

}
- return m, nil
+ return m, func() { release() }, nil
@babbageclunk

babbageclunk Aug 15, 2017

Member

Same here.

@mjs

mjs Aug 15, 2017

Contributor

Same as above

Contributor

mjs commented Aug 15, 2017

$$merge$$

Contributor

jujubot commented Aug 15, 2017

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

@jujubot jujubot merged commit c8d3e6c into juju:develop Aug 15, 2017

1 check passed

continuous-integration/jenkins/pr-merge This commit looks good
Details

@mjs mjs deleted the mjs:remove-GetModel branch Aug 15, 2017

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