Beispiel #1
0
    def test_no_comment_if_verdict_overriden(self, lp, bugs_from_changes,
                                             smtp):
        """Make sure the previous 'bug' of commenting on uploads that had no
           failing tests (or had them still running) because of the
           current_policy_verdict getting reset to REJECTED_PERMANENTLY
           by some other policy does not happen anymore."""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir
            pkg_mock = Mock()
            pkg_mock.self_link = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565'

            lp.return_value = {'entries': [pkg_mock]}

            # This should no longer be a valid bug as we switched how we
            # actually determine if a regression is present, but still
            # - better to have an explicit test case for it.
            excuse = FakeExcuseVerdictOverriden
            pol = SRUADTRegressionPolicy(options, {})
            status = pol.apply_policy_impl(None, None, 'testpackage', None,
                                           FakeSourceData, excuse)
            self.assertEqual(status, PolicyVerdict.PASS)
            bugs_from_changes.assert_not_called()
            lp.assert_not_called()
            smtp.sendmail.assert_not_called()
Beispiel #2
0
    def test_no_comment_if_commented(self, lp, bugs_from_changes, smtp):
        """Don't comment if package has been already commented on"""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir
            pkg_mock = Mock()
            pkg_mock.self_link = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565'
            bugs_from_changes.return_value = {'entries': [pkg_mock]}

            previous_state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '55.0',
                        'ignored': '0.1',
                    }
                },
            }
            excuse = FakeExcuse
            pol = SRUADTRegressionPolicy(options, {})
            # Set a base state
            pol.state = previous_state
            status = pol.apply_policy_impl(None, None, 'testpackage', None,
                                           FakeSourceData, excuse)
            self.assertEqual(status, PolicyVerdict.PASS)
            bugs_from_changes.assert_not_called()
            lp.assert_not_called()
            smtp.sendmail.assert_not_called()
Beispiel #3
0
    def test_no_comment_dry_run(self, lp, bugs_from_changes, smtp, log):
        """Verify bug commenting about ADT regressions and save the state"""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir

            pkg_mock = {}
            pkg_mock[
                'self_link'] = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565'

            lp.return_value = {'entries': [pkg_mock]}

            previous_state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '54.0',
                        'ignored': '0.1',
                    }
                },
                'ghostdistro': {
                    'spooky': {
                        'ignored': '0.1',
                    }
                }
            }
            excuse = FakeExcuse
            pol = SRUADTRegressionPolicy(options, {}, dry_run=True)
            # Set a base state
            pol.state = previous_state
            status = pol.apply_policy_impl(None, None, 'testpackage', None,
                                           FakeSourceData, excuse)
            self.assertEqual(status, PolicyVerdict.PASS)
            # Assert that we were looking for the right package as per
            # FakeSourceData contents
            self.assertSequenceEqual(lp.mock_calls, [
                call(
                    'testbuntu/+archive/primary', {
                        'distro_series': '/testbuntu/zazzy',
                        'exact_match': 'true',
                        'order_by_date': 'true',
                        'pocket': 'Proposed',
                        'source_name': 'testpackage',
                        'version': '55.0',
                        'ws.op': 'getPublishedSources',
                    }),
                call(
                    'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565',
                    {
                        'ws.op': 'changesFileUrl',
                    })
            ])

            # Nothing happened
            smtp.assert_not_called()
            smtp.sendmail.assert_not_called()
            self.assertDictEqual(pol.state, previous_state)
            log.assert_called_with(
                '[dry-run] Sending ADT regression message to LP: #2 regarding testpackage/55.0 in zazzy'
            )
Beispiel #4
0
 def test_bugs_from_changes(self, urlopen_mock):
     """Check extraction of bug numbers from .changes files"""
     with TemporaryDirectory() as tmpdir:
         options = FakeOptions
         options.unstable = tmpdir
         pol = SRUADTRegressionPolicy(options, {})
         bugs = pol.bugs_from_changes('http://some.url')
         self.assertEqual(len(bugs), 4)
         self.assertSetEqual(bugs, set((1, 4, 2, 31337)))
Beispiel #5
0
    def test_initialize(self, lp):
        """Check state load, old package cleanup and LP login"""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir
            pkg_mock1 = Mock()
            pkg_mock1.source_name = 'testpackage'
            pkg_mock2 = Mock()
            pkg_mock2.source_name = 'otherpackage'

            # Since we want to be as accurate as possible, we return query
            # results per what query has been performed.
            def query_side_effect(link, query):
                if query['source_name'] == 'testpackage':
                    return {'entries': [pkg_mock1]}
                elif query['source_name'] == 'otherpackage':
                    return {'entries': [pkg_mock2]}
                return {'entries': []}

            lp.side_effect = query_side_effect
            state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '54.0',
                        'toremove': '0.1',
                        'otherpackage': '13ubuntu1',
                    }
                }
            }
            # Prepare the state file
            state_path = os.path.join(options.unstable,
                                      'sru_regress_inform_state')
            with open(state_path, 'w') as f:
                json.dump(state, f)
            pol = SRUADTRegressionPolicy(options, {})
            pol.initialise(FakeBritney())
            # Check if the stale packages got purged and others not
            expected_state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '54.0',
                        'otherpackage': '13ubuntu1',
                    }
                },
            }
            # Make sure the state file has been loaded correctly
            self.assertDictEqual(pol.state, expected_state)
            # Check if we logged in with the right LP credentials
            self.assertEqual(pol.email_host, 'localhost:1337')
