def update(self, request, system_id, id): """Update RAID on a machine. :param name: Name of the RAID. :param uuid: UUID of the RAID. :param add_block_devices: Block devices to add to the RAID. :param remove_block_devices: Block devices to remove from the RAID. :param add_spare_devices: Spare block devices to add to the RAID. :param remove_spare_devices: Spare block devices to remove from the RAID. :param add_partitions: Partitions to add to the RAID. :param remove_partitions: Partitions to remove from the RAID. :param add_spare_partitions: Spare partitions to add to the RAID. :param remove_spare_partitions: Spare partitions to remove from the RAID. Returns 404 if the machine or RAID is not found. Returns 409 if the machine is not Ready. """ raid = RAID.objects.get_object_or_404(system_id, id, request.user, NodePermission.admin) node = raid.get_node() if node.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot update RAID because the machine is not Ready.") form = UpdateRaidForm(raid, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def test_remove_valid_spare_partition(self): raid = _make_interesting_RAID(node=factory.make_Node()) ids = [ fs.partition.id for fs in raid.filesystems.filter( fstype=FILESYSTEM_TYPE.RAID_SPARE).exclude(partition=None)[:2] ] # Select 2 items for removal form = UpdateRaidForm(raid, data={"remove_partitions": ids}) self.assertTrue(form.is_valid(), form.errors)
def test_remove_valid_blockdevice(self): raid = _make_interesting_RAID(node=factory.make_Node()) ids = [ fs.block_device.id for fs in raid.filesystems.filter( fstype=FILESYSTEM_TYPE.RAID).exclude(block_device=None)[:2] ] # Select 2 items for removal form = UpdateRaidForm(raid, data={"remove_block_devices": ids}) self.assertTrue(form.is_valid(), form.errors)
def test_add_valid_spare_partition(self): raid = factory.make_FilesystemGroup( group_type=FILESYSTEM_GROUP_TYPE.RAID_6) # Add 5 new partitions to the node. part_ids = [factory.make_Partition(node=raid.get_node()).id for _ in range(5)] form = UpdateRaidForm(raid, data={'add_spare_partitions': part_ids}) self.assertTrue(form.is_valid(), form.errors)
def test_add_valid_spare_device(self): raid = factory.make_FilesystemGroup( group_type=FILESYSTEM_GROUP_TYPE.RAID_6) # Add 5 new blockdevices to the node. bd_ids = [factory.make_BlockDevice(node=raid.get_node()).id for _ in range(5)] form = UpdateRaidForm(raid, data={'add_spare_devices': bd_ids}) self.assertTrue(form.is_valid(), form.errors)
def test_remove_invalid_spare_partition_fails(self): raid = _make_interesting_RAID(node=factory.make_Node()) ids = [factory.make_Partition().id for _ in range(2)] form = UpdateRaidForm(raid, data={'remove_spare_partitions': ids}) self.assertFalse(form.is_valid(), form.errors) self.assertIn('remove_spare_partitions', form.errors) self.assertIn('is not one of the available choices.', form.errors['remove_spare_partitions'][0])
def test_remove_invalid_spare_blockdevice_fails(self): raid = _make_interesting_RAID(node=factory.make_Node()) ids = [factory.make_BlockDevice().id for _ in range(2)] form = UpdateRaidForm(raid, data={"remove_spare_devices": ids}) self.assertFalse(form.is_valid(), form.errors) self.assertIn("remove_spare_devices", form.errors) self.assertIn( "is not one of the available choices.", form.errors["remove_spare_devices"][0], )
def test_add_invalid_spare_partition_fails(self): raid = factory.make_FilesystemGroup( group_type=FILESYSTEM_GROUP_TYPE.RAID_6) # Add 5 new partitions to other nodes. part_ids = [factory.make_Partition().id for _ in range(5)] form = UpdateRaidForm(raid, data={'add_spare_partitions': part_ids}) self.assertFalse(form.is_valid(), form.errors) self.assertIn('add_spare_partitions', form.errors) self.assertIn('is not one of the available choices.', form.errors['add_spare_partitions'][0])
def test_add_invalid_spare_blockdevice_fails(self): raid = factory.make_FilesystemGroup( group_type=FILESYSTEM_GROUP_TYPE.RAID_6) # Add 5 new blockdevices to other nodes. bd_ids = [factory.make_BlockDevice().id for _ in range(5)] form = UpdateRaidForm(raid, data={"add_spare_devices": bd_ids}) self.assertFalse(form.is_valid(), form.errors) self.assertIn("add_spare_devices", form.errors) self.assertIn( "is not one of the available choices.", form.errors["add_spare_devices"][0], )
def test_add_valid_spare_boot_disk(self): node = factory.make_Node(with_boot_disk=False) boot_disk = factory.make_PhysicalBlockDevice(node=node) raid = factory.make_FilesystemGroup( group_type=FILESYSTEM_GROUP_TYPE.RAID_6, node=node) raid = RAID.objects.get(id=raid.id) form = UpdateRaidForm(raid, data={'add_spare_devices': [boot_disk.id]}) self.assertTrue(form.is_valid(), form.errors) raid = form.save() boot_partition = boot_disk.get_partitiontable().partitions.first() self.assertEqual( boot_partition.get_effective_filesystem().filesystem_group.id, raid.id)
def update(self, request, system_id, id): """@description-title Update a RAID @description Update a RAID with the given id on a machine with the given system_id. @param (string) "{system_id}" [required=true] The system_id of the machine containing the RAID. @param (int) "{id}" [required=true] A RAID id. @param (string) "name" [required=false] Name of the RAID. @param (string) "uuid" [required=false] UUID of the RAID. @param (string) "add_block_devices" [required=false] Block devices to add to the RAID. @param (string) "remove_block_devices" [required=false] Block devices to remove from the RAID. @param (string) "add_spare_devices" [required=false] Spare block devices to add to the RAID. @param (string) "remove_spare_devices" [required=false] Spare block devices to remove from the RAID. @param (string) "add_partitions" [required=false] Partitions to add to the RAID. @param (string) "remove_partitions" [required=false] Partitions to remove from the RAID. @param (string) "add_spare_partitions" [required=false] Spare partitions to add to the RAID. @param (string) "remove_spare_partitions" [required=false] Spare partitions to remove from the RAID. @success (http-status-code) "200" 200 @success (json) "success-json" A JSON object containing the updated RAID. @success-example "success-json" [exkey=raids-placeholder] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" The requested machine or RAID id is not found. @error-example "not-found" Not Found @error (http-status-code) "409" 409 @error (content) "not-ready" The requested machine is not ready. """ raid = RAID.objects.get_object_or_404(system_id, id, request.user, NodePermission.admin) node = raid.get_node() if node.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot update RAID because the machine is not Ready.") form = UpdateRaidForm(raid, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)