Skip to content

Commit

Permalink
requested changes addressed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpappa200 committed Jul 24, 2023
1 parent f28aaf7 commit f4f6bf0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions cache-config/t3c-apply/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,21 @@ func directoryExists(dir string) (bool, os.FileInfo) {
return info.IsDir(), info
}

const RpmDir = "/var/lib/rpm"
const rpmDir = "/var/lib/rpm"

// verifies the rpm database files. if there is any database corruption
// it will return false
func VerifyRpmDB() bool {
func verifyRpmDB() bool {
exclude := regexp.MustCompile(`(^\.|^__)`)
dbFiles, err := os.ReadDir(RpmDir)
dbFiles, err := os.ReadDir(rpmDir)
if err != nil {
return false
}
for _, file := range dbFiles {
if exclude.Match([]byte(file.Name())) {
continue

Check warning on line 205 in cache-config/t3c-apply/config/config.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/config/config.go#L197-L205

Added lines #L197 - L205 were not covered by tests
}
cmd := exec.Command("/usr/lib/rpm/rpmdb_verify", RpmDir+"/"+file.Name())
cmd := exec.Command("/usr/lib/rpm/rpmdb_verify", rpmDir+"/"+file.Name())
err := cmd.Run()
if err != nil || cmd.ProcessState.ExitCode() > 0 {
return false
Expand Down Expand Up @@ -497,7 +497,7 @@ If any of the related flags are also set, they override the mode's default behav
os.Setenv("TO_PASS", toPass)
}

rpmDBisOk := VerifyRpmDB()
rpmDBisOk := verifyRpmDB()

if *installPackagesPtr && !rpmDBisOk {
if t3cutil.StrToMode(*runModePtr) == t3cutil.ModeBadAss {
Expand All @@ -507,7 +507,7 @@ If any of the related flags are also set, they override the mode's default behav
}

Check warning on line 507 in cache-config/t3c-apply/config/config.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/config/config.go#L500-L507

Added lines #L500 - L507 were not covered by tests
}

toInfoLog = append(toInfoLog, fmt.Sprintf("rpm database is ok: %v", rpmDBisOk))
toInfoLog = append(toInfoLog, fmt.Sprintf("rpm database is ok: %t", rpmDBisOk))

Check warning on line 510 in cache-config/t3c-apply/config/config.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/config/config.go#L510

Added line #L510 was not covered by tests
// set TSHome
var tsHome = ""
if *tsHomePtr != "" {
Expand Down Expand Up @@ -621,7 +621,7 @@ If any of the related flags are also set, they override the mode's default behav
if len(fatalLogStrs) > 0 {
for _, str := range fatalLogStrs {
str = strings.TrimSpace(str)
log.Warnln(str)
log.Errorln(str)
}
return Cfg{}, errors.New("fatal error has occurerd")

Check warning on line 626 in cache-config/t3c-apply/config/config.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/config/config.go#L621-L626

Added lines #L621 - L626 were not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion cache-config/t3c-apply/t3c-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func Main() int {
return GitCommitAndExit(ExitCodeServicesError, FailureExitMsg, cfg, metaData, oldMetaData)
}
} else {
log.Infoln("======== RPM DB checks failed, package processing not possible, using installed packages from metadata if available========")
log.Warnln("======== RPM DB checks failed, package processing not possible, using installed packages from metadata if available========")
trops.ProcessPackagesWithMetaData(oldMetaData.InstalledPackages)

Check warning on line 280 in cache-config/t3c-apply/t3c-apply.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/t3c-apply.go#L278-L280

Added lines #L278 - L280 were not covered by tests
}

Expand Down
14 changes: 7 additions & 7 deletions cache-config/t3c-apply/torequest/torequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,12 @@ func (r *TrafficOpsReq) CheckSystemServices() error {
func (r *TrafficOpsReq) IsPackageInstalled(name string) bool {
for k, v := range r.Pkgs {
if strings.HasPrefix(k, name) {
log.Infof("Found in cache for '%v'", k)
log.Infof("Found in cache for '%s'", k)
return v
}
}
if !r.Cfg.RpmDBOk {
log.Warnf("RPM DB is corrupted cannot run IsPackageInstalled for '%v' and package metadata is unavailable", name)
log.Warnf("RPM DB is corrupted cannot run IsPackageInstalled for '%s' and package metadata is unavailable", name)
return false
}
log.Infof("IsPackageInstalled '%v' not found in cache, querying rpm", name)
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func pkgMetaDataToMap(pmd []string) map[string]bool {

func pkgMatch(pkgMetaData []string, pk string) bool {
for _, pkg := range pkgMetaData {
if ok := strings.Contains(pk, pkg); ok {
if strings.Contains(pk, pkg) {
return true
}

Check warning on line 1049 in cache-config/t3c-apply/torequest/torequest.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/torequest/torequest.go#L1045-L1049

Added lines #L1045 - L1049 were not covered by tests
}
Expand All @@ -1056,18 +1056,18 @@ func (r *TrafficOpsReq) ProcessPackagesWithMetaData(packageMetaData []string) er
pkgs, err := getPackages(r.Cfg)
pkgMdataMap := pkgMetaDataToMap(packageMetaData)
if err != nil {
return errors.New("getting packages: " + err.Error())
return fmt.Errorf("getting packages: %w", err)
}
for _, pkg := range pkgs {
fullPackage := pkg.Name + "-" + pkg.Version
if pkgMdataMap[fullPackage] {
log.Infof("package %v is assumed to be installed according to metadata file", fullPackage)
log.Infof("package %s is assumed to be installed according to metadata file", fullPackage)
r.Pkgs[fullPackage] = true
} else if pkgMatch(packageMetaData, pkg.Name) {
log.Infof("package %v is assumed to be installed according to metadata, but doesn't match traffic ops pkg", fullPackage)
log.Infof("package %s is assumed to be installed according to metadata, but doesn't match traffic ops pkg", fullPackage)
r.Pkgs[fullPackage] = true
} else {
log.Infof("package %v does not appear to be installed.", pkg.Name+"-"+pkg.Version)
log.Infof("package %s does not appear to be installed.", pkg.Name+"-"+pkg.Version)
}

Check warning on line 1071 in cache-config/t3c-apply/torequest/torequest.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/torequest/torequest.go#L1055-L1071

Added lines #L1055 - L1071 were not covered by tests
}
return nil

Check warning on line 1073 in cache-config/t3c-apply/torequest/torequest.go

View check run for this annotation

Codecov / codecov/patch

cache-config/t3c-apply/torequest/torequest.go#L1073

Added line #L1073 was not covered by tests
Expand Down

0 comments on commit f4f6bf0

Please sign in to comment.