Merge pull request #1421 from hashicorp/f-system-count-zero

Allow count 0 on system jobs
This commit is contained in:
Alex Dadgar 2016-07-13 14:39:23 -06:00 committed by GitHub
commit c28027bc9e
2 changed files with 30 additions and 3 deletions

View File

@ -1096,9 +1096,9 @@ func (j *Job) Validate() error {
taskGroups[tg.Name] = idx
}
if j.Type == "system" && tg.Count != 1 {
if j.Type == "system" && tg.Count > 1 {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("Job task group %d has count %d. Only count of 1 is supported with system scheduler",
fmt.Errorf("Job task group %d has count %d. Count cannot exceed 1 with system scheduler",
idx+1, tg.Count))
}
}
@ -1112,7 +1112,7 @@ func (j *Job) Validate() error {
}
// Validate periodic is only used with batch jobs.
if j.IsPeriodic() {
if j.IsPeriodic() && j.Periodic.Enabled {
if j.Type != JobTypeBatch {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("Periodic can only be used with %q scheduler", JobTypeBatch))

View File

@ -117,6 +117,7 @@ func testJob() *Job {
Name: "web",
Count: 10,
RestartPolicy: &RestartPolicy{
Mode: RestartPolicyModeFail,
Attempts: 3,
Interval: 10 * time.Minute,
Delay: 1 * time.Minute,
@ -145,6 +146,7 @@ func testJob() *Job {
Resources: &Resources{
CPU: 500,
MemoryMB: 256,
DiskMB: 20,
Networks: []*NetworkResource{
&NetworkResource{
MBits: 50,
@ -152,6 +154,10 @@ func testJob() *Job {
},
},
},
LogConfig: &LogConfig{
MaxFiles: 10,
MaxFileSizeMB: 1,
},
},
},
Meta: map[string]string{
@ -194,6 +200,27 @@ func TestJob_IsPeriodic(t *testing.T) {
}
}
func TestJob_SystemJob_Validate(t *testing.T) {
j := testJob()
j.Type = JobTypeSystem
j.InitFields()
err := j.Validate()
if err == nil || !strings.Contains(err.Error(), "exceed") {
t.Fatalf("expect error due to count")
}
j.TaskGroups[0].Count = 0
if err := j.Validate(); err != nil {
t.Fatalf("unexpected err: %v", err)
}
j.TaskGroups[0].Count = 1
if err := j.Validate(); err != nil {
t.Fatalf("unexpected err: %v", err)
}
}
func TestTaskGroup_Validate(t *testing.T) {
tg := &TaskGroup{
Count: -1,