Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ceph osd tests #93

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -38,6 +38,7 @@
'python-keystoneclient',
'python-novaclient',
'python-neutronclient',
'python-cinderclient',
]

tests_require = [
Expand Down
103 changes: 103 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_ceph.py
@@ -0,0 +1,103 @@
import unit_tests.utils as ut_utils
import zaza.model as model
import zaza.utilities.ceph as ceph_utils
import zaza.utilities.openstack as openstack_utils


class TestCephUtils(ut_utils.BaseTestCase):

def setUp(self):
super(TestCephUtils, self).setUp()

def _test_expected_pools(self,
os_release_pair,
expected_pools,
radosgw=False):
self.get_current_os_release_pair.return_value = os_release_pair
actual_pools = ceph_utils.get_expected_pools(radosgw)
self.assertEqual(expected_pools, actual_pools)

def test_get_expected_pools(self):
self.patch_object(openstack_utils, 'get_current_os_release_pair')

# Trusty Icehouse
os_release_pair = 'trusty_icehouse'
self.get_current_os_release_pair.return_value = 'trusty_icehouse'
expected_pools = [
'data',
'metadata',
'rbd',
'cinder-ceph',
'glance'
]
self._test_expected_pools(os_release_pair, expected_pools)

# Xenial Ocata
os_release_pair = 'xenial_ocata'
expected_pools = [
'rbd',
'cinder-ceph',
'glance'
]
self._test_expected_pools(os_release_pair, expected_pools)

# Xenial Queens
os_release_pair = 'xenial_queens'
expected_pools = [
'cinder-ceph',
'glance'
]
self._test_expected_pools(os_release_pair, expected_pools)

# Xenial Queens with radosgw
os_release_pair = 'xenial_queens'
expected_pools = [
'cinder-ceph',
'glance',
'.rgw.root',
'.rgw.control',
'.rgw',
'.rgw.gc',
'.users.uid'
]
self._test_expected_pools(os_release_pair, expected_pools, True)

def test_get_ceph_pools(self):
self.patch_object(model, 'run_on_unit')

# Bad return code
result = {
'Code': '1',
'Stdout': '',
'Stderr': 'something went wrong',
}
self.run_on_unit.return_value = result
with self.assertRaises(model.CommandRunFailed):
ceph_utils.get_ceph_pools('ceph-mon/0')

# Xenial Queens output
result = {
'Code': '0',
'Stdout': '1 cinder-ceph,2 glance,',
'Stderr': ''
}
self.run_on_unit.return_value = result
expected = {
'cinder-ceph': 1,
'glance': 2
}
actual = ceph_utils.get_ceph_pools('ceph-mon/0')
self.assertEqual(expected, actual)
# Bionic Queens output
result = {
'Code': '0',
'Stdout': '1 cinder-ceph\n2 glance',
'Stderr': ''
}
self.run_on_unit.return_value = result
expected = {
'cinder-ceph': 1,
'glance': 2
}
actual = ceph_utils.get_ceph_pools('ceph-mon/0')
self.assertEqual(expected, actual)
177 changes: 177 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_generic.py
Expand Up @@ -15,6 +15,7 @@
import mock
import unit_tests.utils as ut_utils
from zaza.utilities import generic as generic_utils
import zaza.utilities.exceptions as zaza_exceptions

FAKE_STATUS = {
'can-upgrade-to': '',
Expand Down Expand Up @@ -368,3 +369,179 @@ def test_set_dpkg_non_interactive_on_unit(self):
'/etc/apt/apt.conf.d/50unattended-upgrades || '
'echo \'DPkg::options { "--force-confdef"; };\' >> '
'/etc/apt/apt.conf.d/50unattended-upgrades')

def test_get_process_id_list(self):
self.patch(
"zaza.utilities.generic.model.run_on_unit",
new_callable=mock.MagicMock(),
name="_run"
)

# Return code is OK and STDOUT contains output
returns_ok = {
"Code": 0,
"Stdout": "1 2",
"Stderr": ""
}
self._run.return_value = returns_ok
p_id_list = generic_utils.get_process_id_list(
"ceph-osd/0",
"ceph-osd",
False
)
expected = ["1", "2"]
cmd = 'pidof -x "ceph-osd" || exit 0 && exit 1'
self.assertEqual(p_id_list, expected)
self._run.assert_called_once_with(unit_name="ceph-osd/0",
command=cmd)

# Return code is not OK
returns_nok = {
"Code": 1,
"Stdout": "",
"Stderr": "Something went wrong"
}
self._run.return_value = returns_nok
with self.assertRaises(zaza_exceptions.ProcessIdsFailed):
generic_utils.get_process_id_list("ceph-osd/0", "ceph")
cmd = 'pidof -x "ceph"'
self._run.assert_called_once_with(unit_name="ceph-osd/0",
command=cmd)

def test_get_unit_process_ids(self):
self.patch(
"zaza.utilities.generic.get_process_id_list",
new_callable=mock.MagicMock(),
name="_get_pids"
)

pids = ["1", "2"]
self._get_pids.return_value = pids
unit_processes = {
"ceph-osd/0": {
"ceph-osd": 2
},
"unit/0": {
"pr1": 2,
"pr2": 2
}
}
expected = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
"pr1": ["1", "2"],
"pr2": ["1", "2"]
}
}
result = generic_utils.get_unit_process_ids(unit_processes)
self.assertEqual(result, expected)

