Skip to content
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

use mnazarenko/docker-routeros #235

Merged
merged 5 commits into from
Nov 30, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
experimental: [false]
go: ["1.18"]
os: [ubuntu-latest]
# Test against latest stable release, v6 beta and v7 beta
routeros: ["6.48.3", "6.49beta54", "7.1beta6"]
# Test against latest stable 6.x and 7.x and "latest" stable
routeros: ["6.49.15", "7.14.3"]
include:
- experimental: true
go: 1.18
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:

services:
routeros:
image: evilfreelancer/docker-routeros:${{ matrix.routeros }}
image: mnazarenko/docker-routeros:${{ matrix.routeros }}
ddelnano marked this conversation as resolved.
Show resolved Hide resolved
ports:
- 8728:8728
volumes:
Expand Down
12 changes: 12 additions & 0 deletions client/client_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ type (
DeleteFieldValue() string
}

// Normalizer is used to normalize response from RouterOS.
// The main use-case is to populate fields which are empty in response but have default value,
// for example `authoritative=yes` in `DHCPServer` resource is not returned by remote RouterOS instance.
Normalizer interface {
Normalize(r *routeros.Reply)
}

// ErrorHandler Defines contract to handle errors returned by RouterOS.
// It can either return another error, or supress original error by returning nil.
ErrorHandler interface {
Expand Down Expand Up @@ -211,6 +218,11 @@ func (client Mikrotik) findByField(d Resource, field, value string) (Resource, e
if err != nil {
return nil, err
}

if n, ok := targetStructInterface.(Normalizer); ok {
n.Normalize(r)
}

// assertion is not checked as we are creating the targetStruct from 'd' argument which satisfies Resource interface
targetResource := targetStructInterface.(Resource)
if targetResource.ID() == "" {
Expand Down
10 changes: 10 additions & 0 deletions client/dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func (b *DhcpServer) FindField() string {
return "name"
}

func (b *DhcpServer) Normalize(r *routeros.Reply) {
if len(r.Re) < 1 || len(r.Re[0].Map) < 1 {
return
}

if _, ok := r.Re[0].Map["authoritative"]; !ok {
b.Authoritative = "yes"
}
}

func (b *DhcpServer) FindFieldValue() string {
return b.Name
}
Expand Down
5 changes: 3 additions & 2 deletions client/dhcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ func TestAddDhcpServerUpdateAndDelete(t *testing.T) {
name := "myserver"
disabled := true
dhcpServer, err := c.AddDhcpServer(&DhcpServer{
Name: name,
Disabled: disabled,
Name: name,
Disabled: disabled,
Interface: "*0",
})
if err != nil {
t.Fatal(err)
Expand Down
19 changes: 0 additions & 19 deletions docker/Dockerfile.routeros

This file was deleted.

6 changes: 1 addition & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

services:
routeros:
build:
context: .
dockerfile: Dockerfile.routeros
args:
ROUTEROS_VERSION: ${ROUTEROS_VERSION}
image: mnazarenko/docker-routeros:${ROUTEROS_VERSION:-latest}
environment:
DEBUG: "N"
DISPLAY: "web"
Expand Down
10 changes: 5 additions & 5 deletions mikrotik/resource_bgp_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccMikrotikBgpInstance_create(t *testing.T) {

resourceName := "mikrotik_bgp_instance.bar"

resource.ParallelTest(t, resource.TestCase{
ddelnano marked this conversation as resolved.
Show resolved Hide resolved
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpInstanceDestroy,
Expand All @@ -47,7 +47,7 @@ func TestAccMikrotikBgpInstance_createFailsOnRouterOSv7(t *testing.T) {
routerId := internal.GetNewIpAddr()
as := acctest.RandIntRange(1, 65535)

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpInstanceDestroy,
Expand All @@ -68,7 +68,7 @@ func TestAccMikrotikBgpInstance_createAndPlanWithNonExistantBgpInstance(t *testi

resourceName := "mikrotik_bgp_instance.bar"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpInstanceDestroy,
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestAccMikrotikBgpInstance_updateBgpInstance(t *testing.T) {

resourceName := "mikrotik_bgp_instance.bar"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpInstanceDestroy,
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestAccMikrotikBgpInstance_import(t *testing.T) {

resourceName := "mikrotik_bgp_instance.bar"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpInstanceDestroy,
Expand Down
8 changes: 4 additions & 4 deletions mikrotik/resource_bgp_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAccMikrotikBgpPeer_create(t *testing.T) {
remoteAddress, _ := acctest.RandIpAddress("192.168.0.0/24")

resourceName := "mikrotik_bgp_peer.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpPeerDestroy,
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestAccMikrotikBgpPeer_createAndPlanWithNonExistantBgpPeer(t *testing.T) {
t.Fatalf("Error removing the bgp peer: %s", err)
}
}
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpPeerDestroy,
Expand All @@ -107,7 +107,7 @@ func TestAccMikrotikBgpPeer_updateBgpPeer(t *testing.T) {
remoteAddress, _ := acctest.RandIpAddress("192.168.3.0/24")

resourceName := "mikrotik_bgp_peer.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpPeerDestroy,
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestAccMikrotikBgpPeer_import(t *testing.T) {

resourceName := "mikrotik_bgp_peer.bar"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikBgpPeerDestroy,
Expand Down
6 changes: 3 additions & 3 deletions mikrotik/resource_dhcp_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccMikrotikDhcpLease_create(t *testing.T) {
comment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_dhcp_lease.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDhcpLeaseDestroy,
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestAccMikrotikDhcpLease_updateLease(t *testing.T) {
updatedComment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_dhcp_lease.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDhcpLeaseDestroy,
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestAccMikrotikDhcpLease_import(t *testing.T) {
comment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_dhcp_lease.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDhcpLeaseDestroy,
Expand Down
10 changes: 5 additions & 5 deletions mikrotik/resource_dns_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccMikrotikDnsRecord_create(t *testing.T) {
ipAddr := internal.GetNewIpAddr()

resourceName := "mikrotik_dns_record.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDnsRecordDestroy,
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestAccMikrotikDnsRecord_createAndPlanWithNonExistantRecord(t *testing.T) {
}

}
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDnsRecordDestroy,
Expand All @@ -74,7 +74,7 @@ func TestAccMikrotikDnsRecord_updateAddress(t *testing.T) {
updatedIpAddr := internal.GetNewIpAddr()

resourceName := "mikrotik_dns_record.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDnsRecordDestroy,
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAccMikrotikDnsRecord_updateComment(t *testing.T) {
updatedComment := "new comment"

resourceName := "mikrotik_dns_record.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDnsRecordDestroy,
Expand All @@ -130,7 +130,7 @@ func TestAccMikrotikDnsRecord_import(t *testing.T) {
ipAddr := internal.GetNewIpAddr()

resourceName := "mikrotik_dns_record.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikDnsRecordDestroy,
Expand Down
6 changes: 3 additions & 3 deletions mikrotik/resource_interface_wireguard_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccMikrotikInterfaceWireguardPeer_create(t *testing.T) {
interfaceName := acctest.RandomWithPrefix("tf-acc-interface-wireguard")
publicKey := "/yZWgiYAgNNSy7AIcxuEewYwOVPqJJRKG90s9ypwfiM="
resourceName := "mikrotik_interface_wireguard_peer.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardPeerDestroy,
Expand All @@ -43,7 +43,7 @@ func TestAccMikrotikInterfaceWireguardPeer_updatedComment(t *testing.T) {
interfaceName := acctest.RandomWithPrefix("tf-acc-interface-wireguard")
publicKey := "/bTmUihbgNsSy2AIcxuEcwYwOVdqJJRKG51s4ypwfiM="
resourceName := "mikrotik_interface_wireguard_peer.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardPeerDestroy,
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestAccMikrotikInterfaceWireguardPeer_import(t *testing.T) {
interfaceName := acctest.RandomWithPrefix("tf-acc-interface-wireguard")
publicKey := "/zYaGiYbgNsSy8AIcxuEcwYwOVdqJJRKG91s9ypwfiM="
resourceName := "mikrotik_interface_wireguard_peer.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardPeerDestroy,
Expand Down
6 changes: 3 additions & 3 deletions mikrotik/resource_interface_wireguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccMikrotikInterfaceWireguard_create(t *testing.T) {
name := acctest.RandomWithPrefix("tf-acc-create")

resourceName := "mikrotik_interface_wireguard.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardDestroy,
Expand All @@ -45,7 +45,7 @@ func TestAccMikrotikInterfaceWireguard_updatedComment(t *testing.T) {
name := acctest.RandomWithPrefix("tf-acc-update-comment")

resourceName := "mikrotik_interface_wireguard.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardDestroy,
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestAccMikrotikInterfaceWireguard_import(t *testing.T) {
name := acctest.RandomWithPrefix("tf-acc-import")

resourceName := "mikrotik_interface_wireguard.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikInterfaceWireguardDestroy,
Expand Down
4 changes: 2 additions & 2 deletions mikrotik/resource_ip_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccMikrotikResourceIpAddress_create(t *testing.T) {
comment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_ip_address.test"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikIpAddressDestroy,
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestAccMikrotikResourceIpAddress_updateAddr(t *testing.T) {
updatedDisabled := "true"

resourceName := "mikrotik_ip_address.test"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikIpAddressDestroy,
Expand Down
4 changes: 2 additions & 2 deletions mikrotik/resource_ipv6_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccMikrotikResourceIpv6Address_create(t *testing.T) {
comment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_ipv6_address.test"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikIpv6AddressDestroy,
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestAccMikrotikResourceIpv6Address_updateAddr(t *testing.T) {
updatedDisabled := "true"

resourceName := "mikrotik_ipv6_address.test"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikIpv6AddressDestroy,
Expand Down
10 changes: 5 additions & 5 deletions mikrotik/resource_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccMikrotikPool_create(t *testing.T) {
ranges := fmt.Sprintf("%s,%s", internal.GetNewIpAddrRange(10), internal.GetNewIpAddr())

resourceName := "mikrotik_pool.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikPoolDestroy,
Expand All @@ -40,7 +40,7 @@ func TestAccMikrotikPool_createNextPool(t *testing.T) {
ranges := fmt.Sprintf("%s,%s", internal.GetNewIpAddrRange(10), internal.GetNewIpAddr())

resourceName := "mikrotik_pool.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikPoolDestroy,
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestAccMikrotikPool_createAndPlanWithNonExistantPool(t *testing.T) {
t.Fatalf("Error removing the pool: %s", err)
}
}
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikPoolDestroy,
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestAccMikrotikPool_updatePool(t *testing.T) {
comment := acctest.RandomWithPrefix("tf-acc-comment")

resourceName := "mikrotik_pool.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikPoolDestroy,
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestAccMikrotikPool_import(t *testing.T) {
ranges := fmt.Sprintf("%s,%s", internal.GetNewIpAddrRange(10), internal.GetNewIpAddr())

resourceName := "mikrotik_pool.bar"
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikPoolDestroy,
Expand Down
Loading
Loading