Bug 1529344

Summary: Printing vdsm configuration by running config.py fail with "AttributeError: 'module' object has no attribute 'glob'"
Product: [oVirt] vdsm Reporter: Nir Soffer <nsoffer>
Component: CoreAssignee: Marcin Sobczyk <msobczyk>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Matyáš <pmatyas>
Severity: low Docs Contact:
Priority: unspecified    
Version: 4.20.15CC: bugs, lleistne, mperina
Target Milestone: ovirt-4.4.0Flags: rule-engine: ovirt-4.4+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-05-20 20:03:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Nir Soffer 2017-12-27 17:26:02 UTC
Description of problem:

Before 4.2, it was possible to the documentation for vdsm configuration file
by running vdsm/config.py as a script:

    python /usr/lib/python2.7/site-packages/vdsm/common/config.py

This fails now with this error:

# python /usr/lib/python2.7/site-packages/vdsm/common/config.py
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/vdsm/common/config.py", line 739, in <module>
    config = load('vdsm')
  File "/usr/lib/python2.7/site-packages/vdsm/common/config.py", line 711, in load
    read_configs(cfg, name)
  File "/usr/lib/python2.7/site-packages/vdsm/common/config.py", line 733, in read_configs
    dropins.extend(glob.glob(pattern))
AttributeError: 'module' object has no attribute 'glob'

The issue is the new vdsm/common/glob.py module, added in:

commit fd13ee1e55d61f06516ad10c890470a2c822b9c8
Author: Idan Shaby <ishaby>
Date:   Thu Jan 12 18:43:56 2017 +0200

    compat: add glob.escape from Python 3.6
    
    glob.escape was added in Python 3.6.
    Since we need it for escaping values that are passed to glob.glob,
    this patch adds it to glob.py.
    
    Change-Id: Id2989a9edcc87ec671d8c29ec7900e01b537b3f1
    Related-To: https://bugzilla.redhat.com/1302358
    Signed-off-by: Idan Shaby <ishaby>

But having a glob.py module in vdsm is correct; we use absolute
imports, so this module does not hide the python stdlib glob module.
In vdsm, we import our private glob with:

   from vdsm.common import glob

So the real issue is running config.py as a script - this is not a reliable
way to print configuration, since running a script change PYTHONPATH
to include the directory where the script is located, and this hides
the python builtin glob module.

The right way to print the configuration is:

# python -c "from vdsm.common import config; config.print_config()"

# VDSM Sample Configuration

[vars]

# Enable core dump.
# core_dump_enable = true

# Reserves memory for the host to prevent VMs from using all the
# physical pages. The values are in Mbytes.
# host_mem_reserve = 256
...


Version-Release number of selected component (if applicable):
vdsm > 4.19.10

How reproducible:
Always

Steps to Reproduce:
1. Run:

    python /usr/lib/python2.7/site-packages/vdsm/common/config.py


I think the best way to resolve this would be to convert config.py to regular
module, so it is not possible to run it as a script.

If the feature of printing the configuration is important enough, it should be
provided by "vdsm-tool show-default-config".

Comment 1 Nir Soffer 2017-12-27 17:26:51 UTC
This is a regression introduced in 4.1.

Comment 2 Red Hat Bugzilla Rules Engine 2017-12-28 15:03:20 UTC
This bug report has Keywords: Regression or TestBlocker.
Since no regressions or test blockers are allowed between releases, it is also being identified as a blocker for this release. Please resolve ASAP.

Comment 3 Red Hat Bugzilla Rules Engine 2018-01-02 14:25:05 UTC
This bug report has Keywords: Regression or TestBlocker.
Since no regressions or test blockers are allowed between releases, it is also being identified as a blocker for this release. Please resolve ASAP.

Comment 4 Irit Goihman 2018-01-02 14:27:24 UTC
Removing regression keyword to avoid automatic assignment of blocker flag.

Comment 6 Petr Matyáš 2020-01-21 14:19:58 UTC
Verified on vdsm-4.40.0-180.giteba0b75.el8ev.x86_64

Now you can do 'vdsm-tool show-default-config'

Comment 7 Sandro Bonazzola 2020-05-20 20:03:05 UTC
This bugzilla is included in oVirt 4.4.0 release, published on May 20th 2020.

Since the problem described in this bug report should be
resolved in oVirt 4.4.0 release, it has been closed with a resolution of CURRENT RELEASE.

If the solution does not work for you, please open a new bug report.