From 639e3d809b850879db29f6dd532f5653f22df62f Mon Sep 17 00:00:00 2001 From: andreaturli Date: Wed, 21 Feb 2018 12:10:32 +0100 Subject: [PATCH] Improve JcloudsWinrmingLiveTest coverage - add Azure ARM - improve error message for DefaultConnectivityResolver --- .../jclouds/DefaultConnectivityResolver.java | 40 +++++++++++-------- .../jclouds/AbstractJcloudsLiveTest.java | 5 ++- .../jclouds/JcloudsWinrmingLiveTest.java | 19 +++++++++ 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/DefaultConnectivityResolver.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/DefaultConnectivityResolver.java index d58660ac90..9434a22558 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/DefaultConnectivityResolver.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/DefaultConnectivityResolver.java @@ -19,11 +19,14 @@ package org.apache.brooklyn.location.jclouds; +import java.util.Collections; import java.util.Iterator; import java.util.Map; import javax.annotation.Nullable; +import com.google.common.base.Predicates; +import com.google.common.collect.Lists; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntityInitializer; import org.apache.brooklyn.api.entity.EntityLocal; @@ -181,24 +184,27 @@ public ManagementAddressResolveResult resolve( LoginCredentials credChoice = null; final Iterable managementCandidates = getManagementCandidates(location, node, config, options); - final Iterable credentialCandidates = getCredentialCandidates(location, node, options, config); - - // Try each pair of address and credential until one succeeds. - if (shouldCheckCredentials() && options.pollForReachableAddresses()) { - for (HostAndPort hap : managementCandidates) { - for (LoginCredentials cred : credentialCandidates) { - LOG.trace("Testing host={} with credential={}", hap, cred); - if (checkCredential(location, hap, cred, config, options.isWindows())) { - hapChoice = hap; - credChoice = cred; - break; + Iterable credentialCandidates = Collections.emptyList(); + if (!Iterables.isEmpty(managementCandidates)) { + credentialCandidates = getCredentialCandidates(location, node, options, config); + + // Try each pair of address and credential until one succeeds. + if (shouldCheckCredentials() && options.pollForReachableAddresses()) { + for (HostAndPort hap : managementCandidates) { + for (LoginCredentials cred : credentialCandidates) { + LOG.trace("Testing host={} with credential={}", hap, cred); + if (checkCredential(location, hap, cred, config, options.isWindows())) { + hapChoice = hap; + credChoice = cred; + break; + } } + if (hapChoice != null) break; } - if (hapChoice != null) break; + } else if (shouldCheckCredentials()) { + LOG.debug("{} set on {} but pollForFirstReachableAddress={}", + new Object[]{CHECK_CREDENTIALS.getName(), this, options.pollForReachableAddresses()}); } - } else if (shouldCheckCredentials()) { - LOG.debug("{} set on {} but pollForFirstReachableAddress={}", - new Object[]{CHECK_CREDENTIALS.getName(), this, options.pollForReachableAddresses()}); } if (hapChoice == null) { @@ -212,8 +218,10 @@ public ManagementAddressResolveResult resolve( } if (hapChoice == null) { - throw new IllegalStateException("jclouds did not return any IP addresses matching " + getNetworkMode() + " in " + location); + LOG.error("None of the addresses of node {} are reachable in mode {}", new Object[]{node, getNetworkMode()}); + throw new IllegalStateException("Could not determine management address for node: " + node + " in mode: " + getNetworkMode()); } + if (credChoice == null) { credChoice = Iterables.getFirst(credentialCandidates, null); if (credChoice == null) { diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java index a4d4c42c81..3143e7a357 100644 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java +++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java @@ -66,7 +66,10 @@ public class AbstractJcloudsLiveTest { public static final String GCE_PROVIDER = "google-compute-engine"; public static final String GCE_USCENTRAL_REGION_NAME = "us-central1-a"; - + + public static final String AZURE_ARM_PROVIDER = "azurecompute-arm"; + public static final String AZURE_ARM_REGION_NAME = "westeurope"; + protected BrooklynProperties brooklynProperties; protected LocalManagementContext managementContext; diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java index df9fefc485..b5a06861a0 100644 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java +++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java @@ -21,6 +21,9 @@ import java.util.Map; import org.apache.brooklyn.util.collections.MutableMap; +import org.jclouds.Constants; +import org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions; +import org.jclouds.azurecompute.compute.options.AzureComputeTemplateOptions; import org.jclouds.compute.domain.OsFamily; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -28,6 +31,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import static org.apache.brooklyn.core.location.LocationConfigKeys.OAUTH_ENDPOINT; + /** * Tests the initial WinRM command execution, for a VM provisioned through jclouds. */ @@ -49,12 +54,26 @@ public class JcloudsWinrmingLiveTest extends AbstractJcloudsLiveTest { public static final String GCE_LOCATION_SPEC = "jclouds:" + GCE_PROVIDER + ":" + GCE_USCENTRAL_REGION_NAME; public static final String GCE_IMAGE_NAME_REGEX = "windows-server-2012-r2-.*"; + public static final String AZURE_ARM_LOCATION_SPEC = "jclouds:" + AZURE_ARM_PROVIDER + ":" + AZURE_ARM_REGION_NAME; + public static final String AZURE_ARM_NAME_REGEX = "WindowsServer"; + public static final String SOFTLAYER_LOCATION_SPEC = "jclouds:" + SOFTLAYER_PROVIDER; public static final String SOFTLAYER_IMAGE_ID = "WIN_2012-STD-R2_64"; @DataProvider(name = "cloudAndImageNames") public Object[][] cloudAndImageNames() { return new Object[][] { + new Object[] { AZURE_ARM_LOCATION_SPEC, AZURE_ARM_NAME_REGEX, ImmutableMap.builder() + .put(Constants.PROPERTY_ENDPOINT, "https://management.azure.com/subscriptions/012e832d-7b27-4c30-9f21-22cdd9159d12") + .put(OAUTH_ENDPOINT.getName(), "https://login.microsoftonline.com/ba85e8cd-8c83-486e-a7e3-0d7666169d34/oauth2/token") + .put(JcloudsLocation.IMAGE_ID.getName(), "westeurope/MicrosoftWindowsServer/WindowsServer/2016-Datacenter") + .put("jclouds.azurecompute.arm.publishers", "MicrosoftWindowsServer") + .put("azure.arm.default.network.enabled", false) + .put("vmNameMaxLength", 15) + .put("destroyOnFailure", false) + .put("useJcloudsSshInit", false) + .build() + }, new Object[] { AWS_EC2_LOCATION_SPEC, AWS_EC2_IMAGE_NAME_REGEX, ImmutableMap.of() }, new Object[] { GCE_LOCATION_SPEC, GCE_IMAGE_NAME_REGEX, ImmutableMap.of(JcloudsLocation.LOGIN_USER.getName(), "myname") }, };