This is an automated email from the ASF dual-hosted git repository.
ocket8888 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 7a3e1e0f55 t3c RPM DB check to work with rocky linux 9 (#7866)
7a3e1e0f55 is described below
commit 7a3e1e0f5566b315252ad8bc9bfe195cc8807096
Author: Joe Pappano <[email protected]>
AuthorDate: Tue Nov 14 15:08:53 2023 -0500
t3c RPM DB check to work with rocky linux 9 (#7866)
* fixed RPM DB check to work with rocky linux 9
* Change log entry
* fixed typo
* fixed 2 typos
---
CHANGELOG.md | 1 +
cache-config/t3c-apply/config/config.go | 110 ++++++++++++++++++++++++--------
2 files changed, 86 insertions(+), 25 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1098d6d003..07dffbfcba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -192,6 +192,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7688](https://github.com/apache/trafficcontrol/pull/7688) *Traffic Ops*:
Fixed secured parameters being visible when role has proper permissions.
- [#7697](https://github.com/apache/trafficcontrol/pull/7697) *Traffic Ops*:
Fixed `iloPassword` and `xmppPassword` checking for priv-level instead of using
permissions.
- [#7817](https://github.com/apache/trafficcontrol/pull/7817) *Traffic Control
Cache Config (t3c)* fixed issue that would cause null ptr panic on client
fallback.
+- [#7866](https://github.com/apache/trafficcontrol/pull/7866) *Traffic Control
Cache Config (t3c)* fixed rpm db check to work with rocky linux 9
### Removed
- [#7808](https://github.com/apache/trafficcontrol/pull/7808) *Traffic
Router*: Set SOA `minimum` field to a custom value defined in the
`tld.soa.minimum` param, and remove the previously added
`dns.negative.caching.ttl` property.
diff --git a/cache-config/t3c-apply/config/config.go
b/cache-config/t3c-apply/config/config.go
index e21f9279fd..7f977cec1e 100644
--- a/cache-config/t3c-apply/config/config.go
+++ b/cache-config/t3c-apply/config/config.go
@@ -191,29 +191,6 @@ func directoryExists(dir string) (bool, os.FileInfo) {
return info.IsDir(), info
}
-const rpmDir = "/var/lib/rpm"
-
-// verifies the rpm database files. if there is any database corruption
-// it will return false
-func verifyRpmDB() bool {
- exclude := regexp.MustCompile(`(^\.|^__)`)
- dbFiles, err := os.ReadDir(rpmDir)
- if err != nil {
- return false
- }
- for _, file := range dbFiles {
- if exclude.Match([]byte(file.Name())) {
- continue
- }
- cmd := exec.Command("/usr/lib/rpm/rpmdb_verify",
rpmDir+"/"+file.Name())
- err := cmd.Run()
- if err != nil || cmd.ProcessState.ExitCode() > 0 {
- return false
- }
- }
- return true
-}
-
// derives the ATS Installation directory from
// the rpm config file list.
func GetTSPackageHome() string {
@@ -251,6 +228,68 @@ func GetTSPackageHome() string {
return tsHome
}
+const (
+ rpmDBBdb = "bdb"
+ rpmDBSquLite = "sqlite"
+ rpmDBUnknown = "unknown"
+ rpmDBVerifyCmd = "/usr/lib/rpm/rpmdb_verify"
+ sqliteRpmDbVerifyCmd = "/bin/sqlite3"
+ rpmDir = "/var/lib/rpm"
+ sqliteRpmDB = "rpmdb.sqlite"
+)
+
+// getRpmDBBackend uses "%_db_backend" macro to get the database type
+func getRpmDBBackend() (string, error) {
+ var outBuf bytes.Buffer
+ cmd := exec.Command("/bin/rpm", "-E", "%_db_backend")
+ cmd.Stdout = &outBuf
+ err := cmd.Run()
+ if err != nil {
+ return rpmDBUnknown, err
+ }
+ return strings.TrimSpace(outBuf.String()), nil
+}
+
+// isSqliteInstalled looks to see if the sqlite3 executable
+// is installed which is needed to do the db verify
+func isSqliteInstalled() bool {
+ sqliteUtil := isCommandAvailable("/bin/sqlite3")
+ return sqliteUtil
+}
+
+// verifies the rpm database files. if there is any database corruption
+// it will return false
+func verifyRpmDB(rpmDir string) bool {
+ exclude := regexp.MustCompile(`(^\.|^__)`)
+ dbFiles, err := os.ReadDir(rpmDir)
+ if err != nil {
+ return false
+ }
+ for _, file := range dbFiles {
+ if exclude.Match([]byte(file.Name())) {
+ continue
+ }
+ cmd := exec.Command(rpmDBVerifyCmd, rpmDir+"/"+file.Name())
+ err := cmd.Run()
+ if err != nil || cmd.ProcessState.ExitCode() > 0 {
+ return false
+ }
+ }
+ return true
+}
+
+// verifySqliteRpmDB runs PRAGMA quick_check
+// requires /bin/sqlite3
+func verifySqliteRpmDB(sqliteDB string) bool {
+ args := []string{sqliteDB, `PRAGMA quick_check`}
+ cmd := exec.Command(sqliteRpmDbVerifyCmd, args...)
+ err := cmd.Run()
+ if err != nil || cmd.ProcessState.ExitCode() > 0 {
+ return false
+ }
+ return true
+}
+
func GetCfg(appVersion string, gitRevision string) (Cfg, error) {
var err error
toInfoLog := []string{}
@@ -499,7 +538,29 @@ If any of the related flags are also set, they override
the mode's default behav
os.Setenv("TO_PASS", toPass)
}
- rpmDBisOk := verifyRpmDB()
+ rpmDBisOk := true
+ rpmDBType, err := getRpmDBBackend()
+ if err != nil {
+ toInfoLog = append(toInfoLog, fmt.Sprintf("error getting db
type: %s", err.Error()))
+ rpmDBType = rpmDBUnknown
+ }
+
+ if rpmDBType == rpmDBSquLite {
+ sqliteUtil := isSqliteInstalled()
+ toInfoLog = append(toInfoLog, fmt.Sprintf("RPM database is %s",
rpmDBSquLite))
+ if sqliteUtil {
+ rpmDBisOk = verifySqliteRpmDB(rpmDir + "/" +
sqliteRpmDB)
+ toInfoLog = append(toInfoLog, fmt.Sprintf("RPM database
is ok: %t", rpmDBisOk))
+ } else {
+ toInfoLog = append(toInfoLog, "/bin/sqlite3 not
available, RPM database not checked")
+ }
+ } else if rpmDBType == rpmDBBdb {
+ toInfoLog = append(toInfoLog, fmt.Sprintf("RPM database is %s",
rpmDBBdb))
+ rpmDBisOk = verifyRpmDB(rpmDir)
+ toInfoLog = append(toInfoLog, fmt.Sprintf("RPM database is ok:
%t", rpmDBisOk))
+ } else {
+ toInfoLog = append(toInfoLog, fmt.Sprintf("RPM DB type is %s DB
check will be skipped", rpmDBUnknown))
+ }
if *installPackagesPtr && !rpmDBisOk {
if t3cutil.StrToMode(*runModePtr) == t3cutil.ModeBadAss {
@@ -509,7 +570,6 @@ If any of the related flags are also set, they override the
mode's default behav
}
}
- toInfoLog = append(toInfoLog, fmt.Sprintf("rpm database is ok: %t",
rpmDBisOk))
// set TSHome
var tsHome = ""
if *tsHomePtr != "" {