Skip to content

Commit

Permalink
ovn-tester: Use Cluster instead of central + worker tuples.
Browse files Browse the repository at this point in the history
A cluster is a collection of central and worker nodes (+ relays).

Signed-off-by: Dumitru Ceara <[email protected]>
  • Loading branch information
dceara committed Sep 28, 2023
1 parent 5ceed6f commit 15ddc8b
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 68 deletions.
54 changes: 27 additions & 27 deletions ovn-tester/cms/ovn_kubernetes/ovn_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@

class OVNKubernetes:
@staticmethod
def create_nodes(cluster_cfg, workers):
def add_cluster_worker_nodes(cluster, workers):
cluster_cfg = cluster.cluster_cfg

# Allocate worker IPs after central and relay IPs.
mgmt_ip = cluster_cfg.node_net.ip + 2
mgmt_ip += 3 if cluster_cfg.clustered_db else 1
mgmt_ip += cluster_cfg.n_relays
mgmt_ip = (
cluster_cfg.node_net.ip
+ 2
+ len(cluster.central_nodes)
+ len(cluster.relay_nodes)
)

protocol = "ssl" if cluster_cfg.enable_ssl else "tcp"
internal_net = cluster_cfg.internal_net
external_net = cluster_cfg.external_net
gw_net = cluster_cfg.gw_net
worker_nodes = [
WorkerNode(
workers[i % len(workers)],
f'ovn-scale-{i}',
mgmt_ip + i,
protocol,
DualStackSubnet.next(internal_net, i),
DualStackSubnet.next(external_net, i),
gw_net,
i,
)
for i in range(cluster_cfg.n_workers)
]
return worker_nodes
cluster.add_workers(
[
WorkerNode(
workers[i % len(workers)],
f'ovn-scale-{i}',
mgmt_ip + i,
protocol,
DualStackSubnet.next(internal_net, i),
DualStackSubnet.next(external_net, i),
gw_net,
i,
)
for i in range(cluster_cfg.n_workers)
]
)

