Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fixes lp:1575676: Detect LXD default profile's bridge name and use it #5871
Conversation
|
@wallyworld As OCR, can you have a look please? |
fwereade
reviewed
Aug 1, 2016
| + // 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
reviewed
Aug 1, 2016
| - return cfg, errors.Trace(err) | ||
| - } | ||
| - return cfg, nil | ||
| + return cfg.WithDefaults() |
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?
|
LGTM |
This was referenced Aug 2, 2016
babbageclunk
reviewed
Aug 2, 2016
| - * 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
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.
babbageclunk
reviewed
Aug 2, 2016
| + // 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
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
Aug 2, 2016
Contributor
Good catch! Will update the comment and change the conditional as suggested.
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.
babbageclunk
reviewed
Aug 2, 2016
| + | ||
| + bridgeConfig, err := ioutil.ReadFile(LXDBridgeFile) | ||
| + if err != nil { | ||
| + if !os.IsNotExist(err) { |
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
Aug 2, 2016
Contributor
Nice! This is mostly pre-existing code factored out into a function, but will change as suggested.
babbageclunk
reviewed
Aug 2, 2016
| - */ | ||
| - 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
Aug 2, 2016
Member
This comment needs updating - it still talks about lxdbr0. (Which would retroactively justify the reformatting! ;)
dimitern
Aug 2, 2016
Contributor
Fair point - will update the comment and the error below as needed.
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).
babbageclunk
reviewed
Aug 2, 2016
| return cfg, errors.Trace(err) | ||
| } | ||
| - remote, err := cfg.Remote.UsingTCP() | ||
| + remote, err := cfg.Remote.UsingTCP(client.defaultProfileBridgeName) |
babbageclunk
Aug 2, 2016
Member
It might be worth keeping the note that this will start the bridge if it's never been activated?
|
LGTM other than the question about the |
added some commits
Jul 8, 2016
|
$$fixes-1575676$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
dimitern commentedJul 26, 2016
•
Edited 1 time
-
dimitern
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: