Exemplo n.º 1
0
    def test_get_server_by_id_integrity_problems(self):
        """Raises an error if more than one group is found."""
        self.client.execute.return_value = defer.succeed(['server-abc', 'server-def'])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz', 'server-abc')

        result = self.failureResultOf(d)
        self.assertTrue(result.check(cass.ExcessiveResultsError))
Exemplo n.º 2
0
    def test_get_server_by_server_id_not_found(self):
        """Raises an error if no server is found."""
        self.client.execute.return_value = defer.succeed([])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz', 'server-abc')

        result = self.failureResultOf(d)
        self.assertTrue(result.check(cass.ResultNotFoundError))
Exemplo n.º 3
0
    def test_get_server_by_server_id_not_found(self):
        """Raises an error if no server is found."""
        self.client.execute.return_value = defer.succeed([])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz',
                                         'server-abc')

        result = self.failureResultOf(d)
        self.assertTrue(result.check(cass.ResultNotFoundError))
Exemplo n.º 4
0
    def test_get_server_by_id_integrity_problems(self):
        """Raises an error if more than one group is found."""
        self.client.execute.return_value = defer.succeed(
            ['server-abc', 'server-def'])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz',
                                         'server-abc')

        result = self.failureResultOf(d)
        self.assertTrue(result.check(cass.ExcessiveResultsError))
Exemplo n.º 5
0
    def delete_server(self, tenant_id, group_id, server_id):
        """ Clean up a server's records """
        d = cass.get_server_by_server_id(self._db, tenant_id, group_id, server_id)

        def delete_entity(result):
            maas_client = self._get_maas_client()
            d = maas_client.delete_entity(result['entityId'])
            return d
        d.addCallback(delete_entity)

        def delete_server_from_db(_):
            return cass.delete_server(self._db, tenant_id, group_id, server_id)
        d.addCallback(delete_server_from_db)

        return d
Exemplo n.º 6
0
    def test_get_server_by_server_id(self):
        """Return a single server dict, rather than a single item list."""
        expected = {'serverId': 'server-abc',
                    'groupId': 'group-def',
                    'entityId': 'entity-ghi'}
        self.client.execute.return_value = defer.succeed([expected])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz', 'server-abc')

        result = self.successResultOf(d)
        self.assertEqual(result, expected)
        self.client.execute.assert_called_once_with(
            'SELECT * FROM servers WHERE "groupId"=:groupId AND "serverId"=:serverId;',
            {'serverId': 'server-abc', 'groupId': 'group-xyz'},
            1)
Exemplo n.º 7
0
    def delete_server(self, tenant_id, group_id, server_id):
        """ Clean up a server's records """
        d = cass.get_server_by_server_id(self._db, tenant_id, group_id,
                                         server_id)

        def delete_entity(result):
            maas_client = self._get_maas_client()
            d = maas_client.delete_entity(result['entityId'])
            return d

        d.addCallback(delete_entity)

        def delete_server_from_db(_):
            return cass.delete_server(self._db, tenant_id, group_id, server_id)

        d.addCallback(delete_server_from_db)

        return d
Exemplo n.º 8
0
    def test_get_server_by_server_id(self):
        """Return a single server dict, rather than a single item list."""
        expected = {
            'serverId': 'server-abc',
            'groupId': 'group-def',
            'entityId': 'entity-ghi'
        }
        self.client.execute.return_value = defer.succeed([expected])

        d = cass.get_server_by_server_id(self.client, '101010', 'group-xyz',
                                         'server-abc')

        result = self.successResultOf(d)
        self.assertEqual(result, expected)
        self.client.execute.assert_called_once_with(
            'SELECT * FROM servers WHERE "groupId"=:groupId AND "serverId"=:serverId;',
            {
                'serverId': 'server-abc',
                'groupId': 'group-xyz'
            }, 1)
Exemplo n.º 9
0
 def get_server(_):
     return cass.get_server_by_server_id(server.get('id'))
Exemplo n.º 10
0
 def get_server(_):
     return cass.get_server_by_server_id(server.get('id'))