示例#1
0
 def test_raid_creation_on_boot_disk(self):
     node = factory.make_Node(with_boot_disk=False)
     bds = [
         factory.make_PhysicalBlockDevice(node=node, bootable=True)
         for _ in range(10)
     ]
     partitions = []
     block_devices = [bd.id for bd in bds[:5]]
     for bd in bds[5:]:
         partition_table = factory.make_PartitionTable(block_device=bd)
         partition = partition_table.add_partition()
         partitions.append(partition.id)
     form = CreateRaidForm(
         node=node,
         data={
             "name": "md1",
             "level": FILESYSTEM_GROUP_TYPE.RAID_6,
             "block_devices": block_devices,
             "partitions": partitions,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     raid = form.save()
     self.assertEqual("md1", raid.name)
     self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type)
     self.assertCountEqual(raid.filesystems.exclude(block_device=None), [])
     self.assertEqual(raid.filesystems.exclude(partition=None).count(), 10)
示例#2
0
 def test_raid_creation_without_storage_fails(self):
     node = factory.make_Node()
     for level in [
             FILESYSTEM_GROUP_TYPE.RAID_0,
             FILESYSTEM_GROUP_TYPE.RAID_1,
             FILESYSTEM_GROUP_TYPE.RAID_5,
             FILESYSTEM_GROUP_TYPE.RAID_6,
             FILESYSTEM_GROUP_TYPE.RAID_10,
     ]:
         form = CreateRaidForm(
             node=node,
             data={
                 "name": "md1",
                 "level": level,
                 "block_devices": [],
                 "partitions": [],
             },
         )
         self.assertFalse(form.is_valid())
         self.assertDictContainsSubset(
             {
                 "__all__": [
                     "At least one block device or partition must "
                     "be added to the array."
                 ]
             },
             form.errors,
         )
示例#3
0
文件: test_raid.py 项目: zhangrb/maas
 def test_requires_fields(self):
     node = factory.make_Node()
     form = CreateRaidForm(node=node, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertDictContainsSubset({
         'level': ['This field is required.'],
     }, form.errors)
示例#4
0
 def test_raid_creation_with_names(self):
     node = factory.make_Node()
     device_size = 10 * 1000 ** 4
     bds = [
         factory.make_PhysicalBlockDevice(node=node, size=device_size)
         for _ in range(10)
     ]
     for bd in bds[5:]:
         factory.make_PartitionTable(block_device=bd)
     block_devices_ids = [
         bd.id
         for bd in bds
         if bd.get_partitiontable() is None
     ]
     block_device_names = [
         bd.name
         for bd in bds
         if bd.get_partitiontable() is None
     ]
     partitions = [
         bd.get_partitiontable().add_partition()
         for bd in bds[5:]
     ]
     partition_ids = [
         part.id
         for part in partitions
     ]
     partition_names = [
         part.name
         for part in partitions
     ]
     form = CreateRaidForm(node=node, data={
         'name': 'md1',
         'level': FILESYSTEM_GROUP_TYPE.RAID_6,
         'block_devices': block_device_names,
         'partitions': partition_names,
     })
     self.assertTrue(form.is_valid(), form.errors)
     raid = form.save()
     self.assertEqual('md1', raid.name)
     self.assertEqual(8 * partitions[0].size, raid.get_size())
     self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type)
     self.assertItemsEqual(
         block_devices_ids,
         [
             fs.block_device.id
             for fs in raid.filesystems.exclude(block_device=None)
         ])
     self.assertItemsEqual(
         partition_ids,
         [
             fs.partition.id
             for fs in raid.filesystems.exclude(partition=None)
         ])
示例#5
0
    def create(self, request, system_id):
        """@description-title Set up a RAID
        @description Set up a RAID on a machine with the given system_id.

        @param (string) "{system_id}" [required=true] The system_id of the
        machine on which to set up the RAID.

        @param (string) "name" [required=false] Name of the RAID.

        @param (string) "uuid" [required=false] UUID of the RAID.

        @param (int) "level" [required=true] RAID level.

        @param (string) "block_devices" [required=false] Block devices to add
        to the RAID.

        @param (string) "spare_devices" [required=false] Spare block devices to
        add to the RAID.

        @param (string) "partitions" [required=false] Partitions to add to the
        RAID.

        @param (string) "spare_partitions" [required=false] Spare partitions to
        add to the RAID.

        @success (http-status-code) "200" 200
        @success (json) "success-json" A JSON object containing information
        about the new RAID.
        @success-example "success-json" [exkey=raids-placeholder] placeholder
        text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested machine 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.
        @error-example "not-ready"
            Cannot create RAID because the machine is not Ready.
        """
        machine = Machine.objects.get_node_or_404(system_id, request.user,
                                                  NodePermission.admin)
        if machine.status != NODE_STATUS.READY:
            raise NodeStateViolation(
                "Cannot create RAID because the machine is not Ready.")
        form = CreateRaidForm(machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#6
0
    def create_raid(self, params):
        """Create a RAID."""
        node = self._get_node_or_permission_error(params)
        form = CreateRaidForm(node=node, data=params)
        if not form.is_valid():
            raise HandlerError(form.errors)
        else:
            raid = form.save()

        self._update_obj_tags(raid.virtual_device, params)
        if 'fstype' in params:
            self.update_blockdevice_filesystem(
                raid.virtual_device, params.get("fstype"),
                params.get("mount_point"), params.get("mount_options"))
示例#7
0
 def test_raid_creation_on_save(self):
     node = factory.make_Node()
     device_size = 10 * 1000**4
     bds = [
         factory.make_PhysicalBlockDevice(node=node, size=device_size)
         for _ in range(10)
     ]
     for bd in bds[5:]:
         factory.make_PartitionTable(block_device=bd)
     block_devices = [
         bd.id for bd in bds if bd.get_partitiontable() is None
     ]
     partition_objs = [
         bd.get_partitiontable().add_partition() for bd in bds[5:]
     ]
     partitions = [partition.id for partition in partition_objs]
     form = CreateRaidForm(
         node=node,
         data={
             "name": "md1",
             "level": FILESYSTEM_GROUP_TYPE.RAID_6,
             "block_devices": block_devices,
             "partitions": partitions,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     raid = form.save()
     self.assertEqual("md1", raid.name)
     self.assertEqual(
         (8 * partition_objs[0].size) - RAID_SUPERBLOCK_OVERHEAD,
         raid.get_size(),
     )
     self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type)
     self.assertItemsEqual(
         block_devices,
         [
             fs.block_device.id
             for fs in raid.filesystems.exclude(block_device=None)
         ],
     )
     self.assertItemsEqual(
         partitions,
         [
             fs.partition.id
             for fs in raid.filesystems.exclude(partition=None)
         ],
     )
示例#8
0
    def create_raid(self, params):
        """Create a RAID."""
        # Only admin users can perform delete.
        if not reload_object(self.user).is_superuser:
            raise HandlerPermissionError()

        node = self.get_object(params)
        form = CreateRaidForm(node=node, data=params)
        if not form.is_valid():
            raise HandlerError(form.errors)
        else:
            raid = form.save()

        self._update_obj_tags(raid.virtual_device, params)
        if 'fstype' in params:
            self.update_blockdevice_filesystem(raid.virtual_device,
                                               params.get("fstype"),
                                               params.get("mount_point"),
                                               params.get("mount_options"))
示例#9
0
    def create(self, request, system_id):
        """Creates a RAID

        :param name: Name of the RAID.
        :param uuid: UUID of the RAID.
        :param level: RAID level.
        :param block_devices: Block devices to add to the RAID.
        :param spare_devices: Spare block devices to add to the RAID.
        :param partitions: Partitions to add to the RAID.
        :param spare_partitions: Spare partitions to add to the RAID.

        Returns 404 if the machine is not found.
        Returns 409 if the machine is not Ready.
        """
        machine = Machine.objects.get_node_or_404(system_id, request.user,
                                                  NodePermission.admin)
        if machine.status != NODE_STATUS.READY:
            raise NodeStateViolation(
                "Cannot create RAID because the machine is not Ready.")
        form = CreateRaidForm(machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#10
0
 def test_raid_creation_without_storage_fails(self):
     node = factory.make_Node()
     for level in [
             FILESYSTEM_GROUP_TYPE.RAID_0,
             FILESYSTEM_GROUP_TYPE.RAID_1,
             FILESYSTEM_GROUP_TYPE.RAID_5,
             FILESYSTEM_GROUP_TYPE.RAID_6,
             FILESYSTEM_GROUP_TYPE.RAID_10,
     ]:
         form = CreateRaidForm(node=node, data={
             'name': 'md1',
             'level': level,
             'block_devices': [],
             'partitions': [],
         })
         self.assertFalse(form.is_valid())
         self.assertDictContainsSubset(
             {
                 '__all__': [
                     'At least one block device or partition must '
                     'be added to the array.',
                 ]
             },
             form.errors)
示例#11
0
 def test_requires_fields(self):
     node = factory.make_Node()
     form = CreateRaidForm(node=node, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual(form.errors["level"], ["This field is required."])