blob: 4dea0aba563f350b33e65850ce1224cd4b35d857 [file] [log] [blame]
Gilles Depatiec68b3ad2018-08-21 16:29:03 -04001#!/usr/bin/python2
2
3#
4# Copyright 2018 the original author or authors.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19"""
20vOLT-HA Automated Testing module
21"""
22import os
23import time
24import argparse
25import volthaMngr
Gilles Depatie84cb1e72018-10-26 12:41:33 -040026import preprovisioning
Gilles Depatie1be639b2018-12-06 10:51:08 -050027import discovery
Gilles Depatiea85fe812019-01-23 15:55:53 -050028import authentication
Gilles Depatie2e683692019-02-22 16:06:52 -050029import dhcp
Gilles Depatieed99efe2019-03-12 16:12:26 -040030import unicast
Gilles Depatie1be639b2018-12-06 10:51:08 -050031import logging
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040032
33DEFAULT_LOG_DIR = '/tmp/voltha_test_results'
Gilles Depatie493ea242019-05-21 14:38:08 -040034DEFAULT_SIMTYPE = 'ponsim'
Gilles Depatie1be639b2018-12-06 10:51:08 -050035logging.basicConfig(level=logging.INFO)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040036
Gilles Depatie0bf31352019-02-04 13:48:41 -050037
38def dir_init(log_dir=DEFAULT_LOG_DIR, voltha_dir=os.environ['VOLTHA_BASE']):
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040039 """
Gilles Depatieea423712019-04-12 16:39:12 -040040
41 :param log_dir: default log dir
42 :param voltha_dir: voltha base dir
43 :return: root_dir, voltha_dir, log_dir
44 """
45 logging.info(__file__)
46
47 """
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040048 Init automated testing environment and return three directories: root dir,
49 voltha sources dir and log dir
50 """
51
Gilles Depatie0bf31352019-02-04 13:48:41 -050052 root_dir = os.path.abspath(os.path.dirname(__file__))
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040053
54 currentTime = time.strftime("%Y-%m-%d-%H-%M-%S")
55
56 # In future in order to keep the history of jobs, the run time should be
57 # added to the log directory name
58 # logDir += '_' + currentTime
Gilles Depatiea85fe812019-01-23 15:55:53 -050059
Gilles Depatie0bf31352019-02-04 13:48:41 -050060 os.system('mkdir -p ' + log_dir + ' > /dev/null 2>&1')
61 os.system('rm -rf %s/*' % log_dir)
Gilles Depatiea85fe812019-01-23 15:55:53 -050062 logging.info('Starting Voltha Test Case Suite at: %s\nRoot Directory: %s\n'
Gilles Depatie0bf31352019-02-04 13:48:41 -050063 'VOLTHA Directory: %s\nLog Directory: %s' %
64 (currentTime, root_dir, voltha_dir, log_dir))
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040065
Gilles Depatie0bf31352019-02-04 13:48:41 -050066 return root_dir, voltha_dir, log_dir
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040067
68
Gilles Depatie493ea242019-05-21 14:38:08 -040069def simtype_init(simtype=DEFAULT_SIMTYPE):
Gilles Depatieea423712019-04-12 16:39:12 -040070 """
71
Gilles Depatie493ea242019-05-21 14:38:08 -040072 :param simtype: ponsim or bbsim
Gilles Depatieea423712019-04-12 16:39:12 -040073 :return: olt_type, onu_type, olt_host_ip, onu_count
74 """
Gilles Depatie493ea242019-05-21 14:38:08 -040075 if simtype == 'ponsim':
Gilles Depatieea423712019-04-12 16:39:12 -040076 olt_type = 'ponsim_olt'
77 onu_type = 'ponsim_onu'
78 olt_host_ip = 'olt.voltha.svc'
79 onu_count = 1
Gilles Depatie493ea242019-05-21 14:38:08 -040080 elif simtype == 'bbsim':
Gilles Depatieea423712019-04-12 16:39:12 -040081 olt_type = 'openolt'
82 onu_type = 'brcm_openomci_onu'
83 olt_host_ip = 'bbsim.voltha.svc'
84 onu_count = 16
85 else:
86 olt_type = None
87 onu_type = None
88 olt_host_ip = None
89 onu_count = 0
90
91 return olt_type, onu_type, olt_host_ip, onu_count
92
93
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040094#
95# MAIN
96#
97if __name__ == "__main__":
98 """
99 Main entry point of the automated testing when executed directly
100 """
101
102 parser = argparse.ArgumentParser(description='VOLTHA Automated Testing')
103 parser.add_argument('-l', dest='logDir', default=DEFAULT_LOG_DIR,
104 help='log directory (default: %s).' % DEFAULT_LOG_DIR)
Gilles Depatie493ea242019-05-21 14:38:08 -0400105 parser.add_argument('-a', dest='simtype', choices=['ponsim', 'bbsim'], default=DEFAULT_SIMTYPE,
106 help='simtype (default: %s).' % DEFAULT_SIMTYPE)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400107 args = parser.parse_args()
108
Gilles Depatiea85fe812019-01-23 15:55:53 -0500109 ROOT_DIR, VOLTHA_DIR, LOG_DIR = dir_init(args.logDir)
Gilles Depatie493ea242019-05-21 14:38:08 -0400110 OLT_TYPE, ONU_TYPE, OLT_HOST_IP, ONU_COUNT = simtype_init(args.simtype)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500111
Gilles Depatie493ea242019-05-21 14:38:08 -0400112 volthaMngr.voltha_initialize(ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.simtype)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400113
Gilles Depatieea423712019-04-12 16:39:12 -0400114 preprovisioning.run_test(OLT_HOST_IP, 50060, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
Gilles Depatiec9a26cf2019-05-10 15:43:12 -0400115
Gilles Depatieea423712019-04-12 16:39:12 -0400116 discovery.run_test(OLT_HOST_IP, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400117
Gilles Depatie493ea242019-05-21 14:38:08 -0400118 authentication.run_test(ONU_COUNT, ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.simtype)
119
120 if args.simtype == 'ponsim':
Gilles Depatieea423712019-04-12 16:39:12 -0400121 dhcp.run_test(ROOT_DIR, VOLTHA_DIR, LOG_DIR)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500122
Gilles Depatieea423712019-04-12 16:39:12 -0400123 unicast.run_test(ONU_TYPE, ONU_COUNT, ROOT_DIR, VOLTHA_DIR, LOG_DIR)