Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
BootSetup is expected to be called from program running from
initramfs, and it looks at the kernel command line to check if
something should be printed or not.
When using SNAPD_DEBUG_HTTP, it was also necessary to set SNAPD_DEBUG
for the HTTP traffic to be logged. So it was impossible to log the HTTP
traffic without logging everything. This commit changes that so that
setting the former logs the HTTP traffic and setting SNAPD_DEBUG
enables the debug logs in the rest of snapd.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Minor changes ensuring unset SNAPD_DEBG to avoid test failures when run with SNAPD_DEBUG=1.
Added support in test.yaml for unit tests with SNAPD_DEBUG=1 to be re-run to avoid regressions.
* 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>
We were previously splitting the kernel cmdline fields using strictly
a space character as separator. If snapd.debug=1 is at the end of
the cmdline it also gets a trailing newline and the parameter was
ignored.
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
While debugging a failure during UC20 seeding I noticed it is
hard to get debug data from snapd. I booted the system with:
```
dangerous systemd.debug-shell=1
```
but the
```
journalctl -u snapd
```
output did not contain that much information because debug
was not enabled. So this commit allows to enable debug via
the kernel commandline to allow easier seeding debugging.
Before this change, logger was inconditionally adding a timestamp to
our logs. Then systemd picks them up and adds a timestamp. This
results in silly logs like
Jul 19 16:40:30 fleet snapd[8498]: 2018/07/19 16:40:30.298179 retry.go:52: DEBUG: <blah blah blah>
With this change we take advantage of the fact that systemd services
run with a very limited environment, and check for TERM being set: if
not set, we disable logging the timestamp ourselves. That way you can
still run snapd by hand to debug things and get timestamps, but let
systemd do it itself otherwise.
We have two noisy tests in the unittest runs right now. Messages
get logged to stdout which really should not be visible. With the use
of the new logger.MockLogger() those are now no longer visible.
I also tweaked the existing pattern of:
var logbuf bytes.Buffer
l, err := logger.New(&logbuf, logger.DefaultFlags)
c.Assert(err, IsNil)
logger.SetLogger(l)
to just use:
logbuf, restore := logger.MockLogger()
defer restore()
logger.ConsoleLog printed to standard output and to syslog, an idea
which has proven to be at least partly misguided: snapd's logs would
typically be duplicated as systemd logs the output already. snap only
rarely logged anything relevant to syslog. Aditionally, syslog was
always written to (even for DEBUG), which has been deemed a misfeature.
This drops logger.ConsoleLog and introudces logger.Log (constructor
goes from logger.NewConsoleLog to logger.New); the new type has no
connection with syslog.