Beispiel #1
0
    def test_get_samples(self):
        next_value = iter((
            virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=90112),
            virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=180224),
        ))

        def inspect_cpu_l3_cache(name):
            return next(next_value)

        self.inspector.inspect_cpu_l3_cache = (mock.Mock(
            side_effect=inspect_cpu_l3_cache))

        mgr = manager.AgentManager(0, self.CONF)
        pollster = cpu.CPUL3CachePollster(self.CONF)

        def _verify_cpu_l3_cache_metering(expected_usage):
            cache = {}
            samples = list(pollster.get_samples(mgr, cache, [self.instance]))
            self.assertEqual(1, len(samples))
            self.assertEqual(set(['cpu_l3_cache']),
                             set([s.name for s in samples]))
            self.assertEqual(expected_usage, samples[0].volume)

        _verify_cpu_l3_cache_metering(90112)
        _verify_cpu_l3_cache_metering(180224)
Beispiel #2
0
 def inspect_cpu_l3_cache(self, instance):
     domain = self._lookup_by_uuid(instance)
     try:
         stats = self.connection.domainListGetStats(
             [domain], libvirt.VIR_DOMAIN_STATS_PERF)
         perf = stats[0][1]
         usage = perf["perf.cmt"]
         return virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=usage)
     except (KeyError, AttributeError) as e:
         # NOTE(sileht): KeyError if for libvirt >=2.0.0,<2.3.0, the perf
         # subsystem ws existing but not  these attributes
         # https://github.com/libvirt/libvirt/commit/bae660869de0612bee2a740083fb494c27e3f80c
         msg = _('Perf is not supported by current version of libvirt, and '
                 'failed to inspect l3 cache usage of %(instance_uuid)s, '
                 'can not get info from libvirt: %(error)s') % {
                     'instance_uuid': instance.id,
                     'error': e
                 }
         raise virt_inspector.NoDataException(msg)
     # domainListGetStats might launch an exception if the method or
     # cmt perf event is not supported by the underlying hypervisor
     # being used by libvirt.
     except libvirt.libvirtError as e:
         msg = _('Failed to inspect l3 cache usage of %(instance_uuid)s, '
                 'can not get info from libvirt: %(error)s') % {
                     'instance_uuid': instance.id,
                     'error': e
                 }
         raise virt_inspector.NoDataException(msg)
Beispiel #3
0
 def inspect_cpu_l3_cache(self, instance):
     domain = self._lookup_by_uuid(instance)
     try:
         stats = self.connection.domainListGetStats(
             [domain], libvirt.VIR_DOMAIN_STATS_PERF)
         perf = stats[0][1]
         usage = perf["perf.cmt"]
         return virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=usage)
     except AttributeError as e:
         msg = _('Perf is not supported by current version of libvirt, and '
                 'failed to inspect l3 cache usage of %(instance_uuid)s, '
                 'can not get info from libvirt: %(error)s') % {
                     'instance_uuid': instance.id,
                     'error': e
                 }
         raise virt_inspector.NoDataException(msg)
     # domainListGetStats might launch an exception if the method or
     # cmt perf event is not supported by the underlying hypervisor
     # being used by libvirt.
     except libvirt.libvirtError as e:
         msg = _('Failed to inspect l3 cache usage of %(instance_uuid)s, '
                 'can not get info from libvirt: %(error)s') % {
                     'instance_uuid': instance.id,
                     'error': e
                 }
         raise virt_inspector.NoDataException(msg)