diff options
author | Kaushal M <kaushal@redhat.com> | 2012-11-20 15:17:06 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2012-11-23 02:08:16 -0800 |
commit | d5999c107a89dda38e8107ab8660130e052418b6 (patch) | |
tree | 727ff381d54e9d931400d15b316a4a962301a070 | |
parent | 14693665710677dfc809af2db199be3ecadacb18 (diff) |
cli: XML output for "geo-replication <VOL> {start|stop}"
Change-Id: I8d2213cc00deb458fb765b848d0e3452574cc98f
BUG: 864499
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.org/4217
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r-- | cli/src/cli-rpc-ops.c | 4 | ||||
-rw-r--r-- | cli/src/cli-xml-output.c | 78 | ||||
-rw-r--r-- | cli/src/cli.h | 4 | ||||
-rw-r--r-- | tests/bugs/bug-864499.t | 20 |
4 files changed, 104 insertions, 2 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 19451e0590e..44202037169 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -3307,8 +3307,8 @@ gf_cli_gsync_set_cbk (struct rpc_req *req, struct iovec *iov, goto out; if (global_state->mode & GLUSTER_MODE_XML) { - ret = cli_xml_output_dict ("volGeoRep", dict, rsp.op_ret, - rsp.op_errno, rsp.op_errstr); + ret = cli_xml_output_vol_gsync (dict, rsp.op_ret, rsp.op_errno, + rsp.op_errstr); if (ret) gf_log ("cli", GF_LOG_ERROR, "Error outputting to xml"); diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 34b046cc976..47c0854b2ed 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -3168,3 +3168,81 @@ out: return 0; #endif } + +int +cli_xml_output_vol_gsync (dict_t *dict, int op_ret, int op_errno, + char *op_errstr) +{ +#if (HAVE_LIB_XML) + int ret = -1; + xmlTextWriterPtr writer = NULL; + xmlBufferPtr buf = NULL; + char *master = NULL; + char *slave = NULL; + + int type = 0; + + GF_ASSERT (dict); + + ret = cli_begin_xml_output (&writer, &buf); + if (ret) + goto out; + + ret = cli_xml_output_common (writer, op_ret, op_errno, op_errstr); + if (ret) + goto out; + + /* <geoRep> */ + ret = xmlTextWriterStartElement (writer, (xmlChar *)"geoRep"); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = dict_get_int32 (dict, "type", &type); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to get type"); + goto out; + } + + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"type", + "%d", type); + XML_RET_CHECK_AND_GOTO (ret, out); + + switch (type) { + case GF_GSYNC_OPTION_TYPE_START: + case GF_GSYNC_OPTION_TYPE_STOP: + if (dict_get_str (dict, "master", &master) != 0) + master = "???"; + if (dict_get_str (dict, "slave", &slave) != 0) + slave = "???"; + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"master", + "%s", master); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"slave", + "%s", slave); + XML_RET_CHECK_AND_GOTO (ret, out); + + break; + + case GF_GSYNC_OPTION_TYPE_CONFIG: + case GF_GSYNC_OPTION_TYPE_STATUS: + // TODO: XML output for these two types. + default: + ret = 0; + break; + } + + /* </geoRep> */ + ret = xmlTextWriterEndElement (writer); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = cli_end_xml_output (writer, buf); +out: + gf_log ("cli",GF_LOG_DEBUG, "Returning %d", ret); + return ret; +#else + return 0; +#endif +} diff --git a/cli/src/cli.h b/cli/src/cli.h index 0221f2e85e9..a5f85ec8835 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -361,4 +361,8 @@ cli_xml_output_vol_create (dict_t *dict, int op_ret, int op_errno, int cli_xml_output_generic_volume (char *op, dict_t *dict, int op_ret, int op_errno, char *op_errstr); + +int +cli_xml_output_vol_gsync (dict_t *dict, int op_ret, int op_errno, + char *op_errstr); #endif /* __CLI_H__ */ diff --git a/tests/bugs/bug-864499.t b/tests/bugs/bug-864499.t new file mode 100644 index 00000000000..03c7bbe136f --- /dev/null +++ b/tests/bugs/bug-864499.t @@ -0,0 +1,20 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc + +cleanup; + + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume create $V0 $H0:$B0/brick0 +TEST $CLI volume start $V0 + +TEST "$CLI volume geo-replication $V0 $B0/slave start --xml | xmllint --format -" + +TEST "$CLI volume geo-replication $V0 $B0/slave stop --xml | xmllint --format -" + +TEST $CLI volume stop $V0 + +cleanup; + |