blob: fb57a2250c9ebdfc87bb66ba67760a8cc2ba0e85 [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
41 self.__fields = []
Kailasha4d45742019-02-11 14:46:43 -080042 self.__logicalDeviceId = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050043 self.__oltDeviceId = None
44 self.__onuDeviceIds = []
45 self.__peers = None
46
Gilles Depatie0bf31352019-02-04 13:48:41 -050047 def d_set_log_dirs(self, log_dir):
48 testCaseUtils.config_dirs(self, log_dir)
Gilles Depatie1be639b2018-12-06 10:51:08 -050049
Gilles Depatie0bf31352019-02-04 13:48:41 -050050 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 Depatie1be639b2018-12-06 10:51:08 -050054
Gilles Depatie0bf31352019-02-04 13:48:41 -050055 def logical_device(self):
Kailasha4d45742019-02-11 14:46:43 -080056 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 Depatie0bf31352019-02-04 13:48:41 -050059 self.__fields = testCaseUtils.parse_fields(statusLines)
Kailasha4d45742019-02-11 14:46:43 -080060 self.__logicalDeviceId = self.__fields[4].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -050061 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 Depatie82dd2022019-02-19 14:31:33 -050064 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 Depatie0bf31352019-02-04 13:48:41 -050067 testCaseUtils.print_log_file(self, 'voltha_logical_device_ports.log')
68 testCaseUtils.print_log_file(self, 'voltha_logical_device_flows.log')
Kailasha4d45742019-02-11 14:46:43 -080069
Gilles Depatie82dd2022019-02-19 14:31:33 -050070 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 Depatie0bf31352019-02-04 13:48:41 -050093 def olt_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050094 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 Depatie0bf31352019-02-04 13:48:41 -050097 self.__fields = testCaseUtils.parse_fields(statusLines)
Gilles Depatie1be639b2018-12-06 10:51:08 -050098 self.__oltDeviceId = self.__fields[1].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -050099 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 Depatie1be639b2018-12-06 10:51:08 -0500104
Gilles Depatie0bf31352019-02-04 13:48:41 -0500105 def onu_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500106 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 Depatie0bf31352019-02-04 13:48:41 -0500111 self.__fields = testCaseUtils.parse_fields(line)
Gilles Depatie1be639b2018-12-06 10:51:08 -0500112 onuDeviceId = self.__fields[1].strip()
113 self.__onuDeviceIds.append(onuDeviceId)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500114 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 Depatie1be639b2018-12-06 10:51:08 -0500121
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 Depatie0bf31352019-02-04 13:48:41 -0500127 self.__fields = testCaseUtils.parse_fields(line)
128 assert (self.check_states(self.__oltDeviceId) is True), 'States of %s does match expected ' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500129 portType = self.__fields[3].strip()
130 assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500131 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500132 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 Depatie0bf31352019-02-04 13:48:41 -0500138 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500139 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 Depatie0bf31352019-02-04 13:48:41 -0500143 statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' +
144 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500145 assert statusLines, 'No Onu device listed under ports'
146 lines = statusLines.splitlines()
147 for line in lines:
Gilles Depatie0bf31352019-02-04 13:48:41 -0500148 self.__fields = testCaseUtils.parse_fields(line)
149 assert (self.check_states(onuDeviceId) is True), 'States of %s does match expected ' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500150 portType = self.__fields[3].strip()
151 assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500152 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500153 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 Depatie0bf31352019-02-04 13:48:41 -0500158 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500159 assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId
160
Gilles Depatie0bf31352019-02-04 13:48:41 -0500161 def check_states(self, device_id):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500162 result = True
163 adminState = self.__fields[4].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500164 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 Depatie1be639b2018-12-06 10:51:08 -0500167 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 Depatie0bf31352019-02-04 13:48:41 -0500179 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' +
180 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500181 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 Depatie0bf31352019-02-04 13:48:41 -0500188def run_test(logical_device_type, olt_type, onu_type, log_dir):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500189 discovery = Discovery()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500190 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 Depatie82dd2022019-02-19 14:31:33 -0500195 discovery.logical_device_ports_should_exist()
196 discovery.logical_device_should_have_at_least_one_flow()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500197 discovery.olt_ports_should_be_enabled_and_active()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500198 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()