@staticmethod
def prepare_test(
central_nodes, relay_nodes, worker_nodes, cluster_cfg, brex_cfg
):
ovn = Cluster(
central_nodes, relay_nodes, worker_nodes, cluster_cfg, brex_cfg
)
with Context(ovn, 'prepare_test'):
ovn.start()
return ovn
def prepare_test(cluster):
with Context(cluster, 'prepare_test'):
cluster.start()
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/base_cluster_bringup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class BaseClusterBringup(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('base_cluster_bringup', dict())
self.config = ClusterBringupCfg(
n_pods_per_node=test_config.get('n_pods_per_node', 0),
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/cluster_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@


class ClusterDensity(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('cluster_density', dict())
self.config = ClusterDensityCfg(
n_runs=test_config.get('n_runs', 0),
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/density_heavy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@


class DensityHeavy(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('density_heavy', dict())
pods_vip_ratio = test_config.get(
'pods_vip_ratio', DENSITY_PODS_VIP_RATIO
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/density_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class DensityLight(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('density_light', dict())
self.config = DensityCfg(
n_pods=test_config.get('n_pods', 0),
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/netpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


class NetPol(ExtCmd):
def __init__(self, name, config, central_node, worker_nodes):
super().__init__(config, central_node, worker_nodes)
def __init__(self, name, config, cluster):
super().__init__(config, cluster)
test_config = config.get(name, dict())
self.config = NpCfg(
n_ns=test_config.get('n_ns', 0),
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/netpol_cross_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class NetpolCrossNs(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('netpol_cross', dict())
self.config = NpCrossNsCfg(
n_ns=test_config.get('n_ns', 0),
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/netpol_large.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class NetpolLarge(NetPol):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__('netpol_large', config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__('netpol_large', config, cluster)

def run(self, ovn, global_cfg):
self.init(ovn, global_cfg)
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/netpol_multitenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


class NetpolMultitenant(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('netpol_multitenant', dict())
ranges = [
NsRange(
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/netpol_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class NetpolSmall(NetPol):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__('netpol_small', config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__('netpol_small', config, cluster)

def run(self, ovn, global_cfg):
self.init(ovn, global_cfg)
Expand Down
4 changes: 2 additions & 2 deletions ovn-tester/cms/ovn_kubernetes/tests/service_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class ServiceRoute(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
def __init__(self, config, cluster, global_cfg):
super().__init__(config, cluster)
test_config = config.get('service_route', dict())
self.config = ServiceRouteCfg(
n_lb=test_config.get('n_lb', 16),
Expand Down
12 changes: 7 additions & 5 deletions ovn-tester/ovn_ext_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class ExtCmdUnit:
def __init__(self, conf, central_node, worker_nodes):
def __init__(self, conf, cluster):
self.iteration = conf.get('iteration')
self.cmd = conf.get('cmd')
self.test = conf.get('test')
Expand All @@ -14,9 +14,11 @@ def __init__(self, conf, central_node, worker_nodes):
self.pid_opt = conf.get('pid_opt', '')

node = conf.get('node')
self.nodes = [n for n in worker_nodes if fnmatch(n.container, node)]
self.nodes = [
n for n in cluster.worker_nodes if fnmatch(n.container, node)
]
self.nodes.extend(
[n for n in central_nodes if fnmatch(n.container, node)]
[n for n in cluster.central_nodes if fnmatch(n.container, node)]
)

def is_valid(self):
Expand Down Expand Up @@ -47,10 +49,10 @@ def _node_exec(self, node):


class ExtCmd:
def __init__(self, config, central_node, worker_nodes):
def __init__(self, config, cluster):
self.cmd_map = defaultdict(list)
for ext_cmd in config.get('ext_cmd', list()):
cmd_unit = ExtCmdUnit(ext_cmd, central_node, worker_nodes)
cmd_unit = ExtCmdUnit(ext_cmd, cluster)
if cmd_unit.is_valid():
self.cmd_map[(cmd_unit.iteration, cmd_unit.test)].append(
cmd_unit
Expand Down
28 changes: 16 additions & 12 deletions ovn-tester/ovn_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

from collections import namedtuple
from ovn_sandbox import PhysicalNode
from ovn_workload import BrExConfig, CentralNode, ClusterConfig, RelayNode
from ovn_workload import (
BrExConfig,
CentralNode,
Cluster,
ClusterConfig,
RelayNode,
)
from ovn_utils import DualStackSubnet
from ovs.stream import Stream

Expand Down Expand Up @@ -166,7 +172,7 @@ def load_cms(cms_name):
return cls()


def configure_tests(yaml, central_nodes, worker_nodes, global_cfg):
def configure_tests(yaml, cluster, global_cfg):
tests = []
for section, cfg in yaml.items():
if section in RESERVED:
Expand All @@ -177,11 +183,11 @@ def configure_tests(yaml, central_nodes, worker_nodes, global_cfg):
)
class_name = ''.join(s.title() for s in section.split('_'))
cls = getattr(mod, class_name)
tests.append(cls(yaml, central_nodes, worker_nodes, global_cfg))
tests.append(cls(yaml, cluster, global_cfg))
return tests


def create_central_nodes(cluster_cfg, central):
def create_cluster(cluster_cfg, central, brex_cfg):
protocol = "ssl" if cluster_cfg.enable_ssl else "tcp"
mgmt_ip = cluster_cfg.node_net.ip + 2
db_containers = (
Expand All @@ -200,7 +206,7 @@ def create_central_nodes(cluster_cfg, central):
RelayNode(central, f'ovn-relay-{i + 1}', mgmt_ip + i, protocol)
for i in range(cluster_cfg.n_relays)
]
return central_nodes, relay_nodes
return Cluster(central_nodes, relay_nodes, cluster_cfg, brex_cfg)


def set_ssl_keys(cluster_cfg):
Expand Down Expand Up @@ -229,16 +235,14 @@ def set_ssl_keys(cluster_cfg):
cms = load_cms(global_cfg.cms_name)

central, workers = read_physical_deployment(sys.argv[1], global_cfg)
central_nodes, relay_nodes = create_central_nodes(cluster_cfg, central)
worker_nodes = cms.create_nodes(cluster_cfg, workers)
tests = configure_tests(config, central_nodes, worker_nodes, global_cfg)
cluster = create_cluster(cluster_cfg, central, brex_cfg)
cms.add_cluster_worker_nodes(cluster, workers)
tests = configure_tests(config, cluster, global_cfg)

if cluster_cfg.enable_ssl:
set_ssl_keys(cluster_cfg)

ovn = cms.prepare_test(
central_nodes, relay_nodes, worker_nodes, cluster_cfg, brex_cfg
)
cms.prepare_test(cluster)
for test in tests:
test.run(ovn, global_cfg)
test.run(cluster, global_cfg)
sys.exit(0)
9 changes: 5 additions & 4 deletions ovn-tester/ovn_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,11 @@ def provision_vips_to_load_balancers(self, backend_lists, version):


class Cluster:
def __init__(
self, central_nodes, relay_nodes, worker_nodes, cluster_cfg, brex_cfg
):
def __init__(self, central_nodes, relay_nodes, cluster_cfg, brex_cfg):
# In clustered mode use the first node for provisioning.
self.central_nodes = central_nodes
self.relay_nodes = relay_nodes
self.worker_nodes = worker_nodes
self.worker_nodes = []
self.cluster_cfg = cluster_cfg
self.brex_cfg = brex_cfg
self.nbctl = None
Expand All @@ -757,6 +755,9 @@ def __init__(
self.last_selected_worker = 0
self.n_ns = 0

def add_workers(self, worker_nodes):
self.worker_nodes.extend(worker_nodes)

def start(self):
for c in self.central_nodes:
c.start(
Expand Down

0 comments on commit 15ddc8b

Please sign in to comment.