Skip to content

Commit 0f093c1

Browse files
authored
Logging: Fix logging system tests (#4768)
1 parent f337498 commit 0f093c1

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

nox.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ def system(session, py):
113113
'-vvv',
114114
'-s',
115115
'tests/system',
116-
*session.posargs,
117-
# Currently allowed to fail due to very high flakiness.
118-
success_codes=range(0, 100)
119-
)
116+
*session.posargs)
120117

121118

122119
@nox.session

tests/system/gapic/v2/test_system_logging_service_v2_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import time
1717

18+
import google.auth
1819
from google.api import monitored_resource_pb2
1920
from google.cloud import logging_v2
2021
from google.cloud.logging_v2.proto import log_entry_pb2
@@ -23,7 +24,7 @@
2324

2425
class TestSystemLoggingServiceV2(object):
2526
def test_write_log_entries(self):
26-
project_id = os.environ['PROJECT_ID']
27+
_, project_id = google.auth.default()
2728

2829
client = logging_v2.LoggingServiceV2Client()
2930
log_name = client.log_path(project_id, 'test-{0}'.format(time.time()))

tests/system/test_system.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def setUp(self):
103103
def tearDown(self):
104104
retry = RetryErrors(NotFound, max_tries=9)
105105
for doomed in self.to_delete:
106-
retry(doomed.delete)()
106+
try:
107+
retry(doomed.delete)()
108+
except AttributeError:
109+
client, dataset = doomed
110+
retry(client.delete_dataset)(dataset)
107111
logging.getLogger().handlers = self._handlers_cache[:]
108112

109113
@staticmethod
@@ -427,25 +431,24 @@ def test_create_sink_pubsub_topic(self):
427431

428432
def _init_bigquery_dataset(self):
429433
from google.cloud import bigquery
430-
from google.cloud.bigquery.dataset import AccessGrant
431-
DATASET_NAME = (
434+
from google.cloud.bigquery.dataset import AccessEntry
435+
dataset_name = (
432436
'system_testing_dataset' + _RESOURCE_ID).replace('-', '_')
433-
DATASET_URI = 'bigquery.googleapis.com/projects/%s/datasets/%s' % (
434-
Config.CLIENT.project, DATASET_NAME,)
437+
dataset_uri = 'bigquery.googleapis.com/projects/%s/datasets/%s' % (
438+
Config.CLIENT.project, dataset_name,)
435439

436440
# Create the destination dataset, and set up the ACL to allow
437441
# Stackdriver Logging to write into it.
438442
bigquery_client = bigquery.Client()
439-
dataset = bigquery_client.dataset(DATASET_NAME)
440-
dataset.create()
441-
self.to_delete.append(dataset)
442-
dataset.reload()
443-
grants = dataset.access_grants
444-
grants.append(AccessGrant(
445-
'WRITER', 'groupByEmail', '[email protected]'))
446-
dataset.access_grants = grants
447-
dataset.update()
448-
return DATASET_URI
443+
dataset_ref = bigquery_client.dataset(dataset_name)
444+
dataset = bigquery_client.create_dataset(bigquery.Dataset(dataset_ref))
445+
self.to_delete.append((bigquery_client, dataset))
446+
bigquery_client.get_dataset(dataset)
447+
access = AccessEntry(
448+
'WRITER', 'groupByEmail', '[email protected]')
449+
dataset.access_entries.append(access)
450+
bigquery_client.update_dataset(dataset, ['access_entries'])
451+
return dataset_uri
449452

450453
def test_create_sink_bigquery_dataset(self):
451454
SINK_NAME = 'test-create-sink-dataset%s' % (_RESOURCE_ID,)

0 commit comments

Comments
 (0)