Example #1
0
class TestDiskInfoPollsters(TestBaseDiskIO):

    DISKS = [
        virt_inspector.DiskInfo(device="vda1",
                                capacity=3,
                                allocation=2,
                                physical=1),
        virt_inspector.DiskInfo(device="vda2",
                                capacity=4,
                                allocation=3,
                                physical=2),
    ]
    TYPE = 'gauge'

    def setUp(self):
        super(TestDiskInfoPollsters, self).setUp()
        self.inspector.inspect_disk_info = mock.Mock(return_value=self.DISKS)

    def test_per_disk_capacity(self):
        self._check_per_device_samples(disk.PerDeviceCapacityPollster,
                                       'disk.device.capacity', 3, 'vda1')
        self._check_per_device_samples(disk.PerDeviceCapacityPollster,
                                       'disk.device.capacity', 4, 'vda2')

    def test_per_disk_allocation(self):
        self._check_per_device_samples(disk.PerDeviceAllocationPollster,
                                       'disk.device.allocation', 2, 'vda1')
        self._check_per_device_samples(disk.PerDeviceAllocationPollster,
                                       'disk.device.allocation', 3, 'vda2')

    def test_per_disk_physical(self):
        self._check_per_device_samples(disk.PerDevicePhysicalPollster,
                                       'disk.device.usage', 1, 'vda1')
        self._check_per_device_samples(disk.PerDevicePhysicalPollster,
                                       'disk.device.usage', 2, 'vda2')
Example #2
0
class TestDiskInfoPollsters(TestBaseDiskIO):

    DISKS = [
        (virt_inspector.Disk(device='vda1'),
         virt_inspector.DiskInfo(capacity=3L, allocation=2L, physical=1L)),
        (virt_inspector.Disk(device='vda2'),
         virt_inspector.DiskInfo(capacity=4L, allocation=3L, physical=2L)),
    ]
    TYPE = 'gauge'
    CACHE_KEY = "CACHE_KEY_DISK_INFO"

    def setUp(self):
        super(TestDiskInfoPollsters, self).setUp()
        self.inspector.inspect_disk_info = mock.Mock(return_value=self.DISKS)

    def test_disk_capacity(self):
        self._check_aggregate_samples(disk.CapacityPollster,
                                      'disk.capacity', 7L,
                                      expected_device=['vda1', 'vda2'])

    def test_disk_allocation(self):
        self._check_aggregate_samples(disk.AllocationPollster,
                                      'disk.allocation', 5L,
                                      expected_device=['vda1', 'vda2'])

    def test_disk_physical(self):
        self._check_aggregate_samples(disk.PhysicalPollster,
                                      'disk.usage', 3L,
                                      expected_device=['vda1', 'vda2'])

    def test_per_disk_capacity(self):
        self._check_per_device_samples(disk.PerDeviceCapacityPollster,
                                       'disk.device.capacity', 3L,
                                       'vda1')
        self._check_per_device_samples(disk.PerDeviceCapacityPollster,
                                       'disk.device.capacity', 4L,
                                       'vda2')

    def test_per_disk_allocation(self):
        self._check_per_device_samples(disk.PerDeviceAllocationPollster,
                                       'disk.device.allocation', 2L,
                                       'vda1')
        self._check_per_device_samples(disk.PerDeviceAllocationPollster,
                                       'disk.device.allocation', 3L,
                                       'vda2')

    def test_per_disk_physical(self):
        self._check_per_device_samples(disk.PerDevicePhysicalPollster,
                                       'disk.device.usage', 1L,
                                       'vda1')
        self._check_per_device_samples(disk.PerDevicePhysicalPollster,
                                       'disk.device.usage', 2L,
                                       'vda2')
