From 7d8f26738ea8fcbc7ab46de3b0d0daf806915616 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Fri, 1 Aug 2014 14:37:35 -0400 Subject: [PATCH 1/6] Take first pass at harness refactoring. --- src/rt.erl | 26 ++-- src/rt_backend.erl | 2 +- src/rt_cluster.erl | 10 +- src/rt_cmd_line.erl | 12 +- src/rt_config.erl | 12 +- src/rt_harness.erl | 131 +++++++++++++++++++ src/rt_harness_util.erl | 283 ++++++++++++++++++++++++++++++++++++++++ src/rt_node.erl | 8 +- src/rtdev.erl | 28 +++- src/rtperf.erl | 68 ++++++++++ src/rtssh.erl | 64 +++++++-- src/test_harness.erl | 48 +++++++ 12 files changed, 647 insertions(+), 45 deletions(-) create mode 100644 src/rt_harness.erl create mode 100644 src/rt_harness_util.erl create mode 100644 src/test_harness.erl diff --git a/src/rt.erl b/src/rt.erl index 348b56402..8883ddd6c 100644 --- a/src/rt.erl +++ b/src/rt.erl @@ -108,7 +108,7 @@ priv_dir() -> %% @doc gets riak deps from the appropriate harness -spec get_deps() -> list(). -get_deps() -> ?HARNESS:get_deps(). +get_deps() -> rt_harness:get_deps(). %% @doc if String contains Substr, return true. -spec str(string(), string()) -> boolean(). @@ -164,26 +164,26 @@ maybe_wait_for_changes(Node) -> %% @doc Spawn `Cmd' on the machine running the test harness spawn_cmd(Cmd) -> - ?HARNESS:spawn_cmd(Cmd). + rt_harness:spawn_cmd(Cmd). %% @doc Spawn `Cmd' on the machine running the test harness spawn_cmd(Cmd, Opts) -> - ?HARNESS:spawn_cmd(Cmd, Opts). + rt_harness:spawn_cmd(Cmd, Opts). %% @doc Wait for a command spawned by `spawn_cmd', returning %% the exit status and result wait_for_cmd(CmdHandle) -> - ?HARNESS:wait_for_cmd(CmdHandle). + rt_harness:wait_for_cmd(CmdHandle). %% @doc Spawn `Cmd' on the machine running the test harness, returning %% the exit status and result cmd(Cmd) -> - ?HARNESS:cmd(Cmd). + rt_harness:cmd(Cmd). %% @doc Spawn `Cmd' on the machine running the test harness, returning %% the exit status and result cmd(Cmd, Opts) -> - ?HARNESS:cmd(Cmd, Opts). + rt_harness:cmd(Cmd, Opts). %% @doc pretty much the same as os:cmd/1 but it will stream the output to lager. %% If you're running a long running command, it will dump the output @@ -545,15 +545,15 @@ enable_search_hook(Node, Bucket) when is_binary(Bucket) -> %% or something like that, it's the version you're upgrading to. -spec get_version() -> binary(). get_version() -> - ?HARNESS:get_version(). + rt_harness:get_version(). %% @doc outputs some useful information about nodes that are up whats_up() -> - ?HARNESS:whats_up(). + rt_harness:whats_up(). -spec get_ip(node()) -> string(). get_ip(Node) -> - ?HARNESS:get_ip(Node). + rt_harness:get_ip(Node). %% @doc Log a message to the console of the specified test nodes. %% Messages are prefixed by the string "---riak_test--- " @@ -595,12 +595,12 @@ pmap(F, L) -> %% @private setup_harness(Test, Args) -> - ?HARNESS:setup_harness(Test, Args). + rt_harness:setup_harness(Test, Args). %% @doc Downloads any extant log files from the harness's running %% nodes. get_node_logs() -> - ?HARNESS:get_node_logs(). + rt_harness:get_node_logs(). check_ibrowse() -> try sys:get_status(ibrowse) of @@ -741,7 +741,7 @@ wait_for_control(VersionedNodes) when is_list(VersionedNodes) -> [wait_for_control(Vsn, Node) || {Vsn, Node} <- VersionedNodes]. node_id(Node) -> - ?HARNESS:node_id(Node). + rt_harness:node_id(Node). node_version(Node) -> - ?HARNESS:node_version(Node). + rt_harness:node_version(Node). diff --git a/src/rt_backend.erl b/src/rt_backend.erl index 59f42739d..3fe13e64d 100644 --- a/src/rt_backend.erl +++ b/src/rt_backend.erl @@ -78,7 +78,7 @@ make_multi_backend_config(Other) -> make_multi_backend_config(default). get_backends() -> - Backends = ?HARNESS:get_backends(), + Backends = rt_harness:get_backends(), case Backends of [riak_kv_bitcask_backend] -> bitcask; [riak_kv_eleveldb_backend] -> eleveldb; diff --git a/src/rt_cluster.erl b/src/rt_cluster.erl index cdd507c3e..a4adcbc5f 100644 --- a/src/rt_cluster.erl +++ b/src/rt_cluster.erl @@ -93,7 +93,7 @@ deploy_nodes(NumNodes, InitialConfig) when is_integer(NumNodes) -> deploy_nodes(NodeConfig); deploy_nodes(Versions, Services) -> NodeConfig = [ rt_config:version_to_config(Version) || Version <- Versions ], - Nodes = ?HARNESS:deploy_nodes(NodeConfig), + Nodes = rt_harness:deploy_nodes(NodeConfig), lager:info("Waiting for services ~p to start on ~p.", [Services, Nodes]), [ ok = rt:wait_for_service(Node, Service) || Node <- Nodes, Service <- Services ], @@ -110,7 +110,7 @@ deploy_clusters(Settings) -> {NumNodes, Vsn, InitialConfig} when is_integer(NumNodes) -> [{Vsn, InitialConfig} || _ <- lists:seq(1,NumNodes)] end || Setting <- Settings], - ?HARNESS:deploy_clusters(ClusterConfigs). + rt_harness:deploy_clusters(ClusterConfigs). build_clusters(Settings) -> Clusters = deploy_clusters(Settings), @@ -201,7 +201,7 @@ clean_data_dir(Nodes) -> clean_data_dir(Nodes, SubDir) when not is_list(Nodes) -> clean_data_dir([Nodes], SubDir); clean_data_dir(Nodes, SubDir) when is_list(Nodes) -> - ?HARNESS:clean_data_dir(Nodes, SubDir). + rt_harness:clean_data_dir(Nodes, SubDir). %% @doc Shutdown every node, this is for after a test run is complete. teardown() -> @@ -210,10 +210,10 @@ teardown() -> %%[ rt_node:stop(Node) || Node <- nodes()], %% Then do the more exhaustive harness thing, in case something was up %% but not connected. - ?HARNESS:teardown(). + rt_harness:teardown(). versions() -> - ?HARNESS:versions(). + rt_harness:versions(). config() -> [{riak_core, [{handoff_concurrency, 11}]}, diff --git a/src/rt_cmd_line.erl b/src/rt_cmd_line.erl index d4022f1ae..f422e68fb 100644 --- a/src/rt_cmd_line.erl +++ b/src/rt_cmd_line.erl @@ -36,16 +36,16 @@ %% @doc Call 'bin/riak-admin' command on `Node' with arguments `Args' admin(Node, Args) -> - ?HARNESS:admin(Node, Args). + rt_harness:admin(Node, Args). %% @doc Call 'bin/riak' command on `Node' with arguments `Args' riak(Node, Args) -> - ?HARNESS:riak(Node, Args). + rt_harness:riak(Node, Args). %% @doc Call 'bin/riak-repl' command on `Node' with arguments `Args' riak_repl(Node, Args) -> - ?HARNESS:riak_repl(Node, Args). + rt_harness:riak_repl(Node, Args). search_cmd(Node, Args) -> {ok, Cwd} = file:get_cwd(), @@ -65,14 +65,14 @@ search_cmd(Node, Args) -> %% expect will process based on the output following the sent data. %% attach(Node, Expected) -> - ?HARNESS:attach(Node, Expected). + rt_harness:attach(Node, Expected). %% @doc Runs 'riak attach-direct' on a specific node %% @see rt_cmd_line:attach/2 attach_direct(Node, Expected) -> - ?HARNESS:attach_direct(Node, Expected). + rt_harness:attach_direct(Node, Expected). %% @doc Runs `riak console' on a specific node %% @see rt_cmd_line:attach/2 console(Node, Expected) -> - ?HARNESS:console(Node, Expected). + rt_harness:console(Node, Expected). diff --git a/src/rt_config.erl b/src/rt_config.erl index 28ffa6cb5..f6e5e8867 100644 --- a/src/rt_config.erl +++ b/src/rt_config.erl @@ -131,30 +131,30 @@ config_or_os_env(Config, Default) -> -spec set_conf(atom(), [{string(), string()}]) -> ok. set_conf(all, NameValuePairs) -> - ?HARNESS:set_conf(all, NameValuePairs); + rt_harness:set_conf(all, NameValuePairs); set_conf(Node, NameValuePairs) -> rt_node:stop(Node), ?assertEqual(ok, rt:wait_until_unpingable(Node)), - ?HARNESS:set_conf(Node, NameValuePairs), + rt_harness:set_conf(Node, NameValuePairs), rt_node:start(Node). -spec set_advanced_conf(atom(), [{string(), string()}]) -> ok. set_advanced_conf(all, NameValuePairs) -> - ?HARNESS:set_advanced_conf(all, NameValuePairs); + rt_harness:set_advanced_conf(all, NameValuePairs); set_advanced_conf(Node, NameValuePairs) -> rt_node:stop(Node), ?assertEqual(ok, rt:wait_until_unpingable(Node)), - ?HARNESS:set_advanced_conf(Node, NameValuePairs), + rt_harness:set_advanced_conf(Node, NameValuePairs), rt_node:start(Node). %% @doc Rewrite the given node's app.config file, overriding the varialbes %% in the existing app.config with those in `Config'. update_app_config(all, Config) -> - ?HARNESS:update_app_config(all, Config); + rt_harness:update_app_config(all, Config); update_app_config(Node, Config) -> rt_node:stop(Node), ?assertEqual(ok, rt:wait_until_unpingable(Node)), - ?HARNESS:update_app_config(Node, Config), + rt_harness:update_app_config(Node, Config), rt_node:start(Node). version_to_config(Config) when is_tuple(Config)-> Config; diff --git a/src/rt_harness.erl b/src/rt_harness.erl new file mode 100644 index 000000000..cd573e9c4 --- /dev/null +++ b/src/rt_harness.erl @@ -0,0 +1,131 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2013-2014 Basho Technologies, Inc. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- +-module(rt_harness). + +-define(HARNESS_MODULE, (rt_config:get(rt_harness))). + +-export([ + start/1, + stop/1, + deploy_clusters/1, + clean_data_dir/2, + deploy_nodes/1, + spawn_cmd/1, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_deps/0, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). + +start(Node) -> + ?HARNESS_MODULE:start(Node). + +stop(Node) -> + ?HARNESS_MODULE:stop(Node). + +deploy_clusters(ClusterConfigs) -> + ?HARNESS_MODULE:deploy_clusters(ClusterConfigs). + +clean_data_dir(Nodes, SubDir) -> + ?HARNESS_MODULE:clean_data_dir(Nodes, SubDir). + +spawn_cmd(Cmd) -> + ?HARNESS_MODULE:spawn_cmd(Cmd). + +spawn_cmd(Cmd, Opts) -> + ?HARNESS_MODULE:spawn_cmd(Cmd, Opts). + +cmd(Cmd) -> + ?HARNESS_MODULE:cmd(Cmd). + +cmd(Cmd, Opts) -> + ?HARNESS_MODULE:cmd(Cmd, Opts). + +deploy_nodes(NodeConfig) -> + ?HARNESS_MODULE:deploy_nodes(NodeConfig). + +setup_harness(Test, Args) -> + ?HARNESS_MODULE:setup_harness(Test, Args). + +get_deps() -> + ?HARNESS_MODULE:get_deps(). +get_version() -> + ?HARNESS_MODULE:get_version(). + +get_backends() -> + ?HARNESS_MODULE:get_backends(). + +set_backend(Backend) -> + ?HARNESS_MODULE:set_backend(Backend). + +whats_up() -> + ?HARNESS_MODULE:whats_up(). + +get_ip(Node) -> + ?HARNESS_MODULE:get_ip(Node). + +node_id(Node) -> + ?HARNESS_MODULE:node_id(Node). + +node_version(N) -> + ?HARNESS_MODULE:node_version(N). + +admin(Node, Args) -> + ?HARNESS_MODULE:admin(Node, Args). + +riak(Node, Args) -> + ?HARNESS_MODULE:riak(Node, Args). + +attach(Node, Expected) -> + ?HARNESS_MODULE:attach(Node, Expected). + +attach_direct(Node, Expected) -> + ?HARNESS_MODULE:attach_direct(Node, Expected). + +console(Node, Expected) -> + ?HARNESS_MODULE:console(Node, Expected). + +update_app_config(Node, Config) -> + ?HARNESS_MODULE:update_app_config(Node, Config). + +teardown() -> + ?HARNESS_MODULE:teardown(). + +set_conf(Node, NameValuePairs) -> + ?HARNESS_MODULE:set_conf(Node, NameValuePairs). + +set_advanced_conf(Node, NameValuePairs) -> + ?HARNESS_MODULE:set_advanced_conf(Node, NameValuePairs). diff --git a/src/rt_harness_util.erl b/src/rt_harness_util.erl new file mode 100644 index 000000000..c636c0cbf --- /dev/null +++ b/src/rt_harness_util.erl @@ -0,0 +1,283 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2013-2014 Basho Technologies, Inc. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- + +-module(rt_harness_util). + +-include_lib("eunit/include/eunit.hrl"). +-define(DEVS(N), lists:concat(["dev", N, "@127.0.0.1"])). +-define(DEV(N), list_to_atom(?DEVS(N))). +-define(PATH, (rt_config:get(rtdev_path))). + +-export([admin/2, + attach/2, + attach_direct/2, + cmd/1, + cmd/2, + console/2, + get_ip/1, + node_id/1, + node_version/1, + riak/2, + set_conf/2, + spawn_cmd/1, + spawn_cmd/2, + whats_up/0]). + +admin(Node, Args) -> + N = node_id(Node), + Path = relpath(node_version(N)), + Cmd = riak_admin_cmd(Path, N, Args), + lager:info("Running: ~s", [Cmd]), + Result = os:cmd(Cmd), + lager:info("~s", [Result]), + {ok, Result}. + +attach(Node, Expected) -> + interactive(Node, "attach", Expected). + +attach_direct(Node, Expected) -> + interactive(Node, "attach-direct", Expected). + +console(Node, Expected) -> + interactive(Node, "console", Expected). + +interactive(Node, Command, Exp) -> + N = node_id(Node), + Path = relpath(node_version(N)), + Cmd = riakcmd(Path, N, Command), + lager:info("Opening a port for riak ~s.", [Command]), + lager:debug("Calling open_port with cmd ~s", [binary_to_list(iolist_to_binary(Cmd))]), + P = open_port({spawn, binary_to_list(iolist_to_binary(Cmd))}, + [stream, use_stdio, exit_status, binary, stderr_to_stdout]), + interactive_loop(P, Exp). + +interactive_loop(Port, Expected) -> + receive + {Port, {data, Data}} -> + %% We've gotten some data, so the port isn't done executing + %% Let's break it up by newline and display it. + Tokens = string:tokens(binary_to_list(Data), "\n"), + [lager:debug("~s", [Text]) || Text <- Tokens], + + %% Now we're going to take hd(Expected) which is either {expect, X} + %% or {send, X}. If it's {expect, X}, we foldl through the Tokenized + %% data looking for a partial match via rt:str/2. If we find one, + %% we pop hd off the stack and continue iterating through the list + %% with the next hd until we run out of input. Once hd is a tuple + %% {send, X}, we send that test to the port. The assumption is that + %% once we send data, anything else we still have in the buffer is + %% meaningless, so we skip it. That's what that {sent, sent} thing + %% is about. If there were a way to abort mid-foldl, I'd have done + %% that. {sent, _} -> is just a pass through to get out of the fold. + + NewExpected = lists:foldl(fun(X, Expect) -> + [{Type, Text}|RemainingExpect] = case Expect of + [] -> [{done, "done"}|[]]; + E -> E + end, + case {Type, rt:str(X, Text)} of + {expect, true} -> + RemainingExpect; + {expect, false} -> + [{Type, Text}|RemainingExpect]; + {send, _} -> + port_command(Port, list_to_binary(Text ++ "\n")), + [{sent, "sent"}|RemainingExpect]; + {sent, _} -> + Expect; + {done, _} -> + [] + end + end, Expected, Tokens), + %% Now that the fold is over, we should remove {sent, sent} if it's there. + %% The fold might have ended not matching anything or not sending anything + %% so it's possible we don't have to remove {sent, sent}. This will be passed + %% to interactive_loop's next iteration. + NewerExpected = case NewExpected of + [{sent, "sent"}|E] -> E; + E -> E + end, + %% If NewerExpected is empty, we've met all expected criteria and in order to boot + %% Otherwise, loop. + case NewerExpected of + [] -> ?assert(true); + _ -> interactive_loop(Port, NewerExpected) + end; + {Port, {exit_status,_}} -> + %% This port has exited. Maybe the last thing we did was {send, [4]} which + %% as Ctrl-D would have exited the console. If Expected is empty, then + %% We've met every expectation. Yay! If not, it means we've exited before + %% something expected happened. + ?assertEqual([], Expected) + after rt_config:get(rt_max_wait_time) -> + %% interactive_loop is going to wait until it matches expected behavior + %% If it doesn't, the test should fail; however, without a timeout it + %% will just hang forever in search of expected behavior. See also: Parenting + ?assertEqual([], Expected) + end. + +spawn_cmd(Cmd) -> + spawn_cmd(Cmd, []). +spawn_cmd(Cmd, Opts) -> + Port = open_port({spawn, lists:flatten(Cmd)}, [stream, in, exit_status] ++ Opts), + Port. + +wait_for_cmd(Port) -> + rt:wait_until(node(), + fun(_) -> + receive + {Port, Msg={exit_status, _}} -> + catch port_close(Port), + self() ! {Port, Msg}, + true + after 0 -> + false + end + end), + get_cmd_result(Port, []). + +cmd(Cmd) -> + cmd(Cmd, []). + +cmd(Cmd, Opts) -> + wait_for_cmd(spawn_cmd(Cmd, Opts)). + +get_cmd_result(Port, Acc) -> + receive + {Port, {data, Bytes}} -> + get_cmd_result(Port, [Bytes|Acc]); + {Port, {exit_status, Status}} -> + Output = lists:flatten(lists:reverse(Acc)), + {Status, Output} + after 0 -> + timeout + end. + +get_ip(_Node) -> + %% localhost 4 lyfe + "127.0.0.1". + +node_id(Node) -> + NodeMap = rt_config:get(rt_nodes), + orddict:fetch(Node, NodeMap). + +node_version(N) -> + VersionMap = rt_config:get(rt_versions), + orddict:fetch(N, VersionMap). + +riak(Node, Args) -> + N = node_id(Node), + Path = relpath(node_version(N)), + Result = run_riak(N, Path, Args), + lager:info("~s", [Result]), + {ok, Result}. + +-spec set_conf(atom() | string(), [{string(), string()}]) -> ok. +set_conf(all, NameValuePairs) -> + lager:info("rtdev:set_conf(all, ~p)", [NameValuePairs]), + [ set_conf(DevPath, NameValuePairs) || DevPath <- devpaths()], + ok; +set_conf(Node, NameValuePairs) when is_atom(Node) -> + append_to_conf_file(get_riak_conf(Node), NameValuePairs), + ok; +set_conf(DevPath, NameValuePairs) -> + [append_to_conf_file(RiakConf, NameValuePairs) || RiakConf <- all_the_files(DevPath, "etc/riak.conf")], + ok. + +whats_up() -> + io:format("Here's what's running...~n"), + + Up = [rpc:call(Node, os, cmd, ["pwd"]) || Node <- nodes()], + [io:format(" ~s~n",[string:substr(Dir, 1, length(Dir)-1)]) || Dir <- Up]. + +riak_admin_cmd(Path, N, Args) -> + Quoted = + lists:map(fun(Arg) when is_list(Arg) -> + lists:flatten([$", Arg, $"]); + (_) -> + erlang:error(badarg) + end, Args), + ArgStr = string:join(Quoted, " "), + ExecName = rt_config:get(exec_name, "riak"), + io_lib:format("~s/dev/dev~b/bin/~s-admin ~s", [Path, N, ExecName, ArgStr]). + +% Private functions + +relpath(Vsn) -> + Path = ?PATH, + relpath(Vsn, Path). + +relpath(Vsn, Paths=[{_,_}|_]) -> + orddict:fetch(Vsn, orddict:from_list(Paths)); +relpath(current, Path) -> + Path; +relpath(root, Path) -> + Path; +relpath(_, _) -> + throw("Version requested but only one path provided"). + +riakcmd(Path, N, Cmd) -> + ExecName = rt_config:get(exec_name, "riak"), + io_lib:format("~s/dev/dev~b/bin/~s ~s", [Path, N, ExecName, Cmd]). + +run_riak(N, Path, Cmd) -> + lager:info("Running: ~s", [riakcmd(Path, N, Cmd)]), + R = os:cmd(riakcmd(Path, N, Cmd)), + case Cmd of + "start" -> + rt_cover:maybe_start_on_node(?DEV(N), node_version(N)), + %% Intercepts may load code on top of the cover compiled + %% modules. We'll just get no coverage info then. + case rt_intercept:are_intercepts_loaded(?DEV(N)) of + false -> + ok = rt_intercept:load_intercepts([?DEV(N)]); + true -> + ok + end, + R; + "stop" -> + rt_cover:maybe_stop_on_node(?DEV(N)), + R; + _ -> + R + end. + +append_to_conf_file(File, NameValuePairs) -> + Settings = lists:flatten( + [io_lib:format("~n~s = ~s~n", [Name, Value]) || {Name, Value} <- NameValuePairs]), + file:write_file(File, Settings, [append]). + +get_riak_conf(Node) -> + N = node_id(Node), + Path = relpath(node_version(N)), + io_lib:format("~s/dev/dev~b/etc/riak.conf", [Path, N]). + +all_the_files(DevPath, File) -> + case filelib:is_dir(DevPath) of + true -> + Wildcard = io_lib:format("~s/dev/dev*/~s", [DevPath, File]), + filelib:wildcard(Wildcard); + _ -> + lager:debug("~s is not a directory.", [DevPath]), + [] + end. + +devpaths() -> + lists:usort([ DevPath || {_Name, DevPath} <- proplists:delete(root, rt_config:get(rtdev_path))]). diff --git a/src/rt_node.erl b/src/rt_node.erl index 21b204035..e52316035 100644 --- a/src/rt_node.erl +++ b/src/rt_node.erl @@ -49,7 +49,7 @@ %% @doc Start the specified Riak node start(Node) -> - ?HARNESS:start(Node). + rt_harness:start(Node). %% @doc Start the specified Riak `Node' and wait for it to be pingable start_and_wait(Node) -> @@ -63,7 +63,7 @@ async_start(Node) -> stop(Node) -> lager:info("Stopping riak on ~p", [Node]), timer:sleep(10000), %% I know, I know! - ?HARNESS:stop(Node). + rt_harness:stop(Node). %%rpc:call(Node, init, stop, []). %% @doc Stop the specified Riak `Node' and wait until it is not pingable @@ -73,12 +73,12 @@ stop_and_wait(Node) -> %% @doc Upgrade a Riak `Node' to the specified `NewVersion'. upgrade(Node, NewVersion) -> - ?HARNESS:upgrade(Node, NewVersion). + rt_harness:upgrade(Node, NewVersion). %% @doc Upgrade a Riak `Node' to the specified `NewVersion' and update %% the config based on entries in `Config'. upgrade(Node, NewVersion, Config) -> - ?HARNESS:upgrade(Node, NewVersion, Config). + rt_harness:upgrade(Node, NewVersion, Config). %% @doc Upgrade a Riak node to a specific version using the alternate %% leave/upgrade/rejoin approach diff --git a/src/rtdev.erl b/src/rtdev.erl index a3bd4b1aa..fc504a543 100644 --- a/src/rtdev.erl +++ b/src/rtdev.erl @@ -18,8 +18,34 @@ %% %% ------------------------------------------------------------------- -%% @private -module(rtdev). +-behaviour(test_harness). +-export([start/1, + stop/1, + deploy_clusters/1, + clean_data_dir/2, + spawn_cmd/1, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). + -compile(export_all). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/rtperf.erl b/src/rtperf.erl index 2f132d588..ee109fffe 100644 --- a/src/rtperf.erl +++ b/src/rtperf.erl @@ -1,9 +1,67 @@ -module(rtperf). +-behaviour(test_harness). + +-export([start/1, + stop/1, + deploy_clusters/1, + clean_data_dir/2, + spawn_cmd/1, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). + -compile(export_all). -include_lib("eunit/include/eunit.hrl"). -include_lib("kernel/include/file.hrl"). +admin(Node, Args) -> + rt_harness_util:admin(Node, Args). + +attach(Node, Expected) -> + rt_harness_util:attach(Node, Expected). + +attach_direct(Node, Expected) -> + rt_harness_util:attach_direct(Node, Expected). + +cmd(Cmd, Opts) -> + rt_harness_util:cmd(Cmd, Opts). + +console(Node, Expected) -> + rt_harness_util:console(Node, Expected). + +get_ip(Node) -> + rt_harness_util:get_ip(Node). + +node_id(Node) -> + rt_harness_util:get_ip(Node). + +node_version(N) -> + rt_harness_util:node_version(N). + +riak(Node, Args) -> + rt_harness_util:riak(Node, Args). + +set_conf(Node, NameValuePairs) -> + rt_harness_util:set_conf(Node, NameValuePairs). + update_app_config(Node, Config) -> rtssh:update_app_config(Node, Config). @@ -401,3 +459,13 @@ deploy_nodes(NodeConfig, Hosts) -> start(Node) -> rtssh:start(Node). + +spawn_cmd(Cmd) -> + rt_harness_util:spawn_cmd(Cmd). + +spawn_cmd(Cmd, Opts) -> + rt_harness_util:spawn_cmd(Cmd, Opts). + +whats_up() -> + rt_harness_util:whats_up(). + diff --git a/src/rtssh.erl b/src/rtssh.erl index 3d7f19372..31d352c8f 100644 --- a/src/rtssh.erl +++ b/src/rtssh.erl @@ -1,7 +1,39 @@ -module(rtssh). +-behaviour(test_harness). + +-export([start/1, + stop/1, + deploy_clusters/1, + clean_data_dir/2, + spawn_cmd/1, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_deps/0, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). + -compile(export_all). -include_lib("eunit/include/eunit.hrl"). +admin(Node, Args) -> + rt_harness_util:admin(Node, Args). + get_version() -> unknown. @@ -291,13 +323,6 @@ remote_cmd(Node, Cmd) -> {0, Result} = ssh_cmd(Node, Cmd), {ok, Result}. -admin(Node, Args) -> - Cmd = riak_admin_cmd(Node, Args), - lager:info("Running: ~s :: ~s", [get_host(Node), Cmd]), - {0, Result} = ssh_cmd(Node, Cmd), - lager:info("~s", [Result]), - {ok, Result}. - riak(Node, Args) -> Result = run_riak(Node, Args), lager:info("~s", [Result]), @@ -667,8 +692,29 @@ node_id(_Node) -> %% orddict:fetch(Node, NodeMap). 1. -node_version(Node) -> - orddict:fetch(Node, rt_config:get(rt_versions)). +set_backend(Backend) -> + set_backend(Backend, []). + +set_backend(Backend, OtherOpts) -> + lager:info("rtssh:set_backend(~p, ~p)", [Backend, OtherOpts]), + Opts = [{storage_backend, Backend} | OtherOpts], + update_app_config(all, [{riak_kv, Opts}]), + get_backends(). + +whats_up() -> + io:format("Here's what's running...~n"), + + Up = [rpc:call(Node, os, cmd, ["pwd"]) || Node <- nodes()], + [io:format(" ~s~n",[string:substr(Dir, 1, length(Dir)-1)]) || Dir <- Up]. + +node_version(_Node) -> ok. + +attach(_Node, _Expected) -> ok. + +attach_direct(_Node, _Expected) -> ok. + +console(_Node, _Expected) -> ok. + %%%=================================================================== %%% Local command spawning diff --git a/src/test_harness.erl b/src/test_harness.erl new file mode 100644 index 000000000..53474841c --- /dev/null +++ b/src/test_harness.erl @@ -0,0 +1,48 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2013-2014 Basho Technologies, Inc. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- +-module(test_harness). + +-callback start(Node :: node()) -> 'ok'. +-callback stop(Node :: node()) -> 'ok'. +-callback deploy_clusters(ClusterConfigs :: list()) -> list(). +-callback clean_data_dir(Nodes :: list(), SubDir :: string()) -> 'ok'. +-callback spawn_cmd(Cmd :: string()) -> Port :: pos_integer(). +-callback spawn_cmd(Cmd :: string(), Opts :: list()) -> Port :: pos_integer(). +-callback cmd(Cmd :: string()) -> term()|timeout. +-callback cmd(Cmd :: string(), Opts :: [atom()]) -> term()|timeout. +-callback setup_harness(Test :: string(), Args :: list()) -> 'ok'. +-callback get_version() -> term(). +-callback get_backends() -> [atom()]. +-callback set_backend(Backend :: atom()) -> [atom()]. +-callback whats_up() -> string(). +-callback get_ip(Node :: node()) -> string(). +-callback node_id(Node :: node()) -> NodeMap :: term(). +-callback node_version(N :: node()) -> VersionMap :: term(). +-callback admin(Node :: node(), Args :: [atom()]) -> {'ok', string()}. +-callback riak(Node :: node(), Args :: [atom()]) -> {'ok', string()}. +-callback attach(Node :: node(), Expected:: list()) -> 'ok'. +-callback attach_direct(Node :: node(), Expected:: list()) -> 'ok'. +-callback console(Node :: node(), Expected:: list()) -> 'ok'. +-callback update_app_config(atom()|node(), Config :: term()) -> 'ok'. +-callback teardown() -> list(). +-callback set_conf(atom()|node(), NameValuePairs :: [{string(), string()}]) -> 'ok'. +-callback set_advanced_conf(atom()|node(), NameValuePairs :: [{string(), string()}]) -> 'ok'. + + From f595253d6c02f009cbe26228ab08fbf5b92c8207 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Fri, 1 Aug 2014 15:54:18 -0400 Subject: [PATCH 2/6] Convert rt_cs_dev harness to test_harness behaviour. --- src/rt_cs_dev.erl | 77 ++++++++++++------- src/rt_harness_util.erl | 166 +++++++++++++++++++++++++++++++++++++++- src/rtssh.erl | 13 ++-- 3 files changed, 220 insertions(+), 36 deletions(-) diff --git a/src/rt_cs_dev.erl b/src/rt_cs_dev.erl index afd3f955f..4dcb28121 100644 --- a/src/rt_cs_dev.erl +++ b/src/rt_cs_dev.erl @@ -20,7 +20,41 @@ %% @private -module(rt_cs_dev). --compile(export_all). +-behavious(test_harness). + +-export([start/1, + stop/1, + deploy_clusters/1, + clean_data_dir/2, + create_dirs/1, + spawn_cmd/1, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, + get_deps/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2, + upgrade/2, + deploy_nodes/1, + versions/0, + get_node_logs/0, + get_node_logs/1]). + -include_lib("eunit/include/eunit.hrl"). -define(DEVS(N), lists:concat(["dev", N, "@127.0.0.1"])). @@ -31,6 +65,12 @@ get_deps() -> lists:flatten(io_lib:format("~s/dev/dev1/lib", [relpath(current)])). +deploy_clusters(ClusterConfig) -> + rt_harness_util:deploy_clusters(ClusterConfig). + +get_ip(Node) -> + rt_harness_util:get_ip(Node). + setup_harness(_Test, _Args) -> Path = relpath(root), %% Stop all discoverable nodes, not just nodes we'll be using for this test. @@ -61,10 +101,6 @@ relpath(Vsn) -> Path = ?BUILD_PATHS, path(Vsn, Path). -srcpath(Vsn) -> - Path = ?SRC_PATHS, - path(Vsn, Path). - path(Vsn, Paths=[{_,_}|_]) -> orddict:fetch(Vsn, orddict:from_list(Paths)); path(current, Path) -> @@ -225,19 +261,6 @@ rm_dir(Dir) -> ?assertCmd("rm -rf " ++ Dir), ?assertEqual(false, filelib:is_dir(Dir)). -add_default_node_config(Nodes) -> - case rt_config:get(rt_default_config, undefined) of - undefined -> ok; - Defaults when is_list(Defaults) -> - rt:pmap(fun(Node) -> - update_app_config(Node, Defaults) - end, Nodes), - ok; - BadValue -> - lager:error("Invalid value for rt_default_config : ~p", [BadValue]), - throw({invalid_config, {rt_default_config, BadValue}}) - end. - deploy_nodes(NodeConfig) -> Path = relpath(root), lager:info("Riak path: ~p", [Path]), @@ -249,14 +272,14 @@ deploy_nodes(NodeConfig) -> VersionMap = lists:zip(NodesN, Versions), %% Check that you have the right versions available - [ check_node(Version) || Version <- VersionMap ], + [ rt_harness_util:check_node(Version) || Version <- VersionMap ], rt_config:set(rt_nodes, NodeMap), rt_config:set(rt_versions, VersionMap), create_dirs(Nodes), %% Set initial config - add_default_node_config(Nodes), + rt_harness_util:add_default_node_config(Nodes), rt:pmap(fun({_, default}) -> ok; ({Node, Config}) -> @@ -482,14 +505,6 @@ get_cmd_result(Port, Acc) -> timeout end. -check_node({_N, Version}) -> - case proplists:is_defined(Version, rt_config:get(build_paths)) of - true -> ok; - _ -> - lager:error("You don't have Riak ~s installed or configured", [Version]), - erlang:error("You don't have Riak " ++ atom_to_list(Version) ++ " installed or configured") - end. - set_backend(Backend) -> lager:info("rtdev:set_backend(~p)", [Backend]), update_app_config(all, [{riak_kv, [{storage_backend, Backend}]}]), @@ -532,3 +547,9 @@ get_node_logs(Base) -> {ok, Port} = file:open(Filename, [read, binary]), {lists:nthtail(RootLen, Filename), Port} end || Filename <- filelib:wildcard(Root ++ "/*/dev/dev*/log/*") ]. + +set_advanced_conf(Node, NameValuePairs) -> + rt_harness_util:set_advanced_conf(Node, NameValuePairs). + +set_conf(Node, NameValuePairs) -> + rt_harness_util:set_conf(Node, NameValuePairs). diff --git a/src/rt_harness_util.erl b/src/rt_harness_util.erl index c636c0cbf..7963939c0 100644 --- a/src/rt_harness_util.erl +++ b/src/rt_harness_util.erl @@ -31,11 +31,15 @@ cmd/1, cmd/2, console/2, + deploy_clusters/1, get_ip/1, node_id/1, node_version/1, riak/2, set_conf/2, + set_advanced_conf/2, + get_advanced_riak_conf/1, + update_app_config_file/2, spawn_cmd/1, spawn_cmd/2, whats_up/0]). @@ -58,6 +62,74 @@ attach_direct(Node, Expected) -> console(Node, Expected) -> interactive(Node, "console", Expected). +deploy_clusters(ClusterConfigs) -> + NumNodes = rt_config:get(num_nodes, 6), + RequestedNodes = lists:flatten(ClusterConfigs), + + case length(RequestedNodes) > NumNodes of + true -> + erlang:error("Requested more nodes than available"); + false -> + Nodes = deploy_nodes(RequestedNodes), + {DeployedClusters, _} = lists:foldl( + fun(Cluster, {Clusters, RemNodes}) -> + {A, B} = lists:split(length(Cluster), RemNodes), + {Clusters ++ [A], B} + end, {[], Nodes}, ClusterConfigs), + DeployedClusters + end. + +deploy_nodes(NodeConfig) -> + Path = relpath(root), + lager:info("Riak path: ~p", [Path]), + NumNodes = length(NodeConfig), + NodesN = lists:seq(1, NumNodes), + Nodes = [?DEV(N) || N <- NodesN], + NodeMap = orddict:from_list(lists:zip(Nodes, NodesN)), + {Versions, Configs} = lists:unzip(NodeConfig), + VersionMap = lists:zip(NodesN, Versions), + + %% Check that you have the right versions available + [ check_node(Version) || Version <- VersionMap ], + rt_config:set(rt_nodes, NodeMap), + rt_config:set(rt_versions, VersionMap), + + create_dirs(Nodes), + + %% Set initial config + add_default_node_config(Nodes), + rt:pmap(fun({_, default}) -> + ok; + ({Node, {cuttlefish, Config}}) -> + set_conf(Node, Config); + ({Node, Config}) -> + rt_config:update_app_config(Node, Config) + end, + lists:zip(Nodes, Configs)), + + %% create snmp dirs, for EE + create_dirs(Nodes), + + %% Start nodes + %%[run_riak(N, relpath(node_version(N)), "start") || N <- Nodes], + rt:pmap(fun(N) -> run_riak(N, relpath(node_version(N)), "start") end, NodesN), + + %% Ensure nodes started + [ok = rt:wait_until_pingable(N) || N <- Nodes], + + %% %% Enable debug logging + %% [rpc:call(N, lager, set_loglevel, [lager_console_backend, debug]) || N <- Nodes], + + %% We have to make sure that riak_core_ring_manager is running before we can go on. + [ok = rt:wait_until_registered(N, riak_core_ring_manager) || N <- Nodes], + + %% Ensure nodes are singleton clusters + [ok = rt_ring:check_singleton_node(?DEV(N)) || {N, Version} <- VersionMap, + Version /= "0.14.2"], + + lager:info("Deployed nodes: ~p", [Nodes]), + Nodes. + interactive(Node, Command, Exp) -> N = node_id(Node), Path = relpath(node_version(N)), @@ -133,6 +205,13 @@ interactive_loop(Port, Expected) -> ?assertEqual([], Expected) end. +node_to_host(Node) -> + case string:tokens(atom_to_list(Node), "@") of + ["riak", Host] -> Host; + _ -> + throw(io_lib:format("rtssh:node_to_host couldn't figure out the host of ~p", [Node])) + end. + spawn_cmd(Cmd) -> spawn_cmd(Cmd, []). spawn_cmd(Cmd, Opts) -> @@ -170,9 +249,21 @@ get_cmd_result(Port, Acc) -> timeout end. -get_ip(_Node) -> - %% localhost 4 lyfe - "127.0.0.1". + +get_host(Node) when is_atom(Node) -> + try orddict:fetch(Node, rt_config:get(rt_hosts)) of + Host -> Host + catch _:_ -> + %% Let's try figuring this out from the node name + node_to_host(Node) + end; +get_host(Host) -> Host. + +get_ip(Node) when is_atom(Node) -> + get_ip(get_host(Node)); +get_ip(Host) -> + {ok, IP} = inet:getaddr(Host, inet), + string:join([integer_to_list(X) || X <- tuple_to_list(IP)], "."). node_id(Node) -> NodeMap = rt_config:get(rt_nodes), @@ -281,3 +372,72 @@ all_the_files(DevPath, File) -> devpaths() -> lists:usort([ DevPath || {_Name, DevPath} <- proplists:delete(root, rt_config:get(rtdev_path))]). + +create_dirs(Nodes) -> + Snmp = [node_path(Node) ++ "/data/snmp/agent/db" || Node <- Nodes], + [?assertCmd("mkdir -p " ++ Dir) || Dir <- Snmp]. + +check_node({_N, Version}) -> + case proplists:is_defined(Version, rt_config:get(rtdev_path)) of + true -> ok; + _ -> + lager:error("You don't have Riak ~s installed or configured", [Version]), + erlang:error("You don't have Riak " ++ atom_to_list(Version) ++ " installed or configured") + end. + +add_default_node_config(Nodes) -> + case rt_config:get(rt_default_config, undefined) of + undefined -> ok; + Defaults when is_list(Defaults) -> + rt:pmap(fun(Node) -> + rt_config:update_app_config(Node, Defaults) + end, Nodes), + ok; + BadValue -> + lager:error("Invalid value for rt_default_config : ~p", [BadValue]), + throw({invalid_config, {rt_default_config, BadValue}}) + end. + +node_path(Node) -> + N = node_id(Node), + Path = relpath(node_version(N)), + lists:flatten(io_lib:format("~s/dev/dev~b", [Path, N])). + +set_advanced_conf(all, NameValuePairs) -> + lager:info("rtdev:set_advanced_conf(all, ~p)", [NameValuePairs]), + [ set_advanced_conf(DevPath, NameValuePairs) || DevPath <- devpaths()], + ok; +set_advanced_conf(Node, NameValuePairs) when is_atom(Node) -> + append_to_conf_file(get_advanced_riak_conf(Node), NameValuePairs), + ok; +set_advanced_conf(DevPath, NameValuePairs) -> + [update_app_config_file(RiakConf, NameValuePairs) || RiakConf <- all_the_files(DevPath, "etc/advanced.config")], + ok. + +get_advanced_riak_conf(Node) -> + N = node_id(Node), + Path = relpath(node_version(N)), + io_lib:format("~s/dev/dev~b/etc/advanced.config", [Path, N]). + +update_app_config_file(ConfigFile, Config) -> + lager:info("rtdev:update_app_config_file(~s, ~p)", [ConfigFile, Config]), + + BaseConfig = case file:consult(ConfigFile) of + {ok, [ValidConfig]} -> + ValidConfig; + {error, enoent} -> + [] + end, + MergeA = orddict:from_list(Config), + MergeB = orddict:from_list(BaseConfig), + NewConfig = + orddict:merge(fun(_, VarsA, VarsB) -> + MergeC = orddict:from_list(VarsA), + MergeD = orddict:from_list(VarsB), + orddict:merge(fun(_, ValA, _ValB) -> + ValA + end, MergeC, MergeD) + end, MergeA, MergeB), + NewConfigOut = io_lib:format("~p.", [NewConfig]), + ?assertEqual(ok, file:write_file(ConfigFile, NewConfigOut)), + ok. diff --git a/src/rtssh.erl b/src/rtssh.erl index 31d352c8f..4cbe4851e 100644 --- a/src/rtssh.erl +++ b/src/rtssh.erl @@ -707,14 +707,17 @@ whats_up() -> Up = [rpc:call(Node, os, cmd, ["pwd"]) || Node <- nodes()], [io:format(" ~s~n",[string:substr(Dir, 1, length(Dir)-1)]) || Dir <- Up]. -node_version(_Node) -> ok. +node_version(Node) -> + rt_harness_util:node_version(Node). -attach(_Node, _Expected) -> ok. +attach(Node, Expected) -> + rt_harness_util:attach(Node, Expected). -attach_direct(_Node, _Expected) -> ok. - -console(_Node, _Expected) -> ok. +attach_direct(Node, Expected) -> + rt_harness_util:attach_direct(Node, Expected). +console(Node, Expected) -> + rt_harness_util:console(Node, Expected). %%%=================================================================== %%% Local command spawning From 194a77d54f50d6c31d325dfe0489a480066a8908 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Mon, 4 Aug 2014 08:13:23 -0400 Subject: [PATCH 3/6] Fix typo in rt_cs_dev: 'behavious' -> 'behaviour'. --- src/rt_cs_dev.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rt_cs_dev.erl b/src/rt_cs_dev.erl index 4dcb28121..edae81926 100644 --- a/src/rt_cs_dev.erl +++ b/src/rt_cs_dev.erl @@ -20,7 +20,7 @@ %% @private -module(rt_cs_dev). --behavious(test_harness). +-behaviour(test_harness). -export([start/1, stop/1, From bdac7c56dddd3846809a3e43047931db23eeae24 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Mon, 4 Aug 2014 13:57:42 -0400 Subject: [PATCH 4/6] Fix whitespace in rt_cs_dev. --- src/rt_cs_dev.erl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rt_cs_dev.erl b/src/rt_cs_dev.erl index edae81926..5c055c345 100644 --- a/src/rt_cs_dev.erl +++ b/src/rt_cs_dev.erl @@ -28,27 +28,27 @@ clean_data_dir/2, create_dirs/1, spawn_cmd/1, - spawn_cmd/2, - cmd/1, - cmd/2, - setup_harness/2, - get_version/0, - get_backends/0, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, get_deps/0, - set_backend/1, - whats_up/0, - get_ip/1, - node_id/1, - node_version/1, - admin/2, - riak/2, - attach/2, - attach_direct/2, - console/2, - update_app_config/2, - teardown/0, - set_conf/2, - set_advanced_conf/2, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2, upgrade/2, deploy_nodes/1, versions/0, From 7a3f0f9de812fb10dec9f1c78d532cd0730ef866 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Wed, 6 Aug 2014 07:36:21 -0400 Subject: [PATCH 5/6] Fix whitespace problems; add some edoc to harness modules. --- src/rt_harness.erl | 4 ++++ src/rt_harness_util.erl | 3 ++- src/rtdev.erl | 40 ++++++++++++++++++++-------------------- src/rtperf.erl | 40 ++++++++++++++++++++-------------------- src/rtssh.erl | 40 ++++++++++++++++++++-------------------- src/test_harness.erl | 1 + 6 files changed, 67 insertions(+), 61 deletions(-) diff --git a/src/rt_harness.erl b/src/rt_harness.erl index cd573e9c4..2d1414760 100644 --- a/src/rt_harness.erl +++ b/src/rt_harness.erl @@ -17,6 +17,10 @@ %% under the License. %% %% ------------------------------------------------------------------- +%% @doc rt_harness provides a level of indirection between the modules +%% calling into the harness and the configured harness, resolving the call +%% to the configured harness. Calls such as 'rt_harness:start(Node)' will +%% be resolved to the configured harness. -module(rt_harness). -define(HARNESS_MODULE, (rt_config:get(rt_harness))). diff --git a/src/rt_harness_util.erl b/src/rt_harness_util.erl index 7963939c0..82c6a4abb 100644 --- a/src/rt_harness_util.erl +++ b/src/rt_harness_util.erl @@ -17,7 +17,8 @@ %% under the License. %% %% ------------------------------------------------------------------- - +%% @doc The purpose of rt_harness_util is to provide common functions +%% to harness modules implementing the test_harness behaviour. -module(rt_harness_util). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/rtdev.erl b/src/rtdev.erl index fc504a543..375de6e47 100644 --- a/src/rtdev.erl +++ b/src/rtdev.erl @@ -25,26 +25,26 @@ deploy_clusters/1, clean_data_dir/2, spawn_cmd/1, - spawn_cmd/2, - cmd/1, - cmd/2, - setup_harness/2, - get_version/0, - get_backends/0, - set_backend/1, - whats_up/0, - get_ip/1, - node_id/1, - node_version/1, - admin/2, - riak/2, - attach/2, - attach_direct/2, - console/2, - update_app_config/2, - teardown/0, - set_conf/2, - set_advanced_conf/2]). + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). -compile(export_all). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/rtperf.erl b/src/rtperf.erl index ee109fffe..f0a68c65c 100644 --- a/src/rtperf.erl +++ b/src/rtperf.erl @@ -6,26 +6,26 @@ deploy_clusters/1, clean_data_dir/2, spawn_cmd/1, - spawn_cmd/2, - cmd/1, - cmd/2, - setup_harness/2, - get_version/0, - get_backends/0, - set_backend/1, - whats_up/0, - get_ip/1, - node_id/1, - node_version/1, - admin/2, - riak/2, - attach/2, - attach_direct/2, - console/2, - update_app_config/2, - teardown/0, - set_conf/2, - set_advanced_conf/2]). + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). -compile(export_all). diff --git a/src/rtssh.erl b/src/rtssh.erl index 4cbe4851e..69d97bbeb 100644 --- a/src/rtssh.erl +++ b/src/rtssh.erl @@ -6,27 +6,27 @@ deploy_clusters/1, clean_data_dir/2, spawn_cmd/1, - spawn_cmd/2, - cmd/1, - cmd/2, - setup_harness/2, + spawn_cmd/2, + cmd/1, + cmd/2, + setup_harness/2, get_deps/0, - get_version/0, - get_backends/0, - set_backend/1, - whats_up/0, - get_ip/1, - node_id/1, - node_version/1, - admin/2, - riak/2, - attach/2, - attach_direct/2, - console/2, - update_app_config/2, - teardown/0, - set_conf/2, - set_advanced_conf/2]). + get_version/0, + get_backends/0, + set_backend/1, + whats_up/0, + get_ip/1, + node_id/1, + node_version/1, + admin/2, + riak/2, + attach/2, + attach_direct/2, + console/2, + update_app_config/2, + teardown/0, + set_conf/2, + set_advanced_conf/2]). -compile(export_all). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/test_harness.erl b/src/test_harness.erl index 53474841c..11006372f 100644 --- a/src/test_harness.erl +++ b/src/test_harness.erl @@ -17,6 +17,7 @@ %% under the License. %% %% ------------------------------------------------------------------- +%% @doc behaviour for all test harnesses. -module(test_harness). -callback start(Node :: node()) -> 'ok'. From b3a886752dff6a1d6d464e956505ded54fd39ae2 Mon Sep 17 00:00:00 2001 From: Jon Anderson Date: Wed, 6 Aug 2014 14:56:06 -0400 Subject: [PATCH 6/6] Fix code reference for edoc in rt_harness. --- src/rt_harness.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rt_harness.erl b/src/rt_harness.erl index 2d1414760..1270f3bfc 100644 --- a/src/rt_harness.erl +++ b/src/rt_harness.erl @@ -19,7 +19,7 @@ %% ------------------------------------------------------------------- %% @doc rt_harness provides a level of indirection between the modules %% calling into the harness and the configured harness, resolving the call -%% to the configured harness. Calls such as 'rt_harness:start(Node)' will +%% to the configured harness. Calls such as `rt_harness:start(Node)' will %% be resolved to the configured harness. -module(rt_harness).