예제 #1
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        store = MockScalingGroupCollection()
        set_store(store)
        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self.config = config()[1]
        self.config['minEntities'] = 0
        self.active_pending_etc = ({}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self,
                                     'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        def _mock_obey_config_change(log, trans, config, group, state):
            return defer.succeed(
                GroupState(state.tenant_id, state.group_id,
                           *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change
예제 #2
0
    def setUp(self):
        """
        Set the Cassandra store, and also patch the controller
        """
        keyspace.resume()
        self.root = Otter(store, 'ord').app.resource()
        set_config_data(limits)
        self.addCleanup(set_config_data, {})

        self.config = config()[0]
        self.config['minEntities'] = 0
        self.active_pending_etc = (self.config['name'], {}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self, 'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        # Patch supervisor
        supervisor = mock.Mock(spec=['validate_launch_config'])
        supervisor.validate_launch_config.return_value = defer.succeed(None)
        set_supervisor(supervisor)

        def _mock_obey_config_change(log, trans, config, group, state,
                                     launch_config):
            return defer.succeed(GroupState(
                state.tenant_id, state.group_id, *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change

        store.kz_client = mock.Mock(Lock=self.mock_lock())
예제 #3
0
    def setUp(self):
        """
        Set the Cassandra store, and also patch the controller
        """
        keyspace.resume()
        set_store(store)
        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self.config = config()[0]
        self.config['minEntities'] = 0
        self.active_pending_etc = ({}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self, 'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        def _mock_obey_config_change(log, trans, config, group, state):
            return defer.succeed(GroupState(
                state.tenant_id, state.group_id, *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change

        self.lock = self.mock_lock()
        patch(self, 'otter.models.cass.BasicLock', return_value=self.lock)
예제 #4
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        store = MockScalingGroupCollection()
        self.mock_log = mock.MagicMock()
        manifest = self.successResultOf(
            store.create_scaling_group(self.mock_log, self.tenant_id,
                                       config()[0],
                                       launch_server_config()[0]))
        self.group_id = manifest['id']
        set_store(store)

        self.policies_url = '/v1.0/{tenant}/groups/{group}/policies/'.format(
            tenant=self.tenant_id, group=self.group_id)

        controller_patcher = mock.patch('otter.rest.policies.controller')
        self.mock_controller = controller_patcher.start()
        self.mock_controller.maybe_execute_scaling_policy.return_value = defer.succeed(
            GroupState(self.tenant_id, self.group_id, {}, {}, 'date', {},
                       False))
        self.addCleanup(controller_patcher.stop)

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})
예제 #5
0
    def setUp(self):
        """
        Set up a silverberg client
        """
        keyspace.resume()
        self.root = Otter(store, 'ord').app.resource()
        store.kz_client = mock.Mock(Lock=self.mock_lock())

        set_config_data(limits)
        self.addCleanup(set_config_data, {})

        self._config = config()[0]
        self._launch = launch_server_config()[0]

        self.mock_controller = patch(self, 'otter.rest.policies.controller')

        def _set_group_id(manifest):
            self.group_id = manifest['state'].group_id
            self.policies_url = (
                '/v1.0/{tenant}/groups/{group}/policies/'.format(
                    tenant=self.tenant_id, group=self.group_id))
            self.mock_controller.maybe_execute_scaling_policy.return_value = defer.succeed(
                GroupState(self.tenant_id, self.group_id,
                           self._config['name'], {}, {}, 'date', {}, False))

        mock_log = mock.MagicMock()
        d = store.create_scaling_group(mock_log, self.tenant_id,
                                       self._config, self._launch)
        d.addCallback(_set_group_id)
        return d
예제 #6
0
    def setUp(self):
        """
        Set up a silverberg client
        """
        keyspace.resume()
        set_store(store)  # ensure it's the cassandra store

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self._config = config()[0]
        self._launch = launch_server_config()[0]

        self.mock_controller = patch(self, 'otter.rest.policies.controller')

        self.lock = self.mock_lock()
        patch(self, 'otter.models.cass.BasicLock', return_value=self.lock)

        def _set_group_id(manifest):
            self.group_id = manifest['id']
            self.policies_url = (
                '/v1.0/{tenant}/groups/{group}/policies/'.format(
                    tenant=self.tenant_id, group=self.group_id))
            self.mock_controller.maybe_execute_scaling_policy.return_value = defer.succeed(
                GroupState(self.tenant_id, self.group_id, {}, {}, 'date', {}, False))

        mock_log = mock.MagicMock()
        d = store.create_scaling_group(mock_log, self.tenant_id,
                                       self._config, self._launch)
        d.addCallback(_set_group_id)
        return d
예제 #7
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        store = MockScalingGroupCollection()
        self.root = Otter(store).app.resource()
        set_config_data({'url_root': 'http://127.0.0.1',
                         'limits': {'pagination': 5}})
        self.addCleanup(set_config_data, {})

        self.config = config()[1]
        self.config['minEntities'] = 0
        self.active_pending_etc = ({}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self, 'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        # Patch supervisor
        supervisor = mock.Mock(spec=['validate_launch_config'])
        supervisor.validate_launch_config.return_value = defer.succeed(None)
        set_supervisor(supervisor)

        def _mock_obey_config_change(log, trans, config, group, state):
            return defer.succeed(GroupState(
                state.tenant_id, state.group_id, state.group_name, *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change
예제 #8
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        store = MockScalingGroupCollection()
        self.mock_log = mock.MagicMock()
        manifest = self.successResultOf(
            store.create_scaling_group(self.mock_log, self.tenant_id, config()[0],
                                       launch_server_config()[0]))
        self.group_id = manifest['state'].group_id
        self.group_name = 'name'

        self.policies_url = '/v1.0/{tenant}/groups/{group}/policies/'.format(
            tenant=self.tenant_id, group=self.group_id)

        controller_patcher = mock.patch('otter.rest.policies.controller')
        self.mock_controller = controller_patcher.start()
        self.mock_controller.maybe_execute_scaling_policy.return_value = defer.succeed(
            GroupState(self.tenant_id, self.group_id, self.group_name, {}, {}, 'date', {}, False))
        self.addCleanup(controller_patcher.stop)

        self.root = Otter(store).app.resource()

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})
예제 #9
0
    def setUp(self):
        """
        Set the Cassandra store, and also patch the controller
        """
        keyspace.resume()
        set_store(store)
        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self.config = config()[0]
        self.config['minEntities'] = 0
        self.active_pending_etc = ({}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self,
                                     'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        def _mock_obey_config_change(log, trans, config, group, state):
            return defer.succeed(
                GroupState(state.tenant_id, state.group_id,
                           *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change

        self.lock = self.mock_lock()
        patch(self, 'otter.models.cass.BasicLock', return_value=self.lock)
예제 #10
0
    def setUp(self):
        """
        Set up a silverberg client
        """
        keyspace.resume()
        set_store(store)  # ensure it's the cassandra store

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self._config = config()[0]
        self._launch = launch_server_config()[0]

        self.mock_controller = patch(self, 'otter.rest.policies.controller')

        self.lock = self.mock_lock()
        patch(self, 'otter.models.cass.BasicLock', return_value=self.lock)

        def _set_group_id(manifest):
            self.group_id = manifest['id']
            self.policies_url = (
                '/v1.0/{tenant}/groups/{group}/policies/'.format(
                    tenant=self.tenant_id, group=self.group_id))
            self.mock_controller.maybe_execute_scaling_policy.return_value = defer.succeed(
                GroupState(self.tenant_id, self.group_id, {}, {}, 'date', {},
                           False))

        mock_log = mock.MagicMock()
        d = store.create_scaling_group(mock_log, self.tenant_id, self._config,
                                       self._launch)
        d.addCallback(_set_group_id)
        return d
예제 #11
0
 def setUp(self):
     """
     Set up a reference to a standard, valid policy, config, and launch
     configs.
     """
     self.policy = group_examples.policy()[0]
     self.config = group_examples.config()[0]
     self.launch = group_examples.launch_server_config()[0]
예제 #12
0
 def setUp(self):
     """
     Set up a reference to a standard, valid policy, config, and launch
     configs.
     """
     self.policy = group_examples.policy()[0]
     self.config = group_examples.config()[0]
     self.launch = group_examples.launch_server_config()[0]
예제 #13
0
파일: test_schemas.py 프로젝트: alex/otter
 def test_wrong_scaling_policy_fails(self):
     """
     An otherwise ok creation blob fails if the provided scaling policies
     are wrong.
     """
     self.assertRaises(
         ValidationError, validate, {
             'groupConfiguration': group_examples.config()[0],
             'launchConfiguration':
             group_examples.launch_server_config()[0],
             'scalingPolicies': {"Hello!": "Yes quite."}
         }, rest_schemas.create_group_request)
예제 #14
0
파일: test_schemas.py 프로젝트: alex/otter
 def test_wrong_launch_config_fails(self):
     """
     Not including a launchConfiguration or including an invalid ones will
     fail to validate.
     """
     invalid = {'groupConfiguration': group_examples.config()[0]}
     self.assertRaisesRegexp(
         ValidationError, 'launchConfiguration',
         validate, invalid, rest_schemas.create_group_request)
     invalid['launchConfiguration'] = {}
     self.assertRaises(ValidationError,
                       validate, invalid, rest_schemas.create_group_request)
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        store = MockScalingGroupCollection()
        set_store(store)
        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})

        self.config = config()[1]
        self.config['minEntities'] = 0
        self.active_pending_etc = ({}, {}, 'date', {}, False)

        # patch both the config and the groups
        self.mock_controller = patch(self, 'otter.rest.configs.controller',
                                     spec=['obey_config_change'])
        patch(self, 'otter.rest.groups.controller', new=self.mock_controller)

        def _mock_obey_config_change(log, trans, config, group, state):
            return defer.succeed(GroupState(
                state.tenant_id, state.group_id, *self.active_pending_etc))

        self.mock_controller.obey_config_change.side_effect = _mock_obey_config_change
예제 #16
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        self.mock_log = mock.MagicMock()
        store = MockScalingGroupCollection()
        manifest = self.successResultOf(
            store.create_scaling_group(self.mock_log, self.tenant_id,
                                       config()[0],
                                       launch_server_config()[0]))
        self.group_id = manifest['state'].group_id
        group = store.get_scaling_group(self.mock_log,
                                        self.tenant_id, self.group_id)
        self.policy_id = self.successResultOf(
            group.create_policies([{
                "name": 'set number of servers to 10',
                "change": 10,
                "cooldown": 3,
                "type": "webhook"
            }]))[0]['id']

        self.webhooks_url = (
            '/v1.0/{tenant}/groups/{group}/policies/{policy}/webhooks/'.format(
                tenant=self.tenant_id, group=self.group_id,
                policy=self.policy_id))

        self.mock_controller = patch(self, 'otter.rest.webhooks.controller')

        def _mock_maybe_execute(log, trans, group, state, policy_id):
            return defer.succeed(state)

        self.mock_controller.maybe_execute_scaling_policy.side_effect = _mock_maybe_execute

        self.root = Otter(store).app.resource()

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})
예제 #17
0
    def setUp(self):
        """
        Replace the store every time with a clean one.
        """
        self.mock_log = mock.MagicMock()
        store = MockScalingGroupCollection()
        manifest = self.successResultOf(
            store.create_scaling_group(self.mock_log, self.tenant_id,
                                       config()[0],
                                       launch_server_config()[0]))
        self.group_id = manifest['id']
        group = store.get_scaling_group(self.mock_log, self.tenant_id,
                                        self.group_id)
        self.policy_id = self.successResultOf(
            group.create_policies([{
                "name": 'set number of servers to 10',
                "change": 10,
                "cooldown": 3,
                "type": "webhook"
            }])).keys()[0]
        set_store(store)

        self.webhooks_url = (
            '/v1.0/{tenant}/groups/{group}/policies/{policy}/webhooks/'.format(
                tenant=self.tenant_id,
                group=self.group_id,
                policy=self.policy_id))

        self.mock_controller = patch(self, 'otter.rest.webhooks.controller')

        def _mock_maybe_execute(log, trans, group, state, policy_id):
            return defer.succeed(state)

        self.mock_controller.maybe_execute_scaling_policy.side_effect = _mock_maybe_execute

        set_config_data({'url_root': 'http://127.0.0.1'})
        self.addCleanup(set_config_data, {})
예제 #18
0
 def test_valid_examples_validate(self):
     """
     The examples in the config examples all validate.
     """
     for example in group_examples.config():
         validate(example, group_schemas.config)
예제 #19
0
 def test_valid_examples_validate(self):
     """
     The examples in the config examples all validate.
     """
     for example in group_examples.config():
         validate(example, group_schemas.config)