You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/08/28 20:33:40 UTC
stratos git commit: Adding integration test to verify repo clone for
tenant users
Repository: stratos
Updated Branches:
refs/heads/stratos-4.1.x 8bd92e89a -> 90b030a6e
Adding integration test to verify repo clone for tenant users
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/90b030a6
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/90b030a6
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/90b030a6
Branch: refs/heads/stratos-4.1.x
Commit: 90b030a6eca02a995b05434b0e7ecba233574fe9
Parents: 8bd92e8
Author: Akila Perera <ra...@gmail.com>
Authored: Sat Aug 29 00:03:21 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Sat Aug 29 00:03:21 2015 +0530
----------------------------------------------------------------------
.../python-cartridge-agent/integration/pom.xml | 13 ++
.../test/ADCMTAppTenantUserTest.java | 213 +++++++++++++++++++
.../src/test/resources/pca-testing4.xml | 29 +++
.../resources/suite-3/payload/launch-params | 3 +-
.../src/test/resources/suite-4/agent.conf | 45 ++++
.../src/test/resources/suite-4/jndi.properties | 22 ++
.../src/test/resources/suite-4/logging.ini | 52 +++++
.../resources/suite-4/payload/launch-params | 1 +
8 files changed, 376 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/pom.xml
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/pom.xml b/products/python-cartridge-agent/integration/pom.xml
index 707a4ae..9b0922a 100755
--- a/products/python-cartridge-agent/integration/pom.xml
+++ b/products/python-cartridge-agent/integration/pom.xml
@@ -117,6 +117,19 @@
<workingDirectory>${basedir}/target</workingDirectory>
</configuration>
</execution>
+ <execution>
+ <id>adc-mt-tenant-user-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <inherited>false</inherited>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/pca-testing4.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ <workingDirectory>${basedir}/target</workingDirectory>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/java/org/apache/stratos/python.cartridge.agent/test/ADCMTAppTenantUserTest.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/java/org/apache/stratos/python.cartridge.agent/test/ADCMTAppTenantUserTest.java b/products/python-cartridge-agent/integration/src/test/java/org/apache/stratos/python.cartridge.agent/test/ADCMTAppTenantUserTest.java
new file mode 100644
index 0000000..a604f55
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/java/org/apache/stratos/python.cartridge.agent/test/ADCMTAppTenantUserTest.java
@@ -0,0 +1,213 @@
+package org.apache.stratos.python.cartridge.agent.test;/*
+ * 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.domain.LoadBalancingIPType;
+import org.apache.stratos.messaging.domain.topology.*;
+import org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent;
+import org.apache.stratos.messaging.event.topology.CompleteTopologyEvent;
+import org.apache.stratos.messaging.event.topology.MemberInitializedEvent;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertTrue;
+
+public class ADCMTAppTenantUserTest extends PythonAgentTestManager {
+ private static final Log log = LogFactory.getLog(ADCMTAppTenantUserTest.class);
+ private static final int ADC_TIMEOUT = 180000;
+ private static final String RESOURCES_PATH = "/suite-4";
+ private static final String APPLICATION_PATH = "/tmp/pca-test-suite-4";
+ private static final String CLUSTER_ID = "tomcat.domain";
+ private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-4";
+ private static final String AUTOSCALING_POLICY_NAME = "autoscaling-policy-4";
+ private static final String APP_ID = "application-4";
+ private static final String MEMBER_ID = "tomcat.member-1";
+ private static final String CLUSTER_INSTANCE_ID = "cluster-1-instance-1";
+ private static final String NETWORK_PARTITION_ID = "network-partition-1";
+ private static final String PARTITION_ID = "partition-1";
+ private static final String TENANT_ID = "4";
+ private static final String SERVICE_NAME = "tomcat-mt";
+
+ private boolean hasADCTestCompleted = false;
+
+ @BeforeSuite
+ public void setupADCMTAppTest() {
+ // Set jndi.properties.dir system property for initializing event publishers and receivers
+ System.setProperty("jndi.properties.dir", getResourcesPath(RESOURCES_PATH));
+
+ // start Python agent with configurations provided in resource path
+ setup(RESOURCES_PATH);
+
+ // Simulate server socket
+ startServerSocket(8080);
+ }
+
+ /**
+ * TearDown method for test method testPythonCartridgeAgent
+ */
+ @AfterSuite
+ public void tearDownADCMTAppTest() {
+ // TODO: app path is duplicated in Java test and payload
+ tearDown(APPLICATION_PATH);
+ }
+
+ @Test(timeOut = ADC_TIMEOUT)
+ public void testADCForMTApps() {
+ startCommunicatorThread();
+ assertAgentActivation();
+ Thread adcTestThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ log.info("Running ADC MT Test thread...");
+ // Send artifact updated event
+ publishEvent(getArtifactUpdatedEventForPublicRepo());
+ log.info("Publishing artifact updated event for repo: " +
+ getArtifactUpdatedEventForPublicRepo().getRepoURL());
+
+ List<String> outputLines = new ArrayList<String>();
+ while (!outputStream.isClosed() && !hasADCTestCompleted) {
+ List<String> newLines = getNewLines(outputLines, outputStream.toString());
+ if (newLines.size() > 0) {
+ for (String line : newLines) {
+ if (line.contains("Git clone executed")) {
+ log.info("Agent has completed git clone. Asserting the operation...");
+ assertRepoClone(getArtifactUpdatedEventForPublicRepo());
+ hasADCTestCompleted = true;
+ }
+ }
+ }
+ sleep(1000);
+ }
+ }
+ });
+ adcTestThread.start();
+
+ while (!hasADCTestCompleted) {
+ // wait until the instance activated event is received.
+ sleep(1000);
+ }
+ }
+
+ private void assertAgentActivation() {
+ Thread startupTestThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!eventReceiverInitiated) {
+ sleep(1000);
+ }
+ List<String> outputLines = new ArrayList<String>();
+ while (!outputStream.isClosed()) {
+ List<String> newLines = getNewLines(outputLines, outputStream.toString());
+ if (newLines.size() > 0) {
+ for (String line : newLines) {
+ if (line.contains("Subscribed to 'topology/#'")) {
+ sleep(2000);
+ // Send complete topology event
+ log.info("Publishing complete topology event...");
+ Topology topology = createTestTopology();
+ CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
+ publishEvent(completeTopologyEvent);
+ log.info("Complete topology event published");
+
+ // Publish member initialized event
+ log.info("Publishing member initialized event...");
+ MemberInitializedEvent memberInitializedEvent = new MemberInitializedEvent(
+ SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID,
+ PARTITION_ID
+ );
+ publishEvent(memberInitializedEvent);
+ log.info("Member initialized event published");
+ }
+
+ // Send artifact updated event to activate the instance first
+ if (line.contains("Artifact repository found")) {
+ publishEvent(getArtifactUpdatedEventForPublicRepo());
+ log.info("Artifact updated event published");
+ }
+ log.info(line);
+ }
+ }
+ sleep(1000);
+ }
+ }
+ });
+ startupTestThread.start();
+
+ while (!instanceStarted || !instanceActivated) {
+ // wait until the instance activated event is received.
+ // this will assert whether instance got activated within timeout period; no need for explicit assertions
+ sleep(2000);
+ }
+ }
+
+ private ArtifactUpdatedEvent getArtifactUpdatedEventForPublicRepo() {
+ ArtifactUpdatedEvent publicRepoEvent = createTestArtifactUpdatedEvent();
+ publicRepoEvent.setRepoURL("https://bitbucket.org/testapache2211/opentestrepo1.git");
+ return publicRepoEvent;
+ }
+
+ private void assertRepoClone(ArtifactUpdatedEvent artifactUpdatedEvent) {
+ File file = new File(APPLICATION_PATH + "/repository/tenants/4/test1.txt");
+ assertTrue("Git clone failed for repo [url] " + artifactUpdatedEvent.getRepoURL(),
+ file.exists());
+ }
+
+ private static ArtifactUpdatedEvent createTestArtifactUpdatedEvent() {
+ ArtifactUpdatedEvent artifactUpdatedEvent = new ArtifactUpdatedEvent();
+ artifactUpdatedEvent.setClusterId(CLUSTER_ID);
+ artifactUpdatedEvent.setTenantId(TENANT_ID);
+ return artifactUpdatedEvent;
+ }
+
+ /**
+ * Create test topology
+ *
+ * @return
+ */
+ private Topology createTestTopology() {
+ Topology topology = new Topology();
+ Service service = new Service(SERVICE_NAME, ServiceType.SingleTenant);
+ topology.addService(service);
+
+ Cluster cluster = new Cluster(service.getServiceName(), CLUSTER_ID, DEPLOYMENT_POLICY_NAME,
+ AUTOSCALING_POLICY_NAME, APP_ID);
+ service.addCluster(cluster);
+
+ Member member = new Member(service.getServiceName(), cluster.getClusterId(), MEMBER_ID,
+ CLUSTER_INSTANCE_ID, NETWORK_PARTITION_ID, PARTITION_ID, LoadBalancingIPType.Private,
+ System.currentTimeMillis());
+
+ member.setDefaultPrivateIP("10.0.0.1");
+ member.setDefaultPublicIP("20.0.0.1");
+ Properties properties = new Properties();
+ properties.setProperty("prop1", "value1");
+ member.setProperties(properties);
+ member.setStatus(MemberStatus.Created);
+ cluster.addMember(member);
+
+ return topology;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/pca-testing4.xml
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/pca-testing4.xml b/products/python-cartridge-agent/integration/src/test/resources/pca-testing4.xml
new file mode 100755
index 0000000..6462774
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/resources/pca-testing4.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="PythonCartridgeAgentIntegrationSuite4">
+ <test name="PCATest">
+ <classes>
+ <class name="org.apache.stratos.python.cartridge.agent.test.ADCMTAppTenantUserTest"/>
+ </classes>
+ </test>
+</suite>
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/suite-3/payload/launch-params
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/suite-3/payload/launch-params b/products/python-cartridge-agent/integration/src/test/resources/suite-3/payload/launch-params
index ba9387b..ed8c67f 100755
--- a/products/python-cartridge-agent/integration/src/test/resources/suite-3/payload/launch-params
+++ b/products/python-cartridge-agent/integration/src/test/resources/suite-3/payload/launch-params
@@ -1,2 +1 @@
-APPLICATION_ID=application-3,SERVICE_NAME=tomcat-mt,HOST_NAME=tomcat.stratos.org,MULTITENANT=true,TENANT_ID=-1234,
-TENANT_RANGE=*,CARTRIDGE_ALIAS=tomcat,CLUSTER_ID=tomcat.domain,CLUSTER_INSTANCE_ID=cluster-1-instance-1,CARTRIDGE_KEY=PUjpXCLujDhYr5A6,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=8080,PUPPET_IP=127.0.0.1,PUPPET_HOSTNAME=puppet.apache.stratos.org,PUPPET_ENV=false,MEMBER_ID=tomcat.member-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-p1,PARTITION_ID=p1,APPLICATION_PATH=/tmp/pca-test-suite-3,MIN_COUNT=1,INTERNAL=false,CLUSTERING_PRIMARY_KEY=A,LOG_FILE_PATHS=/tmp/temp.log,PERSISTENCE_MAPPING=null
+APPLICATION_ID=application-3,SERVICE_NAME=tomcat-mt,HOST_NAME=tomcat.stratos.org,MULTITENANT=true,TENANT_ID=-1234,TENANT_RANGE=*,CARTRIDGE_ALIAS=tomcat,CLUSTER_ID=tomcat.domain,CLUSTER_INSTANCE_ID=cluster-1-instance-1,CARTRIDGE_KEY=PUjpXCLujDhYr5A6,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=8080,PUPPET_IP=127.0.0.1,PUPPET_HOSTNAME=puppet.apache.stratos.org,PUPPET_ENV=false,MEMBER_ID=tomcat.member-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-p1,PARTITION_ID=p1,APPLICATION_PATH=/tmp/pca-test-suite-3,MIN_COUNT=1,INTERNAL=false,CLUSTERING_PRIMARY_KEY=A,LOG_FILE_PATHS=/tmp/temp.log,PERSISTENCE_MAPPING=null
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/suite-4/agent.conf
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/suite-4/agent.conf b/products/python-cartridge-agent/integration/src/test/resources/suite-4/agent.conf
new file mode 100755
index 0000000..f945968
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/resources/suite-4/agent.conf
@@ -0,0 +1,45 @@
+# 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.
+
+[agent]
+mb.ip =localhost
+mb.port =1885
+listen.address =localhost
+thrift.receiver.ip =localhost
+thrift.receiver.port =7712
+thrift.server.admin.username =admin
+thrift.server.admin.password =admin
+cep.stats.publisher.enabled =true
+lb.private.ip =
+lb.public.ip =
+enable.artifact.update =true
+auto.commit =true
+auto.checkout =true
+artifact.update.interval =15
+artifact.clone.retries =5
+artifact.clone.interval =10
+port.check.timeout =600000
+enable.data.publisher =false
+monitoring.server.ip =localhost
+monitoring.server.port =7612
+monitoring.server.secure.port =7712
+monitoring.server.admin.username =admin
+monitoring.server.admin.password =admin
+log.file.paths =/tmp/agent.screen-adc-mt-tenant-user-test.log
+metadata.service.url =https://localhost:9443
+super.tenant.repository.path =/repository/deployment/server/
+tenant.repository.path =/repository/tenants/
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/suite-4/jndi.properties
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/suite-4/jndi.properties b/products/python-cartridge-agent/integration/src/test/resources/suite-4/jndi.properties
new file mode 100755
index 0000000..beefe3c
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/resources/suite-4/jndi.properties
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+connectionfactoryName=TopicConnectionFactory
+java.naming.provider.url=tcp://localhost:61617
+java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/suite-4/logging.ini
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/suite-4/logging.ini b/products/python-cartridge-agent/integration/src/test/resources/suite-4/logging.ini
new file mode 100755
index 0000000..15cad9b
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/resources/suite-4/logging.ini
@@ -0,0 +1,52 @@
+# 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.
+
+
+[formatters]
+keys=default
+
+[formatter_default]
+format=[%(asctime)s] %(levelname)s {%(filename)s:%(funcName)s} - %(message)s
+class=logging.Formatter
+
+[handlers]
+keys=console, error_file, log_file
+
+[handler_console]
+class=logging.StreamHandler
+formatter=default
+args=tuple()
+
+[handler_log_file]
+class=logging.FileHandler
+level=DEBUG
+formatter=default
+args=("agent.log", "w")
+
+[handler_error_file]
+class=logging.FileHandler
+level=ERROR
+formatter=default
+args=("error.log", "w")
+
+[loggers]
+keys=root
+
+[logger_root]
+level=DEBUG
+formatter=default
+handlers=console,error_file,log_file
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/90b030a6/products/python-cartridge-agent/integration/src/test/resources/suite-4/payload/launch-params
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/integration/src/test/resources/suite-4/payload/launch-params b/products/python-cartridge-agent/integration/src/test/resources/suite-4/payload/launch-params
new file mode 100755
index 0000000..b701066
--- /dev/null
+++ b/products/python-cartridge-agent/integration/src/test/resources/suite-4/payload/launch-params
@@ -0,0 +1 @@
+APPLICATION_ID=application-4,SERVICE_NAME=tomcat-mt,HOST_NAME=tomcat.stratos.org,MULTITENANT=true,TENANT_ID=4,TENANT_RANGE=*,CARTRIDGE_ALIAS=tomcat,CLUSTER_ID=tomcat.domain,CLUSTER_INSTANCE_ID=cluster-1-instance-1,CARTRIDGE_KEY=PUjpXCLujDhYr5A6,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=8080,PUPPET_IP=127.0.0.1,PUPPET_HOSTNAME=puppet.apache.stratos.org,PUPPET_ENV=false,MEMBER_ID=tomcat.member-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-p1,PARTITION_ID=p1,APPLICATION_PATH=/tmp/pca-test-suite-4,MIN_COUNT=1,INTERNAL=false,CLUSTERING_PRIMARY_KEY=A,LOG_FILE_PATHS=/tmp/temp.log,PERSISTENCE_MAPPING=null