Skip to content

Commit fc9b6d6

Browse files
committed
addressing the styles and removing the duplicate key
1 parent 54be25e commit fc9b6d6

File tree

7 files changed

+45
-52
lines changed

7 files changed

+45
-52
lines changed

src/migrate/azext_migrate/helpers/replication/get/_execute_get.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def _format_protected_item(item):
172172
'lastSuccessfulUnplannedFailoverTime': properties.get('lastSuccessfulUnplannedFailoverTime', 'N/A'),
173173
'resynchronizationRequired': properties.get('resynchronizationRequired', False),
174174
'lastTestFailoverStatus': properties.get('lastTestFailoverStatus', 'N/A'),
175-
'replicationExtensionName': properties.get('replicationExtensionName', 'N/A'),
176175
'customProperties': custom_properties,
177176
}
178177

src/migrate/azext_migrate/helpers/replication/job/_format.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,23 @@ def calculate_duration(start_time, end_time):
3434

3535
if hours > 0:
3636
return f"{hours}h {minutes}m {seconds}s"
37-
elif minutes > 0:
37+
if minutes > 0:
3838
return f"{minutes}m {seconds}s"
39-
else:
40-
return f"{seconds}s"
41-
else:
42-
# Job still running
43-
now = datetime.utcnow()
44-
duration = now - start
45-
total_seconds = int(duration.total_seconds())
46-
minutes, seconds = divmod(total_seconds, 60)
47-
hours, minutes = divmod(minutes, 60)
48-
49-
if hours > 0:
50-
return f"{hours}h {minutes}m (in progress)"
51-
elif minutes > 0:
52-
return f"{minutes}m {seconds}s (in progress)"
53-
else:
54-
return f"{seconds}s (in progress)"
55-
except Exception:
39+
return f"{seconds}s"
40+
41+
# Job still running
42+
now = datetime.utcnow()
43+
duration = now - start
44+
total_seconds = int(duration.total_seconds())
45+
minutes, seconds = divmod(total_seconds, 60)
46+
hours, minutes = divmod(minutes, 60)
47+
48+
if hours > 0:
49+
return f"{hours}h {minutes}m (in progress)"
50+
if minutes > 0:
51+
return f"{minutes}m {seconds}s (in progress)"
52+
return f"{seconds}s (in progress)"
53+
except Exception: # pylint: disable=broad-exception-caught
5654
return None
5755

5856

src/migrate/azext_migrate/helpers/replication/job/_retrieve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def list_all_jobs(cmd, subscription_id, resource_group_name,
148148
for job in jobs:
149149
try:
150150
formatted_jobs.append(format_job_summary(job))
151-
except Exception as format_error:
151+
except Exception as format_error: # pylint: disable=broad-exception-caught
152152
logger.warning("Error formatting job: %s", str(format_error))
153153
# Skip jobs that fail to format
154154
continue
155155

156156
return formatted_jobs
157157

158-
except Exception as e:
158+
except Exception as e: # pylint: disable=broad-exception-caught
159159
logger.error("Error listing jobs: %s", str(e))
160160
raise CLIError(f"Failed to list jobs: {str(e)}")

src/migrate/azext_migrate/helpers/replication/list/_execute_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def list_protected_items(cmd, subscription_id, resource_group_name, vault_name):
167167
try:
168168
formatted_item = _format_protected_item(item)
169169
formatted_items.append(formatted_item)
170-
except Exception as format_error:
170+
except Exception as format_error: # pylint: disable=broad-exception-caught
171171
logger.warning("Error formatting protected item: %s", str(format_error))
172172
# Skip items that fail to format
173173
continue

src/migrate/azext_migrate/helpers/replication/new/_execute_new.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
# pylint: disable=line-too-long
77
# pylint: disable=possibly-used-before-assignment
8+
from knack.util import CLIError
9+
from knack.log import get_logger
810
from azext_migrate.helpers._utils import (
911
get_resource_by_id,
1012
create_or_update_resource,
1113
APIVersion,
12-
ProvisioningState,
1314
SiteTypes,
1415
VMNicSelection
1516
)
16-
import re
17-
from knack.util import CLIError
18-
from knack.log import get_logger
1917

2018
logger = get_logger(__name__)
2119

@@ -61,17 +59,17 @@ def get_ARC_resource_bridge_info(cmd, target_fabric, migrate_project):
6159
custom_location = get_resource_by_id(
6260
cmd, custom_location_id, "2021-08-15")
6361
custom_location_region = custom_location.get('location')
64-
logger.info(f"Retrieved custom location region: {custom_location_region}")
65-
except Exception as e:
62+
logger.info("Retrieved custom location region: %s", custom_location_region)
63+
except Exception: # pylint: disable=broad-exception-caught
6664
logger.warning(
67-
f"Could not retrieve custom location: {str(e)}. "
68-
f"Falling back to migrate project location.")
65+
"Could not retrieve custom location. "
66+
"Falling back to migrate project location.")
6967

