Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Commit

Permalink
Bug 1516458 - require rootUrl in worker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Jan 2, 2019
1 parent 0ff6a4c commit 309d2f5
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion aws.go
Expand Up @@ -53,7 +53,7 @@ func queryMetaData(url string) (string, error) {
return string(content), err
}

// taken from https://github.com/taskcluster/aws-provisioner/blob/5a01a94141c38447968ec75232fd86a86cca366a/src/worker-type.js#L601-L615
// taken from https://github.com/taskcluster/aws-provisioner/blob/5a2bc7c57b20df00f9c4357e0daeb7967e6f5ee8/lib/worker-type.js#L607-L624
type UserData struct {
Data interface{} `json:"data"`
Capacity int `json:"capacity"`
Expand All @@ -67,6 +67,7 @@ type UserData struct {
LaunchSpecGenerated time.Time `json:"launchSpecGenerated"`
LastModified time.Time `json:"lastModified"`
ProvisionerBaseURL string `json:"provisionerBaseUrl"`
TaskclusterRootURL string `json:"taskclusterRootUrl"`
SecurityToken string `json:"securityToken"`
}

Expand Down Expand Up @@ -214,6 +215,7 @@ func updateConfigWithAmazonSettings(c *gwconfig.Config) error {
c.Certificate = secToken.Credentials.Certificate
c.WorkerGroup = userData.Region
c.WorkerType = userData.WorkerType
c.RootURL = userData.TaskclusterRootURL

awsMetadata := map[string]interface{}{}
for _, url := range []string{
Expand Down
1 change: 1 addition & 0 deletions aws_helper_test.go
Expand Up @@ -93,6 +93,7 @@ func (m *MockAWSProvisionedEnvironment) Setup(t *testing.T) func() {
"instanceType": "p3.teenyweeny",
"spotBid": 3.5,
"price": 3.02,
"taskclusterRootUrl": "http://localhost:13243",
"launchSpecGenerated": time.Now(),
"lastModified": time.Now().Add(time.Minute * -30),
"provisionerBaseUrl": "http://localhost:13243/provisioner",
Expand Down
2 changes: 2 additions & 0 deletions gwconfig/config.go
Expand Up @@ -43,6 +43,7 @@ type (
QueueBaseURL string `json:"queueBaseURL"`
Region string `json:"region"`
RequiredDiskSpaceMegabytes uint `json:"requiredDiskSpaceMegabytes"`
RootURL string `json:"rootURL"`
RunAfterUserCreation string `json:"runAfterUserCreation"`
RunTasksAsCurrentUser bool `json:"runTasksAsCurrentUser"`
SentryProject string `json:"sentryProject"`
Expand Down Expand Up @@ -103,6 +104,7 @@ func (c *Config) Validate() error {
{value: c.SigningKeyLocation, name: "signingKeyLocation", disallowed: ""},
{value: c.Subdomain, name: "subdomain", disallowed: ""},
{value: c.TasksDir, name: "tasksDir", disallowed: ""},
{value: c.RootURL, name: "rootURL", disallowed: ""},
{value: c.WorkerGroup, name: "workerGroup", disallowed: ""},
{value: c.WorkerID, name: "workerId", disallowed: ""},
{value: c.WorkerType, name: "workerType", disallowed: ""},
Expand Down
7 changes: 5 additions & 2 deletions helper_test.go
Expand Up @@ -129,6 +129,7 @@ func setup(t *testing.T) (teardown func()) {
PurgeCacheBaseURL: tcpurgecache.DefaultBaseURL,
QueueBaseURL: tcqueue.DefaultBaseURL,
Region: "test-worker-group",
RootURL: os.Getenv("TASKCLUSTER_ROOT_URL"),
// should be enough for tests, and travis-ci.org CI environments don't
// have a lot of free disk
RequiredDiskSpaceMegabytes: 16,
Expand Down Expand Up @@ -172,8 +173,10 @@ func setup(t *testing.T) (teardown func()) {

func NewQueue(t *testing.T) *tcqueue.Queue {
// check we have all the env vars we need to run this test
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" || os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" {
t.Skip("Skipping test since TASKCLUSTER_CLIENT_ID and/or TASKCLUSTER_ACCESS_TOKEN env vars not set")
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
}
return tcqueue.NewFromEnv()
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Expand Up @@ -170,6 +170,8 @@ and reports back results to the queue.
for serving live logs; see
https://github.com/taskcluster/livelog and
https://github.com/taskcluster/stateless-dns-server
rootURL The root URL of the Taskcluster deploment to which
clientId and accessToken grant access.
signingKeyLocation The PGP signing key for signing artifacts with.
workerId A name to uniquely identify your worker.
workerType This should match a worker_type managed by the
Expand Down Expand Up @@ -487,6 +489,7 @@ func loadConfig(filename string, queryUserData bool) (*gwconfig.Config, error) {
PurgeCacheBaseURL: tcpurgecache.DefaultBaseURL,
QueueBaseURL: tcqueue.DefaultBaseURL,
RequiredDiskSpaceMegabytes: 10240,
RootURL: "",
RunAfterUserCreation: "",
RunTasksAsCurrentUser: runtime.GOOS != "windows",
SentryProject: "",
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Expand Up @@ -92,8 +92,8 @@ func TestAbortAfterMaxRunTime(t *testing.T) {

func TestIdleWithoutCrash(t *testing.T) {
defer setup(t)()
if config.ClientID == "" || config.AccessToken == "" {
t.Skip("Skipping test since TASKCLUSTER_CLIENT_ID and/or TASKCLUSTER_ACCESS_TOKEN env vars not set")
if config.ClientID == "" || config.AccessToken == "" || config.RootURL == "" {
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
}
start := time.Now()
config.IdleTimeoutSecs = 7
Expand Down
1 change: 1 addition & 0 deletions testdata/config/bool-as-string.json
Expand Up @@ -2,6 +2,7 @@
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"workerId" : "myworkerid",
"rootURL" : "https://tc-tests.example.com",
"accessToken" : "V7w5mcc3Q3mQHp3ns0C7dA",
"workerGroup" : "abcde",
"workerType" : "some-worker-type",
Expand Down
1 change: 1 addition & 0 deletions testdata/config/invalid-ip.json
Expand Up @@ -2,6 +2,7 @@
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"workerId" : "myworkerid",
"rootURL" : "https://tc-tests.example.com",
"accessToken" : "V7w5mcc3Q3mQHp3ns0C7dA",
"workerGroup" : "abcde",
"workerType" : "some-worker-type",
Expand Down
1 change: 1 addition & 0 deletions testdata/config/invalid-json.json
@@ -1,6 +1,7 @@
{
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"rootURL" : "https://tc-tests.example.com",
"workerId" : "THERE IS A MISSING COMMA AT THE END OF THIS LINE!!!"
"accessToken" : "V0C7dA",
"workerGroup" : "abcde",
Expand Down
1 change: 1 addition & 0 deletions testdata/config/noip.json
Expand Up @@ -2,6 +2,7 @@
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"workerId" : "myworkerid",
"rootURL" : "https://tc-tests.example.com",
"accessToken" : "V7w5mcc3Q3mQHp3ns0C7dA",
"workerGroup" : "abcde",
"workerType" : "some-worker-type"
Expand Down
1 change: 1 addition & 0 deletions testdata/config/valid.json
Expand Up @@ -2,6 +2,7 @@
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"workerId" : "myworkerid",
"rootURL" : "https://tc-tests.example.com",
"accessToken" : "V7w5mcc3Q3mQHp3ns0C7dA",
"workerGroup" : "abcde",
"workerType" : "some-worker-type",
Expand Down
1 change: 1 addition & 0 deletions testdata/config/worker-type-metadata.json
Expand Up @@ -2,6 +2,7 @@
"livelogSecret" : "this-is-a-secret",
"clientId" : "test-client",
"workerId" : "myworkerid",
"rootURL" : "https://tc-tests.example.com",
"accessToken" : "V7w5mcc3Q3mQHp3ns0C7dA",
"workerGroup" : "abcde",
"workerType" : "some-worker-type",
Expand Down

0 comments on commit 309d2f5

Please sign in to comment.