You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2022/02/17 21:19:34 UTC
[trafficcontrol] branch master updated: Collect config warnings and print a summary at the end of t3c apply (#6429)
This is an automated email from the ASF dual-hosted git repository.
rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 091d2b8 Collect config warnings and print a summary at the end of t3c apply (#6429)
091d2b8 is described below
commit 091d2b83cde1fe470dfc82ac86ee988f7703e81d
Author: Joe Pappano <jo...@cable.comcast.com>
AuthorDate: Thu Feb 17 16:18:22 2022 -0500
Collect config warnings and print a summary at the end of t3c apply (#6429)
* Collect config warnings and print a summary at the end of t3c apply
* fixed formatting errors
* Added warnings to test
* fixed typo
* Updated to capture remap.config issues, and removed check for append that is not needed.
---
cache-config/t3c-apply/t3c-apply.go | 2 ++
cache-config/t3c-apply/torequest/torequest.go | 38 ++++++++++++++++++-----
cache-config/t3c-generate/cfgfile/all.go | 12 +++++--
cache-config/t3c-generate/cfgfile/cfgfile_test.go | 6 ++--
cache-config/t3c-generate/cfgfile/routing.go | 6 ++--
cache-config/t3c-generate/cfgfile/sslkeys.go | 2 ++
cache-config/t3cutil/t3cutil.go | 13 ++++----
7 files changed, 57 insertions(+), 22 deletions(-)
diff --git a/cache-config/t3c-apply/t3c-apply.go b/cache-config/t3c-apply/t3c-apply.go
index 2a26276..b4be92a 100644
--- a/cache-config/t3c-apply/t3c-apply.go
+++ b/cache-config/t3c-apply/t3c-apply.go
@@ -248,6 +248,8 @@ func main() {
runSysctl(cfg)
}
+ trops.PrintWarnings()
+
if err := trops.UpdateTrafficOps(&syncdsUpdate); err != nil {
log.Errorf("failed to update Traffic Ops: %s\n", err.Error())
}
diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go
index fde5296..d52ceb7 100644
--- a/cache-config/t3c-apply/torequest/torequest.go
+++ b/cache-config/t3c-apply/torequest/torequest.go
@@ -60,7 +60,8 @@ type TrafficOpsReq struct {
installedPkgs map[string]struct{} // map of packages which were installed by us.
changedFiles []string // list of config files which were changed
- configFiles map[string]*ConfigFile
+ configFiles map[string]*ConfigFile
+ configFileWarnings map[string][]string
RestartData
}
@@ -100,6 +101,7 @@ type ConfigFile struct {
Perm os.FileMode // default file permissions
Uid int // owner uid, default is 0
Gid int // owner gid, default is 0
+ Warnings []string
}
func (u UpdateStatus) String() string {
@@ -220,6 +222,7 @@ func (r *TrafficOpsReq) checkConfigFile(cfg *ConfigFile, filesAdding []string) e
// perform plugin verification
if cfg.Name == "remap.config" || cfg.Name == "plugin.config" {
if err := checkRefs(r.Cfg, cfg.Body, filesAdding); err != nil {
+ r.configFileWarnings[cfg.Name] = append(r.configFileWarnings[cfg.Name], "failed to verify '"+cfg.Name+"': "+err.Error())
return errors.New("failed to verify '" + cfg.Name + "': " + err.Error())
}
log.Infoln("Successfully verified plugins used by '" + cfg.Name + "'")
@@ -621,6 +624,7 @@ func (r *TrafficOpsReq) GetConfigFileList() error {
}
r.configFiles = map[string]*ConfigFile{}
+ r.configFileWarnings = map[string][]string{}
var mode os.FileMode
for _, file := range allFiles {
if file.Secure {
@@ -630,18 +634,36 @@ func (r *TrafficOpsReq) GetConfigFileList() error {
}
r.configFiles[file.Name] = &ConfigFile{
- Name: file.Name,
- Path: filepath.Join(file.Path, file.Name),
- Dir: file.Path,
- Body: []byte(file.Text),
- Uid: atsUid,
- Gid: atsGid,
- Perm: mode,
+ Name: file.Name,
+ Path: filepath.Join(file.Path, file.Name),
+ Dir: file.Path,
+ Body: []byte(file.Text),
+ Uid: atsUid,
+ Gid: atsGid,
+ Perm: mode,
+ Warnings: file.Warnings,
+ }
+ for _, warn := range file.Warnings {
+ if warn == "" {
+ continue
+ }
+ r.configFileWarnings[file.Name] = append(r.configFileWarnings[file.Name], warn)
}
}
+
return nil
}
+func (r *TrafficOpsReq) PrintWarnings() {
+ log.Infoln("======== Summary of config warnings that may need attention. ========")
+ for file, warning := range r.configFileWarnings {
+ for _, warning := range warning {
+ log.Warnf("%s: %s", file, warning)
+ }
+ }
+ log.Infoln("======== End warning summary ========")
+}
+
// GetHeaderComment looks up the tm.toolname parameter from traffic ops.
func (r *TrafficOpsReq) GetHeaderComment() string {
result, err := getSystemInfo(r.Cfg)
diff --git a/cache-config/t3c-generate/cfgfile/all.go b/cache-config/t3c-generate/cfgfile/all.go
index f0b54da..eb1c9ef 100644
--- a/cache-config/t3c-generate/cfgfile/all.go
+++ b/cache-config/t3c-generate/cfgfile/all.go
@@ -57,14 +57,22 @@ func GetAllConfigs(
if cfg.RevalOnly && fi.Name != atscfg.RegexRevalidateFileName {
continue
}
- txt, contentType, secure, lineComment, err := GetConfigFile(toData, fi, hdrCommentTxt, cfg)
+ txt, contentType, secure, lineComment, warnings, err := GetConfigFile(toData, fi, hdrCommentTxt, cfg)
if err != nil {
return nil, errors.New("getting config file '" + fi.Name + "': " + err.Error())
}
if fi.Name == atscfg.SSLMultiCertConfigFileName {
hasSSLMultiCertConfig = true
}
- configs = append(configs, t3cutil.ATSConfigFile{Name: fi.Name, Path: fi.Path, Text: txt, Secure: secure, ContentType: contentType, LineComment: lineComment})
+ configs = append(configs, t3cutil.ATSConfigFile{
+ Name: fi.Name,
+ Path: fi.Path,
+ Text: txt,
+ Secure: secure,
+ ContentType: contentType,
+ LineComment: lineComment,
+ Warnings: warnings,
+ })
}
if hasSSLMultiCertConfig {
diff --git a/cache-config/t3c-generate/cfgfile/cfgfile_test.go b/cache-config/t3c-generate/cfgfile/cfgfile_test.go
index 60817f2..363d0a4 100644
--- a/cache-config/t3c-generate/cfgfile/cfgfile_test.go
+++ b/cache-config/t3c-generate/cfgfile/cfgfile_test.go
@@ -58,18 +58,18 @@ func TestWriteConfigs(t *testing.T) {
actual := buf.String()
- expected0 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]`
+ expected0 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0","warnings":null},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo","warnings":null}]`
if !strings.Contains(actual, expected0) {
t.Errorf("WriteConfigs expected '%v' actual '%v'", expected0, actual)
}
- expected1 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]`
+ expected1 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0","warnings":null},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo","warnings":null}]`
if !strings.Contains(actual, expected1) {
t.Errorf("WriteConfigs expected config1 '%v' actual '%v'", expected1, actual)
}
- expectedPrefix := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]`
+ expectedPrefix := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0","warnings":null},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo","warnings":null}]`
if !strings.HasPrefix(actual, expectedPrefix) {
t.Errorf("WriteConfigs expected prefix '%v' actual '%v'", expectedPrefix, actual)
}
diff --git a/cache-config/t3c-generate/cfgfile/routing.go b/cache-config/t3c-generate/cfgfile/routing.go
index 0e34832..7323dcb 100644
--- a/cache-config/t3c-generate/cfgfile/routing.go
+++ b/cache-config/t3c-generate/cfgfile/routing.go
@@ -32,7 +32,7 @@ import (
// # DO NOT EDIT - Generated for odol-atsec-sea-22 by Traffic Ops (https://trafficops.comcast.net/) on Mon Oct 26 16:22:19 UTC 2020
// GetConfigFile returns the text of the generated config file, the MIME Content Type of the config file, and any error.
-func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrCommentTxt string, thiscfg config.Cfg) (string, string, bool, string, error) {
+func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrCommentTxt string, thiscfg config.Cfg) (string, string, bool, string, []string, error) {
start := time.Now()
defer func() {
log.Infof("GetConfigFile %v took %v\n", fileInfo.Name, time.Since(start).Round(time.Millisecond))
@@ -44,9 +44,9 @@ func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrComme
logWarnings("getting config file '"+fileInfo.Name+"': ", cfg.Warnings)
if err != nil {
- return "", "", false, "", err
+ return "", "", false, "", []string{}, err
}
- return cfg.Text, cfg.ContentType, cfg.Secure, cfg.LineComment, nil
+ return cfg.Text, cfg.ContentType, cfg.Secure, cfg.LineComment, cfg.Warnings, nil
}
type ConfigFileFunc func(toData *t3cutil.ConfigData, fileName string, hdrCommentTxt string, cfg config.Cfg) (atscfg.Cfg, error)
diff --git a/cache-config/t3c-generate/cfgfile/sslkeys.go b/cache-config/t3c-generate/cfgfile/sslkeys.go
index 478b38f..b9ed4c9 100644
--- a/cache-config/t3c-generate/cfgfile/sslkeys.go
+++ b/cache-config/t3c-generate/cfgfile/sslkeys.go
@@ -66,6 +66,7 @@ func GetSSLCertsAndKeyFiles(toData *t3cutil.ConfigData) ([]t3cutil.ATSConfigFile
keyFile.Path = "/opt/trafficserver/etc/trafficserver/ssl/" // TODO read config, don't hard code
keyFile.Text = string(key)
keyFile.Secure = true
+ keyFile.Warnings = dsWarns
configs = append(configs, keyFile)
certFile := t3cutil.ATSConfigFile{}
@@ -73,6 +74,7 @@ func GetSSLCertsAndKeyFiles(toData *t3cutil.ConfigData) ([]t3cutil.ATSConfigFile
certFile.Path = "/opt/trafficserver/etc/trafficserver/ssl/" // TODO read config, don't hard code
certFile.Text = string(cert)
certFile.Secure = true
+ certFile.Warnings = dsWarns
configs = append(configs, certFile)
}
diff --git a/cache-config/t3cutil/t3cutil.go b/cache-config/t3cutil/t3cutil.go
index a1f7e21..5678ba9 100644
--- a/cache-config/t3cutil/t3cutil.go
+++ b/cache-config/t3cutil/t3cutil.go
@@ -33,12 +33,13 @@ import (
)
type ATSConfigFile struct {
- Name string `json:"name"`
- Path string `json:"path"`
- ContentType string `json:"content_type"`
- LineComment string `json:"line_comment"`
- Secure bool `json:"secure"`
- Text string `json:"text"`
+ Name string `json:"name"`
+ Path string `json:"path"`
+ ContentType string `json:"content_type"`
+ LineComment string `json:"line_comment"`
+ Secure bool `json:"secure"`
+ Text string `json:"text"`
+ Warnings []string `json:"warnings"`
}
// ATSConfigFiles implements sort.Interface and sorts by the Location and then FileNameOnDisk, i.e. the full file path.