Finsh unit tests and fix lint
This commit is contained in:
parent
bee432ba56
commit
ecddb69e30
|
@ -5,4 +5,3 @@ exclude_lines =
|
||||||
include=
|
include=
|
||||||
hooks/ceph.py
|
hooks/ceph.py
|
||||||
hooks/hooks.py
|
hooks/hooks.py
|
||||||
hooks/utils.py
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
||||||
PYTHON := /usr/bin/env python
|
PYTHON := /usr/bin/env python
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@flake8 --exclude hooks/charmhelpers hooks tests
|
@flake8 --exclude hooks/charmhelpers hooks tests unit_tests
|
||||||
@charm proof
|
@charm proof
|
||||||
|
|
||||||
unit_test:
|
unit_test:
|
||||||
|
|
|
@ -86,7 +86,7 @@ def enable_pocket(pocket):
|
||||||
def get_host_ip(hostname=None):
|
def get_host_ip(hostname=None):
|
||||||
try:
|
try:
|
||||||
if not hostname:
|
if not hostname:
|
||||||
hostname=unit_get('private-address')
|
hostname = unit_get('private-address')
|
||||||
# Test to see if already an IPv4 address
|
# Test to see if already an IPv4 address
|
||||||
socket.inet_aton(hostname)
|
socket.inet_aton(hostname)
|
||||||
return hostname
|
return hostname
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from mock import call, patch, MagicMock
|
from test_utils import CharmTestCase
|
||||||
from test_utils import CharmTestCase, patch_open
|
|
||||||
|
|
||||||
import ceph
|
import ceph
|
||||||
|
|
||||||
|
@ -10,26 +9,34 @@ TO_PATCH = [
|
||||||
'time',
|
'time',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CephRadosGWCephTests(CharmTestCase):
|
class CephRadosGWCephTests(CharmTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CephRadosGWCephTests, self).setUp(ceph, TO_PATCH)
|
super(CephRadosGWCephTests, self).setUp(ceph, TO_PATCH)
|
||||||
|
|
||||||
def test_is_quorum_leader(self):
|
def test_is_quorum_leader(self):
|
||||||
|
self.os.path.exists.return_value = True
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
self.subprocess.check_output.return_value = '{"state": "leader"}'
|
self.subprocess.check_output.return_value = '{"state": "leader"}'
|
||||||
self.assertEqual(ceph.is_quorum(), True)
|
self.assertEqual(ceph.is_quorum(), True)
|
||||||
|
|
||||||
def test_is_quorum_notleader(self):
|
def test_is_quorum_notleader(self):
|
||||||
|
self.os.path.exists.return_value = True
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
self.subprocess.check_output.return_value = '{"state": "notleader"}'
|
self.subprocess.check_output.return_value = '{"state": "notleader"}'
|
||||||
self.assertEqual(ceph.is_quorum(), False)
|
self.assertEqual(ceph.is_quorum(), False)
|
||||||
|
|
||||||
def test_is_quorum_valerror(self):
|
def test_is_quorum_valerror(self):
|
||||||
|
self.os.path.exists.return_value = True
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
self.subprocess.check_output.return_value = "'state': 'bob'}"
|
self.subprocess.check_output.return_value = "'state': 'bob'}"
|
||||||
self.assertEqual(ceph.is_quorum(), False)
|
self.assertEqual(ceph.is_quorum(), False)
|
||||||
|
|
||||||
|
def test_is_quorum_no_asok(self):
|
||||||
|
self.os.path.exists.return_value = False
|
||||||
|
self.assertEqual(ceph.is_quorum(), False)
|
||||||
|
|
||||||
def test_is_leader(self):
|
def test_is_leader(self):
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
self.os.path.exists.return_value = True
|
self.os.path.exists.return_value = True
|
||||||
|
@ -53,18 +60,31 @@ class CephRadosGWCephTests(CharmTestCase):
|
||||||
self.os.path.exists.return_value = False
|
self.os.path.exists.return_value = False
|
||||||
self.assertEqual(ceph.is_leader(), False)
|
self.assertEqual(ceph.is_leader(), False)
|
||||||
|
|
||||||
# def test_wait_for_quorum_yes(self):
|
def test_wait_for_quorum_yes(self):
|
||||||
# _is_quorum = self.patch('is_quorum')
|
results = [True, False]
|
||||||
# _is_quorum.return_value = False
|
|
||||||
# self.time.return_value = None
|
|
||||||
# ceph.wait_for_quorum()
|
|
||||||
# self.time.sleep.assert_called_with(3)
|
|
||||||
|
|
||||||
# def test_wait_for_quorum_no(self):
|
def quorum():
|
||||||
# _is_quorum = self.patch('is_quorum')
|
return results.pop()
|
||||||
# _is_quorum.return_value = True
|
_is_quorum = self.patch('is_quorum')
|
||||||
# ceph.wait_for_quorum()
|
_is_quorum.side_effect = quorum
|
||||||
# self.assertFalse(self.time.sleep.called)
|
ceph.wait_for_quorum()
|
||||||
|
self.time.sleep.assert_called_with(3)
|
||||||
|
|
||||||
|
def test_wait_for_quorum_no(self):
|
||||||
|
_is_quorum = self.patch('is_quorum')
|
||||||
|
_is_quorum.return_value = True
|
||||||
|
ceph.wait_for_quorum()
|
||||||
|
self.assertFalse(self.time.sleep.called)
|
||||||
|
|
||||||
|
def test_wait_for_bootstrap(self):
|
||||||
|
results = [True, False]
|
||||||
|
|
||||||
|
def bootstrapped():
|
||||||
|
return results.pop()
|
||||||
|
_is_bootstrapped = self.patch('is_bootstrapped')
|
||||||
|
_is_bootstrapped.side_effect = bootstrapped
|
||||||
|
ceph.wait_for_bootstrap()
|
||||||
|
self.time.sleep.assert_called_with(3)
|
||||||
|
|
||||||
def test_add_bootstrap_hint(self):
|
def test_add_bootstrap_hint(self):
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
|
@ -77,7 +97,7 @@ class CephRadosGWCephTests(CharmTestCase):
|
||||||
]
|
]
|
||||||
self.os.path.exists.return_value = True
|
self.os.path.exists.return_value = True
|
||||||
ceph.add_bootstrap_hint('mypeer')
|
ceph.add_bootstrap_hint('mypeer')
|
||||||
self.subprocess.call.assert_called_with(cmd)
|
self.subprocess.call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_add_bootstrap_hint_noasok(self):
|
def test_add_bootstrap_hint_noasok(self):
|
||||||
self.get_unit_hostname.return_value = 'myhost'
|
self.get_unit_hostname.return_value = 'myhost'
|
||||||
|
@ -87,14 +107,16 @@ class CephRadosGWCephTests(CharmTestCase):
|
||||||
|
|
||||||
def test_is_osd_disk(self):
|
def test_is_osd_disk(self):
|
||||||
# XXX Insert real sgdisk output
|
# XXX Insert real sgdisk output
|
||||||
self.subprocess.check_output.return_value = 'Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
|
self.subprocess.check_output.return_value = \
|
||||||
|
'Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
|
||||||
self.assertEqual(ceph.is_osd_disk('/dev/fmd0'), True)
|
self.assertEqual(ceph.is_osd_disk('/dev/fmd0'), True)
|
||||||
|
|
||||||
def test_is_osd_disk_no(self):
|
def test_is_osd_disk_no(self):
|
||||||
# XXX Insert real sgdisk output
|
# XXX Insert real sgdisk output
|
||||||
self.subprocess.check_output.return_value = 'Partition GUID code: 5FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
|
self.subprocess.check_output.return_value = \
|
||||||
|
'Partition GUID code: 5FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
|
||||||
self.assertEqual(ceph.is_osd_disk('/dev/fmd0'), False)
|
self.assertEqual(ceph.is_osd_disk('/dev/fmd0'), False)
|
||||||
|
|
||||||
def test_rescan_osd_devices(self):
|
def test_rescan_osd_devices(self):
|
||||||
cmd = [
|
cmd = [
|
||||||
'udevadm', 'trigger',
|
'udevadm', 'trigger',
|
||||||
|
@ -102,7 +124,7 @@ class CephRadosGWCephTests(CharmTestCase):
|
||||||
]
|
]
|
||||||
ceph.rescan_osd_devices()
|
ceph.rescan_osd_devices()
|
||||||
self.subprocess.call.assert_called_with(cmd)
|
self.subprocess.call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_zap_disk(self):
|
def test_zap_disk(self):
|
||||||
cmd = [
|
cmd = [
|
||||||
'sgdisk', '--zap-all', '/dev/fmd0',
|
'sgdisk', '--zap-all', '/dev/fmd0',
|
||||||
|
@ -121,9 +143,55 @@ class CephRadosGWCephTests(CharmTestCase):
|
||||||
]
|
]
|
||||||
ceph.import_osd_bootstrap_key('mykey')
|
ceph.import_osd_bootstrap_key('mykey')
|
||||||
self.subprocess.check_call.assert_called_with(cmd)
|
self.subprocess.check_call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_is_bootstrapped(self):
|
def test_is_bootstrapped(self):
|
||||||
self.os.path.exists.return_value = True
|
self.os.path.exists.return_value = True
|
||||||
self.assertEqual(ceph.is_bootstrapped(), True)
|
self.assertEqual(ceph.is_bootstrapped(), True)
|
||||||
self.os.path.exists.return_value = False
|
self.os.path.exists.return_value = False
|
||||||
self.assertEqual(ceph.is_bootstrapped(), False)
|
self.assertEqual(ceph.is_bootstrapped(), False)
|
||||||
|
|
||||||
|
def test_import_radosgw_key(self):
|
||||||
|
self.os.path.exists.return_value = False
|
||||||
|
ceph.import_radosgw_key('mykey')
|
||||||
|
cmd = [
|
||||||
|
'ceph-authtool',
|
||||||
|
'/etc/ceph/keyring.rados.gateway',
|
||||||
|
'--create-keyring',
|
||||||
|
'--name=client.radosgw.gateway',
|
||||||
|
'--add-key=mykey'
|
||||||
|
]
|
||||||
|
self.subprocess.check_call.assert_called_with(cmd)
|
||||||
|
|
||||||
|
def test_get_named_key_create(self):
|
||||||
|
self.get_unit_hostname.return_value = "myhost"
|
||||||
|
self.subprocess.check_output.return_value = """
|
||||||
|
|
||||||
|
[client.dummy]
|
||||||
|
key = AQAPiu1RCMb4CxAAmP7rrufwZPRqy8bpQa2OeQ==
|
||||||
|
"""
|
||||||
|
self.assertEqual(ceph.get_named_key('dummy'),
|
||||||
|
'AQAPiu1RCMb4CxAAmP7rrufwZPRqy8bpQa2OeQ==')
|
||||||
|
cmd = [
|
||||||
|
'ceph',
|
||||||
|
'--name', 'mon.',
|
||||||
|
'--keyring',
|
||||||
|
'/var/lib/ceph/mon/ceph-myhost/keyring',
|
||||||
|
'auth', 'get-or-create', 'client.dummy',
|
||||||
|
'mon', 'allow r', 'osd', 'allow rwx'
|
||||||
|
]
|
||||||
|
self.subprocess.check_output.assert_called_with(cmd)
|
||||||
|
|
||||||
|
def test_get_named_key_get(self):
|
||||||
|
self.get_unit_hostname.return_value = "myhost"
|
||||||
|
key = "AQAPiu1RCMb4CxAAmP7rrufwZPRqy8bpQa2OeQ=="
|
||||||
|
self.subprocess.check_output.return_value = key
|
||||||
|
self.assertEqual(ceph.get_named_key('dummy'), key)
|
||||||
|
cmd = [
|
||||||
|
'ceph',
|
||||||
|
'--name', 'mon.',
|
||||||
|
'--keyring',
|
||||||
|
'/var/lib/ceph/mon/ceph-myhost/keyring',
|
||||||
|
'auth', 'get-or-create', 'client.dummy',
|
||||||
|
'mon', 'allow r', 'osd', 'allow rwx'
|
||||||
|
]
|
||||||
|
self.subprocess.check_output.assert_called_with(cmd)
|
||||||
|
|
|
@ -2,17 +2,27 @@
|
||||||
from mock import call, patch, MagicMock
|
from mock import call, patch, MagicMock
|
||||||
from test_utils import CharmTestCase, patch_open
|
from test_utils import CharmTestCase, patch_open
|
||||||
|
|
||||||
|
import utils
|
||||||
|
_reg = utils.register_configs
|
||||||
|
|
||||||
|
utils.register_configs = MagicMock()
|
||||||
|
|
||||||
import hooks as ceph_hooks
|
import hooks as ceph_hooks
|
||||||
|
|
||||||
|
utils.register_configs = _reg
|
||||||
|
|
||||||
TO_PATCH = [
|
TO_PATCH = [
|
||||||
'add_source',
|
'add_source',
|
||||||
'apt_update',
|
'apt_update',
|
||||||
'apt_install',
|
'apt_install',
|
||||||
|
'apt_purge',
|
||||||
'config',
|
'config',
|
||||||
'cmp_pkgrevno',
|
'cmp_pkgrevno',
|
||||||
'execd_preinstall',
|
'execd_preinstall',
|
||||||
'enable_pocket',
|
'enable_pocket',
|
||||||
'get_host_ip',
|
'get_host_ip',
|
||||||
|
'get_iface_for_address',
|
||||||
|
'get_netmask_for_address',
|
||||||
'get_unit_hostname',
|
'get_unit_hostname',
|
||||||
'glob',
|
'glob',
|
||||||
'is_apache_24',
|
'is_apache_24',
|
||||||
|
@ -25,12 +35,14 @@ TO_PATCH = [
|
||||||
'relation_set',
|
'relation_set',
|
||||||
'relation_get',
|
'relation_get',
|
||||||
'render_template',
|
'render_template',
|
||||||
|
'resolve_address',
|
||||||
'shutil',
|
'shutil',
|
||||||
'subprocess',
|
'subprocess',
|
||||||
'sys',
|
'sys',
|
||||||
'unit_get',
|
'unit_get',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CephRadosGWTests(CharmTestCase):
|
class CephRadosGWTests(CharmTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -47,10 +59,11 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
|
|
||||||
def test_install_ceph_optimised_packages(self):
|
def test_install_ceph_optimised_packages(self):
|
||||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'vivid'}
|
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'vivid'}
|
||||||
git_url = 'http://gitbuilder.ceph.com'
|
fastcgi_source = (
|
||||||
fastcgi_source = ('http://gitbuilder.ceph.com/'
|
'http://gitbuilder.ceph.com/'
|
||||||
'libapache-mod-fastcgi-deb-vivid-x86_64-basic/ref/master')
|
'libapache-mod-fastcgi-deb-vivid-x86_64-basic/ref/master')
|
||||||
apache_source = ('http://gitbuilder.ceph.com/'
|
apache_source = (
|
||||||
|
'http://gitbuilder.ceph.com/'
|
||||||
'apache2-deb-vivid-x86_64-basic/ref/master')
|
'apache2-deb-vivid-x86_64-basic/ref/master')
|
||||||
calls = [
|
calls = [
|
||||||
call(fastcgi_source, key='6EAEAE2203C3951A'),
|
call(fastcgi_source, key='6EAEAE2203C3951A'),
|
||||||
|
@ -64,22 +77,33 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
ceph_hooks.install_packages()
|
ceph_hooks.install_packages()
|
||||||
self.add_source.assert_called_with('distro', 'secretkey')
|
self.add_source.assert_called_with('distro', 'secretkey')
|
||||||
self.apt_update.assert_called()
|
self.apt_update.assert_called()
|
||||||
self.apt_install.assert_called_with(['radosgw',
|
self.apt_install.assert_called_with(['libapache2-mod-fastcgi',
|
||||||
'libapache2-mod-fastcgi',
|
'apache2'], fatal=True)
|
||||||
'apache2',
|
|
||||||
'ntp'], fatal=True)
|
|
||||||
|
|
||||||
def test_install_optimised_packages(self):
|
def test_install_optimised_packages_no_embedded(self):
|
||||||
self.test_config.set('use-ceph-optimised-packages', True)
|
self.test_config.set('use-ceph-optimised-packages', True)
|
||||||
|
self.test_config.set('use-embedded-webserver', False)
|
||||||
|
_install_packages = self.patch('install_ceph_optimised_packages')
|
||||||
|
ceph_hooks.install_packages()
|
||||||
|
self.add_source.assert_called_with('distro', 'secretkey')
|
||||||
|
self.apt_update.assert_called()
|
||||||
|
_install_packages.assert_called()
|
||||||
|
self.apt_install.assert_called_with(['libapache2-mod-fastcgi',
|
||||||
|
'apache2'], fatal=True)
|
||||||
|
|
||||||
|
def test_install_optimised_packages_embedded(self):
|
||||||
|
self.test_config.set('use-ceph-optimised-packages', True)
|
||||||
|
self.test_config.set('use-embedded-webserver', True)
|
||||||
_install_packages = self.patch('install_ceph_optimised_packages')
|
_install_packages = self.patch('install_ceph_optimised_packages')
|
||||||
ceph_hooks.install_packages()
|
ceph_hooks.install_packages()
|
||||||
self.add_source.assert_called_with('distro', 'secretkey')
|
self.add_source.assert_called_with('distro', 'secretkey')
|
||||||
self.apt_update.assert_called()
|
self.apt_update.assert_called()
|
||||||
_install_packages.assert_called()
|
_install_packages.assert_called()
|
||||||
self.apt_install.assert_called_with(['radosgw',
|
self.apt_install.assert_called_with(['radosgw',
|
||||||
'libapache2-mod-fastcgi',
|
'ntp',
|
||||||
'apache2',
|
'haproxy'], fatal=True)
|
||||||
'ntp'], fatal=True)
|
self.apt_purge.assert_called_with(['libapache2-mod-fastcgi',
|
||||||
|
'apache2'])
|
||||||
|
|
||||||
def test_install(self):
|
def test_install(self):
|
||||||
_install_packages = self.patch('install_packages')
|
_install_packages = self.patch('install_packages')
|
||||||
|
@ -105,9 +129,10 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
'old_auth': False,
|
'old_auth': False,
|
||||||
'use_syslog': 'false',
|
'use_syslog': 'false',
|
||||||
'keystone_key': 'keystone_value',
|
'keystone_key': 'keystone_value',
|
||||||
|
'embedded_webserver': False,
|
||||||
}
|
}
|
||||||
self.cmp_pkgrevno.return_value = 1
|
self.cmp_pkgrevno.return_value = 1
|
||||||
with patch_open() as (_open, _file):
|
with patch_open() as (_open, _file):
|
||||||
ceph_hooks.emit_cephconf()
|
ceph_hooks.emit_cephconf()
|
||||||
self.os.makedirs.assert_called_with('/etc/ceph')
|
self.os.makedirs.assert_called_with('/etc/ceph')
|
||||||
_open.assert_called_with('/etc/ceph/ceph.conf', 'w')
|
_open.assert_called_with('/etc/ceph/ceph.conf', 'w')
|
||||||
|
@ -119,9 +144,10 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
apachecontext = {
|
apachecontext = {
|
||||||
"hostname": '10.0.0.1',
|
"hostname": '10.0.0.1',
|
||||||
}
|
}
|
||||||
with patch_open() as (_open, _file):
|
vhost_file = '/etc/apache2/sites-available/rgw.conf'
|
||||||
|
with patch_open() as (_open, _file):
|
||||||
ceph_hooks.emit_apacheconf()
|
ceph_hooks.emit_apacheconf()
|
||||||
_open.assert_called_with('/etc/apache2/sites-available/rgw.conf', 'w')
|
_open.assert_called_with(vhost_file, 'w')
|
||||||
self.render_template.assert_called_with('rgw', apachecontext)
|
self.render_template.assert_called_with('rgw', apachecontext)
|
||||||
|
|
||||||
def test_apache_sites24(self):
|
def test_apache_sites24(self):
|
||||||
|
@ -205,6 +231,7 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
self.test_config.set('revocation-check-interval', '21')
|
self.test_config.set('revocation-check-interval', '21')
|
||||||
self.relation_ids.return_value = ['idrelid']
|
self.relation_ids.return_value = ['idrelid']
|
||||||
self.related_units.return_value = ['idunit']
|
self.related_units.return_value = ['idunit']
|
||||||
|
|
||||||
def _relation_get(key, unit, relid):
|
def _relation_get(key, unit, relid):
|
||||||
ks_dict = {
|
ks_dict = {
|
||||||
'auth_protocol': 'https',
|
'auth_protocol': 'https',
|
||||||
|
@ -214,15 +241,15 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
}
|
}
|
||||||
return ks_dict[key]
|
return ks_dict[key]
|
||||||
self.relation_get.side_effect = _relation_get
|
self.relation_get.side_effect = _relation_get
|
||||||
self.assertEquals(ceph_hooks.get_keystone_conf(),
|
self.assertEquals(ceph_hooks.get_keystone_conf(), {
|
||||||
{'auth_type': 'keystone',
|
'auth_type': 'keystone',
|
||||||
'auth_protocol': 'https',
|
'auth_protocol': 'https',
|
||||||
'admin_token': 'sectocken',
|
'admin_token': 'sectocken',
|
||||||
'user_roles': 'admin',
|
'user_roles': 'admin',
|
||||||
'auth_host': '10.0.0.2',
|
'auth_host': '10.0.0.2',
|
||||||
'cache_size': '42',
|
'cache_size': '42',
|
||||||
'auth_port': '8090',
|
'auth_port': '8090',
|
||||||
'revocation_check_interval': '21'})
|
'revocation_check_interval': '21'})
|
||||||
|
|
||||||
def test_get_keystone_conf_missinginfo(self):
|
def test_get_keystone_conf_missinginfo(self):
|
||||||
self.test_config.set('operator-roles', 'admin')
|
self.test_config.set('operator-roles', 'admin')
|
||||||
|
@ -230,6 +257,7 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
self.test_config.set('revocation-check-interval', '21')
|
self.test_config.set('revocation-check-interval', '21')
|
||||||
self.relation_ids.return_value = ['idrelid']
|
self.relation_ids.return_value = ['idrelid']
|
||||||
self.related_units.return_value = ['idunit']
|
self.related_units.return_value = ['idunit']
|
||||||
|
|
||||||
def _relation_get(key, unit, relid):
|
def _relation_get(key, unit, relid):
|
||||||
ks_dict = {
|
ks_dict = {
|
||||||
'auth_protocol': 'https',
|
'auth_protocol': 'https',
|
||||||
|
@ -248,6 +276,7 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
ceph_hooks.mon_relation()
|
ceph_hooks.mon_relation()
|
||||||
_restart.assert_called()
|
_restart.assert_called()
|
||||||
_ceph.import_radosgw_key.assert_called_with('seckey')
|
_ceph.import_radosgw_key.assert_called_with('seckey')
|
||||||
|
_emit_cephconf.assert_called()
|
||||||
|
|
||||||
def test_mon_relation_nokey(self):
|
def test_mon_relation_nokey(self):
|
||||||
_emit_cephconf = self.patch('emit_cephconf')
|
_emit_cephconf = self.patch('emit_cephconf')
|
||||||
|
@ -257,6 +286,7 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
ceph_hooks.mon_relation()
|
ceph_hooks.mon_relation()
|
||||||
self.assertFalse(_ceph.import_radosgw_key.called)
|
self.assertFalse(_ceph.import_radosgw_key.called)
|
||||||
self.assertFalse(_restart.called)
|
self.assertFalse(_restart.called)
|
||||||
|
_emit_cephconf.assert_called()
|
||||||
|
|
||||||
def test_gateway_relation(self):
|
def test_gateway_relation(self):
|
||||||
self.unit_get.return_value = 'myserver'
|
self.unit_get.return_value = 'myserver'
|
||||||
|
@ -265,15 +295,18 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
ceph_hooks.start()
|
ceph_hooks.start()
|
||||||
self.subprocess.call.assert_called_with(['service', 'radosgw', 'start'])
|
cmd = ['service', 'radosgw', 'start']
|
||||||
|
self.subprocess.call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_stop(self):
|
def test_stop(self):
|
||||||
ceph_hooks.stop()
|
ceph_hooks.stop()
|
||||||
self.subprocess.call.assert_called_with(['service', 'radosgw', 'stop'])
|
cmd = ['service', 'radosgw', 'stop']
|
||||||
|
self.subprocess.call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_start(self):
|
def test_restart(self):
|
||||||
ceph_hooks.restart()
|
ceph_hooks.restart()
|
||||||
self.subprocess.call.assert_called_with(['service', 'radosgw', 'restart'])
|
cmd = ['service', 'radosgw', 'restart']
|
||||||
|
self.subprocess.call.assert_called_with(cmd)
|
||||||
|
|
||||||
def test_identity_joined_early_version(self):
|
def test_identity_joined_early_version(self):
|
||||||
self.cmp_pkgrevno.return_value = -1
|
self.cmp_pkgrevno.return_value = -1
|
||||||
|
@ -282,18 +315,20 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
|
|
||||||
def test_identity_joined(self):
|
def test_identity_joined(self):
|
||||||
self.cmp_pkgrevno.return_value = 1
|
self.cmp_pkgrevno.return_value = 1
|
||||||
|
self.resolve_address.return_value = 'myserv'
|
||||||
self.test_config.set('region', 'region1')
|
self.test_config.set('region', 'region1')
|
||||||
self.test_config.set('operator-roles', 'admin')
|
self.test_config.set('operator-roles', 'admin')
|
||||||
self.unit_get.return_value = 'myserv'
|
self.unit_get.return_value = 'myserv'
|
||||||
ceph_hooks.identity_joined(relid='rid')
|
ceph_hooks.identity_joined(relid='rid')
|
||||||
self.relation_set.assert_called_with(service='swift',
|
self.relation_set.assert_called_with(
|
||||||
region='region1',
|
service='swift',
|
||||||
public_url='http://myserv:80/swift/v1',
|
region='region1',
|
||||||
internal_url='http://myserv:80/swift/v1',
|
public_url='http://myserv:80/swift/v1',
|
||||||
requested_roles='admin',
|
internal_url='http://myserv:80/swift/v1',
|
||||||
rid='rid',
|
requested_roles='admin',
|
||||||
admin_url='http://myserv:80/swift')
|
relation_id='rid',
|
||||||
|
admin_url='http://myserv:80/swift')
|
||||||
|
|
||||||
def test_identity_changed(self):
|
def test_identity_changed(self):
|
||||||
_emit_cephconf = self.patch('emit_cephconf')
|
_emit_cephconf = self.patch('emit_cephconf')
|
||||||
_restart = self.patch('restart')
|
_restart = self.patch('restart')
|
||||||
|
@ -301,3 +336,49 @@ class CephRadosGWTests(CharmTestCase):
|
||||||
_emit_cephconf.assert_called()
|
_emit_cephconf.assert_called()
|
||||||
_restart.assert_called()
|
_restart.assert_called()
|
||||||
|
|
||||||
|
def test_canonical_url_ipv6(self):
|
||||||
|
ipv6_addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348'
|
||||||
|
self.resolve_address.return_value = ipv6_addr
|
||||||
|
self.assertEquals(ceph_hooks.canonical_url({}),
|
||||||
|
'http://[%s]' % ipv6_addr)
|
||||||
|
|
||||||
|
@patch.object(ceph_hooks, 'CONFIGS')
|
||||||
|
def test_cluster_changed(self, configs):
|
||||||
|
_id_joined = self.patch('identity_joined')
|
||||||
|
self.relation_ids.return_value = ['rid']
|
||||||
|
ceph_hooks.cluster_changed()
|
||||||
|
configs.write_all.assert_called()
|
||||||
|
_id_joined.assert_called_with(relid='rid')
|
||||||
|
|
||||||
|
def test_ha_relation_joined_no_vip(self):
|
||||||
|
self.test_config.set('vip', '')
|
||||||
|
ceph_hooks.ha_relation_joined()
|
||||||
|
self.sys.exit.assert_called_with(1)
|
||||||
|
|
||||||
|
def test_ha_relation_joined_vip(self):
|
||||||
|
self.test_config.set('ha-bindiface', 'eth8')
|
||||||
|
self.test_config.set('ha-mcastport', '5000')
|
||||||
|
self.test_config.set('vip', '10.0.0.10')
|
||||||
|
self.get_iface_for_address.return_value = 'eth7'
|
||||||
|
self.get_netmask_for_address.return_value = '255.255.0.0'
|
||||||
|
ceph_hooks.ha_relation_joined()
|
||||||
|
eth_params = ('params ip="10.0.0.10" cidr_netmask="255.255.0.0" '
|
||||||
|
'nic="eth7"')
|
||||||
|
resources = {'res_cephrg_haproxy': 'lsb:haproxy',
|
||||||
|
'res_cephrg_eth7_vip': 'ocf:heartbeat:IPaddr2'}
|
||||||
|
resource_params = {'res_cephrg_haproxy': 'op monitor interval="5s"',
|
||||||
|
'res_cephrg_eth7_vip': eth_params}
|
||||||
|
self.relation_set.assert_called_with(
|
||||||
|
init_services={'res_cephrg_haproxy': 'haproxy'},
|
||||||
|
corosync_bindiface='eth8',
|
||||||
|
corosync_mcastport='5000',
|
||||||
|
resource_params=resource_params,
|
||||||
|
resources=resources,
|
||||||
|
clones={'cl_cephrg_haproxy': 'res_cephrg_haproxy'})
|
||||||
|
|
||||||
|
def test_ha_relation_changed(self):
|
||||||
|
_id_joined = self.patch('identity_joined')
|
||||||
|
self.relation_get.return_value = True
|
||||||
|
self.relation_ids.return_value = ['rid']
|
||||||
|
ceph_hooks.ha_relation_changed()
|
||||||
|
_id_joined.assert_called_with(relid='rid')
|
||||||
|
|
Loading…
Reference in New Issue