def apply_policy(self, tenant_id, group_id, policy_id, check_template, alarm_template, nplan_id): """Apply a new policy accross a group of servers""" d = cass.get_servers_by_group_id(self._db, tenant_id, group_id) def proc_servers(servers): deferreds = [ self.add_policy_to_server(self._db, tenant_id, policy_id, server['serverId'], server['entityId'], check_template, alarm_template, nplan_id) for server in servers ] return defer.gatherResults(deferreds, consumeErrors=False) d.addCallback(proc_servers) d.addCallback(lambda _: None) return d
def test_get_servers_by_group_id(self): """Returns all servers by a given group_id.""" expected = [{'serverId': 'server-abc', 'groupId': 'group-def', 'entityId': 'entity-ghi'}, {'serverId': 'server-xyz', 'groupId': 'group-def', 'entityId': 'entity-uvw'}] self.client.execute.return_value = defer.succeed(expected) d = cass.get_servers_by_group_id(self.client, '101010', 'group-def') result = self.successResultOf(d) self.assertEqual(result, expected) self.client.execute.assert_called_once_with( 'SELECT * FROM servers WHERE "groupId"=:groupId;', {'groupId': 'group-def'}, 1)
def test_get_servers_by_group_id(self): """Returns all servers by a given group_id.""" expected = [{ 'serverId': 'server-abc', 'groupId': 'group-def', 'entityId': 'entity-ghi' }, { 'serverId': 'server-xyz', 'groupId': 'group-def', 'entityId': 'entity-uvw' }] self.client.execute.return_value = defer.succeed(expected) d = cass.get_servers_by_group_id(self.client, '101010', 'group-def') result = self.successResultOf(d) self.assertEqual(result, expected) self.client.execute.assert_called_once_with( 'SELECT * FROM servers WHERE "groupId"=:groupId;', {'groupId': 'group-def'}, 1)