blob: 81cfd8a4c875acc46ceb1c226fae82acfeec8f2a [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
22import os
23import commands
24import testCaseUtils
Gilles Depatie1be639b2018-12-06 10:51:08 -050025import logging
Gilles Depatie84cb1e72018-10-26 12:41:33 -040026
27class Preprovisioning(object):
28
29 """
30 This class implements voltha pre-provisioning 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
38
39 self.__oltIpAddress = None
40 self.__oltPort = None
Gilles Depatie9651e462018-11-21 15:58:33 -050041 self.__oltType = None
42 self.__onuType = 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
46 def pSetLogDirs(self, logDir):
47 testCaseUtils.configDirs(self, logDir)
48
Gilles Depatie1be639b2018-12-06 10:51:08 -050049 def pConfigure(self, oltIpAddress, oltPort, oltType, onuType):
Gilles Depatie84cb1e72018-10-26 12:41:33 -040050 self.__oltIpAddress = oltIpAddress
51 self.__oltPort = oltPort
Gilles Depatie9651e462018-11-21 15:58:33 -050052 self.__oltType = oltType
53 self.__onuType = onuType
Gilles Depatie84cb1e72018-10-26 12:41:33 -040054
55 def preprovisionOlt(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050056 logging.info('Do PROVISIONING')
Gilles Depatie84cb1e72018-10-26 12:41:33 -040057 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
Gilles Depatie1be639b2018-12-06 10:51:08 -050058 'voltha_preprovision_olt.log', 'preprovision_olt -t ponsim_olt -H %s:%s' %
59 (self.__oltIpAddress, self.__oltPort))
Gilles Depatie84cb1e72018-10-26 12:41:33 -040060 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050061
62 def status_should_be_success_after_preprovision_command(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050063 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log')
64 assert statusLines, 'Preprovision Olt command should have returned success but did not'
Gilles Depatie9651e462018-11-21 15:58:33 -050065
66 def query_devices_before_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050067 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
68 'voltha_devices_before_enable.log', 'devices')
69 testCaseUtils.printLogFile (self, 'voltha_devices_before_enable.log')
Gilles Depatie84cb1e72018-10-26 12:41:33 -040070 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050071
72 def check_olt_fields_before_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050073 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log')
74 assert statusLines, 'No Olt listed under devices'
75 self.__fields = testCaseUtils.parseFields(statusLines)
Gilles Depatie84cb1e72018-10-26 12:41:33 -040076 self.__oltDeviceId = self.__fields[1].strip()
Gilles Depatie1be639b2018-12-06 10:51:08 -050077 logging.debug("OLT device id = %s" % self.__oltDeviceId)
Gilles Depatie9651e462018-11-21 15:58:33 -050078 adminState = self.__fields[3].strip()
79 assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED'
80 hostPort = self.__fields[4].strip()
81 assert hostPort, 'hostPort field is empty'
82 hostPortFields = hostPort.split(":")
83 assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
84 'Olt IP or Port does not match'
85
86 def check_states(self, devType):
87 result = True
88 adminState = self.__fields[7].strip()
89 assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % devType
90 operStatus = self.__fields[8].strip()
91 assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % devType
92 connectStatus = self.__fields[9].strip()
93 assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % devType
94 return result
95
96 def check_olt_fields_after_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -050097 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log')
98 assert statusLines, 'No Olt listed under devices'
99 self.__fields = testCaseUtils.parseFields(statusLines)
Gilles Depatie9651e462018-11-21 15:58:33 -0500100 assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType
101 hostPort = self.__fields[11].strip()
102 assert hostPort, 'hostPort field is empty'
103 hostPortFields = hostPort.split(":")
104 assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
105 'Olt IP or Port does not match'
106
107 def check_onu_fields_after_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500108 statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log')
109 assert statusLines, 'No Onu listed under devices'
110 lines = statusLines.splitlines()
Gilles Depatie9651e462018-11-21 15:58:33 -0500111 lenLines = len(lines)
112 assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines
113 for line in lines:
114 self.__fields = testCaseUtils.parseFields(line)
115 assert self.check_states(self.__onuType) == True, 'States of %s does match expected' % self.__onuType
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400116
117 def enable(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500118 logging.info('Enable %s OLT device' % self.__oltDeviceId)
119 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
120 'voltha_enable.log', 'enable ' + self.__oltDeviceId)
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400121
Gilles Depatie9651e462018-11-21 15:58:33 -0500122 def status_should_be_success_after_enable_command(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500123 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log')
124 assert statusLines, 'Enable command should have returned success but did not'
Gilles Depatie9651e462018-11-21 15:58:33 -0500125
126 def query_devices_after_enabling(self):
Gilles Depatie1be639b2018-12-06 10:51:08 -0500127 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
128 'voltha_devices_after_enable.log', 'devices')
129 testCaseUtils.printLogFile (self, 'voltha_devices_after_enable.log')
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400130
Gilles Depatie9651e462018-11-21 15:58:33 -0500131def runTest(oltIpAddress, oltPort, oltType, onuType, logDir):
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400132 preprovisioning = Preprovisioning()
133 preprovisioning.pSetLogDirs(logDir)
Gilles Depatie1be639b2018-12-06 10:51:08 -0500134 preprovisioning.pConfigure(oltIpAddress, oltPort, oltType, onuType)
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400135 preprovisioning.preprovisionOlt()
Gilles Depatie9651e462018-11-21 15:58:33 -0500136 preprovisioning.status_should_be_success_after_preprovision_command()
137 preprovisioning.query_devices_before_enabling()
138 preprovisioning.check_olt_fields_before_enabling()
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400139 preprovisioning.enable()
Gilles Depatie9651e462018-11-21 15:58:33 -0500140 preprovisioning.status_should_be_success_after_enable_command()
141 preprovisioning.query_devices_after_enabling()
142 preprovisioning.check_olt_fields_after_enabling()
143 preprovisioning.check_onu_fields_after_enabling()
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400144
145
146