Beispiel #1
0
    def test_ignored_author_in_parent_dir(self):
        """Check that author ignored in BOTMETA in a parent directory are removed

        Some authors are defined in 'author' field of 'DOCUMENTATION' module
        metadata and ignored in a parent directory entry in BOTMETA: ignored
        authors aren't maintainers.
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
        files:
            # Check with two parent directories
            $modules/baz/test:
                maintainers: ElsA
                ignored: Oliver
            $modules/baz/test/code.py:
                maintainers: bob
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code.py': [u'Louise', u'Oliver'],
        }

        expected_maintainers = sorted([u'ElsA', u'bob',
                                       u'Louise'])  # Oliver not here

        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1,
                         len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(
            sorted(indexer.modules[u'lib/ansible/modules/baz/test/code.py']
                   [u'maintainers']), expected_maintainers)
Beispiel #2
0
    def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self):
        """
        PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set
        """
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
            $module_utils/baz/bar.py:
                maintainers: TiTi ZaZa
        """

        module_indexer = create_indexer(textwrap.dedent(BOTMETA), {})

        self.assertEqual(len(module_indexer.modules), 1)  # ensure only fake data are loaded
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/foo/bar.py'][u'maintainers']), [u'ElsA', u'Oliver'])
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/baz/bar.py'][u'maintainers']), [u'TiTi', u'ZaZa'])

        CM = ComponentMatcherMock()
        CM.expected_results = [
            {
                u'repo_filename': u'lib/ansible/module_utils/foo/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'ElsA', u'Oliver'],
                u'notify': [u'ElsA', u'Oliver'],
                u'ignore': [],
            },
            {
                u'repo_filename': u'lib/ansible/modules/baz/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'TiTi', u'ZaZa'],
                u'notify': [u'TiTi', u'ZaZa'],
                u'ignore': [],
            }
        ]

        issue = IssueMock(u'/dev/null')
        issue.user.login = u'ElsA'
        issue.html_url = u'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [
            MockFile(u'lib/ansible/module_utils/foo/bar.py'),
            MockFile(u'lib/ansible/module_utils/baz/bar.py')
        ]
        iw.file_indexer = FileIndexerMock()
        iw.repo = MockRepo(repo_path='ansible/ansible')

        meta = self.meta.copy()
        iw._commits = []
        meta.update(get_component_match_facts(iw, CM, []))
        facts = get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca', u'mscherer'], botnames=[u'ansibot'])

        self.assertEqual(iw.submitter, u'ElsA')
        self.assertFalse(facts[u'owner_pr'])
