diff --git a/cmd/update_configuration/vers42/datastructure.go b/cmd/update_configuration/vers42/datastructure.go index 787cc5ce..188419d8 100644 --- a/cmd/update_configuration/vers42/datastructure.go +++ b/cmd/update_configuration/vers42/datastructure.go @@ -4,7 +4,7 @@ package vers42 * YAML data representations ******/ -//type nodeYaml struct { +// type nodeYaml struct { type NodeYaml struct { // <-Needs to be exported NodeProfiles map[string]*NodeConf Nodes map[string]*NodeConf diff --git a/cmd/update_configuration/vers43/datastructure.go b/cmd/update_configuration/vers43/datastructure.go index 48712bc5..24e8f185 100644 --- a/cmd/update_configuration/vers43/datastructure.go +++ b/cmd/update_configuration/vers43/datastructure.go @@ -4,7 +4,7 @@ package vers43 * YAML data representations ******/ -//type nodeYaml struct { +// type nodeYaml struct { type NodeYaml struct { // <- needs to be exported WWInternal int `yaml:"WW_INTERNAL"` NodeProfiles map[string]*NodeConf diff --git a/internal/app/wwctl/container/build/root.go b/internal/app/wwctl/container/build/root.go index eb9541cf..8c7a2d15 100644 --- a/internal/app/wwctl/container/build/root.go +++ b/internal/app/wwctl/container/build/root.go @@ -8,11 +8,11 @@ import ( var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "build [OPTIONS] CONTAINER [...]", - Short: "(Re)build a bootable VNFS image", - Long: "This command will build a bootable VNFS image from imported CONTAINER image(s).", - RunE: CobraRunE, - Args: cobra.ArbitraryArgs, + Use: "build [OPTIONS] CONTAINER [...]", + Short: "(Re)build a bootable VNFS image", + Long: "This command will build a bootable VNFS image from imported CONTAINER image(s).", + RunE: CobraRunE, + Args: cobra.ArbitraryArgs, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/container/copy/root.go b/internal/app/wwctl/container/copy/root.go index fad0dbaa..64edb1d9 100644 --- a/internal/app/wwctl/container/copy/root.go +++ b/internal/app/wwctl/container/copy/root.go @@ -9,7 +9,7 @@ var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, Use: "copy CONTAINER NEW_NAME", - Aliases: []string{"cp"}, + Aliases: []string{"cp"}, Short: "Copy an existing container", Long: "This command will duplicate an imported container image.", RunE: CobraRunE, diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index ddb7fa18..bf84b443 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -11,11 +11,11 @@ import ( "strings" "syscall" + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/internal/app/wwctl/container/list/main_test.go b/internal/app/wwctl/container/list/main_test.go index ab3c880f..824abaee 100644 --- a/internal/app/wwctl/container/list/main_test.go +++ b/internal/app/wwctl/container/list/main_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" - "github.com/hpcng/warewulf/internal/pkg/node" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/warewulfd" "github.com/stretchr/testify/assert" ) diff --git a/internal/app/wwctl/node/console/root.go b/internal/app/wwctl/node/console/root.go index a0d05f4e..3256d1bf 100644 --- a/internal/app/wwctl/node/console/root.go +++ b/internal/app/wwctl/node/console/root.go @@ -7,11 +7,11 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "console [OPTIONS] NODENAME", - Short: "Connect to IPMI console", - Long: "Start a new IPMI console for NODENAME.", - Args: cobra.MinimumNArgs(1), - RunE: CobraRunE, + Use: "console [OPTIONS] NODENAME", + Short: "Connect to IPMI console", + Long: "Start a new IPMI console for NODENAME.", + Args: cobra.MinimumNArgs(1), + RunE: CobraRunE, } ) diff --git a/internal/app/wwctl/node/root.go b/internal/app/wwctl/node/root.go index 9c3aa99c..6614e00a 100644 --- a/internal/app/wwctl/node/root.go +++ b/internal/app/wwctl/node/root.go @@ -22,7 +22,7 @@ var ( Long: "Management of node settings. All node ranges can use brackets to identify\n" + "node ranges. For example: n00[00-4].cluster[0-1] will identify the first 5 nodes\n" + "in cluster0 and cluster1.", - Aliases: []string{"nodes"}, + Aliases: []string{"nodes"}, } ) diff --git a/internal/app/wwctl/node/sensors/root.go b/internal/app/wwctl/node/sensors/root.go index 07405812..8740a54f 100644 --- a/internal/app/wwctl/node/sensors/root.go +++ b/internal/app/wwctl/node/sensors/root.go @@ -8,11 +8,11 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "sensors [OPTIONS] PATTERN", - Short: "Show node IPMI sensor information", - Long: "Show IPMI sensor information for nodes matching PATTERN.", - Args: cobra.MinimumNArgs(1), - RunE: CobraRunE, + Use: "sensors [OPTIONS] PATTERN", + Short: "Show node IPMI sensor information", + Long: "Show IPMI sensor information for nodes matching PATTERN.", + Args: cobra.MinimumNArgs(1), + RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/node/set/main_test.go b/internal/app/wwctl/node/set/main_test.go index 48ee49e4..466f889f 100644 --- a/internal/app/wwctl/node/set/main_test.go +++ b/internal/app/wwctl/node/set/main_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - "github.com/hpcng/warewulf/internal/pkg/warewulfd" "github.com/hpcng/warewulf/internal/pkg/testenv" + "github.com/hpcng/warewulf/internal/pkg/warewulfd" "github.com/stretchr/testify/assert" ) diff --git a/internal/app/wwctl/overlay/build/main.go b/internal/app/wwctl/overlay/build/main.go index 75c7cf82..2403f22e 100644 --- a/internal/app/wwctl/overlay/build/main.go +++ b/internal/app/wwctl/overlay/build/main.go @@ -5,9 +5,9 @@ import ( "os" "strings" + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/pkg/hostlist" "github.com/spf13/cobra" diff --git a/internal/app/wwctl/overlay/build/root.go b/internal/app/wwctl/overlay/build/root.go index b9971519..82a657ae 100644 --- a/internal/app/wwctl/overlay/build/root.go +++ b/internal/app/wwctl/overlay/build/root.go @@ -29,10 +29,10 @@ var ( return node_names, cobra.ShellCompDirectiveNoFileComp }, } - BuildHost bool - BuildNodes bool + BuildHost bool + BuildNodes bool OverlayNames []string - OverlayDir string + OverlayDir string ) func init() { diff --git a/internal/app/wwctl/overlay/edit/main.go b/internal/app/wwctl/overlay/edit/main.go index 6d5097c2..655aec3d 100644 --- a/internal/app/wwctl/overlay/edit/main.go +++ b/internal/app/wwctl/overlay/edit/main.go @@ -13,7 +13,6 @@ import ( "github.com/spf13/cobra" ) - const initialTemplate = `# This is a Warewulf Template file. # # This file (suffix '.ww') will be automatically rewritten without the suffix @@ -35,7 +34,6 @@ const initialTemplate = `# This is a Warewulf Template file. # Source: {{.BuildSource}} ` - func CobraRunE(cmd *cobra.Command, args []string) error { overlayName := args[0] fileName := args[1] diff --git a/internal/app/wwctl/power/cycle/root.go b/internal/app/wwctl/power/cycle/root.go index 18f0fc51..fa4a77c8 100644 --- a/internal/app/wwctl/power/cycle/root.go +++ b/internal/app/wwctl/power/cycle/root.go @@ -7,10 +7,10 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "cycle [OPTIONS] [PATTERN ...]", - Short: "Power cycle the given node(s)", - Long: "This command cycles power for a set of nodes specified by PATTERN.", - RunE: CobraRunE, + Use: "cycle [OPTIONS] [PATTERN ...]", + Short: "Power cycle the given node(s)", + Long: "This command cycles power for a set of nodes specified by PATTERN.", + RunE: CobraRunE, } ) diff --git a/internal/app/wwctl/power/off/root.go b/internal/app/wwctl/power/off/root.go index cb659dda..47b9229a 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -8,10 +8,10 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "off [OPTIONS] [PATTERN ...]", - Short: "Power off the given node(s)", - Long: "This command will shutdown power to a set of nodes specified by PATTERN.", - RunE: CobraRunE, + Use: "off [OPTIONS] [PATTERN ...]", + Short: "Power off the given node(s)", + Long: "This command will shutdown power to a set of nodes specified by PATTERN.", + RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/power/reset/root.go b/internal/app/wwctl/power/reset/root.go index 02d79c3a..ed157dfa 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -8,10 +8,10 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "reset [OPTIONS] [PATTERN ...]", - Short: "Issue a reset to node(s)", - Long: "This command will issue a reset to a set of nodes specified by PATTERN.", - RunE: CobraRunE, + Use: "reset [OPTIONS] [PATTERN ...]", + Short: "Issue a reset to node(s)", + Long: "This command will issue a reset to a set of nodes specified by PATTERN.", + RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/power/root.go b/internal/app/wwctl/power/root.go index 135139b2..1aeee739 100644 --- a/internal/app/wwctl/power/root.go +++ b/internal/app/wwctl/power/root.go @@ -13,9 +13,9 @@ import ( var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "power COMMAND [OPTIONS]", - Short: "Warewulf node power management", - Long: "This command controls the power state of nodes.", + Use: "power COMMAND [OPTIONS]", + Short: "Warewulf node power management", + Long: "This command controls the power state of nodes.", } ) diff --git a/internal/app/wwctl/power/soft/root.go b/internal/app/wwctl/power/soft/root.go index 77100254..c2cc559b 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -8,10 +8,10 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "soft", - Short: "Gracefully shuts down the given node(s)", - Long: "This command uses the operationg system to shut down the set of nodes specified by PATTERN.", - RunE: CobraRunE, + Use: "soft", + Short: "Gracefully shuts down the given node(s)", + Long: "This command uses the operationg system to shut down the set of nodes specified by PATTERN.", + RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/power/status/root.go b/internal/app/wwctl/power/status/root.go index 40c6fc64..06487cb2 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -8,10 +8,10 @@ import ( var ( powerCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "status [OPTIONS] [PATTERN ...]", - Short: "Show power status for the given node(s)", - Long: "This command displays the power status of a set of nodes specified by PATTERN.", - RunE: CobraRunE, + Use: "status [OPTIONS] [PATTERN ...]", + Short: "Show power status for the given node(s)", + Long: "This command displays the power status of a set of nodes specified by PATTERN.", + RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/profile/list/main_test.go b/internal/app/wwctl/profile/list/main_test.go index 5741e471..2f6f7564 100644 --- a/internal/app/wwctl/profile/list/main_test.go +++ b/internal/app/wwctl/profile/list/main_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" - "github.com/hpcng/warewulf/internal/pkg/node" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/warewulfd" "github.com/stretchr/testify/assert" ) diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index e694b09f..019db65c 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -14,8 +14,8 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/server" "github.com/hpcng/warewulf/internal/app/wwctl/ssh" "github.com/hpcng/warewulf/internal/app/wwctl/version" - "github.com/hpcng/warewulf/internal/pkg/help" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/help" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" ) diff --git a/internal/app/wwctl/server/reload/root.go b/internal/app/wwctl/server/reload/root.go index 9a880b7a..b8b6d4c2 100644 --- a/internal/app/wwctl/server/reload/root.go +++ b/internal/app/wwctl/server/reload/root.go @@ -5,9 +5,9 @@ import "github.com/spf13/cobra" var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "reload [OPTIONS]", - Short: "Reload the Warewulf server configuration", - RunE: CobraRunE, + Use: "reload [OPTIONS]", + Short: "Reload the Warewulf server configuration", + RunE: CobraRunE, } ) diff --git a/internal/app/wwctl/server/restart/root.go b/internal/app/wwctl/server/restart/root.go index 84224ed6..12be5f97 100644 --- a/internal/app/wwctl/server/restart/root.go +++ b/internal/app/wwctl/server/restart/root.go @@ -5,9 +5,9 @@ import "github.com/spf13/cobra" var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "restart [OPTIONS]", - Short: "Restart the Warewulf server", - RunE: CobraRunE, + Use: "restart [OPTIONS]", + Short: "Restart the Warewulf server", + RunE: CobraRunE, } ) diff --git a/internal/app/wwctl/server/root.go b/internal/app/wwctl/server/root.go index 22b1bce3..736c3dd3 100644 --- a/internal/app/wwctl/server/root.go +++ b/internal/app/wwctl/server/root.go @@ -12,9 +12,9 @@ import ( var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "server COMMAND [OPTIONS]", - Short: "Warewulf server process commands", - Long: "This command will allow you to control the Warewulf daemon process.", + Use: "server COMMAND [OPTIONS]", + Short: "Warewulf server process commands", + Long: "This command will allow you to control the Warewulf daemon process.", } ) diff --git a/internal/app/wwctl/server/start/root.go b/internal/app/wwctl/server/start/root.go index be4e0621..ba0d02b0 100644 --- a/internal/app/wwctl/server/start/root.go +++ b/internal/app/wwctl/server/start/root.go @@ -5,9 +5,9 @@ import "github.com/spf13/cobra" var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "start [OPTIONS]", - Short: "Start Warewulf server", - RunE: CobraRunE, + Use: "start [OPTIONS]", + Short: "Start Warewulf server", + RunE: CobraRunE, } SetForeground bool ) diff --git a/internal/app/wwctl/server/status/root.go b/internal/app/wwctl/server/status/root.go index 83a07b8c..396c44d3 100644 --- a/internal/app/wwctl/server/status/root.go +++ b/internal/app/wwctl/server/status/root.go @@ -5,9 +5,9 @@ import "github.com/spf13/cobra" var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "status [OPTIONS]", - Short: "Warewulf server status", - RunE: CobraRunE, + Use: "status [OPTIONS]", + Short: "Warewulf server status", + RunE: CobraRunE, } ) diff --git a/internal/app/wwctl/server/stop/root.go b/internal/app/wwctl/server/stop/root.go index 94df3acc..02ec9808 100644 --- a/internal/app/wwctl/server/stop/root.go +++ b/internal/app/wwctl/server/stop/root.go @@ -5,9 +5,9 @@ import "github.com/spf13/cobra" var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "stop [OPTIONS]", - Short: "Stop Warewulf server", - RunE: CobraRunE, + Use: "stop [OPTIONS]", + Short: "Stop Warewulf server", + RunE: CobraRunE, } ) diff --git a/internal/pkg/api/apiconfig/tls.go b/internal/pkg/api/apiconfig/tls.go index 1228cc8c..eb101091 100644 --- a/internal/pkg/api/apiconfig/tls.go +++ b/internal/pkg/api/apiconfig/tls.go @@ -17,4 +17,4 @@ type TlsConfig struct { // should be the concatenation of the server's certificate, any // intermediates, and the CA's certificate ConcatCert string `yaml:"concatcert,omitempty"` -} \ No newline at end of file +} diff --git a/internal/pkg/config/dhcp.go b/internal/pkg/config/dhcp.go index 3dbcd241..b1b8790e 100644 --- a/internal/pkg/config/dhcp.go +++ b/internal/pkg/config/dhcp.go @@ -1,6 +1,5 @@ package config - // DHCPConf represents the configuration for the DHCP service that // Warewulf will configure. type DHCPConf struct { diff --git a/internal/pkg/config/nfs.go b/internal/pkg/config/nfs.go index 03726379..c7ad986e 100644 --- a/internal/pkg/config/nfs.go +++ b/internal/pkg/config/nfs.go @@ -1,11 +1,9 @@ package config - import ( "github.com/creasty/defaults" ) - // NFSConf represents the NFS configuration that will be used by // Warewulf to generate exports on the server and mounts on compute // nodes. @@ -15,7 +13,6 @@ type NFSConf struct { SystemdName string `yaml:"systemd name" default:"nfsd"` } - // An NFSExportConf reprents a single NFS export / mount. type NFSExportConf struct { Path string `yaml:"path" default:"/dev/null"` @@ -24,7 +21,6 @@ type NFSExportConf struct { Mount bool `default:"true" yaml:"mount"` } - // Implements the Unmarshal interface for NFSConf to set default // values. func (conf *NFSConf) Unmarshal(unmarshal func(interface{}) error) error { diff --git a/internal/pkg/config/root_test.go b/internal/pkg/config/root_test.go index d1d0f3d1..f8c9a697 100644 --- a/internal/pkg/config/root_test.go +++ b/internal/pkg/config/root_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/assert" ) - func TestDefaultRootConf(t *testing.T) { conf := New() @@ -58,7 +57,6 @@ func TestDefaultRootConf(t *testing.T) { assert.NotEmpty(t, conf.Paths.WWClientdir) } - func TestInitializedFromFile(t *testing.T) { example_warewulf_conf := "WW_INTERNAL: 43" tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-") @@ -74,7 +72,6 @@ func TestInitializedFromFile(t *testing.T) { assert.True(t, conf.InitializedFromFile()) } - func TestExampleRootConf(t *testing.T) { example_warewulf_conf := `WW_INTERNAL: 43 ipaddr: 192.168.200.1 @@ -157,7 +154,6 @@ container mounts: assert.True(t, conf.MountsContainer[0].ReadOnly) } - func TestCache(t *testing.T) { confOrig := New() confCached := Get() diff --git a/internal/pkg/config/tftp.go b/internal/pkg/config/tftp.go index 1c898e39..78f8d2aa 100644 --- a/internal/pkg/config/tftp.go +++ b/internal/pkg/config/tftp.go @@ -1,12 +1,11 @@ package config - // TFTPConf represents that configuration for the TFTP service that // Warewulf will configure. type TFTPConf struct { - Enabled bool `yaml:"enabled" default:"true"` - TftpRoot string `yaml:"tftproot" default:"/var/lib/tftpboot"` - SystemdName string `yaml:"systemd name" default:"tftp"` + Enabled bool `yaml:"enabled" default:"true"` + TftpRoot string `yaml:"tftproot" default:"/var/lib/tftpboot"` + SystemdName string `yaml:"systemd name" default:"tftp"` // Path is relative to buildconfig.DATADIR() IpxeBinaries map[string]string `yaml:"ipxe" default:"{\"00:09\": \"ipxe/ipxe-snponly-x86_64.efi\",\"00:00\": \"ipxe/undionly.kpxe\",\"00:0B\": \"ipxe/arm64-efi/snponly.efi\",\"00:07\": \"ipxe/ipxe-snponly-x86_64.efi\"}"` diff --git a/internal/pkg/config/warewulf.go b/internal/pkg/config/warewulf.go index 75d6b6ba..e8f08ac5 100644 --- a/internal/pkg/config/warewulf.go +++ b/internal/pkg/config/warewulf.go @@ -1,6 +1,5 @@ package config - // WarewulfConf adds additional Warewulf-specific configuration to // BaseConf. type WarewulfConf struct { diff --git a/internal/pkg/configure/dhcp.go b/internal/pkg/configure/dhcp.go index 02613f05..cbac1729 100644 --- a/internal/pkg/configure/dhcp.go +++ b/internal/pkg/configure/dhcp.go @@ -4,9 +4,9 @@ import ( "fmt" "os" + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/pkg/errors" ) diff --git a/internal/pkg/configure/nfs.go b/internal/pkg/configure/nfs.go index 82f70e84..06367caa 100644 --- a/internal/pkg/configure/nfs.go +++ b/internal/pkg/configure/nfs.go @@ -3,9 +3,9 @@ package configure import ( "fmt" + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/pkg/errors" ) diff --git a/internal/pkg/configure/ssh.go b/internal/pkg/configure/ssh.go index 1c24a3b2..a5e220ea 100644 --- a/internal/pkg/configure/ssh.go +++ b/internal/pkg/configure/ssh.go @@ -5,8 +5,8 @@ import ( "os" "path" - "github.com/hpcng/warewulf/internal/pkg/util" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/pkg/errors" ) diff --git a/internal/pkg/configure/tftp.go b/internal/pkg/configure/tftp.go index 6cfb9561..71d7719c 100644 --- a/internal/pkg/configure/tftp.go +++ b/internal/pkg/configure/tftp.go @@ -5,8 +5,8 @@ import ( "os" "path" - "github.com/hpcng/warewulf/internal/pkg/util" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" ) diff --git a/internal/pkg/container/syncuids.go b/internal/pkg/container/syncuids.go index a4bac584..529b2e86 100644 --- a/internal/pkg/container/syncuids.go +++ b/internal/pkg/container/syncuids.go @@ -16,11 +16,9 @@ import ( "github.com/pkg/errors" ) - const passwdPath = "/etc/passwd" const groupPath = "/etc/group" - // SyncUids updates the /etc/passwd and /etc/group files in the // container identified by containerName by installing the equivalent // files from the host and appending names only in the @@ -41,16 +39,32 @@ func SyncUids(containerName string, showOnly bool) error { containerGroupPath := path.Join(containerPath, groupPath) passwdSync := make(syncDB) - if err := passwdSync.readFromHost(passwdPath); err != nil { return err } - if err := passwdSync.readFromContainer(containerPasswdPath); err != nil { return err } - if err := passwdSync.checkConflicts(); err != nil { return err } - if err := passwdSync.findUserFiles(containerPath); err != nil { return err } + if err := passwdSync.readFromHost(passwdPath); err != nil { + return err + } + if err := passwdSync.readFromContainer(containerPasswdPath); err != nil { + return err + } + if err := passwdSync.checkConflicts(); err != nil { + return err + } + if err := passwdSync.findUserFiles(containerPath); err != nil { + return err + } groupSync := make(syncDB) - if err := groupSync.readFromHost(groupPath); err != nil { return err } - if err := groupSync.readFromContainer(containerGroupPath); err != nil { return err } - if err := groupSync.checkConflicts(); err != nil { return err } - if err := groupSync.findGroupFiles(containerPath); err != nil { return err } + if err := groupSync.readFromHost(groupPath); err != nil { + return err + } + if err := groupSync.readFromContainer(containerGroupPath); err != nil { + return err + } + if err := groupSync.checkConflicts(); err != nil { + return err + } + if err := groupSync.findGroupFiles(containerPath); err != nil { + return err + } passwdSync.log("passwd") groupSync.log("group") @@ -62,31 +76,37 @@ func SyncUids(containerName string, showOnly bool) error { wwlog.Info("uid/gid already synced") } } else { - if err := passwdSync.chownUserFiles(); err != nil { return err } - if err := groupSync.chownGroupFiles(); err != nil { return err } + if err := passwdSync.chownUserFiles(); err != nil { + return err + } + if err := groupSync.chownGroupFiles(); err != nil { + return err + } - if err := passwdSync.update(containerPasswdPath, passwdPath); err != nil { return err } - if err := groupSync.update(containerGroupPath, groupPath); err != nil { return err } + if err := passwdSync.update(containerPasswdPath, passwdPath); err != nil { + return err + } + if err := groupSync.update(containerGroupPath, groupPath); err != nil { + return err + } wwlog.Info("uid/gid synced for container %s", containerName) } return nil } - // A syncDB maps user or group names to syncInfo instances, which // correlate IDs between host and container and track affected // files. This can be used for either /etc/passwd or /etc/group IDs. type syncDB map[string]syncInfo - // checkConflicts inspects a syncDB map for irreconcilable // conflicts. A conflict arises if the container has an entry with the // same id as an entry in the host and the host does not have an entry // with the same name. func (db syncDB) checkConflicts() error { for nameInContainer, containerIds := range db { - if (!containerIds.inContainer() || containerIds.inHost()) { + if !containerIds.inContainer() || containerIds.inHost() { continue } @@ -102,7 +122,6 @@ func (db syncDB) checkConflicts() error { return nil } - // log generates debug and verbose logs inspecting a syncDB map. // // The provided prefix is prepended to log entries to provide context @@ -112,10 +131,18 @@ func (db syncDB) log(prefix string) { var onlyContainer, onlyHost, match, differ []string for name, ids := range db { wwlog.Debug("%s: %s: host(%v) container(%v) files: %v", prefix, name, ids.HostID, ids.ContainerID, ids.ContainerFiles) - if ids.onlyContainer() { onlyContainer = append(onlyContainer, name) } - if ids.onlyHost() { onlyHost = append(onlyHost, name) } - if ids.match() { match = append(match, name) } - if ids.differ() { differ = append(differ, name) } + if ids.onlyContainer() { + onlyContainer = append(onlyContainer, name) + } + if ids.onlyHost() { + onlyHost = append(onlyHost, name) + } + if ids.match() { + match = append(match, name) + } + if ids.differ() { + differ = append(differ, name) + } } wwlog.Verbose("%s: container only: %v", prefix, onlyContainer) @@ -124,7 +151,6 @@ func (db syncDB) log(prefix string) { wwlog.Verbose("%s: differ: %v", prefix, differ) } - // read reads fileName (an /etc/passwd or /etc/group file) into a // syncDB map. Since the name and numerical id for both files are // stored at fields 0 and 2, the same function can read both files. @@ -180,19 +206,16 @@ func (db syncDB) read(fileName string, fromContainer bool) error { } } - // readFromHost reads fileName into a syncDB map. // // Equivalent to read(fileName, false) func (db syncDB) readFromHost(fileName string) error { return db.read(fileName, false) } - // readFromContainer reads fileName into a syncDB map. // // Equivalent to read(fileName, true) func (db syncDB) readFromContainer(fileName string) error { return db.read(fileName, true) } - // findFiles finds files under containerPath that are owned by each // tracked container ID. // @@ -200,7 +223,9 @@ func (db syncDB) readFromContainer(fileName string) error { return db.read(fileN // recorded. Otherwise, files with a matching uid are recorded. func (db syncDB) findFiles(containerPath string, byGid bool) error { for name, ids := range db { - if err := ids.findFiles(containerPath, byGid); err != nil { return err } + if err := ids.findFiles(containerPath, byGid); err != nil { + return err + } if len(ids.ContainerFiles) > 0 { wwlog.Debug("files for %s (%v -> %v, gid: %v): %v", name, ids.ContainerID, ids.HostID, byGid, ids.ContainerFiles) } @@ -209,15 +234,12 @@ func (db syncDB) findFiles(containerPath string, byGid bool) error { return nil } - // findUserFiles is equivalent to findFiles(containerPath, false) func (db syncDB) findUserFiles(containerPath string) error { return db.findFiles(containerPath, false) } - // findGroupFiles is equivalent to findFiles(containerPath, true) func (db syncDB) findGroupFiles(containerPath string) error { return db.findFiles(containerPath, true) } - // chownFiles updates found files (see findFiles) to reflect ownership // using host ids. // @@ -225,20 +247,19 @@ func (db syncDB) findGroupFiles(containerPath string) error { return db.findFile // updated. func (db syncDB) chownFiles(byGid bool) error { for _, ids := range db { - if err := ids.chownFiles(byGid); err != nil { return err } + if err := ids.chownFiles(byGid); err != nil { + return err + } } return nil } - // chownUserFiles is equivalent to chownFiles(false) func (db syncDB) chownUserFiles() error { return db.chownFiles(false) } - // chownUserFiles is equivalent to chownFiles(true) func (db syncDB) chownGroupFiles() error { return db.chownFiles(true) } - // getOnlyContainerLines returns the lines from fileName (either an // /etc/passwd or /etc/group file) for names that occur only in the // container. @@ -247,7 +268,9 @@ func (db syncDB) chownGroupFiles() error { return db.chownFiles(true) } // updating the container. func (db syncDB) getOnlyContainerLines(fileName string) ([]string, error) { file, err := os.Open(fileName) - if err != nil { return nil, err } + if err != nil { + return nil, err + } defer file.Close() fileScanner := bufio.NewScanner(file) @@ -268,7 +291,6 @@ func (db syncDB) getOnlyContainerLines(fileName string) ([]string, error) { return lines, nil } - // update replaces containerPath with hostPath and adds lines from // getOnlyContainerLines to the end of containerPath. This is used to // replace /etc/passwd (or /etc/group) in the container with the @@ -279,14 +301,19 @@ func (db syncDB) update(containerPath string, hostPath string) error { if lines, err := db.getOnlyContainerLines(containerPath); err != nil { return err } else { - if err := os.Remove(containerPath); err != nil { return err } - if err := util.CopyFile(hostPath, containerPath); err != nil { return err } - if err := util.AppendLines(containerPath, lines); err != nil { return err } + if err := os.Remove(containerPath); err != nil { + return err + } + if err := util.CopyFile(hostPath, containerPath); err != nil { + return err + } + if err := util.AppendLines(containerPath, lines); err != nil { + return err + } return nil } } - // needsSync returns true if the syncDB map indicates that ids between // the container and host are out-of-sync. func (db syncDB) needsSync() bool { @@ -306,7 +333,6 @@ func (db syncDB) needsSync() bool { return false } - // sycncInfo correlates the numerical id of a name on the host // (HostID) and the container (ContainerID), along with the files in // the container that are owned by that name. This allows affected @@ -317,49 +343,42 @@ type syncInfo struct { ContainerFiles []string `access:"r,w"` } - // inHost returns true if info has a record of an id for this name in // the host. func (info *syncInfo) inHost() bool { return info.HostID != -1 } - // inContainer returns true if info has a record of an id for this // name in the container. func (info *syncInfo) inContainer() bool { return info.ContainerID != -1 } - // onlyHost returns true if info has a record of an id for this name // in the host and not in the container. func (info *syncInfo) onlyHost() bool { return info.inHost() && !info.inContainer() } - // onlyHost returns true if info has a record of an id for this name // in the container and not in the host. func (info *syncInfo) onlyContainer() bool { return info.inContainer() && !info.inHost() } - // match returns true if info represents a name that exists with the // same numerical id in both the host and the container. func (info *syncInfo) match() bool { return info.inContainer() && info.inHost() && info.HostID == info.ContainerID } - // differ returns true if info represents a name that exists in both // the host and the container but with different numerical ids. func (info *syncInfo) differ() bool { return info.inContainer() && info.inHost() && info.HostID != info.ContainerID } - // findFiles walks containerPath to find files owned by the name // represented by info and records them in info.ContainerFiles. // @@ -367,7 +386,7 @@ func (info *syncInfo) differ() bool { // uid is checked. func (info *syncInfo) findFiles(containerPath string, byGid bool) error { var containerFiles []string - if (info.inHost() && !info.match()) { + if info.inHost() && !info.match() { if err := filepath.Walk(containerPath, func(filePath string, fileInfo fs.FileInfo, err error) error { if stat, ok := fileInfo.Sys().(*syscall.Stat_t); ok { var id int @@ -389,7 +408,6 @@ func (info *syncInfo) findFiles(containerPath string, byGid bool) error { return nil } - // chownFiles updates the files recorded in info.ContainerFiles to use // the numerical IDs from the host. // @@ -409,7 +427,9 @@ func (info *syncInfo) chownFiles(byGid bool) error { newUid = info.HostID newGid = -1 } - if err := os.Chown(file, newUid, newGid); err != nil { return err } + if err := os.Chown(file, newUid, newGid); err != nil { + return err + } } } } diff --git a/internal/pkg/container/syncuids_test.go b/internal/pkg/container/syncuids_test.go index d4cf3f8d..70951b92 100644 --- a/internal/pkg/container/syncuids_test.go +++ b/internal/pkg/container/syncuids_test.go @@ -7,8 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) - -func writeTempFile(t *testing.T, input string) (string) { +func writeTempFile(t *testing.T, input string) string { tempFile, createTempError := os.CreateTemp("", "syncuids-*") assert.NoError(t, createTempError) _, writeError := tempFile.Write([]byte(input)) @@ -17,8 +16,7 @@ func writeTempFile(t *testing.T, input string) (string) { return tempFile.Name() } - -func makeSyncDB(t *testing.T, hostInput string, containerInput string) (syncDB) { +func makeSyncDB(t *testing.T, hostInput string, containerInput string) syncDB { hostFileName := writeTempFile(t, hostInput) defer os.Remove(hostFileName) containerFileName := writeTempFile(t, containerInput) @@ -32,7 +30,6 @@ func makeSyncDB(t *testing.T, hostInput string, containerInput string) (syncDB) return db } - func Test_readFromHost_single(t *testing.T) { hostFileName := writeTempFile(t, `testuser:x:1001:1001::/home/testuser:/bin/bash`) defer os.Remove(hostFileName) @@ -46,7 +43,6 @@ func Test_readFromHost_single(t *testing.T) { assert.Equal(t, -1, db["testuser"].ContainerID) } - func Test_readFromHost_multiple(t *testing.T) { hostFileName := writeTempFile(t, ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -65,7 +61,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash assert.Equal(t, -1, db["testuser2"].ContainerID) } - func Test_readFromContainer_single(t *testing.T) { containerFileName := writeTempFile(t, `testuser:x:1001:1001::/home/testuser:/bin/bash`) defer os.Remove(containerFileName) @@ -79,7 +74,6 @@ func Test_readFromContainer_single(t *testing.T) { assert.Equal(t, -1, db["testuser"].HostID) } - func Test_readFromContainer_multiple(t *testing.T) { containerFileName := writeTempFile(t, ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -97,7 +91,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash assert.Equal(t, -1, db["testuser2"].HostID) } - func Test_readFromBoth_multiple(t *testing.T) { containerFileName := writeTempFile(t, ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -105,7 +98,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash `) defer os.Remove(containerFileName) - hostFileName := writeTempFile(t, ` testuser1:x:2001:2001::/home/testuser:/bin/bash testuser3:x:2003:2003::/home/testuser:/bin/bash @@ -127,19 +119,16 @@ testuser3:x:2003:2003::/home/testuser:/bin/bash assert.Equal(t, 2003, db["testuser3"].HostID) } - func Test_checkConflicts_empty(t *testing.T) { db := makeSyncDB(t, "", "") assert.NoError(t, db.checkConflicts()) } - func Test_checkConflicts_single(t *testing.T) { db := makeSyncDB(t, "", "testuser:x:1001:1001::/home/testuser:/bin/bash") assert.NoError(t, db.checkConflicts()) } - func Test_checkConflicts_match(t *testing.T) { db := makeSyncDB(t, "testuser:x:1001:1001::/home/testuser:/bin/bash", @@ -147,7 +136,6 @@ func Test_checkConflicts_match(t *testing.T) { assert.NoError(t, db.checkConflicts()) } - func Test_checkConflicts_conflict(t *testing.T) { db := makeSyncDB(t, "testuser2:x:1001:1001::/home/testuser:/bin/bash", @@ -155,7 +143,6 @@ func Test_checkConflicts_conflict(t *testing.T) { assert.Error(t, db.checkConflicts()) } - func Test_getOnlyContainerLines(t *testing.T) { containerFileName := writeTempFile(t, ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -163,7 +150,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash `) defer os.Remove(containerFileName) - hostFileName := writeTempFile(t, ` testuser1:x:2001:2001::/home/testuser:/bin/bash testuser3:x:2003:2003::/home/testuser:/bin/bash @@ -184,13 +170,11 @@ testuser3:x:2003:2003::/home/testuser:/bin/bash assert.Equal(t, lines[0], "testuser2:x:1002:1002::/home/testuser:/bin/bash") } - func Test_needsSync_empty(t *testing.T) { db := makeSyncDB(t, "", "") assert.False(t, db.needsSync()) } - func Test_needsSync_containerOnly(t *testing.T) { db := makeSyncDB(t, "", ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -199,7 +183,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash`) assert.False(t, db.needsSync()) } - func Test_needsSync_hostOnly(t *testing.T) { db := makeSyncDB(t, ` testuser1:x:1001:1001::/home/testuser:/bin/bash @@ -208,7 +191,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash`, "") assert.True(t, db.needsSync()) } - func Test_needsSync_match(t *testing.T) { db := makeSyncDB(t, "testuser:x:1001:1001::/home/testuser:/bin/bash", @@ -217,7 +199,6 @@ func Test_needsSync_match(t *testing.T) { assert.False(t, db.needsSync()) } - func Test_needsSync_differ(t *testing.T) { db := makeSyncDB(t, ` @@ -230,7 +211,6 @@ testuser2:x:1002:1002::/home/testuser:/bin/bash`) assert.True(t, db.needsSync()) } - func Test_onlyHost(t *testing.T) { db := makeSyncDB(t, "testuser1:x:2001:2001::/home/testuser:/bin/bash", "") entry := db["testuser1"] @@ -242,7 +222,6 @@ func Test_onlyHost(t *testing.T) { assert.False(t, entry.differ()) } - func Test_onlyContainer(t *testing.T) { db := makeSyncDB(t, "", "testuser1:x:2001:2001::/home/testuser:/bin/bash") entry := db["testuser1"] @@ -254,7 +233,6 @@ func Test_onlyContainer(t *testing.T) { assert.False(t, entry.differ()) } - func Test_match(t *testing.T) { db := makeSyncDB(t, "testuser1:x:2001:2001::/home/testuser:/bin/bash", @@ -268,7 +246,6 @@ func Test_match(t *testing.T) { assert.False(t, entry.differ()) } - func Test_differ(t *testing.T) { db := makeSyncDB(t, "testuser1:x:1001:1001::/home/testuser:/bin/bash", diff --git a/internal/pkg/help/help.go b/internal/pkg/help/help.go index 1deda31b..8ce94c9b 100644 --- a/internal/pkg/help/help.go +++ b/internal/pkg/help/help.go @@ -26,6 +26,7 @@ Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} Use "{{.CommandPath}} COMMAND --help" for more information about a COMMAND. {{end}} ` + // End UsageTemplate // HelpTemplate replaces the default help template from cobra diff --git a/internal/pkg/kernel/kernel.go b/internal/pkg/kernel/kernel.go index a735f384..47395d5c 100644 --- a/internal/pkg/kernel/kernel.go +++ b/internal/pkg/kernel/kernel.go @@ -11,8 +11,8 @@ import ( "github.com/pkg/errors" - "github.com/hpcng/warewulf/internal/pkg/util" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" ) diff --git a/internal/pkg/node/constuctors_test.go b/internal/pkg/node/constuctors_test.go index 0aacf659..406dad9d 100644 --- a/internal/pkg/node/constuctors_test.go +++ b/internal/pkg/node/constuctors_test.go @@ -1,9 +1,9 @@ package node import ( - "testing" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + "testing" ) func newConstructorPrimaryNetworkTest() NodeYaml { @@ -107,13 +107,12 @@ func Test_Primary_Network(t *testing.T) { }) } - -var findDiscoverableNodeTests = []struct{ - description string - discoverable_nodes []string - discovered_node string +var findDiscoverableNodeTests = []struct { + description string + discoverable_nodes []string + discovered_node string discovered_interface string - succeed bool + succeed bool }{ {"no discoverable nodes", []string{}, "", "", false}, {"all nodes discoverable", []string{"test_node1", "test_node2", "test_node3", "test_node4"}, "test_node1", "net0", true}, diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 5a979b09..6eb674a8 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -229,4 +229,3 @@ type FileSystemEntry struct { // string which is printed if no value is set const NoValue = "--" - diff --git a/internal/pkg/node/node_test.go b/internal/pkg/node/node_test.go index 13003a06..595f9632 100644 --- a/internal/pkg/node/node_test.go +++ b/internal/pkg/node/node_test.go @@ -3,8 +3,8 @@ package node import ( "testing" - "gopkg.in/yaml.v2" "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" ) func TestNodeUpdate(t *testing.T) { @@ -31,7 +31,7 @@ nodes: err = nodeYaml.NodeUpdate( NodeInfo{ - Id: Entry { + Id: Entry{ value: []string{"n0000"}, }, }, @@ -39,7 +39,6 @@ nodes: assert.NoError(t, err) } - func TestNodeDisk(t *testing.T) { node_config := `WW_INTERNAL: 43 nodes: diff --git a/internal/pkg/oci/defaults.go b/internal/pkg/oci/defaults.go index f7158a6f..e5be5a6a 100644 --- a/internal/pkg/oci/defaults.go +++ b/internal/pkg/oci/defaults.go @@ -8,6 +8,6 @@ import ( var defaultCachePath = filepath.Join(warewulfconf.Get().Warewulf.DataStore, "/container-cache/oci/") const ( - blobPrefix = "blobs" - rootfsPrefix = "rootfs" + blobPrefix = "blobs" + rootfsPrefix = "rootfs" ) diff --git a/internal/pkg/overlay/config.go b/internal/pkg/overlay/config.go index cbfe81b7..11b54112 100644 --- a/internal/pkg/overlay/config.go +++ b/internal/pkg/overlay/config.go @@ -5,8 +5,8 @@ import ( "path" "strings" - "github.com/hpcng/warewulf/internal/pkg/wwlog" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/wwlog" ) func OverlaySourceTopDir() string { @@ -48,7 +48,7 @@ func OverlayImage(nodeName string, context string, overlayNames []string) string } name = "__" + strings.ToUpper(context) + "__.img" } else if len(overlayNames) > 0 { - name = strings.Join(overlayNames, "-")+".img" + name = strings.Join(overlayNames, "-") + ".img" } else { wwlog.Warn("unable to generate overlay image path: no context or overlays specified") return "" diff --git a/internal/pkg/overlay/config_test.go b/internal/pkg/overlay/config_test.go index 34254a45..74033626 100644 --- a/internal/pkg/overlay/config_test.go +++ b/internal/pkg/overlay/config_test.go @@ -1,16 +1,16 @@ package overlay import ( - "testing" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "testing" ) -var overlayImageTests = []struct{ +var overlayImageTests = []struct { description string - node string - context string - overlays []string - image string + node string + context string + overlays []string + image string }{ {"all empty", "", "", nil, ""}, {"empty with named context", "", "system", nil, "p/overlays/__SYSTEM__.img"}, @@ -30,7 +30,7 @@ func Test_OverlayImage(t *testing.T) { for _, tt := range overlayImageTests { t.Run(tt.description, func(t *testing.T) { out := OverlayImage(tt.node, tt.context, tt.overlays) - if tt.image != out { + if tt.image != out { t.Errorf("got %q, want %q", out, tt.image) } }) diff --git a/internal/pkg/overlay/funcmap_test.go b/internal/pkg/overlay/funcmap_test.go index ab1a4be2..03d23a6c 100644 --- a/internal/pkg/overlay/funcmap_test.go +++ b/internal/pkg/overlay/funcmap_test.go @@ -1,9 +1,9 @@ package overlay import ( - "testing" - "github.com/stretchr/testify/assert" "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/stretchr/testify/assert" + "testing" ) func Test_createIgnitionJson(t *testing.T) { diff --git a/internal/pkg/overlay/overlay_test.go b/internal/pkg/overlay/overlay_test.go index 25944a83..2e7d446b 100644 --- a/internal/pkg/overlay/overlay_test.go +++ b/internal/pkg/overlay/overlay_test.go @@ -1,25 +1,25 @@ package overlay import ( + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/sassoftware/go-rpmutils/cpio" + "github.com/stretchr/testify/assert" "io" "os" "path" - "strings" "sort" + "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/sassoftware/go-rpmutils/cpio" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" - "github.com/hpcng/warewulf/internal/pkg/node" ) -var buildOverlayTests = []struct{ +var buildOverlayTests = []struct { description string - nodeName string - context string - overlays []string - image string - contents []string + nodeName string + context string + overlays []string + image string + contents []string }{ {"empty", "", "", nil, "", nil}, {"empty node", "node1", "", nil, "", nil}, @@ -42,9 +42,15 @@ func Test_BuildOverlay(t *testing.T) { defer os.RemoveAll(overlayDir) conf.Paths.WWOverlaydir = overlayDir assert.NoError(t, os.Mkdir(path.Join(overlayDir, "o1"), 0700)) - { _, err := os.Create(path.Join(overlayDir, "o1", "o1.txt")); assert.NoError(t, err) } + { + _, err := os.Create(path.Join(overlayDir, "o1", "o1.txt")) + assert.NoError(t, err) + } assert.NoError(t, os.Mkdir(path.Join(overlayDir, "o2"), 0700)) - { _, err := os.Create(path.Join(overlayDir, "o2", "o2.txt")); assert.NoError(t, err) } + { + _, err := os.Create(path.Join(overlayDir, "o2", "o2.txt")) + assert.NoError(t, err) + } for _, tt := range buildOverlayTests { assert.True(t, (tt.image != "" && tt.contents != nil) || (tt.image == "" && tt.contents == nil), @@ -78,12 +84,12 @@ func Test_BuildOverlay(t *testing.T) { } } -var buildAllOverlaysTests = []struct{ - description string - nodes []string - systemOverlays []string +var buildAllOverlaysTests = []struct { + description string + nodes []string + systemOverlays []string runtimeOverlays []string - succeed bool + succeed bool }{ {"no nodes", nil, nil, nil, true}, {"single empty node", []string{"node1"}, nil, nil, false}, @@ -102,7 +108,6 @@ var buildAllOverlaysTests = []struct{ []string{"o1", "o1,o2"}, []string{"o2", "o2"}, true}, } - func Test_BuildAllOverlays(t *testing.T) { conf := warewulfconf.Get() overlayDir, overlayDirErr := os.MkdirTemp(os.TempDir(), "ww-test-overlay-*") @@ -145,12 +150,12 @@ func Test_BuildAllOverlays(t *testing.T) { } } -var buildSpecificOverlaysTests = []struct{ +var buildSpecificOverlaysTests = []struct { description string - nodes []string - overlays string - images []string - succeed bool + nodes []string + overlays string + images []string + succeed bool }{ {"no nodes", nil, "", nil, true}, {"single empty node", []string{"node1"}, "", nil, false}, @@ -165,7 +170,6 @@ var buildSpecificOverlaysTests = []struct{ []string{"node1/o1.img", "node1/o2.img", "node2/o1.img", "node2/o2.img"}, true}, } - func Test_BuildSpecificOverlays(t *testing.T) { conf := warewulfconf.Get() overlayDir, overlayDirErr := os.MkdirTemp(os.TempDir(), "ww-test-overlay-*") @@ -220,13 +224,17 @@ func dirIsEmpty(t *testing.T, name string) bool { func cpioFiles(t *testing.T, name string) (files []string) { f, openErr := os.Open(name) - if openErr != nil { return } + if openErr != nil { + return + } defer f.Close() reader := cpio.NewReader(f) for { header, err := reader.Next() - if err != nil { return } + if err != nil { + return + } files = append(files, header.Filename()) } } diff --git a/internal/pkg/testenv/testenv.go b/internal/pkg/testenv/testenv.go index a9889b50..15ea117a 100644 --- a/internal/pkg/testenv/testenv.go +++ b/internal/pkg/testenv/testenv.go @@ -79,7 +79,7 @@ func New(t *testing.T) (env *TestEnv) { conf.Paths.WWChrootdir, conf.Paths.WWProvisiondir, conf.Paths.WWClientdir, - }{ + } { env.MkdirAll(t, confPath) } diff --git a/internal/pkg/warewulfd/nodedb.go b/internal/pkg/warewulfd/nodedb.go index 96921261..5d8e4cf8 100644 --- a/internal/pkg/warewulfd/nodedb.go +++ b/internal/pkg/warewulfd/nodedb.go @@ -79,7 +79,6 @@ func getNodeOrSetDiscoverable(hwaddr string) (node.NodeInfo, error) { // to ensure the condition on which the node is updated is still satisfied // after the DB is read back in. - n, err := getNode(hwaddr) if err == nil { return n, nil diff --git a/internal/pkg/warewulfd/parser.go b/internal/pkg/warewulfd/parser.go index 4f4ff167..1e62dd0f 100644 --- a/internal/pkg/warewulfd/parser.go +++ b/internal/pkg/warewulfd/parser.go @@ -49,19 +49,19 @@ func parseReq(req *http.Request) (parserInfo, error) { if len(req.URL.Query()["stage"]) > 0 { ret.stage = req.URL.Query()["stage"][0] - }else{ + } else { if stage == "ipxe" || stage == "provision" { ret.stage = "ipxe" - }else if stage == "kernel" { + } else if stage == "kernel" { ret.stage = "kernel" - }else if stage == "kmods" { + } else if stage == "kmods" { ret.stage = "kmods" - }else if stage == "container" { + } else if stage == "container" { ret.stage = "container" - }else if stage == "overlay-system" { + } else if stage == "overlay-system" { ret.stage = "system" - }else if stage == "overlay-runtime" { + } else if stage == "overlay-runtime" { ret.stage = "runtime" } } diff --git a/internal/pkg/warewulfd/provision.go b/internal/pkg/warewulfd/provision.go index df9ca489..03b2798c 100644 --- a/internal/pkg/warewulfd/provision.go +++ b/internal/pkg/warewulfd/provision.go @@ -8,10 +8,10 @@ import ( "strings" "text/template" + warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/kernel" "github.com/hpcng/warewulf/internal/pkg/util" - warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/wwlog" ) diff --git a/internal/pkg/warewulfd/provision_test.go b/internal/pkg/warewulfd/provision_test.go index f79dd9e0..870e1de0 100644 --- a/internal/pkg/warewulfd/provision_test.go +++ b/internal/pkg/warewulfd/provision_test.go @@ -1,24 +1,23 @@ package warewulfd import ( + "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "net/http/httptest" "os" "path" "testing" - "github.com/stretchr/testify/assert" - "github.com/hpcng/warewulf/internal/pkg/node" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" ) - -var provisionSendTests = []struct{ +var provisionSendTests = []struct { description string - url string - body string - status int + url string + body string + status int }{ {"system overlay", "/overlay-system/00:00:00:ff:ff:ff", "system overlay", 200}, {"runtime overlay", "/overlay-runtime/00:00:00:ff:ff:ff", "runtime overlay", 200}, @@ -30,12 +29,15 @@ func Test_ProvisionSend(t *testing.T) { file, err := os.CreateTemp(os.TempDir(), "ww-test-nodes.conf-*") assert.NoError(t, err) defer file.Close() - { _, err := file.WriteString(`WW_INTERNAL: 43 + { + _, err := file.WriteString(`WW_INTERNAL: 43 nodes: n1: network devices: default: - hwaddr: 00:00:00:ff:ff:ff`); assert.NoError(t, err) } + hwaddr: 00:00:00:ff:ff:ff`) + assert.NoError(t, err) + } assert.NoError(t, file.Sync()) node.ConfigFile = file.Name() dbErr := LoadNodeDB() diff --git a/internal/pkg/warewulfd/util.go b/internal/pkg/warewulfd/util.go index 3cebbe1b..e55bf553 100644 --- a/internal/pkg/warewulfd/util.go +++ b/internal/pkg/warewulfd/util.go @@ -34,7 +34,7 @@ func sendFile( req, filename, stat.ModTime(), - fd ) + fd) wwlog.Send("%15s: %s", sendto, filename) diff --git a/internal/pkg/warewulfd/util_test.go b/internal/pkg/warewulfd/util_test.go index 671a94a9..036a938e 100644 --- a/internal/pkg/warewulfd/util_test.go +++ b/internal/pkg/warewulfd/util_test.go @@ -1,18 +1,18 @@ package warewulfd import ( - "testing" - "github.com/stretchr/testify/assert" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/stretchr/testify/assert" + "testing" ) -var getOverlayFileTests = []struct{ +var getOverlayFileTests = []struct { description string - node string - context string - overlays []string - result string - succeed bool + node string + context string + overlays []string + result string + succeed bool }{ {"empty", "", "", nil, "", true}, {"empty node", "node1", "", nil, "", true}, diff --git a/pkg/hostlist/hostlist_test.go b/pkg/hostlist/hostlist_test.go index bd89d1ff..39c73971 100644 --- a/pkg/hostlist/hostlist_test.go +++ b/pkg/hostlist/hostlist_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" ) - func Test_Single(t *testing.T) { assert.Equal(t, []string{"node1"}, Expand([]string{"node1"})) } @@ -15,12 +14,10 @@ func Test_Multiple(t *testing.T) { assert.Equal(t, []string{"node1", "node2"}, Expand([]string{"node1", "node2"})) } - func Test_Range(t *testing.T) { assert.Equal(t, []string{"node1", "node2"}, Expand([]string{"node[1-2]"})) } - func Test_Internal_Comma(t *testing.T) { assert.Equal(t, []string{"node1", "node2"}, Expand([]string{"node[1,2]"})) } @@ -29,7 +26,6 @@ func Test_Mixed_Range_Comma(t *testing.T) { assert.Equal(t, []string{"node1", "node2", "node3"}, Expand([]string{"node[1,2-3]"})) } - // not currently supported // // func Test_External_Comma(t *testing.T) {