blob: a8bbe3ef5539c66db538f61701739616d03a11e4 [file] [log] [blame]
Gilles Depatiec68b3ad2018-08-21 16:29:03 -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
24
25
26class preprovisioningTest(object):
27
28 """
29 This class implements voltha pre-provisioning test
30 """
31
32 def __init__(self):
33 self.__oltIpAddress = None
34 self.__oltPort = None
35 self.__logDir = None
36 self.__oltDeviceId = None
37 self.__statusLine = ""
38 self.__fields = []
39
40 def configure(self, oltIpAddress, oltPort, logDir):
41 self.__oltIpAddress = oltIpAddress
42 self.__oltPort = oltPort
43 self.__logDir = logDir
44
45
46 def preprovisionOlt(self):
47 print('Do PROVISIONING')
48 self.send_command_to_voltha_cli(
49 'preprovision_olt -t ponsim_olt -H %s:%s' %
50 (self.__oltIpAddress, self.__oltPort),
51 'voltha_preprovision_olt.log')
52 time.sleep(5)
53
54 def query_devices_before_enable(self):
55 self.send_command_to_voltha_cli('devices',
56 'voltha_devices_before_enable.log')
57 time.sleep(5)
58 grepCommand =\
59 "grep PREPROVISIONED %s/voltha_devices_before_enable.log " % self.__logDir
60 self.__statusLine = commands.getstatusoutput(grepCommand)[1]
61 self.__fields = self.parseFields(self.__statusLine)
62 self.__oltDeviceId = self.__fields[1].strip()
63 print ("OLT device id = %s" % self.__oltDeviceId)
64
65 def enable(self):
66 print('Enable %s OLT device' % self.__oltDeviceId)
67 self.send_command_to_voltha_cli('enable ' + self.__oltDeviceId,
68 'voltha_enable.log')
69 def query_devices_after_enable(self):
70 self.send_command_to_voltha_cli('devices',
71 'voltha_devices_after_enable.log')
72
73 def send_command_to_voltha_cli(self, cmd, logFile):
74 # os.system("docker exec -i -t compose_cli_1 sh -c 'echo \"" + cmd +
75 # "\" > /voltha_tmp_command.txt'")
76 os.system("docker exec compose_cli_1 sh -c 'echo \"" + cmd +
77 "\" > /voltha_tmp_command.txt'")
78 os.system("docker exec compose_cli_1 sh -c '/cli/cli/main.py -C "
79 "vconsul:8500 -L < /voltha_tmp_command.txt' > " +
80 self.__logDir + '/' + logFile)
81
82 def send_command_to_onos_cli(self, cmd, logFile):
83 os.system(
84 "sshpass -p karaf ssh -o StrictHostKeyChecking=no -p 8101 "
85 "karaf@localhost " + cmd + " 2>/dev/null > " +
86 self.__logDir + '/' + logFile)
87
88 def parseFields(self, statusLine):
89 statusList = statusLine.split("|")
90 return statusList
91
92
93
94def runTest(oltIpAddress, oltPort, logDir):
95 preprovisioning = preprovisioningTest()
96 preprovisioning.configure(str(oltIpAddress), int(oltPort),
97 str(logDir))
98 preprovisioning.preprovisionOlt()
99 preprovisioning.query_devices_before_enable()
100 preprovisioning.enable()
101 preprovisioning.query_devices_after_enable()
102
103
104
105