Add flag --build to wwctl container copy, default false
Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
6796a69c3f
commit
1f492dfed5
@@ -18,6 +18,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
cdp := &wwapiv1.ContainerCopyParameter{
|
||||
ContainerSource: args[0],
|
||||
ContainerDestination: args[1],
|
||||
Build: Build,
|
||||
}
|
||||
|
||||
if !container.DoesSourceExist(cdp.ContainerSource) {
|
||||
@@ -42,6 +43,13 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if cdp.Build {
|
||||
err = container.Build(cdp.ContainerDestination, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Info("Container %s successfully duplicated as %s", cdp.ContainerSource, cdp.ContainerDestination)
|
||||
return
|
||||
|
||||
|
||||
33
internal/app/wwctl/container/copy/main_test.go
Normal file
33
internal/app/wwctl/container/copy/main_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package copy
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
)
|
||||
|
||||
func Test_Copy(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, path.Join(testenv.WWChrootdir, "test-container/rootfs/bin/sh"), `test`)
|
||||
defer env.RemoveAll(t)
|
||||
warewulfd.SetNoDaemon()
|
||||
|
||||
t.Run("container copy without build", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs([]string{"test-container", "test-container-copy-without-build"})
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.NoFileExists(t, path.Join(env.BaseDir, testenv.WWProvisiondir, "container", "test-container-copy-without-build.img"))
|
||||
})
|
||||
|
||||
t.Run("container copy with build", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs([]string{"-b", "test-container", "test-container-copy"})
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.FileExists(t, path.Join(env.BaseDir, testenv.WWProvisiondir, "container", "test-container-copy.img"))
|
||||
})
|
||||
}
|
||||
@@ -22,10 +22,12 @@ var (
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
Build bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Nothing to do here
|
||||
baseCmd.PersistentFlags().BoolVarP(&Build, "build", "b", false, "Build container after copy")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
Reference in New Issue
Block a user