Beispiel #3
0
    def test_owner_pr_module_utils_and_modules_updated_submitter_maintainer_2(self):
        """
        PR updates 2 files (one below modules, the other below module_utils),
        submitter is a maintainer from both, check that owner_pr is set.
        Submitter is maintainer from module_utils file.
        """
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $modules/foo/bar.py:
                maintainers: ElsA ZaZa
            $module_utils/baz/bar.py:
                maintainers: TiTi mscherer
        """

        modules = {u'lib/ansible/modules/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules), 2)  # ensure only fake data are loaded
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/modules/foo/bar.py'][u'maintainers']), [u'ElsA', u'ZaZa'])
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/baz/bar.py'][u'maintainers']), [u'TiTi', u'mscherer'])

        CM = ComponentMatcherMock()
        CM.expected_results = [
            {
                u'repo_filename': u'lib/ansible/module_utils/foo/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'ElsA', u'mscherer'],
                u'notify': [u'ElsA', u'mscherer'],
                u'ignore': [],
            },
            {
                u'repo_filename': u'lib/ansible/modules/baz/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'TiTi', u'ZaZa'],
                u'notify': [u'TiTi', u'ZaZa'],
                u'ignore': [],
            }
        ]

        meta = self.meta.copy()

        datafile = u'tests/fixtures/shipit/0_issue.yml'
        statusfile = u'tests/fixtures/shipit/0_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [
                MockFile(u'lib/ansible/modules/foo/bar.py'),
                MockFile(u'lib/ansible/module_utils/baz/bar.py')
            ]
            iw.file_indexer = FileIndexerMock()
            meta.update(get_component_match_facts(iw, CM, []))
            facts = get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca'], botnames=[u'ansibot'])

        self.assertEqual(iw.submitter, u'mscherer')
        self.assertFalse(facts[u'owner_pr'])
Beispiel #4
0
    def test_ignored_author(self):
        """Check that author ignored in BOTMETA are removed"""
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
        files:
            $modules/baz/test/code.py:
                maintainers: bob
                ignored: Oliver
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code.py': [u'Louise', u'Oliver'],
        }

        expected_maintainers = sorted([u'bob', u'Louise'])  # not Oliver

        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1,
                         len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(
            sorted(indexer.modules[u'lib/ansible/modules/baz/test/code.py']
                   [u'maintainers']), expected_maintainers)
    def test_ignored_author_in_parent_dir(self):
        """Check that author ignored in BOTMETA in a parent directory are removed

        Some authors are defined in 'author' field of 'DOCUMENTATION' module
        metadata and ignored in a parent directory entry in BOTMETA: ignored
        authors aren't maintainers.
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
        files:
            # Check with two parent directories
            $modules/baz/test:
                maintainers: ElsA
                ignored: Oliver
            $modules/baz/test/code.py:
                maintainers: bob
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code.py': [u'Louise', u'Oliver'],
        }

        expected_maintainers = sorted([u'ElsA', u'bob', u'Louise'])  # Oliver not here

        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1, len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code.py'][u'maintainers']), expected_maintainers)
    def test_ignored_maintainer_in_parent_dir(self):
        """Check that maintainer defined in BOTMETA but ignored in a child entry are ignored.

        No author defined in 'author' field of 'DOCUMENTATION' module metadata.
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
        files:
            # Check with two parent directories
            $modules/baz/test:
                maintainers: ElsA Oliver
            $modules/baz/test/code1.py:
                ignored: Oliver
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code1.py': None,
            u'lib/ansible/modules/baz/test/code2.py': None,
            u'lib/ansible/modules/baz/test/code3.py': None,
            u'lib/ansible/modules/baz/test/code4.py': None,
        }

        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1, len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code1.py'][u'maintainers']), [u'ElsA'])
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code2.py'][u'maintainers']), sorted([u'ElsA', u'Oliver']))
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code3.py'][u'maintainers']), sorted([u'ElsA', u'Oliver']))
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code4.py'][u'maintainers']), sorted([u'ElsA', u'Oliver']))
Beispiel #7
0
    def test_owner_pr_submitter_is_maintainer_one_module_file_updated_changelog(
            self):
        """
        Submitter is a maintainer: ensure owner_pr is set even if changelog fragment is present
        """
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
        files:
            $modules/foo/bar.py:
                maintainers: ElsA Oliver
        """

        modules = {u'lib/ansible/modules/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta[u'files']
                   [u'lib/ansible/modules/foo/bar.py'][u'maintainers']),
            [u'ElsA', u'Oliver'])

        datafile = u'tests/fixtures/shipit/2_issue.yml'
        statusfile = u'tests/fixtures/shipit/2_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [
                MockFile(u'lib/ansible/modules/foo/bar.py'),
                MockFile(u'changelogs/fragments/00000-fragment.yaml')
            ]
            # need to give the wrapper a list of known files to compare against
            iw.file_indexer = FileIndexerMock()
            iw.file_indexer.files.append(u'lib/ansible/modules/foo/bar.py')

            # predefine what the matcher is going to return
            CM = ComponentMatcherMock()
            CM.expected_results = [{
                u'repo_filename': u'lib/ansible/modules/foo/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'ElsA', u'Oliver'],
                u'notify': [u'ElsA', u'Oliver'],
                u'ignore': [],
            }]

            meta = self.meta.copy()
            iw._commits = []
            meta.update(get_component_match_facts(iw, CM, []))
            facts = get_shipit_facts(iw,
                                     meta,
                                     module_indexer,
                                     core_team=[u'bcoca', u'mscherer'],
                                     botnames=[u'ansibot'])

            self.assertEqual(iw.submitter, u'ElsA')
            self.assertTrue(facts[u'owner_pr'])
