blob: a0f3ef53382901292ee293e40ea3b99202336dc5 [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
21import time
22import os
23import commands
24import testCaseUtils
25import logging
26
27class Discovery(object):
28
29 """
30 This class implements voltha discovery test
31 """
32
33 def __init__(self):
34 self.dirs = {}
35 self.dirs ['log'] = None
36 self.dirs ['root'] = None
37 self.dirs ['voltha'] = None
Kailasha4d45742019-02-11 14:46:43 -080038
39 self.__logicalDeviceType = None
Gilles Depatie1be639b2018-12-06 10:51:08 -050040 self.__oltType = None
41 self.__onuType = None
42 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
48 def dSetLogDirs(self, logDir):
49 testCaseUtils.configDirs(self, logDir)
50
Kailasha4d45742019-02-11 14:46:43 -080051 def dConfigure(self, logicalDeviceType, oltType, onuType):
52 self.__logicalDeviceType = logicalDeviceType
Gilles Depatie1be639b2018-12-06 10:51:08 -050053 self.__oltType = oltType
54 self.__onuType = onuType
55
Kailasha4d45742019-02-11 14:46:43 -080056 def logicalDevice(self):
57 logging.info('Logical Device Info')
58 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__logicalDeviceType, 'voltha_devices_after_enable.log')
59 assert statusLines, 'No Logical Devices listed under devices'
60 self.__fields = testCaseUtils.parseFields(statusLines)
61 self.__logicalDeviceId = self.__fields[4].strip()
62 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
63 'voltha_logical_device.log', 'logical_device ' + self.__logicalDeviceId, 'voltha_logical_device_ports.log', 'ports', 'voltha_logical_device_flows.log', 'flows')
64 testCaseUtils.printLogFile (self, 'voltha_logical_device_ports.log')
65 testCaseUtils.printLogFile (self, 'voltha_logical_device_flows.log')
66
Gilles Depatie1be639b2018-12-06 10:51:08 -050067 def oltDiscovery(self):
68 logging.info('Olt Discovery')
69 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log')
70 assert statusLines, 'No Olt listed under devices'
71 self.__fields = testCaseUtils.parseFields(statusLines)
72 self.__oltDeviceId = self.__fields[1].strip()
73 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
74 'voltha_olt_device.log', 'device ' + self.__oltDeviceId, 'voltha_olt_ports.log', 'ports', 'voltha_olt_flows.log', 'flows')
75 testCaseUtils.printLogFile (self, 'voltha_olt_ports.log')
76 testCaseUtils.printLogFile (self, 'voltha_olt_flows.log')
77
78 def onuDiscovery(self):
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:
84 self.__fields = testCaseUtils.parseFields(line)
85 onuDeviceId = self.__fields[1].strip()
86 self.__onuDeviceIds.append(onuDeviceId)
87 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
88 'voltha_onu_device_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'device ' + onuDeviceId,
89 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'ports',
90 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'flows')
91 testCaseUtils.printLogFile (self, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
92 testCaseUtils.printLogFile (self, 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
93
94 def olt_ports_should_be_enabled_and_active(self):
95 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltDeviceId, 'voltha_olt_ports.log')
96 assert statusLines, 'No Olt device listed under ports'
97 lines = statusLines.splitlines()
98 for line in lines:
99 self.__fields = testCaseUtils.parseFields(line)
100 assert self.check_states(self.__oltDeviceId) == True, 'States of %s does match expected ' % self.__oltDeviceId
101 portType = self.__fields[3].strip()
102 assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT'),\
103 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId
104 if portType == 'PON_OLT':
105 self.__peers = self.__fields[7].strip()
106 peerFields = self.__peers.split(',')
107 peerDevices = peerFields[1::2]
108 for peerDevice in peerDevices:
109 deviceFields = peerDevice.split(':')
110 deviceId = deviceFields[1].replace("'","").replace('u','').rstrip("}]").strip()
111 assert deviceId in self.__onuDeviceIds, 'ONU Device %s not found as Peer' % deviceId
112
113 def onu_ports_should_be_enabled_and_active(self):
114 for onuDeviceId in self.__onuDeviceIds:
115 statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' + \
116 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
117 assert statusLines, 'No Onu device listed under ports'
118 lines = statusLines.splitlines()
119 for line in lines:
120 self.__fields = testCaseUtils.parseFields(line)
121 assert self.check_states(onuDeviceId) == True, 'States of %s does match expected ' % onuDeviceId
122 portType = self.__fields[3].strip()
123 assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\
124 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId
125 if portType == 'PON_ONU':
126 self.__peers = self.__fields[7].strip()
127 peerFields = self.__peers.split(',')
128 peerDevice = peerFields[1]
129 deviceFields = peerDevice.split(':')
130 deviceId = deviceFields[1].replace("'","").replace('u','').rstrip("}]").strip()
131 assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId
132
133
134 def check_states(self, deviceId):
135 result = True
136 adminState = self.__fields[4].strip()
137 assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % deviceId
138 operStatus = self.__fields[5].strip()
139 assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % deviceId
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:
152 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' + \
153 str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
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
Kailasha4d45742019-02-11 14:46:43 -0800161def runTest(logicalDeviceType, oltType, onuType, logDir):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500162 discovery = Discovery()
163 discovery.dSetLogDirs(logDir)
Kailasha4d45742019-02-11 14:46:43 -0800164 discovery.dConfigure(logicalDeviceType, oltType, onuType)
Gilles Depatie1be639b2018-12-06 10:51:08 -0500165 discovery.oltDiscovery()
166 discovery.onuDiscovery()
Kailasha4d45742019-02-11 14:46:43 -0800167 discovery.logicalDevice()
Gilles Depatie1be639b2018-12-06 10:51:08 -0500168 discovery.olt_ports_should_be_enabled_and_active()
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()