diff --git a/docs/resource-guide.md b/docs/resource-guide.md index 41b10c1c..0dc368e7 100644 --- a/docs/resource-guide.md +++ b/docs/resource-guide.md @@ -80,7 +80,7 @@ work, and finish by calling the `Init` method of the base resource. ```golang // Init initializes the Foo resource. func (obj *FooRes) Init() error { - obj.BaseRes.kind = "Foo" // must set capitalized resource kind + obj.BaseRes.kind = "foo" // must lower case resource kind // run the resource specific initialization, and error if anything fails if some_error { return err // something went wrong! diff --git a/resources/augeas.go b/resources/augeas.go index 5dbadd8c..6ac72139 100644 --- a/resources/augeas.go +++ b/resources/augeas.go @@ -93,7 +93,7 @@ func (obj *AugeasRes) Validate() error { // Init initiates the resource. func (obj *AugeasRes) Init() error { - obj.BaseRes.kind = "Augeas" + obj.BaseRes.kind = "augeas" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/exec.go b/resources/exec.go index d2372012..0cc6f21b 100644 --- a/resources/exec.go +++ b/resources/exec.go @@ -74,7 +74,7 @@ func (obj *ExecRes) Validate() error { // Init runs some startup code for this resource. func (obj *ExecRes) Init() error { - obj.BaseRes.kind = "Exec" + obj.BaseRes.kind = "exec" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/file.go b/resources/file.go index d7398b00..6ec9989b 100644 --- a/resources/file.go +++ b/resources/file.go @@ -147,7 +147,7 @@ func (obj *FileRes) Init() error { obj.path = obj.GetPath() // compute once obj.isDir = strings.HasSuffix(obj.path, "/") // dirs have trailing slashes - obj.BaseRes.kind = "File" + obj.BaseRes.kind = "file" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/hostname.go b/resources/hostname.go index 896445b4..0a10532d 100644 --- a/resources/hostname.go +++ b/resources/hostname.go @@ -87,7 +87,7 @@ func (obj *HostnameRes) Validate() error { // Init runs some startup code for this resource. func (obj *HostnameRes) Init() error { - obj.BaseRes.kind = "Hostname" + obj.BaseRes.kind = "hostname" if obj.PrettyHostname == "" { obj.PrettyHostname = obj.Hostname } diff --git a/resources/kv.go b/resources/kv.go index 0a438438..8c2bca6f 100644 --- a/resources/kv.go +++ b/resources/kv.go @@ -88,7 +88,7 @@ func (obj *KVRes) Validate() error { // Init initializes the resource. func (obj *KVRes) Init() error { - obj.BaseRes.kind = "KV" + obj.BaseRes.kind = "kv" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/msg.go b/resources/msg.go index 1cae82ff..458ea6a6 100644 --- a/resources/msg.go +++ b/resources/msg.go @@ -75,7 +75,7 @@ func (obj *MsgRes) Validate() error { // Init runs some startup code for this resource. func (obj *MsgRes) Init() error { - obj.BaseRes.kind = "Msg" + obj.BaseRes.kind = "msg" return obj.BaseRes.Init() // call base init, b/c we're overrriding } diff --git a/resources/noop.go b/resources/noop.go index 990eb136..7b382a94 100644 --- a/resources/noop.go +++ b/resources/noop.go @@ -49,7 +49,7 @@ func (obj *NoopRes) Validate() error { // Init runs some startup code for this resource. func (obj *NoopRes) Init() error { - obj.BaseRes.kind = "Noop" + obj.BaseRes.kind = "noop" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/nspawn.go b/resources/nspawn.go index 43d0d35f..85788fbf 100644 --- a/resources/nspawn.go +++ b/resources/nspawn.go @@ -92,7 +92,7 @@ func (obj *NspawnRes) Init() error { if err := obj.svc.Init(); err != nil { return err } - obj.BaseRes.kind = "Nspawn" + obj.BaseRes.kind = "nspawn" return obj.BaseRes.Init() } diff --git a/resources/password.go b/resources/password.go index 885400fb..255b478d 100644 --- a/resources/password.go +++ b/resources/password.go @@ -73,7 +73,7 @@ func (obj *PasswordRes) Validate() error { // Init generates a new password for this resource if one was not provided. It // will save this into a local file. It will load it back in from previous runs. func (obj *PasswordRes) Init() error { - obj.BaseRes.kind = "Password" // must be set before using VarDir + obj.BaseRes.kind = "password" // must be set before using VarDir dir, err := obj.VarDir("") if err != nil { diff --git a/resources/pkg.go b/resources/pkg.go index 06213128..225ad1b5 100644 --- a/resources/pkg.go +++ b/resources/pkg.go @@ -66,7 +66,7 @@ func (obj *PkgRes) Validate() error { // Init runs some startup code for this resource. func (obj *PkgRes) Init() error { - obj.BaseRes.kind = "Pkg" + obj.BaseRes.kind = "pkg" if err := obj.BaseRes.Init(); err != nil { // call base init, b/c we're overriding return err } diff --git a/resources/svc.go b/resources/svc.go index 4ba6c695..abc45d17 100644 --- a/resources/svc.go +++ b/resources/svc.go @@ -65,7 +65,7 @@ func (obj *SvcRes) Validate() error { // Init runs some startup code for this resource. func (obj *SvcRes) Init() error { - obj.BaseRes.kind = "Svc" + obj.BaseRes.kind = "svc" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/resources/timer.go b/resources/timer.go index dfe366e8..fd49d82d 100644 --- a/resources/timer.go +++ b/resources/timer.go @@ -58,7 +58,7 @@ func (obj *TimerRes) Validate() error { // Init runs some startup code for this resource. func (obj *TimerRes) Init() error { - obj.BaseRes.kind = "Timer" + obj.BaseRes.kind = "timer" return obj.BaseRes.Init() // call base init, b/c we're overrriding } diff --git a/resources/virt.go b/resources/virt.go index b8ce0c19..c2b97124 100644 --- a/resources/virt.go +++ b/resources/virt.go @@ -191,7 +191,7 @@ func (obj *VirtRes) Init() error { } } obj.wg = &sync.WaitGroup{} - obj.BaseRes.kind = "Virt" + obj.BaseRes.kind = "virt" return obj.BaseRes.Init() // call base init, b/c we're overriding } diff --git a/test/shell/file-move.sh b/test/shell/file-move.sh index cfe3ca5d..5e4ab951 100755 --- a/test/shell/file-move.sh +++ b/test/shell/file-move.sh @@ -8,19 +8,19 @@ timeout --kill-after=20s 15s ./mgmt run --tmp-prefix --yaml=file-move.yaml 2>&1 pid=$! sleep 5s # let it converge -initial=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) +initial=$(grep -c 'file\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) mv /tmp/mgmt/f1 /tmp/mgmt/f2 sleep 3 -after_move_count=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) +after_move_count=$(grep -c 'file\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) sleep 3 echo f2 > /tmp/mgmt/f2 -after_moved_file_count=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) +after_moved_file_count=$(grep -c 'file\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log) if [[ ${after_move_count} -le ${initial} ]] diff --git a/test/shell/prometheus-3.sh b/test/shell/prometheus-3.sh index 8d510745..8be528d7 100755 --- a/test/shell/prometheus-3.sh +++ b/test/shell/prometheus-3.sh @@ -9,10 +9,10 @@ sleep 10s # let it converge curl 127.0.0.1:9233/metrics # Three CheckApply for a File ; with events -curl 127.0.0.1:9233/metrics | grep '^mgmt_checkapply_total{apply="true",errorful="false",eventful="true",kind="File"} 3$' +curl 127.0.0.1:9233/metrics | grep '^mgmt_checkapply_total{apply="true",errorful="false",eventful="true",kind="file"} 3$' # One CheckApply for a File ; in noop mode. -curl 127.0.0.1:9233/metrics | grep '^mgmt_checkapply_total{apply="false",errorful="false",eventful="true",kind="File"} 1$' +curl 127.0.0.1:9233/metrics | grep '^mgmt_checkapply_total{apply="false",errorful="false",eventful="true",kind="file"} 1$' # Check mgmt_graph_start_time_seconds curl 127.0.0.1:9233/metrics | grep "^mgmt_graph_start_time_seconds [1-9]\+" diff --git a/yamlgraph/gconfig.go b/yamlgraph/gconfig.go index 94904a8b..d15221e2 100644 --- a/yamlgraph/gconfig.go +++ b/yamlgraph/gconfig.go @@ -28,7 +28,6 @@ import ( "github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/resources" - "github.com/purpleidea/mgmt/util" "gopkg.in/yaml.v2" ) @@ -116,8 +115,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World, field := value.FieldByName(name) iface := field.Interface() // interface type of value slice := reflect.ValueOf(iface) - // XXX: should we just drop these everywhere and have the kind strings be all lowercase? - kind := util.FirstToUpper(name) + kind := strings.ToLower(name) for j := 0; j < slice.Len(); j++ { // loop through resources of same kind x := slice.Index(j).Interface() res, ok := x.(resources.Res) // convert to Res type @@ -158,8 +156,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World, var hostnameFilter []string // empty to get from everyone kindFilter := []string{} for _, t := range c.Collector { - // XXX: should we just drop these everywhere and have the kind strings be all lowercase? - kind := util.FirstToUpper(t.Kind) + kind := strings.ToLower(t.Kind) kindFilter = append(kindFilter, kind) } // do all the graph look ups in one single step, so that if the backend @@ -175,8 +172,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World, matched := false // see if we find a collect pattern that matches for _, t := range c.Collector { - // XXX: should we just drop these everywhere and have the kind strings be all lowercase? - kind := util.FirstToUpper(t.Kind) + kind := strings.ToLower(t.Kind) // use t.Kind and optionally t.Pattern to collect from storage log.Printf("Collect: %v; Pattern: %v", kind, t.Pattern) @@ -219,20 +215,20 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World, } for _, e := range c.Edges { - if _, ok := lookup[util.FirstToUpper(e.From.Kind)]; !ok { + if _, ok := lookup[strings.ToLower(e.From.Kind)]; !ok { return nil, fmt.Errorf("can't find 'from' resource") } - if _, ok := lookup[util.FirstToUpper(e.To.Kind)]; !ok { + if _, ok := lookup[strings.ToLower(e.To.Kind)]; !ok { return nil, fmt.Errorf("can't find 'to' resource") } - if _, ok := lookup[util.FirstToUpper(e.From.Kind)][e.From.Name]; !ok { + if _, ok := lookup[strings.ToLower(e.From.Kind)][e.From.Name]; !ok { return nil, fmt.Errorf("can't find 'from' name") } - if _, ok := lookup[util.FirstToUpper(e.To.Kind)][e.To.Name]; !ok { + if _, ok := lookup[strings.ToLower(e.To.Kind)][e.To.Name]; !ok { return nil, fmt.Errorf("can't find 'to' name") } - from := lookup[util.FirstToUpper(e.From.Kind)][e.From.Name] - to := lookup[util.FirstToUpper(e.To.Kind)][e.To.Name] + from := lookup[strings.ToLower(e.From.Kind)][e.From.Name] + to := lookup[strings.ToLower(e.To.Kind)][e.To.Name] edge := pgraph.NewEdge(e.Name) edge.Notify = e.Notify graph.AddEdge(from, to, edge)