Skip to content

Commit

Permalink
Merge pull request #173 from fnordahl/add-cms-plugin
Browse files Browse the repository at this point in the history
ovn-tester: Add CMS plugin support.
  • Loading branch information
dceara authored Sep 28, 2023
2 parents f19d060 + bc24b19 commit 6ad7870
Show file tree
Hide file tree
Showing 55 changed files with 173 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
flake8 --ignore=E203,W504,W503 .
- name: Black
run: |
black -l 79 -S --check --diff .
black --check --diff .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/runtime
/test_results
__pycache__
1 change: 1 addition & 0 deletions copyright
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Numan Siddique [email protected]
Files: *
Copyright: (c) 2020 VMware, Inc.
(c) 2020-2023 RedHat, Inc.
(c) 2023 Canonical
License: Apache-2.0

Files: logo.png
Expand Down
1 change: 1 addition & 0 deletions ovn-fake-multinode-utils/translate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GlobalConfig:
cleanup: bool = False
run_ipv4: bool = True
run_ipv6: bool = False
cms_name: str = ''


def calculate_node_remotes(
Expand Down
Empty file added ovn-tester/cms/__init__.py
Empty file.
1 change: 1 addition & 0 deletions ovn-tester/cms/ovn_kubernetes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ovn_kubernetes import * # noqa
37 changes: 37 additions & 0 deletions ovn-tester/cms/ovn_kubernetes/ovn_kubernetes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from ovn_context import Context
from ovn_workload import WorkerNode, Cluster
from ovn_utils import DualStackSubnet


OVN_HEATER_CMS_PLUGIN = 'OVNKubernetes'


class OVNKubernetes:
@staticmethod
def create_nodes(cluster_config, workers):
mgmt_net = cluster_config.node_net
mgmt_ip = mgmt_net.ip + 2
internal_net = cluster_config.internal_net
external_net = cluster_config.external_net
gw_net = cluster_config.gw_net
worker_nodes = [
WorkerNode(
workers[i % len(workers)],
f'ovn-scale-{i}',
mgmt_net,
mgmt_ip + i,
DualStackSubnet.next(internal_net, i),
DualStackSubnet.next(external_net, i),
gw_net,
i,
)
for i in range(cluster_config.n_workers)
]
return worker_nodes

@staticmethod
def prepare_test(central_node, worker_nodes, cluster_cfg, brex_cfg):
ovn = Cluster(central_node, worker_nodes, cluster_cfg, brex_cfg)
with Context(ovn, 'prepare_test'):
ovn.start()
return ovn
33 changes: 33 additions & 0 deletions ovn-tester/cms/ovn_kubernetes/tests/base_cluster_bringup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from collections import namedtuple

from ovn_context import Context
from ovn_ext_cmd import ExtCmd

ClusterBringupCfg = namedtuple('ClusterBringupCfg', ['n_pods_per_node'])


class BaseClusterBringup(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super().__init__(config, central_node, worker_nodes)
test_config = config.get('base_cluster_bringup', dict())
self.config = ClusterBringupCfg(
n_pods_per_node=test_config.get('n_pods_per_node', 0),
)

def run(self, ovn, global_cfg):
# create ovn topology
with Context(
ovn, 'base_cluster_bringup', len(ovn.worker_nodes)
) as ctx:
ovn.create_cluster_router('lr-cluster')
ovn.create_cluster_join_switch('ls-join')
ovn.create_cluster_load_balancer('lb-cluster', global_cfg)
for i in ctx:
worker = ovn.worker_nodes[i]
worker.provision(ovn)
ports = worker.provision_ports(
ovn, self.config.n_pods_per_node
)
worker.provision_load_balancers(ovn, ports, global_cfg)
worker.ping_ports(ovn, ports)
ovn.provision_lb_group()
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

class ClusterDensity(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super(ClusterDensity, self).__init__(
config, central_node, worker_nodes
)
super().__init__(config, central_node, worker_nodes)
test_config = config.get('cluster_density', dict())
self.config = ClusterDensityCfg(
n_runs=test_config.get('n_runs', 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class DensityHeavy(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super(DensityHeavy, self).__init__(config, central_node, worker_nodes)
super().__init__(config, central_node, worker_nodes)
test_config = config.get('density_heavy', dict())
pods_vip_ratio = test_config.get(
'pods_vip_ratio', DENSITY_PODS_VIP_RATIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class DensityLight(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super(DensityLight, self).__init__(config, central_node, worker_nodes)
super().__init__(config, central_node, worker_nodes)
test_config = config.get('density_light', dict())
self.config = DensityCfg(
n_pods=test_config.get('n_pods', 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class NetPol(ExtCmd):
def __init__(self, name, config, central_node, worker_nodes):
super(NetPol, self).__init__(config, central_node, worker_nodes)
super().__init__(config, central_node, worker_nodes)
test_config = config.get(name, dict())
self.config = NpCfg(
n_ns=test_config.get('n_ns', 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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


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

def run(self, ovn, global_cfg):
self.init(ovn, global_cfg)
super().run(ovn, global_cfg)
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

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


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

def run(self, ovn, global_cfg):
self.init(ovn, global_cfg)
super().run(ovn, global_cfg, True)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class ServiceRoute(ExtCmd):
def __init__(self, config, central_node, worker_nodes, global_cfg):
super(ServiceRoute, self).__init__(config, central_node, worker_nodes)
super().__init__(config, central_node, worker_nodes)
test_config = config.get('service_route', dict())
self.config = ServiceRouteCfg(
n_lb=test_config.get('n_lb', 16),
Expand Down
4 changes: 1 addition & 3 deletions ovn-tester/ovn_ext_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# matching central containers
class CentralNodeWrapper(Sandbox):
def __init__(self, central_node, container):
super(CentralNodeWrapper, self).__init__(
central_node.phys_node, container
)
super().__init__(central_node.phys_node, container)


class ExtCmdUnit:
Expand Down
87 changes: 27 additions & 60 deletions ovn-tester/ovn_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
import time

from collections import namedtuple
from ovn_context import Context
from ovn_sandbox import PhysicalNode
from ovn_workload import BrExConfig, ClusterConfig
from ovn_workload import CentralNode, WorkerNode, Cluster
from ovn_workload import BrExConfig, CentralNode, ClusterConfig
from ovn_utils import DualStackSubnet
from ovs.stream import Stream


GlobalCfg = namedtuple(
'GlobalCfg', ['log_cmds', 'cleanup', 'run_ipv4', 'run_ipv6']
'GlobalCfg', ['log_cmds', 'cleanup', 'run_ipv4', 'run_ipv6', 'cms_name']
)

ClusterBringupCfg = namedtuple('ClusterBringupCfg', ['n_pods_per_node'])


def usage(name):
print(
Expand Down Expand Up @@ -125,11 +121,7 @@ def read_config(config):
physical_net=cluster_args.get('physical_net', 'providernet'),
)

bringup_args = config.get('base_cluster_bringup', dict())
bringup_cfg = ClusterBringupCfg(
n_pods_per_node=bringup_args.get('n_pods_per_node', 10)
)
return global_cfg, cluster_cfg, brex_cfg, bringup_cfg
return global_cfg, cluster_cfg, brex_cfg


def setup_logging(global_cfg):
Expand Down Expand Up @@ -164,30 +156,35 @@ def setup_logging(global_cfg):
RESERVED = [
'global',
'cluster',
'base_cluster_bringup',
'ext_cmd',
]


def load_cms(cms_name):
mod = importlib.import_module(f'cms.{cms_name}')
class_name = getattr(mod, 'OVN_HEATER_CMS_PLUGIN')
cls = getattr(mod, class_name)
return cls()


def configure_tests(yaml, central_node, worker_nodes, global_cfg):
tests = []
for section, cfg in yaml.items():
if section in RESERVED:
continue

mod = importlib.import_module(f'tests.{section}')
mod = importlib.import_module(
f'cms.{global_cfg.cms_name}.tests.{section}'
)
class_name = ''.join(s.title() for s in section.split('_'))
cls = getattr(mod, class_name)
tests.append(cls(yaml, central_node, worker_nodes, global_cfg))
return tests


def create_nodes(cluster_config, central, workers):
def create_central_nodes(cluster_config, central):
mgmt_net = cluster_config.node_net
mgmt_ip = mgmt_net.ip + 2
internal_net = cluster_config.internal_net
external_net = cluster_config.external_net
gw_net = cluster_config.gw_net
db_containers = (
['ovn-central-1', 'ovn-central-2', 'ovn-central-3']
if cluster_config.clustered_db
Expand All @@ -199,20 +196,7 @@ def create_nodes(cluster_config, central, workers):
central_node = CentralNode(
central, db_containers, relay_containers, mgmt_net, mgmt_ip
)
worker_nodes = [
WorkerNode(
workers[i % len(workers)],
f'ovn-scale-{i}',
mgmt_net,
mgmt_ip + i,
DualStackSubnet.next(internal_net, i),
DualStackSubnet.next(external_net, i),
gw_net,
i,
)
for i in range(cluster_config.n_workers)
]
return central_node, worker_nodes
return central_node


def set_ssl_keys(cluster_cfg):
Expand All @@ -221,30 +205,6 @@ def set_ssl_keys(cluster_cfg):
Stream.ssl_set_ca_cert_file(cluster_cfg.ssl_cacert)


def prepare_test(central_node, worker_nodes, cluster_cfg, brex_cfg):
if cluster_cfg.enable_ssl:
set_ssl_keys(cluster_cfg)
ovn = Cluster(central_node, worker_nodes, cluster_cfg, brex_cfg)
with Context(ovn, "prepare_test"):
ovn.start()
return ovn


def run_base_cluster_bringup(ovn, bringup_cfg, global_cfg):
# create ovn topology
with Context(ovn, "base_cluster_bringup", len(ovn.worker_nodes)) as ctx:
ovn.create_cluster_router("lr-cluster")
ovn.create_cluster_join_switch("ls-join")
ovn.create_cluster_load_balancer("lb-cluster", global_cfg)
for i in ctx:
worker = ovn.worker_nodes[i]
worker.provision(ovn)
ports = worker.provision_ports(ovn, bringup_cfg.n_pods_per_node)
worker.provision_load_balancers(ovn, ports, global_cfg)
worker.ping_ports(ovn, ports)
ovn.provision_lb_group()


if __name__ == '__main__':
if len(sys.argv) != 3:
usage(sys.argv[0])
Expand All @@ -253,19 +213,26 @@ def run_base_cluster_bringup(ovn, bringup_cfg, global_cfg):
with open(sys.argv[2], 'r') as yaml_file:
config = yaml.safe_load(yaml_file)

global_cfg, cluster_cfg, brex_cfg, bringup_cfg = read_config(config)
global_cfg, cluster_cfg, brex_cfg = read_config(config)

setup_logging(global_cfg)

if not global_cfg.run_ipv4 and not global_cfg.run_ipv6:
if not global_cfg.cms_name or (
not global_cfg.run_ipv4 and not global_cfg.run_ipv6
):
raise ovn_exceptions.OvnInvalidConfigException()

cms = load_cms(global_cfg.cms_name)

central, workers = read_physical_deployment(sys.argv[1], global_cfg)
central_node, worker_nodes = create_nodes(cluster_cfg, central, workers)
central_node = create_central_nodes(cluster_cfg, central)
worker_nodes = cms.create_nodes(cluster_cfg, workers)
tests = configure_tests(config, central_node, worker_nodes, global_cfg)

ovn = prepare_test(central_node, worker_nodes, cluster_cfg, brex_cfg)
run_base_cluster_bringup(ovn, bringup_cfg, global_cfg)
if cluster_cfg.enable_ssl:
set_ssl_keys(cluster_cfg)

ovn = cms.prepare_test(central_node, worker_nodes, cluster_cfg, brex_cfg)
for test in tests:
test.run(ovn, global_cfg)
sys.exit(0)
Loading

0 comments on commit 6ad7870

Please sign in to comment.