def neutron_plugin_api_changed(): packages_to_purge = [] if use_dvr(): install_packages() # per 17.08 release notes L3HA + DVR is a Newton+ feature _os_release = os_release('neutron-common', base='icehouse') if (use_l3ha() and CompareOpenStackReleases(_os_release) >= 'newton'): install_l3ha_packages() # NOTE(hopem): don't uninstall keepalived if not using l3ha since that # results in neutron-l3-agent also being uninstalled (see LP 1819499). else: packages_to_purge = deepcopy(DVR_PACKAGES) packages_to_purge.extend(L3HA_PACKAGES) if packages_to_purge: purge_packages(packages_to_purge) # NOTE(fnordahl): It is important to write config to disk and perhaps # restart the openvswitch-swith service prior to attempting to do run-time # configuration of OVS as we may have to pass options to `ovs-ctl` for # `ovs-vswitchd` to run at all. LP: #1906280 # TODO: make restart_on_change use contextlib.contextmanager @restart_on_change({cfg: service for cfg, service in restart_map().items() if cfg == OVS_DEFAULT}) def _restart_before_runtime_config_when_required(): CONFIGS.write_all() _restart_before_runtime_config_when_required() configure_ovs() # If dvr setting has changed, need to pass that on for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid)
def _run_configure_ovs_dpdk(self, mock_config, _use_dvr, _resolve_dpdk_bridges, _resolve_dpdk_bonds, _late_init, _test_bonds): _resolve_dpdk_bridges.return_value = OrderedDict([ ('0000:001c.01', 'br-phynet1'), ('0000:001c.02', 'br-phynet2'), ('0000:001c.03', 'br-phynet3'), ]) if _test_bonds: _resolve_dpdk_bonds.return_value = OrderedDict([ ('0000:001c.01', 'bond0'), ('0000:001c.02', 'bond1'), ('0000:001c.03', 'bond2'), ]) else: _resolve_dpdk_bonds.return_value = OrderedDict() _use_dvr.return_value = True self.use_dpdk.return_value = True self.ovs_has_late_dpdk_init.return_value = _late_init mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('enable-dpdk', True) nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'netdev'), call('br-ex', 'netdev'), call('br-phynet1', 'netdev'), call('br-phynet2', 'netdev'), call('br-phynet3', 'netdev')], any_order=True ) if _test_bonds: self.dpdk_add_bridge_bond.assert_has_calls([ call('br-phynet1', 'bond0', ['dpdk0'], ['0000:001c.01']), call('br-phynet2', 'bond1', ['dpdk1'], ['0000:001c.02']), call('br-phynet3', 'bond2', ['dpdk2'], ['0000:001c.03'])], any_order=True ) self.dpdk_set_bond_config.assert_has_calls([ call('bond0', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'}), call('bond1', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'}), call('bond2', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'})], any_order=True ) else: self.dpdk_add_bridge_port.assert_has_calls([ call('br-phynet1', 'dpdk0', '0000:001c.01'), call('br-phynet2', 'dpdk1', '0000:001c.02'), call('br-phynet3', 'dpdk2', '0000:001c.03')], any_order=True )
def test_configure_ovs_doesnt_restart_service(self, mock_config, _use_dvr): _use_dvr.return_value = False mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.service_running.return_value = True nutils.configure_ovs() self.assertFalse(self.full_restart.called)
def test_configure_ovs_ovs_data_port(self, mock_config, _use_dvr): _use_dvr.return_value = False mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.ExternalPortContext.return_value = \ DummyContext(return_value=None) # Test back-compatibility i.e. port but no bridge (so br-data is # assumed) self.test_config.set('data-port', 'eth0') nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'system'), call('br-ex', 'system'), call('br-data', 'system') ]) self.assertTrue(self.add_bridge_port.called) # Now test with bridge:port format self.test_config.set('data-port', 'br-foo:eth0') self.add_bridge.reset_mock() self.add_bridge_port.reset_mock() nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'system'), call('br-ex', 'system'), call('br-data', 'system') ]) # Not called since we have a bogus bridge in data-ports self.assertFalse(self.add_bridge_port.called)
def config_changed(): # if we are paused, delay doing any config changed hooks. # It is forced on the resume. if is_unit_paused_set(): log("Unit is pause or upgrading. Skipping config_changed", "WARN") return install_packages() install_tmpfilesd() # NOTE(jamespage): purge any packages as a result of py3 switch # at rocky. packages_to_purge = determine_purge_packages() request_nova_compute_restart = False if packages_to_purge: purge_packages(packages_to_purge) request_nova_compute_restart = True sysctl_settings = config('sysctl') if not is_container() and sysctl_settings: create_sysctl(sysctl_settings, '/etc/sysctl.d/50-openvswitch.conf') configure_ovs() CONFIGS.write_all() # NOTE(fnordahl): configure_sriov must be run after CONFIGS.write_all() # to allow us to enable boot time execution of init script configure_sriov() for rid in relation_ids('neutron-plugin'): neutron_plugin_joined( relation_id=rid, request_restart=request_nova_compute_restart)
def test_configure_ovs_dpdk(self, mock_config, _use_dvr, _resolve_dpdk_ports): _resolve_dpdk_ports.return_value = { '0000:001c.01': 'br-phynet1', '0000:001c.02': 'br-phynet2', '0000:001c.03': 'br-phynet3', } _use_dvr.return_value = True self.use_dpdk.return_value = True mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('enable-dpdk', True) nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'netdev'), call('br-ex', 'netdev'), call('br-phynet1', 'netdev'), call('br-phynet2', 'netdev'), call('br-phynet3', 'netdev'), ]) self.dpdk_add_bridge_port.assert_has_calls([ call('br-phynet1', 'dpdk0', port_type='dpdk'), call('br-phynet2', 'dpdk1', port_type='dpdk'), call('br-phynet3', 'dpdk2', port_type='dpdk'), ])
def test_configure_ovs_ovs_data_port(self, mock_config, _use_dvr): _use_dvr.return_value = False mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.ExternalPortContext.return_value = \ DummyContext(return_value=None) # Test back-compatibility i.e. port but no bridge (so br-data is # assumed) self.test_config.set('data-port', 'eth0') nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int'), call('br-ex'), call('br-data') ]) self.assertTrue(self.add_bridge_port.called) # Now test with bridge:port format self.test_config.set('data-port', 'br-foo:eth0') self.add_bridge.reset_mock() self.add_bridge_port.reset_mock() nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int'), call('br-ex'), call('br-data') ]) # Not called since we have a bogus bridge in data-ports self.assertFalse(self.add_bridge_port.called)
def test_configure_ovs_starts_service_if_required(self, mock_config, _use_dvr): _use_dvr.return_value = False mock_config.side_effect = self.test_config.get self.config.return_value = 'ovs' self.service_running.return_value = False nutils.configure_ovs() self.assertTrue(self.full_restart.called)
def config_changed(): install_packages() configure_ovs() CONFIGS.write_all() # NOTE(fnordahl): configure_sriov must be run after CONFIGS.write_all() # to allow us to enable boot time execution of init script configure_sriov() for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid)
def test_configure_ovs_enable_ipfix(self, mock_config): mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('plugin', 'ovs') self.test_config.set('ipfix-target', '127.0.0.1:80') nutils.configure_ovs() self.enable_ipfix.assert_has_calls([ call('br-int', '127.0.0.1:80'), call('br-ex', '127.0.0.1:80'), ])
def neutron_plugin_api_changed(): if use_dvr(): install_packages() else: purge_packages(DVR_PACKAGES) configure_ovs() CONFIGS.write_all() # If dvr setting has changed, need to pass that on for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid)
def test_configure_ovs_enable_ipfix(self, mock_config, mock_use_dvr): mock_use_dvr.return_value = False mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('ipfix-target', '127.0.0.1:80') nutils.configure_ovs() self.enable_ipfix.assert_has_calls([ call('br-int', '127.0.0.1:80'), call('br-ex', '127.0.0.1:80'), ])
def config_changed(): install_packages() if git_install_requested(): if config_value_changed('openstack-origin-git'): git_install(config('openstack-origin-git')) configure_ovs() CONFIGS.write_all() for rid in relation_ids('zeromq-configuration'): zeromq_configuration_relation_joined(rid) for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid)
def test_configure_ovs_ovs_ext_port(self, mock_config, _use_dvr): _use_dvr.return_value = True mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('ext-port', 'eth0') self.ExternalPortContext.return_value = \ DummyContext(return_value={'ext_port': 'eth0'}) nutils.configure_ovs() self.add_bridge.assert_has_calls( [call('br-int'), call('br-ex'), call('br-data')]) self.add_bridge_port.assert_called_with('br-ex', 'eth0')
def test_configure_ovs_ovs_ext_port(self, mock_config, _use_dvr): _use_dvr.return_value = True mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('ext-port', 'eth0') self.ExternalPortContext.return_value = \ DummyContext(return_value={'ext_port': 'eth0'}) nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int'), call('br-ex'), call('br-data') ]) self.add_bridge_port.assert_called_with('br-ex', 'eth0')
def test_configure_ovs_data_port_with_bridge(self, mock_config, _use_dvr): _use_dvr.return_value = False self.is_linuxbridge_interface.return_value = True mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.ExternalPortContext.return_value = \ DummyContext(return_value=None) # Now test with bridge:bridge format self.test_config.set('bridge-mappings', 'physnet1:br-foo') self.test_config.set('data-port', 'br-foo:br-juju') self.add_bridge.reset_mock() self.add_bridge_port.reset_mock() nutils.configure_ovs() self.assertTrue(self.add_ovsbridge_linuxbridge.called)
def config_changed(check_deferred_restarts=True): configure_deferred_restarts(deferrable_services()) # policy_rcd.remove_policy_file() # if we are paused, delay doing any config changed hooks. # It is forced on the resume. allowed, reason = is_hook_allowed( 'config-changed', check_deferred_restarts=check_deferred_restarts) if not allowed: log(reason, "WARN") return install_packages() install_tmpfilesd() # NOTE(jamespage): purge any packages as a result of py3 switch # at rocky. packages_to_purge = determine_purge_packages() request_nova_compute_restart = False if packages_to_purge: purge_packages(packages_to_purge) request_nova_compute_restart = True sysctl_settings = config('sysctl') if not is_container() and sysctl_settings: create_sysctl(sysctl_settings, '/etc/sysctl.d/50-openvswitch.conf') # NOTE(fnordahl): It is important to write config to disk and perhaps # restart the openvswitch-swith service prior to attempting to do run-time # configuration of OVS as we may have to pass options to `ovs-ctl` for # `ovs-vswitchd` to run at all. LP: #1906280 # TODO: make restart_on_change use contextlib.contextmanager @restart_on_change({ cfg: services for cfg, services in restart_map().items() if cfg == OVS_DEFAULT }) def _restart_before_runtime_config_when_required(): CONFIGS.write_all() _restart_before_runtime_config_when_required() configure_ovs() for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid, request_restart=request_nova_compute_restart)
def neutron_plugin_api_changed(): packages_to_purge = [] if use_dvr(): install_packages() # per 17.08 release notes L3HA + DVR is a Newton+ feature _os_release = os_release('neutron-common', base='icehouse') if (use_l3ha() and CompareOpenStackReleases(_os_release) >= 'newton'): install_l3ha_packages() # NOTE(hopem): don't uninstall keepalived if not using l3ha since that # results in neutron-l3-agent also being uninstalled (see LP 1819499). else: packages_to_purge = deepcopy(DVR_PACKAGES) packages_to_purge.extend(L3HA_PACKAGES) if packages_to_purge: purge_packages(packages_to_purge) configure_ovs() CONFIGS.write_all() # If dvr setting has changed, need to pass that on for rid in relation_ids('neutron-plugin'): neutron_plugin_joined(relation_id=rid)
def _run_configure_ovs_dpdk(self, mock_config, _use_dvr, _resolve_dpdk_bridges, _resolve_dpdk_bonds, _late_init, _test_bonds): def _resolve_port_name(pci_address, device_index, late_init): if late_init: return 'dpdk-{}'.format( hashlib.sha1(pci_address.encode('UTF-8')).hexdigest()[:7]) else: return 'dpdk{}'.format(device_index) if _test_bonds: _resolve_dpdk_bridges.return_value = OrderedDict() _resolve_dpdk_bonds.return_value = OrderedDict([ ('0000:001c.01', 'bond0'), ('0000:001c.02', 'bond1'), ('0000:001c.03', 'bond2'), ]) self.parse_data_port_mappings.return_value = OrderedDict([ ('bond0', 'br-phynet1'), ('bond1', 'br-phynet2'), ('bond2', 'br-phynet3'), ]) else: _resolve_dpdk_bridges.return_value = OrderedDict([ ('0000:001c.01', 'br-phynet1'), ('0000:001c.02', 'br-phynet2'), ('0000:001c.03', 'br-phynet3'), ]) _resolve_dpdk_bonds.return_value = OrderedDict() _use_dvr.return_value = True self.use_dpdk.return_value = True self.ovs_has_late_dpdk_init.return_value = _late_init mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('enable-dpdk', True) nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'netdev'), call('br-ex', 'netdev'), call('br-phynet1', 'netdev'), call('br-phynet2', 'netdev'), call('br-phynet3', 'netdev') ], any_order=True) if _test_bonds: self.dpdk_add_bridge_bond.assert_has_calls([ call( 'br-phynet1', 'bond0', { _resolve_port_name('0000:001c.01', 0, _late_init): '0000:001c.01' }), call( 'br-phynet2', 'bond1', { _resolve_port_name('0000:001c.02', 1, _late_init): '0000:001c.02' }), call( 'br-phynet3', 'bond2', { _resolve_port_name('0000:001c.03', 2, _late_init): '0000:001c.03' }) ], any_order=True) self.dpdk_set_bond_config.assert_has_calls([ call('bond0', { 'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast' }), call('bond1', { 'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast' }), call('bond2', { 'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast' }) ], any_order=True) else: self.dpdk_add_bridge_port.assert_has_calls([ call('br-phynet1', _resolve_port_name('0000:001c.01', 0, _late_init), '0000:001c.01'), call('br-phynet2', _resolve_port_name('0000:001c.02', 1, _late_init), '0000:001c.02'), call('br-phynet3', _resolve_port_name('0000:001c.03', 2, _late_init), '0000:001c.03') ], any_order=True)
def _run_configure_ovs_dpdk(self, mock_config, _use_dvr, _resolve_dpdk_bridges, _resolve_dpdk_bonds, _late_init, _test_bonds): def _resolve_port_name(pci_address, device_index, late_init): if late_init: return 'dpdk-{}'.format( hashlib.sha1(pci_address.encode('UTF-8')).hexdigest()[:7] ) else: return 'dpdk{}'.format(device_index) if _test_bonds: _resolve_dpdk_bridges.return_value = OrderedDict() _resolve_dpdk_bonds.return_value = OrderedDict([ ('0000:001c.01', 'bond0'), ('0000:001c.02', 'bond1'), ('0000:001c.03', 'bond2'), ]) self.parse_data_port_mappings.return_value = OrderedDict([ ('bond0', 'br-phynet1'), ('bond1', 'br-phynet2'), ('bond2', 'br-phynet3'), ]) else: _resolve_dpdk_bridges.return_value = OrderedDict([ ('0000:001c.01', 'br-phynet1'), ('0000:001c.02', 'br-phynet2'), ('0000:001c.03', 'br-phynet3'), ]) _resolve_dpdk_bonds.return_value = OrderedDict() _use_dvr.return_value = True self.use_dpdk.return_value = True self.ovs_has_late_dpdk_init.return_value = _late_init mock_config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get self.test_config.set('enable-dpdk', True) nutils.configure_ovs() self.add_bridge.assert_has_calls([ call('br-int', 'netdev'), call('br-ex', 'netdev'), call('br-phynet1', 'netdev'), call('br-phynet2', 'netdev'), call('br-phynet3', 'netdev')], any_order=True ) if _test_bonds: self.dpdk_add_bridge_bond.assert_has_calls([ call('br-phynet1', 'bond0', {_resolve_port_name('0000:001c.01', 0, _late_init): '0000:001c.01'}), call('br-phynet2', 'bond1', {_resolve_port_name('0000:001c.02', 1, _late_init): '0000:001c.02'}), call('br-phynet3', 'bond2', {_resolve_port_name('0000:001c.03', 2, _late_init): '0000:001c.03'})], any_order=True ) self.dpdk_set_bond_config.assert_has_calls([ call('bond0', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'}), call('bond1', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'}), call('bond2', {'mode': 'balance-tcp', 'lacp': 'active', 'lacp-time': 'fast'})], any_order=True ) else: self.dpdk_add_bridge_port.assert_has_calls([ call('br-phynet1', _resolve_port_name('0000:001c.01', 0, _late_init), '0000:001c.01'), call('br-phynet2', _resolve_port_name('0000:001c.02', 1, _late_init), '0000:001c.02'), call('br-phynet3', _resolve_port_name('0000:001c.03', 2, _late_init), '0000:001c.03')], any_order=True )