New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(scanner/redhat): make cache before detect dnf modules #1812
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix this bug, shouldn't it be implemented to create a cache before checking the DNF module?
I would write like this diff --git a/scanner/redhatbase.go b/scanner/redhatbase.go
index 47afa67..fb2aa8d 100644
--- a/scanner/redhatbase.go
+++ b/scanner/redhatbase.go
@@ -420,10 +420,6 @@ func (o *redhatBase) scanPackages() (err error) {
return xerrors.Errorf("Failed to scan installed packages: %w", err)
}
- if o.EnabledDnfModules, err = o.detectEnabledDnfModules(); err != nil {
- return xerrors.Errorf("Failed to detect installed dnf modules: %w", err)
- }
-
fn := func(pkgName string) execResult { return o.exec(fmt.Sprintf("rpm -q --last %s", pkgName), noSudo) }
o.Kernel.RebootRequired, err = o.rebootRequired(fn)
if err != nil {
@@ -433,23 +429,37 @@ func (o *redhatBase) scanPackages() (err error) {
// Only warning this error
}
- if o.getServerInfo().Mode.IsOffline() {
+ if o.getServerInfo().Mode.IsOffline() || (o.Distro.Family == constant.RedHat && o.getServerInfo().Mode.IsFast()) {
return nil
- } else if o.Distro.Family == constant.RedHat {
- if o.getServerInfo().Mode.IsFast() {
- return nil
- }
}
- updatable, err := o.scanUpdatablePackages()
+ updatables, modules, err := func() (models.Packages, []string, error) {
+ if err = o.yumMakeCache(); err != nil {
+ return nil, nil, xerrors.Errorf("Failed to `yum makecache`: %w", err)
+ }
+
+ modules, err := o.detectEnabledDnfModules()
+ if err != nil {
+ return nil, nil, xerrors.Errorf("Failed to detect installed dnf modules: %w", err)
+ }
+
+ updatables, err := o.scanUpdatablePackages()
+ if err != nil {
+ return nil, nil, xerrors.Errorf("Failed to scan updatable packages: %w", err)
+ }
+
+ return updatables, modules, nil
+ }()
if err != nil {
- err = xerrors.Errorf("Failed to scan updatable packages: %w", err)
+ // Only warning this error
+ err = xerrors.Errorf("Failed to scan updatable packages and dnf modules: %w", err)
o.log.Warnf("err: %+v", err)
o.warns = append(o.warns, err)
- // Only warning this error
- } else {
- o.Packages.MergeNewVersion(updatable)
+ return nil
}
+ o.Packages.MergeNewVersion(updatables)
+ o.EnabledDnfModules = modules
+
return nil
}
@@ -645,10 +655,6 @@ func (o *redhatBase) yumMakeCache() error {
}
func (o *redhatBase) scanUpdatablePackages() (models.Packages, error) {
- if err := o.yumMakeCache(); err != nil {
- return nil, xerrors.Errorf("Failed to `yum makecache`: %w", err)
- }
-
isDnf := o.exec(util.PrependProxyEnv(`repoquery --version | grep dnf`), o.sudo.repoquery()).isSuccess()
cmd := `repoquery --all --pkgnarrow=updates --qf='%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPO}'`
if isDnf {
|
cc9c610
to
4e01d55
Compare
I tested it and it looked fine, so I modified it as you suggested. |
123b43d
to
e8afbdd
Compare
e8afbdd
to
6d425da
Compare
Detecting the dnf module is a necessary task regardless of offline mode or redhat fast mode. |
What did you implement:
When scanning for redhat, there was an error in the execution part of the following command.
The cacheonly flag was specified for this command, so that module information was retrieved by referencing the cache.
The scan was failing because the
dnf --nogpgcheck --cacheonly --color=never --quiet module list --enabled
was executed before theyum makecache
command to create the cache was executed.This problem does not occur if the cache is created before the scan.
So I changed the
dnf --nogpgcheck --cacheonly --color=never --quiet module list --enabled
to be executed after yum makecache.Note that if you run the scan offline, yum makecache will fail, so the scan will also fail.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist:
You don't have to satisfy all of the following.
make fmt
make test
Is this ready for review?: YES
Reference