Skip to content

Commit

Permalink
Add --sleep option to fetch command
Browse files Browse the repository at this point in the history
Creating and deleting fast a container hangs LXD
sometimes. Adding a sleep that could be increased
on a slow system fixes the issue.
  • Loading branch information
geaaru committed Sep 9, 2024
1 parent 5161d4d commit e5d459c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"strings"
"time"

lxd_executor "github.com/MottainaiCI/lxd-compose/pkg/executor"
loader "github.com/MottainaiCI/lxd-compose/pkg/loader"
Expand Down Expand Up @@ -67,6 +68,7 @@ func newFetchCommand(config *specs.LxdComposeConfig) *cobra.Command {

prefix, _ := cmd.Flags().GetString("nodes-prefix")
testImages, _ := cmd.Flags().GetBool("test-images")
sleep, _ := cmd.Flags().GetUint("sleep")
ret := 0

composer.SetGroupsDisabled(disabledGroups)
Expand Down Expand Up @@ -151,6 +153,13 @@ func newFetchCommand(config *specs.LxdComposeConfig) *cobra.Command {
imageData[1], key, err.Error()))
}

composer.Logger.Info(fmt.Sprintf(
"[%s] Sleeping for %d seconds...",
imageData[0], sleep,
))
duration, _ := time.ParseDuration(fmt.Sprintf("%ds", sleep))
time.Sleep(duration)

err = executor.DeleteContainer("test-image")
if err != nil {
composer.Logger.Error(
Expand Down Expand Up @@ -187,6 +196,8 @@ func newFetchCommand(config *specs.LxdComposeConfig) *cobra.Command {
flags.StringSliceVar(&testProfiles, "test-profile", []string{},
"Define the list of LXD profile to use on testing container. Used with --test-images")
flags.Bool("test-images", false, "Testing fetched images.")
flags.Uint("sleep", 3,
"Number of seconds sleep before delete the testing container. Used with --test-images.")

return cmd
}

0 comments on commit e5d459c

Please sign in to comment.