Beispiel #1
0
    def test_not_drained(self):
        """Ensures nothing happens when the parent is not drained."""
        def json_request(*args, **kwargs):
            self.fail('json_request called')

        self.mock(cleanup.net, 'json_request', json_request)

        key = instances.get_instance_key(
            'base-name',
            'revision',
            'zone',
            'instance-name',
        )
        key = models.Instance(
            key=key,
            instance_group_manager=instances.get_instance_group_manager_key(
                key),
            url='url',
        ).put()
        models.InstanceGroupManager(
            key=instances.get_instance_group_manager_key(key), ).put()
        models.InstanceTemplateRevision(
            key=instances.get_instance_group_manager_key(
                key).parent(), ).put()
        models.InstanceTemplate(key=instances.get_instance_group_manager_key(
            key).parent().parent(), ).put()

        cleanup.cleanup_drained_instance(key)

        self.failIf(key.get().deleted)
Beispiel #2
0
    def post(self):
        """Removes a drained instance entity.

    Params:
      key: URL-safe key for a models.Instance.
    """
        key = ndb.Key(urlsafe=self.request.get('key'))
        assert key.kind() == 'Instance', key
        cleanup.cleanup_drained_instance(key)
  def post(self):
    """Removes a drained instance entity.

    Params:
      key: URL-safe key for a models.Instance.
    """
    key = ndb.Key(urlsafe=self.request.get('key'))
    assert key.kind() == 'Instance', key
    cleanup.cleanup_drained_instance(key)
Beispiel #4
0
    def test_entity_not_found(self):
        """Ensures nothing happens when the entity is not found."""
        def json_request(*args, **kwargs):
            self.fail('json_request called')

        self.mock(cleanup.net, 'json_request', json_request)

        key = ndb.Key(models.Instance, 'fake-key')

        cleanup.cleanup_drained_instance(key)

        self.failIf(key.get())
Beispiel #5
0
    def test_implicitly_drained(self):
        """Ensures the entity is marked deleted when the grandparent is drained."""
        def json_request(*args, **kwargs):
            raise net.NotFoundError('404', 404, '404')

        def send_machine_event(*args, **kwargs):
            pass

        self.mock(cleanup.net, 'json_request', json_request)
        self.mock(cleanup.metrics, 'send_machine_event', send_machine_event)

        key = instances.get_instance_key(
            'base-name',
            'revision',
            'zone',
            'instance-name',
        )
        key = models.Instance(
            key=key,
            instance_group_manager=instances.get_instance_group_manager_key(
                key),
            url='url',
        ).put()
        models.InstanceGroupManager(
            key=instances.get_instance_group_manager_key(key), ).put()
        models.InstanceTemplateRevision(
            key=instances.get_instance_group_manager_key(
                key).parent(), ).put()
        models.InstanceTemplate(
            key=instances.get_instance_group_manager_key(
                key).parent().parent(),
            drained=[
                instances.get_instance_group_manager_key(key).parent(),
            ],
        ).put()

        cleanup.cleanup_drained_instance(key)

        self.failUnless(key.get().deleted)
Beispiel #6
0
    def test_root_unspecified(self):
        """Ensures nothing happens when the parent doesn't exist."""
        key = instances.get_instance_key(
            'base-name',
            'revision',
            'zone',
            'instance-name',
        )
        key = models.Instance(
            key=key,
            instance_group_manager=instances.get_instance_group_manager_key(
                key),
            url='url',
        ).put()
        models.InstanceGroupManager(
            key=instances.get_instance_group_manager_key(key), ).put()
        models.InstanceTemplateRevision(
            key=instances.get_instance_group_manager_key(
                key).parent(), ).put()

        cleanup.cleanup_drained_instance(key)

        self.failIf(key.get().deleted)