Devuan deployment of britney2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

597 lines
27 KiB

  1. import apt_pkg
  2. import os
  3. import tempfile
  4. import unittest
  5. from britney2 import Suites, Suite, SuiteClass, SourcePackage, BinaryPackageId, BinaryPackage
  6. from britney2.excuse import Excuse
  7. from britney2.hints import HintParser
  8. from britney2.migrationitem import MigrationItemFactory, MigrationItem
  9. from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict
  10. from britney2.policies.autopkgtest import AutopkgtestPolicy
  11. from . import MockObject, TEST_HINTER, HINTS_ALL, DEFAULT_URGENCY, new_pkg_universe_builder
  12. POLICY_DATA_BASE_DIR = os.path.join(os.path.dirname(__file__), 'policy-test-data')
  13. ARCH = 'amd64'
  14. def initialize_policy(test_name, policy_class, *args, **kwargs):
  15. test_dir = os.path.join(POLICY_DATA_BASE_DIR, test_name)
  16. debci_data = os.path.join(test_dir, 'debci.json')
  17. target = 'testing'
  18. hints = []
  19. pkg_universe = None
  20. inst_tester = None
  21. if 'hints' in kwargs:
  22. hints = kwargs['hints']
  23. del kwargs['hints']
  24. if 'pkg_universe' in kwargs:
  25. pkg_universe = kwargs['pkg_universe']
  26. del kwargs['pkg_universe']
  27. if 'inst_tester' in kwargs:
  28. inst_tester = kwargs['inst_tester']
  29. del kwargs['inst_tester']
  30. options = MockObject(
  31. state_dir=test_dir,
  32. verbose=0,
  33. default_urgency=DEFAULT_URGENCY,
  34. dry_run=False,
  35. adt_shared_results_cache=False,
  36. series=target,
  37. adt_arches=ARCH,
  38. architectures=ARCH,
  39. adt_swift_url='file://' + debci_data,
  40. adt_ci_url='',
  41. adt_success_bounty=3,
  42. adt_regression_penalty=False,
  43. adt_retry_url_mech='run_id',
  44. **kwargs)
  45. suite_info = Suites(
  46. Suite(SuiteClass.TARGET_SUITE, target, os.path.join(test_dir, target), ''),
  47. [Suite(SuiteClass.PRIMARY_SOURCE_SUITE, 'unstable', os.path.join(test_dir, 'unstable'), '')],
  48. )
  49. mi_factory = MigrationItemFactory(suite_info)
  50. policy = policy_class(options, suite_info, *args)
  51. fake_britney = MockObject(log=lambda x, y='I': None)
  52. hint_parser = HintParser(mi_factory)
  53. if pkg_universe and inst_tester:
  54. build_sources_from_universe_and_inst_tester(policy, pkg_universe, inst_tester)
  55. policy.initialise(fake_britney)
  56. if inst_tester:
  57. policy.britney._inst_tester = inst_tester
  58. if pkg_universe:
  59. policy.britney.pkg_universe = pkg_universe
  60. policy.register_hints(hint_parser)
  61. hint_parser.parse_hints(TEST_HINTER, HINTS_ALL, 'test-%s' % test_name, hints)
  62. policy.hints = hint_parser.hints
  63. return policy
  64. def create_excuse(name):
  65. return Excuse(name)
  66. def create_source_package(version, section='devel', binaries=None):
  67. if binaries is None:
  68. binaries = set()
  69. return SourcePackage(version, section, binaries, 'Random tester', False, None, None, ['autopkgtest'], [])
  70. def create_bin_package(pkg_id, source_name=None, depends=None, conflicts=None):
  71. name = pkg_id.package_name
  72. version = pkg_id.version
  73. source_version = version
  74. if source_name is None:
  75. source_name = name
  76. return BinaryPackage(
  77. version,
  78. 'main',
  79. source_name,
  80. source_version,
  81. ARCH,
  82. None,
  83. depends,
  84. conflicts,
  85. None,
  86. False,
  87. pkg_id,
  88. [],
  89. )
  90. def create_policy_objects(source_name, target_version='1.0', source_version='2.0'):
  91. return (
  92. create_source_package(target_version),
  93. create_source_package(source_version),
  94. create_excuse(source_name),
  95. )
  96. def apply_src_policy(policy, expected_verdict, src_name, *, suite='unstable', target_version='1.0', source_version='2.0'):
  97. suite_info = policy.suite_info
  98. if src_name in suite_info[suite].sources:
  99. src_u = suite_info[suite].sources[src_name]
  100. src_t = suite_info.target_suite.sources.get(src_name)
  101. _, _, excuse = create_policy_objects(src_name)
  102. else:
  103. src_t, src_u, excuse = create_policy_objects(src_name, target_version, source_version)
  104. suite_info.target_suite.sources[src_name] = src_t
  105. suite_info[suite].sources[src_name] = src_u
  106. factory = MigrationItemFactory(suite_info)
  107. item = factory.parse_item(src_name, versioned=False, auto_correct=False)
  108. pinfo = {}
  109. verdict = policy.apply_src_policy_impl(pinfo, item, src_t, src_u, excuse)
  110. assert verdict == expected_verdict
  111. return pinfo
  112. def build_sources_from_universe_and_inst_tester(policy, pkg_universe, inst_tester, suite='unstable'):
  113. suite_info = policy.suite_info
  114. src_universe = {}
  115. bin_universe = {}
  116. src_source = {}
  117. binaries_t = {}
  118. binaries_s = {}
  119. for pkg_id in pkg_universe:
  120. pkg_name = pkg_id.package_name
  121. src_universe[pkg_id] = create_source_package(pkg_id.version, binaries={pkg_id})
  122. bin_universe[pkg_id] = create_bin_package(pkg_id)
  123. if inst_tester.is_pkg_in_the_suite(pkg_id):
  124. if pkg_name in suite_info.target_suite.sources:
  125. # sanity check, this shouldn't happen
  126. raise(KeyError)
  127. suite_info.target_suite.sources[pkg_name] = src_universe[pkg_id]
  128. binaries_t.setdefault(ARCH, {}).setdefault(pkg_name, bin_universe[pkg_id])
  129. # We need to find the highest version of a package to add it to the
  130. # sources of the source suite
  131. if pkg_name not in src_source or \
  132. apt_pkg.version_compare(src_source[pkg_name].version, pkg_id.version) < 0:
  133. src_source[pkg_name] = pkg_id
  134. suite_info.target_suite.binaries = binaries_t
  135. for pkg_id in src_source.values():
  136. pkg_name = pkg_id.package_name
  137. suite_info[suite].sources[pkg_name] = src_universe[pkg_id]
  138. binaries_s.setdefault(ARCH, {}).setdefault(pkg_name, bin_universe[pkg_id])
  139. suite_info[suite].binaries = binaries_s
  140. class TestRCBugsPolicy(unittest.TestCase):
  141. def test_no_bugs(self):
  142. src_name = 'has-no-bugs'
  143. policy = initialize_policy('rc-bugs/basic', RCBugPolicy)
  144. bug_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  145. assert set(bug_policy_info['unique-source-bugs']) == set()
  146. assert set(bug_policy_info['unique-target-bugs']) == set()
  147. assert set(bug_policy_info['shared-bugs']) == set()
  148. def test_regression(self):
  149. src_name = 'regression'
  150. policy = initialize_policy('rc-bugs/basic', RCBugPolicy)
  151. bug_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  152. assert set(bug_policy_info['unique-source-bugs']) == {'123458'}
  153. assert set(bug_policy_info['unique-target-bugs']) == set()
  154. assert set(bug_policy_info['shared-bugs']) == set()
  155. def test_regression_but_fixes_more_bugs(self):
  156. src_name = 'regression-but-fixes-more-bugs'
  157. policy = initialize_policy('rc-bugs/basic', RCBugPolicy)
  158. bug_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  159. assert set(bug_policy_info['unique-source-bugs']) == {'100003'}
  160. assert set(bug_policy_info['unique-target-bugs']) == {'100001', '100002'}
  161. assert set(bug_policy_info['shared-bugs']) == {'100000'}
  162. def test_not_a_regression(self):
  163. src_name = 'not-a-regression'
  164. policy = initialize_policy('rc-bugs/basic', RCBugPolicy)
  165. bug_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  166. assert set(bug_policy_info['unique-source-bugs']) == set()
  167. assert set(bug_policy_info['unique-target-bugs']) == set()
  168. assert set(bug_policy_info['shared-bugs']) == {'123457'}
  169. def test_improvement(self):
  170. src_name = 'fixes-bug'
  171. policy = initialize_policy('rc-bugs/basic', RCBugPolicy)
  172. bug_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  173. assert set(bug_policy_info['unique-source-bugs']) == set()
  174. assert set(bug_policy_info['unique-target-bugs']) == {'123456'}
  175. assert set(bug_policy_info['shared-bugs']) == set()
  176. def test_regression_with_hint(self):
  177. src_name = 'regression'
  178. hints = ['ignore-rc-bugs 123458 regression/2.0']
  179. policy = initialize_policy('rc-bugs/basic', RCBugPolicy, hints=hints)
  180. bug_policy_info = apply_src_policy(policy, PolicyVerdict.PASS_HINTED, src_name)
  181. assert set(bug_policy_info['ignored-bugs']['bugs']) == {'123458'}
  182. assert bug_policy_info['ignored-bugs']['issued-by'] == TEST_HINTER
  183. assert set(bug_policy_info['unique-source-bugs']) == set()
  184. assert set(bug_policy_info['unique-target-bugs']) == set()
  185. assert set(bug_policy_info['shared-bugs']) == set()
  186. def test_regression_but_fixes_more_bugs_bad_hint(self):
  187. src_name = 'regression-but-fixes-more-bugs'
  188. hints = ['ignore-rc-bugs 100000 regression-but-fixes-more-bugs/2.0']
  189. policy = initialize_policy('rc-bugs/basic', RCBugPolicy, hints=hints)
  190. bug_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  191. assert set(bug_policy_info['unique-source-bugs']) == {'100003'}
  192. assert set(bug_policy_info['unique-target-bugs']) == {'100001', '100002'}
  193. assert set(bug_policy_info['ignored-bugs']['bugs']) == {'100000'}
  194. assert bug_policy_info['ignored-bugs']['issued-by'] == TEST_HINTER
  195. assert set(bug_policy_info['shared-bugs']) == set()
  196. class TestAgePolicy(unittest.TestCase):
  197. DEFAULT_MIN_DAYS = {
  198. 'emergency': 0,
  199. 'critical': 0,
  200. 'high': 2,
  201. 'medium': 5,
  202. 'low': 10,
  203. }
  204. @classmethod
  205. def reset_age(cls, policy, effective_date=10):
  206. policy._date_now = effective_date
  207. def test_missing_age_file(self):
  208. age_file = os.path.join(POLICY_DATA_BASE_DIR, 'age', 'missing-age-file', 'age-policy-dates')
  209. assert not os.path.exists(age_file)
  210. try:
  211. src_name = 'unlisted-source-package'
  212. policy = initialize_policy('age/missing-age-file', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
  213. age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  214. assert os.path.exists(age_file)
  215. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  216. assert age_policy_info['current-age'] == 0
  217. finally:
  218. if os.path.exists(age_file):
  219. os.unlink(age_file)
  220. def test_age_new(self):
  221. src_name = 'unlisted-source-package'
  222. policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
  223. age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  224. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  225. assert age_policy_info['current-age'] == 0
  226. def test_age_urgented(self):
  227. src_name = 'unlisted-source-package'
  228. policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS,
  229. hints=['urgent unlisted-source-package/2.0'])
  230. age_policy_info = apply_src_policy(policy, PolicyVerdict.PASS_HINTED, src_name)
  231. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  232. assert age_policy_info['current-age'] == 0
  233. assert age_policy_info['age-requirement-reduced']['new-requirement'] == 0
  234. assert age_policy_info['age-requirement-reduced']['changed-by'] == TEST_HINTER
  235. def test_age_old_version_aged(self):
  236. src_name = 'out-of-date-version'
  237. policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
  238. self.reset_age(policy)
  239. age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  240. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  241. assert age_policy_info['current-age'] == 0
  242. def test_age_almost_aged(self):
  243. src_name = 'almost-aged-properly'
  244. policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
  245. self.reset_age(policy)
  246. age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  247. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  248. assert age_policy_info['current-age'] == 4
  249. def test_age_aged_properly(self):
  250. src_name = 'aged-properly'
  251. policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
  252. self.reset_age(policy)
  253. age_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  254. assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
  255. assert age_policy_info['current-age'] == 5
  256. class TestPiupartsPolicy(unittest.TestCase):
  257. def test_passes(self):
  258. src_name = 'pass'
  259. policy = initialize_policy('piuparts/basic', PiupartsPolicy)
  260. piu_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  261. assert piu_policy_info['test-results'] == 'pass'
  262. assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/p/pass.html'
  263. def test_regression(self):
  264. src_name = 'regression'
  265. policy = initialize_policy('piuparts/basic', PiupartsPolicy)
  266. piu_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  267. assert piu_policy_info['test-results'] == 'regression'
  268. assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/r/regression.html'
  269. def test_regression_hinted(self):
  270. src_name = 'regression'
  271. hints = ['ignore-piuparts regression/2.0']
  272. policy = initialize_policy('piuparts/basic', PiupartsPolicy, hints=hints)
  273. piu_policy_info = apply_src_policy(policy, PolicyVerdict.PASS_HINTED, src_name)
  274. assert piu_policy_info['test-results'] == 'regression'
  275. assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/r/regression.html'
  276. assert piu_policy_info['ignored-piuparts']['issued-by'] == TEST_HINTER
  277. def test_not_tested_yet(self):
  278. src_name = 'not-tested-yet'
  279. policy = initialize_policy('piuparts/basic', PiupartsPolicy)
  280. piu_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  281. assert piu_policy_info['test-results'] == 'waiting-for-test-results'
  282. assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/n/not-tested-yet.html'
  283. def test_failed_not_regression(self):
  284. src_name = 'failed-not-regression'
  285. policy = initialize_policy('piuparts/basic', PiupartsPolicy)
  286. piu_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  287. assert piu_policy_info['test-results'] == 'failed'
  288. assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/f/failed-not-regression.html'
  289. pkg1 = BinaryPackageId('pkg', '1.0', ARCH)
  290. pkg2 = BinaryPackageId('pkg', '2.0', ARCH)
  291. inter = BinaryPackageId('inter', '1.0', ARCH)
  292. broken1 = BinaryPackageId('broken', '1.0', ARCH)
  293. broken2 = BinaryPackageId('broken', '2.0', ARCH)
  294. dummy = BinaryPackageId('dummy', '1', ARCH)
  295. builder = new_pkg_universe_builder()
  296. builder.new_package(pkg1).in_testing()
  297. builder.new_package(pkg2).not_in_testing()
  298. simple_universe, simple_inst_tester = builder.build()
  299. builder_breaks = new_pkg_universe_builder()
  300. builder_breaks.new_package(broken1).in_testing()
  301. builder_breaks.new_package(broken2).not_in_testing()
  302. builder_breaks.new_package(inter).in_testing().depends_on_any_of(broken1, broken2)
  303. builder_breaks.new_package(pkg1).depends_on(inter).in_testing()
  304. builder_breaks.new_package(pkg2).depends_on(inter).not_in_testing().conflicts_with(broken1)
  305. breaks_universe, breaks_inst_tester = builder_breaks.build()
  306. class TestAutopkgtestPolicy(unittest.TestCase):
  307. import apt_pkg
  308. apt_pkg.init()
  309. def read_amqp(self):
  310. with open(self.amqp.replace('file://', ''), 'r+') as f:
  311. amqp = f.read()
  312. return amqp
  313. def setUp(self):
  314. self.amqp = 'file://' + tempfile.NamedTemporaryFile(mode='w', delete=False).name
  315. def tearDown(self):
  316. os.unlink(self.amqp.replace('file://', ''))
  317. def test_pass_to_pass(self):
  318. src_name = 'pkg'
  319. policy = initialize_policy(
  320. 'autopkgtest/pass-to-pass',
  321. AutopkgtestPolicy,
  322. adt_amqp=self.amqp,
  323. pkg_universe=simple_universe,
  324. inst_tester=simple_inst_tester)
  325. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  326. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'PASS'
  327. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  328. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  329. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  330. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  331. amqp = self.read_amqp()
  332. assert len(amqp) == 0
  333. def test_pass_to_fail(self):
  334. src_name = 'pkg'
  335. policy = initialize_policy(
  336. 'autopkgtest/pass-to-fail',
  337. AutopkgtestPolicy,
  338. adt_amqp=self.amqp,
  339. adt_retry_older_than=1,
  340. pkg_universe=simple_universe,
  341. inst_tester=simple_inst_tester)
  342. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  343. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'REGRESSION'
  344. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  345. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  346. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  347. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  348. amqp = self.read_amqp()
  349. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  350. def test_pass_to_fail_no_retrigger(self):
  351. src_name = 'pkg'
  352. policy = initialize_policy(
  353. 'autopkgtest/pass-to-fail',
  354. AutopkgtestPolicy,
  355. adt_amqp=self.amqp,
  356. adt_retry_older_than='',
  357. pkg_universe=simple_universe,
  358. inst_tester=simple_inst_tester)
  359. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  360. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'REGRESSION'
  361. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  362. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  363. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  364. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  365. amqp = self.read_amqp()
  366. assert len(amqp) == 0
  367. def test_pass_to_neutral(self):
  368. src_name = 'pkg'
  369. policy = initialize_policy(
  370. 'autopkgtest/pass-to-neutral',
  371. AutopkgtestPolicy,
  372. adt_amqp=self.amqp,
  373. pkg_universe=simple_universe,
  374. inst_tester=simple_inst_tester)
  375. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  376. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'NEUTRAL'
  377. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  378. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  379. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  380. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  381. amqp = self.read_amqp()
  382. assert len(amqp) == 0
  383. def test_new(self):
  384. src_name = 'pkg'
  385. builder_new = new_pkg_universe_builder()
  386. builder_new.new_package(pkg2).not_in_testing()
  387. builder_new.new_package(dummy).in_testing()
  388. new_universe, new_inst_tester = builder_new.build()
  389. policy = initialize_policy(
  390. 'autopkgtest/new',
  391. AutopkgtestPolicy,
  392. adt_amqp=self.amqp,
  393. pkg_universe=new_universe,
  394. inst_tester=new_inst_tester)
  395. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  396. assert autopkgtest_policy_info[src_name][ARCH][0] == 'RUNNING-ALWAYSFAIL'
  397. assert autopkgtest_policy_info[src_name][ARCH][1] == 'status/pending'
  398. assert autopkgtest_policy_info[src_name][ARCH][2] == \
  399. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  400. amqp = self.read_amqp()
  401. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  402. def test_pass_to_new(self):
  403. src_name = 'pkg'
  404. policy = initialize_policy(
  405. 'autopkgtest/pass-to-new',
  406. AutopkgtestPolicy,
  407. adt_amqp=self.amqp,
  408. pkg_universe=simple_universe,
  409. inst_tester=simple_inst_tester)
  410. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  411. assert autopkgtest_policy_info[src_name][ARCH][0] == 'RUNNING'
  412. assert autopkgtest_policy_info[src_name][ARCH][1] == 'status/pending'
  413. assert autopkgtest_policy_info[src_name][ARCH][2] == 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  414. amqp = self.read_amqp()
  415. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  416. def test_fail_to_new(self):
  417. src_name = 'pkg'
  418. policy = initialize_policy(
  419. 'autopkgtest/fail-to-new',
  420. AutopkgtestPolicy,
  421. adt_amqp=self.amqp,
  422. pkg_universe=simple_universe,
  423. inst_tester=simple_inst_tester)
  424. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  425. assert autopkgtest_policy_info[src_name][ARCH][0] == 'RUNNING-ALWAYSFAIL'
  426. assert autopkgtest_policy_info[src_name][ARCH][1] == 'status/pending'
  427. assert autopkgtest_policy_info[src_name][ARCH][2] == \
  428. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  429. amqp = self.read_amqp()
  430. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  431. def test_neutral_to_new(self):
  432. src_name = 'pkg'
  433. policy = initialize_policy(
  434. 'autopkgtest/neutral-to-new',
  435. AutopkgtestPolicy,
  436. adt_amqp=self.amqp,
  437. pkg_universe=simple_universe,
  438. inst_tester=simple_inst_tester)
  439. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  440. assert autopkgtest_policy_info[src_name][ARCH][0] == 'RUNNING'
  441. assert autopkgtest_policy_info[src_name][ARCH][1] == 'status/pending'
  442. assert autopkgtest_policy_info[src_name][ARCH][2] == \
  443. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  444. amqp = self.read_amqp()
  445. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  446. def test_neutral_to_fail(self):
  447. src_name = 'pkg'
  448. policy = initialize_policy(
  449. 'autopkgtest/neutral-to-fail',
  450. AutopkgtestPolicy,
  451. adt_amqp=self.amqp,
  452. adt_retry_older_than=1,
  453. pkg_universe=simple_universe,
  454. inst_tester=simple_inst_tester)
  455. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  456. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'REGRESSION'
  457. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  458. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  459. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  460. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  461. amqp = self.read_amqp()
  462. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0"]}'
  463. def test_neutral_to_fail_pending_retest(self):
  464. src_name = 'pkg'
  465. policy = initialize_policy(
  466. 'autopkgtest/neutral-to-fail-pending-retest',
  467. AutopkgtestPolicy,
  468. adt_amqp=self.amqp,
  469. adt_retry_older_than=1,
  470. pkg_universe=simple_universe,
  471. inst_tester=simple_inst_tester)
  472. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_PERMANENTLY, src_name)
  473. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'REGRESSION'
  474. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  475. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  476. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  477. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  478. amqp = self.read_amqp()
  479. assert len(amqp) == 0
  480. def test_pass_to_new_with_breaks(self):
  481. src_name = 'pkg'
  482. policy = initialize_policy(
  483. 'autopkgtest/pass-to-new-with-breaks',
  484. AutopkgtestPolicy,
  485. adt_amqp=self.amqp,
  486. pkg_universe=breaks_universe,
  487. inst_tester=breaks_inst_tester)
  488. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  489. assert autopkgtest_policy_info[src_name][ARCH][0] == 'RUNNING'
  490. assert autopkgtest_policy_info[src_name][ARCH][1] == 'status/pending'
  491. assert autopkgtest_policy_info[src_name][ARCH][2] == \
  492. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  493. amqp = self.read_amqp()
  494. assert amqp[0:-1] == 'debci-testing-amd64:' + src_name + ' {"triggers": ["' + src_name + '/2.0 broken/2.0"]}'
  495. def test_fail_old_test_result(self):
  496. src_name = 'broken'
  497. policy = initialize_policy(
  498. 'autopkgtest/fail-old-test-result',
  499. AutopkgtestPolicy,
  500. adt_amqp=self.amqp,
  501. pkg_universe=breaks_universe,
  502. inst_tester=breaks_inst_tester,
  503. adt_baseline='reference')
  504. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
  505. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'PASS'
  506. assert autopkgtest_policy_info['inter'][ARCH][0] == 'RUNNING'
  507. assert autopkgtest_policy_info['inter'][ARCH][1] == 'status/pending'
  508. amqp = self.read_amqp()
  509. assert amqp[0:-1] == 'debci-testing-amd64:inter {"triggers": ["' + src_name + '/2.0"]}'
  510. def test_fail_to_fail(self):
  511. src_name = 'pkg'
  512. policy = initialize_policy(
  513. 'autopkgtest/fail-to-fail',
  514. AutopkgtestPolicy,
  515. adt_amqp=self.amqp,
  516. adt_retry_older_than=1,
  517. pkg_universe=simple_universe,
  518. inst_tester=simple_inst_tester)
  519. autopkgtest_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
  520. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][0] == 'ALWAYSFAIL'
  521. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][1] == \
  522. 'data/autopkgtest/testing/amd64/' + src_name[0] + '/' + src_name + '/2/log.gz'
  523. assert autopkgtest_policy_info[src_name + '/2.0'][ARCH][2] == \
  524. 'packages/' + src_name[0] + '/' + src_name + '/testing/amd64'
  525. amqp = self.read_amqp()
  526. assert len(amqp) == 0
  527. if __name__ == '__main__':
  528. unittest.main()