Exemple #1
0
    def alarm(self, request, log):
        """Change the state of an alarm."""
        _policy_id = []

        content = json.loads(request.content.read())
        alarm_id = content.get('alarm').get('id')
        status = content.get('details').get('state')

        d = cass.alter_alarm_state(self._db, alarm_id, status)

        def check_quorum_health((policy_id, server_id)):
            _policy_id.append(policy_id)
            return cass.check_quorum_health(self._db, policy_id)

        d.addCallback(check_quorum_health)

        def maybe_execute_policy(health):
            if health:
                return self._worker.execute_policy(_policy_id[0])
            else:
                defer.succeed(None)

        d.addCallback(maybe_execute_policy)

        def finish(_):
            request.setResponseCode(200)
            request.finish()

        return d.addCallback(finish)
Exemple #2
0
    def alarm(self, request, log):
        """Change the state of an alarm."""
        _policy_id = []

        content = json.loads(request.content.read())
        alarm_id = content.get('alarm').get('id')
        status = content.get('details').get('state')

        d = cass.alter_alarm_state(self._db, alarm_id, status)

        def check_quorum_health((policy_id, server_id)):
            _policy_id.append(policy_id)
            return cass.check_quorum_health(self._db, policy_id)
        d.addCallback(check_quorum_health)

        def maybe_execute_policy(health):
            if health:
                return self._worker.execute_policy(_policy_id[0])
            else:
                defer.succeed(None)
        d.addCallback(maybe_execute_policy)

        def finish(_):
            request.setResponseCode(200)
            request.finish()
        return d.addCallback(finish)
Exemple #3
0
    def test_alter_alarm_state(self):
        """Creates and returns a policy dict."""
        expected = {'policyId': 'policy-abc',
                    'serverId': 'server-def',
                    'alarmId': 'alghi',
                    'checkId': 'chjkl',
                    'state': True}

        def execute(query, data, consistency):
            if 'UPDATE' in query:
                return defer.succeed(None)
            elif 'SELECT' in query:
                return defer.succeed([expected])
        self.client.execute.side_effect = execute

        d = cass.alter_alarm_state(self.client, expected['alarmId'], False)
        result = self.successResultOf(d)

        self.assertEqual(result, ('policy-abc', 'server-def'))

        calls = [
            mock.call(
                'SELECT * FROM serverpolicies WHERE "alarmId"=:alarmId;',
                {'alarmId': 'alghi'},
                1),
            mock.call(
                ('UPDATE serverpolicies SET state=:state WHERE "policyId"=:policyId AND '
                 '"serverId"=:serverId;'),
                {'state': False,
                 'policyId': 'policy-abc',
                 'serverId': 'server-def'},
                1)
        ]
        self.assertEqual(self.client.execute.mock_calls, calls)
Exemple #4
0
    def test_alter_alarm_state(self):
        """Creates and returns a policy dict."""
        expected = {
            'policyId': 'policy-abc',
            'serverId': 'server-def',
            'alarmId': 'alghi',
            'checkId': 'chjkl',
            'state': True
        }

        def execute(query, data, consistency):
            if 'UPDATE' in query:
                return defer.succeed(None)
            elif 'SELECT' in query:
                return defer.succeed([expected])

        self.client.execute.side_effect = execute

        d = cass.alter_alarm_state(self.client, expected['alarmId'], False)
        result = self.successResultOf(d)

        self.assertEqual(result, ('policy-abc', 'server-def'))

        calls = [
            mock.call('SELECT * FROM serverpolicies WHERE "alarmId"=:alarmId;',
                      {'alarmId': 'alghi'}, 1),
            mock.call((
                'UPDATE serverpolicies SET state=:state WHERE "policyId"=:policyId AND '
                '"serverId"=:serverId;'), {
                    'state': False,
                    'policyId': 'policy-abc',
                    'serverId': 'server-def'
                }, 1)
        ]
        self.assertEqual(self.client.execute.mock_calls, calls)