Skip to content

Commit

Permalink
Merge "fullstack: test for snat and floatingip"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed May 20, 2016
2 parents ed2c167 + b73f849 commit 89e27a3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
20 changes: 17 additions & 3 deletions neutron/tests/fullstack/resources/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ def _create_resource(self, resource_type, spec):
self.addCleanup(_safe_method(delete), data['id'])
return data

def create_router(self, tenant_id, name=None, ha=False):
def create_router(self, tenant_id, name=None, ha=False,
external_network=None):
resource_type = 'router'

name = name or base.get_rand_name(prefix=resource_type)
spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
if external_network:
spec['external_gateway_info'] = {"network_id": external_network}

return self._create_resource(resource_type, spec)

def create_network(self, tenant_id, name=None):
def create_network(self, tenant_id, name=None, external=False):
resource_type = 'network'

name = name or base.get_rand_name(prefix=resource_type)
spec = {'tenant_id': tenant_id, 'name': name}

spec['router:external'] = external
return self._create_resource(resource_type, spec)

def create_subnet(self, tenant_id, network_id,
Expand All @@ -88,6 +91,17 @@ def create_port(self, tenant_id, network_id, hostname, qos_policy_id=None):
spec['qos_policy_id'] = qos_policy_id
return self._create_resource('port', spec)

def create_floatingip(self, tenant_id, floating_network_id,
fixed_ip_address, port_id):
spec = {
'floating_network_id': floating_network_id,
'tenant_id': tenant_id,
'fixed_ip_address': fixed_ip_address,
'port_id': port_id
}

return self._create_resource('floatingip', spec)

def add_router_interface(self, router_id, subnet_id):
body = {'subnet_id': subnet_id}
router_interface_info = self.client.add_interface_router(
Expand Down
43 changes: 42 additions & 1 deletion neutron/tests/fullstack/test_l3_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@
from neutron.agent.l3 import namespaces
from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils
from neutron.common import utils as common_utils
from neutron.tests.common.exclusive_resources import ip_network
from neutron.tests.common import machine_fixtures
from neutron.tests.fullstack import base
from neutron.tests.fullstack.resources import environment
from neutron.tests.fullstack.resources import machine


class TestL3Agent(base.BaseFullStackTestCase):

def _create_external_network_and_subnet(self, tenant_id):
network = self.safe_client.create_network(
tenant_id, name='public', external=True)
cidr = self.useFixture(
ip_network.ExclusiveIPNetwork(
"240.0.0.0", "240.255.255.255", "24")).network
subnet = self.safe_client.create_subnet(
tenant_id, network['id'], cidr,
enable_dhcp=False)
return network, subnet

def block_until_port_status_active(self, port_id):
def is_port_status_active():
port = self.client.show_port(port_id)
Expand Down Expand Up @@ -93,9 +107,36 @@ def test_east_west_traffic(self):
tenant_id, '21.0.0.0/24',
self.environment.hosts[1], router)

# wait until qr-xx port up in qrouter-xx namespace
vm1.block_until_ping(vm2.ip)

def test_snat_and_floatingip(self):
# This function creates external network and boots an extrenal vm
# on it with gateway ip and connected to central_external_bridge.
# Later it creates a tenant vm on tenant network, with tenant router
# connected to tenant network and external network.
# To test snat and floatingip, try ping between tenant and external vms
tenant_id = uuidutils.generate_uuid()
ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id)
external_vm = self.useFixture(
machine_fixtures.FakeMachine(
self.environment.central_external_bridge,
common_utils.ip_to_cidr(ext_sub['gateway_ip'], 24)))

router = self.safe_client.create_router(tenant_id,
external_network=ext_net['id'])
vm = self._create_net_subnet_and_vm(
tenant_id, '20.0.0.0/24',
self.environment.hosts[1], router)

# ping external vm to test snat
vm.block_until_ping(external_vm.ip)

fip = self.safe_client.create_floatingip(
tenant_id, ext_net['id'], vm.ip, vm.neutron_port['id'])

# ping floating ip from external vm
external_vm.block_until_ping(fip['floating_ip_address'])


class TestHAL3Agent(base.BaseFullStackTestCase):

Expand Down

0 comments on commit 89e27a3

Please sign in to comment.