Skip to content

Commit db69e4e

Browse files
Cleanup bigtable python examples [(#2692)](GoogleCloudPlatform/python-docs-samples#2692)
* Cleanup bigtable python: Use new row types for mutations Update bigtable version in requirements Delete table after tests * Change bigtable cluster variable to bigtable instance for consistency Create and delete quickstart table during test * Fixing step size for metric scaler Create unique tables for quickstart tests * Creating fixtures for quickstart tests Fixing hb quickstart test output * Fix quickstart extra delete table Update happybase to use direct row * Use clearer instance names for tests Create unique instances for metric scaler tests * Linting * remove core dep Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
1 parent 38cc39f commit db69e4e

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

samples/metricscaler/metricscaler_test.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,25 @@
1717
import os
1818
import time
1919

20+
import random
21+
22+
import pytest
2023
from google.cloud import bigtable
24+
from google.cloud.bigtable import enums
2125
from mock import patch
2226

2327
from metricscaler import get_cpu_load
2428
from metricscaler import main
2529
from metricscaler import scale_bigtable
2630

27-
# tests assume instance and cluster have the same ID
28-
BIGTABLE_INSTANCE = os.environ['BIGTABLE_CLUSTER']
31+
PROJECT = os.environ['GCLOUD_PROJECT']
32+
BIGTABLE_ZONE = os.environ['BIGTABLE_ZONE']
2933
SIZE_CHANGE_STEP = 3
34+
INSTANCE_ID_FORMAT = 'metric-scale-test-{}'
35+
INSTANCE_ID_RANGE = 10000
36+
BIGTABLE_INSTANCE = INSTANCE_ID_FORMAT.format(
37+
random.randrange(INSTANCE_ID_RANGE))
38+
3039

3140
# System tests to verify API calls succeed
3241

@@ -35,8 +44,33 @@ def test_get_cpu_load():
3544
assert float(get_cpu_load()) > 0.0
3645

3746

38-
def test_scale_bigtable():
47+
@pytest.fixture()
48+
def instance():
49+
cluster_id = BIGTABLE_INSTANCE
50+
51+
client = bigtable.Client(project=PROJECT, admin=True)
52+
53+
serve_nodes = 3
54+
storage_type = enums.StorageType.SSD
55+
production = enums.Instance.Type.PRODUCTION
56+
labels = {'prod-label': 'prod-label'}
57+
instance = client.instance(BIGTABLE_INSTANCE, instance_type=production,
58+
labels=labels)
59+
60+
if not instance.exists():
61+
cluster = instance.cluster(cluster_id, location_id=BIGTABLE_ZONE,
62+
serve_nodes=serve_nodes,
63+
default_storage_type=storage_type)
64+
instance.create(clusters=[cluster])
65+
66+
yield
67+
68+
instance.delete()
69+
70+
71+
def test_scale_bigtable(instance):
3972
bigtable_client = bigtable.Client(admin=True)
73+
4074
instance = bigtable_client.instance(BIGTABLE_INSTANCE)
4175
instance.reload()
4276

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-cloud-bigtable==1.2.0
1+
google-cloud-bigtable==1.2.1
22
google-cloud-monitoring==0.34.0

0 commit comments

Comments
 (0)