def test_updates_uuid(self): vmfs = factory.make_VMFS() new_uuid = str(uuid.uuid4()) form = UpdateVMFSForm(vmfs, data={'uuid': new_uuid}) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertEqual(new_uuid, vmfs.uuid)
def test_updates_name(self): vmfs = factory.make_VMFS() name = factory.make_name('name') form = UpdateVMFSForm(vmfs, data={'name': name}) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertEqual(name, vmfs.name)
def test_is_not_valid_if_invalid_uuid(self): vmfs = factory.make_VMFS() form = UpdateVMFSForm(vmfs, data={'uuid': factory.make_string(32)}) self.assertFalse( form.is_valid(), 'Should be invalid because of an invalid uuid.') self.assertEqual({'uuid': ['Enter a valid value.']}, form._errors)
def update_vmfs_datastore(self, params): """Add or remove block devices or partitions from a datastore.""" vmfs = self._get_vmfs_datastore(params) form = UpdateVMFSForm(vmfs, data=params) if not form.is_valid(): raise HandlerError(form.errors) else: form.save()
def test_adds_block_device_by_name(self): node = make_Node_with_VMFS6_layout() vmfs = factory.make_VMFS(node=node) block_device = factory.make_PhysicalBlockDevice(node=node) data = {"add_block_devices": [block_device.name]} form = UpdateVMFSForm(vmfs, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() part = block_device.get_partitiontable().partitions.first() self.assertEqual(vmfs.id, part.get_effective_filesystem().filesystem_group_id)
def test_adds_partition(self): node = make_Node_with_VMFS6_layout() vmfs = factory.make_VMFS(node=node) block_device = factory.make_PhysicalBlockDevice(node=node) partition_table = factory.make_PartitionTable( block_device=block_device) partition = factory.make_Partition(partition_table=partition_table) data = {"add_partitions": [partition.id]} form = UpdateVMFSForm(vmfs, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertEqual( vmfs.id, partition.get_effective_filesystem().filesystem_group.id)
def update(self, request, system_id, id): """@description-title Update a VMFS datastore. @description Update a VMFS datastore with the given id on the machine with the given system_id. @param (string) "{system_id}" [required=true] The machine system_id containing the VMFS datastore. @param (int) "{id}" [required=true] The id of the VMFS datastore. @param (string) "name" [required=false] Name of the VMFS datastore. @param (string) "uuid" [required=false] UUID of the VMFS datastore. @param (string) "add_block_devices" [required=false] Block devices to add to the VMFS datastore. @param (string) "add_partitions" [required=false] Partitions to add to the VMFS datastore. @param (string) "remove_partitions" [required=false] Partitions to remove from the VMFS datastore. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing the requested VMFS datastore. @success-example "success-json" [exkey=vmfs-datastore-update] 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. """ vmfs = VMFS.objects.get_object_or_404( system_id, id, request.user, NodePermission.admin ) node = vmfs.get_node() if node.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot update the VMFS datastore because the machine is not " "Ready." ) form = UpdateVMFSForm(vmfs, data=request.data) if not form.is_valid(): raise MAASAPIValidationError(form.errors) else: return form.save()
def test_removes_partition_by_name(self): node = make_Node_with_VMFS6_layout() vmfs = factory.make_VMFS(node=node) block_device = factory.make_PhysicalBlockDevice(node=node) partition_table = factory.make_PartitionTable( block_device=block_device) partition = factory.make_Partition(partition_table=partition_table) factory.make_Filesystem( fstype=FILESYSTEM_TYPE.LVM_PV, partition=partition, filesystem_group=vmfs) data = { 'remove_partitions': [partition.name], } form = UpdateVMFSForm(vmfs, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertIsNone(partition.get_effective_filesystem())
def test_requires_no_fields(self): vmfs = factory.make_VMFS() form = UpdateVMFSForm(vmfs, data={}) self.assertTrue(form.is_valid(), form.errors)