blob: 9b194087227e7f6478fe17a6ee9670db9b668071 [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
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
78def 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