Remove remaining gRPC references with additional tests

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2026-03-21 21:42:16 -06:00
parent 4cc6d03f2f
commit c2cfe513d7
21 changed files with 339 additions and 4332 deletions

View File

@@ -4,42 +4,38 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/image"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
cdp := &wwapiv1.ImageCopyParameter{
ImageSource: args[0],
ImageDestination: args[1],
Build: Build,
imageSource := args[0]
imageDestination := args[1]
if !image.DoesSourceExist(imageSource) {
return fmt.Errorf("image's source doesn't exists: %s", imageSource)
}
if !image.DoesSourceExist(cdp.ImageSource) {
return fmt.Errorf("image's source doesn't exists: %s", cdp.ImageSource)
if !image.ValidName(imageDestination) {
return fmt.Errorf("image name contains illegal characters : %s", imageDestination)
}
if !image.ValidName(cdp.ImageDestination) {
return fmt.Errorf("image name contains illegal characters : %s", cdp.ImageDestination)
if image.DoesSourceExist(imageDestination) {
return fmt.Errorf("an other image with name: %s already exists in sources", imageDestination)
}
if image.DoesSourceExist(cdp.ImageDestination) {
return fmt.Errorf("an other image with name: %s already exists in sources", cdp.ImageDestination)
}
err = image.Duplicate(cdp.ImageSource, cdp.ImageDestination)
err = image.Duplicate(imageSource, imageDestination)
if err != nil {
return fmt.Errorf("could not duplicate image: %s", err.Error())
}
if cdp.Build {
err = image.Build(cdp.ImageDestination, true)
if Build {
err = image.Build(imageDestination, true)
if err != nil {
return err
}
}
wwlog.Info("Image %s successfully duplicated as %s", cdp.ImageSource, cdp.ImageDestination)
wwlog.Info("Image %s successfully duplicated as %s", imageSource, imageDestination)
return
}

View File

@@ -0,0 +1,121 @@
package delete
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/warewulf/warewulf/internal/pkg/testenv"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func Test_Delete(t *testing.T) {
tests := []struct {
name string
args []string
inDB string
outDB string
wantErr bool
}{
{
name: "delete single node",
args: []string{"--yes", "n01"},
inDB: `
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default
n02:
profiles:
- default`,
outDB: `
nodeprofiles:
default: {}
nodes:
n02:
profiles:
- default`,
},
{
name: "delete multiple nodes",
args: []string{"--yes", "n01", "n02"},
inDB: `
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default
n02:
profiles:
- default
n03:
profiles:
- default`,
outDB: `
nodeprofiles:
default: {}
nodes:
n03:
profiles:
- default`,
},
{
name: "delete non-existent node",
args: []string{"--yes", "doesnotexist"},
inDB: `
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default`,
outDB: `
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default`,
},
{
name: "delete all nodes",
args: []string{"--yes", "n01", "n02"},
inDB: `
nodeprofiles:
default: {}
nodes:
n01: {}
n02: {}`,
outDB: `
nodeprofiles:
default: {}
nodes: {}`,
},
}
warewulfd.SetNoDaemon()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
env := testenv.New(t)
defer env.RemoveAll()
env.WriteFile("etc/warewulf/nodes.conf", tt.inDB)
buf := new(bytes.Buffer)
baseCmd := GetCommand()
baseCmd.SetArgs(tt.args)
baseCmd.SetOut(buf)
baseCmd.SetErr(buf)
err := baseCmd.Execute()
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
content := env.ReadFile("etc/warewulf/nodes.conf")
assert.YAMLEq(t, tt.outDB, content)
}
})
}
}

View File

@@ -9,7 +9,6 @@ import (
type variables struct {
setYes bool
setForce bool
profileConf node.Profile
profileDel node.NodeConfDel
profileAdd node.NodeConfAdd

View File

@@ -9,9 +9,6 @@ import (
func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Println("wwctl version:\t", version.GetVersion())
wwVersionResponse := version.Version()
fmt.Println("rpc version:", wwVersionResponse.String())
fmt.Println("wwctl version:\t", version.Version())
return nil
}