blob: e125dcfa9acc28338559ee7a55c9f71e4946a724 [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
23
Gilles Depatie0bf31352019-02-04 13:48:41 -050024
Gilles Depatie1be639b2018-12-06 10:51:08 -050025class Discovery(object):
26
27 """
28 This class implements voltha discovery test
29 """
30
31 def __init__(self):
Gilles Depatie0bf31352019-02-04 13:48:41 -050032 self.dirs = dict()
33 self.dirs['log'] = None
34 self.dirs['root'] = None
35 self.dirs['voltha'] = None
Kailasha4d45742019-02-11 14:46:43 -080036
37 self.__logicalDeviceType = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050038 self.__oltType = None
39 self.__onuType = None
40 self.__fields = []
Kailasha4d45742019-02-11 14:46:43 -080041 self.__logicalDeviceId = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050042 self.__oltDeviceId = None
43 self.__onuDeviceIds = []
44 self.__peers = None
45
Gilles Depatie0bf31352019-02-04 13:48:41 -050046 def d_set_log_dirs(self, log_dir):
47 testCaseUtils.config_dirs(self, log_dir)
Gilles Depatie1be639b2018-12-06 10:51:08 -050048
Gilles Depatie0bf31352019-02-04 13:48:41 -050049 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 Depatie1be639b2018-12-06 10:51:08 -050053
Gilles Depatie0bf31352019-02-04 13:48:41 -050054 def logical_device(self):
Kailasha4d45742019-02-11 14:46:43 -080055 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 Depatie0bf31352019-02-04 13:48:41 -050058 self.__fields = testCaseUtils.parse_fields(statusLines)
Kailasha4d45742019-02-11 14:46:43 -080059 self.__logicalDeviceId = self.__fields[4].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -050060 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')
Kailasha4d45742019-02-11 14:46:43 -080065
Gilles Depatie0bf31352019-02-04 13:48:41 -050066 def olt_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050067 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 Depatie0bf31352019-02-04 13:48:41 -050070 self.__fields = testCaseUtils.parse_fields(statusLines)
Gilles Depatie1be639b2018-12-06 10:51:08 -050071 self.__oltDeviceId = self.__fields[1].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -050072 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 Depatie1be639b2018-12-06 10:51:08 -050077
Gilles Depatie0bf31352019-02-04 13:48:41 -050078 def onu_discovery(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050079 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 Depatie0bf31352019-02-04 13:48:41 -050084 self.__fields = testCaseUtils.parse_fields(line)
Gilles Depatie1be639b2018-12-06 10:51:08 -050085 onuDeviceId = self.__fields[1].strip()
86 self.__onuDeviceIds.append(onuDeviceId)
Gilles Depatie0bf31352019-02-04 13:48:41 -050087 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 Depatie1be639b2018-12-06 10:51:08 -050094
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 Depatie0bf31352019-02-04 13:48:41 -0500100 self.__fields = testCaseUtils.parse_fields(line)
101 assert (self.check_states(self.__oltDeviceId) is True), 'States of %s does match expected ' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500102 portType = self.__fields[3].strip()
103 assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500104 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500105 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 Depatie0bf31352019-02-04 13:48:41 -0500111 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500112 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 Depatie0bf31352019-02-04 13:48:41 -0500116 statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' +
117 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500118 assert statusLines, 'No Onu device listed under ports'
119 lines = statusLines.splitlines()
120 for line in lines:
Gilles Depatie0bf31352019-02-04 13:48:41 -0500121 self.__fields = testCaseUtils.parse_fields(line)
122 assert (self.check_states(onuDeviceId) is True), 'States of %s does match expected ' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500123 portType = self.__fields[3].strip()
124 assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\
Gilles Depatie0bf31352019-02-04 13:48:41 -0500125 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId
Gilles Depatie1be639b2018-12-06 10:51:08 -0500126 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 Depatie0bf31352019-02-04 13:48:41 -0500131 deviceId = deviceFields[1].replace("'", "").replace('u', '').rstrip("}]").strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500132 assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId
133
Gilles Depatie0bf31352019-02-04 13:48:41 -0500134 def check_states(self, device_id):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500135 result = True
136 adminState = self.__fields[4].strip()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500137 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 Depatie1be639b2018-12-06 10:51:08 -0500140 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 Depatie0bf31352019-02-04 13:48:41 -0500152 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' +
153 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
Gilles Depatie1be639b2018-12-06 10:51:08 -0500154 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 Depatie0bf31352019-02-04 13:48:41 -0500161def run_test(logical_device_type, olt_type, onu_type, log_dir):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500162 discovery = Discovery()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500163 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 Depatie1be639b2018-12-06 10:51:08 -0500169 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()