From 1476ff884265181b5934d71a7a0e59b705ee1aac Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Thu, 2 Aug 2018 15:06:36 +0900 Subject: dependancy and tests cases added Issue-ID: CCSDK-407 Change-Id: I0450875b0a29cc4612e0979e3d6e97b6c4b398f0 Signed-off-by: Ganesh Chandrasekaran --- .../sli/plugins/sshapicall/SshApiCallNode.java | 69 ++++--- .../sli/plugins/sshapicall/model/AuthType.java | 2 +- .../ccsdk/sli/plugins/sshapicall/model/Format.java | 2 +- .../sli/plugins/sshapicall/model/JsonParser.java | 2 +- .../sli/plugins/sshapicall/model/Parameters.java | 2 +- .../sli/plugins/sshapicall/model/ParseParam.java | 9 +- .../sli/plugins/sshapicall/model/XmlJsonUtil.java | 2 +- .../sli/plugins/sshapicall/model/XmlParser.java | 2 +- .../sli/plugins/sshapicall/TestJsonParser.java | 2 +- .../sli/plugins/sshapicall/TestSshApiCallNode.java | 228 +++++++++++++++++++++ .../sli/plugins/sshapicall/TestXmlJsonUtil.java | 2 +- .../sli/plugins/sshapicall/TestXmlParser.java | 2 +- 12 files changed, 286 insertions(+), 38 deletions(-) create mode 100644 sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/sshapicall/TestSshApiCallNode.java (limited to 'sshapi-call-node/provider/src') 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 e4b082cda..10635be71 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 { * * * - * * * * @@ -90,8 +90,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { * * * - * - * + * + * * vpn-information.vrf-details * * @@ -109,18 +109,29 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { */ public void execCommand(Map params, SvcLogicContext ctx) throws SvcLogicException { + execSshCommand(params, ctx, false); + } + + private void execSshCommand(Map 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 { *
parameterMandatory/Optionaldescriptionexample values
templateFileNameOptionalfull path to template file that can be used to build a request/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json
UrlMandatoryurl to make the SSH connection request to.
PortMandatoryport to make the SSH connection request to.
UserOptionaluser name to use for ssh basic authenticationsdnc_ws
ExecTimeoutOptionalSSH command execution timeoutplain_key
RetryOptionalMake ssh connection with default retry policyplain_key
CmdMandatoryssh command to be executed on the server.get post put delete patch
ResponsePrefixOptionallocation the response will be written to in context memorytmp.sshapi.result
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE) tmp.sshapi.result
ResponsePrefixOptionallocation the response will be written to in context memory
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE)
listName[i]OptionalUsed for processing XML responses with repeating elements.
ConvertResponse Optionalwhether the response should be convertedtrue or false
AuthTypeOptionalType of authentiation to be used BASIC or sshKey basedtrue or false
* * - * * * * @@ -173,8 +186,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { * * * - * - * + * + * * vpn-information.vrf-details * * @@ -193,16 +206,19 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { public void execWithStatusCheck(Map 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 { *
parameterMandatory/Optionaldescriptionexample values
templateFileNameOptionalfull path to template file that can be used to build a request/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json
UrlMandatoryurl to make the SSH connection request to.
PortMandatoryport to make the SSH connection request to.
UserOptionaluser name to use for ssh basic authenticationsdnc_ws
ExecTimeoutOptionalSSH command execution timeoutplain_key
RetryOptionalMake ssh connection with default retry policyplain_key
CmdMandatoryssh command to be executed on the server.get post put delete patch
ResponsePrefixOptionallocation the response will be written to in context memorytmp.sshapi.result
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE) tmp.sshapi.result
ResponsePrefixOptionallocation the response will be written to in context memory
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE)
listName[i]OptionalUsed for processing XML responses with repeating elements.
ConvertResponse Optionalwhether the response should be convertedtrue or false
AuthTypeOptionalType of authentiation to be used BASIC or sshKey basedtrue or false
* * - * * * * @@ -223,8 +238,8 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { * * * - * - * + * + * * vpn-information.vrf-details * * @@ -241,6 +256,6 @@ public class SshApiCallNode implements SvcLogicJavaPlugin { * @param ctx Reference to context memory */ public void execCommandWithPty(Map 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 2ec48c70c..806c80890 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 e50a96c6c..43c3c38d6 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 f40f1ad71..296192a5b 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 a22da5bcb..fa2371e88 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 caf49ef91..a72bc7bbe 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 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 e7fc60edb..d68fbc6ac 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 c23aca6cf..e31754bcd 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 66be73001..4a5b765a8 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 000000000..3992dffe1 --- /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 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 599043e9c..218ad6a8d 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 d904721f8..3f8d37163 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. -- cgit 1.2.3-korg
parameterMandatory/Optionaldescriptionexample values
templateFileNameOptionalfull path to template file that can be used to build a request/sdncopt/bvc/sshapi/templates/vnf_service-configuration-operation_minimal.json
UrlMandatoryurl to make the SSH connection request to.
PortMandatoryport to make the SSH connection request to.
UserOptionaluser name to use for ssh basic authenticationsdnc_ws
ExecTimeoutOptionalSSH command execution timeoutplain_key
RetryOptionalMake ssh connection with default retry policyplain_key
CmdMandatoryssh command to be executed on the server.get post put delete patch
ResponsePrefixOptionallocation the response will be written to in context memorytmp.sshapi.result
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE) tmp.sshapi.result
ResponsePrefixOptionallocation the response will be written to in context memory
ResponseTypeOptionalIf we know the response is to be in a specific format (supported are JSON, XML and NONE)
listName[i]OptionalUsed for processing XML responses with repeating elements.
ConvertResponse Optionalwhether the response should be convertedtrue or false
AuthTypeOptionalType of authentiation to be used BASIC or sshKey basedtrue or false