]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
suite: update tests to handle new 'exists' fs operator
authorDan Mick <dan.mick@redhat.com>
Fri, 26 Feb 2016 02:08:52 +0000 (18:08 -0800)
committerDan Mick <dan.mick@redhat.com>
Fri, 27 May 2016 22:13:01 +0000 (15:13 -0700)
Signed-off-by: Dan Mick <dan.mick@redhat.com>
teuthology/suite.py
teuthology/test/fake_fs.py
teuthology/test/test_describe_tests.py
teuthology/test/test_suite.py

index 53815a8cd13238537c2e27e81ecca1c9adbc152e..843d7c6bbe5bf0c0b3efd902e17114dc3b3e4951 100644 (file)
@@ -991,10 +991,12 @@ def generate_combinations(path, mat, generate_from, generate_to):
             matrix.generate_paths(path, output, combine_path)))
     return ret
 
-def build_matrix(path, _isfile=os.path.isfile,
-                _isdir=os.path.isdir,
-                _listdir=os.listdir,
-                subset=None):
+def build_matrix(path,
+                 _exists=os.path.exists,
+                 _isfile=os.path.isfile,
+                 _isdir=os.path.isdir,
+                 _listdir=os.listdir,
+                 subset=None):
     """
     Return a list of items descibed by path such that if the list of
     items is chunked into mincyclicity pieces, each piece is still a
@@ -1028,16 +1030,17 @@ def build_matrix(path, _isfile=os.path.isfile,
     of chosen subitems.
 
     :param path:        The path to search for yaml fragments
+    :param _exists:     Custom os.path.exists(); for testing only
     :param _isfile:     Custom os.path.isfile(); for testing only
     :param _isdir:      Custom os.path.isdir(); for testing only
     :param _listdir:   Custom os.listdir(); for testing only
     :param subset:     (index, outof)
     """
     mat, first, matlimit = _get_matrix(
-        path, _isfile, _isdir, _listdir, subset)
+        path, _exists, _isfile, _isdir, _listdir, subset)
     return generate_combinations(path, mat, first, matlimit)
 
