[ARVADOS] updated: 1.3.0-1289-g3310da050
Git user
git at public.curoverse.com
Thu Jul 11 21:01:10 UTC 2019
Summary of changes:
lib/config/load.go | 59 ++++++++++++++++++++++++++++++++
lib/config/load_test.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+)
via 3310da050bd763055a67b2395f122ab5c01cbdf9 (commit)
from 05eca3060c7200e47dd83cdcf8f4f7bcad14f62f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3310da050bd763055a67b2395f122ab5c01cbdf9
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date: Thu Jul 11 17:00:45 2019 -0400
13647: Add MungeLegacyConfigArgs.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>
diff --git a/lib/config/load.go b/lib/config/load.go
index 897d99d51..6e0b32677 100644
--- a/lib/config/load.go
+++ b/lib/config/load.go
@@ -55,6 +55,65 @@ func (ldr *Loader) SetupFlags(flagset *flag.FlagSet) {
flagset.StringVar(&ldr.KeepstorePath, "legacy-keepstore-config", defaultKeepstoreConfigPath, "Legacy keepstore configuration `file`")
}
+// MungeLegacyConfigArgs checks args for a -config flag whose argument
+// is a regular file (or a symlink to one), but doesn't have a
+// top-level "Clusters" key and therefore isn't a valid cluster
+// configuration file. If it finds such a flag, it replaces -config
+// with legacyConfigArg (e.g., "-legacy-keepstore-config").
+//
+// This is used by programs that still need to accept "-config" as a
+// way to specify a per-component config file until their config has
+// been migrated.
+//
+// If any errors are encountered while reading or parsing a config
+// file, the given args are not munged. We presume the same errors
+// will be encountered again and reported later on when trying to load
+// cluster configuration from the same file, regardless of which
+// struct we end up using.
+func (ldr *Loader) MungeLegacyConfigArgs(lgr logrus.FieldLogger, args []string, legacyConfigArg string) []string {
+ munged := append([]string(nil), args...)
+ for i := 0; i < len(args); i++ {
+ if !strings.HasPrefix(args[i], "-") || strings.SplitN(strings.TrimPrefix(args[i], "-"), "=", 2)[0] != "config" {
+ continue
+ }
+ var operand string
+ if strings.Contains(args[i], "=") {
+ operand = strings.SplitN(args[i], "=", 2)[1]
+ } else if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
+ i++
+ operand = args[i]
+ } else {
+ continue
+ }
+ if fi, err := os.Stat(operand); err != nil || !fi.Mode().IsRegular() {
+ continue
+ }
+ f, err := os.Open(operand)
+ if err != nil {
+ continue
+ }
+ defer f.Close()
+ buf, err := ioutil.ReadAll(f)
+ if err != nil {
+ continue
+ }
+ var cfg arvados.Config
+ err = yaml.Unmarshal(buf, &cfg)
+ if err != nil {
+ continue
+ }
+ if len(cfg.Clusters) == 0 {
+ lgr.Warnf("%s is not a cluster config file -- interpreting %s as %s (please migrate your config!)", operand, "-config", legacyConfigArg)
+ if operand == args[i] {
+ munged[i-1] = legacyConfigArg
+ } else {
+ munged[i] = legacyConfigArg + "=" + operand
+ }
+ }
+ }
+ return munged
+}
+
func (ldr *Loader) loadBytes(path string) ([]byte, error) {
if path == "-" {
return ioutil.ReadAll(ldr.Stdin)
diff --git a/lib/config/load_test.go b/lib/config/load_test.go
index 0ef149dd8..0d905a217 100644
--- a/lib/config/load_test.go
+++ b/lib/config/load_test.go
@@ -6,7 +6,9 @@ package config
import (
"bytes"
+ "fmt"
"io"
+ "io/ioutil"
"os"
"os/exec"
"strings"
@@ -45,6 +47,93 @@ func (s *LoadSuite) TestNoConfigs(c *check.C) {
c.Check(cc.API.MaxItemsPerResponse, check.Equals, 1000)
}
+func (s *LoadSuite) TestMungeLegacyConfigArgs(c *check.C) {
+ f, err := ioutil.TempFile("", "")
+ c.Check(err, check.IsNil)
+ defer os.Remove(f.Name())
+ io.WriteString(f, "Debug: true\n")
+ oldfile := f.Name()
+
+ f, err = ioutil.TempFile("", "")
+ c.Check(err, check.IsNil)
+ defer os.Remove(f.Name())
+ io.WriteString(f, "Clusters: {aaaaa: {}}\n")
+ newfile := f.Name()
+
+ for _, trial := range []struct {
+ argsIn []string
+ argsOut []string
+ }{
+ {
+ []string{"-config", oldfile},
+ []string{"-old-config", oldfile},
+ },
+ {
+ []string{"-config=" + oldfile},
+ []string{"-old-config=" + oldfile},
+ },
+ {
+ []string{"-config", newfile},
+ []string{"-config", newfile},
+ },
+ {
+ []string{"-config=" + newfile},
+ []string{"-config=" + newfile},
+ },
+ {
+ []string{"-foo", oldfile},
+ []string{"-foo", oldfile},
+ },
+ {
+ []string{"-foo=" + oldfile},
+ []string{"-foo=" + oldfile},
+ },
+ {
+ []string{"-foo", "-config=" + oldfile},
+ []string{"-foo", "-old-config=" + oldfile},
+ },
+ {
+ []string{"-foo", "bar", "-config=" + oldfile},
+ []string{"-foo", "bar", "-old-config=" + oldfile},
+ },
+ {
+ []string{"-foo=bar", "baz", "-config=" + oldfile},
+ []string{"-foo=bar", "baz", "-old-config=" + oldfile},
+ },
+ {
+ []string{"-config=/dev/null"},
+ []string{"-config=/dev/null"},
+ },
+ {
+ []string{"-config=-"},
+ []string{"-config=-"},
+ },
+ {
+ []string{"-config="},
+ []string{"-config="},
+ },
+ {
+ []string{"-foo=bar", "baz", "-config"},
+ []string{"-foo=bar", "baz", "-config"},
+ },
+ {
+ []string{},
+ nil,
+ },
+ } {
+ var logbuf bytes.Buffer
+ logger := logrus.New()
+ logger.Out = &logbuf
+
+ var ldr Loader
+ args := ldr.MungeLegacyConfigArgs(logger, trial.argsIn, "-old-config")
+ c.Check(args, check.DeepEquals, trial.argsOut)
+ if fmt.Sprintf("%v", trial.argsIn) != fmt.Sprintf("%v", trial.argsOut) {
+ c.Check(logbuf.String(), check.Matches, `.*`+oldfile+` is not a cluster config file -- interpreting -config as -old-config.*\n`)
+ }
+ }
+}
+
func (s *LoadSuite) TestSampleKeys(c *check.C) {
for _, yaml := range []string{
`{"Clusters":{"z1111":{}}}`,
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list