Esempio n. 1
0
    def test_mount_sets_mount_path_and_params_on_filesystem_as_admin(self):
        self.become_admin()
        node = factory.make_Node(status=NODE_STATUS.READY)
        block_device = factory.make_VirtualBlockDevice(node=node)
        filesystem = factory.make_Filesystem(block_device=block_device)
        mount_point = factory.make_absolute_path()
        mount_options = factory.make_name("mount-options")
        uri = get_blockdevice_uri(block_device)
        response = self.client.post(
            uri, {
                'op': 'mount',
                'mount_point': mount_point,
                'mount_options': mount_options
            })

        self.assertEqual(http.client.OK, response.status_code,
                         response.content)
        parsed_device = json_load_bytes(response.content)
        self.assertThat(
            parsed_device["filesystem"],
            ContainsDict({
                "mount_point": Equals(mount_point),
                "mount_options": Equals(mount_options),
            }))
        self.assertThat(
            reload_object(filesystem),
            MatchesStructure(
                mount_point=Equals(mount_point),
                mount_options=Equals(mount_options),
                is_mounted=Is(True),
            ))
Esempio n. 2
0
 def test_updates_deployed_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()
     form = UpdateDeployedPhysicalBlockDeviceForm(
         instance=block_device,
         data={
             "name": name,
             "model": model,
             "serial": serial,
             "id_path": id_path,
         },
     )
     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=block_device.size,
             block_size=block_device.block_size,
         ),
     )
Esempio n. 3
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,
         ),
     )
Esempio n. 4
0
 def test_creates_filesystem_with_mount_point_and_options(self):
     owner = None
     if self.acquired:
         owner = factory.make_User()
     node = factory.make_Node(owner=owner)
     mount_point = factory.make_absolute_path()
     mount_options = factory.make_name("options")
     form = MountNonStorageFilesystemForm(
         node,
         data={
             "fstype": self.fstype,
             "mount_point": mount_point,
             # Whitespace is stripped by form validation.
             'mount_options': "  " + mount_options + "\t\n",
         })
     self.assertTrue(form.is_valid(), form.errors)
     filesystem = form.save()
     self.assertThat(
         filesystem,
         MatchesStructure.byEquality(node=node,
                                     fstype=self.fstype,
                                     mount_point=mount_point,
                                     mount_options=mount_options,
                                     is_mounted=True,
                                     acquired=self.acquired))
Esempio n. 5
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,
         ))
Esempio n. 6
0
    def test_mount_sets_mount_path_and_params_on_filesystem_as_user(self):
        node = factory.make_Node(status=NODE_STATUS.ALLOCATED, owner=self.user)
        block_device = factory.make_VirtualBlockDevice(node=node)
        filesystem = factory.make_Filesystem(block_device=block_device,
                                             acquired=True)
        mount_point = factory.make_absolute_path()
        mount_options = factory.make_name("mount-options")
        uri = get_blockdevice_uri(block_device)
        response = self.client.post(
            uri,
            {
                "op": "mount",
                "mount_point": mount_point,
                "mount_options": mount_options,
            },
        )

        self.assertEqual(http.client.OK, response.status_code,
                         response.content)
        parsed_device = json_load_bytes(response.content)
        self.assertThat(
            parsed_device["filesystem"],
            ContainsDict({
                "mount_point": Equals(mount_point),
                "mount_options": Equals(mount_options),
            }),
        )
        self.assertThat(
            reload_object(filesystem),
            MatchesStructure(
                mount_point=Equals(mount_point),
                mount_options=Equals(mount_options),
                is_mounted=Is(True),
            ),
        )
Esempio n. 7
0
 def test_is_not_valid_if_invalid_absolute_path(self):
     substrate = self.make_substrate()
     filesystem = factory.make_Filesystem(fstype=FILESYSTEM_TYPE.EXT4,
                                          **substrate)
     data = {'mount_point': factory.make_absolute_path()[1:]}
     form = MountFilesystemForm(filesystem, data=data)
     self.assertFalse(
         form.is_valid(),
         "Should be invalid because it's not an absolute path.")
     self.assertEqual({'mount_point': ["Enter a valid value."]},
                      form._errors)
Esempio n. 8
0
 def test_unmounts_filesystem_with_mount_point(self):
     node = factory.make_Node()
     mount_point = factory.make_absolute_path()
     mount_options = factory.make_name("options")
     filesystem = factory.make_Filesystem(node=node,
                                          mount_point=mount_point,
                                          mount_options=mount_options)
     form = UnmountNonStorageFilesystemForm(
         node, data={"mount_point": mount_point})
     self.assertTrue(form.is_valid(), form.errors)
     form.save()
     self.assertThat(reload_object(filesystem), Is(None))
