blob: 86c2048c31f1bf9d938a595a9d7d91efa8f8b637 [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"""
18vOLT-HA Pre-provisioning Test module
19"""
20
21import time
22import os
23import commands
24import testCaseUtils
25
26class Preprovisioning(object):
27
28 """
29 This class implements voltha pre-provisioning test
30 """
31
32 def __init__(self):
33 self.dirs = {}
34 self.dirs ['log'] = None
35 self.dirs ['root'] = None
36 self.dirs ['voltha'] = None
37
38 self.__oltIpAddress = None
39 self.__oltPort = None
Gilles Depatie9651e462018-11-21 15:58:33 -050040 self.__oltType = None
41 self.__onuType = None
42 self.__statusLines = ""
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 Depatie9651e462018-11-21 15:58:33 -050049 def configure(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
Gilles Depatie9651e462018-11-21 15:58:33 -050055 def get_fields_from_grep_command(self, searchWord, logFile):
56 grepCommand =\
57 "grep %s %s/%s" % (searchWord, testCaseUtils.getDir(self, 'log'), logFile)
58 self.__statusLines = commands.getstatusoutput(grepCommand)[1]
59
Gilles Depatie84cb1e72018-10-26 12:41:33 -040060 def preprovisionOlt(self):
61 print('Do PROVISIONING')
62 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'),
63 'preprovision_olt -t ponsim_olt -H %s:%s' %
64 (self.__oltIpAddress, self.__oltPort),
65 'voltha_preprovision_olt.log')
66 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050067
68 def status_should_be_success_after_preprovision_command(self):
69 self.get_fields_from_grep_command('success', 'voltha_preprovision_olt.log')
70 assert self.__statusLines, 'Preprovision Olt command should have returned success but did not'
71
72 def query_devices_before_enabling(self):
Gilles Depatie84cb1e72018-10-26 12:41:33 -040073 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices',
74 'voltha_devices_before_enable.log')
75 time.sleep(5)
Gilles Depatie9651e462018-11-21 15:58:33 -050076
77 def check_olt_fields_before_enabling(self):
78 result = True
79 self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_before_enable.log')
80 assert self.__statusLines, 'No Olt listed under devices'
81 self.__fields = testCaseUtils.parseFields(self.__statusLines)
Gilles Depatie84cb1e72018-10-26 12:41:33 -040082 self.__oltDeviceId = self.__fields[1].strip()
83 print ("OLT device id = %s" % self.__oltDeviceId)
Gilles Depatie9651e462018-11-21 15:58:33 -050084 adminState = self.__fields[3].strip()
85 assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED'
86 hostPort = self.__fields[4].strip()
87 assert hostPort, 'hostPort field is empty'
88 hostPortFields = hostPort.split(":")
89 assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
90 'Olt IP or Port does not match'
91
92 def check_states(self, devType):
93 result = True
94 adminState = self.__fields[7].strip()
95 assert adminState == 'ENABLED', 'Admin State of %s not ENABLED' % devType
96 operStatus = self.__fields[8].strip()
97 assert operStatus == 'ACTIVE', 'Oper Status of %s not ACTIVE' % devType
98 connectStatus = self.__fields[9].strip()
99 assert connectStatus == 'REACHABLE', 'Connect Status of %s not REACHABLE' % devType
100 return result
101
102 def check_olt_fields_after_enabling(self):
103 self.get_fields_from_grep_command(self.__oltType, 'voltha_devices_after_enable.log')
104 assert self.__statusLines, 'No Olt listed under devices'
105 self.__fields = testCaseUtils.parseFields(self.__statusLines)
106 assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType
107 hostPort = self.__fields[11].strip()
108 assert hostPort, 'hostPort field is empty'
109 hostPortFields = hostPort.split(":")
110 assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \
111 'Olt IP or Port does not match'
112
113 def check_onu_fields_after_enabling(self):
114 self.get_fields_from_grep_command(self.__onuType, 'voltha_devices_after_enable.log')
115 assert self.__statusLines, 'No Onu listed under devices'
116 lines = self.__statusLines.splitlines()
117 lenLines = len(lines)
118 assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines
119 for line in lines:
120 self.__fields = testCaseUtils.parseFields(line)
121 assert self.check_states(self.__onuType) == True, 'States of %s does match expected' % self.__onuType
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400122
123 def enable(self):
124 print('Enable %s OLT device' % self.__oltDeviceId)
125 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'enable ' + self.__oltDeviceId,
126 'voltha_enable.log')
127
Gilles Depatie9651e462018-11-21 15:58:33 -0500128 def status_should_be_success_after_enable_command(self):
129 self.get_fields_from_grep_command('success', 'voltha_enable.log')
130 assert self.__statusLines, 'Enable command should have returned success but did not'
131
132 def query_devices_after_enabling(self):
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400133 testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices',
134 'voltha_devices_after_enable.log')
135
Gilles Depatie9651e462018-11-21 15:58:33 -0500136def runTest(oltIpAddress, oltPort, oltType, onuType, logDir):
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400137 preprovisioning = Preprovisioning()
138 preprovisioning.pSetLogDirs(logDir)
Gilles Depatie9651e462018-11-21 15:58:33 -0500139 preprovisioning.configure(oltIpAddress, oltPort, oltType, onuType)
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400140 preprovisioning.preprovisionOlt()
Gilles Depatie9651e462018-11-21 15:58:33 -0500141 preprovisioning.status_should_be_success_after_preprovision_command()
142 preprovisioning.query_devices_before_enabling()
143 preprovisioning.check_olt_fields_before_enabling()
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400144 preprovisioning.enable()
Gilles Depatie9651e462018-11-21 15:58:33 -0500145 preprovisioning.status_should_be_success_after_enable_command()
146 preprovisioning.query_devices_after_enabling()
147 preprovisioning.check_olt_fields_after_enabling()
148 preprovisioning.check_onu_fields_after_enabling()
Gilles Depatie84cb1e72018-10-26 12:41:33 -0400149
150
151