feat: PUC-785: crud ucvni-group range on network-segment-range events#796
feat: PUC-785: crud ucvni-group range on network-segment-range events#796haseebsyed12 merged 2 commits intomainfrom
Conversation
3cdd652 to
85aaa2e
Compare
0f2c0d4 to
73b3612
Compare
mfencik
left a comment
There was a problem hiding this comment.
IMHO, the python code should be refactored as those long functions are not readable and I don't see any tests for those too. Let's try to keep our code clean and tested as much as possible, good practices can be found at https://refactoring.guru/refactoring
python/understack-workflows/understack_workflows/main/sync_ucvni_groups.py
Outdated
Show resolved
Hide resolved
73b3612 to
b232ffb
Compare
skrobul
left a comment
There was a problem hiding this comment.
Now that https://github.com/RSS-Engineering/undercloud-rackspace/pull/415 has landed, please rework this to use pynautobot to avoid duplication
b232ffb to
aa5bb4c
Compare
7fe2594 to
faacf4b
Compare
skrobul
left a comment
There was a problem hiding this comment.
this code still has multiple references to the requests library. There are few places where the code looks for RequestException, while the pynautobot documentation states that the unhappy path raises Nautobot specific exceptions. Could you please verify which ones are actually used and adjust if needed?
faacf4b to
a9dc886
Compare
| ) | ||
| notes_endpoint: Endpoint = nautobot.session.extras.notes | ||
| except requests.exceptions.ConnectTimeout as e: | ||
| logger.error("Network error while connecting to Nautobot: %s", str(e)) |
There was a problem hiding this comment.
@skrobul : here I added this to capture nautobot service down scenario. Please suggest if this can be handled using pynautobot exception. I did not find any such.
There was a problem hiding this comment.
Correct me if I'm wrong but this except block is essentially a dead code that can never be reached. Here is why:
- Your code (correctly) initializes
Nautobotobject providing URL, token and logger and accepting other defaults. Nautobotlooks for a providedsessionand if one isn't, it creates one by callingpynautobot.api.- When
pynautobot.apiinitializes, it creates a requests.Session(), again usingrequestslibrary defaults. Unfortunately, these defaults are stupid. All of the requests created with a default session do not time out and hang around forever.
In summary, with current setup, I don't think the ConnectTimeout will ever be raised, but if you managed to get this raised I'd be interested to see the code to replicate this.
Now, in terms of solutions here - I think it would be reasonable to:
- move the Nautobot related code to
nautobot.py - once that's done, look into how we can fix the Connection Timeout handling on connections to Nautobot, not only for this call but also for other ones in
nautobot.pywhich seem to suffer from the same problem
There was a problem hiding this comment.
I tested connection timeout in my local without connecting to Appgate and I am able to catch requests.exceptions.ConnectTimeout.
Regarding setting timeout I followed this documentation. But in my above scenario this is not useful because it's only added after the api() call has already returned in nautobot.py.
def api_session(self, url: str, token: str) -> NautobotApi:
api = pynautobot.api(url, token=token)
api.http_session.mount(api.base_url, TimeoutHTTPAdapter())
return api
What do you suggest about my test without connecting to Appgate ?There was a problem hiding this comment.
Turns out I was wrong. If you ignore the documentation linked above, the connection attempts do not actually hang forever anymore and the ConnectTimeout is handled on the lower level and defaults to socket's default timeout.
After further testing on my machine, the simulated timeout happened after about 2 minutes and 15 seconds
>>> try:
... print(datetime.now())
... nb.dcim.devices.get('52a36d73-2e43-4ba1-b64a-9b99aa6b862c')
... finally:
... print(datetime.now())
...
2025-04-15 15:42:58.739109
2025-04-15 15:45:13.121909The same test on @haseebsyed12 took just 75 seconds. Looking at the urllib3 source code this might be OS dependent:
In conclusion, I think we can stick to the defaults as they are and only implement the TimeoutHTTPAdapter when we need to change them to a specific value. My primary concern was around having the timeout potentially set to infinity which clearly isn't the case, so my comment can be disregarded and no further changes are needed here.

tested end to end workflow