Skip to content

Conversation

@BogdanEmilian
Copy link

Handle cases where TYPE is present but empty, as well as when TYPE is missing entirely from the ifcfg file.

NOTE: The case tried before with using ifcfg.get("TYPE", "Ethernet") was not also handling the case where TYPE was missing entirely.

Handle cases where TYPE is present but empty,
as well as when TYPE is missing entirely from
the ifcfg file.
ifcfg = self.osmorphing_tool._read_config_file_sudo(ifcfg_file)
if not ifcfg.get("TYPE"):
ifcfg["TYPE"] = "Ethernet"
if ifcfg.get("TYPE") == ifcfg_type:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the configs may not have case-sensitive values, please also do the following:

Suggested change
if ifcfg.get("TYPE") == ifcfg_type:
if ifcfg.get("TYPE").lower() == ifcfg_type.lower():

for ifcfg_file in self._get_net_config_files(network_scripts_path):
ifcfg = self.osmorphing_tool._read_config_file_sudo(ifcfg_file)
if not ifcfg.get("TYPE"):
ifcfg["TYPE"] = "Ethernet"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer if the ifcfg type is saved in a separate variable, so that we avoid some dict-related bugs when editing this code:

detected_type = ifcfg.get('TYPE')
if not detected_type:
    detected_type = "Ethernet"
if detected_type.lower() == ifcfg_type.lower():
    # ...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants