Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Pick a random zone for CLI tests. (#2004)
Browse files Browse the repository at this point in the history
This changes the CLI end-to-end test so that it defaults to
picking a random zone in the region 'us-west' instead of being
hard-coded to 'us-west1-a'.

The test will still honor the 'zone' config setting in gcloud if
it is set; this only changes the behavior when that is not set.
  • Loading branch information
ojarjur authored May 8, 2018
1 parent 4fc289b commit 57c55d3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/cli/tests/end-to-end.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# of the bundled CLI tool. This requires a GCP project in which the
# test will create, connect to, and delete Datalab instances.

import random
import socket
import subprocess
import sys
Expand Down Expand Up @@ -58,6 +59,15 @@ def free_port():
return port_number


def random_zone():
zones_list = subprocess.check_output([
'gcloud', 'compute', 'zones', 'list',
'--filter=region~us-west', '--format=value(name)']).decode(
'utf-8')
zones = zones_list.split()
return random.choice(zones)


class DatalabInstance(object):
def __init__(self, test_run_id, project, zone):
self.project = project
Expand Down Expand Up @@ -154,7 +164,7 @@ def setUp(self):
self.zone = call_gcloud(
['config', 'get-value', 'compute/zone']).strip()
if self.zone == '':
self.zone = 'us-west1-a'
self.zone = random_zone()
print('Testing with in the zone {} under the project {}'.format(
self.zone, self.project))

Expand Down

0 comments on commit 57c55d3

Please sign in to comment.