Пример #1
0
 def test_candidates(self):
     # Path B will win; it has one full and two deltas.
     index = get_index('candidates.index_13.json')
     candidates = get_candidates(index, 0)
     self.assertEqual(len(candidates), 3)
     path0 = candidates[0]
     self.assertEqual(descriptions(path0),
                      ['Full A', 'Delta A.1', 'Delta A.2'])
     path1 = candidates[1]
     self.assertEqual(descriptions(path1),
                      ['Full B', 'Delta B.1', 'Delta B.2'])
     path2 = candidates[2]
     self.assertEqual(descriptions(path2), ['Full C', 'Delta C.1'])
     # The version numbers use the new regime.
     self.assertEqual(path0[0].version, 300)
     self.assertEqual(path0[1].base, 300)
     self.assertEqual(path0[1].version, 301)
     self.assertEqual(path0[2].base, 301)
     self.assertEqual(path0[2].version, 304)
     winner = WeightedScorer().choose(candidates, 'devel')
     self.assertEqual(descriptions(winner),
                      ['Full B', 'Delta B.1', 'Delta B.2'])
     self.assertEqual(winner[0].version, 200)
     self.assertEqual(winner[1].base, 200)
     self.assertEqual(winner[1].version, 201)
     self.assertEqual(winner[2].base, 201)
     self.assertEqual(winner[2].version, 304)
Пример #2
0
 def test_filter_for_fulls(self):
     # Run a filter over the candidates, such that the only ones left are
     # those that contain only full upgrades.  This can truncate any paths
     # that start with some fulls and then contain some deltas.
     index = get_index('candidates.index_08.json')
     candidates = get_candidates(index, 600)
     filtered = full_filter(candidates)
     # Since all images start with a full update, we're still left with
     # three candidates.
     self.assertEqual(len(filtered), 3)
     self.assertEqual([image.type for image in filtered[0]], ['full'])
     self.assertEqual([image.type for image in filtered[1]], ['full'])
     self.assertEqual([image.type for image in filtered[2]], ['full'])
     self.assertEqual(descriptions(filtered[0]), ['Full A'])
     self.assertEqual(descriptions(filtered[1]), ['Full B'])
     self.assertEqual(descriptions(filtered[2]), ['Full C'])
Пример #3
0
 def test_filter_for_multiple_deltas(self):
     # The candidate path has multiple deltas.  All are preserved.
     index = get_index('candidates.index_12.json')
     candidates = get_candidates(index, 100)
     filtered = delta_filter(candidates)
     self.assertEqual(len(filtered), 1)
     path = filtered[0]
     self.assertEqual(len(path), 3)
     self.assertEqual(descriptions(path), ['Delta A', 'Delta B', 'Delta C'])
Пример #4
0
 def test_one_path_with_full_and_deltas(self):
     # There's one path to upgrade from our version to the final version.
     # This one starts at a full and includes several deltas.
     index = get_index('candidates.index_06.json')
     candidates = get_candidates(index, 1000)
     self.assertEqual(len(candidates), 1)
     path = candidates[0]
     self.assertEqual(len(path), 3)
     self.assertEqual([image.version for image in path], [1300, 1301, 1302])
     self.assertEqual(descriptions(path), ['Full 1', 'Delta 1', 'Delta 2'])
Пример #5
0
 def test_pulled_update(self):
     # When the final image on an update path has a phase percentage of
     # zero, then regardless of the device's percentage, the candidate path
     # is not okay.  In this case, the `Full B` has phase of 0%.
     index = get_index('scores.index_01.json')
     candidates = get_candidates(index, 100)
     with patch('systemimage.scores.phased_percentage', return_value=0):
         winner = self.scorer.choose(candidates, 'devel')
     self.assertEqual(descriptions(winner),
                      ['Full A', 'Delta A.1', 'Delta A.2'])
