-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add Tests for Reordering Network Interfaces #33
Open
alakae
wants to merge
1
commit into
cloudscale-ch:master
Choose a base branch
from
alakae:reorder_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,6 +325,49 @@ func TestAccCloudscaleNetwork_ServerWithPublicAndPrivateWithoutAddress(t *testin | |
}) | ||
} | ||
|
||
func TestAccCloudscaleSubnet_ServerReorderNetworks(t *testing.T) { | ||
count := 2 | ||
_ = make([]cloudscale.Network, count, count) | ||
var server cloudscale.Server | ||
|
||
rInt1 := acctest.RandInt() | ||
rInt2 := acctest.RandInt() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCloudscaleNetworkDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: twoNetworkConfig(rInt1, rInt2, 0, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleServerExists("cloudscale_server.web-worker01", &server), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.#", "2"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.network_name", fmt.Sprintf("terraform-%d-0", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.network_name", fmt.Sprintf("terraform-%d-1", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.#", "1"), | ||
), | ||
}, | ||
{ | ||
Config: twoNetworkConfig(rInt1, rInt2, 1, 0), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleServerExists("cloudscale_server.web-worker01", &server), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.#", "2"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.network_name", fmt.Sprintf("terraform-%d-1", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.network_name", fmt.Sprintf("terraform-%d-0", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.#", "1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCloudscaleNetworkSubnetCount(n string, network *cloudscale.Network, expectedCount int) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if actualSubnetCount := len(network.Subnets); actualSubnetCount != expectedCount { | ||
|
@@ -504,3 +547,32 @@ resource "cloudscale_server" "basic" { | |
}` | ||
return fmt.Sprintf(template, rInt, DefaultImageSlug) | ||
} | ||
|
||
func twoNetworkConfig(rInt1 int, rInt2 int, networkIndex1 int, networkIndex2 int) string { | ||
template := ` | ||
resource "cloudscale_network" "multi-net" { | ||
count = 2 | ||
name = "terraform-%d-${count.index}" | ||
auto_create_ipv4_subnet = true | ||
} | ||
|
||
resource "cloudscale_server" "web-worker01" { | ||
name = "terraform-%d" | ||
flavor_slug = "flex-4" | ||
image_slug = "debian-9" | ||
volume_size_gb = 50 | ||
interfaces { | ||
type = "private" | ||
network_uuid = cloudscale_network.multi-net[%d].id | ||
} | ||
interfaces { | ||
type = "private" | ||
network_uuid = cloudscale_network.multi-net[%d].id | ||
} | ||
ssh_keys = [ | ||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL2jzgla23DfRVLQr3KT20QQYovqCCN3clHrjm2ZuQFW [email protected]" | ||
] | ||
}` | ||
|
||
return fmt.Sprintf(template, rInt1, rInt2, networkIndex1, networkIndex2) | ||
} |
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 |
---|---|---|
|
@@ -193,7 +193,7 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
CheckDestroy: testAccCheckCloudscaleNetworkDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: multipleSubnetConfig(rInt1, rInt2, 0, 0), | ||
Config: networkAndSubnetWithAddressConfig(rInt1, rInt2, 0, 0), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.0", &networks[0]), | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.1", &networks[1]), | ||
|
@@ -213,7 +213,7 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
), | ||
}, | ||
{ | ||
Config: multipleSubnetConfig(rInt1, rInt2, 1, 1), | ||
Config: networkAndSubnetWithAddressConfig(rInt1, rInt2, 1, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.0", &networks[0]), | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.1", &networks[1]), | ||
|
@@ -233,7 +233,7 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
), | ||
}, | ||
{ | ||
Config: multipleSubnetConfig(rInt1, rInt2, 0, -100), | ||
Config: networkAndSubnetWithAddressConfig(rInt1, rInt2, 0, -100), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.0", &networks[0]), | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.1", &networks[1]), | ||
|
@@ -253,7 +253,7 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
), | ||
}, | ||
{ | ||
Config: multipleSubnetConfig(rInt1, rInt2, 0, 0), | ||
Config: networkAndSubnetWithAddressConfig(rInt1, rInt2, 0, 0), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.0", &networks[0]), | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.1", &networks[1]), | ||
|
@@ -273,7 +273,7 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
), | ||
}, | ||
{ | ||
Config: multipleSubnetConfig(rInt1, rInt2, -100, 1), | ||
Config: networkAndSubnetWithAddressConfig(rInt1, rInt2, -100, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.0", &networks[0]), | ||
testAccCheckCloudscaleNetworkExists("cloudscale_network.multi-net.1", &networks[1]), | ||
|
@@ -296,6 +296,58 @@ func TestAccCloudscaleSubnet_ServerAndMultipleSubnets(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccCloudscaleSubnet_ServerReorderSubnet(t *testing.T) { | ||
count := 2 | ||
_ = make([]cloudscale.Network, count, count) | ||
_ = make([]cloudscale.Subnet, count, count) | ||
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. Same here. |
||
var server cloudscale.Server | ||
|
||
rInt1 := acctest.RandInt() | ||
rInt2 := acctest.RandInt() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCloudscaleNetworkDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: twoSubnetWithAddressConfig(rInt1, rInt2, 0, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleServerExists("cloudscale_server.web-worker01", &server), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.#", "2"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.network_name", fmt.Sprintf("terraform-%d-0", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.0.address", "192.168.0.124"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.0.subnet_cidr", "192.168.0.0/24"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.network_name", fmt.Sprintf("terraform-%d-1", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.0.address", "192.168.1.124"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.0.subnet_cidr", "192.168.1.0/24"), | ||
), | ||
}, | ||
{ | ||
Config: twoSubnetWithAddressConfig(rInt1, rInt2, 1, 0), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudscaleServerExists("cloudscale_server.web-worker01", &server), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.#", "2"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.network_name", fmt.Sprintf("terraform-%d-1", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.0.address", "192.168.1.124"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.0.addresses.0.subnet_cidr", "192.168.1.0/24"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.type", "private"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.network_name", fmt.Sprintf("terraform-%d-0", rInt1)), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.#", "1"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.0.address", "192.168.0.124"), | ||
resource.TestCheckResourceAttr("cloudscale_server.web-worker01", "interfaces.1.addresses.0.subnet_cidr", "192.168.0.0/24"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCloudscaleSubnetOnNetwork(subnet *cloudscale.Subnet, network *cloudscale.Network) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
|
||
|
@@ -436,7 +488,7 @@ resource "cloudscale_server" "basic" { | |
return fmt.Sprintf(template, rInt, DefaultImageSlug, fixedAddressLine) | ||
} | ||
|
||
func multipleSubnetConfig(rInt1 int, rInt2 int, networkIndex int, subnetIndex int) string { | ||
func networkAndSubnetWithAddressConfig(rInt1 int, rInt2 int, networkIndex int, subnetIndex int) string { | ||
template := ` | ||
resource "cloudscale_network" "multi-net" { | ||
count = 2 | ||
|
@@ -483,3 +535,46 @@ resource "cloudscale_server" "web-worker01" { | |
|
||
return fmt.Sprintf(template, rInt1, rInt2, networkTemplate, addressTemplate) | ||
} | ||
|
||
func twoSubnetWithAddressConfig(rInt1 int, rInt2 int, subnetIndex1 int, subnetIndex2 int) string { | ||
template := ` | ||
resource "cloudscale_network" "multi-net" { | ||
count = 2 | ||
name = "terraform-%d-${count.index}" | ||
auto_create_ipv4_subnet = false | ||
} | ||
|
||
resource "cloudscale_subnet" "multi-subnet" { | ||
count = 2 | ||
cidr = "192.168.${count.index}.0/24" | ||
network_uuid = cloudscale_network.multi-net[count.index].id | ||
} | ||
|
||
resource "cloudscale_server" "web-worker01" { | ||
name = "terraform-%d" | ||
flavor_slug = "flex-4" | ||
image_slug = "debian-9" | ||
volume_size_gb = 50 | ||
interfaces { | ||
type = "private" | ||
%s | ||
} | ||
interfaces { | ||
type = "private" | ||
%s | ||
} | ||
ssh_keys = [ | ||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL2jzgla23DfRVLQr3KT20QQYovqCCN3clHrjm2ZuQFW [email protected]" | ||
] | ||
}` | ||
addressTemplate := ` | ||
addresses { | ||
address = "192.168.%d.124" | ||
subnet_uuid = cloudscale_subnet.multi-subnet[%d].id | ||
} | ||
` | ||
address1 := fmt.Sprintf(addressTemplate, subnetIndex1, subnetIndex1) | ||
address2 := fmt.Sprintf(addressTemplate, subnetIndex2, subnetIndex2) | ||
|
||
return fmt.Sprintf(template, rInt1, rInt2, address1, address2) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is this for?