|
| 1 | +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// https://www.mozilla.org/MPL/2.0/ |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | +// SPDX-License-Identifier: MPL-2.0 |
| 17 | + |
| 18 | +package provider |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 25 | +) |
| 26 | + |
| 27 | +func TestAccIosxePolicyMapPoliceCirExceedTransmit(t *testing.T) { |
| 28 | + resourceTransmitChecks := []resource.TestCheckFunc{ |
| 29 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "name", "TFACC_COPP_POLICE_TRANSMIT"), |
| 30 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.name", "TFACC_COPP_ICMP"), |
| 31 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.actions.0.type", "police"), |
| 32 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.actions.0.police_cir", "256000"), |
| 33 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.actions.0.police_bc", "8000"), |
| 34 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.actions.0.police_cir_conform_transmit", "true"), |
| 35 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.0.actions.0.police_cir_exceed_drop", "true"), |
| 36 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.name", "class-default"), |
| 37 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.type", "police"), |
| 38 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir", "10000000"), |
| 39 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.police_bc", "312500"), |
| 40 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_conform_transmit", "true"), |
| 41 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_exceed_transmit", "true"), |
| 42 | + } |
| 43 | + transmitChecks := append([]resource.TestCheckFunc{}, resourceTransmitChecks...) |
| 44 | + transmitChecks = append(transmitChecks, resource.TestCheckResourceAttr("data.iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_exceed_transmit", "true")) |
| 45 | + dropChecks := []resource.TestCheckFunc{ |
| 46 | + resource.TestCheckResourceAttr("iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_exceed_drop", "true"), |
| 47 | + resource.TestCheckResourceAttr("data.iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_exceed_drop", "true"), |
| 48 | + resource.TestCheckResourceAttr("data.iosxe_policy_map.police_cir", "classes.1.actions.0.police_cir_exceed_transmit", "false"), |
| 49 | + } |
| 50 | + |
| 51 | + resource.Test(t, resource.TestCase{ |
| 52 | + PreCheck: func() { testAccPreCheck(t) }, |
| 53 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 54 | + Steps: []resource.TestStep{ |
| 55 | + { |
| 56 | + Config: testAccIosxePolicyMapPoliceCirExceedTransmitConfig(true), |
| 57 | + Check: resource.ComposeTestCheckFunc(transmitChecks...), |
| 58 | + }, |
| 59 | + { |
| 60 | + Config: testAccIosxePolicyMapPoliceCirExceedTransmitConfig(false), |
| 61 | + Check: resource.ComposeTestCheckFunc(dropChecks...), |
| 62 | + }, |
| 63 | + { |
| 64 | + Config: testAccIosxePolicyMapPoliceCirExceedTransmitConfig(true), |
| 65 | + Check: resource.ComposeTestCheckFunc(transmitChecks...), |
| 66 | + }, |
| 67 | + { |
| 68 | + ResourceName: "iosxe_policy_map.police_cir", |
| 69 | + ImportState: true, |
| 70 | + ImportStateVerify: true, |
| 71 | + ImportStateId: "TFACC_COPP_POLICE_TRANSMIT", |
| 72 | + ImportStateVerifyIgnore: []string{ |
| 73 | + "subscriber", |
| 74 | + "classes.0.policy_log", |
| 75 | + "classes.0.actions.0.shape_average_ms", |
| 76 | + "classes.0.actions.0.police_cir_exceed_transmit", |
| 77 | + "classes.0.actions.0.police_target_bitrate_conform_transmit", |
| 78 | + "classes.0.actions.0.police_target_bitrate_exceed_drop", |
| 79 | + "classes.0.actions.0.police_target_bitrate_exceed_transmit", |
| 80 | + "classes.1.policy_log", |
| 81 | + "classes.1.actions.0.shape_average_ms", |
| 82 | + "classes.1.actions.0.police_cir_exceed_drop", |
| 83 | + "classes.1.actions.0.police_target_bitrate_conform_transmit", |
| 84 | + "classes.1.actions.0.police_target_bitrate_exceed_drop", |
| 85 | + "classes.1.actions.0.police_target_bitrate_exceed_transmit", |
| 86 | + }, |
| 87 | + Check: resource.ComposeTestCheckFunc(resourceTransmitChecks...), |
| 88 | + }, |
| 89 | + }, |
| 90 | + }) |
| 91 | +} |
| 92 | + |
| 93 | +func testAccIosxePolicyMapPoliceCirExceedTransmitConfig(exceedTransmit bool) string { |
| 94 | + exceedAction := "police_cir_exceed_drop = true" |
| 95 | + if exceedTransmit { |
| 96 | + exceedAction = "police_cir_exceed_transmit = true" |
| 97 | + } |
| 98 | + |
| 99 | + return fmt.Sprintf(`resource "iosxe_yang" "policy_class_map" { |
| 100 | + path = "/Cisco-IOS-XE-native:native/policy/Cisco-IOS-XE-policy:class-map[name=TFACC_COPP_ICMP]" |
| 101 | + attributes = { |
| 102 | + "name" = "TFACC_COPP_ICMP" |
| 103 | + "prematch" = "match-any" |
| 104 | + } |
| 105 | +} |
| 106 | +
|
| 107 | +resource "iosxe_policy_map" "police_cir" { |
| 108 | + name = "TFACC_COPP_POLICE_TRANSMIT" |
| 109 | + classes = [ |
| 110 | + { |
| 111 | + name = "TFACC_COPP_ICMP" |
| 112 | + actions = [ |
| 113 | + { |
| 114 | + type = "police" |
| 115 | + police_cir = 256000 |
| 116 | + police_bc = 8000 |
| 117 | + police_cir_conform_transmit = true |
| 118 | + police_cir_exceed_drop = true |
| 119 | + }, |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + name = "class-default" |
| 124 | + actions = [ |
| 125 | + { |
| 126 | + type = "police" |
| 127 | + police_cir = 10000000 |
| 128 | + police_bc = 312500 |
| 129 | + police_cir_conform_transmit = true |
| 130 | + %s |
| 131 | + }, |
| 132 | + ] |
| 133 | + }, |
| 134 | + ] |
| 135 | + depends_on = [iosxe_yang.policy_class_map] |
| 136 | +} |
| 137 | +
|
| 138 | +data "iosxe_policy_map" "police_cir" { |
| 139 | + name = iosxe_policy_map.police_cir.name |
| 140 | +} |
| 141 | +`, exceedAction) |
| 142 | +} |
0 commit comments