You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/09/23 12:23:31 UTC

[4/8] incubator-brooklyn git commit: Add 7zip windows blueprint test

Add 7zip windows blueprint test


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f25c6162
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f25c6162
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f25c6162

Branch: refs/heads/master
Commit: f25c616286884f718f66a8fc266b1865b16e5157
Parents: d499c81
Author: Aled Sage <al...@gmail.com>
Authored: Wed Sep 23 01:06:01 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Sep 23 01:32:49 2015 +0100

----------------------------------------------------------------------
 .../blueprints/AbstractBlueprintTest.java       |  38 ++++++-
 .../Windows7zipBlueprintLiveTest.java           | 100 +++++++++++++++++++
 .../src/test/resources/7zip-catalog.yaml        |  42 ++++++++
 .../launcher/src/test/resources/install7zip.ps1 |  35 +++++++
 4 files changed, 212 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f25c6162/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
index 3e0468d..e367a2f 100644
--- a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
+++ b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
@@ -19,12 +19,14 @@
 package org.apache.brooklyn.launcher.blueprints;
 
 import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertTrue;
 
 import java.io.File;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.Collection;
 
+import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -37,17 +39,21 @@ import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
 import org.apache.brooklyn.core.mgmt.rebind.RebindOptions;
 import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
+import org.apache.brooklyn.launcher.BrooklynLauncher;
+import org.apache.brooklyn.launcher.SimpleYamlLauncherForTests;
+import org.apache.brooklyn.launcher.camp.BrooklynCampPlatformLauncher;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.EntityTestUtils;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.stream.Streams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
-import org.apache.brooklyn.launcher.BrooklynLauncher;
-import org.apache.brooklyn.launcher.SimpleYamlLauncherForTests;
-import org.apache.brooklyn.launcher.camp.BrooklynCampPlatformLauncher;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 
 public abstract class AbstractBlueprintTest {
 
@@ -107,6 +113,32 @@ public abstract class AbstractBlueprintTest {
         }
     }
 
