You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ga...@apache.org on 2015/12/08 16:18:01 UTC

[18/50] [abbrv] stratos git commit: PCA Live Test - Refactoring PCA - Fixed missing app path validation in event handler

PCA Live Test - Refactoring
PCA - Fixed missing app path validation in event handler


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/81b72de8
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/81b72de8
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/81b72de8

Branch: refs/heads/master
Commit: 81b72de838432e35bb8af413fd2be50893e61115
Parents: e40f254
Author: Chamila de Alwis <ch...@apache.org>
Authored: Mon Nov 30 19:13:49 2015 +0530
Committer: Chamila de Alwis <ch...@apache.org>
Committed: Mon Nov 30 19:13:56 2015 +0530

----------------------------------------------------------------------
 .../cartridge.agent/healthstats.py              | 16 ++---
 .../modules/event/eventhandler.py               |  9 ++-
 .../integration/tests/ADCExtensionTestCase.java | 27 ---------
 .../tests/ADCMTAppTenantUserTestCase.java       | 42 ++++----------
 .../integration/tests/ADCMTAppTestCase.java     | 41 ++++---------
 .../agent/integration/tests/ADCTestCase.java    | 39 ++++---------
 .../tests/ADCValidationTestCase.java            | 44 +++++---------
 .../integration/tests/AgentStartupTestCase.java | 39 ++++---------
 .../integration/tests/CEPHAModeTestCase.java    | 58 ++++---------------
 .../tests/MessageBrokerHATestCase.java          | 38 ++++--------
 .../tests/PythonAgentIntegrationTest.java       | 61 +++++++++++++++++++-
 11 files changed, 159 insertions(+), 255 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/healthstats.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/healthstats.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/healthstats.py
index 92d2495..71f2894 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/healthstats.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/healthstats.py
@@ -62,7 +62,7 @@ class HealthStatisticsPublisherManager(Thread):
 
                 self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg)
                 self.publisher.publish_load_average(cartridge_stats.load_avg)
-            except ThriftReceiverOfflineException:
+            except Exception as e:
                 self.log.exception(
                     "Couldn't publish health statistics to CEP. Thrift Receiver offline. Reconnecting...")
                 self.publisher = HealthStatisticsPublisher()
@@ -186,6 +186,7 @@ class HealthStatisticsPublisher:
     def add_publishers(self, cep_url):
         """
         Add publishers to the publisher list for publishing
+        :param cep_url:
         """
         cep_ip = cep_url.split(':')[0]
         cep_port = cep_url.split(':')[1]
@@ -199,27 +200,28 @@ class HealthStatisticsPublisher:
 
         self.publishers.append(publisher)
 
-
-    def is_cep_active(self, cep_url):
+    @staticmethod
+    def is_cep_active(cep_url):
         """
         Check if the cep node is active
         return true if active
+        :param cep_url:
         """
-        self.ports = []
+        ports = []
         cep_ip = cep_url.split(':')[0]
         cep_port = cep_url.split(':')[1]
-        self.ports.append(cep_port)
+        ports.append(cep_port)
 
         cep_active = cartridgeagentutils.check_ports_active(
             cep_ip,
-            self.ports)
+            ports)
 
         return cep_active
 
-
     def publish_event(self, event):
         """
         Publish events to cep nodes
+        :param event:
         """
         for publisher in self.publishers:
             try:

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py
index f8b0c2b..cea3c01 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py
@@ -89,6 +89,13 @@ def on_artifact_updated_event(artifacts_updated_event):
         log.error("Repository path is empty. Failed to process artifact updated event.")
         return
 
+    if not validate_repo_path(Config.app_path):
+        log.error(
+            "Repository path cannot be accessed, or is invalid. Failed to process artifact updated event. [App Path] %s"
+            % Config.app_path)
+
+        return
+
     repo_username = artifacts_updated_event.repo_username
     tenant_id = artifacts_updated_event.tenant_id
     is_multitenant = Config.is_multiTenant
@@ -666,7 +673,7 @@ def find_tenant_domain(tenant_id):
 
 def validate_repo_path(app_path):
     # app path would be ex: /var/www, or /opt/server/data
