From fe565ac4911cb3d3bb86fa9597f2f6a8d5f4cdfd Mon Sep 17 00:00:00 2001 From: "yolanda.robla@canonical.com" <> Date: Fri, 28 Mar 2014 12:02:09 +0100 Subject: [PATCH] added postgresql fixing tests --- .../charmhelpers/contrib/openstack/context.py | 29 ++++++++++++ hooks/pgsql-db-relation-changed | 1 + hooks/pgsql-db-relation-joined | 1 + hooks/quantum_contexts.pyc | Bin 0 -> 6064 bytes hooks/quantum_hooks.py | 21 +++++++++ hooks/quantum_hooks.pyc | Bin 0 -> 6481 bytes hooks/quantum_utils.py | 5 ++ hooks/quantum_utils.pyc | Bin 0 -> 12246 bytes metadata.yaml | 2 + revision | 2 +- templates/folsom/nova.conf | 2 +- templates/grizzly/nova.conf | 2 +- templates/havana/nova.conf | 2 +- unit_tests/test_quantum_hooks.py | 32 +++++++++++++ unit_tests/test_quantum_utils.py | 44 ++++++++++++------ 15 files changed, 124 insertions(+), 19 deletions(-) create mode 120000 hooks/pgsql-db-relation-changed create mode 120000 hooks/pgsql-db-relation-joined create mode 100644 hooks/quantum_contexts.pyc create mode 100644 hooks/quantum_hooks.pyc create mode 100644 hooks/quantum_utils.pyc diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index d254de18..125a1be2 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -155,6 +155,35 @@ class SharedDBContext(OSContextGenerator): return {} +class PostgresqlDBContext(OSContextGenerator): + interfaces = ['pgsql-db'] + + def __init__(self, database=None): + self.database = database + + def __call__(self): + self.database = self.database or config('database') + if self.database is None: + log('Could not generate postgresql_db context. ' + 'Missing required charm config options. ' + '(database name)') + raise OSContextError + ctxt = {} + + for rid in relation_ids(self.interfaces[0]): + for unit in related_units(rid): + ctxt = { + 'database_host': relation_get('host', rid=rid, unit=unit), + 'database': self.database, + 'database_user': relation_get('user', rid=rid, unit=unit), + 'database_password': relation_get('password', rid=rid, unit=unit), + 'database_type': 'postgresql', + } + if context_complete(ctxt): + return ctxt + return {} + + def db_ssl(rdata, ctxt, ssl_dir): if 'ssl_ca' in rdata and ssl_dir: ca_path = os.path.join(ssl_dir, 'db-client.ca') diff --git a/hooks/pgsql-db-relation-changed b/hooks/pgsql-db-relation-changed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/pgsql-db-relation-changed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/pgsql-db-relation-joined b/hooks/pgsql-db-relation-joined new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/pgsql-db-relation-joined @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_contexts.pyc b/hooks/quantum_contexts.pyc new file mode 100644 index 0000000000000000000000000000000000000000..57f5c1593f2515bfdde4dfb0e8ac49b658247795 GIT binary patch literal 6064 zcmb_gTXP#(5$+ku@;!F!ScwxS(e8#tS&*`1cU?tT7M$1{0*R80l6cXQni^}4t+7Wl z%A6x#DsdIX=79&QwhD?r06g%*Gd%Lf-=T_U3cl{SIA)W*Vp&J$^tn#=*I)OU(!ZuB zDr@hxyOjNv@%v+Z^*<~kAO9AGM4h5;QOC;VHg#;N+Z2|lU#3o(`XkgCA&Y00D6CL_ zlsco-AEV9~^~b3*PW=h$Oi+K4I+N6&qRv!0x=i6T^-oaeMA{yqaEAJ`)S0FJN$Q+T zr4hYKDJ$y@+|q-{2ck%e2IK)exCek z>Rccn8($=UhB`Hw^&0uJ^c)ZVI{DcB4f5xxbBO|*|J6BCZ_u(@B6SHruhB9K&!@tR zsjx=Noo|spFN?fM{wY$kvpLf1Zel?e#E~Itx&*aj@LVB6}v$^zKA$^O~ z6kEt&qURQU0^59-{PWalkbi*(b(-AUu3v;fga6>KRku+!<0!&F8#fBN+MGaZOG(4+ z?RmbR)GIuSi*6ik23uwd)kKA!3F62Nd~K$4f%4s96c~Mc2$nNr7{XmHH)JiZ+f#lW zxFR!&!W$Sjh_v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|F~s3K zAdO#3T;p`o;n?jkiKi(Io7CChf}wJRE2({c1}vQOetJ#%fTMwKq2N2!lvOP^$7V~_ y@@#3gG-X#n82FSbcJ`6h_$Xu`n36SWP2zXdIx#XnUR|orRp+ZSC2QtnrSxA{P#Ylt literal 0 HcmV?d00001 diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index f9901c22..db8831d5 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -5,6 +5,7 @@ from base64 import b64decode from charmhelpers.core.hookenv import ( log, ERROR, WARNING, config, + is_relation_made, relation_get, relation_set, relation_ids, @@ -77,6 +78,8 @@ def config_changed(): # Re-run joined hooks as config might have changed for r_id in relation_ids('shared-db'): db_joined(relation_id=r_id) + for r_id in relation_ids('pgsql-db'): + pgsql_db_joined(relation_id=r_id) for r_id in relation_ids('amqp'): amqp_joined(relation_id=r_id) if valid_plugin(): @@ -95,12 +98,29 @@ def upgrade_charm(): @hooks.hook('shared-db-relation-joined') def db_joined(relation_id=None): + if is_relation_made('pgsql-db'): + # raise error + e = ('Attempting to associate a mysql database when there is already ' + 'associated a postgresql one') + log(e, level=ERROR) + raise Exception(e) relation_set(username=config('database-user'), database=config('database'), hostname=unit_get('private-address'), relation_id=relation_id) +@hooks.hook('pgsql-db-relation-joined') +def pgsql_db_joined(): + if is_relation_made('shared-db'): + # raise error + e = ('Attempting to associate a postgresql database when there is already ' + 'associated a mysql one') + log(e, level=ERROR) + raise Exception(e) + relation_set(database=config('database')) + + @hooks.hook('amqp-relation-joined') def amqp_joined(relation_id=None): relation_set(relation_id=relation_id, @@ -118,6 +138,7 @@ def amqp_departed(): @hooks.hook('shared-db-relation-changed', + 'pgsql-db-relation-changed', 'amqp-relation-changed', 'cluster-relation-changed', 'cluster-relation-joined') diff --git a/hooks/quantum_hooks.pyc b/hooks/quantum_hooks.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a361fbb0edad670e621531c1a34e701696df281d GIT binary patch literal 6481 zcmcIoO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N3}E}KId&S zvlPqvz`)RG3_kd7CR zSOdix;hFVKqOG?ux#hvKS>9}?HV2&sQ?NKFyVX?j(1viJf}mhu+R}p{5X>RfGuIYv zJuRXHN?Il2!hSrwYw@zpx+gHx`wTswzu{(3^DI=6^`>9%$xRJ_QeZF>heu|I*@sH_ z!R%t?p7UU8W?EmTf5=`PipKeX5ALJ6i|5#kc%_zXzuOK_U5qjEmjx(&{x?O>j6)DJ z4rxpo!1u6KUPhn(BtT7SSAB;0qFDj=Lp3L1INuL5++YMR5|7T=q&S-PFvRZ~v4ZRG zHKV@NXw~7w-irnHlc>HtmWJXnEJ9_dvQd#HRQX+$voX2mjp?1du^u%mUNLFrm0bPP zgVUT&?-$<%pVMQn)TUBa)QEC+atN`m{b>d|rD*44GEPxynv>>6`2~jgnSyE@FC!hM zY>sBMT8ZMOncSASp3yU=Zb~ctk%m^QD^m{~typKBdn?wYnZfXjk6qPlUcF>6^8*o6 z0jJt!)p1t4If?TrI-O7O*i|6kk7PEqn(gYAz0*(>Ic#>}(Zs^z&iol*zxl~u7kt`zFgw%DA2la~KfE_FvCs{qMrFXK^Rs)P z)YA-le~Ca{AidJ;+|vntQ&nS#$$K<)9IGgzQAlG75t4O z_X5o&#aEcvndXC8u=6*3{4F0Fd<1;_nvd&z{52nchesz)XzOj)K6Ju&gOHV;ujuGw zWUq3z_hR4KUOfAc^qj;A_f;d;`}gR+WA|tP(;7^H&D!4gFW5-S#J@e zvoMix*WCM!&FZ(uce6mMpIn0YF^bA@@F}jHFA@u8eaZoW#&+Gk%foo>Y zM({hwPDgjJh-)xO-Qb#@{onSZHf)_p>2_NE)X9hD!sb6Y1)DO7o=yCHwyX D0^uHa literal 0 HcmV?d00001 diff --git a/metadata.yaml b/metadata.yaml index 296e34fe..637f8953 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -21,6 +21,8 @@ provides: requires: shared-db: interface: mysql-shared + pgsql-db: + interface: pgsql amqp: interface: rabbitmq peers: diff --git a/revision b/revision index 4b9026d8..900731ff 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -63 +64 diff --git a/templates/folsom/nova.conf b/templates/folsom/nova.conf index baaab6f7..9d44e9d6 100644 --- a/templates/folsom/nova.conf +++ b/templates/folsom/nova.conf @@ -7,7 +7,7 @@ verbose=True api_paste_config=/etc/nova/api-paste.ini enabled_apis=metadata multi_host=True -sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} +sql_connection = {{ database_type }}://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} quantum_metadata_proxy_shared_secret={{ shared_secret }} service_quantum_metadata_proxy=True # Access to message bus diff --git a/templates/grizzly/nova.conf b/templates/grizzly/nova.conf index f79a9e9a..407e4ea3 100644 --- a/templates/grizzly/nova.conf +++ b/templates/grizzly/nova.conf @@ -7,7 +7,7 @@ verbose=True api_paste_config=/etc/nova/api-paste.ini enabled_apis=metadata multi_host=True -sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} +sql_connection = {{ database_type }}://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} quantum_metadata_proxy_shared_secret={{ shared_secret }} service_quantum_metadata_proxy=True # Access to message bus diff --git a/templates/havana/nova.conf b/templates/havana/nova.conf index 850514fc..a5fef3e4 100644 --- a/templates/havana/nova.conf +++ b/templates/havana/nova.conf @@ -7,7 +7,7 @@ verbose= {{ verbose }} api_paste_config=/etc/nova/api-paste.ini enabled_apis=metadata multi_host=True -sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} +sql_connection = {{ database_type }}://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %} neutron_metadata_proxy_shared_secret={{ shared_secret }} service_neutron_metadata_proxy=True # Access to message bus diff --git a/unit_tests/test_quantum_hooks.py b/unit_tests/test_quantum_hooks.py index 09338d3a..a60e49c7 100644 --- a/unit_tests/test_quantum_hooks.py +++ b/unit_tests/test_quantum_hooks.py @@ -39,6 +39,7 @@ TO_PATCH = [ 'lsb_release', 'stop_services', 'b64decode', + 'is_relation_made' ] @@ -115,6 +116,7 @@ class TestQuantumHooks(CharmTestCase): self.assertTrue(_config_changed.called) def test_db_joined(self): + self.is_relation_made.return_value = False self.unit_get.return_value = 'myhostname' self._call_hook('shared-db-relation-joined') self.relation_set.assert_called_with( @@ -124,6 +126,32 @@ class TestQuantumHooks(CharmTestCase): relation_id=None ) + def test_db_joined_with_postgresql(self): + self.is_relation_made.return_value = True + + with self.assertRaises(Exception) as context: + hooks.db_joined() + self.assertEqual(context.exception.message, + 'Attempting to associate a mysql database when there ' + 'is already associated a postgresql one') + + def test_postgresql_db_joined(self): + self.unit_get.return_value = 'myhostname' + self.is_relation_made.return_value = False + self._call_hook('pgsql-db-relation-joined') + self.relation_set.assert_called_with( + database='nova' + ) + + def test_postgresql_joined_with_db(self): + self.is_relation_made.return_value = True + + with self.assertRaises(Exception) as context: + hooks.pgsql_db_joined() + self.assertEqual(context.exception.message, + 'Attempting to associate a postgresql database when there ' + 'is already associated a mysql one') + def test_amqp_joined(self): self._call_hook('amqp-relation-joined') self.relation_set.assert_called_with( @@ -140,6 +168,10 @@ class TestQuantumHooks(CharmTestCase): self._call_hook('shared-db-relation-changed') self.CONFIGS.write_all.assert_called() + def test_pgsql_db_changed(self): + self._call_hook('pgsql-db-relation-changed') + self.CONFIGS.write_all.assert_called() + def test_nm_changed(self): self.relation_get.return_value = "cert" self._call_hook('quantum-network-service-relation-changed') diff --git a/unit_tests/test_quantum_utils.py b/unit_tests/test_quantum_utils.py index 2824cf40..9249e841 100644 --- a/unit_tests/test_quantum_utils.py +++ b/unit_tests/test_quantum_utils.py @@ -1,4 +1,5 @@ from mock import MagicMock, call, patch +import collections import charmhelpers.contrib.openstack.templating as templating @@ -46,6 +47,16 @@ TO_PATCH = [ class TestQuantumUtils(CharmTestCase): + def assertDictEqual(self, d1, d2, msg=None): # assertEqual uses for dicts + for k,v1 in d1.iteritems(): + self.assertIn(k, d2, msg) + v2 = d2[k] + if(isinstance(v1, collections.Iterable) and + not isinstance(v1, basestring)): + self.assertItemsEqual(v1, v2, msg) + else: + self.assertEqual(v1, v2, msg) + def setUp(self): super(TestQuantumUtils, self).setUp(quantum_utils, TO_PATCH) self.networking_name.return_value = 'neutron' @@ -144,7 +155,6 @@ class TestQuantumUtils(CharmTestCase): quantum_utils.NEUTRON_L3_AGENT_CONF, quantum_utils.NEUTRON_OVS_PLUGIN_CONF, quantum_utils.EXT_PORT_CONF] - print configs.register.calls() for conf in confs: configs.register.assert_any_call( conf, @@ -155,26 +165,30 @@ class TestQuantumUtils(CharmTestCase): def test_restart_map_ovs(self): self.config.return_value = 'ovs' ex_map = { - quantum_utils.NEUTRON_L3_AGENT_CONF: ['neutron-l3-agent'], - quantum_utils.NEUTRON_METERING_AGENT_CONF: - ['neutron-metering-agent'], - quantum_utils.NEUTRON_LBAAS_AGENT_CONF: - ['neutron-lbaas-agent'], - quantum_utils.NEUTRON_OVS_PLUGIN_CONF: - ['neutron-plugin-openvswitch-agent'], - quantum_utils.NOVA_CONF: ['nova-api-metadata'], - quantum_utils.NEUTRON_METADATA_AGENT_CONF: - ['neutron-metadata-agent'], - quantum_utils.NEUTRON_DHCP_AGENT_CONF: ['neutron-dhcp-agent'], - quantum_utils.NEUTRON_DNSMASQ_CONF: ['neutron-dhcp-agent'], quantum_utils.NEUTRON_CONF: ['neutron-l3-agent', 'neutron-dhcp-agent', 'neutron-metadata-agent', 'neutron-plugin-openvswitch-agent', 'neutron-metering-agent', - 'neutron-lbaas-agent'] + 'neutron-lbaas-agent'], + quantum_utils.NEUTRON_DNSMASQ_CONF: ['neutron-dhcp-agent'], + quantum_utils.NEUTRON_LBAAS_AGENT_CONF: + ['neutron-lbaas-agent'], + quantum_utils.NEUTRON_OVS_PLUGIN_CONF: + ['neutron-plugin-openvswitch-agent'], + quantum_utils.NEUTRON_METADATA_AGENT_CONF: + ['neutron-metadata-agent'], + quantum_utils.NEUTRON_VPNAAS_AGENT_CONF: ['neutron-plugin-vpn-agent', + 'neutron-vpn-agent'], + quantum_utils.NEUTRON_L3_AGENT_CONF: ['neutron-l3-agent'], + quantum_utils.NEUTRON_DHCP_AGENT_CONF: ['neutron-dhcp-agent'], + quantum_utils.NEUTRON_FWAAS_CONF: ['neutron-l3-agent'], + quantum_utils.NEUTRON_METERING_AGENT_CONF: + ['neutron-metering-agent', 'neutron-plugin-metering-agent'], + quantum_utils.NOVA_CONF: ['nova-api-metadata'], } - self.assertEquals(quantum_utils.restart_map(), ex_map) + + self.assertDictEqual(quantum_utils.restart_map(), ex_map) def test_register_configs_nvp(self): self.config.return_value = 'nvp'