Ejemplo n.º 1
0
    def update_disk(self, params):
        """Update disk information."""
        # Only admin users can perform delete.
        if not reload_object(self.user).is_superuser:
            raise HandlerPermissionError()

        node = self.get_object(params)
        device = BlockDevice.objects.get(id=params['block_id'],
                                         node=node).actual_instance
        if device.type == 'physical':
            form = UpdatePhysicalBlockDeviceForm(instance=device, data=params)
        elif device.type == 'virtual':
            form = UpdateVirtualBlockDeviceForm(instance=device, data=params)
        else:
            raise HandlerError('Cannot update block device of type %s' %
                               device.type)
        if not form.is_valid():
            raise HandlerError(form.errors)
        else:
            disk_obj = form.save()
            self._update_obj_tags(disk_obj, params)
            if 'fstype' in params:
                self.update_blockdevice_filesystem(
                    disk_obj, params['fstype'], params.get('mount_point', ''),
                    params.get('mount_options', ''))
Ejemplo n.º 2
0
 def update_disk(self, params):
     """Update disk information."""
     node = self._get_node_or_permission_error(
         params, permission=self._meta.edit_permission)
     device = BlockDevice.objects.get(
         id=params['block_id'], node=node).actual_instance
     if device.type == 'physical':
         form = UpdatePhysicalBlockDeviceForm(
             instance=device, data=params)
     elif device.type == 'virtual':
         form = UpdateVirtualBlockDeviceForm(
             instance=device, data=params)
     else:
         raise HandlerError(
             'Cannot update block device of type %s' % device.type)
     if not form.is_valid():
         raise HandlerError(form.errors)
     else:
         disk_obj = form.save()
         self._update_obj_tags(disk_obj, params)
         if 'fstype' in params:
             self.update_blockdevice_filesystem(
                 disk_obj, params['fstype'],
                 params.get('mount_point', ''),
                 params.get('mount_options', ''))
Ejemplo n.º 3
0
 def test_updates_physical_block_device(self):
     block_device = factory.make_PhysicalBlockDevice()
     name = factory.make_name("sd")
     model = factory.make_name("model")
     serial = factory.make_name("serial")
     id_path = factory.make_absolute_path()
     size = random.randint(
         MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = UpdatePhysicalBlockDeviceForm(instance=block_device, data={
         'name': name,
         'model': model,
         'serial': serial,
         'id_path': id_path,
         'size': size,
         'block_size': block_size,
         })
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertThat(block_device, MatchesStructure.byEquality(
         name=name,
         model=model,
         serial=serial,
         id_path=id_path,
         size=size,
         block_size=block_size,
         ))
Ejemplo n.º 4
0
 def test_update_no_numa_node_change(self):
     node = factory.make_Node()
     numa_node = factory.make_NUMANode(node=node)
     # associate with a node different from the default one
     block_device = factory.make_PhysicalBlockDevice(numa_node=numa_node)
     form = UpdatePhysicalBlockDeviceForm(instance=block_device, data={})
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertEqual(block_device.numa_node, numa_node)
Ejemplo n.º 5
0
 def test_udpate_partitiontable_type(self):
     block_device = factory.make_PhysicalBlockDevice()
     factory.make_PartitionTable(table_type=PARTITION_TABLE_TYPE.GPT,
                                 block_device=block_device)
     form = UpdatePhysicalBlockDeviceForm(
         instance=block_device,
         data={"partition_table_type": PARTITION_TABLE_TYPE.MBR},
     )
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertEqual(
         block_device.get_partitiontable().table_type,
         PARTITION_TABLE_TYPE.MBR,
     )
Ejemplo n.º 6
0
 def test_updates_physical_block_device(self):
     block_device = factory.make_PhysicalBlockDevice()
     node = block_device.node
     numa_node = factory.make_NUMANode(node=node)
     name = factory.make_name("sd")
     model = factory.make_name("model")
     serial = factory.make_name("serial")
     id_path = factory.make_absolute_path()
     size = random.randint(MIN_BLOCK_DEVICE_SIZE,
                           MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = UpdatePhysicalBlockDeviceForm(
         instance=block_device,
         data={
             "name": name,
             "model": model,
             "serial": serial,
             "id_path": id_path,
             "size": size,
             "block_size": block_size,
             "numa_node": numa_node.index,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertThat(
         block_device,
         MatchesStructure.byEquality(
             name=name,
             model=model,
             serial=serial,
             id_path=id_path,
             size=size,
             block_size=block_size,
             numa_node=numa_node,
         ),
     )