| 1 |
# Copyright (c) 2015 Midokura SARL |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# 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, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
from tempest import config |
| 17 |
from tempest.lib.common import ssh |
| 18 |
from tempest.lib import exceptions as lib_exc |
| 19 |
|
| 20 |
from neutron_tempest_plugin.fwaas.common import fwaas_v2_client |
| 21 |
from neutron_tempest_plugin.fwaas.scenario import fwaas_v2_manager as manager |
| 22 |
|
| 23 |
CONF = config.CONF |
| 24 |
|
| 25 |
|
| 26 |
class FWaaSScenarioTestBase(object): |
| 27 |
def check_connectivity(self, ip_address, username=None, private_key=None, |
| 28 |
should_connect=True, |
| 29 |
check_icmp=True, check_ssh=True, |
| 30 |
check_reverse_icmp_ip=None, |
| 31 |
should_reverse_connect=True): |
| 32 |
if should_connect: |
| 33 |
msg = "Timed out waiting for %s to become reachable" % ip_address |
| 34 |
else: |
| 35 |
msg = "ip address %s is reachable" % ip_address |
| 36 |
if check_icmp: |
| 37 |
ok = self.ping_ip_address(ip_address, |
| 38 |
should_succeed=should_connect) |
| 39 |
self.assertTrue(ok, msg=msg) |
| 40 |
if check_ssh: |
| 41 |
connect_timeout = CONF.validation.connect_timeout |
| 42 |
kwargs = {} |
| 43 |
if not should_connect: |
| 44 |
# Use a shorter timeout for negative case |
| 45 |
kwargs['timeout'] = 1 |
| 46 |
try: |
| 47 |
client = ssh.Client(ip_address, username, pkey=private_key, |
| 48 |
channel_timeout=connect_timeout, |
| 49 |
ssh_key_type=CONF.validation.ssh_key_type, |
| 50 |
**kwargs) |
| 51 |
client.test_connection_auth() |
| 52 |
self.assertTrue(should_connect, "Unexpectedly reachable") |
| 53 |
if check_reverse_icmp_ip: |
| 54 |
cmd = 'ping -c1 -w1 %s' % check_reverse_icmp_ip |
| 55 |
try: |
| 56 |
client.exec_command(cmd) |
| 57 |
self.assertTrue(should_reverse_connect, |
| 58 |
"Unexpectedly reachable (reverse)") |
| 59 |
except lib_exc.SSHExecCommandFailed: |
| 60 |
if should_reverse_connect: |
| 61 |
raise |
| 62 |
except lib_exc.SSHTimeout: |
| 63 |
if should_connect: |
| 64 |
raise |
| 65 |
|
| 66 |
|
| 67 |
class FWaaSScenarioTest_V2(fwaas_v2_client.FWaaSClientMixin, |
| 68 |
FWaaSScenarioTestBase, |
| 69 |
manager.NetworkScenarioTest): |
| 70 |
pass |