aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-03-22 16:06:51 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-22 16:06:51 +0000
commit669f7a860035fd944699a85ee8726c831efe299c (patch)
treec5473204ac20da902215fc3306a7571e234b9ec0 /ms/blueprintsprocessor/functions
parent466b64f8b3c9ec7b5f184fbf1303fa8eb3aa18da (diff)
parentae19ea7f3aac00a151bd418d1ca948d83731f438 (diff)
Merge "Netconf executor code coverage"
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt11
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt46
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt124
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt120
4 files changed, 272 insertions, 29 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
index cf11cfdde..2dd73ef18 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
@@ -19,8 +19,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet
import org.apache.sshd.client.SshClient
+import org.apache.sshd.client.channel.ChannelSubsystem
import org.apache.sshd.client.channel.ClientChannel
import org.apache.sshd.client.session.ClientSession
+import org.apache.sshd.client.session.ClientSessionImpl
import org.apache.sshd.common.FactoryManager
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
@@ -40,6 +42,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
+import java.util.concurrent.atomic.AtomicReference
class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) :
NetconfSession {
@@ -273,4 +276,12 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
}
}
+
+ fun sessionstatus(state:String): Boolean{
+ return when (state){
+ "Close" -> channel.isClosed
+ "Open" -> channel.isOpen
+ else -> false
+ }
+ }
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
index 045725c79..e7a514347 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
@@ -15,13 +15,18 @@
*/
package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
+import org.apache.sshd.client.channel.ChannelSubsystem
+import org.apache.sshd.client.session.ClientSessionImpl
import org.junit.After
import org.junit.Assert
import org.junit.Before
+import org.junit.Test
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
+import java.util.concurrent.atomic.AtomicReference
+import kotlin.script.experimental.api.asSuccess
class NetconfSessionImplTest {
@@ -62,4 +67,45 @@ class NetconfSessionImplTest {
Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
}
+ @Test
+ fun testNetconfSessionconnect() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+ netconfSession.connect()
+ Assert.assertTrue(netconfSession.sessionstatus("Open"))
+ }
+
+ @Test
+ fun testNetconfSessionreconnect() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+ netconfSession.connect()
+ netconfSession.reconnect()
+ Assert.assertTrue(netconfSession.sessionstatus("Open"))
+
+ }
+ @Test
+ fun testNetconfSessiondisconnect() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+ netconfSession.connect()
+ netconfSession.disconnect()
+ Assert.assertTrue(netconfSession.sessionstatus("Close"))
+
+ }
+ @Test
+ fun testNetconfSessioncheckAndReestablish() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+ netconfSession.connect()
+ netconfSession.checkAndReestablish()
+ Assert.assertTrue(netconfSession.sessionstatus("Open"))
+
+
+ }
+ @Test
+ fun testNetconfSessionconnecgetDeviceInfo() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+ netconfSession.connect()
+ Assert.assertNotNull(netconfSession.getDeviceInfo())
+ Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
+ }
+
+
}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt
new file mode 100644
index 000000000..8f1f71501
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt
@@ -0,0 +1,124 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core
+
+import org.junit.After
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Test
+
+import org.junit.Assert.*
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
+
+class NetconfRpcServiceImplTest {
+
+ private var device: NetconfDeviceSimulator? = null
+ private var deviceInfo: DeviceInfo? = null
+
+ @Before
+ fun before() {
+ deviceInfo = DeviceInfo().apply {
+ username = "username"
+ password = "password"
+ ipAddress = "localhost"
+ port = 2224
+ connectTimeout = 10
+ }
+
+ device = NetconfDeviceSimulator(deviceInfo!!.port)
+ device!!.start()
+ }
+
+ @After
+ fun after() {
+ device!!.stop()
+ }
+
+ @Test
+ fun setNetconfSession() {
+
+ }
+
+ @Test
+ fun getConfig() {
+
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.getConfig("filter","target").status.equals("failure"))
+ }
+
+
+ @Test
+ fun deleteConfig() {
+
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.deleteConfig("target").status.equals("failure"))
+ }
+
+ @Test
+ fun lock() {
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.lock("target").status.equals("failure"))
+ }
+
+ @Test
+ fun unLock() {
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.unLock("target").status.equals("failure"))
+ }
+
+ @Test
+ fun commit() {
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.commit(true,60,"persist","1").status.equals("failure"))
+
+ }
+
+ @Test
+ fun cancelCommit() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo()))
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(DeviceInfo())
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+
+ Assert.assertNotNull(netconfRpcServiceImpl.cancelCommit("1"))
+ }
+
+ @Test
+ fun discardConfig() {
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.discardConfig().status.equals("failure"))
+
+ }
+
+ @Test
+ fun editConfig() {
+ }
+
+ @Test
+ fun validate() {
+ val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+ netconfRpcServiceImpl.setNetconfSession(netconfSession)
+ netconfSession.connect()
+ Assert.assertTrue(netconfRpcServiceImpl.validate("target").status.equals("failure"))
+
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
index d4c27b1c6..8a60d8097 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
@@ -35,7 +35,7 @@ class RpcMessageUtilsTest {
val filterContent = "Test-Filter-Content"
val result =
- NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(result))
Assert.assertEquals(checkString, result)
@@ -46,15 +46,16 @@ class RpcMessageUtilsTest {
fun editConfig() {
val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<get-config><source><candidate/></source><filter type=\"subtree\">Test-Filter-Content</filter>"
- + "</get-config></rpc>")
+ + "<edit-config><target><candidate/></target><default-operation>Test-Default-Operation</default-operation>"
+ + "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">Test-Filter-Content</config></edit-config></rpc>")
val messageId = "Test-Message-ID"
val configType = NetconfDatastore.CANDIDATE.datastore
val filterContent = "Test-Filter-Content"
+ val defaultOperation = "Test-Default-Operation"
val result =
- NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(result))
Assert.assertEquals(checkString, result)
@@ -78,16 +79,16 @@ class RpcMessageUtilsTest {
@Test
fun cancelCommit() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<cancel-commit>" +
- "<persist-id>1234</persist-id>" +
- "</cancel-commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<cancel-commit>" +
+ "<persist-id>1234</persist-id>" +
+ "</cancel-commit></rpc>")
val messageId = "Test-Message-ID"
val cancelCommitPersistId =
- NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId))
Assert.assertEquals(checkString, cancelCommitPersistId)
@@ -96,10 +97,10 @@ class RpcMessageUtilsTest {
@Test
fun cancelCommitNoPersistId() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<cancel-commit>" +
- "</cancel-commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<cancel-commit>" +
+ "</cancel-commit></rpc>")
val messageId = "Test-Message-ID"
@@ -120,7 +121,7 @@ class RpcMessageUtilsTest {
val commit = NetconfMessageUtils.commit(messageId, false, 0, "", "").replace("[\n\r\t]".toRegex(), "")
val commitWithPersistButNotConfirmed =
- NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(commit))
Assert.assertEquals(checkString, commit)
@@ -131,11 +132,11 @@ class RpcMessageUtilsTest {
@Test
fun commitPersistId() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<commit>" +
- "<persist-id>1234</persist-id>" +
- "</commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<commit>" +
+ "<persist-id>1234</persist-id>" +
+ "</commit></rpc>")
val messageId = "Test-Message-ID"
@@ -147,7 +148,7 @@ class RpcMessageUtilsTest {
NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "")
} catch (e: NetconfException) {
Assert.assertEquals("Can't proceed <commit> with both confirmed flag and persistId(1234) specified. Only one should be specified.",
- e.message)
+ e.message)
return
}
@@ -157,13 +158,13 @@ class RpcMessageUtilsTest {
@Test
fun commitPersist() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<commit>" +
- "<confirmed/>" +
- "<confirm-timeout>30</confirm-timeout>" +
- "<persist>1234</persist>" +
- "</commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<commit>" +
+ "<confirmed/>" +
+ "<confirm-timeout>30</confirm-timeout>" +
+ "<persist>1234</persist>" +
+ "</commit></rpc>")
val messageId = "Test-Message-ID"
@@ -176,7 +177,7 @@ class RpcMessageUtilsTest {
NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "")
} catch (e: NetconfException) {
Assert.assertEquals("Can't proceed <commit> with both persist(1234) and persistId(1234) specified. Only one should be specified.",
- e.message)
+ e.message)
return
}
fail()
@@ -240,5 +241,66 @@ class RpcMessageUtilsTest {
Assert.assertEquals(checkString, result)
}
+ @Test
+ fun getMsgId() {
+ val checkString = ("testmessage")
+
+ var messageId = "message-id=\"testmessage\""
+ var result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+ Assert.assertEquals(checkString, result)
+
+ messageId = "message-id=\"hello\""
+ result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+ Assert.assertEquals("hello", result)
+
+ messageId = "message-id"
+ result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+ Assert.assertEquals("", result)
+ }
+
+ @Test
+ fun createHelloString() {
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> "
+ +"<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
+
+ val capability = listOf<String>("hi", "hello")
+
+ val result = NetconfMessageUtils.createHelloString(capability).replace("[\n\r\t]".toRegex(), "")
+ Assert.assertEquals(checkString, result)
+ }
+
+ @Test
+ fun validateChunkedFraming() {
+ val reply = ("hello")
+ val result = NetconfMessageUtils.validateChunkedFraming(reply)
+ Assert.assertFalse(result)
+ }
+
+ @Test
+ fun checkReply(){
+ assertTrue(NetconfMessageUtils.checkReply("ok"))
+ }
+
+ @Test
+ fun formatRPCRequest(){
+ val checkString = ("#199" +
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> <capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>" +
+ "##")
+
+ val request = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> "
+ +"<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
+
+ val messageId = "Test-Message-ID"
+
+ val capabilities = setOf<String>("hi", "hello","urn:ietf:params:netconf:base:1.1")
+
+ val result = NetconfMessageUtils.formatRPCRequest(request,messageId,capabilities).replace("[\n\r\t]".toRegex(), "")
+ Assert.assertEquals(checkString, result)
+
+
+ }
+
+
+
} \ No newline at end of file