blob: b5196d7bc41a3ab48b600ebe28dd585aa0d504ff [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 Depatiea85fe812019-01-23 15:55:53 -050039
Gilles Depatieed99efe2019-03-12 16:12:26 -040040 self.__rgName = testCaseUtils.discover_rg_pod_name()
Gilles Depatiea85fe812019-01-23 15:55:53 -050041 self.__radiusName = None
42 self.__radiusIp = None
43
Gilles Depatie0bf31352019-02-04 13:48:41 -050044 def a_set_log_dirs(self, root_dir, voltha_dir, log_dir):
45 testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir)
Gilles Depatiea85fe812019-01-23 15:55:53 -050046
Gilles Depatie0bf31352019-02-04 13:48:41 -050047 def execute_authentication_on_rg(self):
48 logging.info('Running Radius Authentication from RG')
49 process_output = open('%s/%s' % (testCaseUtils.get_dir(self, 'log'), self.AUTHENTICATE_FILENAME), 'w')
50 proc1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'bash', '-c',
Gilles Depatiea85fe812019-01-23 15:55:53 -050051 '/sbin/wpa_supplicant -Dwired -ieth0 -c /etc/wpa_supplicant/wpa_supplicant.conf'],
52 stdout=process_output,
53 stderr=process_output)
Gilles Depatie0bf31352019-02-04 13:48:41 -050054
Gilles Depatiea85fe812019-01-23 15:55:53 -050055 time.sleep(15)
Gilles Depatie0bf31352019-02-04 13:48:41 -050056 logging.debug('return value from supplicant subprocess = %s' % proc1.returncode)
Gilles Depatiea85fe812019-01-23 15:55:53 -050057 procPidSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
Gilles Depatie0bf31352019-02-04 13:48:41 -050058 stdout=subprocess.PIPE,
59 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050060 procPidSupplicant2 = subprocess.Popen(['grep', '-e', '/sbin/wpa_supplicant'], stdin=procPidSupplicant1.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050061 stdout=subprocess.PIPE,
62 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050063 procPidSupplicant3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidSupplicant2.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050064 stdout=subprocess.PIPE,
65 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050066
67 procPidSupplicant1.stdout.close()
68 procPidSupplicant2.stdout.close()
69
70 out, err = procPidSupplicant3.communicate()
71 supplicantPid = out.strip()
Gilles Depatieed99efe2019-03-12 16:12:26 -040072
Gilles Depatiea85fe812019-01-23 15:55:53 -050073 procKillSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', supplicantPid],
Gilles Depatie0bf31352019-02-04 13:48:41 -050074 stdout=subprocess.PIPE,
75 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050076 out, err = procKillSupplicant1.communicate()
Gilles Depatie0bf31352019-02-04 13:48:41 -050077 assert not err, 'Killing Supplicant returned %s' % err
Gilles Depatiea85fe812019-01-23 15:55:53 -050078
79 procPidBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
Gilles Depatie0bf31352019-02-04 13:48:41 -050080 stdout=subprocess.PIPE,
81 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050082 procPidBash2 = subprocess.Popen(['grep', '-e', '/bin/bash'], stdin=procPidBash1.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050083 stdout=subprocess.PIPE,
84 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050085 procPidBash3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidBash2.stdout,
Gilles Depatie0bf31352019-02-04 13:48:41 -050086 stdout=subprocess.PIPE,
87 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050088
89 procPidBash1.stdout.close()
90 procPidBash2.stdout.close()
91
92 out, err = procPidBash3.communicate()
93 bashPid = out.strip()
94
95 procKillBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', '-9', bashPid],
Gilles Depatie0bf31352019-02-04 13:48:41 -050096 stdout=subprocess.PIPE,
97 stderr=subprocess.PIPE)
Gilles Depatiea85fe812019-01-23 15:55:53 -050098 out, err = procKillBash1.communicate()
Gilles Depatie0bf31352019-02-04 13:48:41 -050099 assert not err, 'Killing Bash returned %s' % err
Gilles Depatiea85fe812019-01-23 15:55:53 -0500100
101 process_output.close()
102
Gilles Depatie0bf31352019-02-04 13:48:41 -0500103 testCaseUtils.print_log_file(self, self.AUTHENTICATE_FILENAME)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500104
105 def verify_authentication_should_have_started(self):
106 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-STARTED', self.AUTHENTICATE_FILENAME)
107 assert statusLines, 'Authentication was not started'
108
109 def verify_authentication_should_have_completed(self):
110 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-SUCCESS', self.AUTHENTICATE_FILENAME)
111 assert statusLines, 'Authentication was not completed successfully'
112
113 def verify_authentication_should_have_disconnected(self):
114 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-DISCONNECTED', self.AUTHENTICATE_FILENAME)
115 assert statusLines, 'Authentication was not disconnected'
116
117 def verify_authentication_should_have_terminated(self):
118 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-TERMINATING', self.AUTHENTICATE_FILENAME)
119 assert statusLines, 'Authentication was not terminated'
120
Gilles Depatie0bf31352019-02-04 13:48:41 -0500121
122def run_test(root_dir, voltha_dir, log_dir):
Gilles Depatiea85fe812019-01-23 15:55:53 -0500123 auth = Authentication()
Gilles Depatie0bf31352019-02-04 13:48:41 -0500124 auth.a_set_log_dirs(root_dir, voltha_dir, log_dir)
Gilles Depatie0bf31352019-02-04 13:48:41 -0500125 auth.execute_authentication_on_rg()
Gilles Depatiea85fe812019-01-23 15:55:53 -0500126 auth.verify_authentication_should_have_started()
127 auth.verify_authentication_should_have_completed()
128 auth.verify_authentication_should_have_disconnected()
129 auth.verify_authentication_should_have_terminated()