|
21 | 21 | from gcloud import logging |
22 | 22 |
|
23 | 23 |
|
24 | | -DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (1000 * time.time(),) |
25 | | -DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (1000 * time.time(),) |
| 24 | +_MILLIS = 1000 * time.time() |
| 25 | +DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (_MILLIS,) |
| 26 | +DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_MILLIS,) |
| 27 | +DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_MILLIS,) |
26 | 28 | DEFAULT_FILTER = 'logName:syslog AND severity>=INFO' |
27 | 29 | DEFAULT_DESCRIPTION = 'System testing' |
| 30 | +BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,) |
28 | 31 |
|
29 | 32 |
|
30 | 33 | class Config(object): |
@@ -123,3 +126,25 @@ def test_update_metric(self): |
123 | 126 | after = after_info[DEFAULT_METRIC_NAME] |
124 | 127 | self.assertEqual(after.filter_, NEW_FILTER) |
125 | 128 | self.assertEqual(after.description, NEW_DESCRIPTION) |
| 129 | + |
| 130 | + def test_create_sink_storage_bucket(self): |
| 131 | + from gcloud import storage |
| 132 | + BUCKET_URI = 'storage.googleapis.com/%s' % (BUCKET_NAME,) |
| 133 | + |
| 134 | + # Create the destination bucket, and set up the ACL to allow |
| 135 | + # Cloud Logging to write into it. |
| 136 | + storage_client = storage.Client() |
| 137 | + bucket = storage_client.create_bucket(BUCKET_NAME) |
| 138 | + self.to_delete.append(bucket) |
| 139 | + bucket.acl.reload() |
| 140 | + logs_group = bucket.acl.group('cloud-logs@google.com') |
| 141 | + logs_group.grant_owner() |
| 142 | + bucket.acl.add_entity(logs_group) |
| 143 | + bucket.acl.save() |
| 144 | + |
| 145 | + sink = Config.CLIENT.sink( |
| 146 | + DEFAULT_SINK_NAME, DEFAULT_FILTER, BUCKET_URI) |
| 147 | + self.assertFalse(sink.exists()) |
| 148 | + sink.create() |
| 149 | + self.to_delete.append(sink) |
| 150 | + self.assertTrue(sink.exists()) |
0 commit comments