Example #1
0
 def test_total_size_of_iscsi_devices_for_returns_sum_of_size(self):
     node = factory.make_Node(with_boot_disk=False)
     sizes = [
         random.randint(MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE * 2)
         for _ in range(3)
         ]
     for size in sizes:
         factory.make_ISCSIBlockDevice(node=node, size=size)
     self.assertEqual(
         sum(sizes),
         ISCSIBlockDevice.objects.total_size_of_iscsi_devices_for(
             node))
Example #2
0
 def test_type_iscsi(self):
     block_device = factory.make_ISCSIBlockDevice()
     self.assertEqual("iscsi", block_device.type)
Example #3
0
 def test_actual_instance_returns_ISCSIBlockDevice(self):
     block_device = factory.make_ISCSIBlockDevice()
     parent_type = BlockDevice.objects.get(id=block_device.id)
     self.assertIsInstance(parent_type.actual_instance, ISCSIBlockDevice)
Example #4
0
    def test_read(self):
        node = factory.make_Node(with_boot_disk=False)

        # Add three physical block devices
        physical_block_devices = [
            factory.make_PhysicalBlockDevice(node=node, size=10 * 1000**3)
            for _ in range(3)
        ]

        # Partition and add a LVM_PV filesystem to the last two physical block
        # devices. Leave the first partition alone.
        lvm_pv_filesystems = [
            factory.make_Filesystem(block_device=device,
                                    fstype=FILESYSTEM_TYPE.LVM_PV)
            for device in physical_block_devices[1:]
        ]

        # Make a filesystem_group (analogous to a volume group) on top of our
        # two lvm-pm filesystems.
        filesystem_group = factory.make_FilesystemGroup(
            group_type=FILESYSTEM_GROUP_TYPE.LVM_VG,
            filesystems=lvm_pv_filesystems)

        # Make a VirtualBlockDevice on top of the filesystem group we just
        # made.
        virtual_block_device = factory.make_VirtualBlockDevice(
            filesystem_group=filesystem_group, size=10 * 1000**3)

        # Add some iSCSI block devices.
        iscsi_block_devices = [
            factory.make_ISCSIBlockDevice(node=node, size=10 * 1000**3)
            for _ in range(3)
        ]

        uri = get_blockdevices_uri(node)
        response = self.client.get(uri)

        self.assertEqual(http.client.OK, response.status_code,
                         response.content)

        devices = json_load_bytes(response.content)

        # We should have seven devices, three physical, one virtual, and
        # three iscsi.
        self.assertEqual(len(devices), 7)
        self.assertEqual(len([d for d in devices if d['type'] == 'physical']),
                         3)
        self.assertEqual(len([d for d in devices if d['type'] == 'virtual']),
                         1)
        self.assertEqual(len([d for d in devices if d['type'] == 'iscsi']), 3)

        # The IDs we expect and the IDs we got through the API should match.
        expected_device_ids = [
            d.id for d in (physical_block_devices + [virtual_block_device] +
                           iscsi_block_devices)
        ]
        result_device_ids = [d["id"] for d in devices]
        self.assertItemsEqual(expected_device_ids, result_device_ids)
        # Validate that every one has a resource_uri.
        for d in devices:
            self.expectThat(
                d, Contains("resource_uri"),
                "Device(%s:%s) is missing a resource_uri." %
                (d['type'], d['id']))