fix(lxd): Select server based on name from result (fixes #151) #181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
lxd help list
(manpage) command help says that the filter passed in (we pass inname
) can be multiple things:To reproduce the issue, just create an LXD instance that has the same prefix as the LXD instance used, by spread, e.g. if spread creates
spread-34-ubuntu-20-04
, run in a separate terminal:After that, listing the instances might match more than one (sometimes the order appears "just right", meaning it happens that the one we're looking for just happens to be the first item):
(
--format=csv
used here to make it easier to read)Alternatively, appending a
$
to the name (so it will match as a regex) would also do the trick, but this assumes that the regex-matching will always work like this, and it wouldn't accidentally match other things.See also: #151, #154 -- I tested this on LXD 5.20
tl;dr: It could be that our
exec.Command("lxc", "list", "--format=json", name)
matches multiple instances. To account for that, instead of assuming it will always return a slice where the first item is the one we're interested in, iterate over the result and pick the one that matches the name exactly. If no such match exists, returnlxdNoServerError
(just like the previouslen(sjsons) == 0
case).