From 4e46a22dc5165611b254081597c65969c8c2ce39 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 9 May 2021 21:19:42 +0200 Subject: [PATCH] sync: remove "detected" log message in packages/services Don't waste one full log message to show the detected system. Instead, append it to an existing log message. Reorder log call in syncPackagesDebian() so the log message comes before calling debianInstalledPackages(). This way errors from this function show clearly where they originate. --- cmd/safcm-remote/sync/packages_debian.go | 7 ++----- cmd/safcm-remote/sync/packages_debian_test.go | 12 ++++-------- cmd/safcm-remote/sync/services_systemd.go | 4 +--- cmd/safcm-remote/sync/services_systemd_test.go | 18 ++++++------------ 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/cmd/safcm-remote/sync/packages_debian.go b/cmd/safcm-remote/sync/packages_debian.go index 0dcbc4f..2e330b9 100644 --- a/cmd/safcm-remote/sync/packages_debian.go +++ b/cmd/safcm-remote/sync/packages_debian.go @@ -27,15 +27,12 @@ import ( ) func (s *Sync) syncPackagesDebian() error { - s.log.Debugf("packages: detected debian") - + s.log.Debugf("packages: checking %s (debian detected)", + strings.Join(s.req.Packages, " ")) installed, err := s.debianInstalledPackages() if err != nil { return err } - - s.log.Debugf("packages: checking %s", - strings.Join(s.req.Packages, " ")) var install []string for _, x := range s.req.Packages { if !installed[x] { diff --git a/cmd/safcm-remote/sync/packages_debian_test.go b/cmd/safcm-remote/sync/packages_debian_test.go index bd54a2f..a51a6a9 100644 --- a/cmd/safcm-remote/sync/packages_debian_test.go +++ b/cmd/safcm-remote/sync/packages_debian_test.go @@ -73,7 +73,7 @@ install ok installed package-two Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: packages: detected debian", + "4: sync remote: packages: checking package-one package-two (debian detected)", `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`, `5: sync remote: packages: command stdout: install ok installed golang @@ -84,7 +84,6 @@ install ok installed golang-1.16-src hold ok installed package-one install ok installed package-two `, - "4: sync remote: packages: checking package-one package-two", }, safcm.MsgSyncResp{}, nil, @@ -138,7 +137,7 @@ install ok installed package-two ), }}, []string{ - "4: sync remote: packages: detected debian", + "4: sync remote: packages: checking package-one package-two package-three (debian detected)", `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`, `5: sync remote: packages: command stdout: install ok installed golang @@ -148,7 +147,6 @@ install ok installed golang-1.16-go install ok installed golang-1.16-src install ok installed package-two `, - "4: sync remote: packages: checking package-one package-two package-three", "3: sync remote: packages: installing package-one package-three", `4: sync remote: packages: running "/usr/bin/apt-get" "install" "--assume-yes" "--no-upgrade" "--no-install-recommends" "-o" "Dpkg::Options::=--force-confdef" "-o" "Dpkg::Options::=--force-confold" "package-one" "package-three"`, "5: sync remote: packages: command output:\nfake stdout/stderr", @@ -215,7 +213,7 @@ install ok installed golang-1.16-src ), }}, []string{ - "4: sync remote: packages: detected debian", + "4: sync remote: packages: checking package-one package-two (debian detected)", `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`, `5: sync remote: packages: command stdout: install ok installed golang @@ -224,7 +222,6 @@ install ok installed golang-1.16-doc install ok installed golang-1.16-go install ok installed golang-1.16-src `, - "4: sync remote: packages: checking package-one package-two", "3: sync remote: packages: installing package-one package-two", `4: sync remote: packages: running "/usr/bin/apt-get" "install" "--assume-yes" "--no-upgrade" "--no-install-recommends" "-o" "Dpkg::Options::=--force-confdef" "-o" "Dpkg::Options::=--force-confold" "package-one" "package-two"`, "5: sync remote: packages: command output:\nfake stdout/stderr", @@ -272,7 +269,7 @@ install ok installed golang-1.16-src Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: packages: detected debian", + "4: sync remote: packages: checking package-one package-two (debian detected)", `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`, `5: sync remote: packages: command stdout: install ok installed golang @@ -281,7 +278,6 @@ install ok installed golang-1.16-doc install ok installed golang-1.16-go install ok installed golang-1.16-src `, - "4: sync remote: packages: checking package-one package-two", }, safcm.MsgSyncResp{ PackageChanges: []safcm.PackageChange{ diff --git a/cmd/safcm-remote/sync/services_systemd.go b/cmd/safcm-remote/sync/services_systemd.go index 68bbc7d..6ed8107 100644 --- a/cmd/safcm-remote/sync/services_systemd.go +++ b/cmd/safcm-remote/sync/services_systemd.go @@ -25,9 +25,7 @@ import ( ) func (s *Sync) syncServicesSystemd() error { - s.log.Debugf("services: detected systemd") - - s.log.Debugf("services: checking %s", + s.log.Debugf("services: checking %s (systemd detected)", strings.Join(s.req.Services, " ")) services, err := s.systemdServiceState(s.req.Services) if err != nil { diff --git a/cmd/safcm-remote/sync/services_systemd_test.go b/cmd/safcm-remote/sync/services_systemd_test.go index e45e790..cf0f4ab 100644 --- a/cmd/safcm-remote/sync/services_systemd_test.go +++ b/cmd/safcm-remote/sync/services_systemd_test.go @@ -75,8 +75,7 @@ LoadError= Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-one service-two", + "4: sync remote: services: checking service-one service-two (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-one" "service-two"`, `5: sync remote: services: command stdout: ActiveState=active @@ -126,8 +125,7 @@ LoadError= "" Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-one service-two", + "4: sync remote: services: checking service-one service-two (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-one" "service-two"`, `5: sync remote: services: command stdout: ActiveState=active @@ -177,8 +175,7 @@ LoadError= Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-does-not-exist service-two", + "4: sync remote: services: checking service-does-not-exist service-two (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-does-not-exist" "service-two"`, `5: sync remote: services: command stdout: ActiveState=inactive @@ -272,8 +269,7 @@ LoadError= Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-one service-two service-three", + "4: sync remote: services: checking service-one service-two service-three (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-one" "service-two" "service-three"`, `5: sync remote: services: command stdout: ActiveState=inactive @@ -356,8 +352,7 @@ LoadError= Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-one service-two service-three", + "4: sync remote: services: checking service-one service-two service-three (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-one" "service-two" "service-three"`, `5: sync remote: services: command stdout: ActiveState=inactive @@ -462,8 +457,7 @@ LoadError= Stderr: &bytes.Buffer{}, }}, []string{ - "4: sync remote: services: detected systemd", - "4: sync remote: services: checking service-one service-two service-three", + "4: sync remote: services: checking service-one service-two service-three (systemd detected)", `4: sync remote: services: running "/bin/systemctl" "show" "--property=ActiveState,UnitFileState,LoadError" "--" "service-one" "service-two" "service-three"`, `5: sync remote: services: command stdout: ActiveState=inactive -- 2.45.2