Exemplo n.º 1
0
 def test_cannot_save_filesystem_if_too_much_storage(self):
     substrate_factories = {
         "block_device": factory.make_BlockDevice,
         "partition": factory.make_Partition,
         "node": factory.make_Node,
     }
     substrate_combos = chain(
         combinations(substrate_factories, 2),
         combinations(substrate_factories, 3),
     )
     for substrates in substrate_combos:
         fs = Filesystem(
             **{
                 substrate: substrate_factories[substrate]()
                 for substrate in substrates
             }
         )
         error = self.assertRaises(ValidationError, fs.save)
         self.expectThat(
             error.messages,
             Equals(
                 [
                     "Only one of partition, block device, "
                     "or node can be specified."
                 ]
             ),
             "using " + ", ".join(substrates),
         )
Exemplo n.º 2
0
 def test_cannot_save_storage_backed_filesystem_if_storage_missing(self):
     fs = Filesystem()
     error = self.assertRaises(ValidationError, fs.save)
     self.assertThat(
         error.messages,
         Equals(["One of partition or block device must be specified."]),
     )
Exemplo n.º 3
0
 def test_cannot_save_host_backed_filesystem_if_node_missing(self):
     for fstype in Filesystem.TYPES - Filesystem.TYPES_REQUIRING_STORAGE:
         fs = Filesystem(fstype=fstype)
         error = self.assertRaises(ValidationError, fs.save)
         self.expectThat(error.messages,
                         Equals([
                             "A node must be specified.",
                         ]), "using " + fstype)
Exemplo n.º 4
0
    def create_bcache(
            self, cache_set, name=None, uuid=None,
            backing_device=None, backing_partition=None, cache_mode=None):
        """Creates a bcache of type `cache_type` using the desired cache and
        backing elements."""

        self.validate_bcache_creation_parameters(
            cache_set, cache_mode, backing_device, backing_partition)

        # Avoid circular import issues
        from maasserver.models.filesystem import Filesystem
        if backing_device is not None:
            backing_filesystem = Filesystem(
                block_device=backing_device,
                fstype=FILESYSTEM_TYPE.BCACHE_BACKING)
        elif backing_partition is not None:
            backing_filesystem = Filesystem(
                partition=backing_partition,
                fstype=FILESYSTEM_TYPE.BCACHE_BACKING)

        # Setup the cache FilesystemGroup and attach the filesystems to it.
        bcache_filesystem_group = FilesystemGroup.objects.create(
            name=name,
            uuid=uuid,
            group_type=FILESYSTEM_GROUP_TYPE.BCACHE,
            cache_mode=cache_mode,
            cache_set=cache_set)
        backing_filesystem.filesystem_group = bcache_filesystem_group
        backing_filesystem.save()
        bcache_filesystem_group.save()
        return bcache_filesystem_group
Exemplo n.º 5
0
 def test_get_block_size_returns_0_when_partition_and_device_None(self):
     fs = Filesystem()
     self.assertEqual(0, fs.get_block_size())
Exemplo n.º 6
0
 def test_get_node_returns_None_when_no_substrate(self):
     fs = Filesystem()
     self.assertIsNone(fs.get_node())