Beispiel #8
0
    def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated(
            self):
        """
        Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated)
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
        """

        modules = {'lib/ansible/module_utils/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')]

        # need to give the wrapper a list of known files to compare against
        iw.file_indexer = FileIndexerMock()

        # predefine what the matcher is going to return
        CM = ComponentMatcherMock()
        CM.expected_results = [{
            'repo_filename': 'lib/ansible/module_utils/foo/bar.py',
            'labels': [],
            'support': None,
            'maintainers': ['ElsA', 'Oliver'],
            'notify': ['ElsA', 'Oliver'],
            'ignore': [],
        }]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, meta, CM, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertTrue(facts['owner_pr'])
Beispiel #9
0
    def test_owner_pr_submitter_is_maintainer_new_module(self):
        """
        Submitter is a maintainer: pull request adds a new module: ensure owner_pr is False
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $modules/foo/bar.py:
                maintainers: ElsA mscherer
        """

        modules = {}  # new module
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         1)  # ensure only fake data are loaded
        # Ensure that BOTMETA.yml updates doesn't interfere
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/modules/foo/bar.py']['maintainers']),
            ['ElsA', 'mscherer'])

        CM = ComponentMatcherMock()
        CM.expected_results = [{
            'repo_filename': 'lib/ansible/modules/foo/bar.py',
            'labels': [],
            'support': None,
            'maintainers': ['ElsA', 'mscherer'],
            'notify': ['ElsA', 'mscherer'],
            'ignore': [],
        }]

        meta = self.meta.copy()

        datafile = 'tests/fixtures/shipit/0_issue.yml'
        statusfile = 'tests/fixtures/shipit/0_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [MockFile('lib/ansible/modules/foo/bar.py')]
            iw.file_indexer = FileIndexerMock()
            #iw.file_indexer.files.append('lib/ansible/modules/foo/bar.py')

            meta.update(
                get_component_match_facts(iw, {}, CM, iw.file_indexer,
                                          module_indexer, []))
            facts = get_shipit_facts(iw,
                                     meta,
                                     module_indexer,
                                     core_team=['bcoca'],
                                     botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'mscherer')
        self.assertFalse(facts['owner_pr'])
Beispiel #10
0
    def test_owner_pr_module_utils_and_modules_updated_submitter_maintainer_2(
            self):
        """
        PR updates 2 files (one below modules, the other below module_utils),
        submitter is a maintainer from both, check that owner_pr is set.
        Submitter is maintainer from module_utils file.
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $modules/foo/bar.py:
                maintainers: ElsA ZaZa
            $module_utils/baz/bar.py:
                maintainers: TiTi mscherer
        """

        modules = {'lib/ansible/modules/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/modules/foo/bar.py']['maintainers']),
            ['ElsA', 'ZaZa'])
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/baz/bar.py']['maintainers']),
            ['TiTi', 'mscherer'])

        meta = self.meta.copy()

        datafile = 'tests/fixtures/shipit/0_issue.yml'
        statusfile = 'tests/fixtures/shipit/0_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [
                MockFile('lib/ansible/modules/foo/bar.py'),
                MockFile('lib/ansible/module_utils/baz/bar.py')
            ]
            meta.update(
                get_component_match_facts(iw, {}, FileIndexerMock(),
                                          module_indexer, []))
            facts = get_shipit_facts(iw,
                                     meta,
                                     module_indexer,
                                     core_team=['bcoca'],
                                     botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'mscherer')
        self.assertFalse(facts['owner_pr'])
