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"])
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": [], }, )
def test_dehydrate_with_versions_deb(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) rack = factory.make_RackController() versions = DebVersionsInfo( current={ "version": "3.0.0~alpha1-111-g.deadbeef", "origin": "http://archive.ubuntu.com main/focal", }, update={ "version": "3.0.0~alpha2-222-g.cafecafe", "origin": "http://archive.ubuntu.com main/focal", }, ) ControllerInfo.objects.set_versions_info(rack, versions) result = handler.list({}) self.assertEqual( result[0]["versions"], { "install_type": "deb", "current": { "version": "3.0.0~alpha1-111-g.deadbeef", }, "update": { "version": "3.0.0~alpha2-222-g.cafecafe", }, "origin": "http://archive.ubuntu.com main/focal", "up_to_date": False, "issues": [], }, )
def test_last_image_sync_returns_none_for_none(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) node = factory.make_RackController(owner=owner, last_image_sync=None) result = handler.list({}) self.assertEqual(1, len(result)) self.assertEqual(NODE_TYPE.RACK_CONTROLLER, result[0].get('node_type')) self.assertIsNone(result[0].get("last_image_sync")) data = handler.get({"system_id": node.system_id}) self.assertIsNone(data.get("last_image_sync"))
def test_dehydrate_includes_version(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) rack = factory.make_RackController() version = "2.3.0~alpha1-6000-gabc123-snap" ControllerInfo.objects.set_version(rack, version) result = handler.list({}) self.assertEqual(version, result[0].get('version')) self.assertEqual("2.3.0~alpha1", result[0].get('version__short')) self.assertEqual("2.3.0~alpha1 (6000-gabc123) (snap)", result[0].get('version__long'))
def test_last_image_sync(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) node = factory.make_RackController(owner=owner) result = handler.list({}) self.assertEqual(1, len(result)) self.assertEqual(NODE_TYPE.RACK_CONTROLLER, result[0].get('node_type')) self.assertEqual(result[0].get('last_image_sync'), dehydrate_datetime(node.last_image_sync)) data = handler.get({"system_id": node.system_id}) self.assertEqual(data.get("last_image_sync"), dehydrate_datetime(node.last_image_sync))
def test_dehydrate_includes_tags(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) region = factory.make_RegionRackController() tags = [] for _ in range(3): tag = factory.make_Tag(definition="") tag.node_set.add(region) tag.save() tags.append(tag.name) result = handler.list({}) self.assertEqual(tags, result[0].get("tags"))
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"], "")
def test_list_ignores_devices_and_nodes(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) # Create a device. factory.make_Node(owner=owner, node_type=NODE_TYPE.DEVICE) # Create a device with Node parent. node = factory.make_Node(owner=owner) device_with_parent = factory.make_Node(owner=owner, interface=True) device_with_parent.parent = node device_with_parent.save() node = factory.make_RackController(owner=owner) result = handler.list({}) self.assertEqual(1, len(result)) self.assertEqual(NODE_TYPE.RACK_CONTROLLER, result[0].get('node_type'))
def test_dehydrate_includes_version(self): self.useFixture( EnvironmentVariableFixture("SNAP", "/var/snap/maas/123")) owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) rack = factory.make_RackController() version = "2.3.0~alpha1-6000-gabc123" ControllerInfo.objects.set_version(rack, version) result = handler.list({}) self.assertEqual(version, result[0].get("version")) self.assertEqual("2.3.0~alpha1", result[0].get("version__short")) self.assertEqual( "2.3.0~alpha1 (6000-gabc123) (snap)", result[0].get("version__long"), )
def test_vlan_counts_list(self): owner = factory.make_admin() rack1 = factory.make_RackController(owner=owner) rack2 = factory.make_RackController(owner=owner) vlan1, vlan2 = VLAN.objects.order_by("id") # attach the first rack to both VLANs iface = factory.make_Interface(node=rack1, vlan=vlan2) factory.make_StaticIPAddress(interface=iface) vlan1.primary_rack = rack1 vlan1.save() # make the second VLAN HA vlan2.primary_rack = rack2 vlan2.secondary_rack = rack1 vlan2.save() handler = ControllerHandler(owner, {}, None) result = {entry["id"]: entry["vlans_ha"] for entry in handler.list({})} self.assertEqual( result, { rack1.id: {"true": 1, "false": 1}, rack2.id: {"true": 1, "false": 0}, }, )
def test_dehydrate_empty_versions(self): owner = factory.make_admin() handler = ControllerHandler(owner, {}, None) factory.make_RackController() result = handler.list({}) self.assertEqual(result[0]["versions"], {})