2.1 kvm race test fixes 1664437 #6988

Merged
merged 8 commits into from Feb 22, 2017

Conversation

Projects
None yet
3 participants
Owner

jameinel commented Feb 15, 2017

This isn't critical for 2.1.0, as it is intended to be a code refactoring at testing change, but it does add tests to an area of the code that I've been working in that did not have much (if any). It also removes some of the code paths that were replaced, but left around because of what testing there was available.

Description of change

PrepareHost wasn't tested directly, and even before my last refactoring, was only loosely tested. We can't test all of ContainerSetup because part of its function is to apt install lxd and actually deploy containers. So this is splitting off a portion of that into a helper object that can have its functionality overridden.

QA steps

go test

Though if you want to make sure I haven't broken the functionality

  $ juju bootstrap maas
  $ juju deploy ubuntu --to lxd:0 -m controller

And see that the host networking is properly updated for the container.

Documentation changes

Internal only refactoring.

Bug reference

This was wanting to get the code tested as part of fixing lp:1664437. It doesn't change the fix for it, but it does add tests that we are correctly interacting with a 'lock' object.

jameinel added some commits Feb 14, 2017

Start working on fixing the test suite.
We have stripped out the functions that we don't want exposed, and retargetted
the test suite into the proper functions.
Not all tests pass.
(broken) considering pulling the 'prepareHost' function out into a se…
…parate testable object.

It has a lot of tentacles, and I'm worried it doesn't hold its weight vs the cost to do it.
Refactor 'prepareHost' into an object and test it.
This adds a bit of indirection, but ultimately makes it actually testable that we're
triggering the lock requests, etc at the right time.
worker/provisioner/host_preparer.go
+)
+
+// we could pull this from
+// github.com/juju/juju/cloudconfig/instancecfg.DefaultBridgePrefix, but it
@axw

axw Feb 16, 2017

Member

AFAICT, the instancecfg.DefaultBridge* consts don't belong in that package anymore. The code in the MAAS provider referencing it appears to be redundant (we add bridge-utils for all machines via cloud-init).

worker/provisioner/host_preparer.go
+// feels bad to import that whole package for a single constant.
+const DefaultBridgePrefix = "br-"
+
+type PrepareAPI interface {
@axw

axw Feb 16, 2017

Member

Please give the interface and its methods a brief comment each

worker/provisioner/host_preparer.go
+ }
+}
+
+// Prepare applies changes to the host machine in that are necessary to create
@axw

axw Feb 16, 2017

Member

delete "in" ?

worker/provisioner/host_preparer.go
+
+// Prepare applies changes to the host machine in that are necessary to create
+// the requested container.
+func (hp *HostPreparer) Prepare(containerTag names.MachineTag, log loggo.Logger) error {
@axw

axw Feb 16, 2017

Member

can loggo.Logger be made part of the struct, rather than an arg? feels like it should be part of the context rather than the args

worker/provisioner/host_preparer.go
+
+ log.Debugf("Bridging %+v devices on host %q for container %q with delay=%v, acquiring lock %q",
+ devicesToBridge, hp.machineTag.String(), containerTag.String(), reconfigureDelay, hp.lockName)
+ // TODO(jam): 2017-02-08 figure out how to thread catacomb.Dying() into
@axw

axw Feb 16, 2017

Member

delete TODO?

@jameinel

jameinel Feb 22, 2017

Owner

It is still valid, but I'll move it to the other location where we're passing AbortChan: nil
StartInstance doesn't take an Abort chan, arguably it really should, as it is one of those things that can actually take a long time.

worker/provisioner/host_preparer_test.go
+
+func (s *hostPreparerSuite) TestPrepareHostChangesUnsupported(c *gc.C) {
+ s.Stub.SetErrors(
+ errors.NotSupportedf("container address allocation"),
@axw

axw Feb 16, 2017

Member

HostChangesForContainer shouldn't ever return that error should it? Doesn't it just change its behaviour based on whether addresses can be allocated for containers?

If I'm wrong, maybe leave a comment explaining the scenario this test covers? If I'm right, can we use a more realistic (or arbitrary, e.g. RPC failure) error?

@jameinel

jameinel Feb 22, 2017

Owner

It was certainly an error that we were hitting in the past, and I wouldn't rule out that we would never see it.
This is mostly about 'if we get an error at this stage' we treat it as a concrete provisioning failure, instead of ignoring it and continuing. I can add some comments about it.

worker/provisioner/host_preparer_test.go
+ // This is what the AcquireLock should look like
+ params.AcquireLockFunc = func(abort <-chan struct{}) (mutex.Releaser, error) {
+ s.Stub.AddCall("AcquireLockFunc")
+ spec := mutex.Spec{
@axw

axw Feb 16, 2017

Member

Can we pare this back a bit please, so it's less integration and more unit test? We don't really care about mutexes specifically here. This should be sufficient to test the abort behaviour:

params.AcquireLockFunc = func(abort <-chan struct{}) (mutex.Releaser, error) {
    select {
    case <-abort:
        return nil, errors.New("cancelled acquiring mutex")
    case <-time.After(coretesting.LongWait):
        return nil, errors.New("timed out waiting for mutex")
    }
}
@jameinel

jameinel Feb 22, 2017

Owner

👍 I also added a test that the abort channel that we set up is being properly passed into the AcquireLock.

axw approved these changes Feb 22, 2017

worker/provisioner/host_preparer.go
@@ -32,6 +41,7 @@ type HostPreparerParams struct {
CreateBridger func() (network.Bridger, error)
AbortChan <-chan struct{}
MachineTag names.MachineTag
+ Logger loggo.Logger
@axw

axw Feb 22, 2017

Member

whitespace looks fishy (and in a couple of other spots), did you go fmt?

Owner

jameinel commented Feb 22, 2017

Owner

jameinel commented Feb 22, 2017

$$merge$$

Contributor

jujubot commented Feb 22, 2017

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

Contributor

jujubot commented Feb 22, 2017

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

Owner

jameinel commented Feb 22, 2017

$$merge$$ looks like Windows got very confused, will try again.

Contributor

jujubot commented Feb 22, 2017

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

@jujubot jujubot merged commit 2e47fac into juju:2.1 Feb 22, 2017

1 check passed

github-check-merge-juju Built PR, ran unit tests, and tested LXD deploy. Use !!.*!! to request another build. IE, !!build!!, !!retry!!
Details

@jameinel jameinel deleted the jameinel:2.1-kvm-race-test-fixes-1664437 branch Apr 22, 2017

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