Skip to content

Commit

Permalink
Merge pull request red-hat-storage#11050 from vavuthu/fix_mcg_cli_del…
Browse files Browse the repository at this point in the history
…ete__when_obj_doesnot_exist

mcg-cli delete for object which doesn't exist
  • Loading branch information
vavuthu authored Dec 17, 2024
2 parents 54e599d + f26af5c commit f7d57c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion ocs_ci/ocs/resources/mcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,9 @@ def _check_state():
)
assert False

def exec_mcg_cmd(self, cmd, namespace=None, use_yes=False, **kwargs):
def exec_mcg_cmd(
self, cmd, namespace=None, use_yes=False, ignore_error=False, **kwargs
):
"""
Executes an MCG CLI command through the noobaa-operator pod's CLI binary
Expand All @@ -887,12 +889,14 @@ def exec_mcg_cmd(self, cmd, namespace=None, use_yes=False, **kwargs):
if use_yes:
result = exec_cmd(
[f"yes | {constants.NOOBAA_OPERATOR_LOCAL_CLI_PATH} {cmd} {namespace}"],
ignore_error=ignore_error,
shell=True,
**kwargs,
)
else:
result = exec_cmd(
f"{constants.NOOBAA_OPERATOR_LOCAL_CLI_PATH} {cmd} {namespace}",
ignore_error=ignore_error,
**kwargs,
)
result.stdout = result.stdout.decode()
Expand Down
16 changes: 13 additions & 3 deletions ocs_ci/ocs/resources/objectbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,19 @@ def internal_delete(self):
NotFoundError: In case the OBC was not found
"""
result = self.mcg.exec_mcg_cmd(f"obc delete {self.name}")
if "deleting" and self.name not in result.stderr.lower():
raise NotFoundError(result)
try:
result = self.mcg.exec_mcg_cmd(f"obc delete {self.name}")
if (
"deleting" not in result.stderr.lower()
and self.name not in result.stderr.lower()
):
raise NotFoundError(result)
except CommandFailed as e:
result = self.mcg.exec_mcg_cmd(f"obc delete {self.name}", ignore_error=True)
if f'Not Found: ObjectBucketClaim "{self.name}"' in str(
result.stderr
) and "does not exist" in str(result.stderr):
raise NotFoundError(e)

@property
def internal_status(self):
Expand Down

0 comments on commit f7d57c0

Please sign in to comment.