forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AliyunContainerService#1078 from Letty5411/0409
test: refine daemon framework
- Loading branch information
Showing
3 changed files
with
115 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/alibaba/pouch/test/command" | ||
"github.com/alibaba/pouch/test/daemon" | ||
|
||
"github.com/gotestyourself/gotestyourself/icmd" | ||
) | ||
|
||
// StartDefaultDaemonDebug starts a deamon with default configuration and debug on. | ||
func StartDefaultDaemonDebug(args ...string) (*daemon.Config, error) { | ||
cfg := daemon.NewConfig() | ||
cfg.Debug = true | ||
|
||
cfg.NewArgs(args...) | ||
|
||
return &cfg, cfg.StartDaemon() | ||
} | ||
|
||
// StartDefaultDaemon starts a deamon with all default configuration and debug off. | ||
func StartDefaultDaemon(args ...string) (*daemon.Config, error) { | ||
cfg := daemon.NewConfig() | ||
cfg.Debug = false | ||
|
||
cfg.NewArgs(args...) | ||
|
||
return &cfg, cfg.StartDaemon() | ||
} | ||
|
||
// StartDaemonBareWithArgs starts a deamon with all user specified parameter. | ||
func StartDaemonBareWithArgs(cfg *daemon.Config, args ...string) error { | ||
cfg.NewArgs(args...) | ||
|
||
return cfg.StartDaemon() | ||
} | ||
|
||
// RestartDaemon restart daemon | ||
func RestartDaemon(cfg *daemon.Config) error { | ||
cfg.KillDaemon() | ||
return cfg.StartDaemon() | ||
} | ||
|
||
// RunWithSpecifiedDaemon run pouch command with --host parameter | ||
func RunWithSpecifiedDaemon(d *daemon.Config, cmd ...string) *icmd.Result { | ||
var sock string | ||
|
||
// Find the first -l or --listen parameter and use it. | ||
for _, v := range d.Args { | ||
if strings.Contains(v, "-l") || strings.Contains(v, "--listen") { | ||
if strings.Contains(v, "=") { | ||
sock = strings.Split(v, "=")[1] | ||
} else { | ||
sock = strings.Fields(v)[1] | ||
} | ||
break | ||
} | ||
} | ||
args := append(append([]string{"--host"}, sock), cmd...) | ||
return command.PouchRun(args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters