Beispiel #1
0
 def test_creates_physical_block_device_with_numa_node(self):
     node = factory.make_Node()
     numa_node = factory.make_NUMANode(node=node)
     name = factory.make_name("sd")
     id_path = factory.make_absolute_path()
     size = random.randint(MIN_BLOCK_DEVICE_SIZE,
                           MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = CreatePhysicalBlockDeviceForm(
         node,
         data={
             "name": name,
             "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,
             id_path=id_path,
             size=size,
             block_size=block_size,
             numa_node=numa_node,
         ),
     )
Beispiel #2
0
 def test_creates_physical_block_device_with_model_serial(self):
     node = factory.make_Node()
     name = factory.make_name("sd")
     model = factory.make_name("model")
     serial = factory.make_name("serial")
     size = random.randint(MIN_BLOCK_DEVICE_SIZE,
                           MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = CreatePhysicalBlockDeviceForm(
         node,
         data={
             "name": name,
             "model": model,
             "serial": serial,
             "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,
             size=size,
             block_size=block_size,
             numa_node=node.default_numanode,
         ),
     )
Beispiel #3
0
 def test_requires_fields(self):
     node = factory.make_Node()
     form = CreatePhysicalBlockDeviceForm(node, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual({
         'name': ['This field is required.'],
         'size': ['This field is required.'],
         'block_size': ['This field is required.'],
         '__all__': [
             'serial/model are required if id_path is not provided.'],
         }, form.errors)
Beispiel #4
0
 def test_creates_physical_block_device_invalid_numa_node(self):
     node = factory.make_Node()
     name = factory.make_name("sd")
     id_path = factory.make_absolute_path()
     size = random.randint(MIN_BLOCK_DEVICE_SIZE,
                           MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = CreatePhysicalBlockDeviceForm(
         node,
         data={
             "name": name,
             "id_path": id_path,
             "size": size,
             "block_size": block_size,
             "numa_node": 4,
         },
     )
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual({"numa_node": ["Invalid NUMA node"]}, form.errors)
Beispiel #5
0
    def create(self, request, system_id):
        """Create a physical block device.

        :param name: Name of the block device.
        :param model: Model of the block device.
        :param serial: Serial number of the block device.
        :param id_path: (optional) Only used if model and serial cannot be
            provided. This should be a path that is fixed and doesn't change
            depending on the boot order or kernel version.
        :param size: Size of the block device.
        :param block_size: Block size of the block device.

        Returns 404 if the node is not found.
        """
        machine = Machine.objects.get_node_or_404(system_id, request.user,
                                                  NODE_PERMISSION.ADMIN)
        form = CreatePhysicalBlockDeviceForm(machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #6
0
 def test_creates_physical_block_device_with_id_path(self):
     node = factory.make_Node()
     name = factory.make_name("sd")
     id_path = factory.make_absolute_path()
     size = random.randint(
         MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = CreatePhysicalBlockDeviceForm(node, data={
         'name': name,
         '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,
         id_path=id_path,
         size=size,
         block_size=block_size,
         ))
Beispiel #7
0
    def create(self, request, system_id):
        """@description-title Create a block device
        @description Create a physical block device.

        @param (string) "{system_id}" [required=true] The machine system_id.

        @param (string) "name" [required=true] Name of the block device.

        @param (string) "model" [required=false] Model of the block device.

        @param (string) "serial" [required=false] Serial number of the block
        device.

        @param (string) "id_path" [required=false] Only used if model and
        serial cannot be provided. This should be a path that is fixed and
        doesn't change depending on the boot order or kernel version.

        @param (string) "size" [required=true] Size of the block device.

        @param (string) "block_size" [required=true] Block size of the block
        device.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the new block
        device.
        @success-example "success-json" [exkey=block-devs-create] placeholder
        text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested machine is not found.
        @error-example "not-found"
            Not Found
        """
        machine = Machine.objects.get_node_or_404(system_id, request.user,
                                                  NodePermission.admin)
        form = CreatePhysicalBlockDeviceForm(machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)