mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-06 08:35:22 +00:00
Initial commit: Giddyup support. Runner can now set backends for a test
This commit is contained in:
parent
c56fe12bae
commit
71b5a63dd8
@ -13,10 +13,11 @@
|
||||
{meck, ".*", {git, "git://github.com/eproxus/meck"}},
|
||||
{mapred_verify, ".*", {git, "git://github.com/basho/mapred_verify"}},
|
||||
{riakc, "1.3.1", {git, "git://github.com/basho/riak-erlang-client", {tag, "1.3.1"}}},
|
||||
{riakhttpc, "1.3.1", {git, "git://github.com/basho/riak-erlang-http-client", {tag, "1.3.1"}}}
|
||||
{riakhttpc, "1.3.1", {git, "git://github.com/basho/riak-erlang-http-client", {tag, "1.3.1"}}},
|
||||
{kvc, "1.2.1", {git, "https://github.com/etrepum/kvc", {tag, "v1.2.1"}}}
|
||||
]}.
|
||||
|
||||
{escript_incl_apps, [lager, getopt, riakhttpc, riakc, ibrowse]}.
|
||||
{escript_incl_apps, [lager, getopt, riakhttpc, riakc, ibrowse, mochiweb, kvc]}.
|
||||
|
||||
{plugin_dir, "src"}.
|
||||
{plugins, [rebar_riak_test_plugin]}.
|
||||
|
34
src/giddyup.erl
Normal file
34
src/giddyup.erl
Normal file
@ -0,0 +1,34 @@
|
||||
-module(giddyup).
|
||||
|
||||
-export([get_suite/3]).
|
||||
|
||||
-define(SUITE_PATH, "http://~s/project/~s?platform=~s").
|
||||
|
||||
get_suite(Host, Project, Platform) ->
|
||||
Schema = get_schema(Host, Project, Platform),
|
||||
Proj = kvc:path(project, Schema),
|
||||
Name = kvc:path(name, Proj),
|
||||
lager:info("Retrieved Project: ~s", [Name]),
|
||||
Tests = kvc:path(tests, Proj),
|
||||
[ {
|
||||
kvc:path(id, Test),
|
||||
binary_to_atom(kvc:path(name, Test), utf8),
|
||||
case kvc:path(tags.backend, Test) of [] -> na; X -> binary_to_atom(X, utf8) end
|
||||
} || Test <- Tests].
|
||||
|
||||
get_schema(Host, Project, Platform) ->
|
||||
URL = io_lib:format(?SUITE_PATH, [Host, Project, Platform]),
|
||||
lager:info("giddyup url: ~s", [URL]),
|
||||
JSON = <<"{
|
||||
\"project\":{
|
||||
\"name\":\"riak\",
|
||||
\"tests\":[
|
||||
{\"id\":1, \"name\":\"verify_build_cluster\",
|
||||
\"tags\":{\"platform\":\"ubuntu-1004-64\"}},
|
||||
{\"id\":2, \"name\":\"secondary_index_tests\",
|
||||
\"tags\":{\"backend\":\"eleveldb\", \"platform\":\"ubuntu-1004-64\"}}
|
||||
]
|
||||
}
|
||||
}">>,
|
||||
mochijson2:decode(JSON).
|
||||
|
@ -16,7 +16,8 @@ cli_options() ->
|
||||
{suites, $s, "suites", string, "which suites to run"},
|
||||
{dir, $d, "dir", string, "run all tests in the specified directory"},
|
||||
{verbose, $v, "verbose", undefined, "verbose output"},
|
||||
{outdir, $o, "outdir", string, "output directory"}
|
||||
{outdir, $o, "outdir", string, "output directory"},
|
||||
{report, $r, "report", undefined, "you're reporting an official test run"}
|
||||
].
|
||||
|
||||
print_help() ->
|
||||
@ -35,39 +36,10 @@ main(Args) ->
|
||||
_ -> print_help()
|
||||
end,
|
||||
|
||||
|
||||
case run_help(ParsedArgs) of
|
||||
true -> print_help();
|
||||
_ -> ok
|
||||
end,
|
||||
Verbose = proplists:is_defined(verbose, ParsedArgs),
|
||||
Config = proplists:get_value(config, ParsedArgs),
|
||||
SpecificTests = proplists:get_all_values(tests, ParsedArgs),
|
||||
Suites = proplists:get_all_values(suites, ParsedArgs),
|
||||
case Suites of
|
||||
[] -> ok;
|
||||
_ -> io:format("Suites are not currently supported.")
|
||||
end,
|
||||
|
||||
Dirs = proplists:get_all_values(dir, ParsedArgs),
|
||||
DirTests = lists:append([load_tests_in_dir(Dir) || Dir <- Dirs]),
|
||||
|
||||
Tests = lists:foldr(fun(X, AccIn) ->
|
||||
case lists:member(X, AccIn) of
|
||||
true -> AccIn;
|
||||
_ -> [X | AccIn]
|
||||
end
|
||||
end, [], lists:sort(DirTests ++ SpecificTests)),
|
||||
io:format("Tests to run: ~p~n", [Tests]),
|
||||
|
||||
rt:load_config(Config),
|
||||
|
||||
[add_deps(Dep) || Dep <- rt:config(rt_deps)],
|
||||
ENode = rt:config(rt_nodename, 'riak_test@127.0.0.1'),
|
||||
Cookie = rt:config(rt_cookie, riak),
|
||||
[] = os:cmd("epmd -daemon"),
|
||||
net_kernel:start([ENode]),
|
||||
erlang:set_cookie(node(), Cookie),
|
||||
|
||||
%% ibrowse
|
||||
application:load(ibrowse),
|
||||
@ -85,7 +57,44 @@ main(Args) ->
|
||||
|
||||
application:set_env(lager, handlers, [{lager_console_backend, ConsoleLagerLevel}]),
|
||||
lager:start(),
|
||||
|
||||
Report = proplists:is_defined(report, ParsedArgs),
|
||||
Verbose = proplists:is_defined(verbose, ParsedArgs),
|
||||
Config = proplists:get_value(config, ParsedArgs),
|
||||
Suites = proplists:get_all_values(suites, ParsedArgs),
|
||||
case Suites of
|
||||
[] -> ok;
|
||||
_ -> io:format("Suites are not currently supported.")
|
||||
end,
|
||||
|
||||
|
||||
Tests = case Report of
|
||||
true ->
|
||||
Suite = giddyup:get_suite("basho-giddyup.herokuapp.com", "riak", "ubuntu-1004-64"),
|
||||
io:format("Suite: ~p", [Suite]),
|
||||
halt(0);
|
||||
false ->
|
||||
SpecificTests = proplists:get_all_values(tests, ParsedArgs),
|
||||
Dirs = proplists:get_all_values(dir, ParsedArgs),
|
||||
DirTests = lists:append([load_tests_in_dir(Dir) || Dir <- Dirs]),
|
||||
lists:foldr(fun(X, AccIn) ->
|
||||
case lists:member(X, AccIn) of
|
||||
true -> AccIn;
|
||||
_ -> [X | AccIn]
|
||||
end
|
||||
end, [], lists:sort(DirTests ++ SpecificTests))
|
||||
end,
|
||||
io:format("Tests to run: ~p~n", [Tests]),
|
||||
|
||||
rt:load_config(Config),
|
||||
|
||||
[add_deps(Dep) || Dep <- rt:config(rt_deps)],
|
||||
ENode = rt:config(rt_nodename, 'riak_test@127.0.0.1'),
|
||||
Cookie = rt:config(rt_cookie, riak),
|
||||
[] = os:cmd("epmd -daemon"),
|
||||
net_kernel:start([ENode]),
|
||||
erlang:set_cookie(node(), Cookie),
|
||||
|
||||
%% rt:set_config(rtdev_path, Path),
|
||||
%% rt:set_config(rt_max_wait_time, 180000),
|
||||
%% rt:set_config(rt_retry_delay, 500),
|
||||
|
@ -8,12 +8,15 @@
|
||||
confirm(TestModule, Outdir) ->
|
||||
start_lager_backend(TestModule, Outdir),
|
||||
|
||||
rt:setup_harness(TestModule, []),
|
||||
|
||||
%% Check for api compatibility
|
||||
{Status, Reason} = case proplists:get_value(confirm,
|
||||
proplists:get_value(exports, TestModule:module_info()),
|
||||
-1) of
|
||||
0 ->
|
||||
lager:notice("Running Test ~s", [TestModule]),
|
||||
rt:set_backend(riak_kv_eleveldb_backend),
|
||||
execute(TestModule);
|
||||
_ ->
|
||||
lager:info("~s is not a runnable test", [TestModule]),
|
||||
|
@ -610,3 +610,8 @@ str(String, Substr) ->
|
||||
0 -> false;
|
||||
_ -> true
|
||||
end.
|
||||
|
||||
-spec set_backend(atom()) -> ok.
|
||||
set_backend(Backend) ->
|
||||
lager:info("rt:set_backend(~p)", [Backend]),
|
||||
?HARNESS:set_backend(Backend).
|
||||
|
@ -33,6 +33,15 @@ run_riak(N, Path, Cmd) ->
|
||||
os:cmd(riakcmd(Path, N, Cmd)).
|
||||
|
||||
setup_harness(_Test, _Args) ->
|
||||
Path = relpath(root),
|
||||
%% Stop all discoverable nodes, not just nodes we'll be using for this test.
|
||||
RTDevPaths = [ DevPath || {_Name, DevPath} <- proplists:delete(root, rt:config(rtdev_path))],
|
||||
rt:pmap(fun(X) -> stop_all(X ++ "/dev") end, RTDevPaths),
|
||||
|
||||
%% Reset nodes to base state
|
||||
lager:info("Resetting nodes to fresh state"),
|
||||
run_git(Path, "reset HEAD --hard"),
|
||||
run_git(Path, "clean -fd"),
|
||||
ok.
|
||||
|
||||
cleanup_harness() ->
|
||||
@ -71,10 +80,27 @@ upgrade(Node, NewVersion) ->
|
||||
start(Node),
|
||||
ok.
|
||||
|
||||
update_app_config(all, Config) ->
|
||||
lager:info("rtdev:update_app_config(all, ~p)", [Config]),
|
||||
Fun = fun(DevPath, Conf) ->
|
||||
case filelib:is_dir(DevPath) of
|
||||
true ->
|
||||
Devs = filelib:wildcard(DevPath ++ "/dev/dev*"),
|
||||
AppConfigs = [ Dev ++ "/etc/app.config" || Dev <- Devs],
|
||||
[update_app_config_file(AppConfig, Conf) || AppConfig <- AppConfigs];
|
||||
_ -> lager:debug("~s is not a directory.", [DevPath])
|
||||
end
|
||||
end,
|
||||
[ Fun(DevPath, Config) || {_Name, DevPath} <- proplists:delete(root, rt:config(rtdev_path))],
|
||||
halt(0);
|
||||
update_app_config(Node, Config) ->
|
||||
N = node_id(Node),
|
||||
Path = relpath(node_version(N)),
|
||||
ConfigFile = io_lib:format("~s/dev/dev~b/etc/app.config", [Path, N]),
|
||||
update_app_config_file(ConfigFile, Config).
|
||||
|
||||
update_app_config_file(ConfigFile, Config) ->
|
||||
lager:info("rtdev:update_app_config_file(~s, ~p)", [ConfigFile, Config]),
|
||||
{ok, [BaseConfig]} = file:consult(ConfigFile),
|
||||
MergeA = orddict:from_list(Config),
|
||||
MergeB = orddict:from_list(BaseConfig),
|
||||
@ -114,28 +140,6 @@ deploy_nodes(NodeConfig) ->
|
||||
rt:set_config(rt_nodes, NodeMap),
|
||||
rt:set_config(rt_versions, VersionMap),
|
||||
|
||||
%% Stop all discoverable nodes, not just nodes we'll be using for this test.
|
||||
RTDevPaths = [ DevPath || {_Name, DevPath} <- proplists:delete(root, rt:config(rtdev_path))],
|
||||
rt:pmap(fun(X) -> stop_all(X ++ "/dev") end, RTDevPaths),
|
||||
|
||||
%% Stop nodes if already running
|
||||
%% [run_riak(N, relpath(node_version(N)), "stop") || N <- Nodes],
|
||||
rt:pmap(fun(Node) ->
|
||||
N = node_id(Node),
|
||||
run_riak(N, relpath(node_version(N)), "stop"),
|
||||
rt:wait_until_unpingable(Node)
|
||||
end, Nodes),
|
||||
%% ?debugFmt("Shutdown~n", []),
|
||||
|
||||
|
||||
%% Reset nodes to base state
|
||||
lager:info("Resetting nodes to fresh state"),
|
||||
%% run_git(Path, "status"),
|
||||
run_git(Path, "reset HEAD --hard"),
|
||||
run_git(Path, "clean -fd"),
|
||||
%% run_git(Path, "status"),
|
||||
%% ?debugFmt("Reset~n", []),
|
||||
|
||||
create_dirs(Nodes),
|
||||
|
||||
%% Set initial config
|
||||
@ -252,3 +256,7 @@ check_node({_N, Version}) ->
|
||||
lager:error("You don't have Riak ~s installed", [Version]),
|
||||
erlang:error("You don't have Riak " ++ Version ++ " installed" )
|
||||
end.
|
||||
|
||||
set_backend(Backend) ->
|
||||
lager:info("rtdev:set_backend(~p)", [Backend]),
|
||||
update_app_config(all, [{riak_kv, [{storage_backend, Backend}]}]).
|
Loading…
Reference in New Issue
Block a user