Ejemplo n.º 1
0
 def test_set_versions_update_first_reported_update_different_update(self):
     controller = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         update={
             "revision": "5678",
             "version": "3.0.0~alpha2-222-g.cafecafe",
         },
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     update_first_reported = controller.controllerinfo.update_first_reported
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         update={
             "revision": "5678",
             "version": "3.0.0~alpha3-333-g.adadadad",
         },
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     controller_info = reload_object(controller).controllerinfo
     self.assertGreater(controller_info.update_first_reported,
                        update_first_reported)
Ejemplo n.º 2
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"),
     )
Ejemplo n.º 3
0
 def test_dehydrate_with_versions_issues(self):
     owner = factory.make_admin()
     handler = ControllerHandler(owner, {}, None)
     rack = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         channel={"track": "3.0", "risk": "stable"},
         cohort="abc",
     )
     ControllerInfo.objects.set_versions_info(rack, versions)
     # another rack with a higher version has no cohort
     ControllerInfo.objects.set_versions_info(
         factory.make_RackController(),
         SnapVersionsInfo(
             current={
                 "revision": "5678",
                 "version": "3.0.0-222-g.cafecafe",
             },
             channel={"track": "3.0", "risk": "stable"},
         ),
     )
     versions = handler.list({})[0]["versions"]
     self.assertEqual(versions["issues"], ["different-cohort"])
Ejemplo n.º 4
0
 def test_snap_cohort_multiple_cohorts_target_version(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"
             },
             cohort="abc",
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             cohort="xyz",
         ),
     )
     target_version = get_target_version()
     self.assertEqual(target_version.snap_cohort, "")
Ejemplo n.º 5
0
 def test_snap_cohort_from_update(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"
             },
             cohort="abc",
             update={
                 "version": "3.0.2-333-g.ccc",
                 "revision": "7890"
             },
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(
             current={
                 "version": "3.0.1-222-g.bbb",
                 "revision": "5678"
             },
             cohort="xyz",
         ),
     )
     target_version = get_target_version()
     self.assertEqual(target_version.snap_cohort, "abc")
Ejemplo n.º 6
0
 def test_different_snap_cohorts(self):
     c1 = factory.make_RegionRackController()
     c2 = factory.make_RegionRackController()
     ControllerInfo.objects.set_versions_info(
         c1,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             cohort="abc",
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             cohort="xyz",
         ),
     )
     notification = Notification.objects.filter(
         ident=UPGRADE_ISSUE_NOTIFICATION_IDENT).first()
     self.assertIn(
         "Controllers have different installation sources.",
         notification.message,
     )
Ejemplo n.º 7
0
 def test_issue_resolved_removes_notification(self):
     c1 = factory.make_RegionRackController()
     c2 = factory.make_RegionRackController()
     ControllerInfo.objects.set_versions_info(
         c1,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0-111-g.aaa",
                 "revision": "1234"
             },
             cohort="abc",
         ),
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(current={
             "version": "3.0.0-111-g.aaa",
             "revision": "1234"
         }, ),
     )
     self.assertTrue(
         Notification.objects.filter(
             ident=UPGRADE_ISSUE_NOTIFICATION_IDENT).exists())
     # remove the cohort
     ControllerInfo.objects.set_versions_info(
         c1,
         SnapVersionsInfo(current={
             "version": "3.0.0-111-g.aaa",
             "revision": "1234"
         }, ),
     )
     self.assertFalse(
         Notification.objects.filter(
             ident=UPGRADE_ISSUE_NOTIFICATION_IDENT).exists())
Ejemplo n.º 8
0
 def test_different_issue_new_notification(self):
     c1 = factory.make_RegionRackController()
     c2 = factory.make_RegionRackController()
     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"
             },
         ),
     )
     notification1 = Notification.objects.filter(
         ident=UPGRADE_ISSUE_NOTIFICATION_IDENT).first()
     self.assertIn(
         "Controllers have different installation sources.",
         notification1.message,
     )
     ControllerInfo.objects.set_versions_info(
         c2,
         SnapVersionsInfo(
             current={
                 "version": "3.0.2-222-g.bbb",
                 "revision": "5678"
             },
             channel={
                 "track": "3.0",
                 "risk": "stable"
             },
         ),
     )
     notification2 = Notification.objects.filter(
         ident=UPGRADE_ISSUE_NOTIFICATION_IDENT).first()
     self.assertIn(
         "Controllers have different versions.",
         notification2.message,
     )
     self.assertNotEqual(notification1.id, notification2.id)
