|
| 1 | +package com.sequenceiq.it.cloudbreak.mock; |
| 2 | + |
| 3 | +import static com.sequenceiq.it.spark.ITResponse.AMBARI_API_ROOT; |
| 4 | +import static com.sequenceiq.it.spark.ITResponse.SALT_API_ROOT; |
| 5 | + |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import org.junit.Before; |
| 9 | +import org.slf4j.Logger; |
| 10 | +import org.slf4j.LoggerFactory; |
| 11 | +import org.testng.Assert; |
| 12 | +import org.testng.annotations.BeforeMethod; |
| 13 | +import org.testng.annotations.Optional; |
| 14 | +import org.testng.annotations.Parameters; |
| 15 | +import org.testng.annotations.Test; |
| 16 | + |
| 17 | +import com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus; |
| 18 | +import com.sequenceiq.it.IntegrationTestContext; |
| 19 | +import com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants; |
| 20 | + |
| 21 | +public class MockKerberizedClusterCreationTest extends MockClusterCreationWithSaltSuccessTest { |
| 22 | + |
| 23 | + private static final Logger LOGGER = LoggerFactory.getLogger(MockKerberizedClusterCreationTest.class); |
| 24 | + |
| 25 | + private static final String DEFAULT_KERBEROS_PASSWORD = "admin123!@#"; |
| 26 | + |
| 27 | + private static final String DEFAULT_KERBEROS_ADMIN = "admin"; |
| 28 | + |
| 29 | + private static final String DEFAULT_KERBEROS_PRINCIPAL = "/admin"; |
| 30 | + |
| 31 | + private String kerberosPassword; |
| 32 | + |
| 33 | + private String kerberosAdmin; |
| 34 | + |
| 35 | + @Before |
| 36 | + public void setup() { } |
| 37 | + |
| 38 | + @BeforeMethod |
| 39 | + public void setContextParameters() { |
| 40 | + IntegrationTestContext itContext = getItContext(); |
| 41 | + Assert.assertNotNull(itContext.getContextParam(CloudbreakITContextConstants.BLUEPRINT_ID), "Blueprint id is mandatory."); |
| 42 | + Assert.assertNotNull(itContext.getContextParam(CloudbreakITContextConstants.STACK_ID), "Stack id is mandatory."); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + @Parameters({"clusterName", "ambariPort", "ambariUser", "ambariPassword", "emailNeeded", "enableSecurity", "kerberosMasterKey", "kerberosAdmin", |
| 47 | + "kerberosPassword", "runRecipesOnHosts", "checkAmbari", "mockPort"}) |
| 48 | + public void testClusterCreation(@Optional("it-cluster") String clusterName, @Optional("8080") String ambariPort, @Optional("admin") String ambariUser, |
| 49 | + @Optional("admin123!@#") String ambariPassword, @Optional("false") boolean emailNeeded, |
| 50 | + @Optional("true") boolean enableSecurity, @Optional(DEFAULT_KERBEROS_PASSWORD) String kerberosMasterKey, |
| 51 | + @Optional(DEFAULT_KERBEROS_ADMIN) String kerberosAdmin, @Optional(DEFAULT_KERBEROS_PASSWORD) String kerberosPassword, |
| 52 | + @Optional("") String runRecipesOnHosts, @Optional("true") boolean checkAmbari, @Optional("9443") int mockPort) throws Exception { |
| 53 | + |
| 54 | + this.kerberosAdmin = kerberosAdmin; |
| 55 | + this.kerberosPassword = kerberosPassword; |
| 56 | + |
| 57 | + super.testClusterCreation(clusterName, |
| 58 | + ambariPort, |
| 59 | + ambariUser, |
| 60 | + ambariPassword, |
| 61 | + emailNeeded, |
| 62 | + enableSecurity, |
| 63 | + kerberosMasterKey, |
| 64 | + kerberosAdmin, |
| 65 | + kerberosPassword, |
| 66 | + runRecipesOnHosts, |
| 67 | + checkAmbari, |
| 68 | + mockPort); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + protected void customMappings(Map<String, CloudVmMetaDataStatus> instanceMap) { |
| 73 | + LOGGER.info("Adding custom mappings for Kerberized cluster"); |
| 74 | + super.customMappings(instanceMap); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + protected void customVerifiers(Map<String, CloudVmMetaDataStatus> instanceMap, Long clusterId, String clusterName) { |
| 79 | + LOGGER.info("Adding custom verifiers for Kerberized cluster"); |
| 80 | + super.customVerifiers(instanceMap, clusterId, clusterName); |
| 81 | + |
| 82 | + verify(SALT_API_ROOT + "/run", "POST") |
| 83 | + .bodyContains("fun=grains.append") |
| 84 | + .bodyContains("kerberos_server_master") |
| 85 | + .exactTimes(1) |
| 86 | + .verify(); |
| 87 | + |
| 88 | + String principalKV = String.format("\"principal\": \"%s%s\"", kerberosAdmin, DEFAULT_KERBEROS_PRINCIPAL); |
| 89 | + String passwordKV = String.format("\"key\": \"%s\"", kerberosPassword); |
| 90 | + verify(AMBARI_API_ROOT + "/clusters/" + clusterName, "POST") |
| 91 | + .exactTimes(1) |
| 92 | + .bodyContains("\"alias\": \"kdc.admin.credential\"") |
| 93 | + .bodyContains(principalKV) |
| 94 | + .bodyContains(passwordKV) |
| 95 | + .verify(); |
| 96 | + } |
| 97 | +} |
0 commit comments