blob: a03f17ed5777970bb9a8a6b4332c01de8dd06a70 [file] [log] [blame]
Gilles Depatiea85fe812019-01-23 15:55:53 -05001#
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 Authentication Test Case module
19"""
20
21import time
Gilles Depatiea85fe812019-01-23 15:55:53 -050022import subprocess
Gilles Depatiea85fe812019-01-23 15:55:53 -050023import testCaseUtils
24import logging
Gilles Depatie0bf31352019-02-04 13:48:41 -050025
Gilles Depatiea85fe812019-01-23 15:55:53 -050026
27class Authentication(object):
28
29 """
30 This class implements voltha authentication test case
31 """
32 AUTHENTICATE_FILENAME = 'voltha_authenticate.log'
33
34 def __init__(self):
Gilles Depatie0bf31352019-02-04 13:48:41 -050035 self.dirs = dict()
36 self.dirs['log'] = None
37 self.dirs['root'] = None
38 self.dirs['voltha'] = None
Gilles Depatie493ea242019-05-21 14:38:08 -040039
40 self.__onuCount = None
Gilles Depatieed99efe2019-03-12 16:12:26 -040041 self.__rgName = testCaseUtils.discover_rg_pod_name()
Gilles Depatie493ea242019-05-21 14:38:08 -040042
Gilles Depatie0bf31352019-02-04 13:48:41 -050043 def a_set_log_dirs(self, root_dir, voltha_dir, log_dir):
44 testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir)
Gilles Depatiea85fe812019-01-23 15:55:53 -050045
Gilles Depatie493ea242019-05-21 14:38:08 -040046 def a_configure(self, onu_count):
47 self.__onuCount = onu_count
48
Gilles Depatie0bf31352019-02-04 13:48:41 -050049 def execute_authentication_on_rg(self):
50 logging.info('Running Radius Authentication from RG')
51 process_output = open('%s/%s' % (testCaseUtils.get_dir(self, 'log'), self.AUTHENTICATE_FILENAME), 'w')
52 proc1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'bash', '-c',
Gilles Depatiea85fe812019-01-23 15:55:53 -050053 '/sbin/wpa_supplicant -Dwired -ieth0 -c /etc/wpa_supplicant/wpa_supplicant.conf'],
54 stdout=process_output,
55 stderr=process_output)
Gilles Depatie0bf31352019-02-04 13:48:41 -050056
Gilles Depatiea85fe812019-01-23 15:55:53 -050057 time.sleep(15)
Gilles Depatie0bf31352019-02-04 13:48:41 -050058 logging.debug('return value from supplicant subprocess = %s' % proc1.returncode)
Gilles Depatiea85fe812019-01-23 15:55:53 -050059 procPidSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
Gilles Depatie0bf31352019-02-04 13:48:41 -050060 stdout=subprocess.PIPE,
61 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050062 procPidSupplicant2 = subprocess.Popen(['grep', '-e', '/sbin/wpa_supplicant'], stdin=procPidSupplicant1.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050063 stdout=subprocess.PIPE,
64 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050065 procPidSupplicant3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidSupplicant2.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050066 stdout=subprocess.PIPE,
67 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050068
69 procPidSupplicant1.stdout.close()
70 procPidSupplicant2.stdout.close()
71
72 out, err = procPidSupplicant3.communicate()
73 supplicantPid = out.strip()
Gilles Depatieed99efe2019-03-12 16:12:26 -040074
Gilles Depatiea85fe812019-01-23 15:55:53 -050075 procKillSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', supplicantPid],
Gilles Depatie0bf31352019-02-04 13:48:41 -050076 stdout=subprocess.PIPE,
77 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050078 out, err = procKillSupplicant1.communicate()
Gilles Depatie0bf31352019-02-04 13:48:41 -050079 assert not err, 'Killing Supplicant returned %s' % err
Gilles Depatiea85fe812019-01-23 15:55:53 -050080
81 procPidBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
Gilles Depatie0bf31352019-02-04 13:48:41 -050082 stdout=subprocess.PIPE,
83 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050084 procPidBash2 = subprocess.Popen(['grep', '-e', '/bin/bash'], stdin=procPidBash1.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050085 stdout=subprocess.PIPE,
86 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050087 procPidBash3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidBash2.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050088 stdout=subprocess.PIPE,
89 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050090
91 procPidBash1.stdout.close()
92 procPidBash2.stdout.close()
93
94 out, err = procPidBash3.communicate()
95 bashPid = out.strip()
96
97 procKillBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', '-9', bashPid],
Gilles Depatie0bf31352019-02-04 13:48:41 -050098 stdout=subprocess.PIPE,
99 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500100 out, err = procKillBash1.communicate()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500101 assert not err, 'Killing Bash returned %s' % err
Gilles Depatiea85fe812019-01-23 15:55:53 -0500102
103 process_output.close()
104
Gilles Depatie0bf31352019-02-04 13:48:41 -0500105 testCaseUtils.print_log_file(self, self.AUTHENTICATE_FILENAME)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500106
Gilles Depatie493ea242019-05-21 14:38:08 -0400107 def authentication_should_have_started(self):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500108 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-STARTED', self.AUTHENTICATE_FILENAME)
109 assert statusLines, 'Authentication was not started'
110
Gilles Depatie493ea242019-05-21 14:38:08 -0400111 def authentication_should_have_completed(self):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500112 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-SUCCESS', self.AUTHENTICATE_FILENAME)
113 assert statusLines, 'Authentication was not completed successfully'
114
Gilles Depatie493ea242019-05-21 14:38:08 -0400115 def authentication_should_have_disconnected(self):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500116 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-DISCONNECTED', self.AUTHENTICATE_FILENAME)
117 assert statusLines, 'Authentication was not disconnected'
118
Gilles Depatie493ea242019-05-21 14:38:08 -0400119 def authentication_should_have_terminated(self):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500120 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-TERMINATING', self.AUTHENTICATE_FILENAME)
121 assert statusLines, 'Authentication was not terminated'
Gilles Depatie0bf31352019-02-04 13:48:41 -0500122
Gilles Depatie493ea242019-05-21 14:38:08 -0400123 def should_have_all_onus_authenticated(self):
124 testCaseUtils.send_command_to_onos_cli(testCaseUtils.get_dir(self, 'log'),
125 'voltha_onu_auth.log', 'aaa-users')
126 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'AUTHORIZED', 'voltha_onu_auth.log')
127 lines = statusLines.splitlines()
128 auth_count = len(lines)
129 assert self.__onuCount == auth_count, 'There are only %s ONUS Authenticated' % auth_count
130
131
132def run_test(onu_count, root_dir, voltha_dir, log_dir, simtype):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500133 auth = Authentication()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500134 auth.a_set_log_dirs(root_dir, voltha_dir, log_dir)
Gilles Depatie493ea242019-05-21 14:38:08 -0400135 auth.a_configure(onu_count)
136 if simtype == 'ponsim':
137 auth.execute_authentication_on_rg()
138 auth.authentication_should_have_started()
139 auth.authentication_should_have_completed()
140 auth.authentication_should_have_disconnected()
141 auth.authentication_should_have_terminated()
142 elif simtype == 'bbsim':
143 auth.should_have_all_onus_authenticated()