|
7 | 7 | "net/http" |
8 | 8 | "os" |
9 | 9 | "path/filepath" |
| 10 | + "regexp" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
@@ -1854,6 +1855,68 @@ func TestAccMemberResource_NodeInfo(t *testing.T) { |
1854 | 1855 | }, |
1855 | 1856 | } |
1856 | 1857 |
|
| 1858 | + nodeInfoSingleNode := []map[string]any{ |
| 1859 | + { |
| 1860 | + "lan_ha_port_setting": map[string]any{ |
| 1861 | + "ha_cloud_attribute": "UNK", |
| 1862 | + "ha_ip_address": "172.28.38.12", |
| 1863 | + "ha_port_setting": map[string]any{ |
| 1864 | + "auto_port_setting_enabled": true, |
| 1865 | + "speed": "10", |
| 1866 | + }, |
| 1867 | + "lan_port_setting": map[string]any{ |
| 1868 | + "auto_port_setting_enabled": true, |
| 1869 | + }, |
| 1870 | + "mgmt_lan": "172.28.38.33", |
| 1871 | + }, |
| 1872 | + }, |
| 1873 | + } |
| 1874 | + |
| 1875 | + nodeInfoThreeNodes := []map[string]any{ |
| 1876 | + { |
| 1877 | + "lan_ha_port_setting": map[string]any{ |
| 1878 | + "ha_cloud_attribute": "UNK", |
| 1879 | + "ha_ip_address": "172.28.38.12", |
| 1880 | + "ha_port_setting": map[string]any{ |
| 1881 | + "auto_port_setting_enabled": true, |
| 1882 | + "speed": "10", |
| 1883 | + }, |
| 1884 | + "lan_port_setting": map[string]any{ |
| 1885 | + "auto_port_setting_enabled": true, |
| 1886 | + }, |
| 1887 | + "mgmt_lan": "172.28.38.33", |
| 1888 | + }, |
| 1889 | + }, |
| 1890 | + { |
| 1891 | + "lan_ha_port_setting": map[string]any{ |
| 1892 | + "ha_cloud_attribute": "UNK", |
| 1893 | + "ha_ip_address": "172.28.38.42", |
| 1894 | + "ha_port_setting": map[string]any{ |
| 1895 | + "auto_port_setting_enabled": true, |
| 1896 | + "speed": "10", |
| 1897 | + }, |
| 1898 | + "lan_port_setting": map[string]any{ |
| 1899 | + "auto_port_setting_enabled": true, |
| 1900 | + }, |
| 1901 | + "mgmt_lan": "172.28.38.44", |
| 1902 | + }, |
| 1903 | + }, |
| 1904 | + { |
| 1905 | + "lan_ha_port_setting": map[string]any{ |
| 1906 | + "ha_cloud_attribute": "UNK", |
| 1907 | + "ha_ip_address": "172.28.38.52", |
| 1908 | + "ha_port_setting": map[string]any{ |
| 1909 | + "auto_port_setting_enabled": true, |
| 1910 | + "speed": "10", |
| 1911 | + }, |
| 1912 | + "lan_port_setting": map[string]any{ |
| 1913 | + "auto_port_setting_enabled": true, |
| 1914 | + }, |
| 1915 | + "mgmt_lan": "172.28.38.55", |
| 1916 | + }, |
| 1917 | + }, |
| 1918 | + } |
| 1919 | + |
1857 | 1920 | nodeInfoMGMTIPv4 := []map[string]any{ |
1858 | 1921 | { |
1859 | 1922 | "mgmt_network_setting": map[string]any{ |
@@ -1937,6 +2000,29 @@ func TestAccMemberResource_NodeInfo(t *testing.T) { |
1937 | 2000 | ), |
1938 | 2001 | }, |
1939 | 2002 | // Update and Read |
| 2003 | + { |
| 2004 | + Config: testAccMemberNodeInfo(hostName, "IPV4", "VNIOS", "ALL_V4", |
| 2005 | + vipAddress, "172.28.38.1", "255.255.254.0", "false", 113, nodeInfoValUpdated, mgmtPortSettingVal), |
| 2006 | + ExpectError: regexp.MustCompile("enable_ha must be true when node_info has 2 nodes"), |
| 2007 | + }, |
| 2008 | + // Condition 2: enable_ha true requires exactly 2 nodes (not more) |
| 2009 | + { |
| 2010 | + Config: testAccMemberNodeInfo(hostName, "IPV4", "VNIOS", "ALL_V4", |
| 2011 | + vipAddress, "172.28.38.1", "255.255.254.0", "true", 113, nodeInfoThreeNodes, mgmtPortSettingVal), |
| 2012 | + ExpectError: regexp.MustCompile("node_info must have exactly 2 nodes when enable_ha is true"), |
| 2013 | + }, |
| 2014 | + // Condition 3a: node_info > 2 with enable_ha false is not allowed |
| 2015 | + { |
| 2016 | + Config: testAccMemberNodeInfo(hostName, "IPV4", "VNIOS", "ALL_V4", |
| 2017 | + vipAddress, "172.28.38.1", "255.255.254.0", "false", 0, nodeInfoThreeNodes, mgmtPortSettingVal), |
| 2018 | + ExpectError: regexp.MustCompile("node_info cannot have more than 2 nodes when enable_ha is false"), |
| 2019 | + }, |
| 2020 | + //Condition 3b: single node with enable_ha true is not allowed |
| 2021 | + { |
| 2022 | + Config: testAccMemberNodeInfo(hostName, "IPV4", "VNIOS", "ALL_V4", |
| 2023 | + vipAddress, "172.28.38.1", "255.255.254.0", "true", 113, nodeInfoSingleNode, mgmtPortSettingVal), |
| 2024 | + ExpectError: regexp.MustCompile(`node_info must have exactly 2 nodes when enable_ha is true; a single\s+node_info entry is not valid`), |
| 2025 | + }, |
1940 | 2026 | { |
1941 | 2027 | Config: testAccMemberNodeInfo(hostName, "IPV4", "VNIOS", "ALL_V4", |
1942 | 2028 | vipAddress, "172.28.38.1", "255.255.254.0", "true", 113, nodeInfoValUpdated, mgmtPortSettingVal), |
|
0 commit comments