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

feat: Refactor mech driver #500

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

feat: Refactor mech driver #500

wants to merge 13 commits into from

Conversation

mfencik
Copy link
Contributor

@mfencik mfencik commented Nov 19, 2024

After this is tested and merged, I'm aware we can do a better cleanup in workflows as we won't need undersync_device workflow anymore.
This PR needs another change in Nautobot prep_switch_interface job as from now on we can use connected_interface_uuid instead of mac_address, so please leave merging to me.

Copy link
Contributor

@stevekeay stevekeay left a comment

Choose a reason for hiding this comment

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

Timeouts were recently added to prevent the undersync workflow from hanging indefinitely. It might be a good idea to do that here, too.

Comment on lines +48 to +51
if method == "delete":
resp_data = {"status_code": resp.status_code}
else:
resp_data = resp.json()
Copy link
Contributor

Choose a reason for hiding this comment

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

What's special about DELETE?

Suggested change
if method == "delete":
resp_data = {"status_code": resp.status_code}
else:
resp_data = resp.json()
if resp.content:
resp_data = resp.json()
else:
resp_data = {"status_code": resp.status_code}

def make_api_request(self, url: str, method: str, payload: dict) -> dict:
endpoint_url = urljoin(self.base_url, url)
caller_function = inspect.stack()[self.CALLER_FRAME].function
api_call = getattr(self.s, method)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider just using self.s.request(method, url, ...) although I think that requires method to be upper case.

https://requests.readthedocs.io/en/latest/api/#requests.Session.request

args = {"url": endpoint_url, "timeout": 10}

if method != "get":
args["payload"] = payload
Copy link
Contributor

Choose a reason for hiding this comment

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

Requests library calls this param data. How is this working?

if network_id == cfg.CONF.ml2_type_understack.provisioning_network:
network_name = "provisioning"
port_status = "Provisioning-Interface"
Copy link
Contributor

Choose a reason for hiding this comment

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

So this sets the port status to Provisioning, doesn't it have to set it back again afterwards?

"Sleeps 5 seconds between attempts.",
),
cfg.BoolOpt("argo_dry_run", default=True, help="Call Undersync with dry-run mode"),
cfg.BoolOpt("argo_force", default=False, help="Call Undersync with force mode"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I added these options to the undersync API because they might be useful for troubleshooting, etc., but I don't think they need to be exposed here unless we have a specific need for them. I can maybe see a reason to have dry_run but certainly "force" would not be a good thing to have permanently switched on.

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

Successfully merging this pull request may close these issues.

2 participants