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.
 
 
 

130 lines
4.4 KiB

  1. #!/usr/bin/python3
  2. # (C) 2017 Canonical Ltd.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. import fileinput
  9. import json
  10. import os
  11. import pprint
  12. import sys
  13. import unittest
  14. import apt_pkg
  15. import yaml
  16. PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  17. sys.path.insert(0, PROJECT_DIR)
  18. from tests import TestBase, mock_swift
  19. apt_pkg.init()
  20. class YamlTest(TestBase):
  21. """Validate generated yaml"""
  22. def setUp(self):
  23. super().setUp()
  24. self.fake_amqp = os.path.join(self.data.path, 'amqp')
  25. # Set fake AMQP and Swift server
  26. for line in fileinput.input(self.britney_conf, inplace=True):
  27. if 'ADT_AMQP' in line:
  28. print('ADT_AMQP = file://%s' % self.fake_amqp)
  29. elif 'ADT_SWIFT_URL' in line:
  30. print('ADT_SWIFT_URL = http://localhost:18085')
  31. elif 'ADT_ARCHES' in line:
  32. print('ADT_ARCHES = amd64 i386')
  33. else:
  34. sys.stdout.write(line)
  35. self.data.add('libc6', False)
  36. self.sourceppa_cache = {}
  37. self.email_cache = {}
  38. for pkg, vals in self.sourceppa_cache.items():
  39. for version, empty in vals.items():
  40. self.email_cache.setdefault(pkg, {})
  41. self.email_cache[pkg][version] = True
  42. # create mock Swift server (but don't start it yet, as tests first need
  43. # to poke in results)
  44. self.swift = mock_swift.AutoPkgTestSwiftServer(port=18085)
  45. self.swift.set_results({})
  46. def tearDown(self):
  47. del self.swift
  48. def do_test(self, unstable_add):
  49. """Run britney with some unstable packages and verify excuses.
  50. unstable_add is a list of (binpkgname, field_dict, daysold)
  51. Return excuses_dict.
  52. """
  53. age_file = os.path.join(self.data.path,
  54. 'data',
  55. 'testing',
  56. 'state',
  57. 'age-policy-dates')
  58. for (pkg, fields, daysold) in unstable_add:
  59. self.data.add(pkg, True, fields, True, None)
  60. self.sourceppa_cache.setdefault(pkg, {})
  61. if fields['Version'] not in self.sourceppa_cache[pkg]:
  62. self.sourceppa_cache[pkg][fields['Version']] = ''
  63. with open(age_file, 'w') as f:
  64. import time
  65. do = time.time() - (60 * 60 * 24 * daysold)
  66. f.write('%s %s %d' % (pkg, fields['Version'], do))
  67. # Set up sourceppa cache for testing
  68. sourceppa_path = os.path.join(self.data.dirs[True], 'SourcePPA')
  69. with open(sourceppa_path, 'w', encoding='utf-8') as sourceppa:
  70. sourceppa.write(json.dumps(self.sourceppa_cache))
  71. (excuses_yaml, excuses_html, out) = self.run_britney()
  72. # convert excuses to source indexed dict
  73. excuses_dict = {}
  74. for s in yaml.load(excuses_yaml, Loader=yaml.CSafeLoader)['sources']:
  75. excuses_dict[s['source']] = s
  76. if 'SHOW_EXCUSES' in os.environ:
  77. print('------- excuses -----')
  78. pprint.pprint(excuses_dict, width=200)
  79. if 'SHOW_YAML' in os.environ:
  80. print('------- excuses.yaml -----\n%s\n' % excuses_yaml)
  81. if 'SHOW_HTML' in os.environ:
  82. print('------- excuses.html -----\n%s\n' % excuses_html)
  83. if 'SHOW_OUTPUT' in os.environ:
  84. print('------- output -----\n%s\n' % out)
  85. self.assertNotIn('FIXME', out)
  86. return excuses_dict
  87. def test_unsat_deps(self):
  88. """Test unsatisfiable dependencies list"""
  89. pkg = ('libc6', {'Version': '2',
  90. 'Depends': 'notavailable (>= 2)'},
  91. 6)
  92. excuse = self.do_test([pkg])
  93. self.assertIn('notavailable (>= 2)', excuse['libc6']['dependencies']['unsatisfiable-dependencies']['amd64'])
  94. def test_epoch_in_deps(self):
  95. """Test dependencies listing with epoch in versioned dep"""
  96. pkg = ('libc6', {'Version': '2',
  97. 'Depends': 'datefudge (>= 99:1.0-0.1ubuntu8)'},
  98. 6)
  99. excuse = self.do_test([pkg])
  100. self.assertIn('datefudge', list(excuse['libc6']['dependencies']['unsatisfiable-dependencies']['amd64'])[0])
  101. if __name__ == '__main__':
  102. unittest.main()