Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | """ |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 18 | vOLT-HA Pre-provisioning Test Case module |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 19 | """ |
| 20 | |
| 21 | import time |
| 22 | import os |
| 23 | import commands |
| 24 | import testCaseUtils |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 25 | import logging |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 26 | |
| 27 | class Preprovisioning(object): |
| 28 | |
| 29 | """ |
| 30 | This class implements voltha pre-provisioning test |
| 31 | """ |
| 32 | |
| 33 | def __init__(self): |
| 34 | self.dirs = {} |
| 35 | self.dirs ['log'] = None |
| 36 | self.dirs ['root'] = None |
| 37 | self.dirs ['voltha'] = None |
| 38 | |
| 39 | self.__oltIpAddress = None |
| 40 | self.__oltPort = None |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 41 | self.__oltType = None |
| 42 | self.__onuType = None |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 43 | self.__fields = [] |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 44 | self.__oltDeviceId = None |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 45 | |
| 46 | def pSetLogDirs(self, logDir): |
| 47 | testCaseUtils.configDirs(self, logDir) |
| 48 | |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 49 | def pConfigure(self, oltIpAddress, oltPort, oltType, onuType): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 50 | self.__oltIpAddress = oltIpAddress |
| 51 | self.__oltPort = oltPort |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 52 | self.__oltType = oltType |
| 53 | self.__onuType = onuType |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 54 | |
| 55 | def preprovisionOlt(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 56 | logging.info('Do PROVISIONING') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 57 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 58 | 'voltha_preprovision_olt.log', 'preprovision_olt -t ponsim_olt -H %s:%s' % |
| 59 | (self.__oltIpAddress, self.__oltPort)) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 60 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 61 | |
| 62 | def status_should_be_success_after_preprovision_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 63 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log') |
| 64 | assert statusLines, 'Preprovision Olt command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 65 | |
| 66 | def query_devices_before_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 67 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
| 68 | 'voltha_devices_before_enable.log', 'devices') |
| 69 | testCaseUtils.printLogFile (self, 'voltha_devices_before_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 70 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 71 | |
| 72 | def check_olt_fields_before_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 73 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log') |
| 74 | assert statusLines, 'No Olt listed under devices' |
| 75 | self.__fields = testCaseUtils.parseFields(statusLines) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 76 | self.__oltDeviceId = self.__fields[1].strip() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 77 | logging.debug("OLT device id = %s" % self.__oltDeviceId) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 78 | adminState = self.__fields[3].strip() |
| 79 | assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED' |
| 80 | hostPort = self.__fields[4].strip() |
| 81 | assert hostPort, 'hostPort field is empty' |
| 82 | hostPortFields = hostPort.split(":") |
| 83 | assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 84 | 'Olt IP or Port does not match' |
| 85 | |
| 86 | def check_states(self, devType): |
| 87 | result = True |
| 88 | adminState = self.__fields[7].strip() |
| 89 | assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % devType |
| 90 | operStatus = self.__fields[8].strip() |
| 91 | assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % devType |
| 92 | connectStatus = self.__fields[9].strip() |
| 93 | assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % devType |
| 94 | return result |
| 95 | |
| 96 | def check_olt_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 97 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') |
| 98 | assert statusLines, 'No Olt listed under devices' |
| 99 | self.__fields = testCaseUtils.parseFields(statusLines) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 100 | assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType |
| 101 | hostPort = self.__fields[11].strip() |
| 102 | assert hostPort, 'hostPort field is empty' |
| 103 | hostPortFields = hostPort.split(":") |
| 104 | assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 105 | 'Olt IP or Port does not match' |
| 106 | |
| 107 | def check_onu_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 108 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log') |
| 109 | assert statusLines, 'No Onu listed under devices' |
| 110 | lines = statusLines.splitlines() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 111 | lenLines = len(lines) |
| 112 | assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines |
| 113 | for line in lines: |
| 114 | self.__fields = testCaseUtils.parseFields(line) |
| 115 | assert self.check_states(self.__onuType) == True, 'States of %s does match expected' % self.__onuType |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 116 | |
| 117 | def enable(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 118 | logging.info('Enable %s OLT device' % self.__oltDeviceId) |
| 119 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
| 120 | 'voltha_enable.log', 'enable ' + self.__oltDeviceId) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 121 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 122 | def status_should_be_success_after_enable_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 123 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log') |
| 124 | assert statusLines, 'Enable command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 125 | |
| 126 | def query_devices_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 127 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
| 128 | 'voltha_devices_after_enable.log', 'devices') |
| 129 | testCaseUtils.printLogFile (self, 'voltha_devices_after_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 130 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 131 | def runTest(oltIpAddress, oltPort, oltType, onuType, logDir): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 132 | preprovisioning = Preprovisioning() |
| 133 | preprovisioning.pSetLogDirs(logDir) |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 134 | preprovisioning.pConfigure(oltIpAddress, oltPort, oltType, onuType) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 135 | preprovisioning.preprovisionOlt() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 136 | preprovisioning.status_should_be_success_after_preprovision_command() |
| 137 | preprovisioning.query_devices_before_enabling() |
| 138 | preprovisioning.check_olt_fields_before_enabling() |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 139 | preprovisioning.enable() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 140 | preprovisioning.status_should_be_success_after_enable_command() |
| 141 | preprovisioning.query_devices_after_enabling() |
| 142 | preprovisioning.check_olt_fields_after_enabling() |
| 143 | preprovisioning.check_onu_fields_after_enabling() |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 144 | |
| 145 | |
| 146 | |