Skip to content

Commit

Permalink
rel-migrate: test release migration function (2600hz#3666)
Browse files Browse the repository at this point in the history
* rel-migrate: test release migration function

* rel-migrate: check return values

* rel-migrate: more checks

* show sup command as it is run

* error when error.log is non-empty

* rel-migrate: use the real sup

* rel-migrate: introduce sup:in_kazoo

* rel-migrate: pass normal errors
fenollp authored and lazedo committed May 4, 2017
1 parent 0827150 commit e962fb2
Showing 10 changed files with 101 additions and 61 deletions.
2 changes: 1 addition & 1 deletion core/kazoo_apps/src/kapps_maintenance.erl
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ migrate(Pause, Databases) ->
io:format("removing depreciated databases...~n"),
_ = remove_depreciated_databases(Databases),

kazoo_bindings:map(binding('migrate'), Accounts),
kazoo_bindings:map(binding('migrate'), [Accounts]),

'no_return'.

5 changes: 0 additions & 5 deletions core/kazoo_bindings/src/kazoo_bindings_sup.erl
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
-behaviour(supervisor).

-export([start_link/0
,stop/0
]).
-export([init/1]).

@@ -44,10 +43,6 @@
start_link() ->
supervisor:start_link({'local', ?SERVER}, ?MODULE, []).

-spec stop() -> 'ok' | {'error', 'not_found'}.
stop() ->
supervisor:terminate_child(?SERVER, ?ID).

%% ===================================================================
%% Supervisor callbacks
%% ===================================================================
1 change: 0 additions & 1 deletion core/sup/priv/sup
Original file line number Diff line number Diff line change
@@ -14,5 +14,4 @@ fi
export NAME_ARG="-name ${DEFAULT_REL}"

RELX_REPLACE_OS_VARS=true KZname="-name ${DEFAULT_REL}" "${DEFAULT_ROOT}"/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"

exit $?
15 changes: 10 additions & 5 deletions core/sup/rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{lib_dirs, ["../../deps", "../../core"]}.
{escript_incl_apps, [getopt, kazoo, kazoo_stdlib, kazoo_config, zucchini, lager]}.
{xref_checks, [
undefined_function_calls,
deprecated_function_calls,
locals_not_used
]}.
{erl_opts, [warn_export_all
,warn_missing_spec
,warnings_as_errors
,debug_info
,{parse_transform, lager_transform}
]}.
{xref_checks, [undefined_function_calls
,deprecated_function_calls
,locals_not_used
]}.
22 changes: 14 additions & 8 deletions core/sup/src/sup.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{application, sup,
[ {description, "Accept RPC requests & push them into a running Kazoo VM"}
, {vsn, "4.0.0"}
, {modules, []}
, {registered, []}
, {applications, [ kernel
, stdlib
]}
, {env, []}
[{description, "Accept RPC requests & push them into a running Kazoo VM"}
,{vsn, "4.0.0"}
,{modules, []}
,{registered, []}
,{applications, [kernel
,stdlib
,getopt
,kazoo
,kazoo_stdlib
,kazoo_config
,zucchini
,lager
]}
,{env, []}
]}.
23 changes: 18 additions & 5 deletions core/sup/src/sup.erl
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
-module(sup).

-export([main/1]).
-export([in_kazoo/3]).

-include_lib("kazoo/include/kz_types.hrl").
-include_lib("kazoo/include/kz_log.hrl").
@@ -37,8 +38,8 @@ main(CommandLineArgs, Loops) ->
{'ok', Options, Args} = parse_args(CommandLineArgs),
lists:member('help', Options)
andalso print_help(),
Verbose = props:get_value('verbose', Options) =/= 'undefined',
Target = get_target(Options, Verbose),
IsVerbose = props:get_value('verbose', Options) =/= 'undefined',
Target = get_target(Options, IsVerbose),
Module =
case props:get_value('module', Options) of
'undefined' -> print_invalid_cli_args();
@@ -49,19 +50,24 @@ main(CommandLineArgs, Loops) ->
'undefined' -> print_invalid_cli_args();
F -> list_to_atom(F)
end,
Arguments = [list_to_binary(Arg) || Arg <- Args],
Timeout = case props:get_value('timeout', Options) of 0 -> 'infinity'; T -> T * 1000 end,
Verbose
IsVerbose
andalso stdout("Running ~s:~s(~s)", [Module, Function, string:join(Args, ", ")]),
case rpc:call(Target, Module, Function, [list_to_binary(Arg) || Arg <- Args], Timeout) of

case rpc:call(Target, ?MODULE, in_kazoo, [Module, Function, Arguments], Timeout) of
{'badrpc', {'EXIT',{'undef', _}}} ->
print_invalid_cli_args();
{badrpc, {'EXIT', {timeout_value,[{Module,Function,_,_}|_]}}} ->
stderr("Command failed: timeout", []),
halt(1);
{'badrpc', Reason} ->
String = io_lib:print(Reason, 1, ?MAX_CHARS, -1),
stderr("Command failed: ~s", [String]),
halt(1);
'no_return' ->
halt(0);
Result when Verbose ->
Result when IsVerbose ->
String = io_lib:print(Result, 1, ?MAX_CHARS, -1),
stdout("Result: ~s", [String]),
halt(0);
@@ -72,6 +78,13 @@ main(CommandLineArgs, Loops) ->
end
end.

-spec in_kazoo(module(), atom(), binaries()) -> no_return().
in_kazoo(M, F, As) ->
kz_util:put_callid(<<"sup_", (kz_binary:rand_hex(8))/binary>>),
lager:notice("~s: ~s ~s ~s", [?MODULE, M, F, kz_util:iolist_join($,, As)]),
R = apply(M, F, As),
lager:notice("~s result: ~p", [?MODULE, R]),
R.

%%% Internals

22 changes: 13 additions & 9 deletions rel/ci-sys.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[
{lager, [
{handlers, [
{lager_console_backend, [debug,
{lager_default_formatter,
[time, color, " [", severity, "] |", {callid,<<"0000000000">>}, "|", module,":",line, " (",pid,") ", "\e[0m", message, "\n"]}]}
]}
,{colored, true}
,{error_logger_hwm, 5000}
]}
{lager, [
{handlers, [
{lager_console_backend, [debug,
{lager_default_formatter,
[time, color, " [", severity, "] |", {callid,<<"0000000000">>}, "|", module,":",line, " (",pid,") ", "\e[0m", message, "\n"]}]}
,{lager_file_backend, [{file, "log/error.log"}, {level, error}, {size, 10485760}, {date, "$D0"}, {count, 5}
,{formatter, lager_default_formatter}
,{formatter_config, [time," [",severity,"] ", "|", {callid, <<"0000000000">>}, "|", module, ":", line, " (",pid, ") ", message, "\n"]}
]}
]}
,{colored, true}
,{error_logger_hwm, 5000}
]}
].
44 changes: 30 additions & 14 deletions scripts/check-release-startup.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
#!/bin/bash
#!/bin/bash -e

[[ ! -d _rel ]] && echo 'Cannot find _rel/ Is the release built?' && exit -1

echo 'Checking the startup of the release...'

rel=${REL:-kazoo_apps} # kazoo_apps | ecallmgr | ...
[[ $rel != *@* ]] && rel=$rel@127.0.0.1

[[ $rel != *@* ]] && rel=$rel@$(hostname -f)
[[ $rel != kazoo_apps* ]] && export KAZOO_APPS='ecallmgr'

function sup_() {
local M=$1; shift
local F=$1; shift
declare -a a=()
for arg in "$@"; do a+=( '<<"'"$arg"'">>' ); done
IFS=, eval 'A=${a[*]}'
erl -noshell -setcookie change_me -name sup_$RANDOM@${rel##*@} -eval "ok = rpc:call('$rel', $M, $F, [$A])." -s init stop
echo "Checking release startup with node $rel..."

sup_() {
RELX_REPLACE_OS_VARS=true KZname="-name $rel" $PWD/_rel/kazoo/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"
}

sleep 360 && sup_ crossbar_maintenance create_account 'compte_maitre' 'royaume' 'superduperuser' 'pwd!' &
sleep 440 && sup_ init stop &
script() {
sup_ crossbar_maintenance create_account 'compte_maitre' 'royaume' 'superduperuser' 'pwd!'
sleep 3
sup_ kapps_maintenance migrate
sleep 3
sup_ kapps_maintenance migrate_to_4_0
sleep 3
sup_ init stop
}

sleep 240 && script &
export KAZOO_CONFIG=$PWD/rel/ci-config.ini
REL=$rel make release
code=$?

if [[ -f erl_crash.dump ]]; then
echo A crash dump was generated!
code=3
fi
error_log=$PWD/_rel/kazoo/log/error.log
if [[ $(grep -c -v -F 'exit with reason shutdown' $error_log) -gt 0 ]]; then
echo
echo Error log:
cat $error_log
code=4
fi
exit $code
26 changes: 15 additions & 11 deletions scripts/dev/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
Kazoo development scripts
=========================
# Kazoo development scripts

```sh
# Starts Kazoo and provide Erlang console
scripts/dev/kazoo.sh
## Starts Kazoo and provide Erlang console

# Runs Kazoo sup wrapper
scripts/dev/sup.sh
```shell
./scripts/dev/kazoo.sh
```

Hot load code
=============
## Runs Kazoo sup wrapper

```shell
./scripts/dev/sup.sh
```

## Hot load code

In Kazoo Erlang shell:

```erlang
> lager:set_loglevel(lager_console_backend, info).
> sync:go().
lager:set_loglevel(lager_console_backend, info).
sync:go().
```
2 changes: 0 additions & 2 deletions scripts/dev/sup.sh
Original file line number Diff line number Diff line change
@@ -4,10 +4,8 @@ echo Connecting to node: $KAZOO_NODE

IFS='@' read -r -a NH <<< "$KAZOO_NODE"
NAME="${NH[0]}"
HOST="${NH[1]}"

RELX_REPLACE_OS_VARS=true KZname="-name $KAZOO_NODE" \
exec _rel/kazoo/bin/kazoo escript lib/sup-*/priv/sup.escript \
-n $NAME \
-h $HOST \
"$*"

0 comments on commit e962fb2

Please sign in to comment.