use of com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode in project cloudbreak by hortonworks.
the class SaltOrchestratorTest method testStopClusterManagerAgent.
@Test
public void testStopClusterManagerAgent() throws Exception {
Set<Node> downscaleTargets = new HashSet<>();
downscaleTargets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg", "fqdn2", null));
downscaleTargets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg", "fqdn3", null));
PowerMockito.mockStatic(SaltStates.class);
Set<String> responsiveAddresses = new HashSet<>();
responsiveAddresses.add("10.0.0.1");
responsiveAddresses.add("10.0.0.2");
responsiveAddresses.add("10.0.0.3");
PowerMockito.when(SaltStates.collectMinionIpAddresses(any(), any())).thenReturn(responsiveAddresses);
Set<OrchestrationNode> allNodes = new HashSet<>();
allNodes.add(() -> new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg", "fqdn3", null));
allNodes.addAll(downscaleTargets.stream().map(node -> (OrchestrationNode) () -> node).collect(Collectors.toSet()));
Callable pillarSaveCallable = mock(Callable.class);
when(saltRunner.runner(any(), any(), any())).thenReturn(pillarSaveCallable);
when(saltRunner.runner(any(), any(), any(), anyInt(), anyBoolean())).thenReturn(mock(Callable.class));
saltOrchestrator.stopClusterManagerAgent(() -> allNodes, gatewayConfig, targets, downscaleTargets, exitCriteriaModel, new CmAgentStopFlags(false, false, false));
ArgumentCaptor<ModifyGrainBase> modifyGrainBaseArgumentCaptor = ArgumentCaptor.forClass(ModifyGrainBase.class);
ArgumentCaptor<PillarSave> pillarSaveArgumentCaptor = ArgumentCaptor.forClass(PillarSave.class);
verify(pillarSaveCallable, times(1)).call();
InOrder inOrder = inOrder(saltCommandRunner, saltRunner);
inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
ModifyGrainBase modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
assertThat(modifyGrainBase, instanceOf(GrainAddRunner.class));
assertEquals("roles", modifyGrainBase.getKey());
assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
inOrder.verify(saltRunner).runner(pillarSaveArgumentCaptor.capture(), any(), any());
PillarSave capturedPillarSave = pillarSaveArgumentCaptor.getValue();
ArgumentCaptor<SaltJobIdTracker> saltJobIdCaptor = ArgumentCaptor.forClass(SaltJobIdTracker.class);
inOrder.verify(saltRunner).runner(saltJobIdCaptor.capture(), any(), any(), anyInt(), anyBoolean());
inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
inOrder.verifyNoMoreInteractions();
modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
assertThat(modifyGrainBase, instanceOf(GrainRemoveRunner.class));
assertEquals("roles", modifyGrainBase.getKey());
assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
Set<String> targets = Whitebox.getInternalState(capturedPillarSave, "targets");
assertTrue(targets.contains("10.0.0.1"));
Pillar pillar = Whitebox.getInternalState(capturedPillarSave, "pillar");
Map<String, Map> hosts = (Map) ((Map) pillar.getJson()).get("hosts");
assertTrue(hosts.keySet().contains("10.0.0.1"));
assertTrue(hosts.keySet().contains("10.0.0.2"));
assertTrue(hosts.keySet().contains("10.0.0.3"));
}
Aggregations