aboutsummaryrefslogtreecommitdiffstats
path: root/sshapi-call-node
diff options
context:
space:
mode:
authorGanesh Chandrasekaran <ganesh.c@samsung.com>2018-08-02 15:06:36 +0900
committerGanesh Chandrasekaran <ganesh.c@samsung.com>2018-08-02 18:36:42 +0900
commit1476ff884265181b5934d71a7a0e59b705ee1aac (patch)
treef983cda14754b3007a37b0b079dcde7e2d3e2f17 /sshapi-call-node
parentbace9b5f98bfef3168134a747c8795196ce9a723 (diff)
dependancy and tests cases added
Issue-ID: CCSDK-407 Change-Id: I0450875b0a29cc4612e0979e3d6e97b6c4b398f0 Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'sshapi-call-node')
-rw-r--r--sshapi-call-node/features/src/main/resources/features.xml14
-rw-r--r--sshapi-call-node/provider/ReadMe.md32
-rwxr-xr-xsshapi-call-node/provider/pom.xml31
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/SshApiCallNode.java69
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/AuthType.java2
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Format.java2
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/JsonParser.java2
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Parameters.java2
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/ParseParam.java9
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlJsonUtil.java2
-rw-r--r--sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlParser.java2
-rw-r--r--sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestJsonParser.java2
-rw-r--r--sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestSshApiCallNode.java228
-rw-r--r--sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlJsonUtil.java2
-rw-r--r--sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlParser.java2
15 files changed, 322 insertions, 79 deletions
diff --git a/sshapi-call-node/features/src/main/resources/features.xml b/sshapi-call-node/features/src/main/resources/features.xml
index 573f5cb0..fd7caf53 100644
--- a/sshapi-call-node/features/src/main/resources/features.xml
+++ b/sshapi-call-node/features/src/main/resources/features.xml
@@ -35,17 +35,11 @@
<feature>sdnc-sli</feature>
<feature>spring</feature>
<feature>spring-dm</feature>
- <bundle>mvn:com.sun.jersey/jersey-client/${jersey.version}</bundle>
- <bundle>
- mvn:com.sun.jersey.contribs.jersey-oauth/oauth-signature/${jersey.version}
- </bundle>
- <bundle>
- mvn:com.sun.jersey.contribs.jersey-oauth/oauth-client/${jersey.version}
- </bundle>
<bundle>mvn:org.codehaus.jettison/jettison/${jettison.version}</bundle>
- <bundle>
- mvn:org.onap.ccsdk.sli.plugins/sshapi-call-node-provider/${project.version}
- </bundle>
+ <bundle>mvn:org.onap.ccsdk.sli.core/sli-common/${project.version}</bundle>
+ <bundle>mvn:org.onap.ccsdk.sli.core/sli-provider/${project.version}</bundle>
+ <bundle dependency="true">mvn:org.onap.appc/appc-ssh-adapter-api/1.3.0</bundle>
+ <bundle>mvn:org.onap.ccsdk.sli.plugins/sshapi-call-node-provider/${project.version}</bundle>
</feature>
</features>
diff --git a/sshapi-call-node/provider/ReadMe.md b/sshapi-call-node/provider/ReadMe.md
new file mode 100644
index 00000000..6c31ae0c
--- /dev/null
+++ b/sshapi-call-node/provider/ReadMe.md
@@ -0,0 +1,32 @@
+SSHApi-Call-Node Plugin:
+
+Parameters List that managed in from Directed Graphs:
+
+Input:
+Url -> Mandatory -> url to make the SSH connection request to.
+Port -> Mandatory -> port to make the SSH connection request to.
+AuthType -> Optional -> Type of authentiation to be used BASIC or sshKey based -> true or false
+User -> Optional -> user name to use for ssh basic authentication -> sdnc_ws
+Password -> Optional -> unencrypted password to use for ssh basic authentication -> plain_password
+SshKey -> Optional -> Consumer SSH key to use for ssh authentication -> plain_key
+ExecTimeout -> Optional -> SSH command execution timeout -> plain_key
+Retry -> Optional -> Make ssh connection with default retry policy -> plain_key
+Cmd -> Mandatory -> ssh command to be executed on the server. -> get post put delete patch
+EnvParameters -> Optional -> A JSON dictionary which should list key value pairs to be passed to the command execution. These values would correspond to instance specific parameters that a command may need to execute an action.
+FileParameters -> Optional -> A JSON dictionary where keys are filenames and values are contents of files. The SSH Server will utilize this feature to generate files with keys as filenames and values as content. This attribute can be used to generate files that a command may require as part of execution.
+ConvertResponse -> Optional -> whether the response should be converted to properties -> true or false
+ResponseType -> Optional -> If we know the response is to be in a specific format (supported are JSON, XML and NONE)
+ResponsePrefix -> Optional -> location the response will be written to in context memory
+listName[i] -> Optional -> Used for processing XML responses with repeating elements.</td>vpn-information.vrf-details
+
+Output:
+"'ResponsePrefix'.sshApi.call.node.status" -> SSH Exit status code is set in here.
+"'ResponsePrefix'.sshApi.call.node.stdout" -> SSH command execution result is put in here.
+"'ResponsePrefix'.sshApi.call.node.stderr" -> SSH execution failure message is put in here.
+
+
+
+API methods that are exposed:
+1) execCommand
+2) execWithStatusCheck: Throws exception if the exit status is not successful.
+3) execCommandWithPty \ No newline at end of file
diff --git a/sshapi-call-node/provider/pom.xml b/sshapi-call-node/provider/pom.xml
index e380d7c2..5434e60f 100755
--- a/sshapi-call-node/provider/pom.xml
+++ b/sshapi-call-node/provider/pom.xml
@@ -27,11 +27,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>sli-common</artifactId>
</dependency>
@@ -50,32 +45,6 @@
<artifactId>json</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
- <artifactId>oauth-signature</artifactId>
- <version>${jersey.version}</version>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
- <artifactId>oauth-client</artifactId>
- <version>${jersey.version}</version>
- </dependency>
- <dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</dependency>
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/SshApiCallNode.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/SshApiCallNode.java
index e4b082cd..10635be7 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/SshApiCallNode.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/SshApiCallNode.java
@@ -3,9 +3,10 @@
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Copyright (C) 2017 Amdocs
* =============================================================================
+ * Copyright (C) 2018 Samsung Electronics. 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
@@ -52,22 +53,22 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
/**
* Output parameter - SSH command execution status.
*/
- String PARAM_OUT_status = "status";
+ private String PARAM_OUT_status = "sshApi.call.node.status";
/**
* Output parameter - content of SSH command stdout.
*/
- String PARAM_OUT_stdout = "stdout";
+ private String PARAM_OUT_stdout = "sshApi.call.node.stdout";
/**
* Output parameter - content of SSH command stderr.
*/
- String PARAM_OUT_stderr = "stderr";
+ private String PARAM_OUT_stderr = "sshApi.call.node.stderr";
/**
* Default success status.
*/
- int DEF_SUCCESS_STATUS = 0;
+ private int DEF_SUCCESS_STATUS = 0;
private SshAdapter sshAdapter;
@@ -81,7 +82,6 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <table border="1">
* <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th><th>example values</th></thead>
* <tbody>
- * <tr><td>templateFileName</td><td>Optional</td><td>full path to template file that can be used to build a request</td><td>/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json</td></tr>
* <tr><td>Url</td><td>Mandatory</td><td>url to make the SSH connection request to.</td></tr>
* <tr><td>Port</td><td>Mandatory</td><td>port to make the SSH connection request to.</td></tr>
* <tr><td>User</td><td>Optional</td><td>user name to use for ssh basic authentication</td><td>sdnc_ws</td></tr>
@@ -90,8 +90,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <tr><td>ExecTimeout</td><td>Optional</td><td>SSH command execution timeout</td><td>plain_key</td></tr>
* <tr><td>Retry</td><td>Optional</td><td>Make ssh connection with default retry policy</td><td>plain_key</td></tr>
* <tr><td>Cmd</td><td>Mandatory</td><td>ssh command to be executed on the server.</td><td>get post put delete patch</td></tr>
- * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td><td>tmp.sshapi.result</td></tr>
- * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td><td>tmp.sshapi.result</td></tr>
+ * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td></tr>
+ * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td></tr>
* <tr><td>listName[i]</td><td>Optional</td><td>Used for processing XML responses with repeating elements.</td>vpn-information.vrf-details<td></td></tr>
* <tr><td>ConvertResponse </td><td>Optional</td><td>whether the response should be converted</td><td>true or false</td></tr>
* <tr><td>AuthType</td><td>Optional</td><td>Type of authentiation to be used BASIC or sshKey based</td><td>true or false</td></tr>
@@ -109,18 +109,29 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
*/
public void execCommand(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ execSshCommand(params, ctx, false);
+ }
+
+ private void execSshCommand(Map<String, String> params, SvcLogicContext ctx, boolean withPty) throws SvcLogicException {
ParseParam parser = new ParseParam();
Parameters p = parser.getParameters(params);
logger.debug("=> Connecting to SSH server...");
- SshConnection sshConnection = getSshConnection(p);
- sshConnection.connect();
+ SshConnection sshConnection = null;
try {
+ sshConnection = getSshConnection(p);
+ sshConnection.connect();
logger.debug("=> Connected to SSH server...");
logger.debug("=> Running SSH command...");
sshConnection.setExecTimeout(p.sshExecTimeout);
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
- int status = sshConnection.execCommand(parser.makeCommand(params), stdout, stderr);
+ int status;
+ if (withPty) {
+ status = sshConnection.execCommandWithPty(parser.makeCommand(params), stdout);
+ stderr = stdout;
+ }
+ else
+ status = sshConnection.execCommand(parser.makeCommand(params), stdout, stderr);
String stdoutRes = stdout.toString();
String stderrRes = stderr.toString();
logger.debug("=> executed SSH command");
@@ -131,12 +142,15 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
ctx.setAttribute(PARAM_OUT_status, String.format("%01d", status));
ctx.setAttribute(PARAM_OUT_stdout, stdoutRes);
ctx.setAttribute(PARAM_OUT_stderr, stderrRes);
+ } catch (Exception e){
+ throw new SvcLogicException("Exception in SSH adaptor : " + e.getMessage());
} finally {
- sshConnection.disconnect();
+ if (sshConnection != null)
+ sshConnection.disconnect();
}
}
- private SshConnection getSshConnection(Parameters p) throws SvcLogicException{
+ private SshConnection getSshConnection(Parameters p) throws SvcLogicException {
if (p.authtype == AuthType.BASIC)
return sshAdapter.getConnection(p.sshapiUrl, p.sshapiPort, p.sshapiUser, p.sshapiPassword);
// This is not supported yet in the API, patch has already been added to APPC
@@ -164,7 +178,6 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <table border="1">
* <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th><th>example values</th></thead>
* <tbody>
- * <tr><td>templateFileName</td><td>Optional</td><td>full path to template file that can be used to build a request</td><td>/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json</td></tr>
* <tr><td>Url</td><td>Mandatory</td><td>url to make the SSH connection request to.</td></tr>
* <tr><td>Port</td><td>Mandatory</td><td>port to make the SSH connection request to.</td></tr>
* <tr><td>User</td><td>Optional</td><td>user name to use for ssh basic authentication</td><td>sdnc_ws</td></tr>
@@ -173,8 +186,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <tr><td>ExecTimeout</td><td>Optional</td><td>SSH command execution timeout</td><td>plain_key</td></tr>
* <tr><td>Retry</td><td>Optional</td><td>Make ssh connection with default retry policy</td><td>plain_key</td></tr>
* <tr><td>Cmd</td><td>Mandatory</td><td>ssh command to be executed on the server.</td><td>get post put delete patch</td></tr>
- * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td><td>tmp.sshapi.result</td></tr>
- * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td><td>tmp.sshapi.result</td></tr>
+ * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td></tr>
+ * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td></tr>
* <tr><td>listName[i]</td><td>Optional</td><td>Used for processing XML responses with repeating elements.</td>vpn-information.vrf-details<td></td></tr>
* <tr><td>ConvertResponse </td><td>Optional</td><td>whether the response should be converted</td><td>true or false</td></tr>
* <tr><td>AuthType</td><td>Optional</td><td>Type of authentiation to be used BASIC or sshKey based</td><td>true or false</td></tr>
@@ -193,16 +206,19 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
public void execWithStatusCheck(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
execCommand(params, ctx);
+ ParseParam parser = new ParseParam();
+ String responsePrefix = parser.getStringParameters(params, parser.SSH_ResponsePrefix);
+ parseResponse(ctx, responsePrefix);
+ }
+
+ private void parseResponse (SvcLogicContext ctx, String responsePrefix) throws SvcLogicException {
int status = Integer.parseInt(ctx.getAttribute(PARAM_OUT_status));
if(status != DEF_SUCCESS_STATUS) {
StringBuilder errmsg = new StringBuilder();
errmsg.append("SSH command returned error status [").append(status).append(']');
- String stderrRes = ctx.getAttribute(PARAM_OUT_stderr);
- String stdoutRes = ctx.getAttribute(PARAM_OUT_stdout);
- if((stderrRes != null) && !stderrRes.isEmpty()) {
- errmsg.append(". Error: [").append(stderrRes).append(']');
- } else if ((stdoutRes != null) && !stdoutRes.isEmpty()) {
- errmsg.append(". Error: [").append(stdoutRes).append(']');
+ String stderr = ctx.getAttribute(PARAM_OUT_stderr);
+ if((stderr != null) && !stderr.isEmpty()) {
+ errmsg.append(". Error: [").append(stderr).append(']');
}
throw new SvcLogicException(errmsg.toString());
}
@@ -214,7 +230,6 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <table border="1">
* <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th><th>example values</th></thead>
* <tbody>
- * <tr><td>templateFileName</td><td>Optional</td><td>full path to template file that can be used to build a request</td><td>/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json</td></tr>
* <tr><td>Url</td><td>Mandatory</td><td>url to make the SSH connection request to.</td></tr>
* <tr><td>Port</td><td>Mandatory</td><td>port to make the SSH connection request to.</td></tr>
* <tr><td>User</td><td>Optional</td><td>user name to use for ssh basic authentication</td><td>sdnc_ws</td></tr>
@@ -223,8 +238,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* <tr><td>ExecTimeout</td><td>Optional</td><td>SSH command execution timeout</td><td>plain_key</td></tr>
* <tr><td>Retry</td><td>Optional</td><td>Make ssh connection with default retry policy</td><td>plain_key</td></tr>
* <tr><td>Cmd</td><td>Mandatory</td><td>ssh command to be executed on the server.</td><td>get post put delete patch</td></tr>
- * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td><td>tmp.sshapi.result</td></tr>
- * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td><td>tmp.sshapi.result</td></tr>
+ * <tr><td>ResponsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td></tr>
+ * <tr><td>ResponseType</td><td>Optional</td><td>If we know the response is to be in a specific format (supported are JSON, XML and NONE) </td></tr>
* <tr><td>listName[i]</td><td>Optional</td><td>Used for processing XML responses with repeating elements.</td>vpn-information.vrf-details<td></td></tr>
* <tr><td>ConvertResponse </td><td>Optional</td><td>whether the response should be converted</td><td>true or false</td></tr>
* <tr><td>AuthType</td><td>Optional</td><td>Type of authentiation to be used BASIC or sshKey based</td><td>true or false</td></tr>
@@ -241,6 +256,6 @@ public class SshApiCallNode implements SvcLogicJavaPlugin {
* @param ctx Reference to context memory
*/
public void execCommandWithPty(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
-
+ execSshCommand(params, ctx, true);
}
}
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/AuthType.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/AuthType.java
index 2ec48c70..806c8089 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/AuthType.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/AuthType.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Format.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Format.java
index e50a96c6..43c3c38d 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Format.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Format.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/JsonParser.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/JsonParser.java
index f40f1ad7..296192a5 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/JsonParser.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/JsonParser.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Parameters.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Parameters.java
index a22da5bc..fa2371e8 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Parameters.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/Parameters.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/ParseParam.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/ParseParam.java
index caf49ef9..a72bc7bb 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/ParseParam.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/ParseParam.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
@@ -59,6 +59,7 @@ public class ParseParam {
* Default SSH command timeout
*/
private final String FILE_PARAMETERS_OPT_KEY = "FileParameters";
+ public final String SSH_ResponsePrefix = "ResponsePrefix";
/**
* Default SSH connection port.
*/
@@ -74,7 +75,7 @@ public class ParseParam {
p.sshExecTimeout = Long.parseLong(parseParam(paramMap, "ExecTimeout", false, Long.toString(dEF_timeout)));
p.sshWithRetry = Boolean.valueOf(parseParam(paramMap, "Retry", false, "false"));
p.cmd = parseParam(paramMap, "Cmd", true, null);
- p.responsePrefix = parseParam(paramMap, "ResponsePrefix", false, null);
+ p.responsePrefix = parseParam(paramMap, SSH_ResponsePrefix, false, null);
p.responseType = Format.fromString(parseParam(paramMap, "ResponseType", false, "none"));
p.listNameList = getListNameList(paramMap);
p.convertResponse = Boolean.valueOf(parseParam(paramMap, "ConvertResponse", false, "true"));
@@ -83,6 +84,10 @@ public class ParseParam {
return p;
}
+ public String getStringParameters(Map<String, String> paramMap, String paramName) throws SvcLogicException {
+ return parseParam(paramMap, SSH_ResponsePrefix, false, null);
+ }
+
public void parseOutput (SvcLogicContext ctx, String outMessage) throws SvcLogicException {
if (p.convertResponse) {
if (p.responseType == Format.NONE) {
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlJsonUtil.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlJsonUtil.java
index e7fc60ed..d68fbc6a 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlJsonUtil.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlJsonUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlParser.java b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlParser.java
index c23aca6c..e31754bc 100644
--- a/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlParser.java
+++ b/sshapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/sshapicall/model/XmlParser.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestJsonParser.java b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestJsonParser.java
index 66be7300..4a5b765a 100644
--- a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestJsonParser.java
+++ b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestJsonParser.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestSshApiCallNode.java b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestSshApiCallNode.java
new file mode 100644
index 00000000..3992dffe
--- /dev/null
+++ b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestSshApiCallNode.java
@@ -0,0 +1,228 @@
+package jtest.org.onap.ccsdk.sli.plugins.sshapicall;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.plugins.sshapicall.SshApiCallNode;
+import org.onap.ccsdk.sli.plugins.sshapicall.model.XmlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestSshApiCallNode {
+
+ private static final Logger log = LoggerFactory.getLogger(TestSshApiCallNode.class);
+
+ private SshApiCallNode adapter;
+ private String TestId;
+ private boolean testMode = true;
+ private Map<String, String> params;
+ private SvcLogicContext svcContext;
+
+
+ @Before
+ public void setup() throws IllegalArgumentException {
+ testMode = true;
+ svcContext = new SvcLogicContext();
+ adapter = new SshApiCallNode();
+
+ params = new HashMap<>();
+ params.put("AgentUrl", "https://192.168.1.1");
+ params.put("User", "test");
+ params.put("Password", "test");
+ }
+
+ @After
+ public void tearDown() {
+ testMode = false;
+ adapter = null;
+ params = null;
+ svcContext = null;
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommand_noUrlFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execCommand(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandPty_noUrlFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execCommandWithPty(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noUrlFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommand_noPortFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execCommand(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandPty_noPortFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execCommandWithPty(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noPortFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "fail");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommand_noCmdFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ adapter.execCommand(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandPty_noCmdFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ adapter.execCommandWithPty(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noCmdFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noSSHBasicFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("AuthType", "basic");
+ params.put("Cmd", "test");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noSSHKeyFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("AuthType", "key");
+ params.put("Cmd", "test");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noSSHNoneFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("AuthType", "none");
+ params.put("Cmd", "test");
+ params.put("ResponseType", "xml");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testExecCommandResponse_noSSHFailed() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Cmd", "test");
+ params.put("ResponseType", "json");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testExecCommandResponse_noSSHInvalidParam() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Cmd", "test");
+ params.put("ResponseType", "txt");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testExecCommandResponse_noSSHInvalidAuthParam() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("Url", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Cmd", "test");
+ params.put("AuthType", "spring");
+ params.put("ResponseType", "json");
+ adapter.execWithStatusCheck(params, svcContext);
+ }
+}
diff --git a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlJsonUtil.java b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlJsonUtil.java
index 599043e9..218ad6a8 100644
--- a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlJsonUtil.java
+++ b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlJsonUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.
diff --git a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlParser.java b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlParser.java
index d904721f..3f8d3716 100644
--- a/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlParser.java
+++ b/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestXmlParser.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * * Copyright (C) 2017 AT&T Intellectual Property.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Samsung Electronics. All rights
* reserved.