Add missing files

This commit is contained in:
James Page 2013-10-22 16:15:28 -07:00
parent 242cf36a78
commit 0d1238d733
4 changed files with 226 additions and 0 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>glance</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

9
.pydevproject Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/glance/hooks</path>
<path>/glance/unit_tests</path>
</pydev_pathproperty>
</pydev_project>

View File

@ -0,0 +1,55 @@
from mock import patch
import glance_contexts as contexts
from test_utils import (
CharmTestCase
)
TO_PATCH = [
'relation_ids',
'is_relation_made',
'service_name',
'determine_haproxy_port',
'determine_api_port',
]
class TestGlanceContexts(CharmTestCase):
def setUp(self):
super(TestGlanceContexts, self).setUp(contexts, TO_PATCH)
def test_swift_not_related(self):
self.relation_ids.return_value = []
self.assertEquals(contexts.ObjectStoreContext()(), {})
def test_swift_related(self):
self.relation_ids.return_value = ['object-store:0']
self.assertEquals(contexts.ObjectStoreContext()(),
{'swift_store': True})
def test_ceph_not_related(self):
self.is_relation_made.return_value = False
self.assertEquals(contexts.CephGlanceContext()(), {})
def test_ceph_related(self):
self.is_relation_made.return_value = True
service = 'glance'
self.service_name.return_value = service
self.assertEquals(
contexts.CephGlanceContext()(),
{'rbd_pool': service,
'rbd_user': service})
def test_haproxy_configuration(self):
self.determine_haproxy_port.return_value = 9292
self.determine_api_port.return_value = 9282
self.assertEquals(
contexts.HAProxyContext()(),
{'service_ports': {'glance_api': [9292, 9282]},
'bind_port': 9282})
@patch('charmhelpers.contrib.openstack.context.https')
def test_apache_ssl_context_service_enabled(self,
https):
https.return_value = False
self.assertEquals(contexts.ApacheSSLContext()(), {})

View File

@ -0,0 +1,145 @@
from mock import patch, call, MagicMock
from collections import OrderedDict
import glance_utils as utils
from test_utils import (
CharmTestCase,
)
TO_PATCH = [
'config',
'log',
'ceph_create_pool',
'ceph_pool_exists',
'relation_ids',
'get_os_codename_package',
'get_os_codename_install_source',
'configure_installation_source',
'eligible_leader',
'templating',
'apt_update',
'apt_install',
'mkdir'
]
class TestGlanceUtils(CharmTestCase):
def setUp(self):
super(TestGlanceUtils, self).setUp(utils, TO_PATCH)
self.config.side_effect = self.test_config.get_all
@patch('subprocess.check_call')
def test_migrate_database(self, check_call):
'''It migrates database with cinder-manage'''
utils.migrate_database()
check_call.assert_called_with(['glance-manage', 'db_sync'])
def test_ensure_ceph_pool(self):
self.ceph_pool_exists.return_value = False
utils.ensure_ceph_pool(service='glance', replicas=3)
self.ceph_create_pool.assert_called_with(service='glance',
name='glance',
replicas=3)
def test_ensure_ceph_pool_already_exists(self):
self.ceph_pool_exists.return_value = True
utils.ensure_ceph_pool(service='glance', replicas=3)
self.assertFalse(self.ceph_create_pool.called)
@patch('os.path.exists')
def test_register_configs_apache(self, exists):
exists.return_value = False
self.get_os_codename_package.return_value = 'grizzly'
self.relation_ids.return_value = False
configs = utils.register_configs()
calls = []
for conf in [utils.GLANCE_REGISTRY_CONF,
utils.GLANCE_API_CONF,
utils.GLANCE_API_PASTE_INI,
utils.GLANCE_REGISTRY_PASTE_INI,
utils.HAPROXY_CONF,
utils.HTTPS_APACHE_CONF]:
calls.append(
call(conf,
utils.CONFIG_FILES[conf]['hook_contexts'])
)
configs.register.assert_has_calls(calls, any_order=True)
@patch('os.path.exists')
def test_register_configs_apache24(self, exists):
exists.return_value = True
self.get_os_codename_package.return_value = 'grizzly'
self.relation_ids.return_value = False
configs = utils.register_configs()
calls = []
for conf in [utils.GLANCE_REGISTRY_CONF,
utils.GLANCE_API_CONF,
utils.GLANCE_API_PASTE_INI,
utils.GLANCE_REGISTRY_PASTE_INI,
utils.HAPROXY_CONF,
utils.HTTPS_APACHE_24_CONF]:
calls.append(
call(conf,
utils.CONFIG_FILES[conf]['hook_contexts'])
)
configs.register.assert_has_calls(calls, any_order=True)
@patch('os.path.exists')
def test_register_configs_ceph(self, exists):
exists.return_value = False
self.get_os_codename_package.return_value = 'grizzly'
self.relation_ids.return_value = ['ceph:0']
configs = utils.register_configs()
calls = []
for conf in [utils.GLANCE_REGISTRY_CONF,
utils.GLANCE_API_CONF,
utils.GLANCE_API_PASTE_INI,
utils.GLANCE_REGISTRY_PASTE_INI,
utils.HAPROXY_CONF,
utils.HTTPS_APACHE_CONF,
utils.CEPH_CONF]:
calls.append(
call(conf,
utils.CONFIG_FILES[conf]['hook_contexts'])
)
configs.register.assert_has_calls(calls, any_order=True)
self.mkdir.assert_called_with('/etc/ceph')
def test_restart_map(self):
ex_map = OrderedDict([
(utils.GLANCE_REGISTRY_CONF, ['glance-registry']),
(utils.GLANCE_API_CONF, ['glance-api']),
(utils.GLANCE_API_PASTE_INI, ['glance-api']),
(utils.GLANCE_REGISTRY_PASTE_INI, ['glance-registry']),
(utils.CEPH_CONF, ['glance-api', 'glance-registry']),
(utils.HAPROXY_CONF, ['haproxy']),
(utils.HTTPS_APACHE_CONF, ['apache2']),
(utils.HTTPS_APACHE_24_CONF, ['apache2'])
])
self.assertEquals(ex_map, utils.restart_map())
@patch.object(utils, 'migrate_database')
def test_openstack_upgrade_leader(self, migrate):
self.config.side_effect = None
self.config.return_value = 'cloud:precise-havana'
self.eligible_leader.return_value = True
self.get_os_codename_install_source.return_value = 'havana'
configs = MagicMock()
utils.do_openstack_upgrade(configs)
self.assertTrue(configs.write_all.called)
configs.set_release.assert_called_with(openstack_release='havana')
self.assertTrue(migrate.called)
@patch.object(utils, 'migrate_database')
def test_openstack_upgrade_not_leader(self, migrate):
self.config.side_effect = None
self.config.return_value = 'cloud:precise-havana'
self.eligible_leader.return_value = False
self.get_os_codename_install_source.return_value = 'havana'
configs = MagicMock()
utils.do_openstack_upgrade(configs)
self.assertTrue(configs.write_all.called)
configs.set_release.assert_called_with(openstack_release='havana')
self.assertFalse(migrate.called)