コード例 #1
0
    def test_no_project(self):
        def get_instance_group_manager(*args, **kwargs):
            self.fail('get_instance_group_manager called')

        def resize_managed_instance_group(*args, **kwargs):
            self.fail('resize_managed_instance_group called')

        self.mock(
            instance_group_managers.gce.Project,
            'get_instance_group_manager',
            get_instance_group_manager,
        )
        self.mock(
            instance_group_managers.gce.Project,
            'resize_managed_instance_group',
            resize_managed_instance_group,
        )

        key = models.InstanceGroupManager(
            key=instance_group_managers.get_instance_group_manager_key(
                'base-name',
                'revision',
                'zone',
            ),
            minimum_size=10,
            maximum_size=10,
            url='https://example.com',
        ).put()
        models.InstanceTemplateRevision(key=key.parent(), ).put()
        models.InstanceTemplate(key=key.parent().parent()).put()

        instance_group_managers.resize(key)
コード例 #2
0
    def post(self):
        """Resizes the instance group managed by the given InstanceGroupManager.

    Params:
      key: URL-safe key for a models.InstanceGroupManager.
    """
        key = ndb.Key(urlsafe=self.request.get('key'))
        assert key.kind() == 'InstanceGroupManager', key
        instance_group_managers.resize(key)
コード例 #3
0
  def post(self):
    """Resizes the instance group managed by the given InstanceGroupManager.

    Params:
      key: URL-safe key for a models.InstanceGroupManager.
    """
    key = ndb.Key(urlsafe=self.request.get('key'))
    assert key.kind() == 'InstanceGroupManager', key
    instance_group_managers.resize(key)
コード例 #4
0
    def test_resize_other_revisions_created(self):
        def get_instance_group_manager(*args, **kwargs):
            return {
                'currentActions': {
                    'none': 0,
                },
                'name': 'name',
                'targetSize': 0,
            }

        def resize_managed_instance_group(_, name, zone, size):
            self.assertEqual(name, 'name')
            self.assertEqual(zone, 'zone')
            self.assertEqual(size, 4)

        self.mock(
            instance_group_managers.gce.Project,
            'get_instance_group_manager',
            get_instance_group_manager,
        )
        self.mock(
            instance_group_managers.gce.Project,
            'resize_managed_instance_group',
            resize_managed_instance_group,
        )

        key = models.InstanceGroupManager(
            key=instance_group_managers.get_instance_group_manager_key(
                'base-name',
                'revision-1',
                'zone',
            ),
            minimum_size=7,
            maximum_size=7,
            url='https://example.com',
        ).put()
        models.InstanceGroupManager(
            key=instance_group_managers.get_instance_group_manager_key(
                'base-name',
                'revision-2',
                'zone',
            ),
            instances=[
                ndb.Key(models.Instance, 'instance-name-1'),
                ndb.Key(models.Instance, 'instance-name-2'),
                ndb.Key(models.Instance, 'instance-name-3'),
            ],
        ).put()
        models.InstanceTemplateRevision(
            key=key.parent(),
            project='fake-project',
        ).put()
        models.InstanceTemplate(key=key.parent().parent()).put()

        instance_group_managers.resize(key)
コード例 #5
0
    def test_resize_excess_created(self):
        def get_instance_group_manager(*args, **kwargs):
            return {
                'currentActions': {
                    'none': 2,
                },
                'name': 'name',
                'targetSize': 2,
            }

        def resize_managed_instance_group(_, name, zone, size):
            self.failIf(True)

        self.mock(
            instance_group_managers.gce.Project,
            'get_instance_group_manager',
            get_instance_group_manager,
        )
        self.mock(
            instance_group_managers.gce.Project,
            'resize_managed_instance_group',
            resize_managed_instance_group,
        )

        key = models.InstanceGroupManager(
            key=instance_group_managers.get_instance_group_manager_key(
                'base-name',
                'revision',
                'zone',
            ),
            minimum_size=1,
            maximum_size=1,
            url='https://example.com',
        ).put()
        models.InstanceTemplateRevision(
            key=key.parent(),
            project='fake-project',
        ).put()
        models.InstanceTemplate(key=key.parent().parent()).put()

        instance_group_managers.resize(key)
コード例 #6
0
    def test_resize_some_created(self):
        def get_instance_group_manager(*args, **kwargs):
            return {
                'currentActions': {
                    'none': 3,
                },
                'name': 'name',
            }

        def resize_managed_instance_group(_, name, zone, size):
            self.assertEqual(name, 'name')
            self.assertEqual(zone, 'zone')
            self.assertEqual(size, 103)

        self.mock(
            instance_group_managers.gce.Project,
            'get_instance_group_manager',
            get_instance_group_manager,
        )
        self.mock(
            instance_group_managers.gce.Project,
            'resize_managed_instance_group',
            resize_managed_instance_group,
        )

        key = models.InstanceGroupManager(
            key=instance_group_managers.get_instance_group_manager_key(
                'base-name',
                'revision',
                'zone',
            ),
            minimum_size=1000,
            url='https://example.com',
        ).put()
        models.InstanceTemplateRevision(
            key=key.parent(),
            project='fake-project',
        ).put()
        models.InstanceTemplate(key=key.parent().parent()).put()

        instance_group_managers.resize(key)
コード例 #7
0
    def test_entity_doesnt_exist(self):
        def get_instance_group_manager(*args, **kwargs):
            self.fail('get_instance_group_manager called')

        def resize_managed_instance_group(*args, **kwargs):
            self.fail('resize_managed_instance_group called')

        self.mock(
            instance_group_managers.gce.Project,
            'get_instance_group_manager',
            get_instance_group_manager,
        )
        self.mock(
            instance_group_managers.gce.Project,
            'resize_managed_instance_group',
            resize_managed_instance_group,
        )

        key = ndb.Key(models.InstanceGroupManager, 'fake-key')
        instance_group_managers.resize(key)
        self.failIf(key.get())