[yolanda] Add postgresql support
Rejig templates to use includes, add Postgresql context for neutron and quantum config files.
This commit is contained in:
commit
3bfcfb5a0a
3
Makefile
3
Makefile
@ -2,8 +2,7 @@
|
||||
PYTHON := /usr/bin/env python
|
||||
|
||||
lint:
|
||||
@flake8 --exclude hooks/charmhelpers hooks
|
||||
@flake8 --exclude hooks/charmhelpers unit_tests
|
||||
@flake8 --exclude hooks/charmhelpers hooks unit_tests
|
||||
@charm proof
|
||||
|
||||
test:
|
||||
|
15
README.txt
Normal file
15
README.txt
Normal file
@ -0,0 +1,15 @@
|
||||
=====================
|
||||
nova-cloud-controller
|
||||
=====================
|
||||
|
||||
Cloud controller node for Openstack nova. Contains nova-schedule, nova-api, nova-network and nova-objectstore.
|
||||
|
||||
******************************************************
|
||||
Special considerations to be deployed using Postgresql
|
||||
******************************************************
|
||||
|
||||
juju deploy nova-cloud-controller
|
||||
juju deploy postgresql
|
||||
|
||||
juju add-relation "nova-cloud-controller:pgsql-nova-db" "postgresql:db"
|
||||
juju add-relation "nova-cloud-controller:pgsql-neutron-db" "postgresql:db"
|
@ -147,7 +147,8 @@ class SharedDBContext(OSContextGenerator):
|
||||
'database_host': rdata.get('db_host'),
|
||||
'database': self.database,
|
||||
'database_user': self.user,
|
||||
'database_password': rdata.get(password_setting)
|
||||
'database_password': rdata.get(password_setting),
|
||||
'database_type': 'mysql'
|
||||
}
|
||||
if context_complete(ctxt):
|
||||
db_ssl(rdata, ctxt, self.ssl_dir)
|
||||
@ -155,6 +156,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')
|
||||
|
@ -152,6 +152,7 @@ class NeutronCCContext(context.NeutronContext):
|
||||
|
||||
|
||||
class IdentityServiceContext(context.IdentityServiceContext):
|
||||
|
||||
def __call__(self):
|
||||
ctxt = super(IdentityServiceContext, self).__call__()
|
||||
if not ctxt:
|
||||
@ -163,3 +164,11 @@ class IdentityServiceContext(context.IdentityServiceContext):
|
||||
ctxt['service_port'])
|
||||
ctxt['keystone_ec2_url'] = ec2_tokens
|
||||
return ctxt
|
||||
|
||||
|
||||
class NovaPostgresqlDBContext(context.PostgresqlDBContext):
|
||||
interfaces = ['pgsql-nova-db']
|
||||
|
||||
|
||||
class NeutronPostgresqlDBContext(context.PostgresqlDBContext):
|
||||
interfaces = ['pgsql-neutron-db']
|
||||
|
@ -13,7 +13,9 @@ from charmhelpers.core.hookenv import (
|
||||
UnregisteredHookError,
|
||||
config,
|
||||
charm_dir,
|
||||
is_relation_made,
|
||||
log,
|
||||
ERROR,
|
||||
relation_get,
|
||||
relation_ids,
|
||||
relation_set,
|
||||
@ -125,6 +127,13 @@ def amqp_changed():
|
||||
|
||||
@hooks.hook('shared-db-relation-joined')
|
||||
def db_joined():
|
||||
if is_relation_made('pgsql-nova-db') or is_relation_made('pgsql-neutron-db'):
|
||||
# error, postgresql is used
|
||||
e = ('Attempting to associate a mysql database when there is already '
|
||||
'associated a postgresql one')
|
||||
log(e, level=ERROR)
|
||||
raise Exception(e)
|
||||
|
||||
relation_set(nova_database=config('database'),
|
||||
nova_username=config('database-user'),
|
||||
nova_hostname=unit_get('private-address'))
|
||||
@ -135,6 +144,30 @@ def db_joined():
|
||||
neutron_hostname=unit_get('private-address'))
|
||||
|
||||
|
||||
@hooks.hook('pgsql-nova-db-relation-joined')
|
||||
def pgsql_nova_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('pgsql-neutron-db-relation-joined')
|
||||
def pgsql_neutron_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('neutron-database'))
|
||||
|
||||
|
||||
@hooks.hook('shared-db-relation-changed')
|
||||
@restart_on_change(restart_map())
|
||||
def db_changed():
|
||||
@ -155,6 +188,30 @@ def db_changed():
|
||||
for rid in relation_ids('cloud-compute')]
|
||||
|
||||
|
||||
@hooks.hook('pgsql-nova-db-relation-changed')
|
||||
@restart_on_change(restart_map())
|
||||
def postgresql_nova_db_changed():
|
||||
if 'pgsql-nova-db' not in CONFIGS.complete_contexts():
|
||||
log('pgsql-nova-db relation incomplete. Peer not ready?')
|
||||
return
|
||||
CONFIGS.write(NOVA_CONF)
|
||||
|
||||
if eligible_leader(CLUSTER_RES):
|
||||
migrate_database()
|
||||
log('Triggering remote cloud-compute restarts.')
|
||||
[compute_joined(rid=rid, remote_restart=True)
|
||||
for rid in relation_ids('cloud-compute')]
|
||||
|
||||
|
||||
@hooks.hook('pgsql-neutron-db-relation-changed')
|
||||
@restart_on_change(restart_map())
|
||||
def postgresql_neutron_db_changed():
|
||||
if network_manager() in ['neutron', 'quantum']:
|
||||
plugin = neutron_plugin()
|
||||
# DB config might have been moved to main neutron.conf in H?
|
||||
CONFIGS.write(neutron_plugin_attribute(plugin, 'config'))
|
||||
|
||||
|
||||
@hooks.hook('image-service-relation-changed')
|
||||
@restart_on_change(restart_map())
|
||||
def image_service_changed():
|
||||
@ -389,7 +446,9 @@ def ha_changed():
|
||||
'identity-service-relation-broken',
|
||||
'image-service-relation-broken',
|
||||
'nova-volume-service-relation-broken',
|
||||
'shared-db-relation-broken'
|
||||
'shared-db-relation-broken',
|
||||
'pgsql-nova-db-relation-broken',
|
||||
'pgsql-neutron-db-relation-broken',
|
||||
'quantum-network-service-relation-broken')
|
||||
def relation_broken():
|
||||
CONFIGS.write_all()
|
||||
|
@ -55,6 +55,7 @@ BASE_PACKAGES = [
|
||||
'haproxy',
|
||||
'python-keystoneclient',
|
||||
'python-mysqldb',
|
||||
'python-psycopg2',
|
||||
'uuid',
|
||||
]
|
||||
|
||||
@ -96,6 +97,7 @@ BASE_RESOURCE_MAP = OrderedDict([
|
||||
'contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR),
|
||||
context.SharedDBContext(
|
||||
relation_prefix='nova', ssl_dir=NOVA_CONF_DIR),
|
||||
nova_cc_context.NovaPostgresqlDBContext(),
|
||||
context.ImageServiceContext(),
|
||||
context.OSConfigFlagContext(),
|
||||
context.SubordinateConfigContext(
|
||||
@ -120,6 +122,7 @@ BASE_RESOURCE_MAP = OrderedDict([
|
||||
database=config('neutron-database'),
|
||||
relation_prefix='neutron',
|
||||
ssl_dir=QUANTUM_CONF_DIR),
|
||||
nova_cc_context.NeutronPostgresqlDBContext(),
|
||||
nova_cc_context.HAProxyContext(),
|
||||
nova_cc_context.IdentityServiceContext(),
|
||||
nova_cc_context.NeutronCCContext()],
|
||||
@ -140,6 +143,7 @@ BASE_RESOURCE_MAP = OrderedDict([
|
||||
database=config('neutron-database'),
|
||||
relation_prefix='neutron',
|
||||
ssl_dir=NEUTRON_CONF_DIR),
|
||||
nova_cc_context.NeutronPostgresqlDBContext(),
|
||||
nova_cc_context.IdentityServiceContext(),
|
||||
nova_cc_context.NeutronCCContext(),
|
||||
nova_cc_context.HAProxyContext()],
|
||||
@ -213,6 +217,10 @@ def resource_map():
|
||||
resource_map[conf]['contexts'].append(
|
||||
nova_cc_context.NeutronCCContext())
|
||||
|
||||
# update for postgres
|
||||
resource_map[conf]['contexts'].append(
|
||||
nova_cc_context.NeutronPostgresqlDBContext())
|
||||
|
||||
# nova-conductor for releases >= G.
|
||||
if os_release('nova-common') not in ['essex', 'folsom']:
|
||||
resource_map['/etc/nova/nova.conf']['services'] += ['nova-conductor']
|
||||
|
1
hooks/pgsql-neutron-db-relation-broken
Symbolic link
1
hooks/pgsql-neutron-db-relation-broken
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-neutron-db-relation-changed
Symbolic link
1
hooks/pgsql-neutron-db-relation-changed
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-neutron-db-relation-joined
Symbolic link
1
hooks/pgsql-neutron-db-relation-joined
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-broken
Symbolic link
1
hooks/pgsql-nova-db-relation-broken
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-changed
Symbolic link
1
hooks/pgsql-nova-db-relation-changed
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-joined
Symbolic link
1
hooks/pgsql-nova-db-relation-joined
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
@ -12,6 +12,10 @@ provides:
|
||||
requires:
|
||||
shared-db:
|
||||
interface: mysql-shared
|
||||
pgsql-nova-db:
|
||||
interface: pgsql
|
||||
pgsql-neutron-db:
|
||||
interface: pgsql
|
||||
amqp:
|
||||
interface: rabbitmq
|
||||
image-service:
|
||||
|
5
setup.cfg
Normal file
5
setup.cfg
Normal file
@ -0,0 +1,5 @@
|
||||
[nosetests]
|
||||
verbosity=2
|
||||
with-coverage=1
|
||||
cover-erase=1
|
||||
cover-package=hooks
|
@ -16,7 +16,7 @@
|
||||
--verbose
|
||||
--ec2_private_dns_show_ip
|
||||
{% if database_host -%}
|
||||
--sql_connection=mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}
|
||||
--sql_connection={{ database_type }}://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}
|
||||
{% endif -%}
|
||||
{% if rabbitmq_host -%}
|
||||
--rabbit_host={{ rabbitmq_host }}
|
||||
|
@ -24,9 +24,7 @@ compute_driver=libvirt.LibvirtDriver
|
||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||
{% endif -%}
|
||||
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
{% endif -%}
|
||||
{% include "parts/database" %}
|
||||
|
||||
{% if rabbitmq_host -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
|
@ -11,7 +11,7 @@ local_ip = {{ local_ip }}
|
||||
|
||||
[DATABASE]
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
reconnect_interval = 2
|
||||
{% else -%}
|
||||
connection = sqlite:////var/lib/quantum/quantum.sqlite
|
||||
|
@ -24,31 +24,9 @@ compute_driver=libvirt.LibvirtDriver
|
||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||
{% endif -%}
|
||||
|
||||
{% if database_host -%}
|
||||
sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}
|
||||
{% endif -%}
|
||||
{% include "parts/database" %}
|
||||
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = true
|
||||
rabbit_durable_queues = false
|
||||
{% endif %}
|
||||
{% else %}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
rabbit_use_ssl=True
|
||||
rabbit_port={{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca %}
|
||||
kombu_ssl_ca_certs={{rabbit_ssl_ca}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif -%}
|
||||
{% include "parts/rabbitmq" %}
|
||||
|
||||
{% if glance_api_servers -%}
|
||||
glance_api_servers = {{ glance_api_servers }}
|
||||
|
@ -21,32 +21,15 @@ control_exchange = quantum
|
||||
notification_driver = quantum.openstack.common.notifier.rpc_notifier
|
||||
default_notification_level = INFO
|
||||
notification_topics = notifications
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = true
|
||||
rabbit_durable_queues = false
|
||||
{% endif %}
|
||||
{% else %}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
rabbit_use_ssl=True
|
||||
rabbit_port={{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca %}
|
||||
kombu_ssl_ca_certs={{rabbit_ssl_ca}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif -%}
|
||||
|
||||
{% include "parts/database" %}
|
||||
|
||||
{% include "parts/rabbitmq" %}
|
||||
|
||||
{% if neutron_security_groups -%}
|
||||
allow_overlapping_ips = True
|
||||
{% endif -%}
|
||||
|
||||
|
||||
[QUOTAS]
|
||||
quota_driver = quantum.db.quota_db.DbQuotaDriver
|
||||
{% if neutron_security_groups -%}
|
||||
|
@ -23,27 +23,8 @@ service_plugins = neutron.services.metering.metering_plugin.MeteringPlugin
|
||||
allow_overlapping_ips = True
|
||||
neutron_firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
|
||||
{% endif -%}
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = true
|
||||
rabbit_durable_queues = false
|
||||
{% endif %}
|
||||
{% else %}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
rabbit_use_ssl=True
|
||||
rabbit_port={{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca %}
|
||||
kombu_ssl_ca_certs={{rabbit_ssl_ca}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif -%}
|
||||
|
||||
{% include "parts/rabbitmq" %}
|
||||
|
||||
[quotas]
|
||||
quota_driver = neutron.db.quota_db.DbQuotaDriver
|
||||
@ -68,5 +49,7 @@ admin_user = {{ admin_user }}
|
||||
admin_password = {{ admin_password }}
|
||||
{% endif -%}
|
||||
|
||||
{% include "parts/section-database" %}
|
||||
|
||||
[lbaas]
|
||||
[service_providers]
|
||||
|
@ -24,31 +24,9 @@ compute_driver=libvirt.LibvirtDriver
|
||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||
{% endif -%}
|
||||
|
||||
{% if database_host -%}
|
||||
sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}
|
||||
{% endif -%}
|
||||
{% include "parts/database" %}
|
||||
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = true
|
||||
rabbit_durable_queues = false
|
||||
{% endif %}
|
||||
{% else %}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
rabbit_use_ssl=True
|
||||
rabbit_port={{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca %}
|
||||
kombu_ssl_ca_certs={{rabbit_ssl_ca}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif -%}
|
||||
{% include "parts/rabbitmq" %}
|
||||
|
||||
{% if glance_api_servers -%}
|
||||
glance_api_servers = {{ glance_api_servers }}
|
||||
|
@ -9,10 +9,3 @@ nvp_password = {{ nvp_password }}
|
||||
nvp_controllers = {{ nvp_controllers }}
|
||||
default_tz_uuid = {{ nvp_tz_uuid }}
|
||||
default_l3_gw_service_uuid = {{ nvp_l3_uuid }}
|
||||
|
||||
[database]
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
{% else -%}
|
||||
connection = sqlite:////var/lib/neutron/neutron.sqlite
|
||||
{% endif -%}
|
||||
|
@ -4,13 +4,6 @@ tenant_network_type = gre
|
||||
enable_tunneling = True
|
||||
local_ip = {{ local_ip }}
|
||||
|
||||
[database]
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
{% else -%}
|
||||
connection = sqlite:////var/lib/neutron/neutron.sqlite
|
||||
{% endif -%}
|
||||
|
||||
[securitygroup]
|
||||
{% if neutron_security_groups -%}
|
||||
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
|
||||
|
@ -27,27 +27,7 @@ allow_overlapping_ips = True
|
||||
neutron_firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
|
||||
{% endif -%}
|
||||
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = true
|
||||
rabbit_durable_queues = false
|
||||
{% endif %}
|
||||
{% else %}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port %}
|
||||
rabbit_use_ssl=True
|
||||
rabbit_port={{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca %}
|
||||
kombu_ssl_ca_certs={{rabbit_ssl_ca}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif -%}
|
||||
{% include "parts/rabbitmq" %}
|
||||
|
||||
[quotas]
|
||||
quota_driver = neutron.db.quota_db.DbQuotaDriver
|
||||
@ -72,12 +52,7 @@ admin_user = {{ admin_user }}
|
||||
admin_password = {{ admin_password }}
|
||||
{% endif -%}
|
||||
|
||||
[database]
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
{% else -%}
|
||||
connection = sqlite:////var/lib/neutron/neutron.sqlite
|
||||
{% endif -%}
|
||||
{% include "parts/section-database" %}
|
||||
|
||||
[service_providers]
|
||||
service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
|
||||
|
3
templates/parts/database
Normal file
3
templates/parts/database
Normal file
@ -0,0 +1,3 @@
|
||||
{% if database_host -%}
|
||||
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 %}
|
||||
{% endif -%}
|
21
templates/parts/rabbitmq
Normal file
21
templates/parts/rabbitmq
Normal file
@ -0,0 +1,21 @@
|
||||
{% if rabbitmq_host or rabbitmq_hosts -%}
|
||||
rabbit_userid = {{ rabbitmq_user }}
|
||||
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
|
||||
rabbit_password = {{ rabbitmq_password }}
|
||||
{% if rabbitmq_hosts -%}
|
||||
rabbit_hosts = {{ rabbitmq_hosts }}
|
||||
{% if rabbitmq_ha_queues -%}
|
||||
rabbit_ha_queues = True
|
||||
rabbit_durable_queues = False
|
||||
{% endif -%}
|
||||
{% else -%}
|
||||
rabbit_host = {{ rabbitmq_host }}
|
||||
{% endif -%}
|
||||
{% if rabbit_ssl_port -%}
|
||||
rabbit_use_ssl = True
|
||||
rabbit_port = {{ rabbit_ssl_port }}
|
||||
{% if rabbit_ssl_ca -%}
|
||||
kombu_ssl_ca_certs = {{ rabbit_ssl_ca }}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
4
templates/parts/section-database
Normal file
4
templates/parts/section-database
Normal file
@ -0,0 +1,4 @@
|
||||
{% if database_host -%}
|
||||
[database]
|
||||
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 %}
|
||||
{% endif -%}
|
@ -1,7 +1,8 @@
|
||||
from mock import MagicMock, patch
|
||||
|
||||
from mock import call, MagicMock, patch
|
||||
from test_utils import CharmTestCase
|
||||
|
||||
with patch('charmhelpers.core.hookenv.config') as config:
|
||||
config.return_value = 'neutron'
|
||||
import nova_cc_utils as utils
|
||||
|
||||
_reg = utils.register_configs
|
||||
@ -15,7 +16,6 @@ import nova_cc_hooks as hooks
|
||||
utils.register_configs = _reg
|
||||
utils.restart_map = _map
|
||||
|
||||
|
||||
TO_PATCH = [
|
||||
'api_port',
|
||||
'apt_update',
|
||||
@ -29,8 +29,11 @@ TO_PATCH = [
|
||||
'determine_packages',
|
||||
'determine_ports',
|
||||
'open_port',
|
||||
'is_relation_made',
|
||||
'log',
|
||||
'relation_get',
|
||||
'relation_set',
|
||||
'relation_ids',
|
||||
'ssh_compute_add',
|
||||
'ssh_known_hosts_b64',
|
||||
'ssh_authorized_keys_b64',
|
||||
@ -42,6 +45,7 @@ TO_PATCH = [
|
||||
'eligible_leader',
|
||||
'keystone_ca_cert_b64',
|
||||
'neutron_plugin',
|
||||
'migrate_database',
|
||||
]
|
||||
|
||||
|
||||
@ -63,6 +67,7 @@ class NovaCCHooksTests(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NovaCCHooksTests, self).setUp(hooks, TO_PATCH)
|
||||
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.charm_dir.return_value = '/var/lib/juju/charms/nova/charm'
|
||||
@ -138,3 +143,93 @@ class NovaCCHooksTests(CharmTestCase):
|
||||
quantum_url='http://nova-cc-host1:9696', quantum_plugin='nvp',
|
||||
relation_id=None,
|
||||
**FAKE_KS_AUTH_CFG)
|
||||
|
||||
def test_db_joined(self):
|
||||
self.unit_get.return_value = 'nova.foohost.com'
|
||||
self.is_relation_made.return_value = False
|
||||
hooks.db_joined()
|
||||
self.relation_set.assert_called_with(nova_database='nova',
|
||||
nova_username='nova',
|
||||
nova_hostname='nova.foohost.com')
|
||||
self.unit_get.assert_called_with('private-address')
|
||||
|
||||
def test_postgresql_nova_db_joined(self):
|
||||
self.is_relation_made.return_value = False
|
||||
hooks.pgsql_nova_db_joined()
|
||||
self.relation_set.assert_called_with(database='nova')
|
||||
|
||||
def test_postgresql_neutron_db_joined(self):
|
||||
self.is_relation_made.return_value = False
|
||||
hooks.pgsql_neutron_db_joined()
|
||||
self.relation_set.assert_called_with(database='neutron')
|
||||
|
||||
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_nova_joined_with_db(self):
|
||||
self.is_relation_made.return_value = True
|
||||
|
||||
with self.assertRaises(Exception) as context:
|
||||
hooks.pgsql_nova_db_joined()
|
||||
self.assertEqual(context.exception.message,
|
||||
'Attempting to associate a postgresql database when there is already '
|
||||
'associated a mysql one')
|
||||
|
||||
def test_postgresql_neutron_joined_with_db(self):
|
||||
self.is_relation_made.return_value = True
|
||||
|
||||
with self.assertRaises(Exception) as context:
|
||||
hooks.pgsql_neutron_db_joined()
|
||||
self.assertEqual(context.exception.message,
|
||||
'Attempting to associate a postgresql database when there is already '
|
||||
'associated a mysql one')
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
def test_db_changed_missing_relation_data(self, configs):
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = []
|
||||
hooks.db_changed()
|
||||
self.log.assert_called_with(
|
||||
'shared-db relation incomplete. Peer not ready?'
|
||||
)
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
def test_postgresql_nova_db_changed_missing_relation_data(self, configs):
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = []
|
||||
hooks.postgresql_nova_db_changed()
|
||||
self.log.assert_called_with(
|
||||
'pgsql-nova-db relation incomplete. Peer not ready?'
|
||||
)
|
||||
|
||||
def _shared_db_test(self, configs):
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = ['shared-db']
|
||||
configs.write = MagicMock()
|
||||
hooks.db_changed()
|
||||
|
||||
def _postgresql_db_test(self, configs):
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = ['pgsql-nova-db']
|
||||
configs.write = MagicMock()
|
||||
hooks.postgresql_nova_db_changed()
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
def test_db_changed(self, configs):
|
||||
self._shared_db_test(configs)
|
||||
self.assertEquals([call('/etc/nova/nova.conf')],
|
||||
configs.write.call_args_list)
|
||||
self.migrate_database.assert_called_with()
|
||||
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
def test_postgresql_db_changed(self, configs):
|
||||
self._postgresql_db_test(configs)
|
||||
self.assertEquals([call('/etc/nova/nova.conf')],
|
||||
configs.write.call_args_list)
|
||||
self.migrate_database.assert_called_with()
|
||||
|
@ -347,7 +347,9 @@ class NovaCCUtilsTests(CharmTestCase):
|
||||
ssh_dir.return_value = '/tmp/foo'
|
||||
self.assertEquals(utils.authorized_keys(), '/tmp/foo/authorized_keys')
|
||||
ssh_dir.assert_called_with(None)
|
||||
self.assertEquals(utils.authorized_keys('bar'), '/tmp/foo/authorized_keys')
|
||||
self.assertEquals(
|
||||
utils.authorized_keys('bar'),
|
||||
'/tmp/foo/authorized_keys')
|
||||
ssh_dir.assert_called_with('bar')
|
||||
|
||||
@patch.object(utils, 'known_hosts')
|
||||
|
Loading…
Reference in New Issue
Block a user