Allow empty target KVS for notification targets (#8644)

This is allowed with enable=off arg value
This commit is contained in:
Harshavardhana 2019-12-12 17:02:14 -08:00 committed by GitHub
parent 80558e839d
commit 39e8e4f4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -620,8 +620,8 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
_, ok := kvs.Lookup(Enable) _, ok := kvs.Lookup(Enable)
// Check if state is required // Check if state is required
_, defaultOk := defaultKVS[subSys].Lookup(Enable) _, enableRequired := defaultKVS[subSys].Lookup(Enable)
if !ok && defaultOk { if !ok && enableRequired {
// implicit state "on" if not specified. // implicit state "on" if not specified.
kvs.Set(Enable, EnableOn) kvs.Set(Enable, EnableOn)
} }
@ -646,8 +646,19 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
hkvs := HelpSubSysMap[subSys] hkvs := HelpSubSysMap[subSys]
for _, hkv := range hkvs { for _, hkv := range hkvs {
var enabled bool
if enableRequired {
enabled = currKVS.Get(Enable) == EnableOn
} else {
// when enable arg is not required
// then it is implicit on for the sub-system.
enabled = true
}
v, _ := currKVS.Lookup(hkv.Key) v, _ := currKVS.Lookup(hkv.Key)
if v == "" && !hkv.Optional { if v == "" && !hkv.Optional && enabled {
// Return error only if the
// key is enabled, for state=off
// let it be empty.
return Errorf(SafeModeKind, return Errorf(SafeModeKind,
"'%s' is not optional for '%s' sub-system, please check '%s' documentation", "'%s' is not optional for '%s' sub-system, please check '%s' documentation",
hkv.Key, subSys, subSys) hkv.Key, subSys, subSys)