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)
Ejemplo n.º 2
0
 def test_restart_map(self, _use_dvr):
     _use_dvr.return_value = False
     _restart_map = nutils.restart_map()
     ML2CONF = "/etc/neutron/plugins/ml2/ml2_conf.ini"
     expect = OrderedDict([
         (nutils.NEUTRON_CONF, ['neutron-plugin-openvswitch-agent']),
         (ML2CONF, ['neutron-plugin-openvswitch-agent']),
         (nutils.PHY_NIC_MTU_CONF, ['os-charm-phy-nic-mtu'])
     ])
     self.assertEqual(expect, _restart_map)
     for item in _restart_map:
         self.assertTrue(item in _restart_map)
         self.assertTrue(expect[item] == _restart_map[item])
Ejemplo n.º 3
0
 def test_restart_map(self, _use_dvr):
     _use_dvr.return_value = False
     _restart_map = nutils.restart_map()
     ML2CONF = "/etc/neutron/plugins/ml2/ml2_conf.ini"
     expect = OrderedDict([
         (nutils.NEUTRON_CONF, ['neutron-plugin-openvswitch-agent']),
         (ML2CONF, ['neutron-plugin-openvswitch-agent']),
         (nutils.PHY_NIC_MTU_CONF, ['os-charm-phy-nic-mtu'])
     ])
     self.assertEqual(expect, _restart_map)
     for item in _restart_map:
         self.assertTrue(item in _restart_map)
         self.assertTrue(expect[item] == _restart_map[item])
 def test_restart_map(self, mock_use_dvr, mock_use_dpdk):
     mock_use_dvr.return_value = False
     mock_use_dpdk.return_value = False
     self.os_release.return_value = "mitaka"
     self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'}
     ML2CONF = "/etc/neutron/plugins/ml2/openvswitch_agent.ini"
     _restart_map = nutils.restart_map()
     expect = OrderedDict([
         (ML2CONF, ['neutron-openvswitch-agent']),
         (nutils.NEUTRON_CONF, ['neutron-openvswitch-agent']),
     ])
     self.assertEqual(expect, OrderedDict(_restart_map))
     for item in _restart_map:
         self.assertTrue(item in _restart_map)
         self.assertTrue(expect[item] == _restart_map[item])
 def test_restart_map(self, mock_use_dvr, mock_use_dpdk, mock_use_l3ha):
     mock_use_dvr.return_value = False
     mock_use_l3ha.return_value = False
     mock_use_dpdk.return_value = False
     self.os_release.return_value = "mitaka"
     self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'}
     ML2CONF = "/etc/neutron/plugins/ml2/openvswitch_agent.ini"
     _restart_map = nutils.restart_map()
     expect = OrderedDict([
         (nutils.NEUTRON_CONF, ['neutron-openvswitch-agent']),
         (ML2CONF, ['neutron-openvswitch-agent']),
     ])
     for item in _restart_map:
         self.assertTrue(item in _restart_map)
         self.assertTrue(expect[item] == _restart_map[item])
     self.assertEqual(len(_restart_map.keys()), 2)
 def test_restart_map(self, _use_dvr):
     _use_dvr.return_value = False
     self.os_release.return_value = "diablo"
     self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}
     _restart_map = nutils.restart_map()
     ML2CONF = "/etc/neutron/plugins/ml2/ml2_conf.ini"
     expect = OrderedDict([
         (nutils.NEUTRON_CONF, ['neutron-plugin-openvswitch-agent']),
         (ML2CONF, ['neutron-plugin-openvswitch-agent']),
         (nutils.OVS_DEFAULT, ['openvswitch-switch']),
         (nutils.PHY_NIC_MTU_CONF, ['os-charm-phy-nic-mtu'])
     ])
     self.assertEqual(expect, _restart_map)
     for item in _restart_map:
         self.assertTrue(item in _restart_map)
         self.assertTrue(expect[item] == _restart_map[item])
