def test_subscribed(self): """Ensures subscribed instance has pending metadata update.""" key = models.Instance( key=instances.get_instance_key( 'base-name', 'revision', 'zone', 'instance-name', ), ).put() models.InstanceGroupManager( key=key.parent(), ).put() models.InstanceTemplateRevision( key=key.parent().parent(), service_accounts=[ models.ServiceAccount( name='name', scopes=[ 'scope', ], ), ], ).put() message = { 'ackId': 'id', 'message': { 'attributes': { 'key': key.urlsafe(), 'subscription': 'subscription', 'subscription_project': 'subscription-project', }, 'data': base64.b64encode('SUBSCRIBED'), }, } expected_pending_metadata_updates = [ models.MetadataUpdate( metadata={ 'pubsub_service_account': 'name', 'pubsub_subscription': 'subscription', 'pubsub_subscription_project': 'subscription-project', }, ) ] pubsub.process(message).wait() self.assertEqual( key.get().pending_metadata_updates, expected_pending_metadata_updates)
def test_reclaimed(self): """Ensures reclaimed instance is marked for deletion.""" key = models.Instance( key=instances.get_instance_key( 'base-name', 'revision', 'zone', 'instance-name', ), ).put() message = { 'ackId': 'id', 'message': { 'attributes': { 'key': key.urlsafe(), }, 'data': base64.b64encode('RECLAIMED'), }, } pubsub.process(message).wait() self.failUnless(key.get().pending_deletion)
def test_leased(self): """Ensures nothing happens when an instance is leased.""" key = models.Instance( key=instances.get_instance_key( 'base-name', 'revision', 'zone', 'instance-name', ), ).put() message = { 'ackId': 'id', 'message': { 'attributes': { 'key': key.urlsafe(), }, 'data': base64.b64encode('LEASED'), }, } pubsub.process(message).wait() self.failUnless(key.get())
def test_unexpected_key(self): """Ensures nothing happens when key has unexpected kind.""" key = models.Instance( key=instances.get_instance_key( 'base-name', 'revision', 'zone', 'instance-name', ), ).put() models.InstanceGroupManager( key=key.parent(), ).put() models.InstanceTemplateRevision( key=key.parent().parent(), service_accounts=[ models.ServiceAccount( name='name', scopes=[ 'scope', ], ), ], ).put() message = { 'ackId': 'id', 'message': { 'attributes': { 'key': key.parent().urlsafe(), 'subscription': 'subscription', 'subscription_project': 'subscription-project', }, 'data': base64.b64encode('SUBSCRIBED'), }, } pubsub.process(message).wait() self.failIf(key.get().pending_metadata_updates)