-    return os.access(app_path, os.W_OK)
+    return os.path.isabs(app_path)
 
 
 class PluginExecutor(Thread):

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCExtensionTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCExtensionTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCExtensionTestCase.java
index ab4975a..2fddf6e 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCExtensionTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCExtensionTestCase.java
@@ -132,31 +132,4 @@ public class ADCExtensionTestCase extends PythonAgentIntegrationTest {
         artifactUpdatedEvent.setTenantId(TENANT_ID);
         return artifactUpdatedEvent;
     }
-
-    /**
-     * Create test topology
-     *
-     * @return Topology object with mock information
-     */
-    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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
index 05d5ba2..b653632 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
@@ -137,7 +137,18 @@ public class ADCMTAppTenantUserTestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
+                                Topology topology = PythonAgentIntegrationTest.createTestTopology(
+                                        SERVICE_NAME,
+                                        CLUSTER_ID,
+                                        DEPLOYMENT_POLICY_NAME,
+                                        AUTOSCALING_POLICY_NAME,
+                                        APP_ID,
+                                        MEMBER_ID,
+                                        CLUSTER_INSTANCE_ID,
+                                        NETWORK_PARTITION_ID,
+                                        PARTITION_ID,
+                                        ServiceType.SingleTenant);
+
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -190,33 +201,4 @@ public class ADCMTAppTenantUserTestCase extends PythonAgentIntegrationTest {
         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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
index 444a5e0..02144e0 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
@@ -139,7 +139,18 @@ public class ADCMTAppTestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
+                                Topology topology = PythonAgentIntegrationTest.createTestTopology(
+                                        SERVICE_NAME,
+                                        CLUSTER_ID,
+                                        DEPLOYMENT_POLICY_NAME,
+                                        AUTOSCALING_POLICY_NAME,
+                                        APP_ID,
+                                        MEMBER_ID,
+                                        CLUSTER_INSTANCE_ID,
+                                        NETWORK_PARTITION_ID,
+                                        PARTITION_ID,
+                                        ServiceType.SingleTenant);
+
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -193,32 +204,4 @@ public class ADCMTAppTestCase extends PythonAgentIntegrationTest {
         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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
index dba6197..6a42cce 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
@@ -196,7 +196,17 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
+                                Topology topology = PythonAgentIntegrationTest.createTestTopology(
+                                        SERVICE_NAME,
+                                        CLUSTER_ID,
+                                        DEPLOYMENT_POLICY_NAME,
+                                        AUTOSCALING_POLICY_NAME,
+                                        APP_ID,
+                                        MEMBER_ID,
+                                        CLUSTER_INSTANCE_ID,
+                                        NETWORK_PARTITION_ID,
+                                        PARTITION_ID,
+                                        ServiceType.SingleTenant);
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -255,31 +265,4 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
         artifactUpdatedEvent.setTenantId(TENANT_ID);
         return artifactUpdatedEvent;
     }
-
-    /**
-     * Create test topology
-     *
-     * @return Topology object with mock information
-     */
-    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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCValidationTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCValidationTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCValidationTestCase.java
index 45834e5..50ed350 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCValidationTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCValidationTestCase.java
@@ -21,7 +21,6 @@ package org.apache.stratos.python.cartridge.agent.integration.tests;
 
 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;
@@ -33,7 +32,6 @@ import org.testng.annotations.Test;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
 
 /**
  * Test validation for application path input on the PCA
@@ -92,7 +90,7 @@ public class ADCValidationTestCase extends PythonAgentIntegrationTest {
                     sleep(1000);
                 }
                 List<String> outputLines = new ArrayList<>();
-                while (!outputStream.isClosed()) {
+                while (!outputStream.isClosed() && !logDetected) {
                     List<String> newLines = getNewLines(outputLines, outputStream.toString());
                     if (newLines.size() > 0) {
                         for (String line : newLines) {
@@ -100,7 +98,18 @@ public class ADCValidationTestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
+                                Topology topology = PythonAgentIntegrationTest.createTestTopology(
+                                        SERVICE_NAME,
+                                        CLUSTER_ID,
+                                        DEPLOYMENT_POLICY_NAME,
+                                        AUTOSCALING_POLICY_NAME,
+                                        APP_ID,
+                                        MEMBER_ID,
+                                        CLUSTER_INSTANCE_ID,
+                                        NETWORK_PARTITION_ID,
+                                        PARTITION_ID,
+                                        ServiceType.SingleTenant);
+
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -151,31 +160,4 @@ public class ADCValidationTestCase extends PythonAgentIntegrationTest {
         artifactUpdatedEvent.setTenantId(TENANT_ID);
         return artifactUpdatedEvent;
     }
-
-    /**
-     * Create test topology
-     *
-     * @return Topology object with mock information
-     */
-    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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
index db21359..4f529d7 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
@@ -61,7 +61,17 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
     private boolean topologyContextTestCompleted = false;
     private boolean completeTenantInitialized = false;
     private boolean thriftTestCompleted = false;
-    private Topology topology = createTestTopology();
+    private Topology topology = PythonAgentIntegrationTest.createTestTopology(
+            SERVICE_NAME,
+            CLUSTER_ID,
+            DEPLOYMENT_POLICY_NAME,
+            AUTOSCALING_POLICY_NAME,
+            APP_ID,
+            MEMBER_ID,
+            CLUSTER_INSTANCE_ID,
+            NETWORK_PARTITION_ID,
+            PARTITION_ID,
+            ServiceType.SingleTenant);
 
     public AgentStartupTestCase() throws IOException {
     }
@@ -217,31 +227,4 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
         tenantList.add(new Tenant(3, "test.three.domain"));
         return tenantList;
     }
