From e3574ed3ffd504d16886acc746c553a26add6a6f Mon Sep 17 00:00:00 2001 From: Alex Ruiz Estradera Date: Mon, 5 Dec 2016 10:17:22 +0100 Subject: [PATCH] Make sure DHCP and Metadata agents are dead Change-Id: I37968533075dc8c4045f7a2e61279a89b8e54a50 --- .../manifests/midonet-disable-services.pp | 116 ++++++++++++++++++ .../manifests/midonet-neutron-configure.pp | 3 +- .../parser/functions/get_node_by_fqdn.rb | 19 +++ deployment_tasks.yaml | 21 +++- 4 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 deployment_scripts/puppet/manifests/midonet-disable-services.pp create mode 100644 deployment_scripts/puppet/modules/plugin_midonet/lib/puppet/parser/functions/get_node_by_fqdn.rb diff --git a/deployment_scripts/puppet/manifests/midonet-disable-services.pp b/deployment_scripts/puppet/manifests/midonet-disable-services.pp new file mode 100644 index 0000000..f524c22 --- /dev/null +++ b/deployment_scripts/puppet/manifests/midonet-disable-services.pp @@ -0,0 +1,116 @@ +# Copyright 2016 Midokura, SARL. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +notice('MODULAR: midonet-disable-services.pp') +include ::stdlib + +# Extract hiera data +$net_metadata = hiera_hash('network_metadata') + +$node = get_node_by_fqdn($net_metadata, $::fqdn) + +$roles = $node['node_roles'] + +$ovs_agent_name = $operatingsystem ? { + 'CentOS' => 'neutron-openvswitch-agent', + 'Ubuntu' => 'neutron-plugin-openvswitch-agent', +} + +$l3_agent_name = $operatingsystem ? { + 'CentOS' => 'neutron-l3-agent', + 'Ubuntu' => 'neutron-l3-agent' +} + +$dhcp_agent_name = $operatingsystem ? { + 'CentOS' => 'neutron-dhcp-agent', + 'Ubuntu' => 'neutron-dhcp-agent' +} + +$metadata_agent_name = $operatingsystem ? { + 'CentOS' => 'neutron-metadata-agent', + 'Ubuntu' => 'neutron-metadata-agent' +} + +if member($roles, 'primary-controller') { + + exec {'stop-dhcp-agent': + command => 'crm resource stop clone_neutron-dhcp-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status clone_neutron-dhcp-agent' + } -> + exec {'stop-metadata-agent': + command => 'crm resource stop clone_neutron-metadata-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status clone_neutron-metadata-agent' + } -> + exec {'delete-metadata-agent': + command => 'crm configure delete clone_neutron-metadata-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status clone_neutron-metadata-agent' + }-> + exec {'delete-dhcp-agent': + command => 'crm configure delete clone_neutron-dhcp-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status clone_neutron-dhcp-agent' + }-> + exec {'stop-dhcp-agent-N': + command => 'crm resource stop neutron-dhcp-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status neutron-dhcp-agent' + } -> + exec {'stop-metadata-agent-N': + command => 'crm resource stop neutron-metadata-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status neutron-metadata-agent' + } -> + exec {'delete-metadata-agent-N': + command => 'crm configure delete neutron-metadata-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status neutron-metadata-agent' + }-> + exec {'delete-dhcp-agent-N': + command => 'crm configure delete neutron-dhcp-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status neutron-dhcp-agent' + }-> + exec {'stop-l3-agent': + command => 'crm resource stop p_neutron-l3-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status p_neutron-l3-agent' + } -> + exec {'delete-l3-agent': + command => 'crm configure delete p_neutron-l3-agent', + path => '/usr/bin:/usr/sbin', + onlyif => 'crm resource status p_neutron-l3-agent' + }-> + service {$dhcp_agent_name: + ensure => stopped, + enable => false + }-> + + service {$metadata_agent_name: + ensure => stopped, + enable => false + } +} else { + + service {$dhcp_agent_name: + ensure => stopped, + enable => false + } + + service {$metadata_agent_name: + ensure => stopped, + enable => false + } +} diff --git a/deployment_scripts/puppet/manifests/midonet-neutron-configure.pp b/deployment_scripts/puppet/manifests/midonet-neutron-configure.pp index 9ccd667..ddcbc42 100644 --- a/deployment_scripts/puppet/manifests/midonet-neutron-configure.pp +++ b/deployment_scripts/puppet/manifests/midonet-neutron-configure.pp @@ -61,8 +61,7 @@ class {'::neutron': base_mac => 'fa:16:3e:00:00:00', allow_overlapping_ips => true, mac_generation_retries => '32', - dhcp_lease_duration => '600', - dhcp_agents_per_network => '2', + dhcp_agent_notification => false, report_interval => '10', rabbit_user => $rabbit_hash['user'], rabbit_host => ['localhost'], diff --git a/deployment_scripts/puppet/modules/plugin_midonet/lib/puppet/parser/functions/get_node_by_fqdn.rb b/deployment_scripts/puppet/modules/plugin_midonet/lib/puppet/parser/functions/get_node_by_fqdn.rb new file mode 100644 index 0000000..628fdbc --- /dev/null +++ b/deployment_scripts/puppet/modules/plugin_midonet/lib/puppet/parser/functions/get_node_by_fqdn.rb @@ -0,0 +1,19 @@ +module Puppet::Parser::Functions + newfunction(:get_node_by_fqdn, :type => :rvalue, :doc => <<-EOS +Return a node (node names are keys) that match the fqdn. +example: + get_node_by_fqdn($network_metadata_hash, 'test.function.com') +EOS + ) do |args| + errmsg = "get_node_by_fqdn($network_metadata_hash, $fqdn)" + n_metadata, fqdn = args + raise(Puppet::ParseError, "#{errmsg}: 1st argument should be a hash") if !n_metadata.is_a?(Hash) + raise(Puppet::ParseError, "#{errmsg}: 1st argument should be a valid network_metadata hash") if !n_metadata.has_key?('nodes') + raise(Puppet::ParseError, "#{errmsg}: 2nd argument should be an string") if !fqdn.is_a?(String) + nodes = n_metadata['nodes'] + # Using unrequired node_property bellow -- is a workaround for ruby 1.8 + mynode = nodes.reject {|node_name, node_property| fqdn != node_property['fqdn']} + raise(Puppet::ArgumentError, "#{errmsg}: No matching node found") if mynode.empty? + return mynode.values[0] + end +end diff --git a/deployment_tasks.yaml b/deployment_tasks.yaml index 351b429..da13748 100644 --- a/deployment_tasks.yaml +++ b/deployment_tasks.yaml @@ -533,7 +533,6 @@ - id: enable_nova_compute_service type: skipped - # POST-DEPLOYMENT TASKS # The task configure_default_route reinstalls openvswitch-switch @@ -651,8 +650,6 @@ - tunnel-zones-midonet reexecute_on: - deploy_changes - required_for: - - openstack-network-end version: 2.0.0 type: puppet parameters: @@ -894,6 +891,24 @@ condition: yaql_exp: "$.midonet.mem = true and $.midonet.mem_insights = true" +# Kill the unneccessary agents the hard way +- id: openstack-network-disable-services + role: + - primary-controller + - controller + requires: + - post_deployment_start + reexecute_on: + - deploy_changes + required_for: + - post_deployment_end + version: 2.0.0 + type: puppet + parameters: + puppet_manifest: puppet/manifests/midonet-disable-services.pp + puppet_modules: "puppet/modules/:/etc/puppet/modules/" + timeout: 1440 + # In the end.. # Grab the Old Astute.yaml and save it somewhere so we can parse it