Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 1 | # |
| 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 | """ |
| 18 | vOLT-HA Pre-provisioning Test module |
| 19 | """ |
| 20 | |
| 21 | import time |
| 22 | import os |
| 23 | import commands |
| 24 | import testCaseUtils |
| 25 | |
| 26 | class 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 |
| 40 | self.__statusLine = "" |
| 41 | self.__fields = [] |
| 42 | |
| 43 | def pSetLogDirs(self, logDir): |
| 44 | testCaseUtils.configDirs(self, logDir) |
| 45 | |
| 46 | def configure(self, oltIpAddress, oltPort): |
| 47 | self.__oltIpAddress = oltIpAddress |
| 48 | self.__oltPort = oltPort |
| 49 | |
| 50 | def preprovisionOlt(self): |
| 51 | print('Do PROVISIONING') |
| 52 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), |
| 53 | 'preprovision_olt -t ponsim_olt -H %s:%s' % |
| 54 | (self.__oltIpAddress, self.__oltPort), |
| 55 | 'voltha_preprovision_olt.log') |
| 56 | time.sleep(5) |
| 57 | |
| 58 | def query_devices_before_enable(self): |
| 59 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices', |
| 60 | 'voltha_devices_before_enable.log') |
| 61 | time.sleep(5) |
| 62 | grepCommand =\ |
| 63 | "grep PREPROVISIONED %s/voltha_devices_before_enable.log " % testCaseUtils.getDir(self, 'log') |
| 64 | self.__statusLine = commands.getstatusoutput(grepCommand)[1] |
| 65 | self.__fields = testCaseUtils.parseFields(self.__statusLine) |
| 66 | self.__oltDeviceId = self.__fields[1].strip() |
| 67 | print ("OLT device id = %s" % self.__oltDeviceId) |
| 68 | |
| 69 | def enable(self): |
| 70 | print('Enable %s OLT device' % self.__oltDeviceId) |
| 71 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'enable ' + self.__oltDeviceId, |
| 72 | 'voltha_enable.log') |
| 73 | |
| 74 | def query_devices_after_enable(self): |
| 75 | testCaseUtils.send_command_to_voltha_cli(testCaseUtils.getDir(self, 'log'), 'devices', |
| 76 | 'voltha_devices_after_enable.log') |
| 77 | |
| 78 | def runTest(oltIpAddress, oltPort, logDir): |
| 79 | preprovisioning = Preprovisioning() |
| 80 | preprovisioning.pSetLogDirs(logDir) |
| 81 | preprovisioning.configure(str(oltIpAddress), int(oltPort)) |
| 82 | preprovisioning.preprovisionOlt() |
| 83 | preprovisioning.query_devices_before_enable() |
| 84 | preprovisioning.enable() |
| 85 | preprovisioning.query_devices_after_enable() |
| 86 | |
| 87 | |
| 88 | |
| 89 | |