Search in sources :

Example 1 with Pillar

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar in project cloudbreak by hortonworks.

the class PillarSaveTest method testDiscovery.

@Test
public void testDiscovery() throws Exception {
    SaltConnector saltConnector = mock(SaltConnector.class);
    GenericResponses responses = new GenericResponses();
    GenericResponse response = new GenericResponse();
    response.setStatusCode(HttpStatus.OK.value());
    response.setAddress("10.0.0.2");
    responses.setResponses(Collections.singletonList(response));
    when(saltConnector.pillar(any(), any(Pillar.class))).thenReturn(responses);
    Set<Node> nodes = new HashSet<>();
    nodes.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    nodes.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    nodes.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    PillarSave pillarSave = new PillarSave(saltConnector, Sets.newHashSet("10.0.0.1"), nodes);
    pillarSave.call();
    ArgumentCaptor<Pillar> pillarCaptor = ArgumentCaptor.forClass(Pillar.class);
    ArgumentCaptor<Set> targetCaptor = ArgumentCaptor.forClass(Set.class);
    verify(saltConnector).pillar(targetCaptor.capture(), pillarCaptor.capture());
    Pillar pillar = pillarCaptor.getValue();
    Map<String, Map<String, Map<String, Object>>> pillarJson = (Map<String, Map<String, Map<String, Object>>>) pillar.getJson();
    Map<String, Map<String, Object>> hostMap = pillarJson.entrySet().iterator().next().getValue();
    for (Node node : nodes) {
        Assert.assertEquals(node.getHostname(), hostMap.get(node.getPrivateIp()).get("fqdn"));
        Assert.assertEquals(node.getHostname().split("\\.")[0], hostMap.get(node.getPrivateIp()).get("hostname"));
        Assert.assertEquals(Boolean.TRUE, hostMap.get(node.getPrivateIp()).get("public_address"));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)1 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)1 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)1 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)1 Pillar (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.junit.Test)1