def test__can_watch_config(self): callback = lambda: None config_name = factory.make_name("config") manager = SignalsManager() manager.watch_config(callback, config_name) self.assertThat(manager._signals, HasLength(1)) [signal] = manager._signals self.assertThat( signal.connect, MatchesPartialCall(Config.objects.config_changed_connect, config_name, callback)) self.assertThat( signal.disconnect, MatchesPartialCall(Config.objects.config_changed_disconnect, config_name, callback))
node.save(update_fields=["gateway_link_ipv6_id"]) def update_interface_monitoring(sender, instance, *args, **kwargs): """Updates the global state of interface monitoring.""" # This is not really ideal, since we don't actually know if any of these # configuration options actually changed. Also, this function may be called # more than once (for each global setting) when the form is submitted, no # matter if anything changed or not. (But a little repitition for the sake # of simpler code is a good tradeoff for now, given that there will be a # relatively small number of Controller interfaces. discovery_config = Config.objects.get_network_discovery_config_from_value( instance.value ) # We only care about Controller objects, since only Controllers run the # networks monitoring service. for controller in Controller.objects.all(): controller.update_discovery_state(discovery_config) signals.watch( m2m_changed, remove_gateway_link_when_ip_address_removed_from_interface, Interface.ip_addresses.through, ) signals.watch_config(update_interface_monitoring, "network_discovery") # Enable all signals by default. signals.enable()
signals = SignalsManager() def save_boot_source_cache(sender, instance, *args, **kwargs): """On first run the ImportResourceService sets the default BootSource then caches the stream's contents as normal. Setting the default BootSource triggers this signal. This prevents updating the cache twice. """ # Don't run if the first row and newly created. if instance.id != 1 and BootSource.objects.count() != 0: update_boot_source_cache(sender, instance, *args, **kwargs) def update_boot_source_cache(sender, instance, *args, **kwargs): """Update the `BootSourceCache` using the updated source. This only begins after a successful commit to the database, and is then run in a thread. Nothing waits for its completion. """ post_commit_do(reactor.callLater, 0, cache_boot_sources) signals.watch(post_save, save_boot_source_cache, BootSource) signals.watch(post_delete, update_boot_source_cache, BootSource) signals.watch_config(update_boot_source_cache, "enable_http_proxy") signals.watch_config(update_boot_source_cache, "http_proxy") # Enable all signals by default. signals.enable()
# Copyright 2012-2016 Canonical Ltd. This software is licensed under the # GNU Affero General Public License version 3 (see the file LICENSE). """Signals called when config values changed.""" __all__ = [ "signals", ] from maasserver.utils.signals import SignalsManager signals = SignalsManager() def dns_kms_setting_changed(sender, instance, created, **kwargs): from maasserver.models.domain import dns_kms_setting_changed dns_kms_setting_changed() # Changes to windows_kms_host. signals.watch_config(dns_kms_setting_changed, "windows_kms_host") # Enable all signals by default. signals.enable()