+    protected void runCatalogTest(String catalogFile, Reader yamlApp) throws Exception {
+        runCatalogTest(catalogFile, yamlApp, Predicates.alwaysTrue());
+    }
+    
+    protected void runCatalogTest(String catalogFile, Reader yamlApp, Predicate<? super Application> assertion) throws Exception {
+        Reader catalogInput = Streams.reader(new ResourceUtils(this).getResourceFromUrl(catalogFile));
+        String catalogContent = Streams.readFully(catalogInput);
+        Iterable<? extends CatalogItem<?, ?>> items = launcher.getManagementContext().getCatalog().addItems(catalogContent);
+        
+        try {
+            final Application app = launcher.launchAppYaml(yamlApp);
+            
+            assertNoFires(app);
+            assertTrue(assertion.apply(app));
+            
+            Application newApp = rebind();
+            assertNoFires(newApp);
+            assertTrue(assertion.apply(app));
+            
+        } finally {
+            for (CatalogItem<?, ?> item : items) {
+                launcher.getManagementContext().getCatalog().deleteCatalogItem(item.getSymbolicName(), item.getVersion());
+            }
+        }
+    }
+    
     protected void runTest(String yamlFile) throws Exception {
         final Application app = launcher.launchAppYaml(yamlFile);
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f25c6162/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/Windows7zipBlueprintLiveTest.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/Windows7zipBlueprintLiveTest.java b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/Windows7zipBlueprintLiveTest.java
new file mode 100644
index 0000000..068f428
--- /dev/null
+++ b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/Windows7zipBlueprintLiveTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.launcher.blueprints;
+
+import java.io.StringReader;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.location.MachineProvisioningLocation;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.entity.software.base.VanillaWindowsProcess;
+import org.apache.brooklyn.entity.software.base.test.location.WindowsTestFixture;
+import org.apache.brooklyn.location.winrm.AdvertiseWinrmLoginPolicy;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.text.Strings;
+import org.python.google.common.collect.Iterables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+import io.cloudsoft.winrm4j.winrm.WinRmTool;
+import io.cloudsoft.winrm4j.winrm.WinRmToolResponse;
+
+public class Windows7zipBlueprintLiveTest extends AbstractBlueprintTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Windows7zipBlueprintLiveTest.class);
+
+    protected MachineProvisioningLocation<WinRmMachineLocation> location;
+    protected WinRmMachineLocation machine;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        super.setUp();
+        location = WindowsTestFixture.setUpWindowsLocation(mgmt);
+        machine = location.obtain(ImmutableMap.of());
+    }
+    
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        try {
+            if (location != null && machine != null) location.release(machine);
+        } finally {
+            super.tearDown();
+        }
+    }
+    
+    @Test(groups={"Live"})
+    public void test7zip() throws Exception {
+        String yamlApp = Joiner.on("\n").join(
+                "location:",
+                "  byon:",
+                "    hosts:",
+                "    - winrm: "+machine.getAddress().getHostAddress()+":5985",
+                "      password: "+machine.config().get(WinRmMachineLocation.PASSWORD),
+                "      user: Administrator",
+                "      osFamily: windows",
+                "services:",
+                "- type: org.apache.brooklyn.windows.7zip:1.0");
+        
+        Predicate<Application> asserter = new Predicate<Application>() {
+            @Override public boolean apply(Application app) {
+                VanillaWindowsProcess entity = Iterables.getOnlyElement(Entities.descendants(app, VanillaWindowsProcess.class));
+                String winRMAddress = entity.getAttribute(AdvertiseWinrmLoginPolicy.VM_USER_CREDENTIALS); 
+                String ipPort = Strings.getFirstWordAfter(winRMAddress, "@");
+                String user = Strings.getFirstWord(winRMAddress);
+                String password = Strings.getFirstWordAfter(winRMAddress, ":");
+                
+                WinRmTool winRmTool = WinRmTool.connect(ipPort, user, password);
+                WinRmToolResponse winRmResponse = winRmTool.executePs(ImmutableList.of("(Get-Item \"C:\\\\Program Files\\\\7-Zip\\\\7z.exe\").name"));
+                
+                LOG.info("winRmResponse: code="+winRmResponse.getStatusCode()+"; out="+winRmResponse.getStdOut()+"; err="+winRmResponse.getStdErr());
+                return "7z.exe\r\n".equals(winRmResponse.getStdOut());
+            }
+        };
+        
+        runCatalogTest("7zip-catalog.yaml", new StringReader(yamlApp), asserter);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f25c6162/usage/launcher/src/test/resources/7zip-catalog.yaml
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/resources/7zip-catalog.yaml b/usage/launcher/src/test/resources/7zip-catalog.yaml
new file mode 100644
index 0000000..55c4389
--- /dev/null
+++ b/usage/launcher/src/test/resources/7zip-catalog.yaml
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+brooklyn.catalog:
+  id: org.apache.brooklyn.windows.7zip
+  version: 1.0
+  description: A Windows Server, with 7Zip installed
+  displayName: 7Zip
+  iconUrl: http://www.7-zip.org/7ziplogo.png
+  itemType: template
+
+  item:
+    services:
+    - type: brooklyn.entity.basic.VanillaWindowsProcess
+      name: 7Zip
+      brooklyn.config:
+        onbox.base.dir.skipResolution: true
+        templates.install:
+          classpath://install7zip.ps1: "C:\\install7zip.ps1"
+        install.command: powershell -NonInteractive -NoProfile -Command "C:\\install7zip.ps1"
+        customize.command: echo true
+        launch.command: echo true
+        stop.command: echo true
+        checkRunning.command: echo true
+        installer.download.url: http://www.7-zip.org/a/7z938-x64.msi
+      brooklyn.policies:
+      - type: brooklyn.policy.os.AdvertiseWinrmLoginPolicy

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f25c6162/usage/launcher/src/test/resources/install7zip.ps1
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/resources/install7zip.ps1 b/usage/launcher/src/test/resources/install7zip.ps1
new file mode 100644
index 0000000..6308fc6
--- /dev/null
+++ b/usage/launcher/src/test/resources/install7zip.ps1
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+$Path="C:\InstallTemp"
+New-Item -ItemType Directory -Force -Path $Path
+
+$Url = "${config['installer.download.url']}"
+$Dl = [System.IO.Path]::Combine($Path, "installer.msi")
+
+$WebClient = New-Object System.Net.WebClient
+
+$WebClient.DownloadFile($Url, $Dl)
+
+$pass = '${attribute['windows.password']}'
+$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
+$mycreds = New-Object System.Management.Automation.PSCredential ($($env:COMPUTERNAME + "\Administrator"), $secpasswd)
+
+Invoke-Command -ComputerName localhost -credential $mycreds -scriptblock {
+    param($Dl)
+    Start-Process "msiexec" -ArgumentList '/qn','/i',$Dl,'/L c:\7ziplog.txt' -Wait
+} -Authentication CredSSP -argumentlist $Dl