TT#56053 Make the node state a run-time variable

Nowadays goss yml files are generated by ngcpcfg. But their content
depends on whether the node is active or not, which can change
dynamically during the lifetime of the generated files from the
templates. Which will make the goss checks fail when the node state
changes.

Switch the node state into a run-time variable, and use go template
support to parametrize this into the goss checks.

For the Template Toolkit values that get instantiated within the go
template conditionals, we need to make sure we always set a boolean
value, as the Template Toolkit will return undef on false values,
which would be considered a non-existining argument. Even though the
has_role method will always return either 0 or 1, we still force
a boolean value to make the code future-proof in case more logic is
added on the same check, which would then turn it into a Template
Toolkit boolean evaluation and possibly return nothing on false.

Change-Id: I19c3ef48f09c8d2e79613ef118adc362399a6e78
changes/94/37394/8
Guillem Jover 5 years ago
parent 38264e82c5
commit 21d7cbbce2

@ -83,11 +83,20 @@ case "${NGCP_TESTS_MODE}" in
esac
export DEBIAN_RELEASE
# Use an actual variable so that the values do not evaluate as strings,
# and thus as always true.
if [ "$(ngcp-check-active -v)" = 'active' ]; then
NODE_ACTIVE=true
else
NODE_ACTIVE=false
fi
VARS=$(mktemp --tmpdir ngcp-system-tests.XXXXXXXXXX.yaml)
trap 'rm -f "${VARS}"' EXIT
cat >"${VARS}" <<-EOF
SKIP_DNS_CHECK_TEST: ${SKIP_DNS_CHECK_TEST:-false}
SKIP_STRICT_HOSTNAME_TEST: ${SKIP_STRICT_HOSTNAME_TEST:-false}
NODE_ACTIVE: ${NODE_ACTIVE}
EOF
PLAN='/etc/ngcp-system-tests/goss.yaml'

