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 | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 39 | |
| 40 | self.__onuCount = None |
Gilles Depatie | ed99efe | 2019-03-12 16:12:26 -0400 | [diff] [blame] | 41 | self.__rgName = testCaseUtils.discover_rg_pod_name() |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 42 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 43 | def a_set_log_dirs(self, root_dir, voltha_dir, log_dir): |
| 44 | testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 45 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 46 | def a_configure(self, onu_count): |
| 47 | self.__onuCount = onu_count |
| 48 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 49 | 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 Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 53 | '/sbin/wpa_supplicant -Dwired -ieth0 -c /etc/wpa_supplicant/wpa_supplicant.conf'], |
| 54 | stdout=process_output, |
| 55 | stderr=process_output) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 56 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 57 | time.sleep(15) |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 58 | logging.debug('return value from supplicant subprocess = %s' % proc1.returncode) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 59 | 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] | 60 | stdout=subprocess.PIPE, |
| 61 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 62 | procPidSupplicant2 = subprocess.Popen(['grep', '-e', '/sbin/wpa_supplicant'], stdin=procPidSupplicant1.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 63 | stdout=subprocess.PIPE, |
| 64 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 65 | procPidSupplicant3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidSupplicant2.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 66 | stdout=subprocess.PIPE, |
| 67 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 68 | |
| 69 | procPidSupplicant1.stdout.close() |
| 70 | procPidSupplicant2.stdout.close() |
| 71 | |
| 72 | out, err = procPidSupplicant3.communicate() |
| 73 | supplicantPid = out.strip() |
Gilles Depatie | ed99efe | 2019-03-12 16:12:26 -0400 | [diff] [blame] | 74 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 75 | 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] | 76 | stdout=subprocess.PIPE, |
| 77 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 78 | out, err = procKillSupplicant1.communicate() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 79 | assert not err, 'Killing Supplicant returned %s' % err |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 80 | |
| 81 | 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] | 82 | stdout=subprocess.PIPE, |
| 83 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 84 | procPidBash2 = subprocess.Popen(['grep', '-e', '/bin/bash'], stdin=procPidBash1.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 85 | stdout=subprocess.PIPE, |
| 86 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 87 | procPidBash3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidBash2.stdout, |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 88 | stdout=subprocess.PIPE, |
| 89 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 90 | |
| 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 Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 98 | stdout=subprocess.PIPE, |
| 99 | stderr=subprocess.PIPE) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 100 | out, err = procKillBash1.communicate() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 101 | assert not err, 'Killing Bash returned %s' % err |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 102 | |
| 103 | process_output.close() |
| 104 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 105 | testCaseUtils.print_log_file(self, self.AUTHENTICATE_FILENAME) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 106 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 107 | def authentication_should_have_started(self): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 108 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-STARTED', self.AUTHENTICATE_FILENAME) |
| 109 | assert statusLines, 'Authentication was not started' |
| 110 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 111 | def authentication_should_have_completed(self): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 112 | 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 Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 115 | def authentication_should_have_disconnected(self): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 116 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-DISCONNECTED', self.AUTHENTICATE_FILENAME) |
| 117 | assert statusLines, 'Authentication was not disconnected' |
| 118 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 119 | def authentication_should_have_terminated(self): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 120 | statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-TERMINATING', self.AUTHENTICATE_FILENAME) |
| 121 | assert statusLines, 'Authentication was not terminated' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 122 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 123 | 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 | |
| 132 | def run_test(onu_count, root_dir, voltha_dir, log_dir, simtype): |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 133 | auth = Authentication() |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 134 | auth.a_set_log_dirs(root_dir, voltha_dir, log_dir) |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 135 | 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() |