Example #1
0
 def test_equal(self):
     self.assertEqual(
         SnapChannel.from_string("2.0/beta"),
         SnapChannel.from_string("2.0/beta"),
     )
     self.assertEqual(
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
     )
Example #2
0
 def get_version_issues(self, target: TargetVersion) -> List[str]:
     """Return a list of version-related issues compared to the target version."""
     issues = []
     if self.install_type == CONTROLLER_INSTALL_TYPE.SNAP:
         if (SnapChannel.from_string(self.update_origin) !=
                 target.snap_channel):
             issues.append(VERSION_ISSUES.DIFFERENT_CHANNEL.value)
         if self.snap_cohort != target.snap_cohort:
             issues.append(VERSION_ISSUES.DIFFERENT_COHORT.value)
     return issues
Example #3
0
 def test_not_equal(self):
     self.assertNotEqual(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.1/stable"),
     )
     self.assertNotEqual(
         SnapChannel.from_string("2.0/stable"),
         SnapChannel.from_string("2.0/beta"),
     )
     self.assertNotEqual(
         SnapChannel.from_string("2.0/stable"),
         SnapChannel.from_string("2.0/stable/branch"),
     )
     self.assertNotEqual(
         SnapChannel.from_string("2.0/beta/ubuntu-18.04"),
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
     )
     self.assertNotEqual(
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
         SnapChannel.from_string("2.0/beta/mybranch"),
     )
Example #4
0
 def test_is_release_branch(self):
     self.assertFalse(
         SnapChannel.from_string("2.0/beta").is_release_branch()
     )
     self.assertFalse(
         SnapChannel.from_string("2.0/beta/branch").is_release_branch()
     )
     self.assertFalse(
         SnapChannel.from_string(
             "2.0/beta/ubuntu-20.04.4"
         ).is_release_branch()
     )
     self.assertFalse(
         SnapChannel.from_string(
             "2.0/beta/myubuntu-20.04"
         ).is_release_branch()
     )
     self.assertTrue(
         SnapChannel.from_string(
             "2.0/beta/ubuntu-20.04"
         ).is_release_branch()
     )
Example #5
0
 def test_from_string_with_branch(self):
     self.assertEqual(
         SnapChannel.from_string("2.0/beta/test"),
         SnapChannel(track="2.0", risk="beta", branch="test"),
     )
Example #6
0
 def test_less(self):
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("latest/stable"),
     )
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.1/stable"),
     )
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.0/beta"),
     )
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.1/stable"),
     )
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.0/stable/branch"),
     )
     self.assertLess(
         SnapChannel.from_string("3.0/stable"),
         SnapChannel.from_string("3.1/stable/ubuntu-20.04"),
     )
     self.assertLess(
         SnapChannel.from_string("2.0/beta/ubuntu-18.04"),
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
     )
     self.assertLess(
         SnapChannel.from_string("2.0/beta/mybranch"),
         SnapChannel.from_string("2.0/beta/ubuntu-20.04"),
     )
Example #7
0
def get_target_version() -> Optional[TargetVersion]:
    """Get the target version for the deployment."""
    highest_version = None
    highest_update = None
    update_first_reported = None
    for info in ControllerInfo.objects.exclude(version=""):
        version = MAASVersion.from_string(info.version)
        highest_version = (max(
            (highest_version, version)) if highest_version else version)

        if not info.update_version:
            continue

        update = MAASVersion.from_string(info.update_version)
        if not highest_update:
            highest_update = update
            update_first_reported = info.update_first_reported
        elif update < highest_update:
            continue
        elif update > highest_update:
            highest_update = update
            update_first_reported = info.update_first_reported
        else:  # same version
            update_first_reported = min(
                (update_first_reported, info.update_first_reported))

    if highest_update and highest_update > highest_version:
        version = highest_update
    else:
        # don't report any update
        version = highest_version
        update_first_reported = None

    if version is None:
        return None

    def field_for_snap_controllers(field, version):
        version = str(version)
        return list(
            ControllerInfo.objects.filter(
                Q(version=version) | Q(update_version=version),
                install_type=CONTROLLER_INSTALL_TYPE.SNAP,
            ).exclude(**{
                field: ""
            }).values_list(field, flat=True).distinct())

    channels = field_for_snap_controllers("update_origin", version)
    snap_channel = None
    if channels:
        # report the minimum (with lowest risk) channel that sees the target
        # version
        for channel in channels:
            channel = SnapChannel.from_string(channel)
            if not channel.is_release_branch():
                # only point to a branch if it's a release one, as other branches
                # are in general intended as a temporary change for testing
                channel.branch = ""
            snap_channel = (min(channel, snap_channel)
                            if snap_channel else channel)
    else:
        # compose the channel from the target version
        risk_map = {"alpha": "edge", "beta": "beta", "rc": "candidate"}
        risk = risk_map.get(version.qualifier_type, "stable")
        snap_channel = SnapChannel(
            track=f"{version.major}.{version.minor}",
            risk=risk,
        )

    # report a cohort only if all controllers with the target version are on
    # the same cohort (or have no cohort)
    cohorts = field_for_snap_controllers("snap_cohort", version)
    snap_cohort = cohorts[0] if len(cohorts) == 1 else ""

    return TargetVersion(
        version,
        snap_channel,
        snap_cohort=snap_cohort,
        first_reported=update_first_reported,
    )