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 |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 22 | import testCaseUtils |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 23 | import logging |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 24 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 25 | |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 26 | class Preprovisioning(object): |
| 27 | |
| 28 | """ |
| 29 | This class implements voltha pre-provisioning test |
| 30 | """ |
| 31 | |
| 32 | def __init__(self): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 33 | self.dirs = dict() |
| 34 | self.dirs['log'] = None |
| 35 | self.dirs['root'] = None |
| 36 | self.dirs['voltha'] = None |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 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 |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 42 | self.__fields = [] |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 43 | self.__oltDeviceId = None |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 44 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 45 | def p_set_log_dirs(self, log_dir): |
| 46 | testCaseUtils.config_dirs(self, log_dir) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 47 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 48 | def p_configure(self, olt_ip_address, olt_port, olt_type, onu_type): |
| 49 | self.__oltIpAddress = olt_ip_address |
| 50 | self.__oltPort = olt_port |
| 51 | self.__oltType = olt_type |
| 52 | self.__onuType = onu_type |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 53 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 54 | def preprovision_olt(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 55 | logging.info('Do PROVISIONING') |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 56 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 57 | 'voltha_preprovision_olt.log', 'preprovision_olt -t ponsim_olt -H %s:%s' % |
| 58 | (self.__oltIpAddress, self.__oltPort)) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 59 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 60 | |
| 61 | def status_should_be_success_after_preprovision_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 62 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log') |
| 63 | assert statusLines, 'Preprovision Olt command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 64 | |
| 65 | def query_devices_before_enabling(self): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 66 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 67 | 'voltha_devices_before_enable.log', 'devices') |
| 68 | testCaseUtils.print_log_file(self, 'voltha_devices_before_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 69 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 70 | |
| 71 | def check_olt_fields_before_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 72 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log') |
| 73 | assert statusLines, 'No Olt listed under devices' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 74 | self.__fields = testCaseUtils.parse_fields(statusLines) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 75 | self.__oltDeviceId = self.__fields[1].strip() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 76 | logging.debug("OLT device id = %s" % self.__oltDeviceId) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 77 | adminState = self.__fields[3].strip() |
| 78 | assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED' |
| 79 | hostPort = self.__fields[4].strip() |
| 80 | assert hostPort, 'hostPort field is empty' |
| 81 | hostPortFields = hostPort.split(":") |
| 82 | assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 83 | 'Olt IP or Port does not match' |
| 84 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 85 | def check_states(self, dev_type): |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 86 | result = True |
| 87 | adminState = self.__fields[7].strip() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 88 | assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % dev_type |
| 89 | operatorStatus = self.__fields[8].strip() |
| 90 | assert operatorStatus == 'ACTIVE', 'Operator Status of %s not ACTIVE' % dev_type |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 91 | connectStatus = self.__fields[9].strip() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 92 | assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % dev_type |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 93 | return result |
| 94 | |
| 95 | def check_olt_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 96 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') |
| 97 | assert statusLines, 'No Olt listed under devices' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 98 | self.__fields = testCaseUtils.parse_fields(statusLines) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 99 | assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType |
| 100 | hostPort = self.__fields[11].strip() |
| 101 | assert hostPort, 'hostPort field is empty' |
| 102 | hostPortFields = hostPort.split(":") |
| 103 | assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 104 | 'Olt IP or Port does not match' |
| 105 | |
| 106 | def check_onu_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 107 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log') |
| 108 | assert statusLines, 'No Onu listed under devices' |
| 109 | lines = statusLines.splitlines() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 110 | lenLines = len(lines) |
| 111 | assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines |
| 112 | for line in lines: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 113 | self.__fields = testCaseUtils.parse_fields(line) |
| 114 | assert (self.check_states(self.__onuType) is True), 'States of %s does match expected' % self.__onuType |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 115 | |
| 116 | def enable(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 117 | logging.info('Enable %s OLT device' % self.__oltDeviceId) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 118 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 119 | 'voltha_enable.log', 'enable ' + self.__oltDeviceId) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 120 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 121 | def status_should_be_success_after_enable_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 122 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log') |
| 123 | assert statusLines, 'Enable command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 124 | |
| 125 | def query_devices_after_enabling(self): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 126 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 127 | 'voltha_devices_after_enable.log', 'devices') |
| 128 | testCaseUtils.print_log_file(self, 'voltha_devices_after_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 129 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 130 | |
| 131 | def run_test(olt_ip_address, olt_port, olt_type, onu_type, log_dir): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 132 | preprovisioning = Preprovisioning() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 133 | preprovisioning.p_set_log_dirs(log_dir) |
| 134 | preprovisioning.p_configure(olt_ip_address, olt_port, olt_type, onu_type) |
| 135 | preprovisioning.preprovision_olt() |
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() |