Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
1. Catch File not found scenario for when gcloud is not found during template generation
2. refactor old code out of EndStep.
fix: 342337332

Change-Id: I4e364c2c9c7f22c41c556096b61964317fb30776
GitOrigin-RevId: f8b7b7b76f470c23825e364806a447b45a7c0558
  • Loading branch information
ebenezergraham authored and Copybara-Service committed Jun 14, 2024
1 parent 847b7ef commit e2919f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 5 additions & 3 deletions bin/runbook-starter-code-generator
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SUPPORTED_PRODUCTS = {


def _get_active_gcloud_project():
"""Best effort check to retrieve the project id currently configured on gcloud."""
try:
# Run the gcloud command to get the current project
result = subprocess.run(['gcloud', 'config', 'get-value', 'project'],
Expand All @@ -26,8 +27,8 @@ def _get_active_gcloud_project():
stderr=subprocess.PIPE,
text=True)
project_id = result.stdout.strip()
except subprocess.CalledProcessError:
pass
except (subprocess.CalledProcessError, OSError, FileNotFoundError):
return None
else:
print(
f'Found project {_color(project_id,"blue")}; will use it arg for `--project`'
Expand Down Expand Up @@ -67,6 +68,8 @@ def _git_operations(runbook_name):
except subprocess.CalledProcessError as e:
print('An error occurred during git operations:')
print(e)
except OSError:
pass


def _get_current_branch():
Expand Down Expand Up @@ -253,7 +256,6 @@ def gen_starter_code(args_: dict):
output_file.write(
textwrap.dedent(f'''\
# pylint: disable=unused-wildcard-import, wildcard-import
from gcpdiag.runbook.gcp.{file} import *
from gcpdiag.runbook.iam.{file} import *
'''))
print('Ok!')
Expand Down
13 changes: 8 additions & 5 deletions gcpdiag/runbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class StartStep(Step):
def __init__(self):
super().__init__(step_type=constants.StepType.START)

def execute(self):
"""Executing default start step for runbooks..."""
pass


class CompositeStep(Step):
"""Composite Events of a Diagnostic tree"""
Expand All @@ -202,11 +206,10 @@ def __init__(self):
def execute(self):
"""Finalizing runbook investigations..."""
if not config.get(flags.INTERACTIVE_MODE):
response = self.interface.prompt(task=self.interface.CONFIRMATION,
message='Is your issue resolved?')
if response == self.interface.NO:
self.interface.prompt(kind=op.CONFIRMATION,
message=constants.END_MESSAGE)
response = op.operator.interface.prompt(kind=op.CONFIRMATION,
message='Is your issue resolved?')
if response == op.NO:
op.operator.interface.info(message=constants.END_MESSAGE)


class Gateway(Step):
Expand Down

0 comments on commit e2919f4

Please sign in to comment.