Fixes lp:1575676: Detect LXD default profile's bridge name and use it #5871

Merged
merged 7 commits into from Aug 2, 2016

Conversation

Projects
None yet
4 participants
Contributor

dimitern commented Jul 26, 2016

Changed tools/lxdclient code not to assume the default LXD bridge name
is always "lxdbr0". Instead, the "default" profile's bridge device name
is determined and used in Client.

See http://pad.lv/1575676 for details.

QA steps to verify the fix:

  1. LXD provider (where it appears):
   $ sudo dpkg-reconfigure -p medium lxd
   # rename the lxdbr0 to something else, keep the rest the same.
   $ juju bootstrap --upload-tools lxd localhost
   # expect success, before this fix it failed to complete due to lxdbr0
   # not existing. 
   $ juju deploy ubuntu # also OK
  1. Manual provider (for completeness):
   $ lxc launch ubuntu:xenial man-x1
   $ lxc info man-x1 | grep eth0    # find eth0's address, e.g. 10.0.1.2
   $ lxc file push ~/.ssh/<ssh-key.pub> man-x1/home/ubuntu/.ssh/authorized_keys
   # to allow the below to work
   $ ssh ubuntu@10.0.1.2            # should work now
   $ juju bootstrap --upload-tools man manual/10.0.1.2
Contributor

dimitern commented Aug 1, 2016

@wallyworld As OCR, can you have a look please?

tools/lxdclient/config.go
+ // profile's bridge device name, otherwise set it up. If this lxd has never
+ // had anything done to it, it hasn't been socket activated yet, and the
+ // bridge won't exist. So, we rely on this poke to get the bridge started.
+
@fwereade

fwereade Aug 1, 2016

Contributor

d?

@dimitern

dimitern Aug 2, 2016

Contributor

Good point - removing.

provider/lxd/config.go
- return cfg, errors.Trace(err)
- }
- return cfg, nil
+ return cfg.WithDefaults()
@fwereade

fwereade Aug 1, 2016

Contributor

every such short-circuit makes me have to stop and double-check that there's no opportunity for hidden-nils to creep in; even though this one is safe, it's annoying to have to stop and check what really happens when you use that construct. revert?

@dimitern

dimitern Aug 2, 2016

Contributor

Reverting.

Contributor

fwereade commented Aug 1, 2016

LGTM

tools/lxdclient/client.go
- * So, we do some basic rendering here to make it look slightly less
- * ugly.
- */
+ // This is sort of a hack, but it's enforced in the LXD code itself as well.
@babbageclunk

babbageclunk Aug 2, 2016

Member

Was this just reformatting the comment? It's a bit confusing - probably better to leave it in a non-standard format than muddy the water with a formatting change in the middle of changing behaviour.

@dimitern

dimitern Aug 2, 2016

Contributor

Yeah, simple reformatting. Will revert as suggested.

tools/lxdclient/client.go
+ // Otherwise, if it looks like it's pointing at bridge, and it is the
+ // default "lxdbr0", verify that is configured correctly.
+ eth0, ok := config.Devices[configEth0]
+ if !ok || eth0[configTypeKey] != configTypeNic || eth0[configNicTypeKey] != configBridged {
@babbageclunk

babbageclunk Aug 2, 2016

Member

I don't think this matches the comment above - if eth0 isn't in config.Devices it will return an error. (Unless maybe the code further up does the "use whatever they set up" bit?) Should it be

if ok && (eth0[configTypeKey] != configTypeNic || eth0[configNicTypeKey] != configBridged) {

instead?

@dimitern

dimitern Aug 2, 2016

Contributor

Good catch! Will update the comment and change the conditional as suggested.

@dimitern

dimitern Aug 2, 2016

Contributor

I changed the logic to first check for !ok and return an error when eth0 is missing, and then check its attributes. Seems to read better now.

tools/lxdclient/client.go
+
+ bridgeConfig, err := ioutil.ReadFile(LXDBridgeFile)
+ if err != nil {
+ if !os.IsNotExist(err) {
@babbageclunk

babbageclunk Aug 2, 2016

Member

Flip the sense of this and switch the legs of the if around - double negatives are confusing!

Actually, os.IsNotExist can take nil, so it might be clearer to get rid of the nesting:

if os.IsNotExist(err) {
    return "", bridgeConfigError("lxdbr0 configured but no config file found at " + LXDBridgeFile)
else if err != nil {
    return "", errors.Trace(err)
}
@dimitern

dimitern Aug 2, 2016

Contributor

Nice! This is mostly pre-existing code factored out into a function, but will change as suggested.

tools/lxdclient/client.go
- */
- if name != "lxdbr0" {
+ // If we're here, we want the bridge to be configured because the
+ // default profile that juju will use says lxdbr0. So let's fail if
@babbageclunk

babbageclunk Aug 2, 2016

Member

This comment needs updating - it still talks about lxdbr0. (Which would retroactively justify the reformatting! ;)

@dimitern

dimitern Aug 2, 2016

Contributor

Fair point - will update the comment and the error below as needed.

@dimitern

dimitern Aug 2, 2016

Contributor

Actually, no - this specific helper func is only called to verify the default lxdbr0 config is sane. If the user changed the default profile's bridge name, it won't be ever called, so the comment still applies (will revert the formatting change though).

tools/lxdclient/config.go
return cfg, errors.Trace(err)
}
- remote, err := cfg.Remote.UsingTCP()
+ remote, err := cfg.Remote.UsingTCP(client.defaultProfileBridgeName)
@babbageclunk

babbageclunk Aug 2, 2016

Member

It might be worth keeping the note that this will start the bridge if it's never been activated?

@dimitern

dimitern Aug 2, 2016

Contributor

Updated.

Member

babbageclunk commented Aug 2, 2016

LGTM other than the question about the if !ok || ... logic in verifyDefaultProfileBridgeConfig.

Contributor

dimitern commented Aug 2, 2016

$$fixes-1575676$$
$$JFDI$$

Contributor

jujubot commented Aug 2, 2016

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

@jujubot jujubot merged commit df65efd into juju:master Aug 2, 2016

@dimitern dimitern deleted the dimitern:lp-1575676-lxd-bridge branch Aug 2, 2016

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