feat(cloud): Add verdict info for passed tests

Additional verdict info is being provided by the CloudPolicy to improve
clarity on the state of cloud tests. When tests pass this will be marked
in the verdict. Also when a package is skipped because it is not in the
cloud package set this will be made clear in the verdict.
sil2100/security-britney
Aleksa Svitlica 2 years ago
parent 19515cea13
commit 22f865d7ae

@ -97,7 +97,12 @@ class CloudPolicy(BasePolicy):
def apply_src_policy_impl(self, policy_info, item, source_data_tdist, source_data_srcdist, excuse): def apply_src_policy_impl(self, policy_info, item, source_data_tdist, source_data_srcdist, excuse):
self.logger.info("Cloud Policy: Looking at {}".format(item.package)) self.logger.info("Cloud Policy: Looking at {}".format(item.package))
if item.package not in self.package_set: if item.package not in self.package_set:
return PolicyVerdict.PASS verdict = PolicyVerdict.PASS
excuse.add_verdict_info(
verdict,
"Cloud tests not required because package is not in the cloud package set."
)
return verdict
if self.dry_run: if self.dry_run:
self.logger.info( self.logger.info(
@ -123,7 +128,9 @@ class CloudPolicy(BasePolicy):
return verdict return verdict
else: else:
self._cleanup_work_directory() self._cleanup_work_directory()
return PolicyVerdict.PASS verdict = PolicyVerdict.PASS
excuse.add_verdict_info(verdict, "Cloud tests passed.")
return verdict
def _mark_tests_run(self, package, version, series, source_type, cloud): def _mark_tests_run(self, package, version, series, source_type, cloud):
"""Mark the selected package version as already tested. """Mark the selected package version as already tested.

@ -11,12 +11,13 @@ import json
import sys import sys
from types import SimpleNamespace from types import SimpleNamespace
import unittest import unittest
from unittest.mock import patch from unittest.mock import MagicMock, patch
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, PROJECT_DIR) sys.path.insert(0, PROJECT_DIR)
from britney2.policies import PolicyVerdict
from britney2.policies.cloud import CloudPolicy, ERR_MESSAGE, MissingURNException from britney2.policies.cloud import CloudPolicy, ERR_MESSAGE, MissingURNException
class FakeItem: class FakeItem:
@ -143,7 +144,7 @@ class T(unittest.TestCase):
self.policy.options.series = "jammy" self.policy.options.series = "jammy"
self.policy.apply_src_policy_impl( self.policy.apply_src_policy_impl(
None, FakeItem, None, FakeSourceData, None None, FakeItem, None, FakeSourceData, MagicMock()
) )
mock_run.assert_called_once_with( mock_run.assert_called_once_with(
@ -157,11 +158,12 @@ class T(unittest.TestCase):
self.policy.package_set = set(["vim"]) self.policy.package_set = set(["vim"])
self.policy.options.series = "jammy" self.policy.options.series = "jammy"
self.policy.apply_src_policy_impl( verdict = self.policy.apply_src_policy_impl(
None, FakeItem, None, FakeSourceData, None None, FakeItem, None, FakeSourceData, MagicMock()
) )
mock_run.assert_not_called() mock_run.assert_not_called()
self.assertEqual(verdict, PolicyVerdict.PASS)
@patch("britney2.policies.cloud.smtplib") @patch("britney2.policies.cloud.smtplib")
@patch("britney2.policies.cloud.CloudPolicy._run_cloud_tests") @patch("britney2.policies.cloud.CloudPolicy._run_cloud_tests")

Loading…
Cancel
Save