Skip to content

Commit

Permalink
test: Add openbmc w/ httppower tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 17, 2019
1 parent 2de1403 commit 81f9625
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 3 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ AC_CONFIG_FILES( \
test/t54.conf \
test/t55.conf \
test/t60.conf \
test/t61.conf \
test/test.conf \
test/test4.conf \
)
Expand Down
10 changes: 7 additions & 3 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ check_PROGRAMS = \
cli \
ilom \
lom \
swpdu
swpdu \
openbmc-httppower

dist_check_SCRIPTS = \
pm-sim \
Expand All @@ -33,7 +34,7 @@ TESTS = t00 t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 \
t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 \
t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 \
t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 \
t56 t57 t58 t59 t60
t56 t57 t58 t59 t60 t61

XFAIL_TESTS =

Expand Down Expand Up @@ -93,6 +94,9 @@ cyclades_LDADD = $(common_ldadd)
ipmipower_SOURCES = ipmipower.c
ipmipower_LDADD = $(common_ldadd)

openbmc_httppower_SOURCES = openbmc-httppower.c
openbmc_httppower_LDADD = $(common_ldadd)

cli_SOURCES = cli.c
cli_LDADD = -L$(top_builddir)/libpowerman -lpowerman

Expand All @@ -104,7 +108,7 @@ check_DATA = \
t35.conf t36.conf t37.conf t38.conf t39.conf t40.conf t41.conf \
t42.conf t43.conf t44.conf t45.conf t46.conf t47.conf t48.conf \
t49.conf t50.conf t51.conf t53.conf t54.conf t55.conf t60.conf \
test4.conf test.conf
t61.conf test4.conf test.conf

EXTRA_DIST = $(TESTS:%=%.exp) t53.dev

2 changes: 2 additions & 0 deletions test/README
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ t50
Test bashfun demo script.
t51
Test Sun LOM using lom.c
t61
Test httppower openbmc using openbmc-httppower.c
139 changes: 139 additions & 0 deletions test/openbmc-httppower.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*****************************************************************************
* Copyright (C) 2004 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Jim Garlick <garlick@llnl.gov>
* UCRL-CODE-2002-008.
*
* This file is part of PowerMan, a remote power management program.
* For details, see http://code.google.com/p/powerman/
*
* PowerMan is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* PowerMan is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with PowerMan; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/

/* openbmc-httppower.c - mimic httppower talking to a openbmc server */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#include "xread.h"

static void
print_unauthenticated (void)
{
printf("{\n"
"\"data\": {\n"
"\"description\": \"Login required\"\n"
"},\n"
"\"message\": \"401 Unauthorized\",\n"
"\"status\": \"error\"\n"
"}\n");
}

static void
prompt_loop(void)
{
char buf[1024], urltmp[1024], datatmp[1024];
int hoststatus = 0; /* 0 = off, 1 = on */
int authenticated = 0;

for (;;) {
if (xreadline("httppower> ", buf, sizeof(buf)) == NULL)
break;
if (!strcmp(buf, "help")) {
printf("Commands are:\n");
printf(" get url data\n");
printf(" post url data\n");
printf(" put url data\n");
} else if (sscanf(buf, "post login %s", datatmp) == 1) {
if (!authenticated)
authenticated = 1;
printf("{\n"
"\"data\": \"User 'root' logged in\",\n"
"\"message\": \"200 OK\",\n"
"\"status\": \"ok\"\n"
"}\n");
} else if (sscanf(buf, "post logout %s", datatmp) == 1) {
if (authenticated) {
authenticated = 0;
printf("{\n"
"\"data\": \"User 'root' logged in\",\n"
"\"message\": \"200 OK\",\n"
"\"status\": \"ok\"\n"
"}\n");
}
else
printf("{\n"
"\"data\": \"No user logged in\",\n"
"\"message\": \"200 OK\",\n"
"\"status\": \"ok\"\n"
"}\n");
} else if (sscanf(buf, "get %s", urltmp) == 1) {
if (!authenticated) {
print_unauthenticated ();
continue;
}
if (strstr (urltmp, "CurrentPowerState") == NULL)
goto err;
printf("{\n"
"\"data\": \"xyz.openbmc_project.State.Chassis.PowerState.%s\",\n"
"\"message\": \"200 OK\",\n"
"\"status\": \"ok\"\n"
"}\n",
hoststatus ? "On" : "Off");
} else if (sscanf(buf, "put xyz/openbmc_project/state/host0/attr/RequestedHostTransition %s",
datatmp) == 1) {
if (!authenticated) {
print_unauthenticated ();
continue;
}
if (strstr (datatmp, "On")) {
hoststatus = 1;
}
else if (strstr (datatmp, "Off")) {
hoststatus = 0;
}
else if (strstr (datatmp, "Reboot")) {
if (!hoststatus)
hoststatus = 1;
}
else
goto err;
/* Doesn't matter what operation, output success */
printf("{\n"
"\"data\": null,\n"
"\"message\": \"200 OK\",\n"
"\"status\": \"ok\"\n"
"}\n");
} else
goto err;

continue;
err:
printf("Error\n");
}
}

int
main(int argc, char *argv[])
{
prompt_loop();
exit (0);
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
10 changes: 10 additions & 0 deletions test/t61
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
TEST=t61
$PATH_POWERMAN -Y -S $PATH_POWERMAND -C ${TEST_BUILDDIR}/$TEST.conf \
-q -1 t[0-4] \
-q -0 t[0-4] \
-q -c t[0-4] \
-q -0 t[0-4] \
-q >$TEST.out 2>$TEST.err
test $? = 0 || exit 1
diff $TEST.out ${TEST_SRCDIR}/$TEST.exp >$TEST.diff
13 changes: 13 additions & 0 deletions test/t61.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include "@top_srcdir@/etc/openbmc.dev"

device "b0" "openbmc" "@top_builddir@/test/openbmc-httppower |&"
device "b1" "openbmc" "@top_builddir@/test/openbmc-httppower |&"
device "b2" "openbmc" "@top_builddir@/test/openbmc-httppower |&"
device "b3" "openbmc" "@top_builddir@/test/openbmc-httppower |&"
device "b4" "openbmc" "@top_builddir@/test/openbmc-httppower |&"

node "t0" "b0" "t0"
node "t1" "b1" "t1"
node "t2" "b2" "t2"
node "t3" "b3" "t3"
node "t4" "b4" "t4"
19 changes: 19 additions & 0 deletions test/t61.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
off: t[0-4]
unknown:
Command completed successfully
on: t[0-4]
off:
unknown:
Command completed successfully
on:
off: t[0-4]
unknown:
Command completed successfully
on: t[0-4]
off:
unknown:
Command completed successfully
on:
off: t[0-4]
unknown:

0 comments on commit 81f9625

Please sign in to comment.