Browse Source

Tests for remaining OpenStack modules (#22)

Major Hayden 2 years ago
parent
commit
10e9634213

+ 1
- 1
monitorstack/plugins/os_vm_used_disk.py View File

@@ -46,8 +46,8 @@ def cli(ctx, config_file):
46 46
     used_collection = collections.Counter()
47 47
     nova_config = utils.read_config(config_file=config_file)['nova']
48 48
     _ost = ost.OpenStack(os_auth_args=nova_config)
49
-    flavors = _ost.get_flavors()
50 49
     try:
50
+        flavors = _ost.get_flavors()
51 51
         variables = output['variables']
52 52
         for used in _ost.get_consumer_usage():
53 53
             flavor = flavors[used['flavor']['id']]

+ 1
- 1
monitorstack/plugins/os_vm_used_ram.py View File

@@ -46,8 +46,8 @@ def cli(ctx, config_file):
46 46
     used_collection = collections.Counter()
47 47
     nova_config = utils.read_config(config_file=config_file)['nova']
48 48
     _ost = ost.OpenStack(os_auth_args=nova_config)
49
-    flavors = _ost.get_flavors()
50 49
     try:
50
+        flavors = _ost.get_flavors()
51 51
         variables = output['variables']
52 52
         for used in _ost.get_consumer_usage():
53 53
             flavor = flavors[used['flavor']['id']]

+ 47
- 9
tests/test_os_vm.py View File

@@ -58,6 +58,8 @@ def mock_get_flavors(self):
58 58
         1: {
59 59
             'name': 'flavor_one',
60 60
             'vcpus': 2,
61
+            'disk': 10,
62
+            'ram': 1024,
61 63
         }
62 64
     }
63 65
 
@@ -143,14 +145,50 @@ class TestOs(object):
143 145
         assert result['measurement_name'] == 'os_vm_used_cores'
144 146
         assert result['meta'] == {'used': 'cores'}
145 147
 
146
-    def test_os_vm_used_disk(self):
147
-        """Ensure the run() method works."""
148
-        pass
148
+    def test_os_vm_used_disk_success(self, monkeypatch):
149
+        """Ensure os_vm_used_disk method works with success."""
150
+        monkeypatch.setattr(Ost, 'get_flavors', mock_get_flavors)
151
+        monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage)
152
+
153
+        result = _runner('os_vm_used_disk')
154
+        assert result['measurement_name'] == 'os_vm_used_disk'
155
+        assert result['meta']['used'] == 'disk'
156
+        assert result['meta']['flavor_one']
157
+
158
+    def test_os_vm_used_disk_failure(self):
159
+        """Ensure os_vm_used_disk method works with failure."""
160
+        result = _runner('os_vm_used_disk')
161
+        assert result['measurement_name'] == 'os_vm_used_disk'
162
+        assert result['meta'] == {'used': 'disk'}
163
+
164
+    def test_os_vm_used_instance_success(self, monkeypatch):
165
+        """Ensure os_vm_used_instance method works with success."""
166
+        monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage)
167
+
168
+        result = _runner('os_vm_used_instance')
169
+        assert result['measurement_name'] == 'os_vm_used_instance'
170
+        assert result['meta']['used'] == 'instances'
171
+        assert result['variables'] == {'test_name': 1}
149 172
 
150
-    def test_os_vm_used_instances(self):
151
-        """Ensure the run() method works."""
152
-        pass
173
+    def test_os_vm_used_instance_failure(self):
174
+        """Ensure os_vm_used_instance method works with failure."""
175
+        result = _runner('os_vm_used_instance')
176
+        assert result['measurement_name'] == 'os_vm_used_instance'
177
+        assert result['meta'] == {'used': 'instances'}
178
+
179
+    def test_os_vm_used_ram_success(self, monkeypatch):
180
+        """Ensure os_vm_used_ram method works with success."""
181
+        monkeypatch.setattr(Ost, 'get_flavors', mock_get_flavors)
182
+        monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage)
183
+
184
+        result = _runner('os_vm_used_ram')
185
+        assert result['measurement_name'] == 'os_vm_used_ram'
186
+        assert result['meta']['used'] == 'ram'
187
+        assert result['meta']['flavor_one']
188
+        assert result['variables'] == {'test_name': 1024}
153 189
 
154
-    def test_os_vm_used_ram(self):
155
-        """Ensure the run() method works."""
156
-        pass
190
+    def test_os_vm_used_ram_failure(self):
191
+        """Ensure os_vm_used_ram method works with failure."""
192
+        result = _runner('os_vm_used_ram')
193
+        assert result['measurement_name'] == 'os_vm_used_ram'
194
+        assert result['meta'] == {'used': 'ram'}

Loading…
Cancel
Save