diff --git a/.project b/.project
new file mode 100644
index 00000000..531bd052
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ glance
+
+
+
+
+
+ org.python.pydev.PyDevBuilder
+
+
+
+
+
+ org.python.pydev.pythonNature
+
+
diff --git a/.pydevproject b/.pydevproject
new file mode 100644
index 00000000..82893fc0
--- /dev/null
+++ b/.pydevproject
@@ -0,0 +1,9 @@
+
+
+python 2.7
+Default
+
+/glance/hooks
+/glance/unit_tests
+
+
diff --git a/unit_tests/test_glance_contexts.py b/unit_tests/test_glance_contexts.py
new file mode 100644
index 00000000..d86ae8a3
--- /dev/null
+++ b/unit_tests/test_glance_contexts.py
@@ -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()(), {})
diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py
new file mode 100644
index 00000000..d32a090a
--- /dev/null
+++ b/unit_tests/test_glance_utils.py
@@ -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)