From: Simon Ruderich Date: Wed, 28 Apr 2021 05:48:18 +0000 (+0200) Subject: config: rename group_order to group_priority X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=45f6c93c3d7ef4a300707bb96d4a1e1fce6df55f;p=safcm%2Fsafcm.git config: rename group_order to group_priority "Priority" describes the actual function better and it was already used internally in the code anyway. --- diff --git a/README.adoc b/README.adoc index f4a34fe..6d85d51 100644 --- a/README.adoc +++ b/README.adoc @@ -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 diff --git a/cmd/safcm/config/config.go b/cmd/safcm/config/config.go index 3973e82..85e0e4b 100644 --- a/cmd/safcm/config/config.go +++ b/cmd/safcm/config/config.go @@ -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) { diff --git a/cmd/safcm/config/groups.go b/cmd/safcm/config/groups.go index d003bdd..5f3f679 100644 --- a/cmd/safcm/config/groups.go +++ b/cmd/safcm/config/groups.go @@ -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 diff --git a/cmd/safcm/config/groups_test.go b/cmd/safcm/config/groups_test.go index 9f5f046..63c2683 100644 --- a/cmd/safcm/config/groups_test.go +++ b/cmd/safcm/config/groups_test.go @@ -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\""), }, { diff --git a/cmd/safcm/main_sync_test.go b/cmd/safcm/main_sync_test.go index 39784fa..f58dabf 100644 --- a/cmd/safcm/main_sync_test.go +++ b/cmd/safcm/main_sync_test.go @@ -110,7 +110,7 @@ func TestSyncSshEndToEnd(t *testing.T) { []string{"-log", "verbose", "no-settings.example.org"}, `[info] [no-settings.example.org] remote helper upload in progress [verbose] [no-settings.example.org] host groups: all no-settings.example.org -[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org +[verbose] [no-settings.example.org] host group priorities (desc. priority): no-settings.example.org [info] [no-settings.example.org] no changes `, nil, @@ -121,7 +121,7 @@ func TestSyncSshEndToEnd(t *testing.T) { []string{"-log", "debug2", "no-settings.example.org"}, `[info] [no-settings.example.org] remote helper upload in progress [verbose] [no-settings.example.org] host groups: all no-settings.example.org -[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org +[verbose] [no-settings.example.org] host group priorities (desc. priority): no-settings.example.org [info] [no-settings.example.org] no changes `, nil, diff --git a/cmd/safcm/sync_sync.go b/cmd/safcm/sync_sync.go index 8b4cec4..930a263 100644 --- a/cmd/safcm/sync_sync.go +++ b/cmd/safcm/sync_sync.go @@ -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] diff --git a/cmd/safcm/sync_sync_test.go b/cmd/safcm/sync_sync_test.go index a5f6581..b8a53a4 100644 --- a/cmd/safcm/sync_sync_test.go +++ b/cmd/safcm/sync_sync_test.go @@ -149,7 +149,7 @@ func TestHostSyncReq(t *testing.T) { }, []string{ "host1.example.org: 3 host groups: all group group3 host1.example.org remove", - "host1.example.org: 3 host group priorities (desc. order): host1.example.org", + "host1.example.org: 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: 3 host groups: all dns host1.example.org", - "host1.example.org: 3 host group priorities (desc. order): host1.example.org", + "host1.example.org: 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: 3 host groups: all detected_other host2.example.org other", - "host2.example.org: 3 host group priorities (desc. order): host2.example.org", + "host2.example.org: 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: 3 host groups: all dns host1.example.org", - "host1.example.org: 3 host group priorities (desc. order): host1.example.org", + "host1.example.org: 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: 3 host groups: all detected_other host2.example.org other", - "host2.example.org: 3 host group priorities (desc. order): host2.example.org", + "host2.example.org: 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: 3 host groups: all group-a group-b host1.example.org", - "host1.example.org: 3 host group priorities (desc. order): host1.example.org group-a group-b all", + "host1.example.org: 3 host group priorities (desc. priority): host1.example.org group-a group-b all", `host1.example.org: 4 files: "/etc": group group-a overwrites triggers from group group-b`, `host1.example.org: 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: 3 host groups: all group-a group-b host1.example.org", - "host1.example.org: 3 host group priorities (desc. order): host1.example.org group-a", + "host1.example.org: 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 index 5a673b2..0000000 --- a/cmd/safcm/testdata/project-group_order-single/config.yaml +++ /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 index 0000000..4cd1806 --- /dev/null +++ b/cmd/safcm/testdata/project-group_priority-single/config.yaml @@ -0,0 +1,2 @@ +group_priority: + - group-a diff --git a/cmd/safcm/testdata/project-group_order-single/group-a/files/file.txt b/cmd/safcm/testdata/project-group_priority-single/group-a/files/file.txt similarity index 100% rename from cmd/safcm/testdata/project-group_order-single/group-a/files/file.txt rename to cmd/safcm/testdata/project-group_priority-single/group-a/files/file.txt diff --git a/cmd/safcm/testdata/project-group_order-single/group-b/files/file.txt b/cmd/safcm/testdata/project-group_priority-single/group-b/files/file.txt similarity index 100% rename from cmd/safcm/testdata/project-group_order-single/group-b/files/file.txt rename to cmd/safcm/testdata/project-group_priority-single/group-b/files/file.txt diff --git a/cmd/safcm/testdata/project-group_order-single/groups.yaml b/cmd/safcm/testdata/project-group_priority-single/groups.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order-single/groups.yaml rename to cmd/safcm/testdata/project-group_priority-single/groups.yaml diff --git a/cmd/safcm/testdata/project-group_order-single/hosts.yaml b/cmd/safcm/testdata/project-group_priority-single/hosts.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order-single/hosts.yaml rename to cmd/safcm/testdata/project-group_priority-single/hosts.yaml diff --git a/cmd/safcm/testdata/project-group_order/config.yaml b/cmd/safcm/testdata/project-group_priority/config.yaml similarity index 66% rename from cmd/safcm/testdata/project-group_order/config.yaml rename to cmd/safcm/testdata/project-group_priority/config.yaml index b409bd6..9cd0657 100644 --- a/cmd/safcm/testdata/project-group_order/config.yaml +++ b/cmd/safcm/testdata/project-group_priority/config.yaml @@ -1,4 +1,4 @@ -group_order: +group_priority: - group-a - group-b - all diff --git a/cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-file b/cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-file similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-file rename to cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-file diff --git a/cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-link b/cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-link similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/files/etc/dir-to-link rename to cmd/safcm/testdata/project-group_priority/group-a/files/etc/dir-to-link diff --git a/cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/dir/file2 b/cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/dir/file2 similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/dir/file2 rename to cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/dir/file2 diff --git a/cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/file b/cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/file similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/files/etc/file-to-dir/file rename to cmd/safcm/testdata/project-group_priority/group-a/files/etc/file-to-dir/file diff --git a/cmd/safcm/testdata/project-group_order/group-a/files/etc/motd b/cmd/safcm/testdata/project-group_priority/group-a/files/etc/motd similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/files/etc/motd rename to cmd/safcm/testdata/project-group_priority/group-a/files/etc/motd diff --git a/cmd/safcm/testdata/project-group_order/group-a/triggers.yaml b/cmd/safcm/testdata/project-group_priority/group-a/triggers.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-a/triggers.yaml rename to cmd/safcm/testdata/project-group_priority/group-a/triggers.yaml diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/dir/file2 b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/dir/file2 similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/dir/file2 rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/dir/file2 diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/file b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/file similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-file/file rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-file/file diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-filex b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-filex similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-filex rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-filex diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/dir/file2 diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/file b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/file similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-link/dir-to-file/file rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-link/dir-to-file/file diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-linkx b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-linkx similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/dir-to-linkx rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/dir-to-linkx diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/file-to-dir b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/file-to-dir similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/file-to-dir rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/file-to-dir diff --git a/cmd/safcm/testdata/project-group_order/group-b/files/etc/motd b/cmd/safcm/testdata/project-group_priority/group-b/files/etc/motd similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/files/etc/motd rename to cmd/safcm/testdata/project-group_priority/group-b/files/etc/motd diff --git a/cmd/safcm/testdata/project-group_order/group-b/triggers.yaml b/cmd/safcm/testdata/project-group_priority/group-b/triggers.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order/group-b/triggers.yaml rename to cmd/safcm/testdata/project-group_priority/group-b/triggers.yaml diff --git a/cmd/safcm/testdata/project-group_order/groups.yaml b/cmd/safcm/testdata/project-group_priority/groups.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order/groups.yaml rename to cmd/safcm/testdata/project-group_priority/groups.yaml diff --git a/cmd/safcm/testdata/project-group_order/host1.example.org/files/etc/motd b/cmd/safcm/testdata/project-group_priority/host1.example.org/files/etc/motd similarity index 100% rename from cmd/safcm/testdata/project-group_order/host1.example.org/files/etc/motd rename to cmd/safcm/testdata/project-group_priority/host1.example.org/files/etc/motd diff --git a/cmd/safcm/testdata/project-group_order/hosts.yaml b/cmd/safcm/testdata/project-group_priority/hosts.yaml similarity index 100% rename from cmd/safcm/testdata/project-group_order/hosts.yaml rename to cmd/safcm/testdata/project-group_priority/hosts.yaml