8000 Merge branch 'master' into storagefix · coreyhu/python-docs-samples@4aad27a · GitHub
[go: up one dir, main page]

Skip to content

Commit 4aad27a

Browse files
authored
Merge branch 'master' into storagefix
2 parents 5a43509 + 56a6b16 commit 4aad27a

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

compute/api/create_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
# [START list_instances]
3636
def list_instances(compute, project, zone):
3737
result = compute.instances().list(project=project, zone=zone).execute()
38-
return result['items']
38+
return result['items'] if 'items' in result else None
3939
# [END list_instances]
4040

4141

4242
# [START create_instance]
4343
def create_instance(compute, project, zone, name, bucket):
4444
# Get the latest Debian Jessie image.
4545
image_response = compute.images().getFromFamily(
46-
project='debian-cloud', family='debian-8').execute()
46+
project='debian-cloud', family='debian-9').execute()
4747
source_disk_image = image_response['selfLink']
4848

4949
# Configure the machine

dns/api/main_test.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from gcp_devrel.testing.flaky import flaky
1717
from google.cloud import dns
18+
from google.cloud.exceptions import NotFound
19+
1820
import pytest
1921

2022
import main
@@ -33,7 +35,10 @@ def client():
3335

3436
# Delete anything created during the test.
3537
for zone in client.list_zones():
36-
zone.delete()
38+
try:
39+
zone.delete()
40+
except NotFound: # May have been in process
41+
pass
3742

3843

3944
@pytest.yield_fixture
@@ -45,7 +50,10 @@ def zone(client):
4550
yield zone
4651

4752
if zone.exists():
48-
zone.delete()
53+
try:
54+
zone.delete()
55+
except NotFound: # May have been under way
56+
pass
4957

5058

5159
@flaky
@@ -77,11 +85,6 @@ def test_list_zones(client, zone):
7785
assert TEST_ZONE_NAME in zones
7886

7987

80-
@flaky
81-
def test_delete_zone(client, zone):
82-
main.delete_zone(PROJECT, TEST_ZONE_NAME)
83-
84-
8588
@flaky
8689
def test_list_resource_records(client, zone):
8790
records = main.list_resource_records(PROJECT, TEST_ZONE_NAME)
@@ -94,3 +97,8 @@ def test_list_changes(client, zone):
9497
changes = main.list_changes(PROJECT, TEST_ZONE_NAME)
9598

9699
assert changes
100+
101+
102+
@flaky
103+
def test_delete_zone(client, zone):
104+
main.delete_zone(PROJECT, TEST_ZONE_NAME)

language/automl/predict_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def test_predict(capsys):
26-
model_id = "3472481026502981088"
26+
model_id = "TCN3472481026502981088"
2727
automl_natural_language_predict.predict(
2828
project_id, compute_region, model_id, "resources/test.txt"
2929
)

monitoring/api/v3/cloud-client/snippets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
import argparse
1616
import os
1717
import pprint
18+
import random
1819
import time
1920

2021
from google.cloud import monitoring_v3
2122

2223

24+
# Avoid collisions with other runs
25+
RANDOM_SUFFIX = str(random.randint(1000, 9999))
26+
27+
2328
def create_metric_descriptor(project_id):
2429
# [START monitoring_create_metric]
2530
client = monitoring_v3.MetricServiceClient()
2631
project_name = client.project_path(project_id)
2732
descriptor = monitoring_v3.types.MetricDescriptor()
28-
descriptor.type = 'custom.googleapis.com/my_metric'
33+
descriptor.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX
2934
descriptor.metric_kind = (
3035
monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE)
3136
descriptor.value_type = (
@@ -50,7 +55,7 @@ def write_time_series(project_id):
5055
project_name = client.project_path(project_id)
5156

5257
series = monitoring_v3.types.TimeSeries()
53-
series.metric.type = 'custom.googleapis.com/my_metric'
58+
series.metric.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX
5459
series.resource.type = 'gce_instance'
5560
series.resource.labels['instance_id'] = '1234567890123456789'
5661
series.resource.labels['zone'] = 'us-central1-f'

translate/automl/predict_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def test_predict(capsys):
26-
model_id = "3128559826197068699"
26+
model_id = "TRL3128559826197068699"
2727
automl_translation_predict.predict(
2828
project_id, compute_region, model_id, "resources/input.txt"
2929
)

vision/automl/predict_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def test_predict(capsys):
26-
model_id = "7383667271543079510"
26+
model_id = "ICN7383667271543079510"
2727
automl_vision_predict.predict(
2828
project_id, compute_region, model_id, "resources/test.png"
2929
)

0 commit comments

Comments
 (0)
0