Beispiel #6
0
    def test_no_comment_if_passed(self, lp, bugs_from_changes, smtp):
        """Don't comment if all tests passed"""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir
            pkg_mock = Mock()
            pkg_mock.self_link = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565'

            bugs_from_changes.return_value = {'entries': [pkg_mock]}

            excuse = FakeExcusePass
            pol = SRUADTRegressionPolicy(options, {})
            status = pol.apply_policy_impl(None, None, 'testpackage', None,
                                           FakeSourceData, excuse)
            self.assertEqual(status, PolicyVerdict.PASS)
            bugs_from_changes.assert_not_called()
            lp.assert_not_called()
            smtp.sendmail.assert_not_called()
Beispiel #7
0
 def test_bugs_from_changes_retry(self, urlopen_mock):
     """Check .changes extraction retry mechanism"""
     with TemporaryDirectory() as tmpdir:
         options = FakeOptions
         options.unstable = tmpdir
         pol = SRUADTRegressionPolicy(options, {})
         self.assertRaises(URLError, pol.bugs_from_changes,
                           'http://some.url')
         self.assertEqual(urlopen_mock.call_count, 3)
Beispiel #8
0
    def test_comment_on_regression_and_update_state(self, lp,
                                                    bugs_from_changes, smtp,
                                                    log):
        """Verify bug commenting about ADT regressions and save the state"""
        with TemporaryDirectory() as tmpdir:
            options = FakeOptions
            options.unstable = tmpdir

            pkg_mock = {}
            pkg_mock[
                'self_link'] = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565'

            lp.return_value = {'entries': [pkg_mock]}

            previous_state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '54.0',
                        'ignored': '0.1',
                    }
                },
                'ghostdistro': {
                    'spooky': {
                        'ignored': '0.1',
                    }
                }
            }
            excuse = FakeExcuse
            pol = SRUADTRegressionPolicy(options, {})
            # Set a base state
            pol.state = previous_state
            status = pol.apply_policy_impl(None, None, 'testpackage', None,
                                           FakeSourceData, excuse)
            self.assertEqual(status, PolicyVerdict.PASS)
            # Assert that we were looking for the right package as per
            # FakeSourceData contents
            self.assertSequenceEqual(lp.mock_calls, [
                call(
                    'testbuntu/+archive/primary', {
                        'distro_series': '/testbuntu/zazzy',
                        'exact_match': 'true',
                        'order_by_date': 'true',
                        'pocket': 'Proposed',
                        'source_name': 'testpackage',
                        'version': '55.0',
                        'ws.op': 'getPublishedSources',
                    }),
                call(
                    'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565',
                    {
                        'ws.op': 'changesFileUrl',
                    })
            ])
            # The .changes file only lists 2 bugs, make sure only those are
            # commented on
            self.assertSequenceEqual(
                smtp.call_args_list,
                [call('localhost:1337'),
                 call('localhost:1337')])
            self.assertEqual(smtp().sendmail.call_count, 2)
            # call_args is a tuple (args, kwargs), and the email content is
            # the third non-named argument of sendmail() - hence [0][2]
            message = smtp().sendmail.call_args[0][2]
            # Check if the e-mail/comment we were sending includes info about
            # which tests have failed
            self.assertIn('testpackage/55.0 (i386)', message)
            self.assertIn('rdep1/1.1-0ubuntu1 (amd64, i386)', message)
            # Check if the state has been saved and not overwritten
            expected_state = {
                'testbuntu': {
                    'zazzy': {
                        'testpackage': '55.0',
                        'ignored': '0.1',
                    }
                },
                'ghostdistro': {
                    'spooky': {
                        'ignored': '0.1',
                    }
                }
            }
            self.assertDictEqual(pol.state, expected_state)
            log.assert_called_with(
                'Sending ADT regression message to LP: #2 regarding testpackage/55.0 in zazzy'
            )
            # But also test if the state has been correctly recorded to the
            # state file
            state_path = os.path.join(options.unstable,
                                      'sru_regress_inform_state')
            with open(state_path) as f:
                saved_state = json.load(f)
                self.assertDictEqual(saved_state, expected_state)