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