Ejemplo n.º 7
0
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 upgrade_charm():
    if OVS_DEFAULT in restart_map():
        # In the 16.10 release of the charms, the code changed from managing
        # the /etc/default/openvswitch-switch file only when dpdk was enabled
        # to always managing this file. Thus, an upgrade of the charm from a
        # release prior to 16.10 or higher will always cause the contents of
        # the file to change and will trigger a restart of the
        # openvswitch-switch service, which in turn causes a temporary
        # network outage. To prevent this outage, determine if the
        # /etc/default/openvswitch-switch file needs to be migrated and if
        # so, migrate the file but do NOT restart the openvswitch-switch
        # service.
        # See bug LP #1712444
        with open(OVS_DEFAULT, 'r') as f:
            # The 'Service restart triggered ...' line was added to the
            # OVS_DEFAULT template in the 16.10 version of the charm to allow
            # restarts so we use this as the key to see if the file needs
            # migrating.
            if 'Service restart triggered' not in f.read():
                CONFIGS.write(OVS_DEFAULT)
def upgrade_charm():
    if OVS_DEFAULT in restart_map():
        # In the 16.10 release of the charms, the code changed from managing
        # the /etc/default/openvswitch-switch file only when dpdk was enabled
        # to always managing this file. Thus, an upgrade of the charm from a
        # release prior to 16.10 or higher will always cause the contents of
        # the file to change and will trigger a restart of the
        # openvswitch-switch service, which in turn causes a temporary
        # network outage. To prevent this outage, determine if the
        # /etc/default/openvswitch-switch file needs to be migrated and if
        # so, migrate the file but do NOT restart the openvswitch-switch
        # service.
        # See bug LP #1712444
        with open(OVS_DEFAULT, 'r') as f:
            # The 'Service restart triggered ...' line was added to the
            # OVS_DEFAULT template in the 16.10 version of the charm to allow
            # restarts so we use this as the key to see if the file needs
            # migrating.
            if 'Service restart triggered' not in f.read():
                CONFIGS.write(OVS_DEFAULT)
Ejemplo n.º 10
0
    assess_status,
)

hooks = Hooks()
CONFIGS = register_configs()


@hooks.hook()
def install():
    install_packages()
    git_install(config('openstack-origin-git'))


@hooks.hook('neutron-plugin-relation-changed')
@hooks.hook('config-changed')
@restart_on_change(restart_map())
def config_changed():
    install_packages()
    if git_install_requested():
        if config_value_changed('openstack-origin-git'):
            git_install(config('openstack-origin-git'))

    configure_ovs()
    configure_sriov()
    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)

        # See bug LP #1712444
        with open(OVS_DEFAULT, 'r') as f:
            # The 'Service restart triggered ...' line was added to the
            # OVS_DEFAULT template in the 16.10 version of the charm to allow
            # restarts so we use this as the key to see if the file needs
            # migrating.
            if 'Service restart triggered' not in f.read():
                CONFIGS.write(OVS_DEFAULT)


@hooks.hook('neutron-plugin-relation-changed')
@hooks.hook('config-changed')
# NOTE(fnordahl): we need to act immediately to changes to OVS_DEFAULT in-line
# so ignore it here to avoid restarting the services twice. LP: #1906280
@restart_on_change({cfg: services
                    for cfg, services in restart_map().items()
                    if cfg != OVS_DEFAULT})
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
Ejemplo n.º 12
0
        with open(OVS_DEFAULT, 'r') as f:
            # The 'Service restart triggered ...' line was added to the
            # OVS_DEFAULT template in the 16.10 version of the charm to allow
            # restarts so we use this as the key to see if the file needs
            # migrating.
            if 'Service restart triggered' not in f.read():
                CONFIGS.write(OVS_DEFAULT)


@hooks.hook('neutron-plugin-relation-changed')
@hooks.hook('config-changed')
# NOTE(fnordahl): we need to act immediately to changes to OVS_DEFAULT in-line
# so ignore it here to avoid restarting the services twice. LP: #1906280
@restart_on_change({
    cfg: services
    for cfg, services in restart_map().items() if cfg != OVS_DEFAULT
})
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()
        # /etc/default/openvswitch-switch file needs to be migrated and if
        # so, migrate the file but do NOT restart the openvswitch-switch
        # service.
        # See bug LP #1712444
        with open(OVS_DEFAULT, 'r') as f:
            # The 'Service restart triggered ...' line was added to the
            # OVS_DEFAULT template in the 16.10 version of the charm to allow
            # restarts so we use this as the key to see if the file needs
            # migrating.
            if 'Service restart triggered' not in f.read():
                CONFIGS.write(OVS_DEFAULT)


@hooks.hook('neutron-plugin-relation-changed')
@hooks.hook('config-changed')
@restart_on_change(restart_map())
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: