From a820cd461925c3d6f61a8527bc4bcc4df844a687 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 15 Oct 2024 23:48:40 +0900 Subject: [PATCH] Fix mypy errors Fix the argument type mismatches detected now. Change-Id: I0f1b7cbee9fc64fd1dba8c488a0634cbbe23adb6 --- cinder/backup/manager.py | 6 +++--- cinder/volume/flows/api/create_volume.py | 5 +++-- cinder/volume/volume_types.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index 9cadf7c9ff6..7e700d4024a 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -384,7 +384,7 @@ class BackupManager(manager.SchedulerDependentManager): self._notify_about_backup_usage(context, backup, "create.start") expected_status = "backing-up" - if snapshot_id: + if snapshot: actual_status = snapshot['status'] if actual_status != expected_status: err = _('Create backup aborted, expected snapshot status ' @@ -546,7 +546,7 @@ class BackupManager(manager.SchedulerDependentManager): message_field.Detail.DETACH_ERROR) except Exception as err: with excutils.save_and_reraise_exception(): - if snapshot_id: + if snapshot: snapshot.status = fields.SnapshotStatus.AVAILABLE snapshot.save() else: @@ -838,7 +838,7 @@ class BackupManager(manager.SchedulerDependentManager): {'volume_id': volume.id, 'backup_id': backup.id}) key_mgr = key_manager.API(CONF) - if orig_key_id is not None: + if orig_key_id: LOG.debug('Deleting original volume encryption key ID.') volume_utils.delete_encryption_key(context, key_mgr, diff --git a/cinder/volume/flows/api/create_volume.py b/cinder/volume/flows/api/create_volume.py index fe071289793..bde89361989 100644 --- a/cinder/volume/flows/api/create_volume.py +++ b/cinder/volume/flows/api/create_volume.py @@ -356,11 +356,12 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask): self, key_manager, context: context.RequestContext, - volume_type_id: str, + volume_type_id: Optional[str], snapshot: Optional[objects.Snapshot], source_volume: Optional[objects.Volume], image_metadata: Optional[dict[str, Any]]) -> Optional[str]: - if volume_types.is_encrypted(context, volume_type_id): + if volume_type_id and volume_types.is_encrypted( + context, volume_type_id): encryption_key_id = None if snapshot is not None: # creating from snapshot diff --git a/cinder/volume/volume_types.py b/cinder/volume/volume_types.py index 5a7954ad0c5..efbbdeeb89c 100644 --- a/cinder/volume/volume_types.py +++ b/cinder/volume/volume_types.py @@ -324,7 +324,7 @@ def remove_volume_type_access(context: context.RequestContext, def is_encrypted(context: context.RequestContext, - volume_type_id: str) -> bool: + volume_type_id: Optional[str]) -> bool: return get_volume_type_encryption(context, volume_type_id) is not None @@ -444,7 +444,7 @@ def volume_types_diff(context: context.RequestContext, def volume_types_encryption_changed( context: context.RequestContext, - vol_type_id1: str, vol_type_id2: str) -> bool: + vol_type_id1: Optional[str], vol_type_id2: Optional[str]) -> bool: """Return whether encryptions of two volume types are same.""" def _get_encryption(enc: dict) -> dict: enc = dict(enc)