[VOL-2855] - Integration Test for OpenOnu go adapter
Change-Id: Iaefa1fc2bc9cad0a5dfa574b7586e3c2646316ec
diff --git a/Makefile b/Makefile
old mode 100644
new mode 100755
index fd803b5..b718b3d
--- a/Makefile
+++ b/Makefile
@@ -66,6 +66,14 @@
functional-single-kind-dt: ROBOT_FILE := Voltha_DT_PODTests.robot
functional-single-kind-dt: voltha-dt-test
+# target to invoke openonu go adapter
+openonu-go-adapter-test: ROBOT_MISC_ARGS += -v state2test:4 -v testmode:SingleState -v timeout:120s
+openonu-go-adapter-test: ROBOT_MISC_ARGS += -i statetest $(ROBOT_DEBUG_LOG_OPT)
+openonu-go-adapter-test: ROBOT_MISC_ARGS += -X
+openonu-go-adapter-test: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_SINGLE_PON_FILE)
+openonu-go-adapter-test: ROBOT_FILE := Voltha_ONUStateTests.robot
+openonu-go-adapter-test: openonu-go-adapter-statetest
+
sanity-single-kind: ROBOT_MISC_ARGS += -i sanity $(ROBOT_DEBUG_LOG_OPT)
sanity-single-kind: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_SINGLE_PON_FILE)
sanity-single-kind: bbsim-kind
@@ -157,6 +165,12 @@
cd tests/scale ;\
robot $(ROBOT_MISC_ARGS) Voltha_Scale_Tests.robot
+openonu-go-adapter-statetest: vst_venv
+ source ./$</bin/activate ; set -u ;\
+ cd tests/openonu-go-adapter ;\
+ robot -V $(ROBOT_CONFIG_FILE) $(ROBOT_MISC_ARGS) $(ROBOT_FILE)
+
+
# self-test, lint, and setup targets
# virtualenv for the robot tools
diff --git a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
new file mode 100755
index 0000000..f583a7e
--- /dev/null
+++ b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
@@ -0,0 +1,167 @@
+*** Settings ***
+Documentation Test states of ONU Go adapter
+Suite Setup Setup Suite
+Suite Teardown Teardown Suite
+Test Setup Setup
+Test Teardown Teardown
+Library Collections
+Library String
+Library OperatingSystem
+Library XML
+Library RequestsLibrary
+Library ../../libraries/DependencyLibrary.py
+Resource ../../libraries/onos.robot
+Resource ../../libraries/voltctl.robot
+Resource ../../libraries/voltha.robot
+Resource ../../libraries/utils.robot
+Resource ../../libraries/k8s.robot
+Resource ../../variables/variables.robot
+
+*** Variables ***
+${POD_NAME} flex-ocp-cord
+${KUBERNETES_CONF} ${KUBERNETES_CONFIGS_DIR}/${POD_NAME}.conf
+${KUBERNETES_CONFIGS_DIR} ~/pod-configs/kubernetes-configs
+#${KUBERNETES_CONFIGS_DIR} ${KUBERNETES_CONFIGS_DIR}/${POD_NAME}.conf
+${KUBERNETES_YAML} ${KUBERNETES_CONFIGS_DIR}/${POD_NAME}.yml
+${HELM_CHARTS_DIR} ~/helm-charts
+${VOLTHA_POD_NUM} 8
+${NAMESPACE} voltha
+# For below variable value, using deployment name as using grep for
+# parsing radius pod name, we can also use full radius pod name
+${RESTART_POD_NAME} radius
+${timeout} 120s
+${of_id} 0
+${logical_id} 0
+${has_dataplane} True
+${external_libs} True
+${teardown_device} True
+${scripts} ../../scripts
+# Per-test logging on failure is turned off by default; set this variable to enable
+${container_log_dir} ${None}
+# state to test variable, can be passed via the command line too
+${state2test} 6
+${testmode} SingleState
+${porttest} True
+
+*** Test Cases ***
+ONU State Test
+ [Documentation] Validates the ONU Go adapter states
+ [Tags] statetest
+ [Setup] Run Keywords Start Logging ONUStateTest
+ ... AND Setup Test
+ Run Keyword If ${has_dataplane} Clean Up Linux
+ Enable Device ${olt_device_id}
+ Run Keyword If "${testmode}"=="SingleState" Do ONU Single State Test
+ ... ELSE IF "${testmode}"=="Up2State" Do ONU Up To State Test
+ ... ELSE Fail The testmode (${testmode}) is not valid!
+ Run Keyword If ${porttest} Do Onu Port Check
+ [Teardown] Run Keywords Collect Logs
+ ... AND Stop Logging ONUStateTest
+
+*** Keywords ***
+Setup Suite
+ [Documentation] Set up the test suite
+ Common Test Suite Setup
+ Run Keyword If ${num_onus}>4 Calculate Timeout
+
+Setup Test
+ [Documentation] Pre-test Setup
+ #test for empty device list
+ Test Empty Device List
+ Run Keyword If ${has_dataplane} Wait Until Keyword Succeeds 120s 10s Openolt is Up
+ ... ${olt_ip} ${olt_user} ${olt_pass}
+ Run Keyword If ${has_dataplane} Sleep 60s
+ #create/preprovision device
+ ${olt_device_id}= Create Device ${olt_ip} ${OLT_PORT}
+ Set Suite Variable ${olt_device_id}
+ #validate olt states
+ Wait Until Keyword Succeeds ${timeout} 5s Validate OLT Device PREPROVISIONED UNKNOWN UNKNOWN
+ ... ${olt_device_id}
+ Sleep 5s
+
+Calculate Timeout
+ [Documentation] Calculates the timeout regarding num-onus in case of more than 4 onus
+ ${timeout} Fetch From Left ${timeout} s
+ ${timeout}= evaluate ${timeout}+((${num_onus}-4)*30)
+ ${timeout}= Catenate SEPARATOR= ${timeout} s
+ Set Suite Variable ${timeout}
+ #Log \r\nTimeout: ${timeout} INFO console=True
+
+Do ONU Up To State Test
+ [Documentation] This keyword performs Up2State Test
+ ... All states up to the passed have to be checked
+ FOR ${I} IN RANGE 0 ${num_onus}
+ ${src}= Set Variable ${hosts.src[${I}]}
+ ${dst}= Set Variable ${hosts.dst[${I}]}
+ Run Keyword If ${state2test}>=1
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=activating-onu
+ Run Keyword If ${state2test}>=2
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=starting-openomci
+ Run Keyword If ${state2test}>=3
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=discovery-mibsync-complete
+ Run Keyword If ${state2test}>=4
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=initial-mib-downloaded
+ Run Keyword If ${state2test}>=5
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=tech-profile-config-download-success
+ Run Keyword If ${state2test}>=6
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=omci-flows-pushed
+ END
+
+Do ONU Single State Test
+ [Documentation] This keyword performs SingleState Test
+ ... Only the passed state has to be checked
+ FOR ${I} IN RANGE 0 ${num_onus}
+ ${src}= Set Variable ${hosts.src[${I}]}
+ ${dst}= Set Variable ${hosts.dst[${I}]}
+ Run Keyword If ${state2test}==1
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=activating-onu
+ ... ELSE IF ${state2test}==2
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=starting-openomci
+ ... ELSE IF ${state2test}==3
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVATING REACHABLE
+ ... ${src['onu']} onu=True onu_reason=discovery-mibsync-complete
+ ... ELSE IF ${state2test}==4
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=initial-mib-downloaded
+ ... ELSE IF ${state2test}==5
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=tech-profile-config-download-success
+ ... ELSE IF ${state2test}==6
+ ... Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
+ ... Validate Device ENABLED ACTIVE REACHABLE
+ ... ${src['onu']} onu=True onu_reason=omci-flows-pushed
+ ... ELSE Fail The state to test (${state2test}) is not valid!
+ END
+
+Do Onu Port Check
+ [Documentation] This keyword performs Onu Port Check
+ ${of_id}= Wait Until Keyword Succeeds ${timeout} 15s Validate OLT Device in ONOS ${olt_serial_number}
+ Set Global Variable ${of_id}
+ FOR ${I} IN RANGE 0 ${num_onus}
+ ${src}= Set Variable ${hosts.src[${I}]}
+ ${dst}= Set Variable ${hosts.dst[${I}]}
+ ${onu_device_id}= Get Device ID From SN ${src['onu']}
+ ${onu_port}= Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2s
+ ... Get ONU Port in ONOS ${src['onu']} ${of_id}
+ Run Keyword And Continue On Failure Wait Until Keyword Succeeds 120s 2s
+ ... Verify ONU Port Is Enabled ${ONOS_SSH_IP} ${ONOS_SSH_PORT} ${onu_port}
+ END