* Group 3rd party imports
* Remove unused vars
* Move var only used in tests into test
* Add 'nolint' to ignore warning on unused iotas (might've been
left to improve readability).
Some packaging frameworks (dh-golang in partcular) invokes go generate. Our code
calls `go run ..` to generate some output files. In particular, when building
with Go modules support, we must pass -mod=vendor occasionally. Allow the build
code to set an environment variables with flags that shall be passed to go run.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
This treats input slices as sets and computes the intersection of those sets.
We need this for cloud-init where we have to take a 3-way intersection of slice
lists.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
A little refactor of match counter to allow it to keep N last matches. Useful
when we want to collect the few last lines of a failed command output, which
likely contain the error cause.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* boot/cmdline.go: add TODO about using strutil.KernelCommandLineSplit
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
* strutil/cmdline.go: add GetKernelCommandLineKeyValue
This complements KernelCommandLineSplit, but goes further, checking for a
specific key-value pair in the kernel command line parameters, and returning the
value if found. This will be useful across the codebase for places where we want
to check one specific kernel command line parameter key-value pair.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
* logger/logger.go: use GetKernelCommandLineKeyValue directly
This is a bit more straight forward to read IMHO and potentially reduces some
looping over the parameters as we break as soon as we find snapd.debug in the
positive case where it is set.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
* strutil,osutil: move kernel commandline helpers to osutil
* boot: tweak TODO now that we use osutil.KernelCommandLineSplit
* many: refactor ModeAnd...FromKernelCommandLine and KernelCommandLineKeyValue
Refactor GetKernelCommandLineKeyValue to KernelCommandLineKeyValue which
returns a map of the specified keys that were found on the kernel command line
that have values. It also no longer takes the command line string as an
argument and instead parses the command line itself.
The above necessitates moving the mocking function for where to find
/proc/cmdline to osutil as well and adjusting many tests for this.
Finally, with all of this in place we can refactor
boot.ModeAndRecoverySystemFromKernelCommandLine to use the osutil helpers
and not duplicate parsing logic in the boot package. This does result in
a slight change in behavior where now duplicated kernel command line
parameters are not a fatal condition, but instead the last definition is
used.
Also adjust some tests to mock an empty proc/cmdline to avoid using the
host's version when running tests.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
* osutil, many: rename to KernelCommandLineKeyValues
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* boot: disallow non empty system label without a mode
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* osutil: tweak handling of cmdline keys
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* osutil: mv cmdline to kcmdline
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* osutil: comment tweak
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* logger: further tweaks
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Co-authored-by: Michael Vogt <mvo@ubuntu.com>
Co-authored-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
This allows us to use -gocheck options for the whole codebase, for example to
run all tests in the codebase with the name matching "kernel" one can now do:
go test ./... -gocheck.f kernel
and that will only fail if the tests fail, whereas previously it would fail
because in these packages gocheck was not imported and as such -gocheck.f was
not recognized as an option and the help text for `go test` was printed off
instead of running any tests.
Eventually we may want to adapt the tests in these packages to use go-check too
so that these can also be filtered/run successfully with go test and gocheck
options.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>