mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
viriscsitest: Introduce testIscsiadmCbData struct
Some tests will want to pass their own callback data into the testIscsiadmCbData callback. Introduce testIscsiadmCbData struct to give this some form and order. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
e97cd364f7
commit
9c2ccd64c9
@ -60,6 +60,10 @@ const char *iscsiadmSendtargetsOutput =
|
|||||||
"10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n"
|
"10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n"
|
||||||
"10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n";
|
"10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n";
|
||||||
|
|
||||||
|
struct testIscsiadmCbData {
|
||||||
|
bool output_version;
|
||||||
|
};
|
||||||
|
|
||||||
static void testIscsiadmCb(const char *const*args,
|
static void testIscsiadmCb(const char *const*args,
|
||||||
const char *const*env ATTRIBUTE_UNUSED,
|
const char *const*env ATTRIBUTE_UNUSED,
|
||||||
const char *input ATTRIBUTE_UNUSED,
|
const char *input ATTRIBUTE_UNUSED,
|
||||||
@ -68,12 +72,13 @@ static void testIscsiadmCb(const char *const*args,
|
|||||||
int *status,
|
int *status,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
int *output_version = opaque;
|
struct testIscsiadmCbData *data = opaque;
|
||||||
|
|
||||||
if (args[0] && STREQ(args[0], ISCSIADM) &&
|
if (args[0] && STREQ(args[0], ISCSIADM) &&
|
||||||
args[1] && STREQ(args[1], "--mode") &&
|
args[1] && STREQ(args[1], "--mode") &&
|
||||||
args[2] && STREQ(args[2], "session") &&
|
args[2] && STREQ(args[2], "session") &&
|
||||||
args[3] == NULL) {
|
args[3] == NULL) {
|
||||||
if (*output_version == 1)
|
if (data->output_version)
|
||||||
ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutputNonFlash));
|
ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutputNonFlash));
|
||||||
else
|
else
|
||||||
ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutput));
|
ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutput));
|
||||||
@ -114,7 +119,7 @@ static void testIscsiadmCb(const char *const*args,
|
|||||||
|
|
||||||
struct testSessionInfo {
|
struct testSessionInfo {
|
||||||
const char *device_path;
|
const char *device_path;
|
||||||
int output_version;
|
bool output_version;
|
||||||
const char *expected_session;
|
const char *expected_session;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,11 +127,13 @@ static int
|
|||||||
testISCSIGetSession(const void *data)
|
testISCSIGetSession(const void *data)
|
||||||
{
|
{
|
||||||
const struct testSessionInfo *info = data;
|
const struct testSessionInfo *info = data;
|
||||||
int ver = info->output_version;
|
struct testIscsiadmCbData cbData = { 0 };
|
||||||
char *actual_session = NULL;
|
char *actual_session = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virCommandSetDryRun(NULL, testIscsiadmCb, &ver);
|
cbData.output_version = info->output_version;
|
||||||
|
|
||||||
|
virCommandSetDryRun(NULL, testIscsiadmCb, &cbData);
|
||||||
|
|
||||||
actual_session = virISCSIGetSession(info->device_path, true);
|
actual_session = virISCSIGetSession(info->device_path, true);
|
||||||
|
|
||||||
@ -227,11 +234,11 @@ mymain(void)
|
|||||||
|
|
||||||
# define DO_SESSION_TEST(name, session) \
|
# define DO_SESSION_TEST(name, session) \
|
||||||
do { \
|
do { \
|
||||||
struct testSessionInfo info = {name, 0, session}; \
|
struct testSessionInfo info = {name, false, session}; \
|
||||||
if (virTestRun("ISCSI get session test" name, \
|
if (virTestRun("ISCSI get session test" name, \
|
||||||
testISCSIGetSession, &info) < 0) \
|
testISCSIGetSession, &info) < 0) \
|
||||||
rv = -1; \
|
rv = -1; \
|
||||||
info.output_version = 1; \
|
info.output_version = true; \
|
||||||
if (virTestRun("ISCSI get (non-flash) session test" name, \
|
if (virTestRun("ISCSI get (non-flash) session test" name, \
|
||||||
testISCSIGetSession, &info) < 0) \
|
testISCSIGetSession, &info) < 0) \
|
||||||
rv = -1; \
|
rv = -1; \
|
||||||
|
Loading…
Reference in New Issue
Block a user