Merge branch 'main' into distro-ipxe
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package imprt
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
@@ -19,6 +22,11 @@ Imported containers are used to create bootable VNFS images.`,
|
||||
Example: "wwctl container import docker://ghcr.io/hpcng/warewulf-rockylinux:8 rockylinux-8",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if SetForce && SetUpdate {
|
||||
wwlog.Warn("Both --force and --update flags are set, will ignore --update flag")
|
||||
}
|
||||
},
|
||||
}
|
||||
SetForce bool
|
||||
SetUpdate bool
|
||||
|
||||
@@ -175,21 +175,23 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
|
||||
containerName = cip.Name
|
||||
fullPath := container.SourceDir(cip.Name)
|
||||
|
||||
// container already exists and should be removed first
|
||||
if util.IsDir(fullPath) && cip.Force {
|
||||
wwlog.Info("Overwriting existing VNFS")
|
||||
err = os.RemoveAll(fullPath)
|
||||
if err != nil {
|
||||
wwlog.ErrorExc(err, "")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if util.IsDir(fullPath) {
|
||||
if cip.Force {
|
||||
wwlog.Info("Overwriting existing VNFS")
|
||||
err = os.RemoveAll(fullPath)
|
||||
if err != nil {
|
||||
wwlog.ErrorExc(err, "")
|
||||
return
|
||||
}
|
||||
} else if cip.Update {
|
||||
wwlog.Info("Updating existing VNFS")
|
||||
} else {
|
||||
if !cip.Update {
|
||||
err = fmt.Errorf("VNFS Name exists, specify --force, --update, or choose a different name: %s", cip.Name)
|
||||
wwlog.Error(err.Error())
|
||||
return
|
||||
}
|
||||
wwlog.Info("Updating existing VNFS")
|
||||
} else if strings.HasPrefix(cip.Source, "docker://") || strings.HasPrefix(cip.Source, "docker-daemon://") ||
|
||||
strings.HasPrefix(cip.Source, "file://") || util.IsFile(cip.Source) {
|
||||
var sCtx *types.SystemContext
|
||||
@@ -238,12 +240,14 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Info("Building container: %s", cip.Name)
|
||||
err = container.Build(cip.Name, true)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not build container %s: %s", cip.Name, err.Error())
|
||||
wwlog.Error(err.Error())
|
||||
return
|
||||
if cip.Build {
|
||||
wwlog.Info("Building container: %s", cip.Name)
|
||||
err = container.Build(cip.Name, true)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not build container %s: %s", cip.Name, err.Error())
|
||||
wwlog.Error(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if cip.Default {
|
||||
|
||||
@@ -113,8 +113,8 @@ func (db syncDB) checkConflicts() error {
|
||||
for nameInHost, hostIds := range db {
|
||||
if hostIds.HostID == containerIds.ContainerID {
|
||||
errorMsg := fmt.Sprintf("id(%v) collision: host(%s) container(%s)", containerIds.ContainerID, nameInHost, nameInContainer)
|
||||
wwlog.Error(errorMsg)
|
||||
wwlog.Error("add %s to host to resolve conflict", nameInContainer)
|
||||
wwlog.Warn(errorMsg)
|
||||
wwlog.Warn("add %s to host to resolve conflict", nameInContainer)
|
||||
return errors.New(errorMsg)
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,10 @@ func (db syncDB) read(fileName string, fromContainer bool) error {
|
||||
for fileScanner.Scan() {
|
||||
line := fileScanner.Text()
|
||||
fields := strings.Split(line, ":")
|
||||
|
||||
if len(fields) != 7 {
|
||||
wwlog.Debug("malformed line in passwd: %s", line)
|
||||
continue
|
||||
}
|
||||
name := fields[0]
|
||||
if name == "" {
|
||||
continue
|
||||
|
||||
@@ -258,3 +258,13 @@ func Test_differ(t *testing.T) {
|
||||
assert.False(t, entry.match())
|
||||
assert.True(t, entry.differ())
|
||||
}
|
||||
|
||||
func Test_malformed_passwd(t *testing.T) {
|
||||
hostInput := `"testuser1:x:1001:1001::/home/testuser:/bin/bash"
|
||||
asdf`
|
||||
hostFileName := writeTempFile(t, hostInput)
|
||||
defer os.Remove(hostFileName)
|
||||
db := make(syncDB)
|
||||
err := db.readFromHost(hostFileName)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ defaultnode:
|
||||
netmask: 255.255.255.0
|
||||
onboot: true`
|
||||
|
||||
func init() {
|
||||
/*
|
||||
Creates a new nodeDb object from the on-disk configuration
|
||||
*/
|
||||
func New() (NodeYaml, error) {
|
||||
conf := warewulfconf.Get()
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf")
|
||||
@@ -48,12 +51,6 @@ func init() {
|
||||
if DefaultConfig == "" {
|
||||
DefaultConfig = path.Join(conf.Paths.Datadir, "warewulf/defaults.conf")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a new nodeDb object from the on-disk configuration
|
||||
*/
|
||||
func New() (NodeYaml, error) {
|
||||
wwlog.Verbose("Opening node configuration file: %s", ConfigFile)
|
||||
data, err := os.ReadFile(ConfigFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -177,7 +177,7 @@ func IsFile(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if stat, err := os.Stat(path); err == nil && !stat.IsDir() {
|
||||
if stat, err := os.Lstat(path); err == nil && !stat.IsDir() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user