Browse Source

Minor test improvement for ceph_pools_pg_protection

Tests now include check of run function and
required module attributes.

Closes-Bug: #1922726

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Id21cd63fff6e8cd2f0aad452ad8f1a5d8ce87930
changes/77/782377/8
Jiri Podivin 1 month ago
parent
commit
f840eb6b23
1 changed files with 82 additions and 0 deletions
  1. +82
    -0
      tripleo_validations/tests/library/test_ceph_pools_pg_protection.py

+ 82
- 0
tripleo_validations/tests/library/test_ceph_pools_pg_protection.py View File

@ -21,10 +21,92 @@ Tests for `ceph_pools_pg_protection` module.
import library.ceph_pools_pg_protection as validation
from tripleo_validations.tests import base
from tripleo_validations.tests import fakes
try:
from unittest import mock
except ImportError:
import mock
class TestCephPoolsPgProtection(base.TestCase):
def test_module_init(self):
module_attributes = dir(validation)
required_attributes = [
'DOCUMENTATION',
'EXAMPLES'
]
self.assertTrue(set(required_attributes).issubset(module_attributes))
@mock.patch(
'library.ceph_pools_pg_protection.run_module')
def test_module_main(self, mock_run_module):
validation.main()
mock_run_module.assert_called_once()
@mock.patch(
'library.ceph_pools_pg_protection.simulate_pool_creation',
return_value={'failed': False})
@mock.patch(
'library.ceph_pools_pg_protection.yaml_safe_load',
return_value={'options': 'bar'})
@mock.patch(
'library.ceph_pools_pg_protection.AnsibleModule')
def test_run_module_sim_success(self, mock_module,
mock_yaml_safe_load,
mock_simulate_pool_creation):
mock_exit_json = mock.MagicMock()
mock_module.return_value = mock.MagicMock(
check_mode=False,
exit_json=mock_exit_json)
validation.run_module()
mock_yaml_safe_load.assert_called_once()
mock_module.assert_called_once_with(
argument_spec='bar',
supports_check_mode=False
)
mock_exit_json.assert_called_once()
@mock.patch(
'library.ceph_pools_pg_protection.simulate_pool_creation',
return_value={'failed': True, 'msg': 'fizz'})
@mock.patch(
'library.ceph_pools_pg_protection.yaml_safe_load',
return_value={'options': 'bar'})
@mock.patch(
'library.ceph_pools_pg_protection.AnsibleModule')
def test_run_module_sim_failed(self, mock_module,
mock_yaml_safe_load,
mock_simulate_pool_creation):
mock_exit_json = mock.MagicMock()
mock_module.return_value = mock.MagicMock(
check_mode=False,
exit_json=mock_exit_json)
validation.run_module()
mock_yaml_safe_load.assert_called_once()
mock_module.assert_called_once_with(
argument_spec='bar',
supports_check_mode=False
)
mock_exit_json.assert_called_once()
def test_check_pg_num_enough_osds(self):
'''Test adding one more pool to the existing pools with 36 OSDs'''
num_osds = 36


Loading…
Cancel
Save