-
-    /**
-     * Create test topology
-     *
-     * @return Topology object with mock information
-     */
-    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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/CEPHAModeTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/CEPHAModeTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/CEPHAModeTestCase.java
index ce13d3f..58b6deb 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/CEPHAModeTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/CEPHAModeTestCase.java
@@ -21,12 +21,9 @@ package org.apache.stratos.python.cartridge.agent.integration.tests;
 import org.apache.commons.io.IOUtils;
 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.Event;
 import org.apache.stratos.messaging.event.topology.CompleteTopologyEvent;
 import org.apache.stratos.messaging.event.topology.MemberInitializedEvent;
-import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener;
 import org.apache.stratos.python.cartridge.agent.integration.common.ThriftTestServer;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -41,7 +38,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
 
 public class CEPHAModeTestCase extends PythonAgentIntegrationTest {
 
@@ -59,7 +55,18 @@ public class CEPHAModeTestCase extends PythonAgentIntegrationTest {
     private static final String TENANT_ID = "-1234";
     private static final String SERVICE_NAME = "tomcat";
     private boolean startupTestCompleted = false;
-    private Topology topology = createTestTopology();
+    private Topology topology = PythonAgentIntegrationTest.createTestTopology(
+            SERVICE_NAME,
+            CLUSTER_ID,
+            DEPLOYMENT_POLICY_NAME,
+            AUTOSCALING_POLICY_NAME,
+            APP_ID,
+            MEMBER_ID,
+            CLUSTER_INSTANCE_ID,
+            NETWORK_PARTITION_ID,
+            PARTITION_ID,
+            ServiceType.SingleTenant);
+
     private static final int ADC_TIMEOUT = 300000;
     private ThriftTestServer secondThriftTestServer;
     private boolean thriftTestCompletedinServerTwo = false;
@@ -180,19 +187,6 @@ public class CEPHAModeTestCase extends PythonAgentIntegrationTest {
 
         startupTestThread.start();
 
-        instanceStatusEventReceiver.addEventListener(new InstanceActivatedEventListener() {
-            @Override
-            protected void onEvent(Event event) {
-                log.info("Publishing complete topology with a new member...");
-                Member newMember = new Member(SERVICE_NAME, CLUSTER_ID, "new-member", CLUSTER_INSTANCE_ID,
-                        NETWORK_PARTITION_ID, PARTITION_ID, LoadBalancingIPType.Private, System.currentTimeMillis());
-                topology.getService(SERVICE_NAME).getCluster(CLUSTER_ID).addMember(newMember);
-                CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
-                publishEvent(completeTopologyEvent);
-                log.info("Complete topology event published with new member");
-            }
-        });
-
         while (!instanceStarted || !instanceActivated || !startupTestCompleted ||
                 !thriftTestCompletedinServerOne || !thriftTestCompletedinServerTwo) {
             // wait until the instance activated event is received.
@@ -274,32 +268,4 @@ public class CEPHAModeTestCase extends PythonAgentIntegrationTest {
             }
         });
     }
-
-    /**
-     * Create test topology
-     *
-     * @return Topology object with mock information
-     */
-    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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/MessageBrokerHATestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/MessageBrokerHATestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/MessageBrokerHATestCase.java
index 8c72f2d..1fdd8cd 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/MessageBrokerHATestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/MessageBrokerHATestCase.java
@@ -212,7 +212,18 @@ public class MessageBrokerHATestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
+                                Topology topology = PythonAgentIntegrationTest.createTestTopology(
+                                        SERVICE_NAME,
+                                        CLUSTER_ID,
+                                        DEPLOYMENT_POLICY_NAME,
+                                        AUTOSCALING_POLICY_NAME,
+                                        APP_ID,
+                                        MEMBER_ID,
+                                        CLUSTER_INSTANCE_ID,
+                                        NETWORK_PARTITION_ID,
+                                        PARTITION_ID,
+                                        ServiceType.SingleTenant);
+
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -245,30 +256,5 @@ public class MessageBrokerHATestCase extends PythonAgentIntegrationTest {
         log.info("PCA activation assertion passed.");
     }
 
-    /**
-     * 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;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81b72de8/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
index 7f436f6..649430f 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
@@ -28,9 +28,11 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.domain.LoadBalancingIPType;
 import org.apache.stratos.common.threading.StratosThreadPool;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
 import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
+import org.apache.stratos.messaging.domain.topology.*;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener;
 import org.apache.stratos.messaging.listener.instance.status.InstanceStartedEventListener;
@@ -549,8 +551,8 @@ public abstract class PythonAgentIntegrationTest {
         if (StringUtils.isNotBlank(output)) {
             List<String> lines = Arrays.asList(output.split(NEW_LINE));
             if (lines.size() > 0) {
-                int readStartIndex = (currentOutputLines.size() > 0) ? currentOutputLines.size() - 1 : 0;
-                for (String line : lines.subList(readStartIndex , lines.size() - 1)) {
+                int readStartIndex = (currentOutputLines.size() > 0) ? (currentOutputLines.size() - 1) : 0;
+                for (String line : lines.subList(readStartIndex , lines.size())) {
                     currentOutputLines.add(line);
                     newLines.add(line);
                 }
@@ -586,4 +588,59 @@ public abstract class PythonAgentIntegrationTest {
             return closed;
         }
     }
+
+    /**
+     * Create a test topology object
+     *
+     * @param serviceName
+     * @param clusterId
+     * @param depPolicyName
+     * @param autoscalingPolicyName
+     * @param appId
+     * @param memberId
+     * @param clusterInstanceId
+     * @param networkPartitionId
+     * @param partitionId
+     * @param serviceType
+     * @return
+     */
+    protected static Topology createTestTopology(
+            String serviceName,
+            String clusterId,
+            String depPolicyName,
+            String autoscalingPolicyName,
+            String appId,
+            String memberId,
+            String clusterInstanceId,
+            String networkPartitionId,
+            String partitionId,
+            ServiceType serviceType) {
+
+
+        Topology topology = new Topology();
+        Service service = new Service(serviceName, serviceType);
+        topology.addService(service);
+
+        Cluster cluster = new Cluster(service.getServiceName(), clusterId, depPolicyName, autoscalingPolicyName, appId);
+        service.addCluster(cluster);
+
+        Member member = new Member(
+                service.getServiceName(),
+                cluster.getClusterId(),
+                memberId,
+                clusterInstanceId,
+                networkPartitionId,
+                partitionId,
+                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;
+    }
 }