From 946c0deb7c8174dfe220b00fbc07b6a342c2f40f Mon Sep 17 00:00:00 2001 From: Ivana Yovcheva Date: Fri, 4 Aug 2017 13:53:35 +0300 Subject: [PATCH] Byon dsl config - fix tests failures --- ...nRmMachineLocationExternalConfigYamlTest.java | 2 +- .../FixedListMachineProvisioningLocation.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WinRmMachineLocationExternalConfigYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WinRmMachineLocationExternalConfigYamlTest.java index 7257ef33c8..bf73dd83b7 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WinRmMachineLocationExternalConfigYamlTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WinRmMachineLocationExternalConfigYamlTest.java @@ -120,7 +120,7 @@ public void testWindowsMachinesNoExternalIPProvider() throws Exception { waitForApplicationTasks(app); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { - Asserts.expectedFailureOfType(e, NullPointerException.class); + Asserts.expectedFailureContains(e, "Must specify exactly one of 'ssh' or 'winrm' for machine"); } } diff --git a/core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java b/core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java index 89b0c3ba8d..648285a7d5 100644 --- a/core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java +++ b/core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Set; +import com.google.common.base.Preconditions; import com.google.common.net.HostAndPort; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.location.LocationSpec; @@ -384,7 +385,10 @@ protected void updateMachineConfig(T machine, Map flags) { // For backwards compatibility, where peristed state did not have this. origConfigs = Maps.newLinkedHashMap(); } - parseMachineConfig((AbstractLocation) machine); + if (((AbstractLocation) machine).config().getBag().getAllConfig().get("provider") != null && + ((AbstractLocation) machine).config().getBag().getAllConfig().get("provider").equals("byon")) { + parseMachineConfig((AbstractLocation) machine); + } Map strFlags = ConfigBag.newInstance(flags).getAllConfig(); Map origConfig = ((ConfigurationSupportInternal)machine.config()).getLocalBag().getAllConfig(); origConfigs.put(machine, origConfig); @@ -399,12 +403,14 @@ private void parseMachineConfig(AbstractLocation machine) { String winrm = machine.config().get(ConfigKeys.newStringConfigKey("winrm")); machine.config().removeKey(ConfigKeys.newStringConfigKey("winrm")); - Map tcpPortMappings = (Map) machine.config().get(ConfigKeys.newConfigKey(Map.class, "tcpPortMappings")); - - if (ssh == null && winrm == null) { - throw new IllegalArgumentException("Must specify exactly one of 'ssh' or 'winrm' for machine: "+machine); + if (ssh ==null && winrm == null && machine.config().get(ConfigKeys.newStringConfigKey("address")) != null) { + return; } + Preconditions.checkArgument(ssh != null || winrm != null, "Must specify exactly one of 'ssh' or 'winrm' for machine: " + machine); + + Map tcpPortMappings = (Map) machine.config().get(ConfigKeys.newConfigKey(Map.class, "tcpPortMappings")); + UserAndHostAndPort userAndHostAndPort; String host; int port;