]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: remove "detected" log message in packages/services
authorSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 19:19:42 +0000 (21:19 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 19:19:42 +0000 (21:19 +0200)
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
cmd/safcm-remote/sync/packages_debian_test.go
cmd/safcm-remote/sync/services_systemd.go
cmd/safcm-remote/sync/services_systemd_test.go

index 0dcbc4f4c571cfdadfbeb1b2a4c972c82c53b9fa..2e330b949368f68e5cb709d2769e70a9cb8f30b2 100644 (file)
@@ -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] {
index bd54a2fdd5d927ae2372aef4f86161813ccf936f..a51a6a9d3f319abc966fbcec473a2c4e3a103d0d 100644 (file)
@@ -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{
index 68bbc7d3e08c07e1e665e2cc7ac175d25a1e7679..6ed810706f3547e3d2c013a3809b7fa41d4efa92 100644 (file)
@@ -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 {
index e45e79050a17183ee4fe4cf5429ae7ec88a536eb..cf0f4ab1de543c99738873fbcf4c11747bfaffa2 100644 (file)
@@ -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