Пример #6
0
 def test_equal_phase_gets_update(self):
     # When the final image on an update path has a phase percentage exactly
     # equal to the device percentage, the candidate path is okay.  In this
     # case, the `Full B` has phase of 50%.
     index = get_index('scores.index_05.json')
     candidates = get_candidates(index, 100)
     with patch('systemimage.scores.phased_percentage', return_value=50):
         winner = self.scorer.choose(candidates, 'devel')
     self.assertEqual(descriptions(winner),
                      ['Full B', 'Delta B.1', 'Delta B.2'])
Пример #7
0
 def test_outside_phase_gets_update(self):
     # When the final image on an update path has a phase percentage lower
     # than the device percentage, the scorer falls back to the next
     # candidate path.
     index = get_index('scores.index_05.json')
     candidates = get_candidates(index, 100)
     with patch('systemimage.scores.phased_percentage', return_value=66):
         winner = self.scorer.choose(candidates, 'devel')
     self.assertEqual(descriptions(winner),
                      ['Full A', 'Delta A.1', 'Delta A.2'])
Пример #8
0
 def test_one_path_with_deltas(self):
     # Similar to above, except that because we're upgrading from the
     # version of the full, the path is only two images long, i.e. the
     # deltas.
     index = get_index('candidates.index_06.json')
     candidates = get_candidates(index, 1300)
     self.assertEqual(len(candidates), 1)
     path = candidates[0]
     self.assertEqual(len(path), 2)
     self.assertEqual([image.version for image in path], [1301, 1302])
     self.assertEqual(descriptions(path), ['Delta 1', 'Delta 2'])
Пример #9
0
 def test_two_deltas_based_on_us(self):
     # There are two deltas that are based on us, so both are candidates.
     # They get us to different final versions.
     index = get_index('candidates.index_05.json')
     candidates = get_candidates(index, 1100)
     self.assertEqual(len(candidates), 2)
     # Both candidate paths have exactly one image in them.  We can't sort
     # these paths, so just test them both.
     path0, path1 = candidates
     self.assertEqual(len(path0), 1)
     self.assertEqual(len(path1), 1)
     # One path gets us to version 1300 and the other 1400.
     images = sorted([path0[0], path1[0]], key=attrgetter('version'))
     self.assertEqual(descriptions(images), ['Delta 2', 'Delta 1'])
Пример #10
0
 def test_no_version_detail(self):
     # The index.json file has three paths for updates, but only one is
     # selected.  The winning path lands on an image without a
     # version_detail key.
     index = get_index('scores.index_07.json')
     candidates = get_candidates(index, 600)
     scores = self.scorer.score(candidates)
     self.assertEqual(scores, [300, 200, 9401])
     winner = self.scorer.choose(candidates, 'devel')
     self.assertEqual(len(winner), 3)
     self.assertEqual([image.version for image in winner],
                      [1200, 1201, 1304])
     self.assertEqual(descriptions(winner),
                      ['Full B', 'Delta B.1', 'Delta B.2'])
     self.assertEqual(winner[-1].version_detail, '')
Пример #11
0
 def test_three_paths(self):
     # - Path A requires three extra reboots, is the smallest total
     #   download and leaves you at the highest available version.
     #   Score: 300
     #
     # - Path B requires one extra reboot, but is 100MiB bigger and leaves
     #   you at the highest available version.  Score: 200
     #
     # - Path C requires no extra reboots, but is 400MiB bigger and leaves
     #   you at 1303 instead of the highest 1304.  For that reason, it gets
     #   a huge score making it impossible to win.
     #
     # Path B wins.
     index = get_index('scores.index_03.json')
     candidates = get_candidates(index, 600)
     # There are three paths.  The scores are as above.
     scores = self.scorer.score(candidates)
     self.assertEqual(scores, [300, 200, 9401])
     winner = self.scorer.choose(candidates, 'devel')
     self.assertEqual(len(winner), 3)
     self.assertEqual([image.version for image in winner],
                      [1200, 1201, 1304])
     self.assertEqual(descriptions(winner),
                      ['Full B', 'Delta B.1', 'Delta B.2'])