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 | """ |
| 18 | vOLT-HA Pre-provisioning Test module |
| 19 | """ |
| 20 | |
| 21 | import time |
| 22 | import os |
| 23 | import commands |
| 24 | import testCaseUtils |
| 25 | |
| 26 | class Preprovisioning(object): |
| 27 | |
| 28 | """ |
| 29 | This class implements voltha pre-provisioning test |
| 30 | """ |
| 31 | |
| 32 | def __init__(self): |
| 33 | self.dirs = {} |
| 34 | self.dirs ['log'] = None |
| 35 | self.dirs ['root'] = None |
| 36 | self.dirs ['voltha'] = None |
| 37 | |
| 38 | self.__oltIpAddress = None |
| 39 | self.__oltPort = None |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 40 | self.__oltType = None |
| 41 | self.__onuType = None |
| 42 | self.__statusLines = "" |
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 | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 49 | def configure(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 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 55 | def get_fields_from_grep_command(self, searchWord, logFile): |
| 56 | grepCommand =\ |
| 57 | "grep %s %s/%s" % (searchWord, testCaseUtils.getDir(self, 'log'), logFile) |
| 58 | self.__statusLines = commands.getstatusoutput(grepCommand)[1] |
| 59 | |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 60 | def preprovisionOlt(self): |
| 61 | print('Do PROVISIONING') |
| 62 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
| 63 | 'preprovision_olt -t ponsim_olt -H %s:%s' % |
| 64 | (self.__oltIpAddress, self.__oltPort), |
| 65 | 'voltha_preprovision_olt.log') |
| 66 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 67 | |
| 68 | def status_should_be_success_after_preprovision_command(self): |
| 69 | self.get_fields_from_grep_command('success', 'voltha_preprovision_olt.log') |
| 70 | assert self.__statusLines, 'Preprovision Olt command should have returned success but did not' |
| 71 | |
| 72 | def query_devices_before_enabling(self): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 73 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices', |
| 74 | 'voltha_devices_before_enable.log') |
| 75 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 76 | |
| 77 | def check_olt_fields_before_enabling(self): |
| 78 | result = True |
| 79 | self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_before_enable.log') |
| 80 | assert self.__statusLines, 'No Olt listed under devices' |
| 81 | self.__fields = testCaseUtils.parseFields(self.__statusLines) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 82 | self.__oltDeviceId = self.__fields[1].strip() |
| 83 | print ("OLT device id = %s" % self.__oltDeviceId) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 84 | adminState = self.__fields[3].strip() |
| 85 | assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED' |
| 86 | hostPort = self.__fields[4].strip() |
| 87 | assert hostPort, 'hostPort field is empty' |
| 88 | hostPortFields = hostPort.split(":") |
| 89 | assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 90 | 'Olt IP or Port does not match' |
| 91 | |
| 92 | def check_states(self, devType): |
| 93 | result = True |
| 94 | adminState = self.__fields[7].strip() |
| 95 | assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % devType |
| 96 | operStatus = self.__fields[8].strip() |
| 97 | assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % devType |
| 98 | connectStatus = self.__fields[9].strip() |
| 99 | assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % devType |
| 100 | return result |
| 101 | |
| 102 | def check_olt_fields_after_enabling(self): |
| 103 | self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_after_enable.log') |
| 104 | assert self.__statusLines, 'No Olt listed under devices' |
| 105 | self.__fields = testCaseUtils.parseFields(self.__statusLines) |
| 106 | assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType |
| 107 | hostPort = self.__fields[11].strip() |
| 108 | assert hostPort, 'hostPort field is empty' |
| 109 | hostPortFields = hostPort.split(":") |
| 110 | assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 111 | 'Olt IP or Port does not match' |
| 112 | |
| 113 | def check_onu_fields_after_enabling(self): |
| 114 | self.get_fields_from_grep_command(self.__onuType, 'voltha_devices_after_enable.log') |
| 115 | assert self.__statusLines, 'No Onu listed under devices' |
| 116 | lines = self.__statusLines.splitlines() |
| 117 | lenLines = len(lines) |
| 118 | assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines |
| 119 | for line in lines: |
| 120 | self.__fields = testCaseUtils.parseFields(line) |
| 121 | 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] | 122 | |
| 123 | def enable(self): |
| 124 | print('Enable %s OLT device' % self.__oltDeviceId) |
| 125 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'enable ' + self.__oltDeviceId, |
| 126 | 'voltha_enable.log') |
| 127 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 128 | def status_should_be_success_after_enable_command(self): |
| 129 | self.get_fields_from_grep_command('success', 'voltha_enable.log') |
| 130 | assert self.__statusLines, 'Enable command should have returned success but did not' |
| 131 | |
| 132 | def query_devices_after_enabling(self): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 133 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices', |
| 134 | 'voltha_devices_after_enable.log') |
| 135 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 136 | def runTest(oltIpAddress, oltPort, oltType, onuType, logDir): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 137 | preprovisioning = Preprovisioning() |
| 138 | preprovisioning.pSetLogDirs(logDir) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 139 | preprovisioning.configure(oltIpAddress, oltPort, oltType, onuType) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 140 | preprovisioning.preprovisionOlt() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 141 | preprovisioning.status_should_be_success_after_preprovision_command() |
| 142 | preprovisioning.query_devices_before_enabling() |
| 143 | preprovisioning.check_olt_fields_before_enabling() |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 144 | preprovisioning.enable() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 145 | preprovisioning.status_should_be_success_after_enable_command() |
| 146 | preprovisioning.query_devices_after_enabling() |
| 147 | preprovisioning.check_olt_fields_after_enabling() |
| 148 | preprovisioning.check_onu_fields_after_enabling() |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 149 | |
| 150 | |
| 151 | |