-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKPORT 2.16.6][PLAT-9906] Master data folders are not cleaned up w…
…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
Showing
2 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...src/test/java/com/yugabyte/yw/commissioner/tasks/subtasks/AnsibleConfigureServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |