Exemplo n.º 1
0
    def test_GET(self):
        node = factory.make_Machine()
        vmfs_datastores = [factory.make_VMFS(node=node) for _ in range(3)]
        # VMFS datastores not assoicated with the node, should not be seen.
        for _ in range(3):
            factory.make_VMFS()

        response = self.client.get(self.get_vmfs_uri(node))
        self.assertThat(response, HasStatusCode(http.client.OK))
        parsed_results = json_load_bytes(response.content)
        self.assertItemsEqual([vmfs.id for vmfs in vmfs_datastores],
                              [result['id'] for result in parsed_results])
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 def test_DELETE(self):
     self.become_admin()
     node = factory.make_Machine(status=NODE_STATUS.READY)
     vmfs = factory.make_VMFS(node=node)
     response = self.client.delete(self.get_vmfs_uri(vmfs))
     self.assertThat(response, HasStatusCode(http.client.NO_CONTENT))
     self.assertIsNone(reload_object(vmfs))
Exemplo n.º 6
0
    def test_PUT(self):
        self.become_admin()
        node = factory.make_Machine(status=NODE_STATUS.READY)
        vmfs = factory.make_VMFS(node=node)
        new_name = factory.make_name('name')
        new_uuid = str(uuid.uuid4())
        new_bd = factory.make_PhysicalBlockDevice(node=node)
        new_partition = factory.make_Partition(node=node)
        del_partition = random.choice(vmfs.filesystems.all()).get_parent()
        partition_ids = set(
            [fs.get_parent().id for fs in vmfs.filesystems.all()])
        partition_ids.add(new_partition.id)
        partition_ids.remove(del_partition.id)

        response = self.client.put(
            self.get_vmfs_uri(vmfs), {
                'name':
                new_name,
                'uuid':
                new_uuid,
                'add_block_devices': [random.choice([new_bd.id, new_bd.name])],
                'add_partitions':
                [random.choice([new_partition.id, new_partition.name])],
                'remove_partitions':
                [random.choice([del_partition.id, del_partition.name])],
            })
        self.assertThat(response, HasStatusCode(http.client.OK))
        vmfs = reload_object(vmfs)
        partition_ids.add(new_bd.get_partitiontable().partitions.first().id)

        self.assertEquals(new_name, vmfs.name)
        self.assertEquals(new_uuid, vmfs.uuid)
        self.assertItemsEqual(
            partition_ids,
            [fs.get_parent().id for fs in vmfs.filesystems.all()])
Exemplo n.º 7
0
 def test_handler_path(self):
     node = factory.make_Machine()
     vmfs = factory.make_VMFS(node=node)
     self.assertEquals(
         "/MAAS/api/2.0/nodes/%s/vmfs-datastore/%s/" %
         (node.system_id, vmfs.id),
         self.get_vmfs_uri(vmfs),
     )
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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())
Exemplo n.º 11
0
 def test_requires_no_fields(self):
     vmfs = factory.make_VMFS()
     form = UpdateVMFSForm(vmfs, data={})
     self.assertTrue(form.is_valid(), form.errors)
Exemplo n.º 12
0
 def test_DELETE_409_when_not_ready(self):
     self.become_admin()
     node = factory.make_Machine(status=NODE_STATUS.ALLOCATED)
     vmfs = factory.make_VMFS(node=node)
     response = self.client.delete(self.get_vmfs_uri(vmfs))
     self.assertThat(response, HasStatusCode(http.client.CONFLICT))
Exemplo n.º 13
0
 def test_DELETE_403_when_not_admin(self):
     node = factory.make_Machine(status=NODE_STATUS.READY)
     vmfs = factory.make_VMFS(node=node)
     response = self.client.delete(self.get_vmfs_uri(vmfs))
     self.assertThat(response, HasStatusCode(http.client.FORBIDDEN))
Exemplo n.º 14
0
 def test_vmfs(self):
     vmfs = factory.make_VMFS()
     part = vmfs.filesystems.first().partition
     self.assertEqual("VMFS extent for %s" % vmfs.name, used_for(part))