diff options
Diffstat (limited to 'lib/spack/spack/test/database.py')
-rw-r--r-- | lib/spack/spack/test/database.py | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py index 4395f17f97..c0bb12ce10 100644 --- a/lib/spack/spack/test/database.py +++ b/lib/spack/spack/test/database.py @@ -30,6 +30,7 @@ import multiprocessing import os.path import spack +import spack.install_area from llnl.util.filesystem import join_path from llnl.util.tty.colify import colify from spack.test.mock_database import MockDatabase @@ -40,16 +41,16 @@ def _print_ref_counts(): recs = [] def add_rec(spec): - cspecs = spack.installed_db.query(spec, installed=any) + cspecs = spack.install_area.db.query(spec, installed=any) if not cspecs: recs.append("[ %-7s ] %-20s-" % ('', spec)) else: key = cspecs[0].dag_hash() - rec = spack.installed_db.get_record(cspecs[0]) + rec = spack.install_area.db.get_record(cspecs[0]) recs.append("[ %-7s ] %-20s%d" % (key[:7], spec, rec.ref_count)) - with spack.installed_db.read_transaction(): + with spack.install_area.db.read_transaction(): add_rec('mpileaks ^mpich') add_rec('callpath ^mpich') add_rec('mpich') @@ -82,7 +83,7 @@ class DatabaseTest(MockDatabase): def test_010_all_install_sanity(self): """Ensure that the install layout reflects what we think it does.""" - all_specs = spack.install_layout.all_specs() + all_specs = spack.install_area.layout.all_specs() self.assertEqual(len(all_specs), 13) # query specs with multiple configurations @@ -113,12 +114,12 @@ class DatabaseTest(MockDatabase): def test_015_write_and_read(self): # write and read DB - with spack.installed_db.write_transaction(): - specs = spack.installed_db.query() - recs = [spack.installed_db.get_record(s) for s in specs] + with spack.install_area.db.write_transaction(): + specs = spack.install_area.db.query() + recs = [spack.install_area.db.get_record(s) for s in specs] for spec, rec in zip(specs, recs): - new_rec = spack.installed_db.get_record(spec) + new_rec = spack.install_area.db.get_record(spec) self.assertEqual(new_rec.ref_count, rec.ref_count) self.assertEqual(new_rec.spec, rec.spec) self.assertEqual(new_rec.path, rec.path) @@ -126,7 +127,7 @@ class DatabaseTest(MockDatabase): def _check_merkleiness(self): """Ensure the spack database is a valid merkle graph.""" - all_specs = spack.installed_db.query(installed=any) + all_specs = spack.install_area.db.query(installed=any) seen = {} for spec in all_specs: @@ -139,8 +140,8 @@ class DatabaseTest(MockDatabase): def _check_db_sanity(self): """Utiilty function to check db against install layout.""" - expected = sorted(spack.install_layout.all_specs()) - actual = sorted(self.installed_db.query()) + expected = sorted(spack.install_area.layout.all_specs()) + actual = sorted(self.install_db.query()) self.assertEqual(len(expected), len(actual)) for e, a in zip(expected, actual): @@ -154,13 +155,13 @@ class DatabaseTest(MockDatabase): def test_025_reindex(self): """Make sure reindex works and ref counts are valid.""" - spack.installed_db.reindex(spack.install_layout) + spack.install_area.db.reindex(spack.install_area.layout) self._check_db_sanity() def test_030_db_sanity_from_another_process(self): def read_and_modify(): self._check_db_sanity() # check that other process can read DB - with self.installed_db.write_transaction(): + with self.install_db.write_transaction(): self._mock_remove('mpileaks ^zmpi') p = multiprocessing.Process(target=read_and_modify, args=()) @@ -168,40 +169,40 @@ class DatabaseTest(MockDatabase): p.join() # ensure child process change is visible in parent process - with self.installed_db.read_transaction(): - self.assertEqual(len(self.installed_db.query('mpileaks ^zmpi')), 0) + with self.install_db.read_transaction(): + self.assertEqual(len(self.install_db.query('mpileaks ^zmpi')), 0) def test_040_ref_counts(self): """Ensure that we got ref counts right when we read the DB.""" - self.installed_db._check_ref_counts() + self.install_db._check_ref_counts() def test_050_basic_query(self): """Ensure querying database is consistent with what is installed.""" # query everything - self.assertEqual(len(spack.installed_db.query()), 13) + self.assertEqual(len(spack.install_area.db.query()), 13) # query specs with multiple configurations - mpileaks_specs = self.installed_db.query('mpileaks') - callpath_specs = self.installed_db.query('callpath') - mpi_specs = self.installed_db.query('mpi') + mpileaks_specs = self.install_db.query('mpileaks') + callpath_specs = self.install_db.query('callpath') + mpi_specs = self.install_db.query('mpi') self.assertEqual(len(mpileaks_specs), 3) self.assertEqual(len(callpath_specs), 3) self.assertEqual(len(mpi_specs), 3) # query specs with single configurations - dyninst_specs = self.installed_db.query('dyninst') - libdwarf_specs = self.installed_db.query('libdwarf') - libelf_specs = self.installed_db.query('libelf') + dyninst_specs = self.install_db.query('dyninst') + libdwarf_specs = self.install_db.query('libdwarf') + libelf_specs = self.install_db.query('libelf') self.assertEqual(len(dyninst_specs), 1) self.assertEqual(len(libdwarf_specs), 1) self.assertEqual(len(libelf_specs), 1) # Query by dependency - self.assertEqual(len(self.installed_db.query('mpileaks ^mpich')), 1) - self.assertEqual(len(self.installed_db.query('mpileaks ^mpich2')), 1) - self.assertEqual(len(self.installed_db.query('mpileaks ^zmpi')), 1) + self.assertEqual(len(self.install_db.query('mpileaks ^mpich')), 1) + self.assertEqual(len(self.install_db.query('mpileaks ^mpich2')), 1) + self.assertEqual(len(self.install_db.query('mpileaks ^zmpi')), 1) def _check_remove_and_add_package(self, spec): """Remove a spec from the DB, then add it and make sure everything's @@ -209,13 +210,13 @@ class DatabaseTest(MockDatabase): removed, that it's back when added again, and that ref counts are consistent. """ - original = self.installed_db.query() - self.installed_db._check_ref_counts() + original = self.install_db.query() + self.install_db._check_ref_counts() # Remove spec - concrete_spec = self.installed_db.remove(spec) - self.installed_db._check_ref_counts() - remaining = self.installed_db.query() + concrete_spec = self.install_db.remove(spec) + self.install_db._check_ref_counts() + remaining = self.install_db.query() # ensure spec we removed is gone self.assertEqual(len(original) - 1, len(remaining)) @@ -223,14 +224,14 @@ class DatabaseTest(MockDatabase): self.assertTrue(concrete_spec not in remaining) # add it back and make sure everything is ok. - self.installed_db.add(concrete_spec, spack.install_layout) - installed = self.installed_db.query() + self.install_db.add(concrete_spec, spack.install_area.layout) + installed = self.install_db.query() self.assertTrue(concrete_spec in installed) self.assertEqual(installed, original) # sanity check against direcory layout and check ref counts. self._check_db_sanity() - self.installed_db._check_ref_counts() + self.install_db._check_ref_counts() def test_060_remove_and_add_root_package(self): self._check_remove_and_add_package('mpileaks ^mpich') @@ -239,95 +240,95 @@ class DatabaseTest(MockDatabase): self._check_remove_and_add_package('dyninst') def test_080_root_ref_counts(self): - rec = self.installed_db.get_record('mpileaks ^mpich') + rec = self.install_db.get_record('mpileaks ^mpich') # Remove a top-level spec from the DB - self.installed_db.remove('mpileaks ^mpich') + self.install_db.remove('mpileaks ^mpich') # record no longer in DB self.assertEqual( - self.installed_db.query('mpileaks ^mpich', installed=any), []) + self.install_db.query('mpileaks ^mpich', installed=any), []) # record's deps have updated ref_counts self.assertEqual( - self.installed_db.get_record('callpath ^mpich').ref_count, 0) - self.assertEqual(self.installed_db.get_record('mpich').ref_count, 1) + self.install_db.get_record('callpath ^mpich').ref_count, 0) + self.assertEqual(self.install_db.get_record('mpich').ref_count, 1) # Put the spec back - self.installed_db.add(rec.spec, spack.install_layout) + self.install_db.add(rec.spec, spack.install_area.layout) # record is present again self.assertEqual( - len(self.installed_db.query('mpileaks ^mpich', installed=any)), 1) + len(self.install_db.query('mpileaks ^mpich', installed=any)), 1) # dependencies have ref counts updated self.assertEqual( - self.installed_db.get_record('callpath ^mpich').ref_count, 1) - self.assertEqual(self.installed_db.get_record('mpich').ref_count, 2) + self.install_db.get_record('callpath ^mpich').ref_count, 1) + self.assertEqual(self.install_db.get_record('mpich').ref_count, 2) def test_090_non_root_ref_counts(self): - self.installed_db.get_record('mpileaks ^mpich') - self.installed_db.get_record('callpath ^mpich') + self.install_db.get_record('mpileaks ^mpich') + self.install_db.get_record('callpath ^mpich') # "force remove" a non-root spec from the DB - self.installed_db.remove('callpath ^mpich') + self.install_db.remove('callpath ^mpich') # record still in DB but marked uninstalled self.assertEqual( - self.installed_db.query('callpath ^mpich', installed=True), []) + self.install_db.query('callpath ^mpich', installed=True), []) self.assertEqual( - len(self.installed_db.query('callpath ^mpich', installed=any)), 1) + len(self.install_db.query('callpath ^mpich', installed=any)), 1) # record and its deps have same ref_counts - self.assertEqual(self.installed_db.get_record( + self.assertEqual(self.install_db.get_record( 'callpath ^mpich', installed=any).ref_count, 1) - self.assertEqual(self.installed_db.get_record('mpich').ref_count, 2) + self.assertEqual(self.install_db.get_record('mpich').ref_count, 2) # remove only dependent of uninstalled callpath record - self.installed_db.remove('mpileaks ^mpich') + self.install_db.remove('mpileaks ^mpich') # record and parent are completely gone. self.assertEqual( - self.installed_db.query('mpileaks ^mpich', installed=any), []) + self.install_db.query('mpileaks ^mpich', installed=any), []) self.assertEqual( - self.installed_db.query('callpath ^mpich', installed=any), []) + self.install_db.query('callpath ^mpich', installed=any), []) # mpich ref count updated properly. - mpich_rec = self.installed_db.get_record('mpich') + mpich_rec = self.install_db.get_record('mpich') self.assertEqual(mpich_rec.ref_count, 0) def test_100_no_write_with_exception_on_remove(self): def fail_while_writing(): - with self.installed_db.write_transaction(): + with self.install_db.write_transaction(): self._mock_remove('mpileaks ^zmpi') raise Exception() - with self.installed_db.read_transaction(): + with self.install_db.read_transaction(): self.assertEqual( - len(self.installed_db.query('mpileaks ^zmpi', installed=any)), + len(self.install_db.query('mpileaks ^zmpi', installed=any)), 1) self.assertRaises(Exception, fail_while_writing) # reload DB and make sure zmpi is still there. - with self.installed_db.read_transaction(): + with self.install_db.read_transaction(): self.assertEqual( - len(self.installed_db.query('mpileaks ^zmpi', installed=any)), + len(self.install_db.query('mpileaks ^zmpi', installed=any)), 1) def test_110_no_write_with_exception_on_install(self): def fail_while_writing(): - with self.installed_db.write_transaction(): + with self.install_db.write_transaction(): self._mock_install('cmake') raise Exception() - with self.installed_db.read_transaction(): + with self.install_db.read_transaction(): self.assertEqual( - self.installed_db.query('cmake', installed=any), []) + self.install_db.query('cmake', installed=any), []) self.assertRaises(Exception, fail_while_writing) # reload DB and make sure cmake was not written. - with self.installed_db.read_transaction(): + with self.install_db.read_transaction(): self.assertEqual( - self.installed_db.query('cmake', installed=any), []) + self.install_db.query('cmake', installed=any), []) |