github.com/openshift/installer@v1.4.17/pkg/asset/ignition/bootstrap/baremetal/template_test.go (about)

     1  package baremetal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/openshift/installer/pkg/ipnet"
     9  	"github.com/openshift/installer/pkg/types/baremetal"
    10  )
    11  
    12  func TestTemplatingIPv4(t *testing.T) {
    13  	bareMetalConfig := baremetal.Platform{
    14  		ProvisioningNetworkCIDR: ipnet.MustParseCIDR("172.22.0.0/24"),
    15  		BootstrapProvisioningIP: "172.22.0.2",
    16  		ProvisioningNetwork:     baremetal.ManagedProvisioningNetwork,
    17  		ProvisioningDHCPRange:   "172.22.0.10,172.22.0.100",
    18  		Hosts: []*baremetal.Host{
    19  			{
    20  				Role:           "master",
    21  				BootMACAddress: "c0:ff:ee:ca:fe:00",
    22  			},
    23  			{
    24  				Role:           "master",
    25  				BootMACAddress: "c0:ff:ee:ca:fe:01",
    26  			},
    27  			{
    28  				Role:           "master",
    29  				BootMACAddress: "c0:ff:ee:ca:fe:02",
    30  			},
    31  			{
    32  				Role:           "worker",
    33  				BootMACAddress: "c0:ff:ee:ca:fe:03",
    34  			},
    35  		},
    36  	}
    37  
    38  	result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
    39  
    40  	assert.Equal(t, result.ProvisioningDHCPRange, "172.22.0.10,172.22.0.100,24")
    41  	assert.Equal(t, result.ProvisioningCIDR, 24)
    42  	assert.Equal(t, result.ProvisioningIPv6, false)
    43  	assert.Equal(t, result.ProvisioningIP, "172.22.0.2")
    44  	assert.Equal(t, result.ProvisioningDHCPAllowList, "c0:ff:ee:ca:fe:00 c0:ff:ee:ca:fe:01 c0:ff:ee:ca:fe:02")
    45  	assert.Equal(t, result.IronicUsername, "bootstrap-ironic-user")
    46  	assert.Equal(t, result.IronicPassword, "passw0rd")
    47  }
    48  
    49  func TestTemplatingManagedIPv6(t *testing.T) {
    50  	bareMetalConfig := baremetal.Platform{
    51  		ProvisioningNetworkCIDR: ipnet.MustParseCIDR("fd2e:6f44:5dd8:b856::0/80"),
    52  		ProvisioningDHCPRange:   "fd2e:6f44:5dd8:b856::1,fd2e:6f44:5dd8::ff",
    53  		BootstrapProvisioningIP: "fd2e:6f44:5dd8:b856::2",
    54  		ProvisioningNetwork:     baremetal.ManagedProvisioningNetwork,
    55  	}
    56  
    57  	result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
    58  
    59  	assert.Equal(t, result.ProvisioningDHCPRange, "fd2e:6f44:5dd8:b856::1,fd2e:6f44:5dd8::ff,80")
    60  	assert.Equal(t, result.ProvisioningCIDR, 80)
    61  	assert.Equal(t, result.ProvisioningIPv6, true)
    62  	assert.Equal(t, result.ProvisioningIP, "fd2e:6f44:5dd8:b856::2")
    63  	assert.Equal(t, result.IronicUsername, "bootstrap-ironic-user")
    64  	assert.Equal(t, result.IronicPassword, "passw0rd")
    65  }
    66  
    67  func TestTemplatingUnmanagedIPv6(t *testing.T) {
    68  	bareMetalConfig := baremetal.Platform{
    69  		ProvisioningNetworkCIDR: ipnet.MustParseCIDR("fd2e:6f44:5dd8:b856::0/64"),
    70  		BootstrapProvisioningIP: "fd2e:6f44:5dd8:b856::2",
    71  		ProvisioningNetwork:     baremetal.UnmanagedProvisioningNetwork,
    72  	}
    73  
    74  	result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
    75  
    76  	assert.Equal(t, result.ProvisioningDHCPRange, "")
    77  	assert.Equal(t, result.ProvisioningCIDR, 64)
    78  	assert.Equal(t, result.ProvisioningIPv6, true)
    79  	assert.Equal(t, result.ProvisioningIP, "fd2e:6f44:5dd8:b856::2")
    80  	assert.Equal(t, result.ProvisioningDHCPAllowList, "")
    81  	assert.Equal(t, result.IronicUsername, "bootstrap-ironic-user")
    82  	assert.Equal(t, result.IronicPassword, "passw0rd")
    83  }