blob: 3f0804f90fde669a45df1cfe98d4cae36c7271a5 [file] [log] [blame]
Gilles Depatie1be639b2018-12-06 10:51:08 -05001#
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"""
18vOLT-HA Discovery Test Case module
19"""
20
Gilles Depatie1be639b2018-12-06 10:51:08 -050021import testCaseUtils
22import logging
Gilles Depatie82dd2022019-02-19 14:31:33 -050023import os
Gilles Depatie1be639b2018-12-06 10:51:08 -050024
Gilles Depatie0bf31352019-02-04 13:48:41 -050025
Gilles Depatie1be639b2018-12-06 10:51:08 -050026class Discovery(object):
27
28 """
29 This class implements voltha discovery test
30 """
31
32 def __init__(self):
Gilles Depatie0bf31352019-02-04 13:48:41 -050033 self.dirs = dict()
34 self.dirs['log'] = None
35 self.dirs['root'] = None
36 self.dirs['voltha'] = None
Kailasha4d45742019-02-11 14:46:43 -080037
38 self.__logicalDeviceType = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050039 self.__oltType = None
40 self.__onuType = None
Gilles Depatieea423712019-04-12 16:39:12 -040041 self.__onuCount = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050042 self.__fields = []
Kailasha4d45742019-02-11 14:46:43 -080043 self.__logicalDeviceId = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050044 self.__oltDeviceId = None
45 self.__onuDeviceIds = []
46 self.__peers = None
47
Gilles Depatie0bf31352019-02-04 13:48:41 -050048 def d_set_log_dirs(self, log_dir):
49 testCaseUtils.config_dirs(self, log_dir)
Gilles Depatie1be639b2018-12-06 10:51:08 -050050
Gilles Depatieea423712019-04-12 16:39:12 -040051 def d_configure(self, logical_device_type, olt_type, onu_type, onu_count):
Gilles Depatie0bf31352019-02-04 13:48:41 -050052 self.__logicalDeviceType = logical_device_type
53 self.__oltType = olt_type
54 self.__onuType = onu_type
Gilles Depatieea423712019-04-12 16:39:12 -040055 self.__onuCount = onu_count
Gilles Depatie1be639b2018-12-06 10:51:08 -050056
Gilles Depatie0bf31352019-02-04 13:48:41 -050057 def logical_device(self):
Kailasha4d45742019-02-11 14:46:43 -080058 logging.info('Logical Device Info')
Gilles Depatieea423712019-04-12 16:39:12 -040059 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 Depatie2e683692019-02-22 16:06:52 -050064 self.__fields = testCaseUtils.parse_fields(statusLines, '|')
Gilles Depatieea423712019-04-12 16:39:12 -040065 self.__logicalDeviceId = self.__fields[1].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -050066 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 Depatie82dd2022019-02-19 14:31:33 -050069 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 Depatie0bf31352019-02-04 13:48:41 -050072 testCaseUtils.print_log_file(self, 'voltha_logical_device_ports.log')
73 testCaseUtils.print_log_file(self, 'voltha_logical_device_flows.log')
Kailasha4d45742019-02-11 14:46:43 -080074
Gilles Depatie82dd2022019-02-19 14:31:33 -050075 def logical_device_ports_should_exist(self):
76 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltDeviceId, 'voltha_logical_device_ports.log')
Gilles Depatieea423712019-04-12 16:39:12 -040077 assert statusLines, 'No Olt ports listed under logical device ports'
Gilles Depatie2e683692019-02-22 16:06:52 -050078 self.__fields = testCaseUtils.parse_fields(statusLines, '|')
Gilles Depatie82dd2022019-02-19 14:31:33 -050079 portType = self.__fields[1].strip()
Gilles Depatieea423712019-04-12 16:39:12 -040080 assert portType.count('nni') == 1, 'Port type for %s does not match expected nni' % self.__oltDeviceId
Gilles Depatie82dd2022019-02-19 14:31:33 -050081 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 Depatieea423712019-04-12 16:39:12 -040084 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 Depatie82dd2022019-02-19 14:31:33 -050087
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 Depatie0bf31352019-02-04 13:48:41 -050096 def olt_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050097 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 Depatie2e683692019-02-22 16:06:52 -0500100 self.__fields = testCaseUtils.parse_fields(statusLines, '|')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500101 self.__oltDeviceId = self.__fields[1].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500102 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 Depatie1be639b2018-12-06 10:51:08 -0500107
Gilles Depatie0bf31352019-02-04 13:48:41 -0500108 def onu_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500109 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 Depatieea423712019-04-12 16:39:12 -0400113 assert len(lines) == self.__onuCount, 'Onu count mismatch found: %s, should be: %s' % (len(lines), self.__onuCount)
Gilles Depatie1be639b2018-12-06 10:51:08 -0500114 for line in lines:
Gilles Depatie2e683692019-02-22 16:06:52 -0500115 self.__fields = testCaseUtils.parse_fields(line, '|')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500116 onuDeviceId = self.__fields[1].strip()
117 self.__onuDeviceIds.append(onuDeviceId)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500118 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 Depatie1be639b2018-12-06 10:51:08 -0500125
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 Depatie2e683692019-02-22 16:06:52 -0500131 self.__fields = testCaseUtils.parse_fields(line, '|')
Gilles Depatie0bf31352019-02-04 13:48:41 -0500132 assert (self.check_states(self.__oltDeviceId) is True), 'States of %s does match expected ' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500133 portType = self.__fields[3].strip()
Gilles Depatieea423712019-04-12 16:39:12 -0400134 assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT' or portType == 'ETHERNET_UNI'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500135 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500136 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 Depatie0bf31352019-02-04 13:48:41 -0500142 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500143 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 Depatie0bf31352019-02-04 13:48:41 -0500147 statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' +
148 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500149 assert statusLines, 'No Onu device listed under ports'
150 lines = statusLines.splitlines()
151 for line in lines:
Gilles Depatie2e683692019-02-22 16:06:52 -0500152 self.__fields = testCaseUtils.parse_fields(line, '|')
Gilles Depatie0bf31352019-02-04 13:48:41 -0500153 assert (self.check_states(onuDeviceId) is True), 'States of %s does match expected ' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500154 portType = self.__fields[3].strip()
155 assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500156 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500157 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 Depatie0bf31352019-02-04 13:48:41 -0500162 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500163 assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId
164
Gilles Depatie0bf31352019-02-04 13:48:41 -0500165 def check_states(self, device_id):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500166 result = True
Gilles Depatieea423712019-04-12 16:39:12 -0400167 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 Depatie1be639b2018-12-06 10:51:08 -0500173 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 Depatie0bf31352019-02-04 13:48:41 -0500185 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' +
186 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500187 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 Depatieea423712019-04-12 16:39:12 -0400194def run_test(logical_device_type, olt_type, onu_type, onu_count, log_dir):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500195 discovery = Discovery()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500196 discovery.d_set_log_dirs(log_dir)
Gilles Depatieea423712019-04-12 16:39:12 -0400197 discovery.d_configure(logical_device_type, olt_type, onu_type, onu_count)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500198 discovery.olt_discovery()
199 discovery.onu_discovery()
200 discovery.logical_device()
Gilles Depatie82dd2022019-02-19 14:31:33 -0500201 discovery.logical_device_ports_should_exist()
202 discovery.logical_device_should_have_at_least_one_flow()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500203 discovery.olt_ports_should_be_enabled_and_active()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500204 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()