def test_validate_unit_process_ids(self):
expected = {
"ceph-osd/0": {
"ceph-osd": 2
},
"unit/0": {
"pr1": 2,
"pr2": [1, 2]
}
}

# Unit count mismatch
actual = {}
with self.assertRaises(zaza_exceptions.UnitCountMismatch):
generic_utils.validate_unit_process_ids(expected, actual)

# Unit not found in actual dict
actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
# unit/0 not in the dict
"unit/1": {
"pr1": ["1", "2"],
"pr2": ["1", "2"]
}
}
with self.assertRaises(zaza_exceptions.UnitNotFound):
generic_utils.validate_unit_process_ids(expected, actual)

# Process names count doesn't match
actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
# Only one process name instead of 2 expected
"pr1": ["1", "2"]
}
}
with self.assertRaises(zaza_exceptions.ProcessNameCountMismatch):
generic_utils.validate_unit_process_ids(expected, actual)

# Process name doesn't match
actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
# Bad process name
"bad_name": ["1", "2"],
"pr2": ["1", "2"]
}
}
with self.assertRaises(zaza_exceptions.ProcessNameMismatch):
generic_utils.validate_unit_process_ids(expected, actual)

# PID count doesn't match
actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
# Only one PID instead of 2 expected
"pr1": ["2"],
"pr2": ["1", "2"]
}
}
with self.assertRaises(zaza_exceptions.PIDCountMismatch):
generic_utils.validate_unit_process_ids(expected, actual)

actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
"pr1": ["1", "2"],
# 3 PID instead of [1, 2] expected
"pr2": ["1", "2", "3"]
}
}
with self.assertRaises(zaza_exceptions.PIDCountMismatch):
generic_utils.validate_unit_process_ids(expected, actual)

# It should work now...
actual = {
"ceph-osd/0": {
"ceph-osd": ["1", "2"]
},
"unit/0": {
"pr1": ["1", "2"],
"pr2": ["1", "2"]
}
}
ret = generic_utils.validate_unit_process_ids(expected, actual)
self.assertTrue(ret)

def test_get_ubuntu_release(self):
# Normal case
expected = 0
actual = generic_utils.get_ubuntu_release('oneiric')
self.assertEqual(expected, actual)

# Ubuntu release doesn't exist
bad_name = 'bad_name'
with self.assertRaises(zaza_exceptions.UbuntuReleaseNotFound):
generic_utils.get_ubuntu_release(bad_name)
15 changes: 15 additions & 0 deletions zaza/charm_tests/ceph/__init__.py
@@ -0,0 +1,15 @@
# Copyright 2018 Canonical Ltd.
#
# 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.

"""Collection of code for setting up and testing ceph-osd."""
20 changes: 20 additions & 0 deletions zaza/charm_tests/ceph/setup.py
@@ -0,0 +1,20 @@
# Copyright 2018 Canonical Ltd.
#
# 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.

"""Setup for ceph-osd deployments."""


def basic_setup():
"""Run basic setup for ceph-osd."""
pass