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 | """ |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 31 | |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 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 | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 42 | self.__onuCount = 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 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 46 | def p_set_log_dirs(self, log_dir): |
| 47 | testCaseUtils.config_dirs(self, log_dir) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 48 | |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 49 | def p_configure(self, olt_ip_address, olt_port, olt_type, onu_type, onu_count): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 50 | self.__oltIpAddress = olt_ip_address |
| 51 | self.__oltPort = olt_port |
| 52 | self.__oltType = olt_type |
| 53 | self.__onuType = onu_type |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 54 | self.__onuCount = onu_count |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 55 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 56 | def preprovision_olt(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 57 | logging.info('Do PROVISIONING') |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 58 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 59 | 'voltha_preprovision_olt.log', 'preprovision_olt -t %s -H %s:%s' % |
| 60 | (self.__oltType, self.__oltIpAddress, self.__oltPort)) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 61 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 62 | |
| 63 | def status_should_be_success_after_preprovision_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 64 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log') |
| 65 | assert statusLines, 'Preprovision Olt command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 66 | |
| 67 | def query_devices_before_enabling(self): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 68 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 69 | 'voltha_devices_before_enable.log', 'devices') |
| 70 | testCaseUtils.print_log_file(self, 'voltha_devices_before_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 71 | time.sleep(5) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 72 | |
| 73 | def check_olt_fields_before_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 74 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log') |
| 75 | assert statusLines, 'No Olt listed under devices' |
Gilles Depatie | 2e68369 | 2019-02-22 16:06:52 -0500 | [diff] [blame] | 76 | self.__fields = testCaseUtils.parse_fields(statusLines, '|') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 77 | self.__oltDeviceId = self.__fields[1].strip() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 78 | logging.debug("OLT device id = %s" % self.__oltDeviceId) |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 79 | adminState = self.__fields[3].strip() |
| 80 | assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED' |
| 81 | hostPort = self.__fields[4].strip() |
| 82 | assert hostPort, 'hostPort field is empty' |
| 83 | hostPortFields = hostPort.split(":") |
| 84 | assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ |
| 85 | 'Olt IP or Port does not match' |
| 86 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 87 | def check_states(self, dev_type): |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 88 | result = True |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 89 | stateMatchCount = 0 |
| 90 | for field in self.__fields: |
| 91 | field_no_space = field.strip() |
| 92 | if field_no_space == 'ENABLED' or field_no_space == 'ACTIVE' or field_no_space == 'DISCOVERED' or field_no_space == 'REACHABLE': |
| 93 | stateMatchCount += 1 |
| 94 | assert stateMatchCount == 3, 'State of %s is not ENABLED, ACTIVE or DISCOVERED and REACHABLE' % dev_type |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 95 | return result |
| 96 | |
| 97 | def check_olt_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 98 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') |
| 99 | assert statusLines, 'No Olt listed under devices' |
Gilles Depatie | 2e68369 | 2019-02-22 16:06:52 -0500 | [diff] [blame] | 100 | self.__fields = testCaseUtils.parse_fields(statusLines, '|') |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 101 | assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 102 | hostPortCount = False |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 103 | for field in self.__fields: |
| 104 | if field.strip() == self.__oltIpAddress + ':' + str(self.__oltPort): |
| 105 | hostPortCount = True |
| 106 | assert hostPortCount, 'hostPort field is empty or Olt IP and/or Port does not match' |
| 107 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 108 | def check_onu_fields_after_enabling(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 109 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log') |
| 110 | assert statusLines, 'No Onu listed under devices' |
| 111 | lines = statusLines.splitlines() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 112 | lenLines = len(lines) |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 113 | assert lenLines == self.__onuCount, ' Discovered onu(s) does not match, ONU Count was %d' % lenLines |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 114 | for line in lines: |
Gilles Depatie | 2e68369 | 2019-02-22 16:06:52 -0500 | [diff] [blame] | 115 | self.__fields = testCaseUtils.parse_fields(line, '|') |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 116 | 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] | 117 | |
| 118 | def enable(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 119 | logging.info('Enable %s OLT device' % self.__oltDeviceId) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 120 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 121 | 'voltha_enable.log', 'enable ' + self.__oltDeviceId) |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 122 | |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 123 | def status_should_be_success_after_enable_command(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 124 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log') |
| 125 | assert statusLines, 'Enable command should have returned success but did not' |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 126 | |
| 127 | def query_devices_after_enabling(self): |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 128 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 129 | 'voltha_devices_after_enable.log', 'devices') |
| 130 | testCaseUtils.print_log_file(self, 'voltha_devices_after_enable.log') |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 131 | |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 132 | def proceed(self): |
| 133 | logging.info('Pre-provisioning hold') |
| 134 | onuOnline = 0 |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 135 | if self.__oltType == 'ponsim_olt': |
| 136 | portType = 'PON_OLT' |
Gilles Depatie | 88c281a | 2019-07-30 16:17:03 -0400 | [diff] [blame] | 137 | while onuOnline < self.__onuCount: |
| 138 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), 'voltha_olt_device.log', 'device ' + |
| 139 | self.__oltDeviceId, 'voltha_olt_ports.log', 'ports') |
| 140 | statusLines = testCaseUtils.get_fields_from_grep_command(self, portType, 'voltha_olt_ports.log') |
| 141 | lines = statusLines.splitlines() |
| 142 | onuOnline = len(lines) |
| 143 | time.sleep(5) |
| 144 | logging.info('All ONUs now Online!') |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 145 | elif self.__oltType == 'openolt': |
Gilles Depatie | 88c281a | 2019-07-30 16:17:03 -0400 | [diff] [blame] | 146 | while onuOnline < self.__onuCount: |
| 147 | testCaseUtils.send_command_to_onos_cli(testCaseUtils.get_dir(self, 'log'), |
| 148 | 'voltha_onu_auth.log', 'aaa-users') |
| 149 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'AUTHORIZED', 'voltha_onu_auth.log') |
| 150 | lines = statusLines.splitlines() |
| 151 | onuOnline = len(lines) |
| 152 | time.sleep(5) |
| 153 | logging.info('All ONUs now AUTHORIZED') |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 154 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 155 | |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 156 | def run_test(olt_ip_address, olt_port, olt_type, onu_type, onu_count, log_dir): |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 157 | preprovisioning = Preprovisioning() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 158 | preprovisioning.p_set_log_dirs(log_dir) |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 159 | preprovisioning.p_configure(olt_ip_address, olt_port, olt_type, onu_type, onu_count) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 160 | preprovisioning.preprovision_olt() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 161 | preprovisioning.status_should_be_success_after_preprovision_command() |
| 162 | preprovisioning.query_devices_before_enabling() |
| 163 | preprovisioning.check_olt_fields_before_enabling() |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 164 | preprovisioning.enable() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 165 | preprovisioning.status_should_be_success_after_enable_command() |
Gilles Depatie | 88c281a | 2019-07-30 16:17:03 -0400 | [diff] [blame] | 166 | preprovisioning.proceed() |
Gilles Depatie | 9651e46 | 2018-11-21 15:58:33 -0500 | [diff] [blame] | 167 | preprovisioning.query_devices_after_enabling() |
| 168 | preprovisioning.check_olt_fields_after_enabling() |
| 169 | preprovisioning.check_onu_fields_after_enabling() |