-
Notifications
You must be signed in to change notification settings - Fork 0
migrate limits in v2.37 #63
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||
| # | ||||||||
| # Copyright (c) 2026, RTE (http://www.rte-france.com) | ||||||||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||
| # | ||||||||
|
|
||||||||
| import requests | ||||||||
| import argparse | ||||||||
| import constant | ||||||||
| import sys | ||||||||
| from tqdm import tqdm | ||||||||
|
|
||||||||
| from functions.networks.networks import get_all_networks_uuid | ||||||||
| from functions.networks.networks import get_variants | ||||||||
| from functions.networks.networks import migrate_v237_limits | ||||||||
| from functions.plateform.plateform import get_plateform_info | ||||||||
| from functions.plateform.plateform import check_server_status | ||||||||
|
|
||||||||
| # | ||||||||
| # @author Etienne Lesot <etienne.lesot at rte-france.com> | ||||||||
| # | ||||||||
|
|
||||||||
| parser = argparse.ArgumentParser(description='Send requests to the gridsuite services to migrate V2.37 limits', ) | ||||||||
|
|
||||||||
| parser.add_argument("-n", "--dry-run", help="test mode (default) will not execute any deletion request", | ||||||||
| action="store_true") | ||||||||
|
|
||||||||
|
|
||||||||
| args = parser.parse_args() | ||||||||
| dry_run = args.dry_run | ||||||||
|
Comment on lines
+24
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make dry-run the real default before this runs against all networks. With Suggested fix parser = argparse.ArgumentParser(description='Send requests to the gridsuite services to migrate V2.37 limits', )
-parser.add_argument("-n", "--dry-run", help="test mode (default) will not execute any deletion request",
- action="store_true")
+parser.add_argument(
+ "-n",
+ "--dry-run",
+ dest="dry_run",
+ action="store_true",
+ default=True,
+ help="test mode (default) will not execute any migration request",
+)
+parser.add_argument(
+ "--execute",
+ dest="dry_run",
+ action="store_false",
+ help="apply the migration requests",
+)
args = parser.parse_args()
dry_run = args.dry_run🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| print("---------------------------------------------------------") | ||||||||
| print("V2.37 limits migration script") | ||||||||
| if dry_run: | ||||||||
| print("dry-run=" + str(dry_run) + " -> will run without modifying anything (test mode)") | ||||||||
| if constant.DEV: | ||||||||
| print("DEV=" + str(constant.DEV) + " -> hostnames configured for a local execution (172.17.0.1:xxxx)") | ||||||||
| print("\n") | ||||||||
|
|
||||||||
| # Check network-store-server | ||||||||
| if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME): sys.exit() | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exit non-zero when the preflight check fails. A bare Suggested fix-if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME): sys.exit()
+if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME):
+ sys.exit(1)📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.13)[error] 42-42: Multiple statements on one line (colon) (E701) 🤖 Prompt for AI Agents |
||||||||
| print("\n") | ||||||||
| # Just getting an enlightening url opportunistically from here because it exists | ||||||||
| plateformName = get_plateform_info()['redirect_uri'] | ||||||||
|
|
||||||||
| print("\n") | ||||||||
|
|
||||||||
| print("---------------------------------------------------------") | ||||||||
| print("This script will apply on plateform = " + plateformName ) | ||||||||
| print("\n") | ||||||||
| print("===> network-store-server seems OK ! The script can proceed") | ||||||||
| print("\n") | ||||||||
| networks = get_all_networks_uuid() | ||||||||
| print("For a total of " + str(len(networks)) + " networks") | ||||||||
| print("---------------------------------------------------------") | ||||||||
|
|
||||||||
| print("V2.11 limits migration (dry-run=" + str(dry_run) + ") in processing...") | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the migration banner version. This still logs Suggested fix-print("V2.11 limits migration (dry-run=" + str(dry_run) + ") in processing...")
+print("V2.37 limits migration (dry-run=" + str(dry_run) + ") in processing...")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| failCount = 0 | ||||||||
| successCount = 0 | ||||||||
| for network in tqdm(networks): | ||||||||
| variants = get_variants(network['uuid']) | ||||||||
| for variant in variants: | ||||||||
| if not dry_run: | ||||||||
| try: | ||||||||
| migrate_v237_limits(network['uuid'], variant['num']) | ||||||||
| successCount += 1 | ||||||||
| except Exception as e: | ||||||||
| failCount += 1 | ||||||||
| # print only str(e) instead of the full traceback because we call this method from a simple for loop script | ||||||||
| tqdm.write("network " + network['uuid'] + ", variantNum " + str(variant['num']) + " => migration failed: "+ str(e)) | ||||||||
| if isinstance(e, requests.exceptions.RequestException) and e.response is not None: | ||||||||
| tqdm.write("Response body: " + repr(e.response.text)) # repr for cheap escaping | ||||||||
| tqdm.write("") # emtpy newline between errors for legibility | ||||||||
|
Comment on lines
+68
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n scripts/migrate_v237_limits.py | head -100Repository: gridsuite/admin-tools Length of output: 3740 🏁 Script executed: find . -type f -name "*.py" | xargs grep -l "def migrate_v237_limits"Repository: gridsuite/admin-tools Length of output: 106 🏁 Script executed: cat -n ./scripts/functions/networks/networks.py | head -200Repository: gridsuite/admin-tools Length of output: 1682 Narrow exception handling to requests failures only. The Suggested fix- except Exception as e:
+ except requests.exceptions.RequestException as e:
failCount += 1
# print only str(e) instead of the full traceback because we call this method from a simple for loop script
tqdm.write("network " + network['uuid'] + ", variantNum " + str(variant['num']) + " => migration failed: "+ str(e))
- if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
+ if e.response is not None:
tqdm.write("Response body: " + repr(e.response.text)) # repr for cheap escaping
tqdm.write("") # emtpy newline between errors for legibility🧰 Tools🪛 Ruff (0.15.13)[warning] 68-68: Do not catch blind exception: (BLE001) 🤖 Prompt for AI Agents |
||||||||
| print("End of V2.37.0 limits migration") | ||||||||
| print("Variant migration sucesses : " + str(successCount)) | ||||||||
| print("Variant migration failures : " + str(failCount)) | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 106
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 697
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 1293
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 7742
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 47
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 1082
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 3227
🏁 Script executed:
Repository: gridsuite/admin-tools
Length of output: 1682
Add an explicit timeout to prevent indefinite blocking in the migration loop.
This function is called within a nested loop over all networks and variants. Without a timeout, a single hung HTTP request will stall the entire migration indefinitely. The fix is straightforward.
Suggested fix
🧰 Tools
🪛 Ruff (0.15.13)
[error] 34-34: Probable use of
requestscall without timeout(S113)
🤖 Prompt for AI Agents