def _get_upgrade_versions(cros_versions, omaha_versions, boards): """ Get the new stable versions to which we should update. The new versions are returned as a tuple of a dictionary mapping board names to versions, plus a new default board setting. The new default is determined as the most commonly used version across the given boards. The new dictionary will have a mapping for every board in `boards`. That mapping will be taken from `cros_versions`, unless the board has a mapping in `omaha_versions` _and_ the omaha version is more recent than the AFE version. @param cros_versions The current board->version mappings in the AFE. @param omaha_versions The current board->version mappings from Omaha for the Beta channel. @param boards Set of boards to be upgraded. @return Tuple of (mapping, default) where mapping is a dictionary mapping boards to versions, and default is a version string. """ upgrade_versions = {} version_counts = {} afe_default = cros_versions[_DEFAULT_BOARD] for board in boards: version = build_data.get_omaha_upgrade( omaha_versions, board, cros_versions.get(board, afe_default)) upgrade_versions[board] = version version_counts.setdefault(version, 0) version_counts[version] += 1 return (upgrade_versions, max(version_counts.items(), key=lambda x: x[1])[0])
def test_board_name_mapping(self): """Test that AFE board names are mapped to Omaha board names.""" board_equivalents = [('a-b', 'a-b'), ('c_d', 'c-d'), ('e_f-g', 'e-f-g'), ('hi', 'hi')] for afe_board, omaha_board in board_equivalents: new_version = build_data.get_omaha_upgrade({omaha_board: self.V1}, afe_board, self.V0) self.assertEquals(new_version, self.V1)
def set_mapping(self, board, version): """Assign the Chrome OS mapping for the given board. This function assigns the given Chrome OS version to the given board. Additionally, for any model with firmware bundled in the assigned build, that model will be assigned the firmware version found for it in the build. @param board Chrome OS board to be assigned a new version. @param version New Chrome OS version to be assigned to the board. """ new_version = build_data.get_omaha_upgrade( build_data.get_omaha_version_map(), board, version) if new_version != version: print 'Force %s version from Omaha: %-12s -> %s' % ( self._description, board, new_version) super(_CrOSVersionMapHandler, self).set_mapping(board, new_version) fw_versions = build_data.get_firmware_versions(board, new_version) fw_handler = _FirmwareVersionMapHandler(self._afe, self._dry_run) for model, fw_version in fw_versions.iteritems(): if fw_version is not None: fw_handler.set_mapping(model, fw_version)
def test_choose_cros_version(self): """Test that the CrOS version is chosen when it is later.""" new_version = build_data.get_omaha_upgrade({'board': self.V0}, 'board', self.V1) self.assertEquals(new_version, self.V1)
def test_no_version_whatsoever(self): """Test handling when both versions are `None`.""" new_version = build_data.get_omaha_upgrade({}, 'board', None) self.assertIsNone(new_version)
def test_no_afe_version(self): """Test handling when there's no CrOS version.""" new_version = build_data.get_omaha_upgrade({'board': self.V1}, 'board', None) self.assertEquals(new_version, self.V1)
def test_no_omaha_version(self): """Test handling when there's no Omaha version.""" new_version = build_data.get_omaha_upgrade({}, 'board', self.V1) self.assertEquals(new_version, self.V1)
def test_identical_versions(self): """Test handling when both the versions are the same.""" new_version = build_data.get_omaha_upgrade({'board': self.V1}, 'board', self.V1) self.assertEquals(new_version, self.V1)
def test_branch_version_comparison(self): """Test that versions on different branches compare properly.""" new_version = build_data.get_omaha_upgrade({'board': self.V1}, 'board', self.V2) self.assertEquals(new_version, self.V2)