fuel-qa/fuel_tests/tests/test_neutron_ipv6.py

247 lines
8.0 KiB
Python

# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import unicode_literals
import pytest
from paramiko import ChannelException
from devops.helpers.ssh_client import SSHAuth
from devops.helpers.helpers import wait
from fuelweb_test import logger
from fuelweb_test import settings
from fuelweb_test.helpers import os_actions
cirros_auth = SSHAuth(**settings.SSH_IMAGE_CREDENTIALS)
# pylint: disable=no-member
@pytest.mark.get_logs
@pytest.mark.fail_snapshot
@pytest.mark.need_ready_cluster
@pytest.mark.neutron
@pytest.mark.thread_1
class TestNeutronIPv6(object):
"""NeutronIPv6."""
cluster_config = {
"name": "NeutronVlan",
"mode": settings.DEPLOYMENT_MODE,
"settings": {
"net_provider": settings.NEUTRON,
"net_segment_type": settings.NEUTRON_SEGMENT['vlan'],
'tenant': 'simpleVlan',
'user': 'simpleVlan',
'password': 'simpleVlan'
},
"nodes": {
'slave-01': ['controller'],
'slave-02': ['compute'],
'slave-03': ['compute']
}
}
@pytest.mark.deploy_neutron_ip_v6
@pytest.mark.nova
@pytest.mark.nova_compute
@pytest.mark.neutron_ipv6
@pytest.mark.deploy_neutron_ip_v6
def test_deploy_neutron_ip_v6(self):
"""Check IPv6 only functionality for Neutron VLAN
Scenario:
1. Revert deploy_neutron_vlan snapshot
2. Create two dualstack network IPv6 subnets
(should be in SLAAC mode,
address space should not intersect).
3. Create virtual router and set gateway.
4. Attach this subnets to the router.
5. Create a Security Group,
that allows SSH and ICMP for both IPv4 and IPv6.
6. Launch two instances, one for each network.
7. Lease a floating IP.
8. Attach Floating IP for main instance.
9. SSH to the main instance and ping6 another instance.
Duration 10m
Snapshot deploy_neutron_ip_v6
"""
self.manager.show_step(1)
cluster_id = self._storage['cluster_id']
fuel_web = self.manager.fuel_web
public_vip = fuel_web.get_public_vip(cluster_id)
logger.info('Public vip is %s', public_vip)
os_conn = os_actions.OpenStackActions(
controller_ip=public_vip,
user='simpleVlan',
passwd='simpleVlan',
tenant='simpleVlan'
)
tenant = os_conn.get_tenant('simpleVlan')
self.manager.show_step(2)
net1 = os_conn.create_network(
network_name='net1',
tenant_id=tenant.id)['network']
net2 = os_conn.create_network(
network_name='net2',
tenant_id=tenant.id)['network']
subnet_1_v4 = os_conn.create_subnet(
subnet_name='subnet_1_v4',
network_id=net1['id'],
cidr='192.168.100.0/24',
ip_version=4)
subnet_1_v6 = os_conn.create_subnet(
subnet_name='subnet_1_v6',
network_id=net1['id'],
ip_version=6,
cidr="2001:db8:100::/64",
gateway_ip="2001:db8:100::1",
ipv6_ra_mode="slaac",
ipv6_address_mode="slaac")
subnet_2_v4 = os_conn.create_subnet(
subnet_name='subnet_2_v4',
network_id=net2['id'],
cidr='192.168.200.0/24',
ip_version=4)
subnet_2_v6 = os_conn.create_subnet(
subnet_name='subnet_2_v6',
network_id=net2['id'],
ip_version=6,
cidr="2001:db8:200::/64",
gateway_ip="2001:db8:200::1",
ipv6_ra_mode="slaac",
ipv6_address_mode="slaac")
self.manager.show_step(3)
router = os_conn.create_router('test_router', tenant=tenant)
self.manager.show_step(4)
os_conn.add_router_interface(
router_id=router["id"],
subnet_id=subnet_1_v4["id"])
os_conn.add_router_interface(
router_id=router["id"],
subnet_id=subnet_1_v6["id"])
os_conn.add_router_interface(
router_id=router["id"],
subnet_id=subnet_2_v4["id"])
os_conn.add_router_interface(
router_id=router["id"],
subnet_id=subnet_2_v6["id"])
self.manager.show_step(5)
security_group = os_conn.create_sec_group_for_ssh()
self.manager.show_step(6)
instance1 = os_conn.create_server(
name='instance1',
security_groups=[security_group],
net_id=net1['id'],
)
instance2 = os_conn.create_server(
name='instance2',
security_groups=[security_group],
net_id=net2['id'],
)
self.manager.show_step(7)
self.manager.show_step(8)
floating_ip = os_conn.assign_floating_ip(instance1)
floating_ip2 = os_conn.assign_floating_ip(instance2)
self.manager.show_step(9)
instance1_ipv6 = [
addr['addr'] for addr in instance1.addresses[net1['name']]
if addr['version'] == 6].pop()
instance2_ipv6 = [
addr['addr'] for addr in instance2.addresses[net2['name']]
if addr['version'] == 6].pop()
logger.info(
'\ninstance1:\n'
'\tFloatingIP: {ip!s}\n'
'\tIPv6 address: {ipv6!s}'.format(
ip=floating_ip.ip,
ipv6=instance1_ipv6))
logger.info(
'\ninstance2:\n'
'\tFloatingIP: {ip!s}\n'
'\tIPv6 address: {ipv6!s}'.format(
ip=floating_ip2.ip,
ipv6=instance2_ipv6))
with fuel_web.get_ssh_for_node("slave-01") as remote:
def ssh_ready(vm_host):
try:
remote.execute_through_host(
hostname=vm_host,
cmd="ls -la",
auth=cirros_auth
)
return True
except ChannelException:
return False
for vm_host, hostname in (
(floating_ip.ip, instance1),
(floating_ip2.ip, instance2)
):
wait(lambda: ssh_ready(vm_host), timeout=120,
timeout_msg='ssh is not ready on host '
'{hostname:s} ({ip:s}) at timeout 120s'
''.format(hostname=hostname, ip=vm_host))
res = remote.execute_through_host(
hostname=floating_ip.ip,
cmd="{ping:s} -q "
"-c{count:d} "
"-w{deadline:d} "
"-s{packetsize:d} "
"{dst_address:s}".format(
ping='ping6',
count=10,
deadline=20,
packetsize=1452,
dst_address=instance2_ipv6),
auth=cirros_auth
)
logger.info(
'Ping results: \n\t{res:s}'.format(res=res['stdout_str']))
assert res['exit_code'] == 0, (
'Ping failed with error code: {code:d}\n'
'\tSTDOUT: {stdout:s}\n'
'\tSTDERR: {stderr:s}'.format(
code=res['exit_code'],
stdout=res['stdout_str'],
stderr=res['stderr_str']))
self.env.make_snapshot('deploy_neutron_ip_v6')