Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OPENSTACK-2896] remove net/subnet cache #1224

Open
wants to merge 1 commit into
base: pike-rj
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion f5lbaasdriver/v2/bigip/constants_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

# service builder constants
VIF_TYPE = 'f5'
NET_CACHE_SECONDS = 1800

# SUPPORTED PROVIDERNET TUNNEL NETWORK TYPES
TUNNEL_TYPES = ['vxlan', 'gre']
Expand Down
85 changes: 23 additions & 62 deletions f5lbaasdriver/v2/bigip/service_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import datetime
import json

from oslo_config import cfg
from oslo_log import helpers as log_helpers
from oslo_log import log as logging

from f5lbaasdriver.v2.bigip import constants_v2
from f5lbaasdriver.v2.bigip.disconnected_service import DisconnectedService
from f5lbaasdriver.v2.bigip import exceptions as f5_exc
from f5lbaasdriver.v2.bigip import neutron_client as q_client
Expand All @@ -46,21 +44,12 @@ def __init__(self, driver):
"""Get full service definition from loadbalancer id."""
self.driver = driver

self.net_cache = {}
self.subnet_cache = {}
self.last_cache_update = datetime.datetime.fromtimestamp(0)
self.plugin = self.driver.plugin
self.disconnected_service = DisconnectedService()
self.q_client = q_client.F5NetworksNeutronClient(self.plugin)

def build(self, context, loadbalancer, agent, **kwargs):
"""Get full service definition from loadbalancer ID."""
# Invalidate cache if it is too old
if ((datetime.datetime.now() - self.last_cache_update).seconds >
constants_v2.NET_CACHE_SECONDS):
self.net_cache = {}
self.subnet_cache = {}

service = {}
with context.session.begin(subtransactions=True):
LOG.debug('Building service definition entry for %s'
Expand All @@ -75,7 +64,7 @@ def build(self, context, loadbalancer, agent, **kwargs):
# Get the subnet network associated with the VIP.
subnet_map = {}
subnet_id = loadbalancer.vip_subnet_id
vip_subnet = self._get_subnet_cached(
vip_subnet = self._get_subnet(
context,
subnet_id
)
Expand All @@ -86,7 +75,7 @@ def build(self, context, loadbalancer, agent, **kwargs):
vip_port = service['loadbalancer']['vip_port']
network_id = vip_port['network_id']
service['loadbalancer']['network_id'] = network_id
network = self._get_network_cached(
network = self._get_network(
context,
network_id
)
Expand Down Expand Up @@ -216,57 +205,29 @@ def _get_extended_loadbalancer(self, context, loadbalancer):
return loadbalancer_dict

@log_helpers.log_method_call
def _get_subnet_cached(self, context, subnet_id):
"""Retrieve subnet from cache if available; otherwise, from Neutron."""
if subnet_id not in self.subnet_cache:
subnet = self.plugin.db._core_plugin.get_subnet(
context,
subnet_id
)
self.subnet_cache[subnet_id] = subnet
return self.subnet_cache[subnet_id]

@log_helpers.log_method_call
def _get_network_cached(self, context, network_id):
"""Retrieve network from cache or from Neutron."""
if network_id not in self.net_cache:
network = self.plugin.db._core_plugin.get_network(
context,
network_id
)
if 'provider:network_type' not in network:
network['provider:network_type'] = 'undefined'
if 'provider:segmentation_id' not in network:
network['provider:segmentation_id'] = 0
self.net_cache[network_id] = network

return self.net_cache[network_id]
def _get_subnet(self, context, subnet_id):
"""Retrieve subnet from Neutron."""
subnet = self.plugin.db._core_plugin.get_subnet(
context,
subnet_id
)
return subnet

@log_helpers.log_method_call
def _get_member_network_cached(self, context, network_id):
"""Retrieve network from cache or from Neutron."""
if network_id not in self.net_cache:
network = self.plugin.db._core_plugin.get_network(
context,
network_id
)
if 'provider:network_type' not in network:
network['provider:network_type'] = 'undefined'
if 'provider:segmentation_id' not in network:
network['provider:segmentation_id'] = 0
if 'segments' in network:
LOG.info("afred Begin net_dict is %s.", network)
for segment in network['segments']:
if segment['provider:network_type'] == 'vlan':
network['provider:network_type'] = 'vlan'
network['provider:segmentation_id'] = segment[
'provider:segmentation_id']
network['provider:physical_network'] = segment[
'provider:physical_network']
LOG.info("afred End net_dict is %s.", network)
self.net_cache[network_id] = network

return self.net_cache[network_id]
def _get_network(self, context, network_id):
"""Retrieve network from Neutron."""
network = self.plugin.db._core_plugin.get_network(
context,
network_id
)
LOG.debug("Network %s obtained from core plugin is: %s",
network_id, network)

if 'provider:network_type' not in network:
network['provider:network_type'] = 'undefined'
if 'provider:segmentation_id' not in network:
network['provider:segmentation_id'] = 0
return network

@log_helpers.log_method_call
def _populate_loadbalancer_network_vteps(
Expand Down