-def _get_matrix(path, _isfile=os.path.isfile,
+def _get_matrix(path, _exists=os.path.exists, _isfile=os.path.isfile,
                  _isdir=os.path.isdir,
                  _listdir=os.listdir,
                  subset=None):
@@ -1046,7 +1049,7 @@ def _get_matrix(path, _isfile=os.path.isfile,
     matlimit = None
     if subset:
         (index, outof) = subset
-        mat = _build_matrix(path, _isfile, _isdir, _listdir, mincyclicity=outof)
+        mat = _build_matrix(path, _exists, _isfile, _isdir, _listdir, mincyclicity=outof)
         first = (mat.size() / outof) * index
         if index == outof or index == outof - 1:
             matlimit = mat.size()
@@ -1054,13 +1057,13 @@ def _get_matrix(path, _isfile=os.path.isfile,
             matlimit = (mat.size() / outof) * (index + 1)
     else:
         first = 0
-        mat = _build_matrix(path, _isfile, _isdir, _listdir)
+        mat = _build_matrix(path, _exists, _isfile, _isdir, _listdir)
         matlimit = mat.size()
     return mat, first, matlimit
 
-def _build_matrix(path, _isfile=os.path.isfile,
+def _build_matrix(path, _exists=os.path.exists, _isfile=os.path.isfile,
                   _isdir=os.path.isdir, _listdir=os.listdir, mincyclicity=0, item=''):
-    if not os.path.exists(path):
+    if not _exists(path):
         raise IOError('%s does not exist' % path)
     if _isfile(path):
         if path.endswith('.yaml'):
@@ -1079,6 +1082,7 @@ def _build_matrix(path, _isfile=os.path.isfile,
             for fn in sorted(files):
                 submat = _build_matrix(
                     os.path.join(path, fn),
+                    _exists,
                     _isfile,
                     _isdir,
                     _listdir,
@@ -1094,6 +1098,7 @@ def _build_matrix(path, _isfile=os.path.isfile,
             for fn in sorted(files):
                 submat = _build_matrix(
                     os.path.join(path, fn),
+                    _exists,
                     _isfile,
                     _isdir,
                     _listdir,
@@ -1113,6 +1118,7 @@ def _build_matrix(path, _isfile=os.path.isfile,
             for fn in sorted(files):
                 submat = _build_matrix(
                     os.path.join(path, fn),
+                    _exists,
                     _isfile,
                     _isdir,
                     _listdir,
index 4f6d78b6afb560ab94036869fbf1ff8e6446f24d..5c764484a1e4c4314d8c524b079c1c16e083d359 100644 (file)
@@ -66,6 +66,9 @@ def make_fake_fstools(fake_filesystem):
     def fake_isdir(path, fsdict=False):
         return not fake_isfile(path)
 
+    def fake_exists(path, fsdict=False):
+        return fake_isfile(path, fsdict) or fake_isdir(path, fsdict)
+
     def fake_open(path, mode=None, buffering=None):
         components = path.strip('/').split('/')
         subdict = fake_filesystem
@@ -80,4 +83,4 @@ def make_fake_fstools(fake_filesystem):
             return closing(StringIO(''))
         return closing(StringIO(subdict))
 
-    return fake_listdir, fake_isfile, fake_isdir, fake_open
+    return fake_exists, fake_listdir, fake_isfile, fake_isdir, fake_open
index 411ccbc3c7f50395d4577c5ce2dc528d1fdf1c64..c85e0f857fb6d9bec9fd484b187dcf48c4d77615 100644 (file)
@@ -106,8 +106,8 @@ expected_rbd_features = [
 class TestDescribeTests(object):
 
     def setup(self):
-        self.fake_listdir, self.fake_isfile, self.fake_isdir, self.fake_open = \
-            make_fake_fstools(realistic_fs)
+        self.fake_exists, self.fake_listdir, self.fake_isfile,
+            self.fake_isdir, self.fake_open = make_fake_fstools(realistic_fs)
 
     @staticmethod
     def assert_expected_combo_headers(headers):
@@ -231,7 +231,7 @@ class TestDescribeTests(object):
 
 def test_extract_info_dir():
     simple_fs = {'a': {'b.yaml': 'meta: [{foo: c}]'}}
-    _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
+    _, _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
     info = extract_info('a', [], fake_isdir, fake_open)
     assert info == {}
 
@@ -243,7 +243,7 @@ def test_extract_info_dir():
 
 
 def check_parse_error(fs):
-    _, _, fake_isdir, fake_open = make_fake_fstools(fs)
+    _, _, _, fake_isdir, fake_open = make_fake_fstools(fs)
     with pytest.raises(ParseError):
         a = extract_info('a.yaml', ['a'], fake_isdir, fake_open)
         raise Exception(str(a))
@@ -263,6 +263,6 @@ def test_extract_info_not_a_dict():
 
 def test_extract_info_empty_file():
     simple_fs = {'a.yaml': ''}
-    _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
+    _, _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
     info = extract_info('a.yaml', [], fake_isdir, fake_open)
     assert info == {}
index 9c320800ad1338cfd64689454b7ab397f0c7158f..ca2a047c758f06e811c66dedbc21330611b91862 100644 (file)
@@ -463,8 +463,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
                                     fake_listdir)
         assert len(result) == 1
 
@@ -482,8 +482,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
                                     fake_listdir)
         assert len(result) == 4
         assert self.fragment_occurences(result, 'd1_1_1.yaml') == 0.5
@@ -506,8 +506,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
                                     fake_listdir)
         assert len(result) == 8
         assert self.fragment_occurences(result, 'd1_2_0.yaml') == 0.5
@@ -531,8 +531,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
                                     fake_listdir)
         assert len(result) == 8
         assert self.fragment_occurences(result, 'd1_2_2.yaml') == 0.25
@@ -557,8 +557,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
                                     fake_listdir)
         assert len(result) == 2
         for i in result:
@@ -594,8 +594,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
                                     fake_isdir, fake_listdir)
         assert len(result) == 11
         assert self.fragment_occurences(result, 'vps.yaml') == 1 / 11.0
@@ -627,8 +627,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
                                     fake_isdir, fake_listdir)
         fake_fs2 = {
             'teuthology': {
@@ -658,8 +658,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
-        result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2,
+        fake_exists2, fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
+        result2 = suite.build_matrix('teuthology/no-ceph', fake_exists2, fake_isfile2,
                                      fake_isdir2, fake_listdir2)
         assert len(result) == 11
         assert len(result2) == len(result)
@@ -691,8 +691,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
                                     fake_isdir, fake_listdir)
         fake_fs2 = {
             'teuthology': {
@@ -728,8 +728,8 @@ class TestBuildMatrix(object):
                 },
             },
         }
-        fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
-        result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2,
+        fake_exists2, fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
+        result2 = suite.build_matrix('teuthology/no-ceph', fake_exists2, fake_isfile2,
                                      fake_isdir2, fake_listdir2)
         assert len(result) == 11
         assert len(result2) == len(result)
@@ -750,8 +750,8 @@ class TestBuildMatrix(object):
                 'tasks': {'cfuse_workunit_suites_fsstress.yaml': None},
             },
         }
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
-        result = suite.build_matrix('thrash', fake_isfile,
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+        result = suite.build_matrix('thrash', fake_exists, fake_isfile,
                                     fake_isdir, fake_listdir)
         assert len(result) == 1
         assert self.fragment_occurences(result, 'base.yaml') == 1
@@ -810,9 +810,9 @@ class TestSubset(object):
 
     @staticmethod
     def generate_description_list(tree, subset):
-        fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree)
+        fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree)
         mat, first, matlimit = suite._get_matrix(
-            'root', _isfile=fake_isfile, _isdir=fake_isdir,
+            'root', _exists=fake_exists, _isfile=fake_isfile, _isdir=fake_isdir,
             _listdir=fake_listdir, subset=subset)
         return [i[0] for i in suite.generate_combinations(
             'root', mat, first, matlimit)], mat, first, matlimit