Example #3
0
 def inspect_disk_info(self, instance):
     domain = self._get_domain_not_shut_off_or_raise(instance)
     tree = etree.fromstring(domain.XMLDesc(0))
     for disk in tree.findall('devices/disk'):
         disk_type = disk.get('type')
         if disk_type:
             if disk_type == 'network':
                 LOG.warning(
                     _LW('Inspection disk usage of network disk '
                         '%(instance_uuid)s unsupported by libvirt') %
                     {'instance_uuid': instance.id})
                 continue
             # NOTE(lhx): "cdrom" device associated to the configdrive
             # no longer has a "source" element. Releated bug:
             # https://bugs.launchpad.net/ceilometer/+bug/1622718
             if disk.find('source') is None:
                 continue
             target = disk.find('target')
             device = target.get('dev')
             if device:
                 dsk = virt_inspector.Disk(device=device)
                 block_info = domain.blockInfo(device)
                 info = virt_inspector.DiskInfo(capacity=block_info[0],
                                                allocation=block_info[1],
                                                physical=block_info[2])
                 yield (dsk, info)
Example #4
0
 def inspect_disk_info(self, instance, duration):
     domain = self._get_domain_not_shut_off_or_raise(instance)
     for device in self._get_disk_devices(domain):
         block_info = domain.blockInfo(device)
         yield virt_inspector.DiskInfo(device=device,
                                       capacity=block_info[0],
                                       allocation=block_info[1],
                                       physical=block_info[2])
Example #5
0
 def inspect_disk_info(self, instance, duration):
     domain = self._get_domain_not_shut_off_or_raise(instance)
     for device in self._get_disk_devices(domain):
         block_info = domain.blockInfo(device)
         # if vm mount cdrom, libvirt will align by 4K bytes, capacity may
         # be smaller than physical, avoid with this.
         # https://libvirt.org/html/libvirt-libvirt-domain.html
         disk_capacity = max(block_info[0], block_info[2])
         yield virt_inspector.DiskInfo(device=device,
                                       capacity=disk_capacity,
                                       allocation=block_info[1],
                                       physical=block_info[2])
Example #6
0
    def inspect_disk_info(self, instance):
        domain = self._get_domain_not_shut_off_or_raise(instance)

        tree = etree.fromstring(domain.XMLDesc(0))
        for device in filter(bool, [
                target.get("dev")
                for target in tree.findall('devices/disk/target')
        ]):
            disk = virt_inspector.Disk(device=device)
            block_info = domain.blockInfo(device)
            info = virt_inspector.DiskInfo(capacity=block_info[0],
                                           allocation=block_info[1],
                                           physical=block_info[2])

            yield (disk, info)
 def inspect_disk_info(self, instance, duration):
     domain = self._get_domain_not_shut_off_or_raise(instance)
     tree = etree.fromstring(domain.XMLDesc(0))
     for disk in tree.findall('devices/disk'):
         # NOTE(lhx): "cdrom" device associated to the configdrive
         # no longer has a "source" element. Releated bug:
         # https://bugs.launchpad.net/ceilometer/+bug/1622718
         if disk.find('source') is None:
             continue
         target = disk.find('target')
         device = target.get('dev')
         if device:
             block_info = domain.blockInfo(device)
             yield virt_inspector.DiskInfo(device=device,
                                           capacity=block_info[0],
                                           allocation=block_info[1],
                                           physical=block_info[2])
Example #8
0
 def inspect_disk_info(self, instance):
     domain = self._get_domain_not_shut_off_or_raise(instance)
     tree = etree.fromstring(domain.XMLDesc(0))
     for disk in tree.findall('devices/disk'):
         disk_type = disk.get('type')
         if disk_type:
             if disk_type == 'network':
                 LOG.warning(
                     _LW('Inspection disk usage of network disk '
                         '%(instance_uuid)s unsupported by libvirt') %
                     {'instance_uuid': instance.id})
                 continue
             target = disk.find('target')
             device = target.get('dev')
             if device:
                 dsk = virt_inspector.Disk(device=device)
                 block_info = domain.blockInfo(device)
                 info = virt_inspector.DiskInfo(capacity=block_info[0],
                                                allocation=block_info[1],
                                                physical=block_info[2])
                 yield (dsk, info)