blob: 6bbc669df3e4bfb7703f2d14dcc60440612a52f7 [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
22import os
23import subprocess
24import commands
25import testCaseUtils
26import logging
27import signal
28
29class Authentication(object):
30
31 """
32 This class implements voltha authentication test case
33 """
34 AUTHENTICATE_FILENAME = 'voltha_authenticate.log'
35
36 def __init__(self):
37 self.dirs = {}
38 self.dirs ['log'] = None
39 self.dirs ['root'] = None
40 self.dirs ['voltha'] = None
41
42 self.__rgName = None
43 self.__radiusName = None
44 self.__radiusIp = None
45
46 def aSetLogDirs(self, rootDir, volthaDir, logDir):
47 testCaseUtils.configDirs(self, logDir, rootDir, volthaDir)
48
49 def discover_rg_pod_name(self):
50 self.__rgName = testCaseUtils.extractPodName('rg-').strip()
51
52 def discover_freeradius_pod_name(self):
53 self.__radiusName = testCaseUtils.extractPodName('freeradius').strip()
54 logging.info ('freeradius Name = %s' % self.__radiusName)
55
56 def discover_freeradius_ip_addr(self):
57 ipAddr = testCaseUtils.extractRadiusIpAddr(self.__radiusName)
58 assert ipAddr, 'No IP address listed for freeradius'
59 self.__radiusIp = ipAddr.strip()
60 logging.info('freeradius IP = %s' % self.__radiusIp)
61
62 def set_current_freeradius_ip_in_aaa_json(self):
63 status = testCaseUtils.modifyRadiusIpInJsonUsingSed(self, self.__radiusIp)
64 assertFalse = 'Setting Radius Ip in Json File did not return Success'
65
66 def alter_aaa_application_configuration_in_onos_using_aaa_json(self):
67 logging.info ('Altering the Onos NetCfg AAA apps with Freeradius IP address')
68 logging.debug ('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
69 'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
70 % testCaseUtils.getDir(self, 'voltha'))
71 os.system('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
72 'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
73 % testCaseUtils.getDir(self, 'voltha'))
74
75 def execute_authenticatication_on_rg(self):
76 logging.info ('Running Radius Authentication from RG')
77 process_output = open('%s/%s' % (testCaseUtils.getDir(self, 'log'), self.AUTHENTICATE_FILENAME), 'w')
78 proc1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'bash', '-c', \
79 '/sbin/wpa_supplicant -Dwired -ieth0 -c /etc/wpa_supplicant/wpa_supplicant.conf'],
80 stdout=process_output,
81 stderr=process_output)
82 time.sleep(15)
83 procPidSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
84 stdout=subprocess.PIPE,
85 stderr=subprocess.PIPE)
86 procPidSupplicant2 = subprocess.Popen(['grep', '-e', '/sbin/wpa_supplicant'], stdin=procPidSupplicant1.stdout,
87 stdout=subprocess.PIPE,
88 stderr=subprocess.PIPE)
89 procPidSupplicant3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidSupplicant2.stdout,
90 stdout=subprocess.PIPE,
91 stderr=subprocess.PIPE)
92
93 procPidSupplicant1.stdout.close()
94 procPidSupplicant2.stdout.close()
95
96 out, err = procPidSupplicant3.communicate()
97 supplicantPid = out.strip()
98
99 procKillSupplicant1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', supplicantPid],
100 stdout=subprocess.PIPE,
101 stderr=subprocess.PIPE)
102 out, err = procKillSupplicant1.communicate()
103
104 procPidBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'ps', '-ef'],
105 stdout=subprocess.PIPE,
106 stderr=subprocess.PIPE)
107 procPidBash2 = subprocess.Popen(['grep', '-e', '/bin/bash'], stdin=procPidBash1.stdout,
108 stdout=subprocess.PIPE,
109 stderr=subprocess.PIPE)
110 procPidBash3 = subprocess.Popen(['awk', "{print $2}"], stdin=procPidBash2.stdout,
111 stdout=subprocess.PIPE,
112 stderr=subprocess.PIPE)
113
114 procPidBash1.stdout.close()
115 procPidBash2.stdout.close()
116
117 out, err = procPidBash3.communicate()
118 bashPid = out.strip()
119
120 procKillBash1 = subprocess.Popen(['/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'kill', '-9', bashPid],
121 stdout=subprocess.PIPE,
122 stderr=subprocess.PIPE)
123 out, err = procKillBash1.communicate()
124
125 process_output.close()
126
127 testCaseUtils.printLogFile(self, self.AUTHENTICATE_FILENAME)
128
129 def verify_authentication_should_have_started(self):
130 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-STARTED', self.AUTHENTICATE_FILENAME)
131 assert statusLines, 'Authentication was not started'
132
133 def verify_authentication_should_have_completed(self):
134 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-EAP-SUCCESS', self.AUTHENTICATE_FILENAME)
135 assert statusLines, 'Authentication was not completed successfully'
136
137 def verify_authentication_should_have_disconnected(self):
138 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-DISCONNECTED', self.AUTHENTICATE_FILENAME)
139 assert statusLines, 'Authentication was not disconnected'
140
141 def verify_authentication_should_have_terminated(self):
142 statusLines = testCaseUtils.get_fields_from_grep_command(self, 'CTRL-EVENT-TERMINATING', self.AUTHENTICATE_FILENAME)
143 assert statusLines, 'Authentication was not terminated'
144
145def runTest(rootDir, volthaDir, logDir):
146 auth = Authentication()
147 auth.aSetLogDirs(rootDir, volthaDir, logDir)
148 auth.discover_rg_pod_name()
149 auth.discover_freeradius_pod_name()
150 auth.discover_freeradius_ip_addr()
151 auth.set_current_freeradius_ip_in_aaa_json()
152 auth.alter_aaa_application_configuration_in_onos_using_aaa_json()
153 auth.execute_authenticatication_on_rg()
154 auth.verify_authentication_should_have_started()
155 auth.verify_authentication_should_have_completed()
156 auth.verify_authentication_should_have_disconnected()
157 auth.verify_authentication_should_have_terminated()
158