Skip to content

Commit

Permalink
Merge pull request #1322 from TangLeDaily/install_action_1
Browse files Browse the repository at this point in the history
AgentCore动态安装卸载测试:测试插件、测试应用、流水线
  • Loading branch information
Sherlockhan authored Oct 8, 2023
2 parents 63e8c97 + 30b0e19 commit 3ebe342
Show file tree
Hide file tree
Showing 23 changed files with 965 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: "Agent-core Common Test"
description: "Auto test for spring common, include nacos dynamic config"
description: "Auto test for agent-core common, include nacos dynamic config"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test
log-dir: ./logs/agentcore-test/dynamic-config
- name: start applications
shell: bash
env:
Expand All @@ -23,7 +23,7 @@ runs:
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
- name: agentcore test module start
shell: bash
run: mvn test --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
run: mvn test -Dagentcore.test.type=DYNAMIC_CONFIG --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
Expand Down
92 changes: 92 additions & 0 deletions .github/actions/scenarios/agentcore/dynamic/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: "Agent-core Dynamic Install/Uninstall Test"
description: "Auto test for agent-core dynamic install/uninstall"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test/dynamic
- name: compile AgentLoader
shell: bash
run: |
cp sermant-integration-tests/scripts/AgentLoader.java ./
javac -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader.java
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:2181
dynamic.config.dynamicConfigType: ZOOKEEPER
service.meta.project: TestAgentCore
run: |
nohup java -jar \
sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir
}}/agentcore-test.log 2>&1 &
- name: waiting for agentcore services start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
- name: (install agent) modify plugins file
shell: bash
run: |
sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/ passive:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/ passive:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
- name: (install agent) dynamic install agent
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: (install plugin) dynamic install plugin
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar command=INSTALL-PLUGINS:dynamic-test-first-plugin/dynamic-test-second-plugin
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: (install plugin) test install plugin
shell: bash
run: mvn test -Dagentcore.test.type=INSTALL_PLUGIN --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: (uninstall plugin) dynamic uninstall plugin
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar command=UNINSTALL-PLUGINS:dynamic-test-first-plugin
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: (uninstall plugin) test uninstall plugin
shell: bash
run: mvn test -Dagentcore.test.type=UNINSTALL_PLUGIN --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: (uninstall agent) dynamic uninstall agent
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar command=UNINSTALL-AGENT
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: (uninstall agent) test uninstall agent
shell: bash
run: mvn test -Dagentcore.test.type=UNINSTALL_AGENT --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: (reinstall agent) dynamic reinstall agent
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar command=INSTALL-PLUGINS:dynamic-test-first-plugin/dynamic-test-second-plugin
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: (reinstall agent) test reinstall agent
shell: bash
run: mvn test -Dagentcore.test.type=REINSTALL_AGENT --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: agentcore
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
27 changes: 23 additions & 4 deletions .github/workflows/agentcore_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ jobs:
- name: move test plugin
run: |
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin
cp ./sermant-integration-tests/agentcore-test/agentcore-test-plugin/target/agentcore-test-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/dynamic-test-first-plugin/target/dynamic-test-first-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/dynamic-test-second-plugin/target/dynamic-test-second-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/agentcore-test-application/target/agentcore-test-application-1.0.0-jar-with-dependencies.jar sermant-agent-${{ env.sermantVersion }}/agent/
sed -i '/plugins:/a \ - agentcore-test-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
test-for-agentcore:
name: Test for agentcore
test-for-agentcore-common:
name: Test for agentcore common
runs-on: ubuntu-latest
needs: [ build-agent-and-cache, download-midwares-and-cache ]
steps:
Expand All @@ -93,7 +97,22 @@ jobs:
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/agentcore
- name: start agentcore test
uses: ./.github/actions/scenarios/agentcore
- name: start agentcore common test
uses: ./.github/actions/scenarios/agentcore/agentcore-common
test-for-agentcore-dynamic:
name: Test for agentcore dynamic
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/agentcore
- name: start dynamic test
uses: ./.github/actions/scenarios/agentcore/dynamic


Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.surefire.plugin.version>3.0.0</maven.surefire.plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -55,15 +56,14 @@
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed 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 com.huaweicloud.agentcore.test.request;

import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.Test;

import java.io.IOException;

/**
* 请求测试类,采用http请求调用方式测试
*
* @author tangle
* @since 2023-09-07
*/
public class RequestTest {
/**
* 动态配置测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "DYNAMIC_CONFIG")
public void testDynamicConfig() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testDynamicConfig");
}

/**
* 动态卸载插件测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "UNINSTALL_PLUGIN")
public void testUninstallPlugin() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testUninstallPlugin");
}

/**
* 动态卸载Agent测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "UNINSTALL_AGENT")
public void testUninstallAgent() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testUninstallAgent");
}

/**
* 动态重装Agent测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "REINSTALL_AGENT")
public void testReInstallPlugin() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testReInstallAgent");
}

/**
* 动态安装插件测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "INSTALL_PLUGIN")
public void testInstallPlugin() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testInstallPlugin");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,38 @@

import com.alibaba.fastjson.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* agentcore测试方法,采用http请求调用方式测试
* http请求工具类
*
* @author tangle
* @since 2023-09-07
* @since 2023-09-26
*/
public class AgentcoreTest {
private static final Logger LOGGER = LoggerFactory.getLogger(AgentcoreTest.class);
public class RequestUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtils.class);

@Test
public void testAgentcore() throws IOException {
testRequest("http://127.0.0.1:8915/testDynamicConfig");
private RequestUtils() {
}

/**
* 对测试请求结果进行断言判断
*
* @param url 测试请求接口的url
*/
public void testRequest(String url) throws IOException {
public static void testRequest(String url) throws IOException {
String response = doGet(url);
Assertions.assertNotEquals("", response, url + " Request Error. ");
Map<String, Boolean> resultMap = convertHttpEntityToMap(response);
Expand All @@ -67,7 +64,7 @@ public void testRequest(String url) throws IOException {
* @param url http请求url
* @return 响应体body
*/
private String doGet(String url) {
private static String doGet(String url) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
RequestConfig requestConfig = RequestConfig.custom()
.build();
Expand All @@ -93,7 +90,7 @@ private String doGet(String url) {
* @param response JSON数据
* @return map数据
*/
private Map<String, Boolean> convertHttpEntityToMap(String response) throws IOException {
private static Map<String, Boolean> convertHttpEntityToMap(String response) throws IOException {
Map<String, Boolean> result = new HashMap<>();
JSONObject jsonObject = JSONObject.parseObject(response);
for (String key : jsonObject.keySet()) {
Expand Down
Loading

0 comments on commit 3ebe342

Please sign in to comment.