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

Bail out configuring ovs if no OVNSDB available #96

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
36 changes: 22 additions & 14 deletions lib/charms/ovn_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,20 +1118,28 @@ def configure_ovs(self, sb_conn, mlockall_changed):
self.options.ovn_cert,
self.options.ovn_ca_cert)

# The local ``ovn-controller`` process will retrieve information about
# how to connect to OVN from the local Open vSwitch database.
cmd = ('ovs-vsctl',)
for ovs_ext_id in ('external-ids:ovn-encap-type=geneve',
'external-ids:ovn-encap-ip={}'
.format(self.get_data_ip()),
'external-ids:system-id={}'
.format(self.get_ovs_hostname()),
'external-ids:ovn-remote={}'.format(sb_conn),
'external_ids:ovn-match-northd-version={}'
.format(self.options.enable_version_pinning),
):
cmd = cmd + ('--', 'set', 'open-vswitch', '.', ovs_ext_id)
self.run(*cmd)
if sb_conn:
# The local ``ovn-controller`` process will retrieve information
# about how to connect to OVN from the local Open vSwitch
# database.
cmd = ('ovs-vsctl',)
for ovs_ext_id in ('external-ids:ovn-encap-type=geneve',
'external-ids:ovn-encap-ip={}'
.format(self.get_data_ip()),
'external-ids:system-id={}'
.format(self.get_ovs_hostname()),
'external-ids:ovn-remote={}'.format(sb_conn),
'external_ids:ovn-match-northd-version={}'
.format(self.options.enable_version_pinning),
):
cmd = cmd + ('--', 'set', 'open-vswitch', '.', ovs_ext_id)
self.run(*cmd)
else:
ch_core.hookenv.log('could not configure ovs due to unavailable '
'sbdb connection info - ovn-central relation '
'no longer available?',
level=ch_core.hookenv.WARNING)

if self.enable_openstack:
# OpenStack Nova expects the local OVSDB server to listen to
# TCP port 6640 on localhost. We use this for the OVN metadata
Expand Down
10 changes: 9 additions & 1 deletion unit_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@

import sys

import mock

sys.path.append('lib')

# Mock out charmhelpers so that we can test without it.
import charms_openstack.test_mocks # noqa

# charms.openstack (commit b90327) re-introduced a dependency on charmhelpers
# so we need to mock that out explicitly here since we do not install
# charmhelpers as a test dependency.
sys.modules['charmhelpers.contrib.openstack.utils'] = mock.MagicMock()
sys.modules['charmhelpers.contrib.openstack.utils'].\
CompareOpenStackReleases = mock.MagicMock()
charms_openstack.test_mocks.mock_charmhelpers()

import mock
import charms


Expand Down
20 changes: 20 additions & 0 deletions unit_tests/test_reactive_ovn_chassis_charm_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ def test_configure_ovs(self):
self.charm.configure_iptables_rules.assert_called_once_with()
self.charm.assess_status.assert_called_once_with()

def test_configure_ovs_no_sb_conn(self):
self.patch_object(handlers.reactive, 'endpoint_from_flag')
self.patch_object(handlers.charm, 'optional_interfaces')
self.patch_object(handlers.reactive, 'set_flag')
self.patch_object(handlers.reactive, 'is_flag_set', return_value=True)
ovsdb = mock.MagicMock()
ovsdb.db_sb_connection_strs = []
self.endpoint_from_flag.return_value = ovsdb
handlers.configure_ovs()
self.charm.configure_ovs.assert_called_once_with(
','.join(ovsdb.db_sb_connection_strs), True)
self.charm.render_with_interfaces.assert_called_once_with(
self.optional_interfaces((ovsdb,),
'nova-compute.connected',
'amqp.connected'))
self.set_flag.assert_called_once_with('config.rendered')
self.charm.configure_bridges.assert_called_once_with()
self.charm.configure_iptables_rules.assert_called_once_with()
self.charm.assess_status.assert_called_once_with()

def test_configure_nrpe(self):
self.patch_object(handlers.reactive, 'endpoint_from_flag')
self.endpoint_from_flag.return_value = 'nrpe-external-master'
Expand Down