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

[kms] fix flaky test #3268

Merged
merged 16 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
2 changes: 2 additions & 0 deletions kms/api-client/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pytest==5.3.2
gcp-devrel-py-tools==0.0.15
google-cloud-core
48 changes: 29 additions & 19 deletions kms/api-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import time
from os import environ

from google.api_core.exceptions import GoogleAPICallError
from google.api_core.exceptions import Aborted, GoogleAPICallError
from google.cloud import kms_v1
from google.cloud.kms_v1 import enums
from google.iam.v1.policy_pb2 import Policy
Expand All @@ -25,6 +25,8 @@

import snippets

from gcp_devrel.testing import eventually_consistent


def create_key_helper(key_id, purpose, algorithm, t):
try:
Expand Down Expand Up @@ -177,31 +179,39 @@ def test_key_policy(self):
self.symId,
self.member,
self.role)
policy = snippets.get_crypto_key_policy(self.project_id,
self.location,
self.keyring_id,
self.symId)
found = False
for b in list(policy.bindings):
if b.role == self.role and self.member in b.members:
found = True
assert found

def check_policy():
policy = snippets.get_crypto_key_policy(self.project_id,
daniel-sanche marked this conversation as resolved.
Show resolved Hide resolved
self.location,
self.keyring_id,
self.symId)
found = False
for b in list(policy.bindings):
if b.role == self.role and self.member in b.members:
found = True
assert found
eventually_consistent.call(check_policy,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the decorator form doesn't work with the current 0.0.15 release.
See: GoogleCloudPlatform/python-repo-tools#25

I'm trying to make a new release of the above module.

I'm fine with the current form :)

exceptions=[Aborted, AssertionError])
daniel-sanche marked this conversation as resolved.
Show resolved Hide resolved
# remove member
snippets.remove_member_from_crypto_key_policy(self.project_id,
self.location,
self.keyring_id,
self.symId,
self.member,
self.role)
policy = snippets.get_crypto_key_policy(self.project_id,
self.location,
self.keyring_id,
self.symId)
found = False
for b in list(policy.bindings):
if b.role == self.role and self.member in b.members:
found = True
assert not found

def check_policy():
policy = snippets.get_crypto_key_policy(self.project_id,
daniel-sanche marked this conversation as resolved.
Show resolved Hide resolved
self.location,
self.keyring_id,
self.symId)
found = False
for b in list(policy.bindings):
if b.role == self.role and self.member in b.members:
found = True
assert not found
eventually_consistent.call(check_policy,
exceptions=[Aborted, AssertionError])
daniel-sanche marked this conversation as resolved.
Show resolved Hide resolved

def test_symmetric_encrypt_decrypt(self):
cipher_bytes = snippets.encrypt_symmetric(self.project_id,
Expand Down