Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [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 Discovery Test Case module |
| 19 | """ |
| 20 | |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 21 | import testCaseUtils |
| 22 | import logging |
Gilles Depatie | 82dd202 | 2019-02-19 14:31:33 -0500 | [diff] [blame] | 23 | import os |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 24 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 25 | |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 26 | class Discovery(object): |
| 27 | |
| 28 | """ |
| 29 | This class implements voltha discovery 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 |
Kailash | a4d4574 | 2019-02-11 14:46:43 -0800 | [diff] [blame] | 37 | |
| 38 | self.__logicalDeviceType = None |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 39 | self.__oltType = None |
| 40 | self.__onuType = None |
| 41 | self.__fields = [] |
Kailash | a4d4574 | 2019-02-11 14:46:43 -0800 | [diff] [blame] | 42 | self.__logicalDeviceId = None |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 43 | self.__oltDeviceId = None |
| 44 | self.__onuDeviceIds = [] |
| 45 | self.__peers = None |
| 46 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 47 | def d_set_log_dirs(self, log_dir): |
| 48 | testCaseUtils.config_dirs(self, log_dir) |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 49 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 50 | def d_configure(self, logical_device_type, olt_type, onu_type): |
| 51 | self.__logicalDeviceType = logical_device_type |
| 52 | self.__oltType = olt_type |
| 53 | self.__onuType = onu_type |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 54 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 55 | def logical_device(self): |
Kailash | a4d4574 | 2019-02-11 14:46:43 -0800 | [diff] [blame] | 56 | logging.info('Logical Device Info') |
| 57 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__logicalDeviceType, 'voltha_devices_after_enable.log') |
| 58 | assert statusLines, 'No Logical Devices listed under devices' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 59 | self.__fields = testCaseUtils.parse_fields(statusLines) |
Kailash | a4d4574 | 2019-02-11 14:46:43 -0800 | [diff] [blame] | 60 | self.__logicalDeviceId = self.__fields[4].strip() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 61 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 62 | 'voltha_logical_device.log', 'logical_device ' + self.__logicalDeviceId, |
| 63 | 'voltha_logical_device_ports.log', 'ports', 'voltha_logical_device_flows.log', 'flows') |
Gilles Depatie | 82dd202 | 2019-02-19 14:31:33 -0500 | [diff] [blame] | 64 | assert os.path.exists(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') and \ |
| 65 | (os.path.getsize(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') is 0), \ |
| 66 | 'voltha_logical_device.log is not 0 length' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 67 | testCaseUtils.print_log_file(self, 'voltha_logical_device_ports.log') |
| 68 | testCaseUtils.print_log_file(self, 'voltha_logical_device_flows.log') |
Kailash | a4d4574 | 2019-02-11 14:46:43 -0800 | [diff] [blame] | 69 | |
Gilles Depatie | 82dd202 | 2019-02-19 14:31:33 -0500 | [diff] [blame] | 70 | def logical_device_ports_should_exist(self): |
| 71 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltDeviceId, 'voltha_logical_device_ports.log') |
| 72 | assert statusLines, 'No Olt device listed under logical device ports' |
| 73 | self.__fields = testCaseUtils.parse_fields(statusLines) |
| 74 | portType = self.__fields[1].strip() |
| 75 | assert portType == 'nni', 'Port type for %s does not match expected nni' % self.__oltDeviceId |
| 76 | for onuDeviceId in self.__onuDeviceIds: |
| 77 | statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_logical_device_ports.log') |
| 78 | assert statusLines, 'No Onu device %s listed under logical device ports' % onuDeviceId |
| 79 | lines = statusLines.splitlines() |
| 80 | for line in lines: |
| 81 | self.__fields = testCaseUtils.parse_fields(line) |
| 82 | portType = self.__fields[1].strip() |
| 83 | assert portType == 'uni-128', 'Port type for %s does not match expected uni-128' % onuDeviceId |
| 84 | |
| 85 | def logical_device_should_have_at_least_one_flow(self): |
| 86 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_logical_device_flows.log') |
| 87 | assert statusLines, 'No Logical device flows listed for logical device' |
| 88 | before, flows, numFlows = statusLines.partition('Flows') |
| 89 | plainNumber = numFlows.strip().strip('():') |
| 90 | if plainNumber.isdigit(): |
| 91 | assert int(plainNumber) > 0, 'Zero number of flows for logical device' |
| 92 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 93 | def olt_discovery(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 94 | logging.info('Olt Discovery') |
| 95 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') |
| 96 | assert statusLines, 'No Olt listed under devices' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 97 | self.__fields = testCaseUtils.parse_fields(statusLines) |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 98 | self.__oltDeviceId = self.__fields[1].strip() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 99 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 100 | 'voltha_olt_device.log', 'device ' + self.__oltDeviceId, 'voltha_olt_ports.log', |
| 101 | 'ports', 'voltha_olt_flows.log', 'flows') |
| 102 | testCaseUtils.print_log_file(self, 'voltha_olt_ports.log') |
| 103 | testCaseUtils.print_log_file(self, 'voltha_olt_flows.log') |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 104 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 105 | def onu_discovery(self): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 106 | logging.info('Onu Discovery') |
| 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() |
| 110 | for line in lines: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 111 | self.__fields = testCaseUtils.parse_fields(line) |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 112 | onuDeviceId = self.__fields[1].strip() |
| 113 | self.__onuDeviceIds.append(onuDeviceId) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 114 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), |
| 115 | 'voltha_onu_device_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', |
| 116 | 'device ' + onuDeviceId, 'voltha_onu_ports_' + |
| 117 | str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'ports', 'voltha_onu_flows_' + |
| 118 | str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'flows') |
| 119 | testCaseUtils.print_log_file(self, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') |
| 120 | testCaseUtils.print_log_file(self, 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 121 | |
| 122 | def olt_ports_should_be_enabled_and_active(self): |
| 123 | statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltDeviceId, 'voltha_olt_ports.log') |
| 124 | assert statusLines, 'No Olt device listed under ports' |
| 125 | lines = statusLines.splitlines() |
| 126 | for line in lines: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 127 | self.__fields = testCaseUtils.parse_fields(line) |
| 128 | assert (self.check_states(self.__oltDeviceId) is True), 'States of %s does match expected ' % self.__oltDeviceId |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 129 | portType = self.__fields[3].strip() |
| 130 | assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT'),\ |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 131 | 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 132 | if portType == 'PON_OLT': |
| 133 | self.__peers = self.__fields[7].strip() |
| 134 | peerFields = self.__peers.split(',') |
| 135 | peerDevices = peerFields[1::2] |
| 136 | for peerDevice in peerDevices: |
| 137 | deviceFields = peerDevice.split(':') |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 138 | deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 139 | assert deviceId in self.__onuDeviceIds, 'ONU Device %s not found as Peer' % deviceId |
| 140 | |
| 141 | def onu_ports_should_be_enabled_and_active(self): |
| 142 | for onuDeviceId in self.__onuDeviceIds: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 143 | statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' + |
| 144 | str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 145 | assert statusLines, 'No Onu device listed under ports' |
| 146 | lines = statusLines.splitlines() |
| 147 | for line in lines: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 148 | self.__fields = testCaseUtils.parse_fields(line) |
| 149 | assert (self.check_states(onuDeviceId) is True), 'States of %s does match expected ' % onuDeviceId |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 150 | portType = self.__fields[3].strip() |
| 151 | assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\ |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 152 | 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 153 | if portType == 'PON_ONU': |
| 154 | self.__peers = self.__fields[7].strip() |
| 155 | peerFields = self.__peers.split(',') |
| 156 | peerDevice = peerFields[1] |
| 157 | deviceFields = peerDevice.split(':') |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 158 | deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 159 | assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId |
| 160 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 161 | def check_states(self, device_id): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 162 | result = True |
| 163 | adminState = self.__fields[4].strip() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 164 | assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % device_id |
| 165 | operatorStatus = self.__fields[5].strip() |
| 166 | assert operatorStatus == 'ACTIVE', 'Operator Status of %s not ACTIVE' % device_id |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 167 | return result |
| 168 | |
| 169 | def olt_should_have_at_least_one_flow(self): |
| 170 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_olt_flows.log') |
| 171 | assert statusLines, 'No Olt flows under device %s' % self.__oltDeviceId |
| 172 | before, flows, numFlows = statusLines.partition('Flows') |
| 173 | plainNumber = numFlows.strip().strip('():') |
| 174 | if plainNumber.isdigit(): |
| 175 | assert int(plainNumber) > 0, 'Zero number of flows for Olt %s' % self.__oltDeviceId |
| 176 | |
| 177 | def onu_should_have_at_least_one_flow(self): |
| 178 | for onuDeviceId in self.__onuDeviceIds: |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 179 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' + |
| 180 | str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 181 | assert statusLines, 'No Onu flows under device %s' % onuDeviceId |
| 182 | before, flows, numFlows = statusLines.partition('Flows') |
| 183 | plainNumber = numFlows.strip().strip('():') |
| 184 | if plainNumber.isdigit(): |
| 185 | assert int(plainNumber) > 0, 'Zero number of flows for Onu %s' % onuDeviceId |
| 186 | |
| 187 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 188 | def run_test(logical_device_type, olt_type, onu_type, log_dir): |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 189 | discovery = Discovery() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 190 | discovery.d_set_log_dirs(log_dir) |
| 191 | discovery.d_configure(logical_device_type, olt_type, onu_type) |
| 192 | discovery.olt_discovery() |
| 193 | discovery.onu_discovery() |
| 194 | discovery.logical_device() |
Gilles Depatie | 82dd202 | 2019-02-19 14:31:33 -0500 | [diff] [blame] | 195 | discovery.logical_device_ports_should_exist() |
| 196 | discovery.logical_device_should_have_at_least_one_flow() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 197 | discovery.olt_ports_should_be_enabled_and_active() |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 198 | discovery.onu_ports_should_be_enabled_and_active() |
| 199 | discovery.olt_should_have_at_least_one_flow() |
| 200 | discovery.onu_should_have_at_least_one_flow() |