2012-10-10 22:14:06 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2012 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.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
2012-08-24 14:08:04 +00:00
|
|
|
-module(riaknostic_rt).
|
2012-12-14 15:50:49 +00:00
|
|
|
-behavior(riak_test).
|
2012-09-07 23:49:36 +00:00
|
|
|
-export([confirm/0]).
|
2012-08-31 14:53:05 +00:00
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
2012-08-24 14:08:04 +00:00
|
|
|
|
|
|
|
%% Change when a new release comes out.
|
|
|
|
-define(RIAKNOSTIC_URL, "https://github.com/basho/riaknostic/downloads/riaknostic-1.0.2.tar.gz").
|
|
|
|
|
2012-12-03 21:13:55 +00:00
|
|
|
%% REQUIRES (sh, curl, tar)
|
|
|
|
|
2012-09-07 23:49:36 +00:00
|
|
|
confirm() ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Build a small cluster
|
|
|
|
[Node1, _Node2] = rt:build_cluster(2, []),
|
2012-12-03 21:13:55 +00:00
|
|
|
?assertEqual(ok, rt:wait_until_nodes_ready([Node1])),
|
|
|
|
|
|
|
|
%% Install riaknostic for Riak versions below 1.3.0
|
|
|
|
riaknostic_bootstrap(Node1),
|
|
|
|
|
|
|
|
%% Run through all tests on Node1
|
2012-12-03 22:31:57 +00:00
|
|
|
check_riaknostic_execute(Node1),
|
2012-12-03 21:13:55 +00:00
|
|
|
check_riaknostic_usage(Node1),
|
|
|
|
check_riaknostic_command_list(Node1),
|
|
|
|
check_riaknostic_log_levels(Node1),
|
|
|
|
|
|
|
|
%% Done!
|
|
|
|
lager:info("Test riaknostic: PASS"),
|
|
|
|
pass.
|
|
|
|
|
|
|
|
riaknostic_bootstrap(Node) ->
|
|
|
|
lager:info("Check if riaknostic is installed"),
|
|
|
|
{ok, RiaknosticOut1} = rt:admin(Node, ["diag"]),
|
|
|
|
riaknostic_install((rt:str(RiaknosticOut1, "is not present!")), Node).
|
2012-08-24 14:08:04 +00:00
|
|
|
|
2012-12-03 21:13:55 +00:00
|
|
|
%% riaknostic is already installed, move along
|
|
|
|
riaknostic_install(false, _Node) ->
|
|
|
|
ok;
|
2012-08-31 14:53:05 +00:00
|
|
|
|
2012-12-03 21:13:55 +00:00
|
|
|
%% install riaknostic
|
|
|
|
riaknostic_install(true, Node) ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Install
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:info("Installing Riaknostic"),
|
|
|
|
{ok, LibDir} = rpc:call(Node, application, get_env, [riak_core, platform_lib_dir]),
|
|
|
|
Cmd = io_lib:format("sh -c \"cd ~s && curl -O -L ~s && tar xzf ~s\"",
|
|
|
|
[LibDir, ?RIAKNOSTIC_URL, filename:basename(?RIAKNOSTIC_URL)]),
|
2012-08-24 14:08:04 +00:00
|
|
|
lager:info("Running command: ~s", [Cmd]),
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:debug("~p~n", [rpc:call(Node, os, cmd, [Cmd])]),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%% Check that riaknostic executes
|
2012-12-03 22:31:57 +00:00
|
|
|
check_riaknostic_execute(Node) ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Execute
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:info("** Check Riaknostic executes"),
|
|
|
|
{ok, RiaknosticOut} = rt:admin(Node, ["diag"]),
|
|
|
|
?assertNot(rt:str(RiaknosticOut, "is not present!")),
|
|
|
|
?assertNot(rt:str(RiaknosticOut, "[debug]")),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%% Check that riaknostic gives a usage message
|
|
|
|
check_riaknostic_usage(Node) ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Check usage message
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:info("** Run Riaknostic usage message"),
|
|
|
|
{ok, RiaknosticOut} = rt:admin(Node, ["diag", "--help"]),
|
|
|
|
?assert(rt:str(RiaknosticOut, "Usage: riak-admin")),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%% Check that riaknostic gives a command listing
|
|
|
|
check_riaknostic_command_list(Node) ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Check commands list
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:info("** Run Riaknostic commands list message"),
|
|
|
|
{ok, RiaknosticOut} = rt:admin(Node, ["diag", "--list"]),
|
|
|
|
?assert(rt:str(RiaknosticOut, "Available diagnostic checks")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " disk ")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " dumps ")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " memory_use ")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " nodes_connected")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " ring_membership")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " ring_preflists ")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " ring_size ")),
|
|
|
|
?assert(rt:str(RiaknosticOut, " search ")),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%% Check that log levels can be set
|
|
|
|
check_riaknostic_log_levels(Node) ->
|
2012-08-24 14:08:04 +00:00
|
|
|
%% Check log levels
|
2012-12-03 21:13:55 +00:00
|
|
|
lager:info("** Run Riaknostic with a different log level"),
|
|
|
|
{ok, RiaknosticOut} = rt:admin(Node, ["diag", "--level", "debug"]),
|
|
|
|
?assert(rt:str(RiaknosticOut, "[debug]")),
|
|
|
|
ok.
|
2012-08-24 14:08:04 +00:00
|
|
|
|