Beispiel #11
0
    def test_review_facts_are_defined_module_utils(self):
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils:
              support: community
            $modules/foo/bar.py:
                maintainers: ElsA ZaZa
            $module_utils/baz/bar.py:
                maintainers: TiTi mscherer
        """

        modules = {u'lib/ansible/modules/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules), 2)  # ensure only fake data are loaded
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/modules/foo/bar.py'][u'maintainers']),[u'ElsA', u'ZaZa'])
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/baz/bar.py'][u'maintainers']),[u'TiTi', u'mscherer'])

        datafile = u'tests/fixtures/shipit/2_issue.yml'
        statusfile = u'tests/fixtures/shipit/2_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [MockFile(u'lib/ansible/module_utils/foo/bar.py')]
            # need to give the wrapper a list of known files to compare against
            iw.file_indexer = FileIndexerMock()
            iw.file_indexer.files.append(u'lib/ansible/modules/foo/bar.py')

            # predefine what the matcher is going to return
            CM = ComponentMatcherMock()
            CM.expected_results = [
                {
                    u'repo_filename': u'lib/ansible/module_utils/foo/bar.py',
                    u'labels': [],
                    u'support': None,
                    u'maintainers': [u'ElsA', u'Oliver'],
                    u'notify': [u'ElsA', u'Oliver'],
                    u'ignore': [],
                }
            ]

            meta = self.meta.copy()
            iw._commits = []
            meta.update(get_component_match_facts(iw, CM, []))
            meta.update(get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca'], botnames=[u'ansibot']))
            facts = get_review_facts(iw, meta)

        self.assertTrue(facts[u'community_review'])
        self.assertFalse(facts[u'core_review'])
        self.assertFalse(facts[u'committer_review'])
Beispiel #12
0
    def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self):
        """
        PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
            $module_utils/baz/bar.py:
                maintainers: TiTi ZaZa
        """

        module_indexer = create_indexer(textwrap.dedent(BOTMETA), {})

        self.assertEqual(len(module_indexer.modules),
                         1)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/baz/bar.py']['maintainers']),
            ['TiTi', 'ZaZa'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [
            MockFile('lib/ansible/module_utils/foo/bar.py'),
            MockFile('lib/ansible/module_utils/baz/bar.py')
        ]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, {}, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertFalse(facts['owner_pr'])
Beispiel #13
0
    def test_owner_pr_submitter_is_maintainer_new_module(self):
        """
        Submitter is a maintainer: pull request adds a new module: ensure owner_pr is False
        """
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $modules/foo/bar.py:
                maintainers: ElsA mscherer
        """

        modules = {}  # new module
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules), 1)  # ensure only fake data are loaded
        # Ensure that BOTMETA.yml updates doesn't interfere
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/modules/foo/bar.py'][u'maintainers']), [u'ElsA', u'mscherer'])

        CM = ComponentMatcherMock()
        CM.expected_results = [
            {
                u'repo_filename': u'lib/ansible/modules/foo/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'ElsA', u'mscherer'],
                u'notify': [u'ElsA', u'mscherer'],
                u'ignore': [],
            }
        ]

        meta = self.meta.copy()

        datafile = u'tests/fixtures/shipit/0_issue.yml'
        statusfile = u'tests/fixtures/shipit/0_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [MockFile(u'lib/ansible/modules/foo/bar.py')]
            iw.file_indexer = FileIndexerMock()

            meta.update(get_component_match_facts(iw, CM, []))
            facts = get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca'], botnames=[u'ansibot'])

        self.assertEqual(iw.submitter, u'mscherer')
        self.assertFalse(facts[u'owner_pr'])
Beispiel #14
0
    def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated(
            self):
        """
        Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated)
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
        """

        modules = {'lib/ansible/module_utils/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, None, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertTrue(facts['owner_pr'])
Beispiel #15
0
    def test_owner_pr_submitter_is_maintainer_one_modules_file_updated(self):
        """
        Submitter is a maintainer: ensure owner_pr is set (only one file below modules updated)
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $modules/foo/bar.py:
                maintainers: ElsA mscherer
        """

        modules = {'lib/ansible/modules/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/modules/foo/bar.py']['maintainers']),
            ['ElsA', 'mscherer'])

        meta = self.meta.copy()

        datafile = 'tests/fixtures/shipit/0_issue.yml'
        statusfile = 'tests/fixtures/shipit/0_prstatus.json'
        with get_issue(datafile, statusfile) as iw:
            iw.pr_files = [MockFile('lib/ansible/modules/foo/bar.py')]

            meta.update(
                get_component_match_facts(iw, {}, FileIndexerMock(),
                                          module_indexer, []))
            facts = get_shipit_facts(iw,
                                     meta,
                                     module_indexer,
                                     core_team=['bcoca'],
                                     botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'mscherer')
        self.assertTrue(facts['owner_pr'])
