Skip to content

Commit

Permalink
[BACKPORT 2.16.6][PLAT-9906] Master data folders are not cleaned up w…
Browse files Browse the repository at this point in the history
…hen it is added back in shell mode

Summary:
Original diff - https://phorge.dev.yugabyte.com/D27473 (65b6b8226cad8bfacdc1d4f75c0bf5839095c6bf)

This fixes the regression. Further work can come in.

Fix.

Test Plan: Added some unit tests.

Reviewers: sanketh, amalyshev, cwang, nbhatia

Reviewed By: cwang

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D27546
  • Loading branch information
nkhogen committed Aug 3, 2023
1 parent defc255 commit 540f6ff
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ && taskParams().isMasterInShellMode
// Reset may be set only if node is not a master.
// Once isMaster is set, it can be tied to a cluster.
resetMasterState =
isChangeMasterConfigDone(universe, node, true, node.cloudInfo.private_ip);
isChangeMasterConfigDone(universe, node, false, node.cloudInfo.private_ip);
}
}
log.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) YugaByte, Inc.

package com.yugabyte.yw.commissioner.tasks.subtasks;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.yugabyte.yw.commissioner.AbstractTaskBase;
import com.yugabyte.yw.commissioner.Common;
import com.yugabyte.yw.commissioner.tasks.UniverseTaskBase.ServerType;
import com.yugabyte.yw.common.ApiUtils;
import com.yugabyte.yw.common.FakeDBApplication;
import com.yugabyte.yw.common.ModelFactory;
import com.yugabyte.yw.common.NodeManager;
import com.yugabyte.yw.common.ShellResponse;
import com.yugabyte.yw.models.AccessKey;
import com.yugabyte.yw.models.AvailabilityZone;
import com.yugabyte.yw.models.Customer;
import com.yugabyte.yw.models.Provider;
import com.yugabyte.yw.models.Region;
import com.yugabyte.yw.models.Universe;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import junitparams.JUnitParamsRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.yb.client.ListMastersResponse;
import org.yb.client.YBClient;
import org.yb.util.ServerInfo;

@RunWith(JUnitParamsRunner.class)
public class AnsibleConfigureServerTest extends FakeDBApplication {
private Customer defaultCustomer;
private AvailabilityZone az;
private Provider provider;
private Universe universe;
private ListMastersResponse mockMastersResponse;
private YBClient mockYBClient;

@Before
public void setup() {
defaultCustomer = ModelFactory.testCustomer();
setupUniverse(Common.CloudType.onprem);
mockMastersResponse = mock(ListMastersResponse.class);
mockYBClient = mock(YBClient.class);
when(mockService.getClient(any(), any())).thenReturn(mockYBClient);
List<ServerInfo> servers = new ArrayList<>();
// IP for host-n1.
servers.add(new ServerInfo(UUID.randomUUID().toString(), "10.0.0.1", 9070, false, "NONE"));
try {
when(mockNodeManager.nodeCommand(any(), any())).thenReturn(ShellResponse.create(0, ""));
when(mockYBClient.listMasters()).thenReturn(mockMastersResponse);
} catch (Exception e) {
fail();
}
when(mockMastersResponse.getMasters()).thenReturn(servers);
}

private void setupUniverse(Common.CloudType cloudType) {
AccessKey.KeyInfo keyInfo = new AccessKey.KeyInfo();
provider = ModelFactory.newProvider(defaultCustomer, cloudType);
Region r = Region.create(provider, "r-1", "r-1", "yb-image");
AccessKey.create(provider.uuid, "demo-key", keyInfo);
az = AvailabilityZone.createOrThrow(r, "az-1", "az-1", "subnet-1");
universe =
ModelFactory.createUniverse(
cloudType.name() + "-universe", defaultCustomer.getCustomerId(), cloudType);
// Save the updates to the universe.
Universe.saveDetails(universe.getUniverseUUID(), ApiUtils.mockUniverseUpdater());
}

@Test
public void testNoResetMasterStateInMaster() {
AnsibleConfigureServers.Params params = new AnsibleConfigureServers.Params();
params.azUuid = az.uuid;
params.universeUUID = universe.getUniverseUUID();
params.nodeName = "host-n1";
params.resetMasterState = true;
params.isMasterInShellMode = true;
params.setProperty("processType", ServerType.MASTER.name().toLowerCase());
AnsibleConfigureServers ansibleConfigServer =
AbstractTaskBase.createTask(AnsibleConfigureServers.class);
ansibleConfigServer.initialize(params);
ansibleConfigServer.run();
verify(mockNodeManager, times(1)).nodeCommand(NodeManager.NodeCommandType.Configure, params);
assertFalse(params.resetMasterState);
}

@Test
public void testResetMasterState() {
AnsibleConfigureServers.Params params = new AnsibleConfigureServers.Params();
params.azUuid = az.uuid;
params.universeUUID = universe.getUniverseUUID();
params.nodeName = "host-n2";
params.resetMasterState = true;
params.isMasterInShellMode = true;
params.setProperty("processType", ServerType.MASTER.name().toLowerCase());
AnsibleConfigureServers ansibleConfigServer =
AbstractTaskBase.createTask(AnsibleConfigureServers.class);
ansibleConfigServer.initialize(params);
ansibleConfigServer.run();
verify(mockNodeManager, times(1)).nodeCommand(NodeManager.NodeCommandType.Configure, params);
assertTrue(params.resetMasterState);
}

@Test
public void testNoResetMasterStateNonShellMode() {
AnsibleConfigureServers.Params params = new AnsibleConfigureServers.Params();
params.azUuid = az.uuid;
params.universeUUID = universe.getUniverseUUID();
params.nodeName = "host-n2";
params.resetMasterState = true;
params.isMasterInShellMode = false;
params.setProperty("processType", ServerType.MASTER.name().toLowerCase());
AnsibleConfigureServers ansibleConfigServer =
AbstractTaskBase.createTask(AnsibleConfigureServers.class);
ansibleConfigServer.initialize(params);
ansibleConfigServer.run();
verify(mockNodeManager, times(1)).nodeCommand(NodeManager.NodeCommandType.Configure, params);
assertFalse(params.resetMasterState);
}
}

0 comments on commit 540f6ff

Please sign in to comment.