Skip to content

Commit

Permalink
CMS Openstack: Evenly distribute GW chassis
Browse files Browse the repository at this point in the history
Attempt to evenly distribute load when assigning Gateway
Chassis to project routers.

Signed-off-by: Martin Kalcok <[email protected]>
  • Loading branch information
mkalcok committed Sep 26, 2023
1 parent 9d006a3 commit 2ef1fae
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
53 changes: 46 additions & 7 deletions ovn-tester/cms/openstack/openstack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import random
import uuid

from dataclasses import dataclass
from typing import List, Optional, Dict

Expand Down Expand Up @@ -64,6 +66,8 @@ def uuid(self) -> str:
class OpenStackCloud(Cluster):
"""Representation of Openstack cloud/deployment."""

MAX_GW_PER_ROUTER = 5

def __init__(self, central_node, worker_nodes, cluster_cfg, brex_cfg):
super().__init__(central_node, worker_nodes, cluster_cfg, brex_cfg)
self.router = None
Expand Down Expand Up @@ -98,19 +102,19 @@ def next_int_net(self):

return network

def new_project(
self, gw_nodes: Optional[List[ChassisNode]] = None
) -> Project:
def new_project(self, gw_nodes: int = 0) -> Project:
"""Create new Project/Tenant in the Openstack cloud.
Following things are provisioned for the Project:
* Project router
* Internal network
If 'gw_nodes' are provided, external network is also provisioned
with default route through the gateway nodes.
If 'gw_nodes' count is more than 0, external network is also
provisioned with default route through the gateway nodes. Gateway
nodes and their priority are selected at random from all
available 'worker_nodes'.
:param gw_nodes: Optional list of Chassis that act like gateways.
:param gw_nodes: Number of gateway chassis to use.
:return: New Project object that is automatically also added
to 'self.projects' list.
"""
Expand All @@ -121,7 +125,10 @@ def new_project(
)

if gw_nodes:
self.add_external_network_to_project(project, gw_nodes)
self.add_external_network_to_project(
project,
self._get_gateway_chassis(gw_nodes),
)

self.add_internal_network_to_project(project, self.external_port)
self._projects.append(project)
Expand Down Expand Up @@ -204,6 +211,38 @@ def add_internal_network_to_project(
if snat_port is not None:
self.nbctl.nat_add(project.router, snat_port.ip, snated_network)

def _get_gateway_chassis(self, count: int = 1) -> List[ChassisNode]:
"""Return list of Gateway Chassis with size defined by 'count'.
Chassis are picked at random from all available 'worker_nodes' to
attempt to evenly distribute gateway loads.
Parameter 'count' can't be larger than number of all available gateways
or larger than 5 which is hardcoded maximum of gateways per router in
Neutron.
"""
warn = ""
worker_count = len(self.worker_nodes)
if count > worker_count:
count = worker_count
warn += (
f"{count} Gateway chassis requested but only "
f"{worker_count} available.\n"
)

if count > self.MAX_GW_PER_ROUTER:
count = self.MAX_GW_PER_ROUTER
warn += (
f"Maximum number of gateways per router "
f"is {self.MAX_GW_PER_ROUTER}\n"
)

if warn:
warn += f"Using only {count} Gateways per router."
log.warning(warn)

return random.sample(self.worker_nodes, count)

def _create_project_net(self, net_name: str, mtu: int = 1500) -> LSwitch:
"""Create Logical Switch that represents neutron network.
Expand Down
3 changes: 2 additions & 1 deletion ovn-tester/cms/openstack/tests/base_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class BaseOpenstackConfig:

n_projects: int = 1
n_gws_per_project: int = 1


class BaseOpenstack(ExtCmd):
Expand All @@ -36,4 +37,4 @@ def run(self, ovn: OpenStackCloud, global_cfg):
worker_node.provision(ovn)

for _ in range(self.config.n_projects):
_ = ovn.new_project(gw_nodes=ovn.worker_nodes)
_ = ovn.new_project(gw_nodes=self.config.n_gws_per_project)
3 changes: 2 additions & 1 deletion test-scenarios/openstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cluster:
n_workers: 3

base_openstack:
n_projects: 3
n_projects: 3
n_gws_per_project: 3

0 comments on commit 2ef1fae

Please sign in to comment.