~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/tests/compute/virt/libvirt/test_inspector.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-02-19 14:59:07 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20150219145907-9jojybdsl64zcn14
Tags: 2015.1~b2-0ubuntu1
[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/p/skip-test.patch: Rebased.

[ James Page ]
* d/rules,d/p/skip-gabbi.patch: Skip tests that rely on python-gabbi until
  packaging and MIR is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Copyright 2012 Red Hat, Inc
4
4
#
5
 
# Author: Eoghan Glynn <eglynn@redhat.com>
6
 
#
7
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
6
# not use this file except in compliance with the License. You may obtain
9
7
# a copy of the License at
22
20
 
23
21
import fixtures
24
22
import mock
25
 
from oslo.utils import units
 
23
from oslo_utils import units
26
24
from oslotest import base
27
25
 
28
26
from ceilometer.compute.virt import inspector as virt_inspector
34
32
    def setUp(self):
35
33
        super(TestLibvirtInspection, self).setUp()
36
34
 
37
 
        class VMInstance:
 
35
        class VMInstance(object):
38
36
            id = 'ff58e738-12f4-4c58-acde-77617b68da56'
39
37
            name = 'instance-00000001'
40
38
        self.instance = VMInstance
45
43
        self.domain = mock.Mock()
46
44
        self.addCleanup(mock.patch.stopall)
47
45
 
48
 
    def test_inspect_instances(self):
49
 
        class FakeDomain(object):
50
 
            def name(self):
51
 
                return 'fake_name'
52
 
 
53
 
            def UUIDString(self):
54
 
                return 'uuid'
55
 
 
56
 
        fake_domain = FakeDomain()
57
 
        connection = self.inspector.connection
58
 
        with contextlib.nested(mock.patch.object(connection, 'numOfDomains',
59
 
                                                 return_value=1),
60
 
                               mock.patch.object(connection, 'listDomainsID',
61
 
                                                 return_value=[42]),
62
 
                               mock.patch.object(connection, 'lookupByID',
63
 
                                                 return_value=fake_domain)):
64
 
            inspected_instances = list(self.inspector.inspect_instances())
65
 
            self.assertEqual(1, len(inspected_instances))
66
 
            inspected_instance = inspected_instances[0]
67
 
            self.assertEqual('fake_name', inspected_instance.name)
68
 
            self.assertEqual('uuid', inspected_instance.UUID)
69
 
 
70
46
    def test_inspect_cpus(self):
71
47
        with contextlib.nested(mock.patch.object(self.inspector.connection,
72
48
                                                 'lookupByUUIDString',
202
178
                               mock.patch.object(self.domain, 'info',
203
179
                                                 return_value=(5L, 0L, 0L,
204
180
                                                               2L, 999999L))):
205
 
            interfaces = list(self.inspector.inspect_vnics(self.instance))
206
 
            self.assertEqual([], interfaces)
 
181
            inspect = self.inspector.inspect_vnics
 
182
            self.assertRaises(virt_inspector.InstanceShutOffException,
 
183
                              list, inspect(self.instance))
207
184
 
208
185
    def test_inspect_disks(self):
209
186
        dom_xml = """
250
227
                               mock.patch.object(self.domain, 'info',
251
228
                                                 return_value=(5L, 0L, 0L,
252
229
                                                               2L, 999999L))):
253
 
            disks = list(self.inspector.inspect_disks(self.instance))
254
 
            self.assertEqual([], disks)
 
230
            inspect = self.inspector.inspect_disks
 
231
            self.assertRaises(virt_inspector.InstanceShutOffException,
 
232
                              list, inspect(self.instance))
255
233
 
256
234
    def test_inspect_memory_usage(self):
257
235
        fake_memory_stats = {'available': 51200L, 'unused': 25600L}
274
252
            with mock.patch.object(self.domain, 'info',
275
253
                                   return_value=(5L, 0L, 0L,
276
254
                                                 2L, 999999L)):
277
 
                memory = self.inspector.inspect_memory_usage(
278
 
                    self.instance)
279
 
                self.assertIsNone(memory)
 
255
                self.assertRaises(virt_inspector.InstanceShutOffException,
 
256
                                  self.inspector.inspect_memory_usage,
 
257
                                  self.instance)
280
258
 
281
259
    def test_inspect_memory_usage_with_empty_stats(self):
282
260
        connection = self.inspector.connection
287
265
                                                 2L, 999999L)):
288
266
                with mock.patch.object(self.domain, 'memoryStats',
289
267
                                       return_value={}):
290
 
                    memory = self.inspector.inspect_memory_usage(
291
 
                        self.instance)
292
 
                    self.assertIsNone(memory)
 
268
                    self.assertRaises(virt_inspector.NoDataException,
 
269
                                      self.inspector.inspect_memory_usage,
 
270
                                      self.instance)
293
271
 
294
272
 
295
273
class TestLibvirtInspectionWithError(base.BaseTestCase):
307
285
        libvirt_inspector.libvirt = mock.Mock()
308
286
        libvirt_inspector.libvirt.libvirtError = self.fakeLibvirtError
309
287
 
 
288
    @staticmethod
310
289
    def _dummy_get_connection(*args, **kwargs):
311
290
        raise Exception('dummy')
312
291