Skip to content

Instantly share code, notes, and snippets.

@TheRealFalcon
Created February 17, 2021 18:32
Show Gist options
  • Save TheRealFalcon/42083a9062a15ccdfdabe03ff598efa9 to your computer and use it in GitHub Desktop.
Save TheRealFalcon/42083a9062a15ccdfdabe03ff598efa9 to your computer and use it in GitHub Desktop.

I have been trying to understand the behavior of apply_network_config in stages.py.

When trying to update the code to support configrable EventTypes, I noticed that we sometimes apply networking configuration twice.

apply_network_config only has two call points, both in main.py. The happy-path call gets called twice, once during local phase, then again during network phase.

Inside of the function, there is some logic to determine if we should apply networking config. One of these calls is self.is_new_instance(), which is a bit of a misnomer. It only returns True during the first local run. During the network phase run (still on first boot), it will return False.

Prior to the introduction of EventTypes (e.g., commit 58581362), network config would get applied during local stage and that's it. If self.is_new_instance() returned True, we would apply config. If False, skip it. Since it only returns True during local phase, it would only set network config once during local phase.

After the introduction of EventType's, when self.is_new_instance() returns False, we check to see if the datasource supports the EventType.BOOT. If so, we'll again apply networking config and also bring up interfaces in net phase. Thus, DataSources which have update_events including EventType.BOOT wind up having network_config applied twice: once during local stage, then again during net stage.

DataSources that include EventType.BOOT:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment