File: test_poe.py

package info (click to toggle)
prometheus-openstack-exporter 0.1.4-2.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: python: 766; sh: 77; makefile: 32
file content (63 lines) | stat: -rw-r--r-- 2,680 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest

import mock

import prometheus_openstack_exporter as poe


class TestPrometheusOpenstackExporter(unittest.TestCase):
    def test_data_gatherer_needed(self):
        self.assertTrue(
            poe.data_gatherer_needed(
                {'enabled_collectors':
                 ['cinder', 'neutron', 'nova', 'swift']}))
        self.assertTrue(
            poe.data_gatherer_needed(
                {'enabled_collectors':
                 ['cinder', 'neutron', 'nova', 'swift', 'swift-account-usage']}))
        self.assertFalse(
            poe.data_gatherer_needed(
                {'enabled_collectors':
                 ['swift-account-usage']}))
        self.assertFalse(
            poe.data_gatherer_needed(
                {'enabled_collectors':
                 ['swift', 'swift-account-usage']}))
        self.assertEqual(
            poe.data_gatherer_needed(
                {'enabled_collectors':
                 ['cinder', 'neutron', 'nova', 'swift']}),
            set(['cinder', 'nova', 'neutron']),
        )
        self.assertEqual(
            poe.data_gatherer_needed({}),
            set(['cinder', 'nova', 'neutron']),
        )

    @mock.patch('prometheus_openstack_exporter.config')
    def test_get_nova_info(self, config):
        config.return_value = {}
        prodstack = {'tenants': []}
        nova = mock.Mock()
        nova.aggregates = mock.MagicMock()
        nova.flavors = mock.MagicMock()
        nova.hypervisors = mock.MagicMock()
        nova.servers = mock.MagicMock()
        nova.servers.list = mock.MagicMock()
        nova.services = mock.MagicMock()

        data_gatherer = poe.DataGatherer()
        data_gatherer._get_nova_info(nova, None, prodstack)

        expected = [
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'ACTIVE', 'all_tenants': '1'}),
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'ERROR', 'all_tenants': '1'}),
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'SHELVED_OFFLOADED', 'all_tenants': '1'}),
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'SHUTOFF', 'all_tenants': '1'}),
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'SUSPENDED', 'all_tenants': '1'}),
            mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'VERIFY_RESIZE', 'all_tenants': '1'}),
        ]
        nova.servers.list.assert_has_calls(expected, any_order=True)

        not_expected = mock.call(search_opts={'marker': '', 'limit': '100', 'status': 'BUILD', 'all_tenants': '1'})
        self.assertTrue(not_expected not in nova.servers.list.call_args_list)