Skip to content

Commit

Permalink
Fixes time out when applying updates to Triton machine metadata. (#6149)
Browse files Browse the repository at this point in the history
* Add Triton Metadata modification AccTest.

The test starts the basic machine and then adds the metadata field
user_data.
Test fails if the user_data field does not match what we expect
OR it times out.

Related to #6148

* Fix the non-convergence of Triton metadata changes

The code waiting for the entire Machine Metadata to "deep equal" the Terraform
metadata modifications. These two sets will only be the same if the user
changes all metadata fields of the resource before calling `apply`.

Closes #6148
  • Loading branch information
sodre authored and stack72 committed Apr 20, 2016
1 parent c682dec commit 33d4c44
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion builtin/providers/triton/resource_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ func resourceMachineUpdate(d *schema.ResourceData, meta interface{}) error {
err = waitFor(
func() (bool, error) {
machine, err := client.GetMachine(d.Id())
return reflect.DeepEqual(machine.Metadata, metadata), err
for k, v := range metadata {
if provider_v, ok := machine.Metadata[k]; !ok || v != provider_v {
return false, err
}
}
return true, err
},
machineStateChangeCheckInterval,
1*time.Minute,
Expand Down
42 changes: 42 additions & 0 deletions builtin/providers/triton/resource_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ func TestAccTritonMachine_firewall(t *testing.T) {
})
}

func TestAccTritonMachine_metadata(t *testing.T) {
machineName := fmt.Sprintf("acctest-%d", acctest.RandInt())
basic := fmt.Sprintf(testAccTritonMachine_basic, machineName)
add_metadata := fmt.Sprintf(testAccTritonMachine_basic, machineName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckTritonMachineDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: basic,
Check: resource.ComposeTestCheckFunc(
testCheckTritonMachineExists("triton_machine.test"),
),
},
resource.TestStep{
Config: add_metadata,
Check: resource.ComposeTestCheckFunc(
testCheckTritonMachineExists("triton_machine.test"),
resource.TestCheckResourceAttr(
"triton_machine.test", "user_data", "hello"),
),
},
},
})
}

var testAccTritonMachine_basic = `
resource "triton_machine" "test" {
name = "%s"
Expand Down Expand Up @@ -145,3 +173,17 @@ resource "triton_machine" "test" {
firewall_enabled = 1
}
`

var testAccTritonMachine_metadata_1 = `
resource "triton_machine" "test" {
name = "%s"
package = "t4-standard-128M"
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
user_data = "hello"
tags = {
test = "hello!"
}
}
`

0 comments on commit 33d4c44

Please sign in to comment.