-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow instance rename #526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,62 @@ func TestAccInstance_restartVirtualMachine(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccInstance_renameInstance(t *testing.T) { | ||
instanceNameA := acctest.GenerateName(3, "-") | ||
instanceNameB := acctest.GenerateName(3, "-") | ||
instanceNameC := acctest.GenerateName(3, "-") | ||
instanceNameD := acctest.GenerateName(3, "-") | ||
instanceNameE := acctest.GenerateName(3, "-") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
// Launch a new instance. | ||
Config: testAccInstance_rename(instanceNameA, true), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "name", instanceNameA), | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "status", "Running"), | ||
), | ||
}, | ||
{ | ||
// Stop and rename the instance. | ||
Config: testAccInstance_rename(instanceNameB, false), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "name", instanceNameB), | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "status", "Stopped"), | ||
), | ||
}, | ||
{ | ||
// Rename the instance while stopped. | ||
Config: testAccInstance_rename(instanceNameC, false), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "name", instanceNameC), | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "status", "Stopped"), | ||
), | ||
}, | ||
{ | ||
// Rename and start the instance. | ||
Config: testAccInstance_rename(instanceNameD, true), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "name", instanceNameD), | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "status", "Running"), | ||
), | ||
}, | ||
{ | ||
// Ensure instance rename fails when instance is running. | ||
Config: testAccInstance_rename(instanceNameE, true), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "name", instanceNameD), // Ensure name is unchanged. | ||
resource.TestCheckResourceAttr("lxd_instance.instance1", "status", "Running"), | ||
), | ||
ExpectError: regexp.MustCompile("Renaming of running instance not allowed"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if state is testable when error is expected, but worth trying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to be working. Thanks :) |
||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccInstance_remoteImage(t *testing.T) { | ||
instanceName := acctest.GenerateName(2, "-") | ||
|
||
|
@@ -1884,6 +1940,16 @@ resource "lxd_instance" "instance1" { | |
`, instanceName, acctest.TestImage) | ||
} | ||
|
||
func testAccInstance_rename(name string, running bool) string { | ||
return fmt.Sprintf(` | ||
resource "lxd_instance" "instance1" { | ||
name = "%s" | ||
running = %v | ||
image = "%s" | ||
} | ||
`, name, running, acctest.TestImage) | ||
} | ||
|
||
func testAccInstance_remoteImage(name string) string { | ||
return fmt.Sprintf(` | ||
resource "lxd_instance" "instance1" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided name could be a bit more indicative of the intention. Say the instance started with
A
, then move toA2B
->B2C
->C2D
-(fail)->D2E
.Just an idea as I think what you have is fine, it just required a bit more mental tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, will fix :)