Skip to content

Commit

Permalink
Merge pull request #190 from google/zone_project_empty_fix
Browse files Browse the repository at this point in the history
Correctly error if the project name or zone name is unset
  • Loading branch information
Obliviour authored Sep 30, 2023
2 parents 02a2f64 + ecbc0f0 commit 31ee358
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions multihost_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
def get_project():
completed_command = subprocess.run(["gcloud", "config", "get", "project"], check=True, capture_output=True)
project_outputs = completed_command.stdout.decode().strip().split('\n')
if len(project_outputs) < 1:
if len(project_outputs) < 1 or project_outputs[-1]=='':
sys.exit("You must specify the project in the PROJECT flag or set it with 'gcloud config set project <project>'")
return project_outputs[-1] # The project name lives on the last line of the output

def get_zone():
completed_command = subprocess.run(["gcloud", "config", "get", "compute/zone"], check=True, capture_output=True)
zone_outputs = completed_command.stdout.decode().strip().split('\n')
if len(zone_outputs) < 1:
if len(zone_outputs) < 1 or zone_outputs[-1]=='':
sys.exit("You must specify the zone in the ZONE flag or set it with 'gcloud config set compute/zone <zone>'")
return zone_outputs[-1] # The zone name lives on the last line of the output

Expand Down
4 changes: 2 additions & 2 deletions xpk/xpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def get_project():
['gcloud', 'config', 'get', 'project'], check=True, capture_output=True
)
project_outputs = completed_command.stdout.decode().strip().split('\n')
if len(project_outputs) < 1:
if len(project_outputs) < 1 or project_outputs[-1] == '':
sys.exit(
'You must specify the project in the project flag or set it with'
" 'gcloud config set project <project>'"
Expand All @@ -599,7 +599,7 @@ def get_zone():
capture_output=True,
)
zone_outputs = completed_command.stdout.decode().strip().split('\n')
if len(zone_outputs) < 1:
if len(zone_outputs) < 1 or zone_outputs[-1] == '':
sys.exit(
"You must specify the zone in the zone flag or set it with 'gcloud"
" config set compute/zone <zone>'"
Expand Down

0 comments on commit 31ee358

Please sign in to comment.