From 4eb19f80802a27376515af3945851af41566fd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ole=C5=9B?= Date: Wed, 21 Oct 2015 14:41:44 +0200 Subject: [PATCH] Do not use hardcoded db port --- examples/openstack/openstack.py | 34 ++++++++++++++----- resources/cinder_puppet/actions/run.pp | 4 ++- resources/cinder_puppet/meta.yaml | 3 ++ resources/glance_puppet/actions/run.pp | 4 ++- resources/glance_puppet/meta.yaml | 3 ++ .../glance_registry_puppet/actions/run.pp | 6 ++-- resources/glance_registry_puppet/meta.yaml | 3 ++ resources/keystone_puppet/actions/run.pp | 3 +- resources/keystone_puppet/meta.yaml | 3 ++ resources/mariadb_service/actions/remove.yaml | 1 + resources/mariadb_service/actions/run.yaml | 5 ++- .../neutron_server_puppet/actions/run.pp | 5 +-- resources/neutron_server_puppet/meta.yaml | 3 ++ .../nova_conductor_puppet/actions/run.pp | 2 +- resources/nova_puppet/actions/run.pp | 3 +- resources/nova_puppet/meta.yaml | 3 ++ 16 files changed, 67 insertions(+), 18 deletions(-) diff --git a/examples/openstack/openstack.py b/examples/openstack/openstack.py index b5137ab..f12ad51 100755 --- a/examples/openstack/openstack.py +++ b/examples/openstack/openstack.py @@ -201,7 +201,10 @@ def setup_keystone(node, librarian, mariadb_service, openstack_rabbitmq_user): keystone_db_user.connect(keystone_puppet, { 'user_name': 'db_user', 'user_password': 'db_password', - 'db_host' : 'db_host' + }) + mariadb_service.connect(keystone_puppet, { + 'ip': 'db_host', + 'port': 'db_port', }) return {'keystone_puppet': keystone_puppet, 'keystone_db': keystone_db, @@ -293,6 +296,9 @@ def setup_neutron_api(node, mariadb_service, admin_user, keystone_puppet, servic 'db_name':'db_name', 'user_password':'db_password', 'db_host' : 'db_host'}) + mariadb_service.connect(neutron_server_puppet, { + 'port': 'db_port', + 'ip' : 'db_host'}) node.connect(neutron_server_puppet) admin_user.connect(neutron_server_puppet, { 'user_name': 'auth_user', @@ -434,8 +440,10 @@ def setup_cinder(node, librarian, rabbitmq_service, mariadb_service, keystone_pu cinder_db_user.connect(cinder_puppet, { 'user_name':'db_user', 'db_name':'db_name', - 'user_password':'db_password', - 'db_host' : 'db_host'}) + 'user_password':'db_password'}) + mariadb_service.connect(cinder_puppet, { + 'port': 'db_port', + 'ip': 'db_host'}) keystone_puppet.connect(cinder_puppet, {'ip': 'keystone_host', 'admin_port': 'keystone_port'}) #or non admin port? services_tenant.connect(cinder_keystone_user) cinder_keystone_user.connect(cinder_keystone_role) @@ -470,6 +478,7 @@ def setup_cinder_api(node, cinder_puppet): cinder_puppet.connect(cinder_api_puppet, { 'keystone_host': 'keystone_auth_host', 'keystone_port': 'keystone_auth_port'}) + evapi.add_react(cinder_puppet.name, cinder_api_puppet.name, actions=('update',)) return {'cinder_api_puppet': cinder_api_puppet} def setup_cinder_scheduler(node, cinder_puppet): @@ -477,6 +486,7 @@ def setup_cinder_scheduler(node, cinder_puppet): cinder_scheduler_puppet = vr.create('cinder_scheduler_puppet', 'resources/cinder_scheduler_puppet', {})[0] node.connect(cinder_scheduler_puppet) cinder_puppet.connect(cinder_scheduler_puppet) + evapi.add_react(cinder_puppet.name, cinder_scheduler_puppet.name, actions=('update',)) return {'cinder_scheduler_puppet': cinder_scheduler_puppet} def setup_cinder_volume(node, cinder_puppet): @@ -484,6 +494,7 @@ def setup_cinder_volume(node, cinder_puppet): cinder_volume_puppet = vr.create('cinder_volume_puppet', 'resources/cinder_volume_puppet', {})[0] node.connect(cinder_volume_puppet) cinder_puppet.connect(cinder_volume_puppet) + evapi.add_react(cinder_puppet.name, cinder_volume_puppet.name, actions=('update',)) return {'cinder_volume_puppet': cinder_volume_puppet} def setup_nova(node, librarian, mariadb_service, rabbitmq_service, admin_user, openstack_vhost, services_tenant, keystone_puppet, openstack_rabbitmq_user): @@ -545,12 +556,12 @@ def setup_nova(node, librarian, mariadb_service, rabbitmq_service, admin_user, o 'admin_port': 'keystone_admin_port', 'admin_token': 'admin_token'}) mariadb_service.connect(nova_puppet, { - 'ip':'db_host'}) + 'ip':'db_host', + 'port': 'db_port'}) nova_db_user.connect(nova_puppet, { 'user_name':'db_user', 'db_name':'db_name', - 'user_password':'db_password', - 'db_host' : 'db_host'}) + 'user_password':'db_password'}) nova_puppet.connect(nova_keystone_service_endpoint, { 'ip': ['ip', 'keystone_host', 'public_ip', 'internal_ip', 'admin_ip'], 'port': ['admin_port', 'internal_port', 'public_port'], @@ -572,6 +583,7 @@ def setup_nova_api(node, nova_puppet, neutron_agents_metadata): 'keystone_password': 'admin_password', 'keystone_host': 'auth_host', 'keystone_port': 'auth_port'}) + evapi.add_react(nova_puppet.name, nova_api_puppet.name, actions=('update',)) nova_api_puppet.connect(neutron_agents_metadata, {'ip': 'metadata_ip'}) return {'nova_api_puppet': nova_api_puppet} @@ -581,6 +593,7 @@ def setup_nova_conductor(node, nova_puppet, nova_api_puppet): node.connect(nova_conductor_puppet) nova_puppet.connect(nova_conductor_puppet) evapi.add_dep(nova_api_puppet.name, nova_conductor_puppet.name, actions=('run',)) + evapi.add_react(nova_puppet.name, nova_conductor_puppet.name, actions=('update',)) return {'nova_conductor': nova_conductor_puppet} def setup_nova_scheduler(node, nova_puppet, nova_api_puppet): @@ -593,6 +606,7 @@ def setup_nova_scheduler(node, nova_puppet, nova_api_puppet): node.connect(nova_scheduler_puppet) evapi.add_dep(nova_puppet.name, nova_scheduler_puppet.name, actions=('run',)) evapi.add_dep(nova_api_puppet.name, nova_scheduler_puppet.name, actions=('run',)) + evapi.add_react(nova_puppet.name, nova_scheduler_puppet.name, actions=('update',)) return {'nova_scheduler_puppet': nova_scheduler_puppet} def setup_nova_compute(node, librarian, nova_puppet, nova_api_puppet, neutron_server_puppet, neutron_keystone_service_endpoint): @@ -694,6 +708,9 @@ def setup_glance_api(node, librarian, mariadb_service, admin_user, keystone_pupp 'db_name':'db_name', 'user_password':'db_password', 'db_host' : 'db_host'}) + mariadb_service.connect(glance_api_puppet,{ + 'port': 'db_port', + 'ip': 'db_host'}) keystone_puppet.connect(glance_api_puppet, {'ip': 'keystone_host', 'admin_port': 'keystone_port'}) #or non admin port? services_tenant.connect(glance_keystone_user) glance_keystone_user.connect(glance_keystone_role) @@ -729,6 +746,7 @@ def setup_glance_registry(node, glance_api_puppet): glance_registry_puppet = vr.create('glance_registry_puppet', 'resources/glance_registry_puppet', {})[0] node.connect(glance_registry_puppet) glance_api_puppet.connect(glance_registry_puppet) + evapi.add_react(glance_api_puppet.name, glance_registry_puppet.name, actions=('update',)) # API and registry should not listen same ports # should not use the same log destination and a pipeline, # so disconnect them and restore the defaults @@ -760,7 +778,7 @@ def validate(): @click.command() -def deploy(): +def create(): r= {} r.update(setup_base()) r.update(setup_keystone(r['node1'], r['librarian_node1'], @@ -794,7 +812,7 @@ def deploy(): if __name__ == '__main__': - main.add_command(deploy) + main.add_command(create) main() if PROFILE: diff --git a/resources/cinder_puppet/actions/run.pp b/resources/cinder_puppet/actions/run.pp index 1be5df4..d8daffd 100644 --- a/resources/cinder_puppet/actions/run.pp +++ b/resources/cinder_puppet/actions/run.pp @@ -5,6 +5,8 @@ $ip = $resource['input']['ip']['value'] $db_user = $resource['input']['db_user']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] +$db_host = $resource['input']['db_host']['value'] +$db_port = $resource['input']['db_port']['value'] $database_connection = $resource['input']['database_connection']['value'] $database_idle_timeout = $resource['input']['database_idle_timeout']['value'] @@ -60,7 +62,7 @@ $mysql_module = $resource['input']['mysql_module']['value'] $sql_idle_timeout = $resource['input']['sql_idle_timeout']['value'] class {'cinder': - database_connection => "mysql://${db_user}:${db_password}@${ip}/${db_name}", + database_connection => "mysql://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}", database_idle_timeout => $database_idle_timeout, database_min_pool_size => $database_min_pool_size, database_max_pool_size => $database_max_pool_size, diff --git a/resources/cinder_puppet/meta.yaml b/resources/cinder_puppet/meta.yaml index 21862b3..37d77ed 100644 --- a/resources/cinder_puppet/meta.yaml +++ b/resources/cinder_puppet/meta.yaml @@ -168,6 +168,9 @@ input: db_host: schema: str! value: + db_port: + schema: int! + value: port: schema: int! diff --git a/resources/glance_puppet/actions/run.pp b/resources/glance_puppet/actions/run.pp index 76d1c16..10b10b1 100644 --- a/resources/glance_puppet/actions/run.pp +++ b/resources/glance_puppet/actions/run.pp @@ -5,6 +5,8 @@ $ip = $resource['input']['ip']['value'] $db_user = $resource['input']['db_user']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] +$db_host = $resource['input']['db_host']['value'] +$db_port = $resource['input']['db_port']['value'] $filesystem_store_datadir = $resource['input']['filesystem_store_datadir']['value'] @@ -84,7 +86,7 @@ class {'glance::api': key_file => $key_file, ca_file => $ca_file, known_stores => $known_stores, - database_connection => "mysql://${db_user}:${db_password}@${ip}/${db_name}", + database_connection => "mysql://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}", database_idle_timeout => $database_idle_timeout, image_cache_dir => $image_cache_dir, os_region_name => $os_region_name, diff --git a/resources/glance_puppet/meta.yaml b/resources/glance_puppet/meta.yaml index 1708378..0eebea6 100644 --- a/resources/glance_puppet/meta.yaml +++ b/resources/glance_puppet/meta.yaml @@ -150,6 +150,9 @@ input: db_host: schema: str! value: + db_port: + schema: int! + value: keystone_host: schema: str! diff --git a/resources/glance_registry_puppet/actions/run.pp b/resources/glance_registry_puppet/actions/run.pp index 09f8b45..02c34aa 100644 --- a/resources/glance_registry_puppet/actions/run.pp +++ b/resources/glance_registry_puppet/actions/run.pp @@ -5,6 +5,8 @@ $ip = $resource['input']['ip']['value'] $db_user = $resource['input']['db_user']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] +$db_host = $resource['input']['db_host']['value'] +$db_port = $resource['input']['db_port']['value'] $keystone_password = $resource['input']['keystone_password']['value'] $package_ensure = $resource['input']['package_ensure']['value'] @@ -49,7 +51,7 @@ class {'glance::registry': bind_port => $bind_port, log_file => $log_file, log_dir => $log_dir, - database_connection => "mysql://${db_user}:${db_password}@${ip}/${db_name}", + database_connection => "mysql://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}", database_idle_timeout => $database_idle_timeout, auth_type => $auth_type, auth_host => $auth_host, @@ -69,4 +71,4 @@ class {'glance::registry': sync_db => $sync_db, mysql_module => $mysql_module, sql_idle_timeout => $sql_idle_timeout, -} \ No newline at end of file +} diff --git a/resources/glance_registry_puppet/meta.yaml b/resources/glance_registry_puppet/meta.yaml index 3d66489..4b27fe1 100644 --- a/resources/glance_registry_puppet/meta.yaml +++ b/resources/glance_registry_puppet/meta.yaml @@ -114,6 +114,9 @@ input: db_host: schema: str! value: + db_port: + schema: str! + value: keystone_host: schema: str! diff --git a/resources/keystone_puppet/actions/run.pp b/resources/keystone_puppet/actions/run.pp index 71222ed..087ad4d 100644 --- a/resources/keystone_puppet/actions/run.pp +++ b/resources/keystone_puppet/actions/run.pp @@ -6,6 +6,7 @@ $db_user = $resource['input']['db_user']['value'] $db_host = $resource['input']['db_host']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] +$db_port = $resource['input']['db_port']['value'] $admin_port = $resource['input']['admin_port']['value'] $port = $resource['input']['port']['value'] @@ -14,7 +15,7 @@ class {'keystone': verbose => true, catalog_type => 'sql', admin_token => $admin_token, - database_connection => "mysql://$db_user:$db_password@$db_host/$db_name", + database_connection => "mysql://$db_user:$db_password@$db_host:$db_port/$db_name", public_port => "$port", admin_port => "$admin_port", token_driver => 'keystone.token.persistence.backends.sql.Token' diff --git a/resources/keystone_puppet/meta.yaml b/resources/keystone_puppet/meta.yaml index f04aa93..ac0d6fb 100644 --- a/resources/keystone_puppet/meta.yaml +++ b/resources/keystone_puppet/meta.yaml @@ -18,6 +18,9 @@ input: db_host: schema: str! value: + db_port: + schema: int! + value: admin_port: schema: int! diff --git a/resources/mariadb_service/actions/remove.yaml b/resources/mariadb_service/actions/remove.yaml index 512b8f5..0ec5e3f 100644 --- a/resources/mariadb_service/actions/remove.yaml +++ b/resources/mariadb_service/actions/remove.yaml @@ -6,3 +6,4 @@ name: {{ resource_name }} image: {{ image }} state: absent + - file: path=/var/lib/docker/data/{{resource_name}} state=absent diff --git a/resources/mariadb_service/actions/run.yaml b/resources/mariadb_service/actions/run.yaml index 671c602..0719a98 100644 --- a/resources/mariadb_service/actions/run.yaml +++ b/resources/mariadb_service/actions/run.yaml @@ -1,15 +1,18 @@ - hosts: [{{host}}] sudo: yes tasks: + - file: path=/var/lib/docker/data/{{resource_name}} state=directory - name: mariadb container docker: name: {{ resource_name }} image: {{ image }} - state: running + state: reloaded ports: - {{ port }}:3306 env: MYSQL_ROOT_PASSWORD: {{ root_password }} + volumes: + - /var/lib/docker/data/{{resource_name}}:/var/lib/mysql - shell: docker exec -t {{ resource_name }} mysql -p{{ root_password }} -uroot -e "SELECT 1" register: result diff --git a/resources/neutron_server_puppet/actions/run.pp b/resources/neutron_server_puppet/actions/run.pp index 47fcb2c..1d7d831 100644 --- a/resources/neutron_server_puppet/actions/run.pp +++ b/resources/neutron_server_puppet/actions/run.pp @@ -4,6 +4,7 @@ $ip = $resource['input']['ip']['value'] $db_user = $resource['input']['db_user']['value'] $db_host = $resource['input']['db_host']['value'] +$db_port = $resource['input']['db_port']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] @@ -47,7 +48,7 @@ $report_interval = $resource['input']['report_interval']['value'] class { 'neutron::server': enabled => true, manage_service => true, - database_connection => "mysql://${db_user}:${db_password}@${db_host}/${db_name}", + database_connection => "mysql://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}", package_ensure => $package_ensure, auth_password => $auth_password, auth_type => $auth_type, @@ -89,4 +90,4 @@ class { 'neutron::server': # Remove external class dependency Service <| title == 'neutron-server' |> { require => undef -} \ No newline at end of file +} diff --git a/resources/neutron_server_puppet/meta.yaml b/resources/neutron_server_puppet/meta.yaml index 8233da6..009847a 100644 --- a/resources/neutron_server_puppet/meta.yaml +++ b/resources/neutron_server_puppet/meta.yaml @@ -23,6 +23,9 @@ input: db_host: schema: str! value: + db_port: + schema: int! + value: package_ensure: schema: str diff --git a/resources/nova_conductor_puppet/actions/run.pp b/resources/nova_conductor_puppet/actions/run.pp index 271fc17..93daf76 100644 --- a/resources/nova_conductor_puppet/actions/run.pp +++ b/resources/nova_conductor_puppet/actions/run.pp @@ -19,4 +19,4 @@ class { 'nova::conductor': manage_service => true, ensure_package => $ensure_package, workers => $workers, -} \ No newline at end of file +} diff --git a/resources/nova_puppet/actions/run.pp b/resources/nova_puppet/actions/run.pp index 81a5982..46bf2b4 100644 --- a/resources/nova_puppet/actions/run.pp +++ b/resources/nova_puppet/actions/run.pp @@ -4,6 +4,7 @@ $db_user = $resource['input']['db_user']['value'] $db_password = $resource['input']['db_password']['value'] $db_name = $resource['input']['db_name']['value'] $db_host = $resource['input']['db_host']['value'] +$db_port = $resource['input']['db_port']['value'] $glance_api_servers_host = $resource['input']['glance_api_servers_host']['value'] $glance_api_servers_port = $resource['input']['glance_api_servers_port']['value'] @@ -72,7 +73,7 @@ $logdir = $resource['input']['logdir']['value'] $os_region_name = $resource['input']['os_region_name']['value'] class { 'nova': - database_connection => "mysql://${db_user}:${db_password}@${db_host}/${db_name}?charset=utf8", + database_connection => "mysql://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}?charset=utf8", ensure_package => $ensure_package, slave_connection => $slave_connection, database_idle_timeout => $database_idle_timeout, diff --git a/resources/nova_puppet/meta.yaml b/resources/nova_puppet/meta.yaml index 590ea03..fd16f39 100644 --- a/resources/nova_puppet/meta.yaml +++ b/resources/nova_puppet/meta.yaml @@ -205,6 +205,9 @@ input: db_host: schema: str! value: + db_port: + schema: int! + value: keystone_password: schema: str!