Skip to content

Commit

Permalink
refactor(physical-restore): Comment down only failed ansible commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Jan 20, 2025
1 parent 391ead0 commit ee45d31
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def mount_volume_to_instance(self) -> StepStatus: # noqa: C901
"""
result = self.ansible_run("lsblk --json -o name,fstype,type,label")
if result["status"] != "Success":
self.add_comment(text=f"Error getting disks info: {result}")
return StepStatus.Failure

devices_info_str: str = result["output"]
Expand Down Expand Up @@ -264,7 +263,6 @@ def mount_volume_to_instance(self) -> StepStatus: # noqa: C901

mount_response = self.ansible_run(f"mount {disk_partition_to_mount} {self.mount_point}")
if mount_response["status"] != "Success":
self.add_comment(text=f"Error mounting disk: {mount_response}")
return StepStatus.Failure
return StepStatus.Success

Expand Down Expand Up @@ -337,7 +335,6 @@ def detach_volume_from_instance(self) -> StepStatus:
if not self.volume or self.get_step_status(self.attach_volume_to_instance) != "Success":
return StepStatus.Success
state = self.virtual_machine.get_state_of_volume(self.volume)
self.add_comment(text=f"Volume state: {state}")
if state != "in-use":
return StepStatus.Success
self.virtual_machine.detach(self.volume)
Expand Down Expand Up @@ -517,7 +514,8 @@ def get_step_by_method(self, method_name) -> PhysicalBackupRestorationStep | Non
def ansible_run(self, command):
inventory = f"{self.virtual_machine.public_ip_address},"
result = AnsibleAdHoc(sources=inventory).run(command, self.name)[0]
self.add_command(command, result)
if result["status"] != "Success":
self.add_command(command, result)
return result

def add_command(self, command, result):
Expand Down

0 comments on commit ee45d31

Please sign in to comment.