Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 1 | # |
| 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 | """ |
| 18 | vOLT-HA Authentication Test Case module |
| 19 | """ |
| 20 | |
| 21 | import time |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 22 | import subprocess |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 23 | import testCaseUtils |
| 24 | import logging |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 25 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 26 | |
| 27 | class 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 Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 35 | self.dirs = dict() |
| 36 | self.dirs['log'] = None |
| 37 | self.dirs['root'] = None |
| 38 | self.dirs['voltha'] = None |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 39 | |
Gilles Depatie | ed99efe | 2019-03-12 16:12:26 -0400 | [diff] [blame] | 40 | self.__rgName = testCaseUtils.discover_rg_pod_name() |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 41 | self.__radiusName = None |
| 42 | self.__radiusIp = None |
| 43 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 44 | def a_set_log_dirs(self, root_dir, voltha_dir, log_dir): |
| 45 | testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 46 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 47 | 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 Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 51 | '/sbin/wpa_supplicant -Dwired -ieth0 -c /etc/wpa_supplicant/wpa_supplicant.conf'], |
| 52 | stdout=process_output, |
| 53 | stderr=process_output) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 54 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 55 | time.sleep(15) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 56 | logging.debug('return value from supplicant subprocess = %s' % proc1.returncode) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 57 | procPidSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'], |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 58 | stdout=subprocess.PIPE, |
| 59 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 60 | procPidSupplicant2 = subprocess.Popen(['grep', '-e', '/sbin/wpa_supplicant'], stdin=procPidSupplicant1.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 61 | stdout=subprocess.PIPE, |
| 62 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 63 | procPidSupplicant3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidSupplicant2.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 64 | stdout=subprocess.PIPE, |
| 65 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 66 | |
| 67 | procPidSupplicant1.stdout.close() |
| 68 | procPidSupplicant2.stdout.close() |
| 69 | |
| 70 | out, err = procPidSupplicant3.communicate() |
| 71 | supplicantPid = out.strip() |
Gilles Depatie | ed99efe | 2019-03-12 16:12:26 -0400 | [diff] [blame] | 72 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 73 | procKillSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', supplicantPid], |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 74 | stdout=subprocess.PIPE, |
| 75 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 76 | out, err = procKillSupplicant1.communicate() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 77 | assert not err, 'Killing Supplicant returned %s' % err |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 78 | |
| 79 | procPidBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'], |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 80 | stdout=subprocess.PIPE, |
| 81 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 82 | procPidBash2 = subprocess.Popen(['grep', '-e', '/bin/bash'], stdin=procPidBash1.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 83 | stdout=subprocess.PIPE, |
| 84 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 85 | procPidBash3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidBash2.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 86 | stdout=subprocess.PIPE, |
| 87 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 88 | |
| 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 Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 96 | stdout=subprocess.PIPE, |
| 97 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 98 | out, err = procKillBash1.communicate() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 99 | assert not err, 'Killing Bash returned %s' % err |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 100 | |
| 101 | process_output.close() |
| 102 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 103 | testCaseUtils.print_log_file(self, self.AUTHENTICATE_FILENAME) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 104 | |
| 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 Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 121 | |
| 122 | def run_test(root_dir, voltha_dir, log_dir): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 123 | auth = Authentication() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 124 | auth.a_set_log_dirs(root_dir, voltha_dir, log_dir) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 125 | auth.execute_authentication_on_rg() |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 126 | 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() |