Skip to content

Commit

Permalink
Merge pull request #1305 in CLOUD/terraform-provider-yandex-mirror fr…
Browse files Browse the repository at this point in the history
…om test/opensearch to master

Squashed commit of the following:

commit dd4c471451d640e2e4db04d1fb72f621df77d3d1
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Mon Jul 15 10:48:33 2024 +0200

    fix(opensearch): drop maps.Keys call because indeterminate order

commit 86b421323302a48fd7abb6f9c61d0b113b86281d
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Mon Jul 15 08:07:21 2024 +0200

    chore(opensearch): add changelog

commit 9f17132fba20733cee01d468c7f8a9fcb377b3be
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Sat Jul 13 12:48:23 2024 +0200

    test(opensearch): add sleeps before import call

commit a8055be533d8843e25f80243c1da34b80a72b5f1
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Fri Jul 12 21:01:14 2024 +0200

    test(opensearch): move case with network change

    It cause a problems because of remove zone when cluster have a data-node in each zone lead to an error because opensearch can't move shards from zone because of awarness settings
  • Loading branch information
Aleksandr Tuliakov committed Jul 15, 2024
1 parent ca4fda3 commit eb2306b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/BUG FIXES-20240715-080653.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: BUG FIXES
body: 'opensearch: fix remove/add network acceptance test'
time: 2024-07-15T08:06:53.43424+02:00
14 changes: 11 additions & 3 deletions yandex-framework/services/mdb/opensearch/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/opensearch/v1"
"github.com/yandex-cloud/terraform-provider-yandex/yandex-framework/timestamp"
"golang.org/x/exp/maps"
)

