diff --git a/deployment/puppet/cluster/manifests/neutron/dhcp.pp b/deployment/puppet/cluster/manifests/neutron/dhcp.pp index cffe1b0b7d..259f37b20d 100644 --- a/deployment/puppet/cluster/manifests/neutron/dhcp.pp +++ b/deployment/puppet/cluster/manifests/neutron/dhcp.pp @@ -24,7 +24,7 @@ class cluster::neutron::dhcp ( #TODO (bogdando) move to extras ha wrappers cluster::corosync::cs_service {'dhcp': - ocf_script => 'ocf-neutron-dhcp-agent', + ocf_script => 'neutron-dhcp-agent', csr_parameters => { 'plugin_config' => $plugin_config, 'remove_artifacts_on_stop_start' => true, diff --git a/deployment/puppet/cluster/manifests/neutron/l3.pp b/deployment/puppet/cluster/manifests/neutron/l3.pp index c07223d4f6..dbdadcffbb 100644 --- a/deployment/puppet/cluster/manifests/neutron/l3.pp +++ b/deployment/puppet/cluster/manifests/neutron/l3.pp @@ -20,7 +20,7 @@ define cluster::neutron::l3 ( #TODO (bogdando) move to extras ha wrappers cluster::corosync::cs_service {'l3': - ocf_script => 'ocf-neutron-l3-agent', + ocf_script => 'neutron-l3-agent', csr_parameters => { 'plugin_config' => $plugin_config, 'remove_artifacts_on_stop_start' => true, diff --git a/deployment/puppet/cluster/manifests/neutron/metadata.pp b/deployment/puppet/cluster/manifests/neutron/metadata.pp index 8ac38cdbb9..c9d1e105ea 100644 --- a/deployment/puppet/cluster/manifests/neutron/metadata.pp +++ b/deployment/puppet/cluster/manifests/neutron/metadata.pp @@ -13,7 +13,7 @@ class cluster::neutron::metadata ( #TODO (bogdando) move to extras ha wrappers cluster::corosync::cs_service {'neutron-metadata-agent': - ocf_script => 'ocf-neutron-metadata-agent', + ocf_script => 'neutron-metadata-agent', csr_complex_type => 'clone', csr_ms_metadata => { 'interleave' => 'true' }, csr_mon_intr => '60', diff --git a/deployment/puppet/cluster/manifests/neutron/ovs.pp b/deployment/puppet/cluster/manifests/neutron/ovs.pp index 8846bfdb22..f6909b2867 100644 --- a/deployment/puppet/cluster/manifests/neutron/ovs.pp +++ b/deployment/puppet/cluster/manifests/neutron/ovs.pp @@ -13,7 +13,7 @@ class cluster::neutron::ovs ( } cluster::corosync::cs_service {'ovs': - ocf_script => 'ocf-neutron-ovs-agent', + ocf_script => 'neutron-ovs-agent', csr_complex_type => 'clone', csr_ms_metadata => { 'interleave' => 'true' }, csr_parameters => { 'plugin_config' => $plugin_config }, diff --git a/files/fuel-ha-utils/ocf/ceilometer-agent-central b/files/fuel-ha-utils/ocf/ceilometer-agent-central index 6dcfcf031d..9da834a39d 100644 --- a/files/fuel-ha-utils/ocf/ceilometer-agent-central +++ b/files/fuel-ha-utils/ocf/ceilometer-agent-central @@ -146,31 +146,15 @@ END ####################################################################### # Functions invoked by resource manager actions -ceilometer_agent_central_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - - local int - local cnt - - int="$1" - cnt=${#int} - echo $int |egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} - ceilometer_agent_central_validate() { local rc check_binary $OCF_RESKEY_binary check_binary netstat - ceilometer_agent_central_check_port $OCF_RESKEY_amqp_server_port + + if ! validate_port "${OCF_RESKEY_amqp_server_port}"; then + return ${OCF_ERR_CONFIGURED} + fi # A config file on shared storage that is not available # during probes is OK. @@ -189,7 +173,7 @@ ceilometer_agent_central_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } ceilometer_agent_central_status() { diff --git a/files/fuel-ha-utils/ocf/ceilometer-agent-compute b/files/fuel-ha-utils/ocf/ceilometer-agent-compute index 98c0adb366..ccda351016 100644 --- a/files/fuel-ha-utils/ocf/ceilometer-agent-compute +++ b/files/fuel-ha-utils/ocf/ceilometer-agent-compute @@ -146,31 +146,15 @@ END ####################################################################### # Functions invoked by resource manager actions -ceilometer_agent_compute_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - - local int - local cnt - - int="$1" - cnt=${#int} - echo $int |egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} - ceilometer_agent_compute_validate() { local rc check_binary $OCF_RESKEY_binary check_binary netstat - ceilometer_agent_compute_check_port $OCF_RESKEY_amqp_server_port + + if ! validate_port $OCF_RESKEY_amqp_server_port; then + return ${OCF_ERR_CONFIGURED} + fi # A config file on shared storage that is not available # during probes is OK. @@ -189,7 +173,7 @@ ceilometer_agent_compute_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } ceilometer_agent_compute_status() { diff --git a/files/fuel-ha-utils/ocf/ceilometer-alarm-evaluator b/files/fuel-ha-utils/ocf/ceilometer-alarm-evaluator index 383e046bc8..c0c84a4aa7 100644 --- a/files/fuel-ha-utils/ocf/ceilometer-alarm-evaluator +++ b/files/fuel-ha-utils/ocf/ceilometer-alarm-evaluator @@ -135,24 +135,6 @@ END ####################################################################### # Functions invoked by resource manager actions -ceilometer_alarm_evaluator_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - - local int - local cnt - - int="$1" - cnt=${#int} - echo $int |egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} ceilometer_alarm_evaluator_validate() { local rc @@ -160,6 +142,10 @@ ceilometer_alarm_evaluator_validate() { check_binary $OCF_RESKEY_binary check_binary netstat + if ! validate_port $OCF_RESKEY_amqp_server_port; then + return ${OCF_ERR_CONFIGURED} + fi + # A config file on shared storage that is not available # during probes is OK. if [ ! -f $OCF_RESKEY_config ]; then @@ -177,7 +163,7 @@ ceilometer_alarm_evaluator_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } ceilometer_alarm_evaluator_status() { diff --git a/files/fuel-ha-utils/ocf/heat-engine b/files/fuel-ha-utils/ocf/heat-engine index 83a97daa4e..d439890acc 100644 --- a/files/fuel-ha-utils/ocf/heat-engine +++ b/files/fuel-ha-utils/ocf/heat-engine @@ -147,31 +147,15 @@ END ####################################################################### # Functions invoked by resource manager actions -heat_engine_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - - local int - local cnt - - int="$1" - cnt=${#int} - echo $int |egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} - service_validate() { local rc check_binary $OCF_RESKEY_binary check_binary netstat - heat_engine_check_port $OCF_RESKEY_amqp_server_port + + if ! validate_port $OCF_RESKEY_amqp_server_port; then + return ${OCF_ERR_CONFIGURED} + fi # A config file on shared storage that is not available # during probes is OK. @@ -190,7 +174,7 @@ service_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } service_status() { @@ -232,8 +216,6 @@ service_status() { service_monitor() { local rc local pid - local rc_amqp - local engine_amqp_check service_status rc=$? diff --git a/files/fuel-ha-utils/ocf/ocf-neutron-dhcp-agent b/files/fuel-ha-utils/ocf/neutron-dhcp-agent similarity index 99% rename from files/fuel-ha-utils/ocf/ocf-neutron-dhcp-agent rename to files/fuel-ha-utils/ocf/neutron-dhcp-agent index 7dbbacbae5..c31fb6fd1f 100644 --- a/files/fuel-ha-utils/ocf/ocf-neutron-dhcp-agent +++ b/files/fuel-ha-utils/ocf/neutron-dhcp-agent @@ -249,7 +249,7 @@ neutron_dhcp_agent_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } neutron_dhcp_agent_status() { diff --git a/files/fuel-ha-utils/ocf/ocf-neutron-l3-agent b/files/fuel-ha-utils/ocf/neutron-l3-agent similarity index 99% rename from files/fuel-ha-utils/ocf/ocf-neutron-l3-agent rename to files/fuel-ha-utils/ocf/neutron-l3-agent index 17d7a96dea..2139143112 100644 --- a/files/fuel-ha-utils/ocf/ocf-neutron-l3-agent +++ b/files/fuel-ha-utils/ocf/neutron-l3-agent @@ -258,7 +258,7 @@ neutron_l3_agent_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } neutron_l3_agent_status() { diff --git a/files/fuel-ha-utils/ocf/ocf-neutron-metadata-agent b/files/fuel-ha-utils/ocf/neutron-metadata-agent similarity index 99% rename from files/fuel-ha-utils/ocf/ocf-neutron-metadata-agent rename to files/fuel-ha-utils/ocf/neutron-metadata-agent index 968c83cb63..10899610a4 100644 --- a/files/fuel-ha-utils/ocf/ocf-neutron-metadata-agent +++ b/files/fuel-ha-utils/ocf/neutron-metadata-agent @@ -189,7 +189,7 @@ neutron_metadata_agent_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } diff --git a/files/fuel-ha-utils/ocf/ocf-neutron-ovs-agent b/files/fuel-ha-utils/ocf/neutron-ovs-agent similarity index 99% rename from files/fuel-ha-utils/ocf/ocf-neutron-ovs-agent rename to files/fuel-ha-utils/ocf/neutron-ovs-agent index 3d3811019c..9f3eb6cb49 100644 --- a/files/fuel-ha-utils/ocf/ocf-neutron-ovs-agent +++ b/files/fuel-ha-utils/ocf/neutron-ovs-agent @@ -213,7 +213,7 @@ neutron_ovs_agent_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } diff --git a/files/fuel-ha-utils/ocf/nova-compute b/files/fuel-ha-utils/ocf/nova-compute index 3a7ef013d6..24d41f6a68 100644 --- a/files/fuel-ha-utils/ocf/nova-compute +++ b/files/fuel-ha-utils/ocf/nova-compute @@ -157,32 +157,15 @@ END ####################################################################### # Functions invoked by resource manager actions -nova_compute_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - - local int - local cnt - - int="$1" - cnt=${#int} - echo $int | egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} - nova_compute_validate() { local rc check_binary $OCF_RESKEY_binary check_binary netstat - nova_compute_check_port $OCF_RESKEY_amqp_server_port + if ! validate_port $OCF_RESKEY_amqp_server_port; then + return ${OCF_ERR_CONFIGURED} + fi # A config file on shared storage that is not available # during probes is OK. @@ -201,7 +184,7 @@ nova_compute_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } nova_compute_status() { @@ -270,7 +253,7 @@ nova_compute_start() { # run the actual nova-compute daemon. Don't use ocf_run as we're sending the tool's output # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. - su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file=$OCF_RESKEY_config \ + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file=${OCF_RESKEY_config} \ $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid ocf_log debug "Create pid file: ${OCF_RESKEY_pid} with content $(cat ${OCF_RESKEY_pid})" diff --git a/files/fuel-ha-utils/ocf/nova-network b/files/fuel-ha-utils/ocf/nova-network index 489bdf8d02..40efd0b66b 100644 --- a/files/fuel-ha-utils/ocf/nova-network +++ b/files/fuel-ha-utils/ocf/nova-network @@ -194,24 +194,6 @@ END ####################################################################### # Functions invoked by resource manager actions -nova_network_check_port() { -# This function has been taken from the squid RA and improved a bit -# The length of the integer must be 4 -# Examples of valid port: "1080", "0080" -# Examples of invalid port: "1080bad", "0", "0000", "" - local int - local cnt - - int="$1" - cnt=${#int} - echo $int | egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*' - - if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then - ocf_log err "Invalid port number: $1" - exit $OCF_ERR_CONFIGURED - fi -} - nova_network_validate() { local rc @@ -221,7 +203,9 @@ nova_network_validate() { check_binary iptables check_binary ip6tables - nova_network_check_port $OCF_RESKEY_amqp_server_port + if ! validate_port $OCF_RESKEY_amqp_server_port; then + return ${OCF_ERR_CONFIGURED} + fi # A config file on shared storage that is not available # during probes is OK. @@ -230,7 +214,7 @@ nova_network_validate() { ocf_log err "Config $OCF_RESKEY_config doesn't exist" return $OCF_ERR_INSTALLED fi - ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + ocf_log warn "Config $OCF_RESKEY_config not available during a probe" fi getent passwd $OCF_RESKEY_user >/dev/null 2>&1 @@ -240,7 +224,7 @@ nova_network_validate() { return $OCF_ERR_INSTALLED fi - true + return ${OCF_SUCCESS} } nova_network_cleanup() { diff --git a/files/fuel-ha-utils/ocf/ocf-fuel-funcs b/files/fuel-ha-utils/ocf/ocf-fuel-funcs index 8470036b09..2f31546292 100644 --- a/files/fuel-ha-utils/ocf/ocf-fuel-funcs +++ b/files/fuel-ha-utils/ocf/ocf-fuel-funcs @@ -195,3 +195,43 @@ ocf_run_as_root() { ocf_run su - root -c "$(printf '%q ' "$@")" } + +########################################################### +# Validate a port according to RFC 793 +# +# Globals: +# LL +# Arguments: +# $1 - port for validation +# Returns: +# 0 - if port valid +# 1 - if port invalid +# 2 - if invalid parameters passed in +########################################################### +validate_port() +{ + local port=$1 + local LH="${LL} validate_port():" + + if [ -z "${port}" ]; then + ocf_log info "${LH} Port provided is empty" + return 2 + fi + + case ${port} in + *[^0-9]*) + ocf_log info "${LH}: invalid port specified: $port" + return 1 + ;; + esac + + # $port contains only digits, check if it's in the correct range + if [ $port -gt 65535 ] || [ $port -lt 1 ]; then + ocf_log err "${LH}: invalid port specified: $port" + return 1 + else + ocf_log debug "${LH} got a valid port: $port" + return 0 + fi +} +# vim: set ts=4 sw=4 tw=0 et : diff --git a/specs/fuel-library9.0.spec b/specs/fuel-library9.0.spec index 0f50bc9407..a1fc231db5 100644 --- a/specs/fuel-library9.0.spec +++ b/specs/fuel-library9.0.spec @@ -98,10 +98,10 @@ install -m 0755 %{files_source}/fuel-ha-utils/ocf/ns_dns %{buildroot}/usr/lib/oc install -m 0755 %{files_source}/fuel-ha-utils/ocf/heat-engine %{buildroot}/usr/lib/ocf/resource.d/fuel/heat-engine install -m 0755 %{files_source}/fuel-ha-utils/ocf/ns_ntp %{buildroot}/usr/lib/ocf/resource.d/fuel/ns_ntp install -m 0755 %{files_source}/fuel-ha-utils/ocf/ns_vrouter %{buildroot}/usr/lib/ocf/resource.d/fuel/ns_vrouter -install -m 0755 %{files_source}/fuel-ha-utils/ocf/ocf-neutron-ovs-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/ocf-neutron-ovs-agent -install -m 0755 %{files_source}/fuel-ha-utils/ocf/ocf-neutron-metadata-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/ocf-neutron-metadata-agent -install -m 0755 %{files_source}/fuel-ha-utils/ocf/ocf-neutron-dhcp-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/ocf-neutron-dhcp-agent -install -m 0755 %{files_source}/fuel-ha-utils/ocf/ocf-neutron-l3-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/ocf-neutron-l3-agent +install -m 0755 %{files_source}/fuel-ha-utils/ocf/neutron-ovs-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/neutron-ovs-agent +install -m 0755 %{files_source}/fuel-ha-utils/ocf/neutron-metadata-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/neutron-metadata-agent +install -m 0755 %{files_source}/fuel-ha-utils/ocf/neutron-dhcp-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/neutron-dhcp-agent +install -m 0755 %{files_source}/fuel-ha-utils/ocf/neutron-l3-agent %{buildroot}/usr/lib/ocf/resource.d/fuel/neutron-l3-agent #TODO(dmitryme): remove rabbitmq-server-upstream once we switch to rabbitmq-3.5.7, as it will be included here install -m 0755 %{files_source}/fuel-ha-utils/ocf/rabbitmq %{buildroot}/usr/lib/ocf/resource.d/fuel/rabbitmq-server-upstream install -m 0755 %{files_source}/fuel-ha-utils/ocf/rabbitmq-fuel %{buildroot}/usr/lib/ocf/resource.d/fuel/rabbitmq-server diff --git a/tests/bats/ocf-fuel-funcs b/tests/bats/ocf-fuel-funcs index f374027ca8..15a041bef3 100755 --- a/tests/bats/ocf-fuel-funcs +++ b/tests/bats/ocf-fuel-funcs @@ -132,3 +132,33 @@ load "$fms" [ "${lines[0]}" = "${expected}" ] } trap 'rm -rf $TMPFILE' EXIT INT HUP + +@test "Check validate_port(): without parameters" { + run validate_port + [ $status -eq 2 ] +} + +@test "Check validate_port(): with port 0" { + run validate_port 0 + [ $status -eq 1 ] +} + +@test "Check validate_port(): with port 1" { + run validate_port 1 + [ $status -eq 0 ] +} + +@test "Check validate_port(): with port 65535" { + run validate_port 65535 + [ $status -eq 0 ] +} + +@test "Check validate_port(): with port 65536" { + run validate_port 65536 + [ $status -eq 1 ] +} + +@test "Check validate_port(): with alphanumeric parameter" { + run validate_port aaa1 + [ $status -eq 1 ] +}