Esempio n. 9
0
 def test_is_not_valid_if_there_is_no_filesystem(self):
     data = {'mount_point': factory.make_absolute_path()}
     form = MountFilesystemForm(None, data=data)
     self.assertFalse(
         form.is_valid(), "Should be invalid because block device does "
         "not have a filesystem.")
     self.assertEqual(
         {
             '__all__': [
                 "Cannot mount an unformatted partition or block device.",
             ]
         }, form._errors)
Esempio n. 10
0
 def test_will_not_unmount_filesystem_on_partition(self):
     node = factory.make_Node()
     partition = factory.make_Partition(node=node)
     filesystem = factory.make_Filesystem(
         mount_point=factory.make_absolute_path(), partition=partition)
     form = UnmountNonStorageFilesystemForm(
         node, data={"mount_point": filesystem.mount_point})
     self.assertFalse(form.is_valid())
     self.assertThat(
         form.errors,
         Equals({
             "mount_point":
             ["No special filesystem is mounted at this path."]
         }),
     )
Esempio n. 11
0
 def test_is_not_valid_if_invalid_absolute_path_too_long(self):
     substrate = self.make_substrate()
     filesystem = factory.make_Filesystem(fstype=FILESYSTEM_TYPE.EXT4,
                                          **substrate)
     mount_point = factory.make_absolute_path(directory_length=4096)
     data = {'mount_point': mount_point}
     form = MountFilesystemForm(filesystem, data=data)
     self.assertFalse(
         form.is_valid(),
         "Should be invalid because its not an absolute path.")
     self.assertEqual(
         {
             'mount_point': [
                 "Ensure this value has at most 4095 characters "
                 "(it has %s)." % len(mount_point)
             ],
         }, form._errors)
Esempio n. 12
0
 def test_will_not_unmount_filesystem_on_block_device(self):
     node = factory.make_Node()
     block_device = factory.make_BlockDevice(node=node)
     filesystem = factory.make_Filesystem(
         mount_point=factory.make_absolute_path(),
         block_device=block_device)
     form = UnmountNonStorageFilesystemForm(
         node, data={"mount_point": filesystem.mount_point})
     self.assertFalse(form.is_valid())
     self.assertThat(
         form.errors,
         Equals({
             'mount_point': [
                 "No special filesystem is "
                 "mounted at this path.",
             ],
         }))
Esempio n. 13
0
 def test_sets_mount_point_and_options_on_filesystem(self):
     substrate = self.make_substrate()
     filesystem = factory.make_Filesystem(fstype=FILESYSTEM_TYPE.EXT4,
                                          **substrate)
     self.assertThat(filesystem.is_mounted, Is(False))
     mount_point = factory.make_absolute_path()
     mount_options = factory.make_name("options")
     data = {
         'mount_point': mount_point,
         # Whitespace is stripped by form validation.
         'mount_options': "  " + mount_options + "\t\n",
     }
     form = MountFilesystemForm(filesystem, data=data)
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     self.assertEqual(mount_point, filesystem.mount_point)
     self.assertEqual(mount_options, filesystem.mount_options)
     self.assertThat(filesystem.is_mounted, Is(True))
Esempio n. 14
0
 def test_is_not_valid_if_substrate_in_filesystem_group(self):
     substrate = self.make_substrate()
     filesystem = factory.make_Filesystem(fstype=FILESYSTEM_TYPE.LVM_PV,
                                          **substrate)
     factory.make_FilesystemGroup(group_type=FILESYSTEM_GROUP_TYPE.LVM_VG,
                                  filesystems=[filesystem])
     data = {'mount_point': factory.make_absolute_path()}
     form = MountFilesystemForm(filesystem, data=data)
     self.assertFalse(
         form.is_valid(),
         "Should be invalid because block device is in a filesystem group.")
     self.assertEqual(
         {
             '__all__': [
                 "Filesystem is part of a filesystem group, and cannot be "
                 "mounted.",
             ]
         }, form._errors)
Esempio n. 15
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)
Esempio n. 16
0
 def test_cannot_mount_two_filesystems_at_same_point(self):
     substrate = self.make_substrate()
     filesystem1 = factory.make_Filesystem(fstype=self.fstype, **substrate)
     filesystem2 = factory.make_Filesystem(node=filesystem1.get_node())
     mount_point = factory.make_absolute_path()
     filesystem1.mount_point = mount_point
     filesystem1.save()
     filesystem2.mount_point = mount_point
     # Filesystems that can be mounted at a directory complain when mounted
     # at the same directory as another filesystem.
     if filesystem1.uses_mount_point:
         error = self.assertRaises(ValidationError, filesystem2.save)
         self.assertThat(
             error.messages,
             Equals([
                 "Another filesystem is already mounted at %s." %
                 mount_point,
             ]))
     else:
         self.assertThat(filesystem2.save(), Is(None))
Esempio n. 17
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,
         ))