Ejemplo n.º 9
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",
         ),
     )
Ejemplo n.º 10
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"
         ),
     )
Ejemplo n.º 11
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")
Ejemplo n.º 12
0
 def test_set_versions_update_first_reported_update_same_update_different_install_type(
     self, ):
     controller = factory.make_RackController()
     versions = DebVersionsInfo(
         current={
             "version": "3.0.0~alpha1-111-g.deadbeef",
             "origin": "http://archive.ubuntu.com/ focal/main",
         },
         update={
             "version": "3.0.0~alpha2-222-g.cafecafe",
             "origin": "http://archive.ubuntu.com/ focal/main",
         },
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     update_first_reported = controller.controllerinfo.update_first_reported
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         update={
             "revision": "5678",
             "version": "3.0.0~alpha2-222-g.cafecafe",
         },
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     controller_info = reload_object(controller).controllerinfo
     self.assertGreater(controller_info.update_first_reported,
                        update_first_reported)
Ejemplo n.º 13
0
 def test_dehydrate_with_versions_only_current(self):
     owner = factory.make_admin()
     handler = ControllerHandler(owner, {}, None)
     rack = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         channel={"track": "3.0", "risk": "stable"},
     )
     ControllerInfo.objects.set_versions_info(rack, versions)
     result = handler.list({})
     self.assertEqual(
         result[0]["versions"],
         {
             "install_type": "snap",
             "current": {
                 "version": "3.0.0~alpha1-111-g.deadbeef",
                 "snap_revision": "1234",
             },
             "origin": "3.0/stable",
             "up_to_date": True,
             "issues": [],
         },
     )
Ejemplo n.º 14
0
 def test_set_versions_info_snap(self):
     controller = factory.make_RackController()
     versions = 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",
         },
         cohort="abc123",
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     controller_info = controller.controllerinfo
     self.assertEqual(controller_info.install_type,
                      CONTROLLER_INSTALL_TYPE.SNAP)
     self.assertEqual(controller_info.version,
                      "3.0.0~alpha1-111-g.deadbeef")
     self.assertEqual(controller_info.update_version,
                      "3.0.0~alpha2-222-g.cafecafe")
     self.assertEqual(controller_info.update_origin, "3.0/stable")
     self.assertEqual(controller_info.snap_revision, "1234")
     self.assertEqual(controller_info.snap_update_revision, "5678")
     self.assertEqual(controller_info.snap_cohort, "abc123")
     self.assertIsNotNone(controller_info.update_first_reported)
Ejemplo n.º 15
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"),
     )
Ejemplo n.º 16
0
 def test_dehydrate_with_versions_empty_origin(self):
     owner = factory.make_admin()
     handler = ControllerHandler(owner, {}, None)
     rack = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
     )
     ControllerInfo.objects.set_versions_info(rack, versions)
     result = handler.list({})
     self.assertEqual(result[0]["versions"]["origin"], "")
Ejemplo n.º 17
0
 def test_get_snap_versions_info_no_file(self):
     versions = get_snap_versions_info(Path("/not/here"))
     self.assertEqual(
         versions,
         SnapVersionsInfo(
             current=SnapVersion(
                 revision="1234", version="3.0.0~alpha1-111-g.deadbeef"
             ),
             channel=None,
             update=None,
             cohort="",
         ),
     )
Ejemplo n.º 18
0
 def test_is_up_to_date_with_different_version(self):
     target_version = TargetVersion(
         version=MAASVersion.from_string("3.0.0-222-g.cafecafe"),
         snap_channel="3.0/stable",
     )
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         }, ),
     )
     self.assertFalse(controller.info.is_up_to_date(target_version))