@ -8,24 +8,18 @@
is_rtp = ngcp.has_role(hostname, 'rtp');
is_li_dist = ngcp.has_role(hostname, 'li_dist');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
command:
"pgrep -c -f 'lua5\\.. /usr/bin/prosody'":
[% IF is_proxy && prosody.enable == 'yes' && node_state == 'active' -%]
{{if and [% is_proxy && prosody.enable == 'yes' ? 1 : 0 %] .Vars.NODE_ACTIVE}}
exit-status: 0
stdout:
- "1"
[% ELSE -%]
{{else}}
exit-status: 1
stdout: []
[% END -%]
{{end}}
stderr: []
"pgrep -c -f '[p]erl-fcgi-pm \\[NGCP::Panel\\]'":
@ -40,48 +34,48 @@ command:
stderr: []
"pgrep -n -f '[k]amailio.*kamailio.proxy.pid'":
[% IF is_proxy && kamailio.proxy.start == "yes" && node_state == 'active' -%]
{{if and [% is_proxy && kamailio.proxy.start == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}}
exit-status: 0
stdout:
- "/[0-9]+/"
[% ELSE -%]
{{else}}
exit-status: 1
stdout: []
[% END -%]
{{end}}
stderr: []
"pgrep -n -f '[k]amailio.*kamailio.lb.pid'":
[% IF is_lb && kamailio.lb.start == "yes" && node_state == 'active' -%]
{{if and [% is_lb && kamailio.lb.start == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}}
exit-status: 0
stdout:
- "/[0-9]+/"
[% ELSE -%]
{{else}}
exit-status: 1
stdout: []
[% END -%]
{{end}}
stderr: []
process:
asterisk:
running: [% is_proxy && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
influxd:
running: true
kamailio:
running: [% (is_lb || is_proxy) && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_lb || is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-mediator:
running: [% is_proxy && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-sems:
running: [% is_proxy && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-witnessd:
running: true
ngcp-rate-o-mat:
running: [% is_proxy && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
nginx:
running: [% (is_mgmt || is_lb || is_li_dist) && nginx.enable == 'yes' ? 'true' : 'false' %]
@ -90,10 +84,10 @@ process:
running: [% is_mgmt ? 'true' : 'false' %]
rtpengine:
running: [% is_rtp && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_rtp ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
rtpengine-recording:
running: [% is_rtp && node_state == 'active' && rtpproxy.recording.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_rtp && rtpproxy.recording.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
telegraf:
running: true

@ -5,12 +5,6 @@
is_lb = ngcp.has_role(hostname, 'lb');
is_rtp = ngcp.has_role(hostname, 'rtp');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
process:
glusterfs:
@ -34,38 +28,38 @@ process:
running: [% general.license_key != '' || general.anonymous_usage_statistics == 'yes' ? 'true' : 'false' %]
ngcp-faxserver:
running: [% is_proxy && node_state == 'active' ? 'true' : 'false' %]
running: {{if and [% is_proxy ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-snmp-agent:
running: true
ngcp-voisniff:
running: [% (is_proxy || is_lb || is_rtp) && node_state == 'active' && voisniff.daemon.start == 'yes' ? 'true' : 'false' %]
running: {{if and [% (is_proxy || is_lb || is_rtp) && voisniff.daemon.start == 'yes' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
snmpd:
running: true
janus:
running: [% is_proxy && (node_state == 'active' && (janus.enable == 'yes' || (rtcengine.conference.enable == 'yes' && rtcengine.conference.type == 'janus'))) ? 'true' : 'false' %]
running: {{if and [% is_proxy && (janus.enable == 'yes' || (rtcengine.conference.enable == 'yes' && rtcengine.conference.type == 'janus')) ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
command:
"pgrep -c -n -f '[r]tcengine.js'":
[% IF is_proxy && rtcengine.enable == "yes" && node_state == 'active' -%]
{{if and [% is_proxy && rtcengine.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}}
exit-status: 0
stdout:
- "1"
[% ELSE -%]
{{else}}
exit-status: 1
stdout: []
[% END -%]
{{end}}
stderr: []
"pgrep -c -n -f '[c]omx-fileshare.js'":
[% IF is_proxy && fileshare.enable == "yes" && node_state == 'active' -%]
{{if and [% is_proxy && fileshare.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}}
exit-status: 0
stdout:
- "1"
[% ELSE -%]
{{else}}
exit-status: 1
stdout: []
[% END -%]
{{end}}

@ -8,17 +8,11 @@
is_rtp = ngcp.has_role(hostname, 'rtp');
is_li_dist = ngcp.has_role(hostname, 'li_dist');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
service:
asterisk.service:
enabled: [% general.process_handler == 'none' && asterisk.enable == "yes" ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && asterisk.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_proxy && asterisk.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
coturn.service:
enabled: [% is_rtp && turnserver.enable == 'yes' ? 'true' : 'false' %]
@ -26,7 +20,7 @@ service:
dnsmasq.service:
enabled: false
running: [% is_mgmt && node_state == 'active' && bootenv.dhcp.enable == 'yes' ? 'true' : 'false' %]
running: {{if and [% is_mgmt && bootenv.dhcp.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
haproxy.service:
enabled: [% is_lb && haproxy.enable == "yes" && general.ngcp_type == 'carrier' ? 'true' : 'false' %]
@ -38,11 +32,11 @@ service:
kamailio-lb.service:
enabled: [% general.process_handler == 'none' && kamailio.lb.start == "yes" ? 'true' : 'false' %]
running: [% is_lb && node_state == 'active' && kamailio.lb.start == "yes" ? 'true' : 'false' %]
running: {{if and [% is_lb && kamailio.lb.start == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
kamailio-proxy.service:
enabled: [% general.process_handler == 'none' && kamailio.proxy.start == "yes" ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && kamailio.proxy.start == "yes" ? 'true' : 'false' %]
running: {{if and [% is_proxy && kamailio.proxy.start == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-license-client.service:
enabled: [% general.process_handler == 'none' && (general.license_key != '' || general.anonymous_usage_statistics == 'yes') ? 'true' : 'false' %]
@ -50,7 +44,7 @@ service:
ngcp-mediator.service:
enabled: [% general.process_handler == 'none' && mediator.enable == 'yes' ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && mediator.enable == 'yes' ? 'true' : 'false' %]
running: {{if and [% is_proxy && mediator.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-panel.service:
enabled: [% is_mgmt && www_admin.enable == 'yes' ? 'true' : 'false' %]
@ -58,19 +52,19 @@ service:
ngcp-rate-o-mat.service:
enabled: [% general.process_handler == 'none' && rateomat.enable == "yes" ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && rateomat.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_proxy && rateomat.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-rtpengine-recording-daemon.service:
enabled: [% general.process_handler == 'none' && rtpproxy.recording.enable == "yes" ? 'true' : 'false' %]
running: [% is_rtp && node_state == 'active' && rtpproxy.recording.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_rtp && rtpproxy.recording.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-rtpengine-daemon.service:
enabled: [% general.process_handler == 'none' && rtpproxy.enable == "yes" ? 'true' : 'false' %]
running: [% is_rtp && node_state == 'active' && rtpproxy.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_rtp && rtpproxy.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-sems.service:
enabled: [% general.process_handler == 'none' && sems.enable == "yes" ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && sems.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_proxy && sems.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-witnessd.service:
enabled: true
@ -82,7 +76,7 @@ service:
prosody.service:
enabled: [% general.process_handler == 'none' && prosody.enable == 'yes' ? 'true' : 'false' %]
running: [% is_proxy && node_state == 'active' && prosody.enable == 'yes' ? 'true' : 'false' %]
running: {{if and [% is_proxy && prosody.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-pushd.service:
enabled: [% is_lb && pushd.enable == "yes" ? 'true' : 'false' %]
@ -98,11 +92,11 @@ service:
sems-pbx.service:
enabled: false
running: [% is_proxy && node_state == 'active' && pbx.enable == "yes" ? 'true' : 'false' %]
running: {{if and [% is_proxy && pbx.enable == "yes" ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-voisniff.service:
enabled: false
running: [% (is_proxy || is_lb || is_rtp) && node_state == 'active' && voisniff.daemon.start == 'yes' ? 'true' : 'false' %]
running: {{if and [% (is_proxy || is_lb || is_rtp) && voisniff.daemon.start == 'yes' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcpcfg-api.service:
enabled: [% is_mgmt && general.ngcp_type != 'spce' ? 'true' : 'false' %]
@ -110,7 +104,7 @@ service:
ngcp-faxserver.service:
enabled: false
running: [% is_proxy && node_state == 'active' && faxserver.enable == "yes" && general.ngcp_type != 'spce' ? 'true' : 'false' %]
running: {{if and [% is_proxy && faxserver.enable == "yes" && general.ngcp_type != 'spce' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
influxdb-relay.service:
enabled: [% general.ngcp_type != 'spce' ? 'true' : 'false' %]
@ -132,15 +126,15 @@ service:
[% END -%]
ngcp-rtcengine.service:
enabled: false
running: [% is_proxy && node_state == 'active' && rtcengine.enable == "yes" && general.ngcp_type != 'spce' ? 'true' : 'false' %]
running: {{if and [% is_proxy && rtcengine.enable == "yes" && general.ngcp_type != 'spce' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
ngcp-comx-fileshare-service.service:
enabled: false
running: [% is_proxy && node_state == 'active' && fileshare.enable == "yes" && general.ngcp_type != 'spce' ? 'true' : 'false' %]
running: {{if and [% is_proxy && fileshare.enable == "yes" && general.ngcp_type != 'spce' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
janus.service:
enabled: false
running: [% is_proxy && node_state == 'active' && general.ngcp_type != 'spce' && (janus.enable == 'yes' || (rtcengine.conference.enable == 'yes' && rtcengine.conference.type == 'janus')) ? 'true' : 'false' %]
running: {{if and [% is_proxy && (janus.enable == 'yes' || (rtcengine.conference.enable == 'yes' && rtcengine.conference.type == 'janus')) && general.ngcp_type != 'spce' ? 1 : 0 %] .Vars.NODE_ACTIVE}} true {{else}} false {{end}}
monit.service:
enabled: [% general.process_handler == 'monit' ? 'true' : 'false' %]

@ -3,12 +3,6 @@
is_proxy = ngcp.has_role(hostname, 'proxy');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
command:
@ -16,11 +10,11 @@ command:
exit-status: 0
stdout: []
stderr: []
[% IF is_proxy && node_state == 'active' && rtpproxy.enable == "yes" -%]
{{if and [% (rtpproxy.enable == "yes" && is_proxy) ? 1 : 0 %] .Vars.NODE_ACTIVE}}
lsmod | grep -c xt_RTPENGINE:
exit-status: 0
stdout:
- '/^2$/'
stderr: []
[% END -%]
{{end}}

@ -66,12 +66,6 @@
PROCESS '/usr/lib/ngcp-ngcpcfg/get_all_ips_for_host';
ha_int_ips = out;
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
port:
@ -111,7 +105,7 @@ port:
[% IF is_lb -%]
# Kamailio load-balancer
tcp:5060:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_ext_ips.0 %]"]
# HAProxy
@ -138,57 +132,57 @@ port:
[% IF is_proxy -%]
# Kamailio proxy
tcp:5062:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# Prosody
tcp:5222:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_proxy_ip %]"]
# Prosody
tcp:5269:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_proxy_ip %]"]
# Prosody
tcp:5280:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# Prosody
tcp:5281:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# Prosody
tcp:5582:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# SEMS
tcp:8090:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# Asterisk
tcp:5038:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["127.0.0.1"]
# SEMS
udp:5040:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# Asterisk
udp:5070:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
# SEMS
udp:5080:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
[% END -%]
@ -202,7 +196,7 @@ port:
[% IF is_rtp -%]
# rtpengine
udp:2223:
listening: [% node_state == 'active' ? 'true' : 'false' %]
listening: {{.Vars.NODE_ACTIVE}}
ip: ["[% sip_int_ips.0 %]"]
[% END -%]

@ -36,12 +36,6 @@
is_mgmt = ngcp.has_role(hostname, 'mgmt');
is_li_dist = ngcp.has_role(hostname, 'li_dist');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
[% IF is_mgmt || is_li_dist -%]
command:
@ -165,7 +159,7 @@ command:
timeout: 30000
[% IF www_admin.enable == 'yes' && node_state == 'active' -%]
{{if and [% www_admin.enable == 'yes' ? 1 : 0 %] .Vars.NODE_ACTIVE}}
"curl -H 'NGCP-UserAgent: NGCP::API::Client' --insecure -L https://[% credentials.rest_api.auth_system.u %]:[% credentials.rest_api.auth_system.p %]@[% api_int_ips.0 %]:[% www_admin.http_system.port %]/api/":
exit-status: 0
stdout:
@ -207,8 +201,7 @@ command:
- "/Authorization required/"
stderr: []
timeout: 30000
[% END -%]
{{end}}
"curl -L http://localhost:8081/nginx_status":
exit-status: 0

@ -3,28 +3,20 @@
is_proxy = ngcp.has_role(hostname, 'proxy');
-%]
[% PERL -%]
my $node_state = qx(ngcp-check-active -v);
chomp $node_state;
$stash->set(node_state => $node_state);
[% END -%]
command:
[% IF is_proxy && asterisk.enable == "yes" && node_state == 'active' -%]
{{if and [% (is_proxy && asterisk.enable == 'yes') ? 1 : 0 %] .Vars.NODE_ACTIVE}}
asterisk -rx "odbc read ODBC_VMGREETUNAVAIL test exec":
exit-status: 0
stdout:
- "/Returned 1 row/"
stderr: []
timeout: 10000
[% ELSE -%]
{{else}}
echo "The test for active node with enabled asterisk and proxy role only":
exit-status: 0
stdout: []
stderr: []
timeout: 10000
[% END -%]
{{end}}

Loading…
Cancel
Save