Beispiel #16
0
    def test_module_authors_inherit_from_directory_maintainers(self):
        """Check maintainers

        Authors defined in 'author' field of 'DOCUMENTATION' module metadata inherit from
        directory maintainers specified in BOTMETA.

        - author is defined in 'author' field of 'DOCUMENTATION' module metadata ('bob')
        - module path not in BOTMETA ('lib/ansible/modules/foo/bar/baz.py')
        - one parent directory in BOTMETA with one maintainer ('lib/ansible/modules/foo/bar')
        """
        BOTMETA = """
        ---
        macros:
            team_green:
              - larry
              - cow
            modules: lib/ansible/modules
        files:
            $modules/foo/bar: jim
        """

        expected = {
            u'lib/ansible/modules/foo/bar': {
                u'labels':
                sorted([u'lib', u'ansible', u'modules', u'foo', u'bar']),
                u'maintainers': [u'jim'],
                u'maintainers_keys': [u'lib/ansible/modules/foo/bar'],
            }
        }

        filepath = u'lib/ansible/modules/foo/bar/baz.py'
        filepaths = {filepath: [u'bob']}
        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(indexer.botmeta[u'files'], expected)

        self.assertEqual(len(indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(set(indexer.modules[filepath][u'maintainers']),
                         set([u'bob', u'jim']))  # both
        self.assertEqual(indexer.modules[filepath][u'maintainers_keys'],
                         [u'lib/ansible/modules/foo/bar'])
    def test_authors_not_omitted_if_entry_in_BOTMETA(self):
        """Check that authors aren't omitted when metadata are overidden in BOTMETA

        Ensure that authors defined in 'author' field of 'DOCUMENTATION' module
        metadata aren't omitted when there is a matching entry in BOTMETA.yml.

        Same BOTMETA.yml, but now authors are defined in 'author' field of
        'DOCUMENTATION' module metadata.
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code.py': [u'Louise'],
        }

        expected_maintainers = sorted([u'Loulou', u'bob', u'jim', u'ZaZa', u'Louise'])

        indexer = create_indexer(textwrap.dedent(self.BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1, len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code.py'][u'maintainers']), expected_maintainers)
    def test_ignored_author(self):
        """Check that author ignored in BOTMETA are removed"""
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
        files:
            $modules/baz/test/code.py:
                maintainers: bob
                ignored: Oliver
        """

        filepaths = {
            u'lib/ansible/modules/baz/test/code.py': [u'Louise', u'Oliver'],
        }

        expected_maintainers = sorted([u'bob', u'Louise'])  # not Oliver

        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1, len(filepaths))  # ensure only fake data are loaded
        self.assertEqual(sorted(indexer.modules[u'lib/ansible/modules/baz/test/code.py'][u'maintainers']), expected_maintainers)
Beispiel #19
0
    def test_maintainers(self):
        """maintainers don't get mix up

        - author is defined in 'author' field of 'DOCUMENTATION' module metadata ('Hubert')
        - module path not in BOTMETA ('lib/ansible/modules/packaging/apt.py')
        - one another directory with one maintainer in BOTMETA, directory name
          is included in module path but is unrelated ('packaging/')
        """

        BOTMETA = """
        ---
        macros:
            team_green:
              - larry
              - cow
            modules: lib/ansible/modules
        files:
            packaging/:
              maintainers: csim
        """
        expected = {
            u'packaging': {
                u'maintainers': [u'csim'],
                u'maintainers_keys': [u'packaging'],
                u'labels': [u'packaging'],
            }
        }

        filepath = u'lib/ansible/modules/packaging/apt.py'
        filepaths = {filepath: [u'Hubert']}
        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(indexer.botmeta[u'files'], expected)

        self.assertEqual(len(indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(indexer.modules[filepath][u'maintainers'],
                         [u'Hubert'])
        self.assertFalse(indexer.modules[filepath][u'maintainers_keys'])
    def test_module_authors_inherit_from_directory_maintainers(self):
        """Check maintainers

        Authors defined in 'author' field of 'DOCUMENTATION' module metadata inherit from
        directory maintainers specified in BOTMETA.

        - author is defined in 'author' field of 'DOCUMENTATION' module metadata ('bob')
        - module path not in BOTMETA ('lib/ansible/modules/foo/bar/baz.py')
        - one parent directory in BOTMETA with one maintainer ('lib/ansible/modules/foo/bar')
        """
        BOTMETA = """
        ---
        macros:
            team_green:
              - larry
              - cow
            modules: lib/ansible/modules
        files:
            $modules/foo/bar: jim
        """

        expected = {
            u'lib/ansible/modules/foo/bar': {
                u'labels': sorted([u'lib', u'ansible', u'modules', u'foo', u'bar']),
                u'maintainers': [u'jim'],
                u'maintainers_keys': [u'lib/ansible/modules/foo/bar'],
            }
        }

        filepath = u'lib/ansible/modules/foo/bar/baz.py'
        filepaths = {filepath: [u'bob']}
        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(indexer.botmeta[u'files'], expected)

        self.assertEqual(len(indexer.modules), 2)  # ensure only fake data are loaded
        self.assertEqual(set(indexer.modules[filepath][u'maintainers']), set([u'bob', u'jim']))  # both
        self.assertEqual(indexer.modules[filepath][u'maintainers_keys'], [u'lib/ansible/modules/foo/bar'])
    def test_maintainers(self):
        """maintainers don't get mix up

        - author is defined in 'author' field of 'DOCUMENTATION' module metadata ('Hubert')
        - module path not in BOTMETA ('lib/ansible/modules/packaging/apt.py')
        - one another directory with one maintainer in BOTMETA, directory name
          is included in module path but is unrelated ('packaging/')
        """

        BOTMETA = """
        ---
        macros:
            team_green:
              - larry
              - cow
            modules: lib/ansible/modules
        files:
            packaging/:
              maintainers: csim
        """
        expected = {
            u'packaging': {
                u'maintainers': [u'csim'],
                u'maintainers_keys': [u'packaging'],
                u'labels': [u'packaging'],
            }
        }

        filepath = u'lib/ansible/modules/packaging/apt.py'
        filepaths = {filepath: [u'Hubert']}
        indexer = create_indexer(textwrap.dedent(BOTMETA), filepaths)

        self.assertEqual(indexer.botmeta[u'files'], expected)

        self.assertEqual(len(indexer.modules), 2)  # ensure only fake data are loaded
        self.assertEqual(indexer.modules[filepath][u'maintainers'], [u'Hubert'])
        self.assertFalse(indexer.modules[filepath][u'maintainers_keys'])
    def test_maintainers_inherit_from_directory_maintainers(self):
        """Check maintainers inheritance

        No author defined in 'author' field of 'DOCUMENTATION' module metadata.
        """

        filepaths = {
            u'lib/ansible/modules/foo/bar/baz.py': None,
            u'lib/ansible/modules/foo2/bar2/baz.py': None,
            u'lib/ansible/modules/bar/foofoo.py': None,
            u'lib/ansible/modules/baz/test/code.py': None,
        }

        expected = {}
        key = u'lib/ansible/modules/foo/bar'
        expected[key] = {
            u'maintainers': [u'jim'],
            u'maintainers_keys': [key],
        }
        key = u'lib/ansible/modules/foo/bar/baz.py'
        expected[key] = {
            u'maintainers': [u'bob', u'jim'],
            u'maintainers_keys': [u'lib/ansible/modules/foo/bar', key],
        }
        key = u'lib/ansible/modules/foo2/bar2'
        expected[key] = {
            u'maintainers': [u'jim'],
            u'maintainers_keys': [key],
        }
        key = u'lib/ansible/modules/foo2/bar2/baz.py'
        expected[key] = {
            u'maintainers': [u'bob', u'jim'],
            u'maintainers_keys': [u'lib/ansible/modules/foo2/bar2', key],
        }
        key = u'lib/ansible/modules/bar/foo'
        expected[key] = {
            u'maintainers': [u'csim'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/bar/foofoo.py'
        expected[key] = {
            u'maintainers': [u'uolip'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/baz'
        expected[key] = {
            u'maintainers': [u'Loulou', u'ZaZa'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/baz/test'
        expected[key] = {
            u'maintainers': [u'Loulou', u'jim', u'ZaZa'],
            u'maintainers_keys': [u'lib/ansible/modules/baz', key],
        }

        key = u'lib/ansible/modules/baz/test/code.py'
        expected[key] = {
            u'maintainers': [u'Loulou', u'bob', u'jim', u'ZaZa'],
            u'maintainers_keys': [u'lib/ansible/modules/baz', u'lib/ansible/modules/baz/test', key],
        }

        indexer = create_indexer(textwrap.dedent(self.BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1, len(filepaths))  # ensure only fake data are loaded

        for k in expected:
            # BOTMETA and modules have identical maintainers since there is no authors
            # defined in source code
            self.assertEqual(sorted(indexer.botmeta[u'files'][k][u'maintainers_keys']),sorted(expected[k][u'maintainers_keys']))
            self.assertEqual(sorted(indexer.botmeta[u'files'][k][u'maintainers']), sorted(expected[k][u'maintainers']))

        for k in filepaths:
            self.assertEqual(sorted(indexer.modules[k][u'maintainers_keys']),sorted(expected[k][u'maintainers_keys']))
            self.assertEqual(sorted(indexer.modules[k][u'maintainers']), sorted(expected[k][u'maintainers']))
Beispiel #23
0
    def test_maintainers_inherit_from_directory_maintainers(self):
        """Check maintainers inheritance

        No author defined in 'author' field of 'DOCUMENTATION' module metadata.
        """

        filepaths = {
            u'lib/ansible/modules/foo/bar/baz.py': None,
            u'lib/ansible/modules/foo2/bar2/baz.py': None,
            u'lib/ansible/modules/bar/foofoo.py': None,
            u'lib/ansible/modules/baz/test/code.py': None,
        }

        expected = {}
        key = u'lib/ansible/modules/foo/bar'
        expected[key] = {
            u'maintainers': [u'jim'],
            u'maintainers_keys': [key],
        }
        key = u'lib/ansible/modules/foo/bar/baz.py'
        expected[key] = {
            u'maintainers': [u'bob', u'jim'],
            u'maintainers_keys': [u'lib/ansible/modules/foo/bar', key],
        }
        key = u'lib/ansible/modules/foo2/bar2'
        expected[key] = {
            u'maintainers': [u'jim'],
            u'maintainers_keys': [key],
        }
        key = u'lib/ansible/modules/foo2/bar2/baz.py'
        expected[key] = {
            u'maintainers': [u'bob', u'jim'],
            u'maintainers_keys': [u'lib/ansible/modules/foo2/bar2', key],
        }
        key = u'lib/ansible/modules/bar/foo'
        expected[key] = {
            u'maintainers': [u'csim'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/bar/foofoo.py'
        expected[key] = {
            u'maintainers': [u'uolip'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/baz'
        expected[key] = {
            u'maintainers': [u'Loulou', u'ZaZa'],
            u'maintainers_keys': [key],
        }

        key = u'lib/ansible/modules/baz/test'
        expected[key] = {
            u'maintainers': [u'Loulou', u'jim', u'ZaZa'],
            u'maintainers_keys': [u'lib/ansible/modules/baz', key],
        }

        key = u'lib/ansible/modules/baz/test/code.py'
        expected[key] = {
            u'maintainers': [u'Loulou', u'bob', u'jim', u'ZaZa'],
            u'maintainers_keys':
            [u'lib/ansible/modules/baz', u'lib/ansible/modules/baz/test', key],
        }

        indexer = create_indexer(textwrap.dedent(self.BOTMETA), filepaths)

        self.assertEqual(len(indexer.modules) - 1,
                         len(filepaths))  # ensure only fake data are loaded

        for k in expected:
            # BOTMETA and modules have identical maintainers since there is no authors
            # defined in source code
            self.assertEqual(
                sorted(indexer.botmeta[u'files'][k][u'maintainers_keys']),
                sorted(expected[k][u'maintainers_keys']))
            self.assertEqual(
                sorted(indexer.botmeta[u'files'][k][u'maintainers']),
                sorted(expected[k][u'maintainers']))

        for k in filepaths:
            self.assertEqual(sorted(indexer.modules[k][u'maintainers_keys']),
                             sorted(expected[k][u'maintainers_keys']))
            self.assertEqual(sorted(indexer.modules[k][u'maintainers']),
                             sorted(expected[k][u'maintainers']))