From 817ec14513f533ae2d5776f0647965c0238e4832 Mon Sep 17 00:00:00 2001 From: Menno Hamburg Date: Tue, 13 Jun 2023 15:43:25 +0200 Subject: [PATCH] Fixed tests --- routeros/resource_routing_ospf_area.go | 18 ++-- routeros/resource_routing_ospf_area_test.go | 6 ++ routeros/resource_routing_ospf_instance.go | 28 ++++--- ...esource_routing_ospf_interface_template.go | 84 ++++++++++++------- ...ce_routing_ospf_interface_template_test.go | 10 ++- 5 files changed, 93 insertions(+), 53 deletions(-) diff --git a/routeros/resource_routing_ospf_area.go b/routeros/resource_routing_ospf_area.go index d2dbbadc..efa7a149 100644 --- a/routeros/resource_routing_ospf_area.go +++ b/routeros/resource_routing_ospf_area.go @@ -27,13 +27,15 @@ func ResourceRoutingOspfArea() *schema.Resource { KeyName: PropNameForceNewRw, KeyComment: PropCommentRw, KeyDisabled: PropDisabledRw, - "area-id": { + "area_id": { Type: schema.TypeString, + Default: "0.0.0.0", + Optional: true, Description: "OSPF area identifier.", }, - "default-cost": { + "default_cost": { Type: schema.TypeInt, - Required: false, + Optional: true, Description: "Default cost of injected LSAs into the area.", }, "instance": { @@ -41,21 +43,21 @@ func ResourceRoutingOspfArea() *schema.Resource { Required: true, Description: "Name of the OSPF instance this area belongs to.", }, - "no-summaries": { + "no_summaries": { Type: schema.TypeBool, Default: false, - Required: false, + Optional: true, Description: "If set then the area will not flood summary LSAs in the stub area.", }, - "nssa-translate": { + "nssa_translate": { Type: schema.TypeString, - Required: false, + Optional: true, Description: "The parameter indicates which ABR will be used as a translator from type7 to type5 LSA.", ValidateFunc: validation.StringInSlice([]string{"no", "yes", "candidate"}, false), }, "type": { Type: schema.TypeString, - Required: true, + Optional: true, Default: "default", Description: "The area type.", ValidateFunc: validation.StringInSlice([]string{"default", "nssa", "stub"}, true), diff --git a/routeros/resource_routing_ospf_area_test.go b/routeros/resource_routing_ospf_area_test.go index 1ec6ac5b..45405709 100644 --- a/routeros/resource_routing_ospf_area_test.go +++ b/routeros/resource_routing_ospf_area_test.go @@ -57,9 +57,15 @@ provider "routeros" { insecure = true } +resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { + name = "test_routing_ospf_instance" + disabled = false + } + resource "routeros_routing_ospf_area" "test_routing_ospf_area" { name = "test_routing_ospf_area" disabled = true + instance = routeros_routing_ospf_instance.test_routing_ospf_instance.name } ` diff --git a/routeros/resource_routing_ospf_instance.go b/routeros/resource_routing_ospf_instance.go index 63a6b0b6..ef170723 100644 --- a/routeros/resource_routing_ospf_instance.go +++ b/routeros/resource_routing_ospf_instance.go @@ -34,44 +34,45 @@ func ResourceRoutingOspfInstance() *schema.Resource { KeyName: PropNameForceNewRw, KeyComment: PropCommentRw, KeyDisabled: PropDisabledRw, - "domain-id": { + "domain_id": { Type: schema.TypeString, Optional: true, Description: "MPLS-related parameter.", }, - "domain-tag": { + "domain_tag": { Type: schema.TypeInt, Optional: true, Description: "if set, then used in route redistribution (as route-tag in all external LSAs " + "generated by this router), and in route calculation (all external LSAs having this route " + "tag are ignored). Needed for interoperability with older Cisco systems. By default not set.", }, - "in-filter": { + "in_filter": { Type: schema.TypeString, Optional: true, Description: "name of the routing filter chain used for incoming prefixes", }, - "mpls-te-address": { + "mpls_te_address": { Type: schema.TypeString, Optional: true, Description: "the area used for MPLS traffic engineering.", }, - "mpls-te-area": { + "mpls_te_area": { Type: schema.TypeString, Optional: true, Description: "the area used for MPLS traffic engineering.", }, - "originate-default": { + "originate_default": { Type: schema.TypeString, Default: "never", + Optional: true, Description: "Specifies default route (0.0.0.0/0) distribution method.", }, - "out-filter-chain": { + "out_filter_chain": { Type: schema.TypeString, Optional: true, Description: "name of the routing filter chain used for outgoing prefixes filtering.", }, - "out-filter-select": { + "out_filter_select": { Type: schema.TypeString, Optional: true, Description: "name of the routing filter select chain, used for output selection.", @@ -81,24 +82,27 @@ func ResourceRoutingOspfInstance() *schema.Resource { Optional: true, Description: "Enable redistribution of specific route types.", }, - "router-id": { - Type: schema.TypeString, - Default: "main", + "router_id": { + Type: schema.TypeString, + Default: "main", + Optional: true, Description: "OSPF Router ID. Can be set explicitly as an IP address, or as the name " + "of the router-id instance.", }, "version": { Type: schema.TypeInt, Default: 2, + Optional: true, Description: "OSPF version this instance will be running (v2 for IPv4, v3 for IPv6).", ValidateFunc: validation.IntBetween(2, 3), }, "vrf": { Type: schema.TypeString, Default: "main", + Optional: true, Description: "the VRF table this OSPF instance operates on", }, - "use-dn": { + "use_dn": { Type: schema.TypeString, Optional: true, Description: "", diff --git a/routeros/resource_routing_ospf_interface_template.go b/routeros/resource_routing_ospf_interface_template.go index 5400363c..4eb97922 100644 --- a/routeros/resource_routing_ospf_interface_template.go +++ b/routeros/resource_routing_ospf_interface_template.go @@ -35,20 +35,19 @@ import ( func ResourceRoutingOspfInterfaceTemplate() *schema.Resource { resSchema := map[string]*schema.Schema{ MetaResourcePath: PropResourcePath("/routing/ospf/interface-template"), - MetaId: PropId(Name), + MetaId: PropId(Id), KeyComment: PropCommentRw, KeyDisabled: PropDisabledRw, "interfaces": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, + Type: schema.TypeString, + Optional: true, + Default: "none", Description: "Interfaces to match.", }, "network": { Type: schema.TypeString, + Optional: true, Description: "The network prefix associated with the area.", }, "area": { @@ -58,76 +57,99 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource { }, "auth": { Type: schema.TypeString, + Optional: true, Description: "Specifies authentication method for OSPF protocol messages.", ValidateFunc: validation.StringInSlice([]string{"simple", "md5", "sha1", "sha256", "sha384", "sha512"}, true), }, - "auth-id": { + "auth_id": { Type: schema.TypeInt, + Optional: true, Description: "The key id is used to calculate message digest (used when MD5 or SHA authentication is enabled).", }, - "authentication-key": { + "authentication_key": { Type: schema.TypeString, + Optional: true, Description: "The authentication key to be used, should match on all the neighbors of the network segment.", }, "cost": { Type: schema.TypeInt, + Optional: true, Default: 1, Description: "Interface cost expressed as link state metric.", ValidateFunc: validation.IntBetween(0, 65535), }, - "dead-interval": { - Type: schema.TypeString, - Default: "00:00:40", - Description: "Specifies the interval after which a neighbor is declared dead.", - }, - "hello-interval": { - Type: schema.TypeString, - Default: "00:00:10", - Description: "The interval between HELLO packets that the router sends out this interface.", - }, - "instance-id": { + "dead_interval": { + Type: schema.TypeString, + Optional: true, + Default: "40s", + ValidateFunc: ValidationTime, + DiffSuppressFunc: TimeEquall, + Description: "Specifies the interval after which a neighbor is declared dead.", + }, + "hello_interval": { + Type: schema.TypeString, + Optional: true, + Default: "10s", + ValidateFunc: ValidationTime, + DiffSuppressFunc: TimeEquall, + Description: "The interval between HELLO packets that the router sends out this interface.", + }, + "instance_id": { Type: schema.TypeInt, + Optional: true, Description: "Interface cost expressed as link state metric.", Default: 0, ValidateFunc: validation.IntBetween(0, 255), }, "passive": { Type: schema.TypeBool, + Optional: true, Default: false, Description: "If enabled, then do not send or receive OSPF traffic on the matching interfaces", }, - "prefix-list": { + "prefix_list": { Type: schema.TypeString, + Optional: true, Description: "Name of the address list containing networks that should be advertised to the v3 interface.", }, "priority": { Type: schema.TypeInt, + Optional: true, Description: "Router's priority. Used to determine the designated router in a broadcast network.", Default: 128, ValidateFunc: validation.IntBetween(0, 255), }, - "retransmit-interval": { - Type: schema.TypeString, - Default: "00:00:05", - Description: "Time interval the lost link state advertisement will be resent.", - }, - "transmit-delay": { - Type: schema.TypeString, - Default: "00:00:01", - Description: "Link-state transmit delay is the estimated time it takes to transmit a link-state update packet on the interface.", + "retransmit_interval": { + Type: schema.TypeString, + Optional: true, + Default: "5s", + ValidateFunc: ValidationTime, + DiffSuppressFunc: TimeEquall, + Description: "Time interval the lost link state advertisement will be resent.", + }, + "transmit_delay": { + Type: schema.TypeString, + Optional: true, + Default: "1s", + ValidateFunc: ValidationTime, + DiffSuppressFunc: TimeEquall, + Description: "Link-state transmit delay is the estimated time it takes to transmit a link-state update packet on the interface.", }, "type": { Type: schema.TypeString, Description: "The OSPF network type on this interface.", + Optional: true, Default: "broadcast", ValidateFunc: validation.StringInSlice([]string{"broadcast", "nbma", "ptp", "ptmp", "ptp-unnumbered", "virtual-link"}, true), }, - "vlink-neighbor-id": { + "vlink_neighbor_id": { Type: schema.TypeString, + Optional: true, Description: "Specifies the router-id of the neighbor which should be connected over the virtual link.", }, - "vlink-transit-area": { + "vlink_transit_area": { Type: schema.TypeString, + Optional: true, Description: "A non-backbone area the two routers have in common over which the virtual link will be established.", }, } diff --git a/routeros/resource_routing_ospf_interface_template_test.go b/routeros/resource_routing_ospf_interface_template_test.go index c76c38dc..a39af541 100644 --- a/routeros/resource_routing_ospf_interface_template_test.go +++ b/routeros/resource_routing_ospf_interface_template_test.go @@ -25,7 +25,7 @@ func TestAccRoutingOspfInterfaceTemplateTest_basic(t *testing.T) { Config: testAccCheckRoutingOspfInterfaceTemplateConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckRoutingOspfInterfaceTemplateExists(testRoutingOspfInterfaceTemplate), - resource.TestCheckResourceAttr(testRoutingOspfInterfaceTemplate, "name", "test_routing_ospf_interface_template"), + resource.TestCheckResourceAttr(testRoutingOspfInterfaceTemplate, "area", "test_routing_ospf_area"), ), }, }, @@ -57,9 +57,15 @@ provider "routeros" { insecure = true } +resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { + name = "test_routing_ospf_instance" + disabled = false + } + resource "routeros_routing_ospf_area" "test_routing_ospf_area" { name = "test_routing_ospf_area" - disabled = true + disabled = false + instance = routeros_routing_ospf_instance.test_routing_ospf_instance.name } resource "routeros_routing_ospf_interface_template" "test_routing_ospf_interface_template" {