Merge branch 'development' into genconf

This commit is contained in:
Christian Goll
2023-03-22 12:06:58 +01:00
committed by GitHub
32 changed files with 147 additions and 305 deletions

View File

@@ -15,7 +15,7 @@ curl --cacert /usr/local/etc/warewulf/keys/cacert.pem \
curl http://localhost:9871/v1/container
# container import
curl -d '{"source": "docker://warewulf/rocky:8", "name": "rocky-8", "update": true, "default": true}' -H "Content-Type: application/json" -X POST http://localhost:9871/v1/container
curl -d '{"source": "docker://ghcr.io/hpcng/warewulf-rockylinux:8", "name": "rocky-8", "update": true, "default": true}' -H "Content-Type: application/json" -X POST http://localhost:9871/v1/container
# container delete
curl -X DELETE http://localhost:9871/v1/container?containerNames=rocky-8
@@ -54,4 +54,4 @@ curl http://localhost:9871/v1/nodestatus?nodeNames=testApiNode0
# node delete single node
curl -X DELETE http://localhost:9871/v1/node?nodeNames=testApiNode0
curl -X DELETE http://localhost:9871/v1/node?nodeNames=testApiNode1
curl -X DELETE http://localhost:9871/v1/node?nodeNames=testApiNode1

View File

@@ -16,7 +16,7 @@ are:
* /path/to/archive/tar/ball
* /path/to/chroot/
Imported containers are used to create bootable VNFS images.`,
Example: "wwctl container import docker://warewulf/centos-8 my_container",
Example: "wwctl container import docker://ghcr.io/hpcng/warewulf-rockylinux:8 rockylinux-8",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"
@@ -18,7 +19,6 @@ import (
)
func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) {
if cbp == nil {
return fmt.Errorf("ContainerBuildParameter is nil")
}
@@ -60,7 +60,7 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) {
return
}
//TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
// TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
profiles, _ := nodeDB.FindAllProfiles()
for _, profile := range profiles {
wwlog.Debug("Looking for profile default: %s", profile.Id.Get())
@@ -85,7 +85,6 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) {
}
func ContainerDelete(cdp *wwapiv1.ContainerDeleteParameter) (err error) {
if cdp == nil {
return fmt.Errorf("ContainerDeleteParameter is nil")
}
@@ -132,7 +131,6 @@ ARG_LOOP:
}
func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName string, err error) {
if cip == nil {
err = fmt.Errorf("NodeAddParameter is nil")
return
@@ -176,6 +174,14 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
// TODO: mhink - return was missing here. Was that deliberate?
}
if util.IsFile(cip.Source) && !filepath.IsAbs(cip.Source) {
cip.Source, err = filepath.Abs(cip.Source)
if err != nil {
err = fmt.Errorf("when resolving absolute path of %s, err: %v", cip.Source, err)
wwlog.Error(err.Error())
return
}
}
err = container.ImportDocker(cip.Source, cip.Name, sCtx)
if err != nil {
err = fmt.Errorf("could not import image: %s", err.Error())
@@ -221,7 +227,7 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
return
}
//TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
// TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
profiles, _ := nodeDB.FindAllProfiles()
for _, profile := range profiles {
wwlog.Debug("Looking for profile default: %s", profile.Id.Get())
@@ -332,7 +338,6 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) {
}
func ContainerShow(csp *wwapiv1.ContainerShowParameter) (response *wwapiv1.ContainerShowResponse, err error) {
containerName := csp.ContainerName
if !container.ValidName(containerName) {

View File

@@ -15,7 +15,6 @@ import (
// NodeSet is the wwapiv1 implmentation for updating nodeinfo fields.
func ProfileSet(set *wwapiv1.NodeSetParameter) (err error) {
if set == nil {
return fmt.Errorf("NodeAddParameter is nil")
}
@@ -85,6 +84,10 @@ func ProfileSetParameterCheck(set *wwapiv1.NodeSetParameter, console bool) (node
for _, p := range profiles {
if util.InSlice(set.NodeNames, p.Id.Get()) {
wwlog.Verbose("Evaluating profile: %s", p.Id.Get())
// Fix issue: https://github.com/hpcng/warewulf/issues/661
if p.Id.Get() == "default" && len(p.NetDevs) == 0 {
set.NetdevDelete = p.Id.Get()
}
p.SetFrom(&pConf)
if set.NetdevDelete != "" {
if _, ok := p.NetDevs[set.NetdevDelete]; !ok {

View File

@@ -17,13 +17,6 @@ func New(active int) *BatchPool {
return pool
}
func Min(x, y int) int {
if x < y {
return x
}
return y
}
func (pool *BatchPool) Submit(f func()) {
pool.jobs = append(pool.jobs, f)
}

View File

@@ -0,0 +1,34 @@
package batch
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
/* Submits 10 jobs into a pool that supports 2 simultaneous jobs, and
tests that only two of the jobs ran at a time by capturing the time
that they ran and comparing against the start time. */
func TestBatchPool (t *testing.T) {
pool := New(2)
var times []time.Time
for i := 0; i <= 10; i++ {
pool.Submit(func() {
times = append(times, time.Now())
time.Sleep(1 * time.Second)
})
}
startTime := time.Now()
pool.Run()
assert.Equal(t, 0 * time.Second, times[0].Sub(startTime).Round(time.Second))
assert.Equal(t, 0 * time.Second, times[1].Sub(startTime).Round(time.Second))
assert.Equal(t, 1 * time.Second, times[2].Sub(startTime).Round(time.Second))
assert.Equal(t, 1 * time.Second, times[3].Sub(startTime).Round(time.Second))
assert.Equal(t, 2 * time.Second, times[4].Sub(startTime).Round(time.Second))
assert.Equal(t, 2 * time.Second, times[5].Sub(startTime).Round(time.Second))
assert.Equal(t, 3 * time.Second, times[6].Sub(startTime).Round(time.Second))
assert.Equal(t, 3 * time.Second, times[7].Sub(startTime).Round(time.Second))
assert.Equal(t, 4 * time.Second, times[8].Sub(startTime).Round(time.Second))
assert.Equal(t, 4 * time.Second, times[9].Sub(startTime).Round(time.Second))
}