115 lines
3.7 KiB
Python
115 lines
3.7 KiB
Python
# Copyright 2017, Kevin Carter <kevin@cloudnull.com>
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""Tests for the KVM plugin."""
|
|
|
|
from monitorstack.utils.os_utils import OpenStack as Ost
|
|
|
|
import tests.unit
|
|
|
|
CONF_FILE = 'tests/unit/files/test-openstack.ini'
|
|
|
|
|
|
class OpenStackObject(object):
|
|
"""Mocked server object."""
|
|
|
|
def __init__(self, id=None, name=None):
|
|
"""Mocked server class."""
|
|
self.id = id
|
|
self.name = name
|
|
self.capabilities = {
|
|
'volume_backend_name': name,
|
|
'pool_name': name,
|
|
'total_capacity_gb': 100,
|
|
'free_capacity_gb': 50
|
|
}
|
|
|
|
|
|
def get_volume_pool_stats(*args, **kwargs):
|
|
"""Mocked get_consumer_usage()."""
|
|
return [
|
|
OpenStackObject(1, 'pool_name1'),
|
|
OpenStackObject(1, 'pool_name2')
|
|
]
|
|
|
|
|
|
class TestOsBlock(object):
|
|
"""Tests for the os_vm.* monitors."""
|
|
|
|
def test_os_block_pools_totals_success(self, monkeypatch):
|
|
"""Ensure os_block_pools_totals method works with success."""
|
|
monkeypatch.setattr(
|
|
Ost,
|
|
'get_volume_pool_stats',
|
|
get_volume_pool_stats
|
|
)
|
|
result = tests.runner(
|
|
'os_block_pools_totals',
|
|
extra_args=[
|
|
'--config-file',
|
|
CONF_FILE
|
|
]
|
|
)
|
|
assert result['measurement_name'] == 'os_block_pools_totals'
|
|
|
|
def test_os_block_pools_totals_failure(self):
|
|
"""Ensure os_block_pools_totals method works with success."""
|
|
result = tests.runner(
|
|
'os_block_pools_totals',
|
|
extra_args=[
|
|
'--config-file',
|
|
CONF_FILE
|
|
]
|
|
)
|
|
assert result['measurement_name'] == 'os_block_pools_totals'
|
|
assert result['exit_code'] == 1
|
|
|
|
def test_os_block_pools_usage_success(self, monkeypatch):
|
|
"""Ensure os_block_pools_totals method works with success."""
|
|
monkeypatch.setattr(
|
|
Ost,
|
|
'get_volume_pool_stats',
|
|
get_volume_pool_stats
|
|
)
|
|
result = tests.runner(
|
|
'os_block_pools_usage',
|
|
extra_args=[
|
|
'--config-file',
|
|
CONF_FILE
|
|
]
|
|
)
|
|
variables = result['variables']
|
|
meta = result['meta']
|
|
assert variables['pool_name1_free_capacity_gb'] == 50
|
|
assert variables['pool_name2_total_capacity_gb'] == 100
|
|
assert variables['pool_name1_percent_used'] == 50
|
|
assert variables['pool_name1_total_capacity_gb'] == 100
|
|
assert variables['pool_name2_free_capacity_gb'] == 50
|
|
assert variables['pool_name2_percent_used'] == 50
|
|
assert meta['block_pools'] == 'usage'
|
|
assert meta['pool_name1'] is True
|
|
assert meta['pool_name2'] is True
|
|
assert result['measurement_name'] == 'os_block_pools_usage'
|
|
|
|
def test_os_block_pools_usage_failure(self):
|
|
"""Ensure os_block_pools_totals method works with success."""
|
|
result = tests.runner(
|
|
'os_block_pools_usage',
|
|
extra_args=[
|
|
'--config-file',
|
|
CONF_FILE
|
|
]
|
|
)
|
|
assert result['measurement_name'] == 'os_block_pools_usage'
|
|
assert result['exit_code'] == 1
|