]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: rename group_order to group_priority
authorSimon Ruderich <simon@ruderich.org>
Wed, 28 Apr 2021 05:48:18 +0000 (07:48 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 28 Apr 2021 05:53:22 +0000 (07:53 +0200)
"Priority" describes the actual function better and it was already used
internally in the code anyway.

32 files changed:
README.adoc
cmd/safcm/config/config.go
cmd/safcm/config/groups.go
cmd/safcm/config/groups_test.go
cmd/safcm/main_sync_test.go
cmd/safcm/sync_sync.go
cmd/safcm/sync_sync_test.go
cmd/safcm/testdata/project-group_order-single/config.yaml [deleted file]
cmd/safcm/testdata/project-group_priority-single/config.yaml [new file with mode: 0644]
cmd/safcm/testdata/project-group_priority-single/group-a/files/file.txt [moved from cmd/safcm/testdata/project-group_order-single/group-a/files/file.txt with 100% similarity]
cmd/safcm/testdata/project-group_priority-single/group-b/files/file.txt [moved from cmd/safcm/testdata/project-group_order-single/group-b/files/file.txt with 100% similarity]
cmd/safcm/testdata/project-group_priority-single/groups.yaml [moved from cmd/safcm/testdata/project-group_order-single/groups.yaml with 100% similarity]
cmd/safcm/testdata/project-group_priority-single/hosts.yaml [moved from cmd/safcm/testdata/project-group_order-single/hosts.yaml with 100% similarity]
cmd/safcm/testdata/project-group_priority/config.yaml [moved from cmd/safcm/testdata/project-group_order/config.yaml with 66% similarity]
cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-file [moved from cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-file with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-link [moved from cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-link with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/dir/file2 [moved from cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/dir/file2 with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/file [moved from cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/file with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-a/files/etc/motd [moved from cmd/safcm/testdata/project-group_order/group-a/files/etc/motd with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-a/triggers.yaml [moved from cmd/safcm/testdata/project-group_order/group-a/triggers.yaml with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/dir/file2 [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/dir/file2 with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/file [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/file with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-filex [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-filex with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/file [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/file with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-linkx [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-linkx with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/file-to-dir [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/file-to-dir with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/files/etc/motd [moved from cmd/safcm/testdata/project-group_order/group-b/files/etc/motd with 100% similarity]
cmd/safcm/testdata/project-group_priority/group-b/triggers.yaml [moved from cmd/safcm/testdata/project-group_order/group-b/triggers.yaml with 100% similarity]
cmd/safcm/testdata/project-group_priority/groups.yaml [moved from cmd/safcm/testdata/project-group_order/groups.yaml with 100% similarity]
cmd/safcm/testdata/project-group_priority/host1.example.org/files/etc/motd [moved from cmd/safcm/testdata/project-group_order/host1.example.org/files/etc/motd with 100% similarity]
cmd/safcm/testdata/project-group_priority/hosts.yaml [moved from cmd/safcm/testdata/project-group_order/hosts.yaml with 100% similarity]

index f4a34feb91c2e259f25e2f3408e9fe6afb9659d4..6d85d51bb297dd8ce9abd085f5c198b26a26a191 100644 (file)
@@ -58,9 +58,10 @@ service names of the remote operating system. Commands are shell commands
 passed to `/bin/sh`.
 
 When files with the same path are present in multiple groups of a host, an
-explicit _group order_ must be configured to resolve the conflict. Conflicts
-do not apply to packages and services which are simply merged from all groups.
-Commands are appended so that the same command can be executed multiple times.
+explicit _group priority_ must be configured to resolve the conflict.
+Conflicts do not apply to packages and services which are simply merged from
+all groups. Commands are appended so that the same command can be executed
+multiple times.
 
 To sync the configuration to a remote host, the local `safcm` binary connects
 to it via `ssh`. It then copies a _remote helper_ binary to `/tmp` on the
index 3973e82c9866f61395f2002366d08466af89b241..85e0e4bb92516c6907052047905c2a8a43dc4c6a 100644 (file)
@@ -33,7 +33,7 @@ type Config struct {
        SshConfig string         `yaml:"-"` // set via command line
 
        DetectGroups []string `yaml:"detect_groups"`
-       GroupOrder   []string `yaml:"group_order"`
+       GroupPriority []string `yaml:"group_priority"`
 }
 
 func LoadConfig() (*Config, error) {
index d003bddeed1c9e5efdf24db2db57b788dc252b3f..5f3f679f5a9bde9ec1368d3f705f08d313647094 100644 (file)
@@ -103,8 +103,8 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) {
        }
 
        // Sanity check for global configuration
-       for _, x := range cfg.GroupOrder {
-               const errPrefix = "config.yaml: group_order:"
+       for _, x := range cfg.GroupPriority {
+               const errPrefix = "config.yaml: group_priority:"
 
                if x == GroupAll {
                        continue
index 9f5f046385cedf077455fb99d31b93d0075ecdce..63c26836d92de66969904d643d77d7c9ae9a8222 100644 (file)
@@ -55,7 +55,7 @@ func TestLoadGroups(t *testing.T) {
                {
                        "../testdata/project",
                        &Config{
-                               GroupOrder: []string{
+                               GroupPriority: []string{
                                        "detected_linux",
                                        "detected_freebsd",
                                },
@@ -105,38 +105,38 @@ func TestLoadGroups(t *testing.T) {
                {
                        "../testdata/project",
                        &Config{
-                               GroupOrder: []string{
+                               GroupPriority: []string{
                                        "detected_freebsd",
                                        "does-not-exist",
                                },
                        },
                        hosts,
                        nil,
-                       fmt.Errorf("config.yaml: group_order: group \"does-not-exist\" does not exist"),
+                       fmt.Errorf("config.yaml: group_priority: group \"does-not-exist\" does not exist"),
                },
                {
                        "../testdata/project",
                        &Config{
-                               GroupOrder: []string{
+                               GroupPriority: []string{
                                        "detected_freebsd",
                                        "special:group",
                                },
                        },
                        hosts,
                        nil,
-                       fmt.Errorf("config.yaml: group_order: invalid group name \"special:group\""),
+                       fmt.Errorf("config.yaml: group_priority: invalid group name \"special:group\""),
                },
                {
                        "../testdata/project",
                        &Config{
-                               GroupOrder: []string{
+                               GroupPriority: []string{
                                        "detected_freebsd",
                                        "group:remove",
                                },
                        },
                        hosts,
                        nil,
-                       fmt.Errorf("config.yaml: group_order: invalid group name \"group:remove\""),
+                       fmt.Errorf("config.yaml: group_priority: invalid group name \"group:remove\""),
                },
 
                {
index 39784fa12ef270ab380ff3402112a55f5660cc50..f58dabf96256d814583e8e4ac1481a9b591fbc03 100644 (file)
@@ -110,7 +110,7 @@ func TestSyncSshEndToEnd(t *testing.T) {
                        []string{"-log", "verbose", "no-settings.example.org"},
                        `<LOG>[info]    [no-settings.example.org] remote helper upload in progress
 <LOG>[verbose] [no-settings.example.org] host groups: all <DET> <DET> no-settings.example.org
-<LOG>[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org
+<LOG>[verbose] [no-settings.example.org] host group priorities (desc. priority): no-settings.example.org
 <LOG>[info]    [no-settings.example.org] no changes
 `,
                        nil,
@@ -121,7 +121,7 @@ func TestSyncSshEndToEnd(t *testing.T) {
                        []string{"-log", "debug2", "no-settings.example.org"},
                        `<LOG>[info]    [no-settings.example.org] remote helper upload in progress
 <LOG>[verbose] [no-settings.example.org] host groups: all <DET> <DET> no-settings.example.org
-<LOG>[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org
+<LOG>[verbose] [no-settings.example.org] host group priorities (desc. priority): no-settings.example.org
 <LOG>[info]    [no-settings.example.org] no changes
 `,
                        nil,
index 8b4cec45d0ba837cc490ac332a9b5d124883c136..930a263998566c3a71563b30c1e374f6ada06ecb 100644 (file)
@@ -66,8 +66,8 @@ func (s *Sync) hostSyncReq(detectedGroups []string) (
                return empty, err
        }
        {
-               // Don't leak internal group order which is confusing without
-               // knowing the implementation details.
+               // Don't leak internal group priority which is confusing
+               // without knowing the implementation details.
                groupsSorted := make([]string, len(groups))
                copy(groupsSorted, groups)
                sort.Strings(groupsSorted)
@@ -85,7 +85,7 @@ func (s *Sync) hostSyncReq(detectedGroups []string) (
                        b := priorities[j]
                        return groupPriority[a] < groupPriority[b]
                })
-               s.logVerbosef("host group priorities (desc. order): %v",
+               s.logVerbosef("host group priorities (desc. priority): %v",
                        strings.Join(priorities, " "))
        }
 
@@ -188,7 +188,7 @@ func (s *Sync) resolveHostGroups(detectedGroups []string) (
 
        // Early entries have higher priorities
        groupPriority := make(map[string]int)
-       for i, x := range s.config.GroupOrder {
+       for i, x := range s.config.GroupPriority {
                groupPriority[x] = math.MinInt32 + i + 1
        }
        // Host itself always has highest priority
@@ -242,7 +242,7 @@ func (s *Sync) checkFileConflict(group string, path string, file *safcm.File,
        }
 
        return fmt.Errorf("groups %s and %s both provide file %q\n"+
-               "Use 'group_order' in config.yaml to declare preference",
+               "Use 'group_priority' in config.yaml to declare preference",
                group, old.OrigGroup, path)
 }
 
@@ -257,9 +257,9 @@ func resolveFileDirConflicts(files map[string]*safcm.File) {
 
        const sep = string(filepath.Separator)
 
-       // Remove invalid paths which can result from group_order overriding
-       // paths from another group (e.g. "/foo" as file from one group and
-       // "/foo/bar" from another).
+       // Remove invalid paths which can result from group_priority
+       // overriding paths from another group (e.g. "/foo" as file from one
+       // group and "/foo/bar" from another).
        var last *safcm.File
        for _, x := range paths {
                file := files[x]
index a5f65811e0d82297f642f01dcf027dd175ff9da3..b8a53a40889d735531cd0079431ca88ad74e00bc 100644 (file)
@@ -149,7 +149,7 @@ func TestHostSyncReq(t *testing.T) {
                        },
                        []string{
                                "host1.example.org: <nil> 3 host groups: all group group3 host1.example.org remove",
-                               "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org",
+                               "host1.example.org: <nil> 3 host group priorities (desc. priority): host1.example.org",
                        },
                        nil,
                },
@@ -265,9 +265,9 @@ func TestHostSyncReq(t *testing.T) {
                        safcm.MsgSyncReq{},
                        []string{
                                "host1.example.org: <nil> 3 host groups: all dns host1.example.org",
-                               "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org",
+                               "host1.example.org: <nil> 3 host group priorities (desc. priority): host1.example.org",
                        },
-                       fmt.Errorf("groups dns and all both provide file \"/etc/resolv.conf\"\nUse 'group_order' in config.yaml to declare preference"),
+                       fmt.Errorf("groups dns and all both provide file \"/etc/resolv.conf\"\nUse 'group_priority' in config.yaml to declare preference"),
                },
                {
                        "conflict: file from detected group",
@@ -280,9 +280,9 @@ func TestHostSyncReq(t *testing.T) {
                        safcm.MsgSyncReq{},
                        []string{
                                "host2.example.org: <nil> 3 host groups: all detected_other host2.example.org other",
-                               "host2.example.org: <nil> 3 host group priorities (desc. order): host2.example.org",
+                               "host2.example.org: <nil> 3 host group priorities (desc. priority): host2.example.org",
                        },
-                       fmt.Errorf("groups other and all both provide file \"/etc/resolv.conf\"\nUse 'group_order' in config.yaml to declare preference"),
+                       fmt.Errorf("groups other and all both provide file \"/etc/resolv.conf\"\nUse 'group_priority' in config.yaml to declare preference"),
                },
 
                {
@@ -294,9 +294,9 @@ func TestHostSyncReq(t *testing.T) {
                        safcm.MsgSyncReq{},
                        []string{
                                "host1.example.org: <nil> 3 host groups: all dns host1.example.org",
-                               "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org",
+                               "host1.example.org: <nil> 3 host group priorities (desc. priority): host1.example.org",
                        },
-                       fmt.Errorf("groups dns and all both provide file \"/etc\"\nUse 'group_order' in config.yaml to declare preference"),
+                       fmt.Errorf("groups dns and all both provide file \"/etc\"\nUse 'group_priority' in config.yaml to declare preference"),
                },
                {
                        "conflict: dir from detected group",
@@ -309,9 +309,9 @@ func TestHostSyncReq(t *testing.T) {
                        safcm.MsgSyncReq{},
                        []string{
                                "host2.example.org: <nil> 3 host groups: all detected_other host2.example.org other",
-                               "host2.example.org: <nil> 3 host group priorities (desc. order): host2.example.org",
+                               "host2.example.org: <nil> 3 host group priorities (desc. priority): host2.example.org",
                        },
-                       fmt.Errorf("groups other and all both provide file \"/etc\"\nUse 'group_order' in config.yaml to declare preference"),
+                       fmt.Errorf("groups other and all both provide file \"/etc\"\nUse 'group_priority' in config.yaml to declare preference"),
                },
 
                {
@@ -326,8 +326,8 @@ func TestHostSyncReq(t *testing.T) {
                },
 
                {
-                       "group_order",
-                       "project-group_order",
+                       "group_priority",
+                       "project-group_priority",
                        "host1.example.org",
                        nil,
                        safcm.LogDebug3,
@@ -422,7 +422,7 @@ func TestHostSyncReq(t *testing.T) {
                        },
                        []string{
                                "host1.example.org: <nil> 3 host groups: all group-a group-b host1.example.org",
-                               "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org group-a group-b all",
+                               "host1.example.org: <nil> 3 host group priorities (desc. priority): host1.example.org group-a group-b all",
                                `host1.example.org: <nil> 4 files: "/etc": group group-a overwrites triggers from group group-b`,
                                `host1.example.org: <nil> 4 files: "/etc": group host1.example.org overwrites triggers from group group-a`,
                        },
@@ -430,8 +430,8 @@ func TestHostSyncReq(t *testing.T) {
                },
 
                {
-                       "group_order (single group)",
-                       "project-group_order-single",
+                       "group_priority (single group)",
+                       "project-group_priority-single",
                        "host1.example.org",
                        nil,
                        safcm.LogDebug3,
@@ -457,7 +457,7 @@ func TestHostSyncReq(t *testing.T) {
                        },
                        []string{
                                "host1.example.org: <nil> 3 host groups: all group-a group-b host1.example.org",
-                               "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org group-a",
+                               "host1.example.org: <nil> 3 host group priorities (desc. priority): host1.example.org group-a",
                        },
                        nil,
                },
diff --git a/cmd/safcm/testdata/project-group_order-single/config.yaml b/cmd/safcm/testdata/project-group_order-single/config.yaml
deleted file mode 100644 (file)
index 5a673b2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-group_order:
-  - group-a
diff --git a/cmd/safcm/testdata/project-group_priority-single/config.yaml b/cmd/safcm/testdata/project-group_priority-single/config.yaml
new file mode 100644 (file)
index 0000000..4cd1806
--- /dev/null
@@ -0,0 +1,2 @@
+group_priority:
+  - group-a
similarity index 66%
rename from cmd/safcm/testdata/project-group_order/config.yaml
rename to cmd/safcm/testdata/project-group_priority/config.yaml
index b409bd6b02081ba5cd014664e8518c1637102d20..9cd0657b9066b910447e8cf66aa74d619d1fdb19 100644 (file)
@@ -1,4 +1,4 @@
-group_order:
+group_priority:
   - group-a
   - group-b
   - all