blob: e0defd6738ca6370ba824693f3fac5eabba66311 [file] [log] [blame]
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +00001#
2# Copyright 2016-present Ciena Corporation
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#
16import unittest
17import os,sys
18import keystoneclient.v2_0.client as ksclient
19import keystoneclient.apiclient.exceptions
20import neutronclient.v2_0.client as nclient
21import neutronclient.common.exceptions
22from novaclient import client as nova_client
23from neutronclient.v2_0 import client as neutron_client
24import neutronclient.v2_0.client as neutronclient
25from nose.tools import assert_equal
26from CordTestUtils import get_mac, log_test
27from OnosCtrl import OnosCtrl
28from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000029from OnboardingServiceUtils import OnboardingServiceUtils
30from SSHTestAgent import SSHTestAgent
A R Karthick19771192017-04-25 14:57:05 -070031from CordTestUtils import running_on_pod
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000032from CordLogger import CordLogger
33from CordTestUtils import log_test as log
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000034import requests
35import time
36import json
37
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000038class onboarding_exchange(CordLogger):
Chetan Gaonkerc6853932017-04-24 22:16:37 +000039 ONOS_INSTANCES = 3
40 V_INF1 = 'veth0'
41 device_id = 'of:' + get_mac()
42 TEST_IP = '8.8.8.8'
43 HOST = "10.1.0.1"
44 USER = "vagrant"
45 PASS = "vagrant"
46 head_node = os.getenv('HEAD_NODE', 'prod')
47 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
48 test_path = os.path.dirname(os.path.realpath(__file__))
A R Karthick19771192017-04-25 14:57:05 -070049 on_pod = running_on_pod()
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000050
51 @classmethod
52 def setUpClass(cls):
53 OnboardingServiceUtils.setUp()
54
55 @classmethod
56 def tearDownClass(cls):
57 OnboardingServiceUtils.tearDown()
58
59 def cliEnter(self, controller = None):
60 retries = 0
61 while retries < 30:
62 self.cli = OnosCliDriver(controller = controller, connect = True)
63 if self.cli.handle:
64 break
65 else:
66 retries += 1
67 time.sleep(2)
68
69 def cliExit(self):
70 self.cli.disconnect()
71
72 def onos_shutdown(self, controller = None):
73 status = True
74 self.cliEnter(controller = controller)
75 try:
76 self.cli.shutdown(timeout = 10)
77 except:
78 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
79 status = False
80
81 self.cliExit()
82 return status
83
84 def test_exampleservice_health(self):
85 """
86 Algo:
87 1. Login to compute node VM
88 2. Get all exampleservice
89 3. Ping to all exampleservice
90 4. Verifying Ping success
91 """
92 status = OnboardingServiceUtils.health_check()
93 assert_equal(status, True)
94
Chetan Gaonkerc6853932017-04-24 22:16:37 +000095 def test_exampleservice_for_login(self):
A R Karthick19771192017-04-25 14:57:05 -070096 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +000097 return
98 exampleservices = OnboardingServiceUtils.get_exampleservices()
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000099 log.info('list of all exampleservices are %s'%exampleservices)
100 """exampleservice_access_status = map(lambda exampleservice: exampleservice.check_access(), exampleservices)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000101 status = filter(lambda st: st == False, exampleservice_access_status)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000102 assert_equal(len(status), 0)"""
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000103
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000104 def test_exampleservice_for_default_route_through_testclient(self):
Chetan Gaonker4cff4432017-05-01 17:56:56 +0000105 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000106 return
107 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
108 cmd = "sudo lxc exec testclient -- route | grep default"
109 status, output = ssh_agent.run_cmd(cmd)
110 assert_equal(status, True)
111
112 def test_exampleservice_for_service_access_through_testclient(self):
A R Karthick19771192017-04-25 14:57:05 -0700113 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000114 return
115 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
116 cmd = "lxc exec testclient -- ping -c 3 8.8.8.8"
117 status, output = ssh_agent.run_cmd(cmd)
118 assert_equal( status, True)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000119
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000120 def get_exampleservice_vm_public_ip(self,vm='mysite_exampleservice'):
121 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
122 cmd = "nova list --all-tenants|grep {}|cut -d '|' -f 2".format(vm)
123 status, nova_id = ssh_agent.run_cmd(cmd)
124 assert_equal(status, True)
125 #Get public IP of VM
126 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
127 status, public_ip = ssh_agent.run_cmd(cmd)
128 assert_equal(status, True)
129 return public_ip
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000130
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000131 def test_exampleservice_operational_status_from_testclient(self):
132 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
133 #Wait for ExampleService VM to come up
134 cmd = "nova list --all-tenants|grep 'exampleservice.*ACTIVE'"
135 status, output = ssh_agent.run_cmd(cmd)
136 assert_equal(status, True)
137 #Get ID of VM
138 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
139 status, nova_id = ssh_agent.run_cmd(cmd)
140 assert_equal(status, True)
141 #Get mgmt IP of VM
142 cmd = 'nova interface-list {} |grep -o -m 1 172\.27\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
143 status, mgmt_ip = ssh_agent.run_cmd(cmd)
144 assert_equal(status, True)
145 #Get public IP of VM
146 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
147 status, public_ip = ssh_agent.run_cmd(cmd)
148 assert_equal(status, True)
149 #Get name of compute node
150 cmd = "nova service-list|grep nova-compute|cut -d '|' -f 3"
151 status, compute_node = ssh_agent.run_cmd(cmd)
152 assert_equal(status, True)
153 #Wait for Apache to come up inside VM
154 cmd = "ssh -o ProxyCommand='ssh -W %h:%p -l ubuntu {}' ubuntu@{} 'ls /var/run/apache2/apache2.pid'".fromat(compute_node,mgmt_ip)
155 #Make sure testclient has default route to vSG
156 cmd = "lxc exec testclient -- route | grep default | grep eth0.222.111"
157 status, output = ssh_agent.run_cmd(cmd)
158 assert_equal(status, True)
159 cmd = 'lxc exec testclient -- apt-get install -y curl'
160 status, output = ssh_agent.run_cmd(cmd)
161 assert_equal(status, True)
162 #Test connectivity to ExampleService from test client
163 cmd = 'lxc exec testclient -- curl -s http://{}'.format(public_ip)
164 status, output = ssh_agent.run_cmd(cmd)
165 assert_equal(status, True)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000166
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000167 def test_subscribers_operational_status_for_exampleservice_from_cord_tester(self):
168 if not vcpe_intf:
169 vcpe_intf = self.dhcp_vcpes_reserved[0]
170 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
171 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
172 status, nova_id = ssh_agent.run_cmd(cmd)
173 assert_equal(status, True)
174 #Get public IP of VM
175 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
176 status, public_ip = ssh_agent.run_cmd(cmd)
177 assert_equal(status, True)
178 try:
179 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
180 #curl request from test container
181 cmd = 'curl -s http://{}'.format(public_ip)
182 st,_ = getstatusoutput(cmd)
183 assert_equal(st, True)
184 finally:
185 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000186
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000187 def test_subscriber_access_status_for_exampleservice_after_subscriber_interface_toggle(self,vcpe_intf=None):
188 if not vcpe_intf:
189 vcpe_intf = self.dhcp_vcpes_reserved[0]
190 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
191 #Get public IP of VM
192 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
193 status, nova_id = ssh_agent.run_cmd(cmd)
194 assert_equal(status, True)
195 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
196 status, public_ip = ssh_agent.run_cmd(cmd)
197 assert_equal(status, True)
198 try:
199 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
200 #curl request from test container
201 cmd = 'curl -s http://{}'.format(public_ip)
202 st,_ = getstatusoutput(cmd)
203 assert_equal(st, True)
204 st,_ = getstatusoutput('ifconfig {} down'.format(vcpe_intf))
205 assert_equal(st, True)
206 st,_ = getstatusoutput(cmd)
207 assert_equal(st, True)
208 finally:
209 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
210
211 def test_subscriber_access_status_for_exampleservice_after_service_restart(self, vcpe_intf=None):
212 if not vcpe_intf:
213 vcpe_intf = self.dhcp_vcpes_reserved[0]
214 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
215 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
216 status, nova_id = ssh_agent.run_cmd(cmd)
217 assert_equal(status, True)
218 #Get public IP of VM
219 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
220 status, public_ip = ssh_agent.run_cmd(cmd)
221 assert_equal(status, True)
222 try:
223 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
224 #curl request from test container
225 curl_cmd = 'curl -s http://{}'.format(public_ip)
226 st,_ = getstatusoutput(curl_cmd)
227 assert_equal(st, True)
228 #restarting example service VM
229 cmd = 'nova reset-state {}'.format(nova_id)
230 status, _ = ssh_agent.run_cmd(cmd)
231 assert_equal(status, True)
232 time.sleep(10)
233 st,_ = getstatusoutput(curl_cmd)
234 assert_equal(st, True)
235 finally:
236 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
237
238 def test_subcriber_access_status_for_exampleservice_after_service_stop(self, vcpe_intf=None):
239 if not vcpe_intf:
240 vcpe_intf = self.dhcp_vcpes_reserved[0]
241 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
242 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
243 status, nova_id = ssh_agent.run_cmd(cmd)
244 assert_equal(status, True)
245 #Get public IP of VM
246 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
247 status, public_ip = ssh_agent.run_cmd(cmd)
248 assert_equal(status, True)
249 try:
250 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
251 #curl request from test container
252 curl_cmd = 'curl -s http://{}'.format(public_ip)
253 st,_ = getstatusoutput(curl_cmd)
254 assert_equal(st, True)
255 #restarting example service VM
256 cmd = 'nova stop {}'.format(nova_id)
257 status, _ = ssh_agent.run_cmd(cmd)
258 assert_equal(status, True)
259 time.sleep(1)
260 st,_ = getstatusoutput(curl_cmd)
261 assert_equal(st, False)
262 cmd = 'nova start {}'.format(nova_id)
263 status, _ = ssh_agent.run_cmd(cmd)
264 assert_equal(status, True)
265 time.sleep(1)
266 st,_ = getstatusoutput(curl_cmd)
267 assert_equal(st, True)
268 finally:
269 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
270
271 def test_multiple_subcriber_access_for_same_exampleservice(self):
272 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
273 cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
274 status, nova_id = ssh_agent.run_cmd(cmd)
275 assert_equal(status, True)
276 #Get public IP of VM
277 cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id)
278 status, public_ip = ssh_agent.run_cmd(cmd)
279 assert_equal(status, True)
280 for vcpe in self.dhcp_vcpes:
281 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe)
282 #curl request from test container
283 curl_cmd = 'curl -s http://{}'.format(public_ip)
284 st,_ = getstatusoutput(curl_cmd)
285 assert_equal(st, True)
286 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe)
287 time.sleep(1)
288
289 def test_exampleservice_after_vcpe_instance_restart(self,vcpe_intf=None,vcpe_name=None):
290 if not vcpe_intf:
291 vcpe_intf = self.dhcp_vcpes_reserved[0]
292 if not vcpe_name:
293 vcpe_name = self.container_vcpes_reserved[0]
294 public_ip = self.get_exampleservice_vm_public_ip()
295 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
296 try:
297 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
298 #curl request from test container
299 curl_cmd = 'curl -s http://{}'.format(public_ip)
300 st,_ = getstatusoutput(curl_cmd)
301 assert_equal(st, True)
302 #restarting example service VM
303 cmd = 'sudo docker restart {}'.format(vcpe_name)
304 status, _ = vsg.run_cmd(cmd)
305 assert_equal(status, True)
306 time.sleep(10)
307 st,_ = getstatusoutput(curl_cmd)
308 assert_equal(st, True)
309 finally:
310 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
311
312 def test_exampleservice_after_firewall_rule_added_to_drop_service_running_server_ip_in_vcpe(self):
313 if not vcpe_intf:
314 vcpe_intf = self.dhcp_vcpes_reserved[0]
315 if not vcpe_name:
316 vcpe_name = self.container_vcpes_reserved[0]
317 public_ip = self.get_exampleservice_vm_public_ip()
318 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
319 try:
320 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
321 #curl request from test container
322 curl_cmd = 'curl -s http://{}'.format(public_ip)
323 st,_ = getstatusoutput(curl_cmd)
324 assert_equal(st, True)
325 #restarting example service VM
326 st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j ACCEPT'.format(vcpe_name,public_ip))
327 time.sleep(1)
328 st,_ = getstatusoutput(curl_cmd)
329 assert_equal(st, False)
330 finally:
331 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,public_ip))
332 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)