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