def test_emulate_teuthology_noceph(self): fake_fs = { 'teuthology': { 'no-ceph': { '%': None, 'clusters': { 'single.yaml': None, }, 'distros': { 'baremetal.yaml': None, 'rhel7.0.yaml': None, 'ubuntu12.04.yaml': None, 'ubuntu14.04.yaml': None, 'vps.yaml': None, 'vps_centos6.5.yaml': None, 'vps_debian7.yaml': None, 'vps_rhel6.4.yaml': None, 'vps_rhel6.5.yaml': None, 'vps_rhel7.0.yaml': None, 'vps_ubuntu14.04.yaml': None, }, 'tasks': { 'teuthology.yaml': None, }, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('teuthology/no-ceph', fake_isfile, fake_isdir, fake_listdir) assert len(result) == 11 assert self.fragment_occurences(result, 'vps.yaml') == 1 / 11.0
def test_convolve_with_concat(self): fake_fs = { 'd0_0': { '%': None, 'd1_0': { 'd1_0_0.yaml': None, }, 'd1_1': { 'd1_1_0.yaml': None, 'd1_1_1.yaml': None, }, 'd1_2': { '+': None, 'd1_2_0.yaml': None, 'd1_2_1.yaml': None, 'd1_2_2.yaml': None, 'd1_2_3.yaml': None, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('d0_0', fake_isfile, fake_isdir, fake_listdir) assert len(result) == 2 for i in result: assert 'd0_0/d1_2/d1_2_0.yaml' in i[1] assert 'd0_0/d1_2/d1_2_1.yaml' in i[1] assert 'd0_0/d1_2/d1_2_2.yaml' in i[1] assert 'd0_0/d1_2/d1_2_3.yaml' in i[1]
def generate_description_list(tree, subset): fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree) mat, first, matlimit = suite._get_matrix( 'root', _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
def test_extract_info_dir(): simple_fs = {'a': {'b.yaml': 'meta: [{foo: c}]'}} _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs) info = extract_info('a', [], fake_isdir, fake_open) assert info == {} info = extract_info('a', ['foo', 'bar'], fake_isdir, fake_open) assert info == {'foo': '', 'bar': ''} info = extract_info('a/b.yaml', ['foo', 'bar'], fake_isdir, fake_open) assert info == {'foo': 'c', 'bar': ''}
def generate_description_list(tree, subset): fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree) mat, first, matlimit = suite._get_matrix('root', _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
def test_extract_info_dir(m_isdir, m_open): simple_fs = {'a': {'b.yaml': 'meta: [{foo: c}]'}} _, _, _, m_isdir.side_effect, m_open.side_effect = \ make_fake_fstools(simple_fs) info = extract_info('a', []) assert info == {} info = extract_info('a', ['foo', 'bar']) assert info == {'foo': '', 'bar': ''} info = extract_info('a/b.yaml', ['foo', 'bar']) assert info == {'foo': 'c', 'bar': ''}
def test_convolve_2x2(self): fake_fs = { 'd0_0': { '%': None, 'd1_0': { 'd1_0_0.yaml': None, 'd1_0_1.yaml': None, }, 'd1_1': { 'd1_1_0.yaml': None, 'd1_1_1.yaml': None, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('d0_0', fake_isfile, fake_isdir, fake_listdir) assert len(result) == 4 assert self.fragment_occurences(result, 'd1_1_1.yaml') == 0.5
def test_sort_order(self): # This test ensures that 'ceph' comes before 'ceph-thrash' when yaml # fragments are sorted. fake_fs = { 'thrash': { '%': None, 'ceph-thrash': { 'default.yaml': None }, 'ceph': { 'base.yaml': None }, 'clusters': { 'mds-1active-1standby.yaml': None }, 'debug': { 'mds_client.yaml': None }, 'fs': { 'btrfs.yaml': None }, 'msgr-failures': { 'none.yaml': None }, 'overrides': { 'whitelist_wrongly_marked_down.yaml': None }, '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_isdir, fake_listdir) assert len(result) == 1 assert self.fragment_occurences(result, 'base.yaml') == 1 fragments = result[0][1] assert fragments[0] == 'thrash/ceph/base.yaml' assert fragments[1] == 'thrash/ceph-thrash/default.yaml'
def test_concatenate_1x2x3(self): fake_fs = { 'd0_0': { '+': None, 'd1_0': { 'd1_0_0.yaml': None, }, 'd1_1': { 'd1_1_0.yaml': None, 'd1_1_1.yaml': None, }, 'd1_2': { 'd1_2_0.yaml': None, 'd1_2_1.yaml': None, 'd1_2_2.yaml': None, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('d0_0', fake_isfile, fake_isdir, fake_listdir) assert len(result) == 1
def test_sort_order(self): # This test ensures that 'ceph' comes before 'ceph-thrash' when yaml # fragments are sorted. fake_fs = { 'thrash': { '%': None, 'ceph-thrash': {'default.yaml': None}, 'ceph': {'base.yaml': None}, 'clusters': {'mds-1active-1standby.yaml': None}, 'debug': {'mds_client.yaml': None}, 'fs': {'btrfs.yaml': None}, 'msgr-failures': {'none.yaml': None}, 'overrides': {'whitelist_wrongly_marked_down.yaml': None}, '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_isdir, fake_listdir) assert len(result) == 1 assert self.fragment_occurences(result, 'base.yaml') == 1 fragments = result[0][1] assert fragments[0] == 'thrash/ceph/base.yaml' assert fragments[1] == 'thrash/ceph-thrash/default.yaml'
def check_parse_error(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))
def setup(self): self.fake_listdir, self.fake_isfile, self.fake_isdir, self.fake_open = \ make_fake_fstools(realistic_fs)
def test_extract_info_empty_file(): simple_fs = {'a.yaml': ''} _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs) info = extract_info('a.yaml', [], fake_isdir, fake_open) assert info == {}
def test_disable_extension(self): fake_fs = { 'teuthology': { 'no-ceph': { '%': None, 'clusters': { 'single.yaml': None, }, 'distros': { 'baremetal.yaml': None, 'rhel7.0.yaml': None, 'ubuntu12.04.yaml': None, 'ubuntu14.04.yaml': None, 'vps.yaml': None, 'vps_centos6.5.yaml': None, 'vps_debian7.yaml': None, 'vps_rhel6.4.yaml': None, 'vps_rhel6.5.yaml': None, 'vps_rhel7.0.yaml': None, 'vps_ubuntu14.04.yaml': None, }, 'tasks': { 'teuthology.yaml': None, }, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('teuthology/no-ceph', fake_isfile, fake_isdir, fake_listdir) fake_fs2 = { 'teuthology': { 'no-ceph': { '%': None, 'clusters': { 'single.yaml': None, }, 'distros': { 'baremetal.yaml': None, 'rhel7.0.yaml': None, 'ubuntu12.04.yaml': None, 'ubuntu14.04.yaml': None, 'vps.yaml': None, 'vps_centos6.5.yaml': None, 'vps_debian7.yaml': None, 'vps_rhel6.4.yaml': None, 'vps_rhel6.5.yaml': None, 'vps_rhel7.0.yaml': None, 'vps_ubuntu14.04.yaml': None, 'forcefilevps_ubuntu14.04.yaml.disable': None, 'forcefilevps_ubuntu14.04.yaml.anotherextension': None, }, 'tasks': { 'teuthology.yaml': None, 'forcefilevps_ubuntu14.04notyaml': None, }, 'forcefilevps_ubuntu14.04notyaml': None, 'tasks.disable': { 'teuthology2.yaml': None, 'forcefilevps_ubuntu14.04notyaml': None, }, }, }, } fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools( fake_fs2) result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2, fake_isdir2, fake_listdir2) assert len(result) == 11 assert len(result2) == len(result)
def check_parse_error(fs, m_isdir, m_open): _, _, _, m_isdir.side_effect, m_open.side_effect = make_fake_fstools(fs) with pytest.raises(ParseError): a = extract_info('a.yaml', ['a']) raise Exception(str(a))
class TestDescribeTests(object): patchpoints = [ 'os.path.exists', 'os.listdir', 'os.path.isfile', 'os.path.isdir', '__builtin__.open', ] fake_fns = make_fake_fstools(realistic_fs) def setup(self): self.mocks = dict() self.patchers = dict() klass = self.__class__ for ppoint, fn in zip(klass.patchpoints, klass.fake_fns): mockobj = MagicMock() patcher = patch(ppoint, mockobj) mockobj.side_effect = fn patcher.start() self.mocks[ppoint] = mockobj self.patchers[ppoint] = patcher def stop_patchers(self): for patcher in self.patchers.values(): patcher.stop() def teardown(self): self.stop_patchers() @staticmethod def assert_expected_combo_headers(headers): assert headers == (['subsuite depth 0'] + sorted(set(filter(bool, expected_facets)))) def test_no_filters(self): rows = tree_with_info('basic', [], False, '', []) assert rows == [[x] for x in expected_tree] def test_single_filter(self): rows = tree_with_info('basic', ['desc'], False, '', []) assert rows == map(list, zip(expected_tree, expected_desc)) rows = tree_with_info('basic', ['rbd_features'], False, '', []) assert rows == map(list, zip(expected_tree, expected_rbd_features)) def test_single_filter_with_facets(self): rows = tree_with_info('basic', ['desc'], True, '', []) assert rows == map(list, zip(expected_tree, expected_facets, expected_desc)) rows = tree_with_info('basic', ['rbd_features'], True, '', []) assert rows == map( list, zip(expected_tree, expected_facets, expected_rbd_features)) def test_no_matching(self): rows = tree_with_info('basic', ['extra'], False, '', []) assert rows == map(list, zip(expected_tree, [''] * len(expected_tree))) rows = tree_with_info('basic', ['extra'], True, '', []) assert rows == map( list, zip(expected_tree, expected_facets, [''] * len(expected_tree))) def test_multiple_filters(self): rows = tree_with_info('basic', ['desc', 'rbd_features'], False, '', []) assert rows == map( list, zip(expected_tree, expected_desc, expected_rbd_features)) rows = tree_with_info('basic', ['rbd_features', 'desc'], False, '', []) assert rows == map( list, zip(expected_tree, expected_rbd_features, expected_desc)) def test_multiple_filters_with_facets(self): rows = tree_with_info('basic', ['desc', 'rbd_features'], True, '', []) assert rows == map( list, zip(expected_tree, expected_facets, expected_desc, expected_rbd_features)) rows = tree_with_info('basic', ['rbd_features', 'desc'], True, '', []) assert rows == map( list, zip(expected_tree, expected_facets, expected_rbd_features, expected_desc)) def test_combinations_only_facets(self): headers, rows = get_combinations('basic', [], None, 1, None, None, True) self.assert_expected_combo_headers(headers) assert rows == [['basic', 'install', 'fixed-1', 'rbd_api_tests']] def test_combinations_desc_features(self): headers, rows = get_combinations('basic', ['desc', 'rbd_features'], None, 1, None, None, False) assert headers == ['desc', 'rbd_features'] descriptions = '\n'.join([ 'install ceph', 'single node cluster', 'c/c++ librbd api tests with default settings', ]) assert rows == [[descriptions, 'default']] def test_combinations_filter_in(self): headers, rows = get_combinations('basic', [], None, 0, ['old_format'], None, True) self.assert_expected_combo_headers(headers) assert rows == [[ 'basic', 'install', 'fixed-1', 'rbd_api_tests_old_format' ]] def test_combinations_filter_out(self): headers, rows = get_combinations('basic', [], None, 0, None, ['old_format'], True) self.assert_expected_combo_headers(headers) assert rows == [['basic', 'install', 'fixed-1', 'rbd_api_tests']]
def test_extract_info_empty_file(m_isdir, m_open): simple_fs = {'a.yaml': ''} _, _, _, m_isdir.side_effect, m_open.side_effect = \ make_fake_fstools(simple_fs) info = extract_info('a.yaml', []) assert info == {}
def test_disable_extension(self): fake_fs = { 'teuthology': { 'no-ceph': { '%': None, 'clusters': { 'single.yaml': None, }, 'distros': { 'baremetal.yaml': None, 'rhel7.0.yaml': None, 'ubuntu12.04.yaml': None, 'ubuntu14.04.yaml': None, 'vps.yaml': None, 'vps_centos6.5.yaml': None, 'vps_debian7.yaml': None, 'vps_rhel6.4.yaml': None, 'vps_rhel6.5.yaml': None, 'vps_rhel7.0.yaml': None, 'vps_ubuntu14.04.yaml': None, }, 'tasks': { 'teuthology.yaml': None, }, }, }, } fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs) result = suite.build_matrix('teuthology/no-ceph', fake_isfile, fake_isdir, fake_listdir) fake_fs2 = { 'teuthology': { 'no-ceph': { '%': None, 'clusters': { 'single.yaml': None, }, 'distros': { 'baremetal.yaml': None, 'rhel7.0.yaml': None, 'ubuntu12.04.yaml': None, 'ubuntu14.04.yaml': None, 'vps.yaml': None, 'vps_centos6.5.yaml': None, 'vps_debian7.yaml': None, 'vps_rhel6.4.yaml': None, 'vps_rhel6.5.yaml': None, 'vps_rhel7.0.yaml': None, 'vps_ubuntu14.04.yaml': None, 'forcefilevps_ubuntu14.04.yaml.disable': None, 'forcefilevps_ubuntu14.04.yaml.anotherextension': None, }, 'tasks': { 'teuthology.yaml': None, 'forcefilevps_ubuntu14.04notyaml': None, }, 'forcefilevps_ubuntu14.04notyaml': None, 'tasks.disable': { 'teuthology2.yaml': None, 'forcefilevps_ubuntu14.04notyaml': None, }, }, }, } fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2) result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2, fake_isdir2, fake_listdir2) assert len(result) == 11 assert len(result2) == len(result)