Refactor OCF functions

- Move port validation *_check_port from all OCF script to OCF library
  (validate_port)
   - ceilometer_agent_central_check_port()
   - ceilometer_alarm_evaluator_check_port()
   - heat_engine_check_port()
   - nova_compute_check_port()
   - write bats unit tests for validate_port
- Remove 'ocf-' from neutron OCF scripts names to make them typical to all
  OpenStack services
  - Rename ocf-neutron-dhcp-agent to neutron-dhcp-agent
  - Rename ocf-neutron-l3-agent to neutron-l3-agent
  - Rename ocf-neutron-ovs-agent to neutron-ovs-agent
- Some minor bash typos and old comments clean-up

Change-Id: Ic4bcecdbc05f6306be63dea211df96a104cb2d36
Signed-off-by: Sergii Golovatiuk <sgolovatiuk@mirantis.com>
This commit is contained in:
Sergii Golovatiuk 2015-10-10 12:57:17 +02:00
parent 9b1df9e7ab
commit df082efdb3
17 changed files with 112 additions and 139 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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',

View File

@ -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 },

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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=$?

View File

@ -249,7 +249,7 @@ neutron_dhcp_agent_validate() {
return $OCF_ERR_INSTALLED
fi
true
return ${OCF_SUCCESS}
}
neutron_dhcp_agent_status() {

View File

@ -258,7 +258,7 @@ neutron_l3_agent_validate() {
return $OCF_ERR_INSTALLED
fi
true
return ${OCF_SUCCESS}
}
neutron_l3_agent_status() {

View File

@ -189,7 +189,7 @@ neutron_metadata_agent_validate() {
return $OCF_ERR_INSTALLED
fi
true
return ${OCF_SUCCESS}
}

View File

@ -213,7 +213,7 @@ neutron_ovs_agent_validate() {
return $OCF_ERR_INSTALLED
fi
true
return ${OCF_SUCCESS}
}

View File

@ -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})"

View File

@ -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() {

View File

@ -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 :

View File

@ -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

View File

@ -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 ]
}