blob: 975e11c8da39d01336db5fc5990dc8a26de603f3 [file] [log] [blame]
Chetan Gaonker52418832017-01-26 23:03:13 +00001#copyright 2016-present Ciena Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15import unittest
16from nose.tools import *
17from scapy.all import *
18from OnosCtrl import OnosCtrl, get_mac
19from OltConfig import OltConfig
20from socket import socket
21from OnosFlowCtrl import OnosFlowCtrl
22from nose.twistedtools import reactor, deferred
23from twisted.internet import defer
24from onosclidriver import OnosCliDriver
25from CordContainer import Container, Onos, Quagga
26from CordTestServer import cord_test_onos_restart, cord_test_onos_shutdown
27from portmaps import g_subscriber_port_map
28from scapy.all import *
29import time, monotonic
30from OnosLog import OnosLog
31from CordLogger import CordLogger
32from os import environ as env
33import os
34import json
35import random
36import collections
37import paramiko
38from paramiko import SSHClient
39log.setLevel('INFO')
40
41class vsg_exchange(CordLogger):
42 ONOS_INSTANCES = 3
43 V_INF1 = 'veth0'
44 device_id = 'of:' + get_mac()
45 testcaseLoggers = ("")
46 TEST_IP = '8.8.8.8'
47 HOST = "10.1.0.1"
48 USER = "vagrant"
49 PASS = "vagrant"
50
51
52 def setUp(self):
53 if self._testMethodName not in self.testcaseLoggers:
54 super(vsg_exchange, self).setUp()
55
56 def tearDown(self):
57 if self._testMethodName not in self.testcaseLoggers:
58 super(vsg_exchange, self).tearDown()
59
60 def get_controller(self):
61 controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
62 controller = controller.split(',')[0]
63 return controller
64
65 @classmethod
66 def get_controllers(cls):
67 controllers = os.getenv('ONOS_CONTROLLER_IP') or ''
68 return controllers.split(',')
69
70 def cliEnter(self, controller = None):
71 retries = 0
72 while retries < 30:
73 self.cli = OnosCliDriver(controller = controller, connect = True)
74 if self.cli.handle:
75 break
76 else:
77 retries += 1
78 time.sleep(2)
79
80 def cliExit(self):
81 self.cli.disconnect()
82
83 def onos_shutdown(self, controller = None):
84 status = True
85 self.cliEnter(controller = controller)
86 try:
87 self.cli.shutdown(timeout = 10)
88 except:
89 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
90 status = False
91
92 self.cliExit()
93 return status
94
95 def log_set(self, level = None, app = 'org.onosproject', controllers = None):
96 CordLogger.logSet(level = level, app = app, controllers = controllers, forced = True)
97
98 def get_nova_credentials_v2():
99 credential = {}
100 credential['version'] = '2'
101 credential['username'] = env['OS_USERNAME']
102 credential['api_key'] = env['OS_PASSWORD']
103 credential['auth_url'] = env['OS_AUTH_URL']
104 credential['project_id'] = env['OS_TENANT_NAME']
105 return credential
106
107 def get_vsg_ip(vm_id):
108 credentials = get_nova_credentials_v2()
109 nova_client = Client(**credentials)
110 result = nova_client.servers.list()
111 for server in result:
112 print server;
113
114 def health_check(self):
115 cmd = "nova list --all-tenants|grep mysite_vsg|cut -d '|' -f 2"
116 status, nova_id = commands.getstatusoutput(cmd)
117 cmd = "nova interface-list {{ nova_id }}|grep -o -m 1 '172\.27\.[[:digit:]]*\.[[:digit:]]*'"
118 status, ip = commands.getstatusoutput(cmd)
119 cmd = "ping -c1 {0}".format(ip)
120 status = os.system(cmd)
121 return status
122
123 def ping_ip(remote, ip):
124 results = []
125 cmd = "ping -c1 {0}".format(ip)
126 result = remote.execute(cmd, verbose=False)
127 return results
128
129 def vsg_vm_ssh_check(vsg_ip):
130 cmd = "nc -z -v "+str(vsg_ip)+" 22"
131 status = os.system(cmd)
132 return status
133
134 def get_vcpe(self):
135 cmd = "nova list --all-tenants|grep mysite_vsg|cut -d '|' -f 2"
136 status, node_id = commands.getstatusoutput(cmd)
137
138 def connect_ssh(vsg_ip, private_key_file=None, user='ubuntu'):
139 key = ssh.RSAKey.from_private_key_file(private_key_file)
140 client = ssh.SSHClient()
141 client.set_missing_host_key_policy(ssh.WarningPolicy())
142 client.connect(ip, username=user, pkey=key, timeout=5)
143 return client
144
145 def test_vsg_vm(self):
146 status = self.health_check()
147 assert_equal( status, False)
148
149 def test_vsg_for_default_route_to_vsg_vm(self):
150 client = SSHClient()
151 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
152 client.connect( self.HOST, username = self.USER, password=self.PASS)
153 cmd = "sudo lxc exec testclient -- route | grep default"
154 stdin, stdout, stderr = client.exec_command(cmd)
155 status = stdout.channel.recv_exit_status()
156 assert_equal( status, False)
157
158 def test_vsg_vm_for_vcpe(self):
159 client = SSHClient()
160 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
161 client.connect( self.HOST, username = self.USER, password=self.PASS)
162 cmd = "nova service-list|grep nova-compute|cut -d '|' -f 3"
163 stdin, stdout, stderr = client.exec_command(cmd)
164 cmd = "nova list --all-tenants | grep mysite_vsg|cut -d '|' -f 7 | cut -d '=' -f 2 | cut -d ';' -f 1"
165 status, ip = commands.getstatusoutput(cmd)
166 #cmd = "ssh -o ProxyCommand="ssh -W %h:%p -l ubuntu {0}" ubuntu@{1} "sudo docker ps|grep vcpe"".format(compute_node_name, ip)
167 status = stdout.channel.recv_exit_status()
168 assert_equal( status, False)
169
170 def test_vsg_for_external_connectivity(self):
171 client = SSHClient()
172 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
173 client.connect( self.HOST, username = self.USER, password=self.PASS)
174 cmd = "lxc exec testclient -- ping -c 3 8.8.8.8"
175 stdin, stdout, stderr = client.exec_command(cmd)
176 status = stdout.channel.recv_exit_status()
177 assert_equal( status, False)
178
179 def test_vsg_cord_subscriber_creation(self):
180 pass
181
182 def test_vsg_for_dhcp_client(self):
183 pass
184
185 def test_vsg_for_snat(self):
186 pass
187
188 def test_vsg_for_dns_service(self):
189 pass
190
191 def test_vsg_dnsmasq(self):
192 pass
193
194 def test_vsg_with_external_parental_control_family_shield_for_filter(self):
195 pass
196
197 def test_vsg_with_external_parental_control_with_answerx(self):
198 pass
199
200 def test_vsg_for_subscriber_upstream_bandwidth(self):
201 pass
202
203 def test_vsg_for_subscriber_downstream_bandwidth(self):
204 pass
205
206 def test_vsg_for_diagnostic_run_of_traceroute(self):
207 pass
208
209 def test_vsg_for_diagnostic_run_of_tcpdump(self):
210 pass
211
212 def test_vsg_for_iptable_rules(self):
213 pass
214
215 def test_vsg_for_iptables_with_neutron(self):
216 pass
217