blob: 2b077c91105a519db54649067549313623959af6 [file] [log] [blame]
Gilles Depatie84cb1e72018-10-26 12:41:33 -04001#
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"""
Gilles Depatie1be639b2018-12-06 10:51:08 -050018vOLT-HA Pre-provisioning Test Case module
Gilles Depatie84cb1e72018-10-26 12:41:33 -040019"""
20
21import time
Gilles Depatie84cb1e72018-10-26 12:41:33 -040022import testCaseUtils
Gilles Depatie1be639b2018-12-06 10:51:08 -050023import logging
Gilles Depatie84cb1e72018-10-26 12:41:33 -040024
Gilles Depatie0bf31352019-02-04 13:48:41 -050025
Gilles Depatie84cb1e72018-10-26 12:41:33 -040026class Preprovisioning(object):
27
28 """
29 This class implements voltha pre-provisioning test
30 """
Gilles Depatiec9a26cf2019-05-10 15:43:12 -040031
Gilles Depatie84cb1e72018-10-26 12:41:33 -040032 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
Gilles Depatie84cb1e72018-10-26 12:41:33 -040037
38 self.__oltIpAddress = None
39 self.__oltPort = None
Gilles Depatie9651e462018-11-21 15:58:33 -050040 self.__oltType = None
41 self.__onuType = None
Gilles Depatieea423712019-04-12 16:39:12 -040042 self.__onuCount = None
Gilles Depatie84cb1e72018-10-26 12:41:33 -040043 self.__fields = []
Gilles Depatie9651e462018-11-21 15:58:33 -050044 self.__oltDeviceId = None
Gilles Depatie84cb1e72018-10-26 12:41:33 -040045
Gilles Depatie0bf31352019-02-04 13:48:41 -050046 def p_set_log_dirs(self, log_dir):
47 testCaseUtils.config_dirs(self, log_dir)
Gilles Depatie84cb1e72018-10-26 12:41:33 -040048
Gilles Depatieea423712019-04-12 16:39:12 -040049 def p_configure(self, olt_ip_address, olt_port, olt_type, onu_type, onu_count):
Gilles Depatie0bf31352019-02-04 13:48:41 -050050 self.__oltIpAddress = olt_ip_address
51 self.__oltPort = olt_port
52 self.__oltType = olt_type
53 self.__onuType = onu_type
Gilles Depatieea423712019-04-12 16:39:12 -040054 self.__onuCount = onu_count
Gilles Depatie84cb1e72018-10-26 12:41:33 -040055
Gilles Depatie0bf31352019-02-04 13:48:41 -050056 def preprovision_olt(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050057 logging.info('Do PROVISIONING')
Gilles Depatie0bf31352019-02-04 13:48:41 -050058 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'),
Gilles Depatieea423712019-04-12 16:39:12 -040059 'voltha_preprovision_olt.log', 'preprovision_olt -t %s -H %s:%s' %
60 (self.__oltType, self.__oltIpAddress, self.__oltPort))
Gilles Depatie84cb1e72018-10-26 12:41:33 -040061 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050062
63 def status_should_be_success_after_preprovision_command(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050064 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log')
65 assert statusLines, 'Preprovision Olt command should have returned success but did not'
Gilles Depatie9651e462018-11-21 15:58:33 -050066
67 def query_devices_before_enabling(self):
Gilles Depatie0bf31352019-02-04 13:48:41 -050068 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'),
69 'voltha_devices_before_enable.log', 'devices')
70 testCaseUtils.print_log_file(self, 'voltha_devices_before_enable.log')
Gilles Depatie84cb1e72018-10-26 12:41:33 -040071 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050072
73 def check_olt_fields_before_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050074 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log')
75 assert statusLines, 'No Olt listed under devices'
Gilles Depatie2e683692019-02-22 16:06:52 -050076 self.__fields = testCaseUtils.parse_fields(statusLines, '|')
Gilles Depatie84cb1e72018-10-26 12:41:33 -040077 self.__oltDeviceId = self.__fields[1].strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -050078 logging.debug("OLT device id = %s" % self.__oltDeviceId)
Gilles Depatie9651e462018-11-21 15:58:33 -050079 adminState = self.__fields[3].strip()
80 assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED'
81 hostPort = self.__fields[4].strip()
82 assert hostPort, 'hostPort field is empty'
83 hostPortFields = hostPort.split(":")
84 assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
85 'Olt IP or Port does not match'
86
Gilles Depatie0bf31352019-02-04 13:48:41 -050087 def check_states(self, dev_type):
Gilles Depatie9651e462018-11-21 15:58:33 -050088 result = True
Gilles Depatieea423712019-04-12 16:39:12 -040089 stateMatchCount = 0
90 for field in self.__fields:
91 field_no_space = field.strip()
92 if field_no_space == 'ENABLED' or field_no_space == 'ACTIVE' or field_no_space == 'DISCOVERED' or field_no_space == 'REACHABLE':
93 stateMatchCount += 1
94 assert stateMatchCount == 3, 'State of %s is not ENABLED, ACTIVE or DISCOVERED and REACHABLE' % dev_type
Gilles Depatie9651e462018-11-21 15:58:33 -050095 return result
96
97 def check_olt_fields_after_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050098 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 Depatie9651e462018-11-21 15:58:33 -0500101 assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType
Gilles Depatiec9a26cf2019-05-10 15:43:12 -0400102 hostPortCount = False
Gilles Depatieea423712019-04-12 16:39:12 -0400103 for field in self.__fields:
104 if field.strip() == self.__oltIpAddress + ':' + str(self.__oltPort):
105 hostPortCount = True
106 assert hostPortCount, 'hostPort field is empty or Olt IP and/or Port does not match'
107
Gilles Depatie9651e462018-11-21 15:58:33 -0500108 def check_onu_fields_after_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500109 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log')
110 assert statusLines, 'No Onu listed under devices'
111 lines = statusLines.splitlines()
Gilles Depatie9651e462018-11-21 15:58:33 -0500112 lenLines = len(lines)
Gilles Depatieea423712019-04-12 16:39:12 -0400113 assert lenLines == self.__onuCount, ' Discovered onu(s) does not match, ONU Count was %d' % lenLines
Gilles Depatie9651e462018-11-21 15:58:33 -0500114 for line in lines:
Gilles Depatie2e683692019-02-22 16:06:52 -0500115 self.__fields = testCaseUtils.parse_fields(line, '|')
Gilles Depatie0bf31352019-02-04 13:48:41 -0500116 assert (self.check_states(self.__onuType) is True), 'States of %s does match expected' % self.__onuType
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400117
118 def enable(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500119 logging.info('Enable %s OLT device' % self.__oltDeviceId)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500120 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'),
121 'voltha_enable.log', 'enable ' + self.__oltDeviceId)
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400122
Gilles Depatie9651e462018-11-21 15:58:33 -0500123 def status_should_be_success_after_enable_command(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500124 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log')
125 assert statusLines, 'Enable command should have returned success but did not'
Gilles Depatie9651e462018-11-21 15:58:33 -0500126
127 def query_devices_after_enabling(self):
Gilles Depatie0bf31352019-02-04 13:48:41 -0500128 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'),
129 'voltha_devices_after_enable.log', 'devices')
130 testCaseUtils.print_log_file(self, 'voltha_devices_after_enable.log')
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400131
Gilles Depatiec9a26cf2019-05-10 15:43:12 -0400132 def proceed(self):
133 logging.info('Pre-provisioning hold')
134 onuOnline = 0
135 portType = None
136 if self.__oltType == 'ponsim_olt':
137 portType = 'PON_OLT'
138 elif self.__oltType == 'openolt':
139 portType = 'ETHERNET_UNI'
140 while onuOnline < self.__onuCount:
141 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), 'voltha_olt_device.log', 'device ' +
142 self.__oltDeviceId, 'voltha_olt_ports.log', 'ports')
143 statusLines = testCaseUtils.get_fields_from_grep_command(self, portType, 'voltha_olt_ports.log')
144 lines = statusLines.splitlines()
145 onuOnline = len(lines)
146 time.sleep(5)
147 logging.info('All ONUs now Online!')
148
Gilles Depatie0bf31352019-02-04 13:48:41 -0500149
Gilles Depatieea423712019-04-12 16:39:12 -0400150def run_test(olt_ip_address, olt_port, olt_type, onu_type, onu_count, log_dir):
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400151 preprovisioning = Preprovisioning()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500152 preprovisioning.p_set_log_dirs(log_dir)
Gilles Depatieea423712019-04-12 16:39:12 -0400153 preprovisioning.p_configure(olt_ip_address, olt_port, olt_type, onu_type, onu_count)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500154 preprovisioning.preprovision_olt()
Gilles Depatie9651e462018-11-21 15:58:33 -0500155 preprovisioning.status_should_be_success_after_preprovision_command()
156 preprovisioning.query_devices_before_enabling()
157 preprovisioning.check_olt_fields_before_enabling()
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400158 preprovisioning.enable()
Gilles Depatie9651e462018-11-21 15:58:33 -0500159 preprovisioning.status_should_be_success_after_enable_command()
160 preprovisioning.query_devices_after_enabling()
161 preprovisioning.check_olt_fields_after_enabling()
162 preprovisioning.check_onu_fields_after_enabling()
Gilles Depatiec9a26cf2019-05-10 15:43:12 -0400163 preprovisioning.proceed()