VOL-1056: Test Case: OLT provisioning and enabling
Refactor python test case libraries to use asserts
Simplify Robot code to single line test
Change-Id: Id9a740df7b5e4ee8c4faf6d38130a2a13158ce4b
diff --git a/tests/atests/common/auto_test.py b/tests/atests/common/auto_test.py
index 8f1997e..709d218 100755
--- a/tests/atests/common/auto_test.py
+++ b/tests/atests/common/auto_test.py
@@ -69,6 +69,6 @@
volthaMngr.voltha_Initialize(ROOT_DIR, VOLTHA_DIR, LOG_DIR)
- preprovisioning.runTest('olt.voltha.svc', 50060, LOG_DIR)
+ preprovisioning.runTest('olt.voltha.svc', 50060, 'ponsim_olt', 'ponsim_onu', LOG_DIR)
time.sleep(5)
diff --git a/tests/atests/common/preprovisioning.py b/tests/atests/common/preprovisioning.py
index 9b19408..86c2048 100755
--- a/tests/atests/common/preprovisioning.py
+++ b/tests/atests/common/preprovisioning.py
@@ -37,16 +37,26 @@
self.__oltIpAddress = None
self.__oltPort = None
- self.__statusLine = ""
+ self.__oltType = None
+ self.__onuType = None
+ self.__statusLines = ""
self.__fields = []
+ self.__oltDeviceId = None
def pSetLogDirs(self, logDir):
testCaseUtils.configDirs(self, logDir)
- def configure(self, oltIpAddress, oltPort):
+ def configure(self, oltIpAddress, oltPort, oltType, onuType):
self.__oltIpAddress = oltIpAddress
self.__oltPort = oltPort
+ self.__oltType = oltType
+ self.__onuType = onuType
+ def get_fields_from_grep_command(self, searchWord, logFile):
+ grepCommand =\
+ "grep %s %s/%s" % (searchWord, testCaseUtils.getDir(self, 'log'), logFile)
+ self.__statusLines = commands.getstatusoutput(grepCommand)[1]
+
def preprovisionOlt(self):
print('Do PROVISIONING')
testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
@@ -54,36 +64,88 @@
(self.__oltIpAddress, self.__oltPort),
'voltha_preprovision_olt.log')
time.sleep(5)
-
- def query_devices_before_enable(self):
+
+ def status_should_be_success_after_preprovision_command(self):
+ self.get_fields_from_grep_command('success', 'voltha_preprovision_olt.log')
+ assert self.__statusLines, 'Preprovision Olt command should have returned success but did not'
+
+ def query_devices_before_enabling(self):
testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices',
'voltha_devices_before_enable.log')
time.sleep(5)
- grepCommand =\
- "grep PREPROVISIONED %s/voltha_devices_before_enable.log " % testCaseUtils.getDir(self, 'log')
- self.__statusLine = commands.getstatusoutput(grepCommand)[1]
- self.__fields = testCaseUtils.parseFields(self.__statusLine)
+
+ def check_olt_fields_before_enabling(self):
+ result = True
+ self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_before_enable.log')
+ assert self.__statusLines, 'No Olt listed under devices'
+ self.__fields = testCaseUtils.parseFields(self.__statusLines)
self.__oltDeviceId = self.__fields[1].strip()
print ("OLT device id = %s" % self.__oltDeviceId)
+ adminState = self.__fields[3].strip()
+ assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED'
+ hostPort = self.__fields[4].strip()
+ assert hostPort, 'hostPort field is empty'
+ hostPortFields = hostPort.split(":")
+ assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
+ 'Olt IP or Port does not match'
+
+ def check_states(self, devType):
+ result = True
+ adminState = self.__fields[7].strip()
+ assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % devType
+ operStatus = self.__fields[8].strip()
+ assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % devType
+ connectStatus = self.__fields[9].strip()
+ assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % devType
+ return result
+
+ def check_olt_fields_after_enabling(self):
+ self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_after_enable.log')
+ assert self.__statusLines, 'No Olt listed under devices'
+ self.__fields = testCaseUtils.parseFields(self.__statusLines)
+ assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType
+ hostPort = self.__fields[11].strip()
+ assert hostPort, 'hostPort field is empty'
+ hostPortFields = hostPort.split(":")
+ assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
+ 'Olt IP or Port does not match'
+
+ def check_onu_fields_after_enabling(self):
+ self.get_fields_from_grep_command(self.__onuType, 'voltha_devices_after_enable.log')
+ assert self.__statusLines, 'No Onu listed under devices'
+ lines = self.__statusLines.splitlines()
+ lenLines = len(lines)
+ assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines
+ for line in lines:
+ self.__fields = testCaseUtils.parseFields(line)
+ assert self.check_states(self.__onuType) == True, 'States of %s does match expected' % self.__onuType
def enable(self):
print('Enable %s OLT device' % self.__oltDeviceId)
testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'enable ' + self.__oltDeviceId,
'voltha_enable.log')
- def query_devices_after_enable(self):
+ def status_should_be_success_after_enable_command(self):
+ self.get_fields_from_grep_command('success', 'voltha_enable.log')
+ assert self.__statusLines, 'Enable command should have returned success but did not'
+
+ def query_devices_after_enabling(self):
testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices',
'voltha_devices_after_enable.log')
-def runTest(oltIpAddress, oltPort, logDir):
+def runTest(oltIpAddress, oltPort, oltType, onuType, logDir):
preprovisioning = Preprovisioning()
preprovisioning.pSetLogDirs(logDir)
- preprovisioning.configure(str(oltIpAddress), int(oltPort))
+ preprovisioning.configure(oltIpAddress, oltPort, oltType, onuType)
preprovisioning.preprovisionOlt()
- preprovisioning.query_devices_before_enable()
+ preprovisioning.status_should_be_success_after_preprovision_command()
+ preprovisioning.query_devices_before_enabling()
+ preprovisioning.check_olt_fields_before_enabling()
preprovisioning.enable()
- preprovisioning.query_devices_after_enable()
-
+ preprovisioning.status_should_be_success_after_enable_command()
+ preprovisioning.query_devices_after_enabling()
+ preprovisioning.check_olt_fields_after_enabling()
+ preprovisioning.check_onu_fields_after_enabling()
diff --git a/tests/atests/common/testCaseUtils.py b/tests/atests/common/testCaseUtils.py
index 541c9c0..72ba087 100755
--- a/tests/atests/common/testCaseUtils.py
+++ b/tests/atests/common/testCaseUtils.py
@@ -50,7 +50,7 @@
child.expect('[pP]assword:')
child.sendline('admin')
child.expect('\((\\x1b\[\d*;?\d+m){1,2}voltha(\\x1b\[\d*;?\d+m){1,2}\)')
- time.sleep(5)
+ time.sleep(10)
bytes = child.sendline(cmd)
child.expect('\((\\x1b\[\d*;?\d+m){1,2}voltha(\\x1b\[\d*;?\d+m){1,2}\)')
print (child.before)
diff --git a/tests/atests/robot/voltha_automated_test_suite.robot b/tests/atests/robot/voltha_automated_test_suite.robot
index 0ac9ae4..68cd305 100755
--- a/tests/atests/robot/voltha_automated_test_suite.robot
+++ b/tests/atests/robot/voltha_automated_test_suite.robot
@@ -20,6 +20,7 @@
Library ../common/preprovisioning.py
Library volthaMngr.VolthaMngr
Library preprovisioning.Preprovisioning
+
Test Setup Start Voltha
Test Teardown Stop Voltha
@@ -27,11 +28,11 @@
${LOG_DIR} /tmp/voltha_test_results
${ROOT_DIR} ${EMPTY}
${VOLTHA_DIR} ${EMPTY}
-${PONSIM_PID} ${EMPTY}
${ONOS_SSH_PORT} 8101
${OLT_IP_ADDR} olt.voltha.svc
${OLT_PORT_ID} 50060
-
+${OLT_TYPE} ponsim_olt
+${ONU_TYPE} ponsim_onu
*** Test Cases ***
Provisioning
@@ -41,12 +42,16 @@
... information. It then verifies that all the physical and logical devices are ACTIVE
... and REACHEABLE
PSet Log Dirs ${LOG_DIR}
- Configure ${OLT_IP_ADDR} ${OLT_PORT_ID}
+ Configure ${OLT_IP_ADDR} ${OLT_PORT_ID} ${OLT_TYPE} ${ONU_TYPE}
Preprovision Olt
- Wait Until Keyword Succeeds 60s 2s Query Devices Before Enable
+ Wait Until Keyword Succeeds 60s 2s Query Devices Before Enabling
+ Status Should Be Success After Preprovision Command
+ Check Olt Fields Before Enabling
Enable
- Wait Until Keyword Succeeds 60s 2s Query Devices After Enable
-
+ Wait Until Keyword Succeeds 60s 2s Query Devices After Enabling
+ Status Should Be Success After Enable Command
+ Check Olt Fields After Enabling
+ Check Onu Fields After Enabling
*** Keywords ***
Start Voltha