This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 'test_distutils.test_bdist_rpm' causes creation of directory '.rpmdb' on home dir
Type: behavior Stage: resolved
Components: Distutils, Tests Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dstufft, eric.araujo, francismb, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2014-09-28 21:26 by francismb, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
confine_hidden_rpmdb_dir_creation.patch francismb, 2014-09-28 21:26 review
Messages (10)
msg227777 - (view) Author: Francis MB (francismb) * Date: 2014-09-28 21:26
Running the test suite or 'test_distutils' triggers the creation of the directory '.rpmdb'. I noticed that because somehow that directory was bad formed and got errors while running the test suite:

error: db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH:
Database environment version mismatch
error: cannot open Packages index using db5 -  (-30969)
error: cannot open Packages database in /home/ci/.rpmdb
error: db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH:
Database environment version mismatch
error: cannot open Packages index using db5 -  (-30969)
error: cannot open Packages database in /home/ci/.rpmdb
After moving that directory and running the suite again the directory reappeared (but that time, and since then, no errors occurred). It seems that 'test_distutils.test_bdist_rpm' triggers that behavior. This seems to be due 'rpm' having it so configured [1]. In my case:

$ rpm -v --showrc | grep '.rpmdb'
-14: _dbpath    %(bash -c 'echo ~/.rpmdb')

Here is a patch that confines the creation of this directory to the temporal test directory.

Regards,
francis

----
[1] https://bugs.launchpad.net/rpm/+bug/1069350
msg227785 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-29 01:40
Thanks for the report and patch.

You should use test.support.EnvironmentVarGuard to make the environment change temporary.
msg227830 - (view) Author: Francis MB (francismb) * Date: 2014-09-29 20:33
Why is test.support.EnvironmentVarGuard preferable over distutils.test.support.EnvironGuard (with this one I'm not getting the warnings below)?

If I change the patch to (not so different (?) as in other tests using EnvironmentVarGuard):

$hg diff
diff -r 2b212a8186e0 Lib/distutils/tests/test_bdist_rpm.py
--- a/Lib/distutils/tests/test_bdist_rpm.py     Mon Sep 29 11:25:00 2014 -0400
+++ b/Lib/distutils/tests/test_bdist_rpm.py     Mon Sep 29 21:11:25 2014 +0200
@@ -5,7 +5,7 @@
 import os
 import tempfile
 import shutil
-from test.support import run_unittest
+from test.support import run_unittest, EnvironmentVarGuard
 
 from distutils.core import Distribution
 from distutils.command.bdist_rpm import bdist_rpm
@@ -36,8 +36,11 @@
         super(BuildRpmTestCase, self).setUp()
         self.old_location = os.getcwd()
         self.old_sys_argv = sys.argv, sys.argv[:]
+        self.env = EnvironmentVarGuard()
 
     def tearDown(self):
+        self.env.__exit__()
+        del self.env                                                                      
         os.chdir(self.old_location)                                                       
         sys.argv = self.old_sys_argv[0]                                                   
         sys.argv[:] = self.old_sys_argv[1]                                                
@@ -54,6 +57,7 @@                                                                          
     def test_quiet(self):                                                                 
         # let's create a package                                                          
         tmp_dir = self.mkdtemp()                                                          
+        self.env['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation                   
         pkg_dir = os.path.join(tmp_dir, 'foo')                                            
         os.mkdir(pkg_dir)                                                                 
         self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
@@ -96,6 +100,7 @@
     def test_no_optimize_flag(self):
         # let's create a package that brakes bdist_rpm
         tmp_dir = self.mkdtemp()
+        self.env['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation
         pkg_dir = os.path.join(tmp_dir, 'foo')
         os.mkdir(pkg_dir)
         self.write_file((pkg_dir, 'setup.py'), SETUP_PY)

I get the message:
[102/390] test_distutils
Warning -- threading._dangling was modified by test_distutils

Using EnvironmentVarGuard as context manager gives the same warning.
msg227833 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-29 20:43
Sorry, I'm not that familiar with distutils and did not realize it had stuff for environment protection in the setUp/tearDown.
msg227840 - (view) Author: Francis MB (francismb) * Date: 2014-09-29 21:06
No problem, but is the, 3 lines, patch ok?
what are the next steps, if yes?
Shouldn't be the issue status now 'patch review' or similar?

Thanks in advance!
msg227841 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-29 21:07
Yes, sorry I forgot to change the stage.
msg228046 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-01 00:54
New changeset ec6cee80926f by R David Murray in branch '3.4':
#22512: move distutils rpm test's .rpmdb to testing tmpdir.
https://hg.python.org/cpython/rev/ec6cee80926f

New changeset 4877f91a0389 by R David Murray in branch 'default':
Merge: #22512: move distutils rpm test's .rpmdb to testing tmpdir.
https://hg.python.org/cpython/rev/4877f91a0389
msg228047 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-01 00:58
New changeset c5bcc4d07344 by R David Murray in branch '2.7':
#22512: move distutils rpm test's .rpmdb to testing tmpdir.
https://hg.python.org/cpython/rev/c5bcc4d07344
msg228048 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-01 00:58
Thanks, Francis.
msg228103 - (view) Author: Francis MB (francismb) * Date: 2014-10-01 17:40
I have to thank for your time, David!
History
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66702
2014-10-01 17:40:19francismbsetmessages: + msg228103
2014-10-01 00:58:39r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg228048

stage: commit review -> resolved
2014-10-01 00:58:27python-devsetmessages: + msg228047
2014-10-01 00:54:22python-devsetnosy: + python-dev
messages: + msg228046
2014-09-29 21:07:48r.david.murraysetmessages: + msg227841
stage: commit review
2014-09-29 21:06:12francismbsetmessages: + msg227840
2014-09-29 20:43:06r.david.murraysetmessages: + msg227833
2014-09-29 20:33:12francismbsetmessages: + msg227830
2014-09-29 01:40:23r.david.murraysetnosy: + r.david.murray

messages: + msg227785
versions: + Python 3.4
2014-09-28 21:26:41francismbcreate