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

added veth interface and tests #217

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

robbisso
Copy link

@robbisso robbisso commented Dec 8, 2023

Added interface veth resource and tests to go with, it is missing testing for gateway6 field the code covers updating and handling this field just fine. If you have recommendations on how you would like this handled I will update accordingly

Copy link
Collaborator

@maksym-nazarenko maksym-nazarenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbisso thank you for this contribution,
I left some comments which should be addressed before approving so don't hesitate to ask for help, if needed.

client/interface_veth_test.go Outdated Show resolved Hide resolved
client/interface_veth_test.go Outdated Show resolved Hide resolved
client/interface_veth_test.go Outdated Show resolved Hide resolved
client/interface_veth_test.go Outdated Show resolved Hide resolved
mikrotik/resource_interface_veth.go Outdated Show resolved Hide resolved
mikrotik/resource_interface_veth.go Outdated Show resolved Hide resolved
mikrotik/resource_interface_veth.go Outdated Show resolved Hide resolved
mikrotik/resource_interface_veth.go Show resolved Hide resolved
mikrotik/resource_interface_veth_test.go Outdated Show resolved Hide resolved
@maksym-nazarenko
Copy link
Collaborator

@robbisso forgot to add to the review: tfplugindocs / tfplugindocs (pull_request) Failing after 45s
pr should contain updated docs, which can be generated with go generate and committed in this PR.

@maksym-nazarenko maksym-nazarenko added the enhancement New feature or request label Dec 8, 2023
@maksym-nazarenko
Copy link
Collaborator

@ddelnano we have a major issue here - the latest Docker image for RouterOS has v7.1beta6 as version, but veth support appeared in v7.4 if I read changelog correctly.
We might need to handle this on our own as the upstream for Docker image seems to be abandoned. (I'll create an issue in some days)

@robbisso
Copy link
Author

@maksym-nazarenko I'm using a CHR vm to do the testing in esxi, but I came to the same conclusion regarding abandoned docker image. There are also issues with dhcp_server_test.go and interface_wireguard_peer_test.go, I'm assuming that the newer routeros version is partially at fault. I can submit a PR with those adjustments later.

@robbisso
Copy link
Author

@maksym-nazarenko I caught an email from you regarding the vlan_interface, it doesn't follow the naming convention for the other "interface" types, should this item be named veth_interface instead or vlan_interface -> interface_vlan?

@robbisso
Copy link
Author

@maksym-nazarenko updated with the requested changes please let me know if there is anything else that should be changed.

@maksym-nazarenko
Copy link
Collaborator

@maksym-nazarenko I caught an email from you regarding the vlan_interface, it doesn't follow the naming convention for the other "interface" types, should this item be named veth_interface instead or vlan_interface -> interface_vlan?

You are right - the vlan_interface was named wrongly.
Ideally, the resource name should be the same as RouterOS command path with / replaced by _, e.f. mikrotik_interface_vlan, so your way for veth is correct one

@robbisso
Copy link
Author

Having some issues with making non-blank fields blank on update, haven't troubleshooted too deep on it yet but wonder if it might have something to do with the generic crud operations. I don't want to mark the fields as resource replace required since they do not need replacement to update via shell or winbox. I have created a gist https://gist.github.com/robbisso/fee7e832a2b1bdbdef6cf5990a899b29 with the updated test code

@maksym-nazarenko
Copy link
Collaborator

Having some issues with making non-blank fields blank on update, haven't troubleshooted too deep on it yet but wonder if it might have something to do with the generic crud operations. I don't want to mark the fields as resource replace required since they do not need replacement to update via shell or winbox. I have created a gist https://gist.github.com/robbisso/fee7e832a2b1bdbdef6cf5990a899b29 with the updated test code

that's because our client does not marshal empty values, which is a broader issue (it's on my personal roadmap, but still didn't have time to look into it).

I've already faced it for pool resource

@robbisso
Copy link
Author

Thanks, that'll help narrow it down a bit I'll try to find a patch that works for it later in the week if I have time.

@robbisso
Copy link
Author

robbisso commented Dec 11, 2023

Having some issues with making non-blank fields blank on update, haven't troubleshooted too deep on it yet but wonder if it might have something to do with the generic crud operations. I don't want to mark the fields as resource replace required since they do not need replacement to update via shell or winbox. I have created a gist https://gist.github.com/robbisso/fee7e832a2b1bdbdef6cf5990a899b29 with the updated test code

that's because our client does not marshal empty values, which is a broader issue (it's on my personal roadmap, but still didn't have time to look into it).

I've already faced it for pool resource

Well I do know what's going wrong as far as the command it is issuing to the router goes, appears that since the value is empty it isn't sending over the "" that mikrotik is expecting to see for an unset.

I'm not super familiar with go, fixing this for string should be easy enough but depending on how go handles empty ints/datatypes there may be an issue with adjusting the marshaller for those. Perhaps you can offer some insight on that.

Due to the way the marshaller handles types in general and some fields should or should not be sent on commands such as print, I see that this is a larger issue overall. It may be best solved with adding tags to the struct field based on the command type to be run / or specifying data fields in the same manner. the check for value.IsZero() is filtering out the empty strings well as the ints == 0

@maksym-nazarenko
Copy link
Collaborator

Yeah, change like this requires some work.

While it might be valid for some cases for the Terraform provider itself, it breaks the client in some places.

One example is dhcp-server.

If Marshal() function skips IsZero() check, it will render all fields, including authoritative and you will get this error:

from RouterOS device: ambiguous value of authoritative, more than one possible value matches input

it's because authoritative field has several possible values:

[admin@MikroTik] /ip/dhcp-server> add authoritative=
after-2sec-delay  after-10sec-delay  no  yes

but client does not have concept of default value.
In turn, Terraform resource provides default values so acceptance test doesn't fail.

I don't have clear, easy and maintainable solution for this right now, that's why I haven't started implementation.

As an option, we could add omitempty to tags for client struct and mark individual fields to be omitted if blank, while other are passed with empty value =field= while marshaling.
However, we should be careful here, as not all fields accept empty values for unsetting (see next-pool field in pool resource)

@robbisso
Copy link
Author

robbisso commented Dec 12, 2023 via email

@robbisso
Copy link
Author

robbisso commented Dec 13, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants