Skip to content

Commit

Permalink
test(single replica, rebuild): add test cases for single replica rebu…
Browse files Browse the repository at this point in the history
…ild cases (#275)

 add test cases for single replica rebuild cases.

Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
  • Loading branch information
sai chaithanya authored and pawanpraka1 committed Nov 6, 2019
1 parent e6918bc commit 55b3edc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 27 additions & 3 deletions tests/cstor/gtest/test_uzfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,6 @@ set_zvol_io_hdr(zvol_io_hdr_t *hdrp, zvol_op_status_t status,
hdrp->opcode = opcode;
hdrp->len = len;
}

TEST(uZFSRebuildStart, TestStartRebuild) {
int i;
uzfs_mgmt_conn_t *conn;
Expand Down Expand Up @@ -1413,6 +1412,7 @@ TEST(uZFSRebuildStart, TestStartRebuild) {
EXPECT_EQ(ZVOL_OP_STATUS_FAILED, ((zvol_io_hdr_t *)conn->conn_buf)->status);
EXPECT_EQ(2, zinfo->refcnt);

uzfs_zinfo_set_status(zinfo, ZVOL_STATUS_DEGRADED);
/* invalid rebuild state */
for (i = 1; i < 5; i++) {
conn->conn_buf = NULL;
Expand All @@ -1423,6 +1423,7 @@ TEST(uZFSRebuildStart, TestStartRebuild) {
EXPECT_EQ(ZVOL_OP_STATUS_FAILED, ((zvol_io_hdr_t *)conn->conn_buf)->status);
EXPECT_EQ(2, zinfo->refcnt);
}

/* We are covering this code path from zrepl_rebuild test case */
#if 0
/* rebuild for single replica case */
Expand Down Expand Up @@ -2811,7 +2812,7 @@ void mock_tgt_thread(void *arg)
zvol_state_t *zv;
socklen_t in_len;
zvol_io_hdr_t hdr, phdr;
rebuild_req_t req;
rebuild_req_t req;
struct sockaddr in_addr;
zvol_op_resize_data_t resize;
char buf[512];
Expand Down Expand Up @@ -3004,6 +3005,15 @@ void mock_tgt_thread(void *arg)
p = (char *)&req;
}

/* Single Replica when volumes are healthy */
if (mgmt_test_case == 25) {
hdr.opcode = ZVOL_OPCODE_START_REBUILD;
hdr.len = sizeof (rebuild_req_t);
bzero(&req, sizeof (rebuild_req_t));
strcpy(req.dw_volname, zinfo->name);
p = (char *)&req;
}

send_hdr:

if (phdr.opcode == ZVOL_OPCODE_SNAP_PREPARE) {
Expand Down Expand Up @@ -3342,13 +3352,27 @@ TEST(MgmtThreadTest, RebuildFailureWrongRebuildState) {
EXPECT_EQ(status, ZVOL_OP_STATUS_FAILED);
}

/* Rebuild success, Single replica success */
/* Rebuild failed, Single replica */
TEST(MgmtThreadTest, RebuildFailureSingleReplica) {
uzfs_mgmt_conn_t *conn = (uzfs_mgmt_conn_t *)zinfo->mgmt_conn;
mgmt_thread_test_case(24);
EXPECT_EQ(status, ZVOL_OP_STATUS_FAILED); // errout on healthy replica
}

/* Rebuild success, Single replica case when volumes are healthy but quorum is off*/
TEST(MgmtThreadTest, RebuildFailureNonQuorumSingleHealthyReplica) {
uzfs_zinfo_set_status(zinfo, ZVOL_STATUS_HEALTHY);
uzfs_zvol_set_rebuild_status(zinfo->main_zv, ZVOL_REBUILDING_DONE);

uint64_t quorum = 0;
EXPECT_EQ(0, dsl_prop_set_int(zinfo->main_zv->zv_name,
zfs_prop_to_name(ZFS_PROP_QUORUM), ZPROP_SRC_LOCAL, quorum));

uzfs_mgmt_conn_t *conn = (uzfs_mgmt_conn_t *)zinfo->mgmt_conn;
mgmt_thread_test_case(25);
EXPECT_EQ(status, ZVOL_OP_STATUS_FAILED);
}

TEST(RebuildMgmtTest, RebuildFailureOldDegraded) {
rebuild_scanner = &uzfs_zvol_rebuild_scanner;
dw_replica_fn = &uzfs_mock_zvol_rebuild_dw_replica;
Expand Down
4 changes: 2 additions & 2 deletions tests/cstor/gtest/test_zrepl_prot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,8 @@ TEST(ReplicaState, SingleReplicaQuorumOff) {
wait_for_zvol_status(zvol_name1, ioseq1, control_fd1, ZVOL_STATUS_HEALTHY, ZVOL_REBUILDING_DONE);
wait_for_zvol_status(zvol_name2, ioseq1, control_fd2, ZVOL_STATUS_DEGRADED, ZVOL_REBUILDING_INIT);

/* transition the zvol to online state */
transition_zvol_to_online(ioseq1, control_fd1, zvol_name1, ZVOL_OP_STATUS_FAILED, MIN_SUPPORTED_REPLICA_VERSION);
/* transition the zvol to online state since replica is already Healthy it should return ZVOL_OP_STATUS_OK */
transition_zvol_to_online(ioseq1, control_fd1, zvol_name1, ZVOL_OP_STATUS_OK, MIN_SUPPORTED_REPLICA_VERSION);

zrepl.kill();
}
Expand Down

0 comments on commit 55b3edc

Please sign in to comment.