var defaultOpts = basetypes.ObjectAsOptions{UnhandledNullAsEmpty: false, UnhandledUnknownAsEmpty: false}
Expand Down Expand Up @@ -334,7 +333,7 @@ func dashboardSubConfigToObject(ctx context.Context, cfg *opensearch.Dashboards,
func openSearchNodeGroupsToList(ctx context.Context, nodeGroups []*opensearch.OpenSearch_NodeGroup, state []OpenSearchNode) (types.List, diag.Diagnostics) {
groupsByName := GetGroupByName(nodeGroups)
var ret = make([]OpenSearchNode, 0, len(nodeGroups))
nodeGroupNames := maps.Keys(groupsByName)
nodeGroupNames := getGroupNames(nodeGroups)
stateGroupsByName := make(map[string]OpenSearchNode, len(state))

if len(state) != 0 && len(state) == len(nodeGroups) {
Expand Down Expand Up @@ -440,7 +439,7 @@ func sameNodeGroup(ctx context.Context, res *opensearch.OpenSearch_NodeGroup, st
func dashboardsNodeGroupsToList(ctx context.Context, nodeGroups []*opensearch.Dashboards_NodeGroup, state []DashboardNode) (types.List, diag.Diagnostics) {
groupsByName := GetGroupByName(nodeGroups)
var ret = make([]DashboardNode, 0, len(nodeGroups))
nodeGroupNames := maps.Keys(groupsByName)
nodeGroupNames := getGroupNames(nodeGroups)
if len(state) != 0 {
nodeGroupNames = make([]string, 0, len(state))
for _, s := range state {
Expand Down Expand Up @@ -665,3 +664,12 @@ func GetGroupByName[T withName](groups []T) map[string]T {

return groupsByName
}

func getGroupNames[T withName](groups []T) []string {
names := make([]string, len(groups))
for i, g := range groups {
names[i] = g.GetName()
}

return names
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ func TestAccMDBOpenSearchCluster_basic(t *testing.T) {
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
//Networks remove
{
Config: testAccMDBOpenSearchClusterConfigNetworksRemove(openSearchName, openSearchDesc2, randInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckMDBOpenSearchClusterExists(openSearchResource, &r, 2),
testAccCheckMDBOpenSearchSubnetsAndZonesCount(&r, 2),
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
//Networks restore
{
Config: testAccMDBOpenSearchClusterConfigNetworksRestore(openSearchName, openSearchDesc2, "PRESTABLE", randInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckMDBOpenSearchClusterExists(openSearchResource, &r, 2),
testAccCheckMDBOpenSearchSubnetsAndZonesCount(&r, 3),
func(s *terraform.State) error {
time.Sleep(1 * time.Minute)
return nil
},
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
//Update OpenSearch Cluster
{
Config: testAccMDBOpenSearchClusterConfigUpdated(openSearchName, openSearchDesc2, randInt),
Expand All @@ -276,26 +298,8 @@ func TestAccMDBOpenSearchCluster_basic(t *testing.T) {
testAccCheckMDBOpenSearchClusterDashboardsHasResources(&r, "s2.small", "network-ssd", 11*1024*1024*1024),
testAccCheckMDBOpenSearchClusterHasPlugins(&r, "repository-s3"),
resource.TestCheckResourceAttr(openSearchResource, "maintenance_window.type", "ANYTIME"),
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
//Networks remove
{
Config: testAccMDBOpenSearchClusterConfigNetworksRemove(openSearchName, openSearchDesc2, randInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckMDBOpenSearchClusterExists(openSearchResource, &r, 5),
testAccCheckMDBOpenSearchSubnetsAndZonesCount(&r, 2),
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
//Networks restore
{
Config: testAccMDBOpenSearchClusterConfigNetworksRestore(openSearchName, openSearchDesc2, randInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckMDBOpenSearchClusterExists(openSearchResource, &r, 5),
testAccCheckMDBOpenSearchSubnetsAndZonesCount(&r, 3),
func(s *terraform.State) error {
time.Sleep(5 * time.Minute)
time.Sleep(1 * time.Minute)
return nil
},
),
Expand All @@ -308,6 +312,10 @@ func TestAccMDBOpenSearchCluster_basic(t *testing.T) {
testAccCheckMDBOpenSearchClusterExists(openSearchResource, &r, 12),
resource.TestCheckResourceAttr(openSearchResource, "hosts.#", "12"),
test.AccCheckCreatedAtAttr(openSearchResource),
func(s *terraform.State) error {
time.Sleep(1 * time.Minute)
return nil
},
),
},
mdbOpenSearchClusterImportStep(openSearchResource),
Expand All @@ -327,6 +335,10 @@ func TestAccMDBOpenSearchCluster_basic(t *testing.T) {
}
return nil
},
func(s *terraform.State) error {
time.Sleep(1 * time.Minute)
return nil
},
test.AccCheckCreatedAtAttr(openSearchResource),
),
},
Expand Down Expand Up @@ -746,45 +758,47 @@ resource "yandex_mdb_opensearch_cluster" "foo" {
}
environment = "PRESTABLE"
network_id = "${yandex_vpc_network.mdb-opensearch-test-net.id}"
security_group_ids = [yandex_vpc_security_group.mdb-opensearch-test-sg-x.id, yandex_vpc_security_group.mdb-opensearch-test-sg-y.id]
security_group_ids = [yandex_vpc_security_group.mdb-opensearch-test-sg-x.id]
service_account_id = "${yandex_iam_service_account.sa.id}"
deletion_protection = false
config {
admin_password = "password_updated"
admin_password = "password"
opensearch {
node_groups {
name = "datamaster0"
assign_public_ip = false
hosts_count = 3
hosts_count = 1
zone_ids = local.zones
subnet_ids = [
"${yandex_vpc_subnet.mdb-opensearch-test-subnet-a.id}",
"${yandex_vpc_subnet.mdb-opensearch-test-subnet-b.id}",
]
roles = ["DATA", "MANAGER"]
resources {
resource_preset_id = "s2.small"
disk_size = 11811160064
disk_type_id = "network-ssd"
resource_preset_id = "s2.micro"
disk_size = 10737418240
disk_type_id = "network-ssd"
}
}
plugins = ["repository-s3"]
plugins = ["analysis-icu", "repository-s3"]
}
dashboards {
node_groups {
name = "dash0"
assign_public_ip = false
hosts_count = 2
hosts_count = 1
zone_ids = local.zones
subnet_ids = [
"${yandex_vpc_subnet.mdb-opensearch-test-subnet-a.id}",
"${yandex_vpc_subnet.mdb-opensearch-test-subnet-b.id}",
]
resources {
resource_preset_id = "s2.small"
disk_size = 11811160064
resource_preset_id = "s2.micro"
disk_size = 10737418240
disk_type_id = "network-ssd"
}
}
Expand All @@ -811,8 +825,8 @@ resource "yandex_mdb_opensearch_cluster" "foo" {
`, name, desc)
}

func testAccMDBOpenSearchClusterConfigNetworksRestore(name, desc string, randInt int) string {
return testAccMDBOpenSearchClusterConfigUpdated(name, desc, randInt)
func testAccMDBOpenSearchClusterConfigNetworksRestore(name, desc, environment string, randInt int) string {
return testAccMDBOpenSearchClusterConfig(name, desc, environment, false, randInt)
}

func testAccMDBOpenSearchClusterConfigUpdated(name, desc string, randInt int) string {
Expand Down

0 comments on commit eb2306b

Please sign in to comment.