def test_os_vm_quota_cores_failure(self): """Ensure os_vm_quota_cores method works with failure.""" result = tests.runner( 'os_vm_quota_cores', extra_args=['--config-file', 'tests/files/test-openstack.ini']) assert result['measurement_name'] == 'os_vm_quota_cores' assert result['meta'] == {'quotas': 'cores'}
def test_os_vm_used_ram_failure(self): """Ensure os_vm_used_ram method works with failure.""" result = tests.runner( 'os_vm_used_ram', extra_args=['--config-file', 'tests/files/test-openstack.ini']) assert result['measurement_name'] == 'os_vm_used_ram' assert result['meta'] == {'used': 'ram'}
def test_os_vm_quota_cores_success(self, monkeypatch): """Ensure os_vm_quota_cores method works with success.""" monkeypatch.setattr(Ost, 'get_projects', mock_get_projects) monkeypatch.setattr(Ost, 'get_compute_limits', mock_get_compute_limits) result = tests.runner( 'os_vm_quota_cores', extra_args=['--config-file', 'tests/files/test-openstack.ini']) assert result['measurement_name'] == 'os_vm_quota_cores' assert result['meta'] == {'quotas': 'cores'}
def test_os_vm_used_instance_success(self, monkeypatch): """Ensure os_vm_used_instance method works with success.""" monkeypatch.setattr(Ost, 'get_flavors', mock_get_flavors) monkeypatch.setattr(Ost, 'get_flavor', mock_get_flavor) monkeypatch.setattr(Ost, 'get_project_name', mock_get_project_name) monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage) result = tests.runner( 'os_vm_used_instance', extra_args=['--config-file', 'tests/files/test-openstack.ini']) assert result['measurement_name'] == 'os_vm_used_instance' assert result['meta']['used'] == 'instances' assert result['variables'] == {'test_name': 1}
def test_get_cmdlines_exception(self, monkeypatch): """Ensure the get_cmdlines() method works.""" class _RaisePid(object): pid = 'not-a-pid' @staticmethod def cmdline(): raise process.psutil.NoSuchProcess('not-a-pid') def _mock_process_iter(): return [_RaisePid, _RaisePid, _RaisePid] with mock.patch('psutil.process_iter') as MockClass: MockClass.return_value = _mock_process_iter() process_name = 'dont-go-chasing-waterfalls' result = tests.runner('process', extra_args=[process_name]) assert result['variables'] == {process_name: 0} assert result['exit_code'] == 1
def test_run_failure_no_libvirt(self): """Ensure the run() method works.""" sys.modules.pop('libvirt', None) result = tests.runner('kvm') self.assertTrue(isinstance(result.exception, SystemExit))
def test_run_failure(self): """Ensure the run() method works.""" sys.modules['libvirt'] = LibvirtStubFailed() result = tests.runner('kvm') assert result['measurement_name'] == 'kvm' assert result['exit_code'] == 1
def test_run_success(self): """Ensure the run() method works.""" process_name = '/' result = tests.runner('process', extra_args=[process_name]) assert result['variables'] == {process_name: 1} assert result['exit_code'] == 0
def test_run_failure(self): """Ensure the run() method works.""" process_name = 'dont-go-chasing-waterfalls' result = tests.runner('process', extra_args=[process_name]) assert result['variables'] == {process_name: 0} assert result['exit_code'] == 1
def test_run(self): """Ensure the run() method works.""" result = tests.runner('uptime') assert 'uptime' in result['variables'] assert result['exit_code'] == 0