Skip to content

feat(specs): Add codegen specs and acceptance tests for virtual router static routes resources #487

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

Open
wants to merge 2 commits into
base: feat-codegen-child-resources
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/pango/errors/panos.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
)

var ObjectExists = stderr.New("object already exists")
var InvalidFilterError = stderr.New("filter is improperly formatted")
var NameNotSpecifiedError = stderr.New("name is not specified")
var NoLocationSpecifiedError = stderr.New("no location specified")
Expand Down Expand Up @@ -151,3 +152,17 @@ func (e *errorCheck) CodeError() string {
return fmt.Sprintf("(%d) Unknown failure code, operation failed", e.Code)
}
}

type InvalidXpathComponentError struct {
Message string
}

func (o InvalidXpathComponentError) Error() string {
return o.Message
}

func NewInvalidXpathComponentError(message string) *InvalidXpathComponentError {
return &InvalidXpathComponentError{
Message: message,
}
}
33 changes: 2 additions & 31 deletions assets/pango/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,6 @@ func checkVr(c *pango.Client, ctx context.Context) {
Enable: util.Bool(false),
},
},
RoutingTable: &virtual_router.RoutingTable{
// Ip: &virtual_router.RoutingTableIp{
// StaticRoutes: []virtual_router.RoutingTableIpStaticRoutes{
// {
// Name: "default",
// Destination: util.String("0.0.0.0/0"),
// Interface: util.String("ethernet1/2"),
// NextHop: &virtual_router.RoutingTableIpStaticRoutesNextHop{
// IpAddress: util.String("1.1.1.1"),
// },
// Metric: util.Int(64),
// AdminDist: util.Int(120),
// },
// },
// },
// Ipv6: &virtual_router.RoutingTableIpv6{
// StaticRoutes: []virtual_router.RoutingTableIpv6StaticRoutes{
// {
// Name: "default",
// Destination: util.String("0.0.0.0/0"),
// NextHop: &virtual_router.RoutingTableIpv6StaticRoutesNextHop{
// Ipv6Address: util.String("2001:0000:130F:0000:0000:09C0:876A:230D"),
// },
// Metric: util.Int(24),
// AdminDist: util.Int(20),
// },
// },
// },
},
Ecmp: &virtual_router.Ecmp{
Enable: util.Bool(true),
SymmetricReturn: util.Bool(true),
Expand Down Expand Up @@ -670,8 +641,8 @@ func checkSecurityPolicyRules(c *pango.Client, ctx context.Context) {
log.Printf("Security policy rule '%s:%s' with description '%s' read by id", *securityPolicyRuleReply.Uuid, securityPolicyRuleReply.Name, *securityPolicyRuleReply.Description)

// SECURITY POLICY RULE - UPDATE 2
securityPolicyRuleEntry.Description = util.String("changed by id description")
securityPolicyRuleReply, err = securityPolicyRuleApi.UpdateById(ctx, *securityPolicyRuleLocation, securityPolicyRuleEntry, *securityPolicyRuleReply.Uuid)
securityPolicyRuleEntry.Description = util.String("changed by name description")
securityPolicyRuleReply, err = securityPolicyRuleApi.Update(ctx, *securityPolicyRuleLocation, securityPolicyRuleEntry, securityPolicyRuleReply.Name)
if err != nil {
log.Printf("Failed to update security policy rule: %s", err)
return
Expand Down
18 changes: 9 additions & 9 deletions assets/pango/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func AsXpath(i interface{}) string {
}

// AsEntryXpath returns the given values as an entry xpath segment.
func AsEntryXpath(vals []string) string {
func AsEntryXpath(vals ...string) string {
if len(vals) == 0 || (len(vals) == 1 && vals[0] == "") {
return "entry"
}
Expand Down Expand Up @@ -160,18 +160,18 @@ func TemplateXpathPrefix(tmpl, ts string) []string {
return []string{
"config",
"devices",
AsEntryXpath([]string{"localhost.localdomain"}),
AsEntryXpath("localhost.localdomain"),
"template",
AsEntryXpath([]string{tmpl}),
AsEntryXpath(tmpl),
}
}

return []string{
"config",
"devices",
AsEntryXpath([]string{"localhost.localdomain"}),
AsEntryXpath("localhost.localdomain"),
"template-stack",
AsEntryXpath([]string{ts}),
AsEntryXpath(ts),
}
}

Expand All @@ -185,9 +185,9 @@ func DeviceGroupXpathPrefix(dg string) []string {
return []string{
"config",
"devices",
AsEntryXpath([]string{"localhost.localdomain"}),
AsEntryXpath("localhost.localdomain"),
"device-group",
AsEntryXpath([]string{dg}),
AsEntryXpath(dg),
}
}

Expand All @@ -202,9 +202,9 @@ func VsysXpathPrefix(vsys string) []string {
return []string{
"config",
"devices",
AsEntryXpath([]string{"localhost.localdomain"}),
AsEntryXpath("localhost.localdomain"),
"vsys",
AsEntryXpath([]string{vsys}),
AsEntryXpath(vsys),
}
}

Expand Down
8 changes: 4 additions & 4 deletions assets/pango/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func BenchmarkAsXpath(b *testing.B) {
p := []string{
"config",
"devices",
AsEntryXpath([]string{"localhost.localdomain"}),
AsEntryXpath("localhost.localdomain"),
"vsys",
AsEntryXpath([]string{"vsys1"}),
AsEntryXpath("vsys1"),
"import",
"network",
}
Expand All @@ -124,7 +124,7 @@ func BenchmarkAsEntryXpathMultiple(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
_ = AsEntryXpath(v)
_ = AsEntryXpath(v...)
}
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func TestAsEntryXpath(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.r, func(t *testing.T) {
if AsEntryXpath(tc.v) != tc.r {
if AsEntryXpath(tc.v...) != tc.r {
t.Fail()
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
resource "panos_template" "example" {
location = { panorama = {} }
name = "example"
}

resource "panos_ethernet_interface" "example" {
location = {
template = {
name = panos_template.example.name
}
}
name = "ethernet1/1"
layer3 = {
ips = [{ name = "192.168.1.1/32" }]
}
}

resource "panos_virtual_router" "example" {
location = {
template = {
name = panos_template.example.name
}
}
name = "example-vr1"
interfaces = [panos_ethernet_interface.example.name]
}

resource "panos_virtual_router" "example2" {
location = {
template = {
name = panos_template.example.name
}
}
name = "example-vr2"
}

resource "panos_virtual_router_static_route_ipv4" "vr1-example-route1" {
location = {
template = {
name = panos_template.example.name
}
}
virtual_router = panos_virtual_router.example.name
name = "example-route"
admin_dist = 15
destination = "192.168.2.0/24"
interface = panos_ethernet_interface.example.name
metric = 100

nexthop = {
ip_address = "192.168.1.254"
}

path_monitor = {
enable = true
failure_condition = "any"
hold_time = 2
monitor_destinations = [{
name = "dest-1"
enable = true
source = "192.168.1.1/32"
destination = "192.168.1.254"
interval = 3
count = 5
}]
}

route_table = {
unicast = {}
}
}

resource "panos_virtual_router_static_route_ipv4" "vr2-example-route1" {
location = {
template = {
name = panos_template.example.name
}
}
virtual_router = panos_virtual_router.example2.name
name = "example-route"
destination = "192.168.1.0/24"

nexthop = {
next_vr = panos_virtual_router.example.name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
resource "panos_template" "example" {
location = { panorama = {} }
name = "example-template"
}

resource "panos_ethernet_interface" "example" {
location = panos_template.example.location
name = "ethernet1/1"
layer3 = {
ipv6 = {
enabled = true
addresses = [{ name = "2001:db8:1::1/64" }]
}
}
}

resource "panos_virtual_router" "example" {
depends_on = [panos_template.example]
location = panos_template.example.location
name = "example-vr1"
interfaces = [panos_ethernet_interface.example.name]
}

resource "panos_virtual_router" "example2" {
depends_on = [panos_template.example]
location = panos_template.example.location
name = "example-vr2"
}

resource "panos_virtual_router_static_route_ipv6" "example" {
location = panos_template.example.location
virtual_router = panos_virtual_router.example.name
name = "example-route"
admin_dist = 15
destination = "2001:db8:2::/64"
interface = panos_ethernet_interface.example.name
metric = 100

nexthop = {
ipv6_address = "2001:db8:1::254"
}

path_monitor = {
enable = true
failure_condition = "any"
hold_time = 2
monitor_destinations = [{
name = "dest-1"
enable = true
source = "2001:db8:1::1/64"
destination = "2001:db8:1::254"
interval = 3
count = 5
}]
}

route_table = {
unicast = {}
}
}

resource "panos_virtual_router_static_route_ipv6" "example2" {
location = panos_template.example.location
virtual_router = panos_virtual_router.example2.name
name = "example-route2"
destination = "2001:db8:1::/64"

nexthop = {
next_vr = panos_virtual_router.example.name
}
}
Loading
Loading