Skip to content

Conversation

@cfconrad
Copy link
Collaborator

Problem

Upstream bonding was finally merged and now we can re-implement the migrate-wicked side.

Testing

  • Added a new unit test

@cfconrad cfconrad requested a review from jcronenberg December 20, 2023 16:53
@cfconrad cfconrad changed the title Wicked nm migration add bonding again Add bond migration Dec 21, 2023
Comment on lines 135 to 484

if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
connection.mac_address = MacAddress::from_str(address)?;
}
} else if let Some(ethernet) = &self.ethernet {
if let Some(ethernet) = &self.ethernet {
if let Some(address) = &ethernet.address {
connection.mac_address = MacAddress::from_str(address)?;
}
}

if self.dummy.is_some() {
if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = model::ConnectionConfig::Dummy
} else if let Some(bond) = &self.bond {
if let Some(address) = &bond.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = bond.into()
} else {
connection.config = model::ConnectionConfig::Ethernet
};
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
connection.mac_address = MacAddress::from_str(address)?;
}
} else if let Some(ethernet) = &self.ethernet {
if let Some(ethernet) = &self.ethernet {
if let Some(address) = &ethernet.address {
connection.mac_address = MacAddress::from_str(address)?;
}
}
if self.dummy.is_some() {
if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = model::ConnectionConfig::Dummy
} else if let Some(bond) = &self.bond {
if let Some(address) = &bond.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = bond.into()
} else {
connection.config = model::ConnectionConfig::Ethernet
};
if let Some(ethernet) = &self.ethernet {
if let Some(address) = &ethernet.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = model::ConnectionConfig::Ethernet
} else if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = model::ConnectionConfig::Dummy
} else if let Some(bond) = &self.bond {
if let Some(address) = &bond.address {
connection.mac_address = MacAddress::from_str(address)?;
}
connection.config = bond.into()
};

and maybe some DRY before we repeat it for every connection type:

macro_rules! ADD_MAC {
    ($connection:expr, $config:expr) => {
        if let Some(address) = &$config.address {
            $connection.mac_address = MacAddress::from_str(address)?;
        }
    };
}
...
        if let Some(ethernet) = &self.ethernet {
            ADD_MAC!(connection, ethernet);
            connection.config = model::ConnectionConfig::Ethernet
        }
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WDYT of

impl TryFrom<&Option<String>> for MacAddress {
    type Error = InvalidMacAddress;

    fn try_from(value: &Option<String>) -> Result<Self, Self::Error> {
        match &value {
            Some(str) => MacAddress::from_str(str),
            None => Ok(Self::Unset)
        }
    }
}

Copy link
Owner

Choose a reason for hiding this comment

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

Sure, should also work if you prefer it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I finally go with

#serde(default)
address: String,

which lead to empty string if it isn't in xml...

Copy link
Owner

Choose a reason for hiding this comment

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

I finally go with

#serde(default)
address: String,

which lead to empty string if it isn't in xml...

In that case you should also add

#[serde(skip_serializing_if = "String::is_empty")]

Copy link
Collaborator Author

@cfconrad cfconrad Jan 9, 2024

Choose a reason for hiding this comment

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

valid point.

Lets see if this agama-project#983 gets accepted, then I go back to Option<String>

@jcronenberg jcronenberg merged commit f41700c into jcronenberg:wicked-nm-migration Jan 10, 2024
@cfconrad cfconrad deleted the wicked-nm-migration-add-bonding-again branch January 16, 2024 15:54
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