This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
51 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
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/taskcluster/taskcluster-base-go/scopes" | ||
) | ||
|
||
// one instance overall - represents feature | ||
type OSGroupsFeature struct { | ||
} | ||
|
||
// one instance per task | ||
type OSGroups struct { | ||
Task *TaskRun | ||
// keep track of which groups we successfully update | ||
AddedGroups []string | ||
} | ||
|
||
func (feature *OSGroupsFeature) Name() string { | ||
return "OS Groups" | ||
} | ||
|
||
func (feature *OSGroupsFeature) Initialise() error { | ||
return nil | ||
} | ||
|
||
func (feature *OSGroupsFeature) PersistState() error { | ||
return nil | ||
} | ||
|
||
func (feature *OSGroupsFeature) IsEnabled(task *TaskRun) bool { | ||
// always enabled, since scopes protect usage at a group level | ||
return true | ||
} | ||
|
||
func (feature *OSGroupsFeature) NewTaskFeature(task *TaskRun) TaskFeature { | ||
osGroups := &OSGroups{ | ||
Task: task, | ||
} | ||
return osGroups | ||
} | ||
|
||
func (osGroups *OSGroups) ReservedArtifacts() []string { | ||
return []string{} | ||
} | ||
|
||
func (osGroups *OSGroups) RequiredScopes() scopes.Required { | ||
requiredScopes := make([]string, len(osGroups.Task.Payload.OSGroups), len(osGroups.Task.Payload.OSGroups)) | ||
for i, osGroup := range osGroups.Task.Payload.OSGroups { | ||
requiredScopes[i] = "generic-worker:os-group:" + config.ProvisionerID + "/" + config.WorkerType + "/" + osGroup | ||
} | ||
return scopes.Required{requiredScopes} | ||
} |
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,18 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
func (osGroups *OSGroups) Start() *CommandExecutionError { | ||
if len(osGroups.Task.Payload.OSGroups) > 0 { | ||
return MalformedPayloadError(fmt.Errorf("osGroups feature is not supported on platform %v - please modify task definition and try again", runtime.GOOS)) | ||
} | ||
return nil | ||
} | ||
|
||
func (osGroups *OSGroups) Stop(err *ExecutionErrors) { | ||
} |
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestEmptyOSGroups(t *testing.T) { | ||
defer setup(t)() | ||
payload := GenericWorkerPayload{ | ||
Command: helloGoodbye(), | ||
MaxRunTime: 30, | ||
OSGroups: []string{}, | ||
} | ||
td := testTask(t) | ||
|
||
_ = submitAndAssert(t, td, payload, "completed", "completed") | ||
} | ||
|
||
func TestNonEmptyOSGroups(t *testing.T) { | ||
defer setup(t)() | ||
payload := GenericWorkerPayload{ | ||
Command: helloGoodbye(), | ||
MaxRunTime: 30, | ||
OSGroups: []string{"abc"}, | ||
} | ||
td := testTask(t) | ||
|
||
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload") | ||
|
||
// check log mentions issue | ||
bytes, err := ioutil.ReadFile(filepath.Join(taskContext.TaskDir, logPath)) | ||
if err != nil { | ||
t.Fatalf("Error when trying to read log file: %v", err) | ||
} | ||
logtext := string(bytes) | ||
if !strings.Contains(logtext, "- osGroups: Array must have at most 0 items") { | ||
t.Fatalf("Was expecting log file to contain '- osGroups: Array must have at most 0 items' but it doesn't") | ||
} | ||
} |
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
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