Factor out common methods #6893

Merged
merged 1 commit into from Jan 31, 2017

Conversation

Projects
None yet
3 participants
Owner

jameinel commented Jan 31, 2017

The associated methods really didn't belong on Machine, as it was dealing with how to relate 2 machine objects (a machine with its container).
We also want to have more flexibility for setting different policies for how we will be doing bridging. This is a first step towards pulling out the rough shape of that work.
It also gives us a better surface area for injecting more configuration into the system.
Potentially this lets us write tests that don't rely on state, but to make it fast to iterate, I pulled across the Database based tests.
This is simply a refactor, none of the functionality has changed.

A few comments but LGTM.

network/containerizer/bridgepolicy.go
+}
+
+// Machine describes either a host machine, or a container machine. Either way
+// *state.Machine should fulfill the interface in real code.
@frobware

frobware Jan 31, 2017

Contributor

What would "real code" be in this case?

network/containerizer/bridgepolicy.go
+type Machine interface {
+ Id() string
+ AllSpaces() (set.Strings, error)
+ LinkLayerDevicesForSpaces([]string) (map[string][]*state.LinkLayerDevice, error)
@frobware

frobware Jan 31, 2017

Contributor

The return could just be []*state.LinkLayerDevice, err. From a callers perspective order may be important. And the result can be indexed via its input []string.

@jameinel

jameinel Jan 31, 2017

Owner

we are mapping them by space name, not by their device name.

network/containerizer/bridgepolicy.go
+ if err != nil {
+ return nil, errors.Trace(err)
+ }
+ logger.Debugf("container %q not qualified to a space, host machine %q is using spaces %v",
@frobware

frobware Jan 31, 2017

Contributor

Do we want to quote the space name output as we have done elsewhere? (IIRC, we had a function to do this.)

@jameinel

jameinel Jan 31, 2017

Owner

yes we should, thanks for the catch.

state/machine_linklayerdevices.go
- return nil
+func DefineEthernetDeviceOnBridge(name string, hostBridge *LinkLayerDevice) (LinkLayerDeviceArgs, error) {
+ if hostBridge.Type() != BridgeDevice {
+ return LinkLayerDeviceArgs{}, errors.Errorf("hostBridge must be a Bridge Device not %q", hostBridge.Type())
@frobware

frobware Jan 31, 2017

Contributor

The hostBridge string doesn't seem something like a human would digest.

@jameinel

jameinel Jan 31, 2017

Owner

getting this would be a programming error. Thoughts on better phrasing?
"can only create an Ethernet device on a bridge not %q"
better?

+ s.machine, err = s.State.AddMachine("quantal", state.JobHostUnits)
+ c.Assert(err, jc.ErrorIsNil)
+
+ //s.otherState = s.NewStateForModelNamed(c, "other-model")
@frobware

frobware Jan 31, 2017

Contributor

If this is dead code can we remove it?

Owner

jameinel commented Jan 31, 2017

$$merge$$

Contributor

jujubot commented Jan 31, 2017

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

Contributor

jujubot commented Jan 31, 2017

Build failed: Generating tarball failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10155

Refactor 'BridgePolicy' out of Machine.
They were a bunch of methods that really didn't belong on Machine,
so we moved them out into their own type, and bring along its test suite.

Move netBondReconfigureDelay to be initialization instead of a parameter.
Owner

jameinel commented Jan 31, 2017

$$merge$$

Contributor

jujubot commented Jan 31, 2017

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

@jujubot jujubot merged commit 4f6c4f2 into juju:2.1 Jan 31, 2017

@jameinel jameinel deleted the jameinel:2.1-refactor-containerizer branch Apr 22, 2017

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