示例#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"),
     )
示例#2
0
 def test_get_snap_versions_info(self):
     data = {
         "channel": "3.0/edge/fix-9991",
         "update": {
             "revision": "5678",
             "version": "3.0.0~alpha2-222-g.cafecafe",
         },
         "cohort": "abcd1234",
     }
     path = self.make_file(contents=json.dumps(data))
     versions = get_snap_versions_info(info_file=Path(path))
     self.assertEqual(
         versions,
         SnapVersionsInfo(
             current=SnapVersion(
                 revision="1234", version="3.0.0~alpha1-111-g.deadbeef"
             ),
             channel=SnapChannel(
                 track="3.0", risk="edge", branch="fix-9991"
             ),
             update=SnapVersion(
                 revision="5678", version="3.0.0~alpha2-222-g.cafecafe"
             ),
             cohort="abcd1234",
         ),
     )
示例#3
0
 def test_snap_channel(self):
     c1 = factory.make_RackController()
     c2 = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         c1,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             channel={
                 "track": "3.0",
                 "risk": "stable"
             },
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             channel={
                 "track": "3.0",
                 "risk": "beta"
             },
         ),
     )
     target_version = get_target_version()
     # the most stable channel is returned
     self.assertEqual(
         target_version.snap_channel,
         SnapChannel("3.0", "stable"),
     )
示例#4
0
    def test_update_version(self):
        region = yield deferToDatabase(factory.make_RegionController)
        # Declare this region controller as the one running here.
        self.useFixture(MAASIDFixture(region.system_id))

        versions_info = SnapVersionsInfo(
            current=SnapVersion(revision="1234",
                                version="3.0.0~alpha1-111-g.deadbeef"),
            channel=SnapChannel(track="3.0"),
            update=SnapVersion(revision="5678",
                               version="3.0.0~alpha2-222-g.cafecafe"),
        )
        self.patch(version_update_check,
                   "get_snap_versions_info").return_value = versions_info

        service = RegionVersionUpdateCheckService(reactor)
        yield service.startService()
        yield service.stopService()

        info = yield deferToDatabase(getattr, region, "info")
        self.assertEqual(info.version, "3.0.0~alpha1-111-g.deadbeef")
        self.assertEqual(info.snap_revision, "1234")
        self.assertEqual(info.update_version, "3.0.0~alpha2-222-g.cafecafe")
        self.assertEqual(info.snap_update_revision, "5678")
        self.assertEqual(info.update_origin, "3.0/stable")
示例#5
0
 def test_deserialize(self):
     info = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         channel={"track": "3.0", "risk": "stable"},
         update={
             "revision": "5678",
             "version": "3.0.0~alpha2-222-g.cafecafe",
         },
     )
     self.assertEqual(
         info.current,
         SnapVersion(
             revision="1234", version="3.0.0~alpha1-111-g.deadbeef"
         ),
     )
     self.assertEqual(info.channel, SnapChannel(track="3.0"))
     self.assertEqual(
         info.update,
         SnapVersion(
             revision="5678", version="3.0.0~alpha2-222-g.cafecafe"
         ),
     )
示例#6
0
 def test_snap_channel_ignores_deb(self):
     c1 = factory.make_RackController()
     c2 = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         c1,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             channel={
                 "track": "3.0",
                 "risk": "stable"
             },
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         DebVersionsInfo(
             current={
                 "version": "3.0.0~beta1-001-g.bbb",
                 "origin": "http://archive.ubuntu.com/ focal/main",
             },
             update={
                 "version": "3.0.0-111-g.aaa",
                 "origin": "http://archive.ubuntu.com/ focal/main",
             },
         ),
     )
     target_version = get_target_version()
     self.assertEqual(
         target_version.snap_channel,
         SnapChannel("3.0", "stable"),
     )
示例#7
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
示例#8
0
 def test_snap_channel_from_version(self):
     c1 = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         c1,
         DebVersionsInfo(current={"version": "3.0.0~rc1-111-g.aaa"}, ),
     )
     target_version = get_target_version()
     self.assertEqual(
         target_version.snap_channel,
         SnapChannel("3.0", "candidate"),
     )
示例#9
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"),
     )
示例#10
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()
     )
示例#11
0
 def test_get_snap_version_info_no_update(self):
     data = {
         "channel": "3.0/edge/fix-9991",
     }
     path = self.make_file(contents=json.dumps(data))
     versions = get_snap_versions_info(info_file=Path(path))
     self.assertEqual(
         versions,
         SnapVersionsInfo(
             current=SnapVersion(
                 revision="1234", version="3.0.0~alpha1-111-g.deadbeef"
             ),
             channel=SnapChannel(
                 track="3.0", risk="edge", branch="fix-9991"
             ),
             update=None,
             cohort="",
         ),
     )
示例#12
0
 def test_snap_channel_keep_release_branch(self):
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             channel={
                 "track": "3.0",
                 "risk": "beta",
                 "branch": "ubuntu-20.04",
             },
         ),
     )
     target_version = get_target_version()
     self.assertEqual(
         target_version.snap_channel,
         SnapChannel("3.0", "beta", branch="ubuntu-20.04"),
     )
示例#13
0
 def test_str_default(self):
     self.assertEqual(str(SnapChannel(track="latest")), "latest/stable")
示例#14
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"),
     )
示例#15
0
 def test_str_with_branch(self):
     self.assertEqual(
         str(SnapChannel(track="2.0", risk="beta", branch="test")),
         "2.0/beta/test",
     )
示例#16
0
 def test_str_no_branch(self):
     self.assertEqual(
         str(SnapChannel(track="2.0", risk="beta")), "2.0/beta"
     )
示例#17
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,
    )
示例#18
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"),
     )