Ejemplo n.º 19
0
 def test_is_up_to_date(self):
     version = "3.0.0~alpha1-111-g.deadbeef"
     target_version = TargetVersion(
         version=MAASVersion.from_string(version),
         snap_channel="3.0/stable",
     )
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(current={
             "revision": "1234",
             "version": version,
         }, ),
     )
     self.assertTrue(controller.info.is_up_to_date(target_version))
Ejemplo n.º 20
0
 def test_target_version_snap_cohort(self):
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0~beta2-123-g.asdf",
                 "revision": "1234",
             },
             channel="3.0/beta",
             cohort="abc",
         ),
     )
     handler = GeneralHandler(factory.make_User(), {}, None)
     result = handler.target_version({})
     self.assertEqual(result["snap_cohort"], "abc")
Ejemplo n.º 21
0
 def test_set_versions_info_snap_no_update(self):
     controller = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         channel={
             "track": "3.0",
             "risk": "stable"
         },
     )
     ControllerInfo.objects.set_versions_info(controller, versions)
     controller_info = controller.controllerinfo
     self.assertEqual(controller_info.update_origin, "3.0/stable")
     self.assertEqual(controller_info.snap_update_revision, "")
     self.assertEqual(controller_info.snap_cohort, "")
     self.assertIsNone(controller_info.update_first_reported)
Ejemplo n.º 22
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="",
         ),
     )
Ejemplo n.º 23
0
 def test_target_version(self):
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0~beta2-123-g.asdf",
                 "revision": "1234",
             },
             update={
                 "version": "3.0.0~beta3-456-g.cafe",
                 "revision": "5678",
             },
             channel="3.0/beta",
         ),
     )
     handler = GeneralHandler(factory.make_User(), {}, None)
     result = handler.target_version({})
     self.assertEqual(result["version"], "3.0.0~beta3-456-g.cafe")
     self.assertEqual(result["snap_channel"], "3.0/beta")
     self.assertIsNotNone(result["first_reported"])
Ejemplo n.º 24
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"),
     )
Ejemplo n.º 25
0
 def test_set_versions_info_change_type(self):
     controller = factory.make_RackController()
     deb_versions = DebVersionsInfo(
         current={
             "version": "3.0.0",
             "origin": "http://archive.ubuntu.com/ focal/main",
         },
         update={
             "version": "3.0.1",
             "origin": "http://mymirror.example.com/ focal/main",
         },
     )
     snap_versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.1.0",
         },
         channel={
             "track": "3.0",
             "risk": "stable"
         },
         update={
             "revision": "5678",
             "version": "3.1.1",
         },
         cohort="abc123",
     )
     ControllerInfo.objects.set_versions_info(controller, deb_versions)
     ControllerInfo.objects.set_versions_info(controller, snap_versions)
     controller_info = reload_object(controller).controllerinfo
     # all fields are updated
     self.assertEqual(controller_info.install_type,
                      CONTROLLER_INSTALL_TYPE.SNAP)
     self.assertEqual(controller_info.version, "3.1.0")
     self.assertEqual(controller_info.update_version, "3.1.1")
     self.assertEqual(controller_info.update_origin, "3.0/stable")
     self.assertEqual(controller_info.snap_revision, "1234")
     self.assertEqual(controller_info.snap_update_revision, "5678")
     self.assertEqual(controller_info.snap_cohort, "abc123")
Ejemplo n.º 26
0
 def test_get_version_issues(self):
     target_version = TargetVersion(
         version=MAASVersion.from_string("3.0.0-222-g.cafecafe"),
         snap_channel="3.0/stable",
     )
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "revision": "1234",
                 "version": "3.0.0~alpha1-111-g.deadbeef",
             },
             channel="3.0/beta",
             cohort="abc",
         ),
     )
     self.assertEqual(
         controller.info.get_version_issues(target_version),
         [
             VERSION_ISSUES.DIFFERENT_CHANNEL.value,
             VERSION_ISSUES.DIFFERENT_COHORT.value,
         ],
     )