Skip to content

Commit

Permalink
Merge pull request #804 from ssorenso/feature.mitaka.common_networks2…
Browse files Browse the repository at this point in the history
…True

Feature.mitaka.common networks2 true
  • Loading branch information
jlongstaf authored Jul 14, 2017
2 parents 593f434 + 9bd0e83 commit 433f750
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 6 deletions.
7 changes: 6 additions & 1 deletion f5_openstack_agent/lbaasv2/drivers/bigip/l2_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ def set_context(self, context):
self.fdb_connector.set_context(context)

def is_common_network(self, network):
# Does this network belong in the /Common folder?
"""Returns True if this belongs in the /Common folder
This object method will return positive if the L2ServiceBuilder object
should be stored under the Common partition on the BIG-IP.
"""
return network['shared'] or \
self.conf.f5_common_networks or \
(network['id'] in self.conf.common_network_ids) or \
('router:external' in network and
network['router:external'] and
Expand Down
129 changes: 129 additions & 0 deletions f5_openstack_agent/lbaasv2/drivers/bigip/test/test_l2_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env python
# Copyright 2017 F5 Networks 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.
#

import pytest

from mock import Mock
from mock import patch

from f5_openstack_agent.lbaasv2.drivers.bigip.l2_service import \
L2ServiceBuilder


class Test_L2ServiceBuilder(object):
"""Performs tests against L2ServiceBuilder
The beginning variable assignments should reflect the items that should be
rotated back to their original values in code-space in the teardown()
method. All items that are manipulated to mocks initially should be
performed in a fixture method when repeated.
"""

@pytest.fixture(autouse=True)
def create_self(self, request):
"""Creates a 'blank' L2ServiceBuilder instance in self
This method is executed for every test method during runtime.
"""
request.addfinalizer(self.teardown)

# create our fake driver object...
self.driver = Mock()
self.driver.conf = Mock()
force_false = ['vlan_binding_driver']
list_vars = ['f5_external_physical_mappings']
for item in force_false:
setattr(self.driver.conf, item, False)
for item in list_vars:
setattr(self.driver.conf, item, list())

# set our mocks...
self.system_helper = Mock()
self.network_helper = Mock()
self.service_model_adopter = Mock()
self.f5_global_routed_mode = Mock()
args = [self.driver, self.f5_global_routed_mode]

NetworkHelper = \
str('f5_openstack_agent.lbaasv2.drivers.bigip.l2_service.'
'NetworkHelper')
ServiceModelAdapter = \
str('f5_openstack_agent.lbaasv2.drivers.bigip.l2_service.'
'ServiceModelAdapter')
SystemHelper = \
str('f5_openstack_agent.lbaasv2.drivers.bigip.l2_service.'
'SystemHelper')
with patch(SystemHelper, self.system_helper, create=True):
with patch(ServiceModelAdapter, self.service_model_adopter,
create=True):
with patch(NetworkHelper, self.network_helper, create=True):
self.l2_service_builder = L2ServiceBuilder(*args)

def test__init__(self):
"""tests the target's __init__ method"""
# tests based on basic object creation from self.create_self():
assert self.l2_service_builder.driver is self.driver, \
"Driver provisioning test"
assert self.l2_service_builder.conf is self.driver.conf, \
"Dirver conf provisioning test"
assert self.l2_service_builder.f5_global_routed_mode is \
self.f5_global_routed_mode, \
"f5_global_routed_mode provisioning test"
self.system_helper.assert_called_once_with()
self.network_helper.assert_called_once_with()
self.service_model_adopter.assert_called_once_with(self.driver.conf)

# further tests needed:
# add tests for...
# - f5_external_physical_mappings assignment test
# - vlan_binding_driver assignment/importation test
# Suggest a refactor for implementing the above in unit tests...

def teardown(self):
"""Tears down the code space variables returning code state."""
pass

def test_is_common_network(self):
"""Tests the target's is_common_network() method"""
target = self.l2_service_builder
network = {"shared": True, "id": "foodogzoo", "router:external": True,
}
setattr(target.conf, "f5_common_external_networks", True)
setattr(target.conf, "common_network_ids", ['foodogzoo'])
setattr(target.conf, "f5_common_networks", True)
# network['shared'] condition
assert target.is_common_network(network), "shared test"
# self.conf.f5_common_networks condition
network['shared'] = False
assert target.is_common_network(network), "f5_common_networks test"
# self.conf.f5_common_external_networks condition
setattr(target.conf, "f5_common_networks", False)
assert target.is_common_network(network), \
"f5_common_external_networks test"
setattr(target.conf, "f5_common_external_networks", False)
target.conf.common_network_ids.pop()
assert not target.is_common_network(network), \
"f5_common_external_networks negative test"
setattr(target.conf, "f5_common_external_networks", True)
assert target.is_common_network(network), \
"f5_common_network_ids negative test"
target.conf.f5_common_network_ids.push('foodogzoo')
network['router:external'] = False
assert not target.is_common_network(network), \
"network['reouter:external'] negative test"
del network['router:external']
assert not target.is_common_network(network), \
"No 'reouter:external' network 'negative' test"
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ def test_assign_route_domain(self, network_service, network, subnet):
"""
tenant_id = 'f2a944c28b5d43ad808cc28ba1f03cce'

network_service.conf.f5_common_networks = False

# shared (common) network always get RD 0
network['shared'] = True
network_service.assign_route_domain(tenant_id, network, subnet)
Expand Down
1 change: 1 addition & 0 deletions test/functional/config/basic_agent_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"environment_prefix": "TEST",
"environment_specific_plugin": true,
"f5_bigip_lbaas_device_driver": "f5_openstack_agent.lbaasv2.drivers.bigip.icontrol_driver.iControlDriver",
"f5_common_networks": false,
"f5_common_external_networks": true,
"f5_device_type": "external",
"f5_external_physical_mappings": [
Expand Down
41 changes: 40 additions & 1 deletion test/functional/neutronless/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ def __repr__(self):

@pytest.fixture()
def icd_config():
relative = get_relative_path()
basic_agent_config = str("{}/f5-openstack-agent/test/functional/config"
"/basic_agent_config.json".format(relative))
oslo_config_filename = (
os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../config/basic_agent_config.json')
basic_agent_config)
)
OSLO_CONFIGS = json.load(open(oslo_config_filename))

Expand All @@ -84,3 +87,39 @@ def icd_config():
except AttributeError:
config['f5_vtep_selfip_name'] = "selfip.external"
return config


@pytest.fixture()
def get_relative_path():
"""Discovers the relative path to the start of the repo's path and returns
This test fixture will find the relative path of the beginning of the repo.
This path is then returned. If it is discovered that:
./f5-openstack-agent/test/functional/neutronless/
Is not a full path, then it will raise and AssertionError. If the user
executes this within a non-existent or partial repo that is fake or
unexpected, then it is assumed any subsequent test would fail.
The purpose of this code is to free up some tests from having to be run
from an explicit point of reference from within the repo's many possible
paths or tributaries.
"""
current = os.getcwd()
repo_name = "f5-openstack-agent"
expected_relative = [repo_name, 'test', 'functional', 'neutronless']
relative_path = list()
for level in current.split("/"):
if level == repo_name:
break
relative_path.append(level)
else:
raise AssertionError(
"{} is not in your path! Please be "
"within the repo!".format(repo_name))
found = list(relative_path)
found.extend(expected_relative)
discovered = '/'.join(found)
assert os.path.isdir('/'.join(found)), \
"{} does not exist!".format(discovered)
return '/'.join(relative_path)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from copy import deepcopy
from f5_openstack_agent.lbaasv2.drivers.bigip.icontrol_driver import \
iControlDriver
import json
Expand All @@ -26,6 +25,7 @@
from ..testlib.fake_rpc import FakeRPCPlugin
from ..testlib.service_reader import LoadbalancerReader
from ..testlib.resource_validator import ResourceValidator
from ..conftest import get_relative_path

requests.packages.urllib3.disable_warnings()

Expand All @@ -34,9 +34,13 @@

@pytest.fixture(scope="module")
def services():
# ./f5-openstack-agent/test/functional/neutronless/conftest.py
relative = get_relative_path()
snat_pool_json = str("{}/f5-openstack-agent/test/functional/testdata/"
"service_requests/snat_pool.json".format(relative))
neutron_services_filename = (
os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../testdata/service_requests/snat_pool.json')
snat_pool_json)
)
return (json.load(open(neutron_services_filename)))

Expand Down
6 changes: 4 additions & 2 deletions test/functional/symbols.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"bigip_mgmt_ip": "192.168.1.1",
"bigip_mgmt_ip": "10.190.7.183",
"bigip_mgmt_ip_public": "10.190.7.183",
"bigip_username": "admin",
"bigip_password": "admin"
"bigip_password": "admin",
"f5_vtep_selfip_name": "selfip.client"
}

0 comments on commit 433f750

Please sign in to comment.