Skip to content

Commit 843c57e

Browse files
committed
nova: refactor the IronicUnderstackDriver to make testing easier
This way our modified code is almost all in separate method and it's clear what has been changed.
1 parent a9c4e7b commit 843c57e

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from nova.virt.ironic_understack import driver
1+
from .driver import IronicUnderstackDriver
22

3-
IronicUnderstackDriver = driver.IronicUnderstackDriver
3+
__all__ = ["IronicUnderstackDriver"]

python/nova-understack/ironic_understack/driver.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,20 @@ def _get_network_metadata_with_storage(self, node, network_info):
5151
base_metadata["networks"].append(network)
5252
return base_metadata
5353

54-
# This is almost exact copy of the IronicDriver's _generate_configdrive,
55-
# but we make a determination if injecting storage IPs information is needed
56-
# based on the instance 'storage' property.
57-
def _generate_configdrive(
58-
self, context, instance, node, network_info, extra_md=None, files=None
59-
):
60-
"""Generate a config drive with optional storage info.
54+
def _understack_get_network_metadata(self, instance, node, network_info):
55+
"""Get network metadata with optional storage network configuration.
56+
57+
This method implements the Understack-specific logic for determining
58+
whether to include storage network configuration based on instance
59+
metadata and configuration settings.
6160
6261
:param instance: The instance object.
6362
:param node: The node object.
6463
:param network_info: Instance network information.
65-
:param extra_md: Optional, extra metadata to be added to the
66-
configdrive.
67-
:param files: Optional, a list of paths to files to be added to
68-
the configdrive.
69-
64+
:returns: Network metadata dictionary
7065
"""
71-
if not extra_md:
72-
extra_md = {}
73-
74-
### Understack modified code START
7566
if (
76-
instance.metadata["storage"] == "wanted"
67+
instance.metadata.get("storage") == "wanted"
7768
and CONF.nova_understack.ip_injection_enabled
7869
):
7970
logger.info("Instance %s requires storage network setup.", instance.uuid)
@@ -99,6 +90,31 @@ def _generate_configdrive(
9990
instance.uuid,
10091
)
10192
network_metadata = self._get_network_metadata(node, network_info)
93+
94+
return network_metadata
95+
96+
# This is almost exact copy of the IronicDriver's _generate_configdrive,
97+
# but we make a determination if injecting storage IPs information is needed
98+
# based on the instance 'storage' property.
99+
def _generate_configdrive(
100+
self, context, instance, node, network_info, extra_md=None, files=None
101+
):
102+
"""Generate a config drive with optional storage info.
103+
104+
:param instance: The instance object.
105+
:param node: The node object.
106+
:param network_info: Instance network information.
107+
:param extra_md: Optional, extra metadata to be added to the
108+
configdrive.
109+
:param files: Optional, a list of paths to files to be added to
110+
the configdrive.
111+
112+
"""
113+
if not extra_md:
114+
extra_md = {}
115+
116+
### Understack modified code START
117+
network_metadata = self._understack_get_network_metadata(instance, node, network_info)
102118
### Understack modified code END
103119

104120
i_meta = instance_metadata.InstanceMetadata(

0 commit comments

Comments
 (0)