7068
# Fall back to migrate project location if we couldn't get custom location region
7169
if not custom_location_region:
7270
custom_location_region = migrate_project.get('location', 'eastus')
7371
logger.warning(
74-
f"Using migrate project location as fallback: {custom_location_region}")
72+
"Using migrate project location as fallback: %s", custom_location_region)
7573

7674
return custom_location_id, custom_location_region, target_cluster_id
7775

@@ -109,16 +107,16 @@ def ensure_target_resource_group_exists(cmd, target_resource_group_id,
109107
cmd, rg_check_uri, "2021-04-01")
110108
if existing_rg:
111109
logger.info(
112-
f"Target resource group '{target_rg_name}' already exists "
113-
f"in subscription '{target_subscription_id}'")
110+
"Target resource group '%s' already exists "
111+
"in subscription '%s'", target_rg_name, target_subscription_id)
114112
return existing_rg
115113
except CLIError as e:
116114
error_str = str(e)
117115
if "ResourceGroupNotFound" in error_str or "404" in error_str:
118116
# Resource group doesn't exist, create it
119117
logger.info(
120-
f"Target resource group '{target_rg_name}' not found. "
121-
f"Creating in subscription '{target_subscription_id}'...")
118+
"Target resource group '%s' not found. "
119+
"Creating in subscription '%s'...", target_rg_name, target_subscription_id)
122120

123121
rg_body = {
124122
"location": custom_location_region,
@@ -128,18 +126,17 @@ def ensure_target_resource_group_exists(cmd, target_resource_group_id,
128126
}
129127

130128
print(
131-
f"Creating target resource group '{target_rg_name}' "
132-
f"in region '{custom_location_region}'...")
129+
"Creating target resource group '%s' "
130+
"in region '%s'..." % (target_rg_name, custom_location_region))
133131

134132
created_rg = create_or_update_resource(
135133
cmd, rg_check_uri, "2021-04-01", rg_body)
136134

137-
print(
138-
f"✓ Target resource group '{target_rg_name}' created successfully")
135+
print("Target resource group '%s' created successfully." % target_rg_name)
139136
return created_rg
140-
else:
141-
# Some other error, re-raise
142-
raise
137+
138+
# Re-raise if it's a different error
139+
raise
143140

144141

145142
def construct_disk_and_nic_mapping(is_power_user_mode,
@@ -262,7 +259,8 @@ def _handle_configuration_validation(cmd,
262259
APIVersion.Microsoft_DataReplication.value)
263260
if existing_item:
264261
protection_state = existing_item.get('properties', {}).get('protectionState')
265-
logger.warning(f"Found existing protected item: {existing_item.get('id', 'unknown')}, state: {protection_state}")
262+
logger.warning("Found existing protected item: %s, state: %s",
263+
existing_item.get('id', 'unknown'), protection_state)
266264

267265
# If in failed state, offer helpful guidance
268266
if protection_state in ['EnablingFailed', 'DisablingFailed', 'Failed']:
@@ -271,14 +269,13 @@ def _handle_configuration_validation(cmd,
271269
f"Please delete it first using Azure Portal or contact Azure Support. "
272270
f"Protected item ID: {protected_item_uri}"
273271
)
274-
else:
275-
raise CLIError(
276-
f"A replication already exists for machine '{machine_name}' (state: {protection_state}). "
277-
"Remove it first before creating a new one.")
272+
raise CLIError(
273+
f"A replication already exists for machine '{machine_name}' (state: {protection_state}). "
274+
"Remove it first before creating a new one.")
278275
except (CLIError, ValueError, KeyError, TypeError) as e:
279276
# Check if it's a 404 Not Found error - that's expected and fine
280277
error_str = str(e)
281-
logger.info(f"Exception during protected item check: {error_str}")
278+
logger.info("Exception during protected item check: %s", error_str)
282279
if ("ResourceNotFound" in error_str or "404" in error_str or
283280
"Not Found" in error_str):
284281
existing_item = None

src/migrate/azext_migrate/helpers/replication/new/_process_inputs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
# pylint: disable=line-too-long
77
# pylint: disable=possibly-used-before-assignment
8-
from azure.cli.core.commands.client_factory import get_subscription_id
98
from azext_migrate.helpers._utils import (
109
send_get_request,
1110
get_resource_by_id,

src/migrate/azext_migrate/helpers/replication/remove/_execute_delete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_job_details(cmd, subscription_id, resource_group_name,
120120

121121
return job_details
122122

123-
except Exception as job_error:
123+
except Exception as job_error: # pylint: disable=broad-exception-caught
124124
logger.warning(
125125
"Could not retrieve job details: %s. "
126126
"Replication removal was initiated.",
@@ -181,8 +181,8 @@ def execute_removal(cmd, subscription_id, target_object_id,
181181
display_removal_success(
182182
protected_item_name, job_name, resource_group_name)
183183
return job_details
184-
else:
185-
# Job details unavailable but we have the job name
184+
185+
# Job details unavailable but we have the job name
186186
display_removal_success(
187187
protected_item_name, job_name, resource_group_name)
188188
return None

0 commit comments

Comments
 (0)