Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stale test registries to avoid reaching limits #2159

Merged
merged 4 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes broken style
  • Loading branch information
gguuss committed May 15, 2019
commit ec3ebf2af1cc2e3098844f8f609dd8fccbc8a37c
42 changes: 21 additions & 21 deletions iot/api-client/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ def create_device(

client = get_client(service_account_json)
registry_path = 'projects/{}/locations/{}/registries/{}'.format(
project_id, cloud_region, registry_id)
project_id, cloud_region, registry_id)

devices = client.projects().locations().registries().devices(
).list(
parent=registry_path, fieldMask='config,gatewayConfig'
).execute().get('devices', [])
).list(
parent=registry_path, fieldMask='config,gatewayConfig'
).execute().get('devices', [])

for device in devices:
if device.get('id') == device_id:
exists = True
if device.get('id') == device_id:
exists = True

# Create the device
registry_name = 'projects/{}/locations/{}/registries/{}'.format(
Expand Down Expand Up @@ -295,9 +295,9 @@ def list_devices(
).list(parent=registry_path).execute().get('devices', [])

for device in devices:
print('Device: {} : {}'.format(
device.get('numId'),
device.get('id')))
print('Device: {} : {}'.format(
device.get('numId'),
device.get('id')))

return devices
# [END iot_list_devices]
Expand All @@ -314,9 +314,9 @@ def list_registries(service_account_json, project_id, cloud_region):
parent=registry_path).execute().get('deviceRegistries', [])

for registry in registries:
print('id: {}\n\tname: {}'.format(
registry.get('id'),
registry.get('name')))
print('id: {}\n\tname: {}'.format(
registry.get('id'),
registry.get('name')))

return registries
# [END iot_list_registries]
Expand Down Expand Up @@ -375,7 +375,7 @@ def open_registry(
service_account_json, project_id, cloud_region,
pubsub_topic, registry_id)

if (response is ""):
if response == "":
# Device registry already exists
print(
'Registry {} already exists - looking it up instead.'.format(
Expand Down Expand Up @@ -572,14 +572,14 @@ def create_gateway(
).execute().get('devices', [])

for device in devices:
if device.get('id') == gateway_id:
exists = True
print('Device: {} : {} : {} : {}'.format(
device.get('id'),
device.get('numId'),
device.get('config'),
device.get('gatewayConfig')
))
if device.get('id') == gateway_id:
exists = True
print('Device: {} : {} : {} : {}'.format(
device.get('id'),
device.get('numId'),
device.get('config'),
device.get('gatewayConfig')
))

# Create the gateway
registry_name = 'projects/{}/locations/{}/registries/{}'.format(
Expand Down
8 changes: 4 additions & 4 deletions iot/api-client/manager/manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def clean_up_registries():
for registry in all_registries:
registry_id = registry.get('id')
if registry_id.find('test-registry-') == 0:
time_str =
registry_id[registry_id.rfind('-') + 1: len(registry_id)]
time_str = registry_id[
registry_id.rfind('-') + 1: len(registry_id)]
test_date = datetime.datetime.utcfromtimestamp(int(time_str))
now_date = datetime.datetime.utcfromtimestamp(int(time.time()))
difftime = now_date - test_date

# *NOTE* Restrict to registries used in the tests older than 30
# *NOTE* Restrict to registries used in the tests older than 30
# days to prevent thrashing in the case of async tests
if (difftime.days > 30):
client = manager.get_client(service_account_json)
Expand Down Expand Up @@ -101,7 +101,7 @@ def clean_up_registries():
try:
client.projects().locations().registries().devices(
).get(name=device_name).execute()
except:
except Exception:
remove_device = False

if remove_device:
Expand Down