diff options
author | sxt1001 <shixuantong1@huawei.com> | 2023-04-03 23:52:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 10:52:15 -0500 |
commit | 0273712c90d6facfc0fbf8d6def352f9810902a3 (patch) | |
tree | c43853b03c1a71a2ae935bbd03dcdc5d01d6ebc2 /cloudinit | |
parent | 09a64badfb3f51b1b391fa29be19962381a4bbeb (diff) | |
download | cloud-init-git-0273712c90d6facfc0fbf8d6def352f9810902a3.tar.gz |
Cleanup ephemeral IP routes on exception (#2100)
If an exception occurs during EphemeralIPv4Network setup, any routes
that were setup need to be torn down. This wasn't happening, and this
commit adds the teardown.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/net/ephemeral.py | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/cloudinit/net/ephemeral.py b/cloudinit/net/ephemeral.py index cade2e5f..1dfd1c42 100644 --- a/cloudinit/net/ephemeral.py +++ b/cloudinit/net/ephemeral.py @@ -84,23 +84,32 @@ class EphemeralIPv4Network: ) return - self._bringup_device() - - # rfc3442 requires us to ignore the router config *if* classless static - # routes are provided. - # - # https://tools.ietf.org/html/rfc3442 - # - # If the DHCP server returns both a Classless Static Routes option and - # a Router option, the DHCP client MUST ignore the Router option. - # - # Similarly, if the DHCP server returns both a Classless Static Routes - # option and a Static Routes option, the DHCP client MUST ignore the - # Static Routes option. - if self.static_routes: - self._bringup_static_routes() - elif self.router: - self._bringup_router() + try: + self._bringup_device() + + # rfc3442 requires us to ignore the router config *if* + # classless static routes are provided. + # + # https://tools.ietf.org/html/rfc3442 + # + # If the DHCP server returns both a Classless Static Routes + # option and a Router option, the DHCP client MUST ignore + # the Router option. + # + # Similarly, if the DHCP server returns both a Classless + # Static Routes option and a Static Routes option, the DHCP + # client MUST ignore the Static Routes option. + if self.static_routes: + self._bringup_static_routes() + elif self.router: + self._bringup_router() + except subp.ProcessExecutionError: + LOG.error( + "Error bringing up EphemeralIPv4Network. " + "Datasource setup cannot continue" + ) + self.__exit__(None, None, None) + raise def __exit__(self, excp_type, excp_value, excp_traceback): """Teardown anything we set up.""" |