Skip to content

Commit

Permalink
Add more EthernetInterface updatable fields
Browse files Browse the repository at this point in the history
There are a few fields for EthernetInterface that are not marked as
`read-only: false` in the schema files, but are notes as read-write in
the schema guide. This updates the set of properties to check when
performing an update.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis committed Apr 29, 2024
1 parent ea45d5a commit cf61634
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
31 changes: 26 additions & 5 deletions redfish/ethernetinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import (
"github.com/stmcginnis/gofish/common"
)

type DHCPFallback string

const (
// StaticDHCPFallback shall fall back to a static address specified by IPv4StaticAddresses.
StaticDHCPFallback DHCPFallback = "Static"
// AutoConfigDHCPFallback shall fall back to an address generated by the implementation.
AutoConfigDHCPFallback DHCPFallback = "AutoConfig"
// NoneDHCPFallback shall continue trying to obtain an address without falling back to a fixed address.
NoneDHCPFallback DHCPFallback = "None"
)

// DHCPv6OperatingMode is the IPv6 DHCP mode.
type DHCPv6OperatingMode string

Expand Down Expand Up @@ -105,21 +116,23 @@ type DHCPv4Configuration struct {
// DHCPEnabled shall indicate whether DHCP v4 is enabled for this
// EthernetInterface.
DHCPEnabled bool
// FallbackAddress shall contain the fallback address method of DHCPv4.
FallbackAddress DHCPFallback `json:",omitempty"`
// UseDNSServers shall indicate whether the interface will use
// DHCPv4-supplied DNS servers.
UseDNSServers bool
UseDNSServers bool `json:",omitempty"`
// UseDomainName shall indicate whether the interface will use a
// DHCPv4-supplied domain name.
UseDomainName bool
UseDomainName bool `json:",omitempty"`
// UseGateway shall indicate whether the interface will use a
// DHCPv4-supplied gateway.
UseGateway bool
UseGateway bool `json:",omitempty"`
// UseNTPServers shall indicate whether the interface will use
// DHCPv4-supplied NTP servers.
UseNTPServers bool
UseNTPServers bool `json:",omitempty"`
// UseStaticRoutes shall indicate whether the interface will use a
// DHCPv4-supplied static routes.
UseStaticRoutes bool
UseStaticRoutes bool `json:",omitempty"`
}

// DHCPv6Configuration describes the configuration of DHCP v6.
Expand Down Expand Up @@ -359,16 +372,24 @@ func (ethernetinterface *EthernetInterface) Update() error {

readWriteFields := []string{
"AutoNeg",
"DHCPv4",
"DHCPv6",
"FQDN",
"FullDuplex",
"HostName",
"IPv4StaticAddresses",
"IPv6AddressPolicyTable",
"IPv6Enabled",
"IPv6StaticAddresses",
"IPv6StaticDefaultGateways",
"InterfaceEnabled",
"MACAddress",
"MTUSize",
"SpeedMbps",
"StatelessAddressAutoConfig",
"StaticNameServers",
"TeamMode",
"VLAN",
}

originalElement := reflect.ValueOf(original).Elem()
Expand Down
29 changes: 29 additions & 0 deletions redfish/ethernetinterface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func TestEthernetInterface(t *testing.T) {
}

// TestEthernetInterfaceUpdate tests the Update call.
//
//nolint:funlen
func TestEthernetInterfaceUpdate(t *testing.T) {
var result EthernetInterface
err := json.NewDecoder(strings.NewReader(ethernetInterfaceBody)).Decode(&result)
Expand All @@ -162,6 +164,13 @@ func TestEthernetInterfaceUpdate(t *testing.T) {
result.MACAddress = "de:ad:de:ad:de:ad"
result.MTUSize = 9216
result.SpeedMbps = 1000

result.DHCPv4.DHCPEnabled = true
result.DHCPv6.UseDNSServers = true
result.IPv6AddressPolicyTable = append(result.IPv6AddressPolicyTable, IPv6AddressPolicyEntry{Label: 5})
result.StatelessAddressAutoConfig.IPv6AutoConfigEnabled = true
result.VLAN.VLANID = 8

err = result.Update()

if err != nil {
Expand Down Expand Up @@ -205,6 +214,26 @@ func TestEthernetInterfaceUpdate(t *testing.T) {
if strings.Contains(calls[0].Payload, "FullDuplex") {
t.Errorf("Unexpected update for FullDuplex in payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "DHCPEnabled:true") {
t.Errorf("Unexpected DHCPv4.DHCPEnabled update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "UseDNSServers:true") {
t.Errorf("Unexpected DHCPv6.UseDNSServers update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "Label:5") {
t.Errorf("Unexpected IPv6AddressPolicyTable Label update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "IPv6AutoConfigEnabled:true") {
t.Errorf("Unexpected StatelessAddressAutoConfig IPv6AutoConfigEnabled update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "VLANId:8") {
t.Errorf("Unexpected VLAN VLANID update payload: %s", calls[0].Payload)
}
}

var ethernetInterfaceIPv6Body = `{
Expand Down
12 changes: 6 additions & 6 deletions redfish/ipaddresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,32 @@ type IPv4Address struct {
// is enabled on the interface, this property becomes read-only.
Address string
// AddressOrigin shall be the IP address origin for this network interface.
AddressOrigin IPv4AddressOrigin
AddressOrigin IPv4AddressOrigin `json:",omitempty"`
// Gateway shall be the IPv4 default gateway address for this interface. If
// DHCPv4 is enabled on the interface and is configured to set the IPv4
// default gateway address, this property becomes read-only.
Gateway string
Gateway string `json:",omitempty"`
// SubnetMask shall be the IPv4 subnet mask for this address. If DHCPv4 is
// enabled on the interface, this property becomes read-only.
SubnetMask string
SubnetMask string `json:",omitempty"`
}

// IPv6Address describes an IPv6 address assigned to an interface.
type IPv6Address struct {
// Address lists an IPv6 address that is currently assigned on this interface.
Address string
// AddressOrigin shall be the IPv6 address origin for this interface.
AddressOrigin IPv6AddressOrigin
AddressOrigin IPv6AddressOrigin `json:",omitempty"`
// AddressState Preferred and Deprecated states follow the definitions
// given RFC4862 Section 5.5.4. An address is in the Tentative state
// while undergoing Duplicate Address Detection (DAD) per RFC4862 Section
// 5.4. The Failed state indicates a Static addresses which did not pass
// DAD. A Static address in the Failed state is not in use on the
// network stack, and corrective action will be needed to remedy this
// condition.
AddressState AddressState
AddressState AddressState `json:",omitempty"`
// PrefixLength shall be the IPv6 address prefix length for this interface.
PrefixLength uint8
PrefixLength uint8 `json:",omitempty"`
}

// IPv6GatewayStaticAddress shall represent a single IPv6 static address to be
Expand Down

0 comments on commit cf61634

Please sign in to comment.