rackerlabs / mimic

An API mock service
Other
168 stars 57 forks source link

Record of all errors seen with Cloud Load Balancers #270

Open cyli opened 9 years ago

cyli commented 9 years ago

See #269 - this is the same but with CLBs.

This is a poor record, but here's some so far that Autoscale has seen:

cyli commented 9 years ago

Using the following script:

"""
Script to see what responses CLB returns when it's immutable (BUILD,
PENDING_UPDATE, PENDING_DELETE, DELETED)
"""

from twisted.internet.task import deferLater, react

from twisted.internet.defer import gatherResults, inlineCallbacks

import json
import treq

@inlineCallbacks
def what_happens_when(clock, tenant_id, auth_token):
    """
    Hammer CLB while it's immutable and see what responses are.
    """
    lb_config = {
        "loadBalancer": {
            "name": "cyli-test",
            "protocol": "HTTP",
            "virtualIps": [
                {"type": "PUBLIC"}
            ]
        }
    }
    nodes = {
        "nodes": [
            {
                "address": "124.1.2.3",
                "port": 80,
                "condition": "ENABLED",
                "type": "PRIMARY"
            },
            {
                "address": "125.1.2.4",
                "port": 81,
                "condition": "ENABLED",
                "type": "SECONDARY"
            }
        ]
    }

    url = "/".join((
        "https://iad.loadbalancers.api.rackspacecloud.com/v1.0",
        tenant_id, "loadbalancers"))
    headers = {'x-auth-token': auth_token,
               'content-type': 'application/json',
               'accept': 'application/json'}

    @inlineCallbacks
    def see_how_responds(node_id='12345'):
        resps = yield gatherResults([
            treq.get('/'.join((url, lbid)), headers=headers),
            treq.post('/'.join((url, lbid, 'nodes')), headers=headers,
                      data=json.dumps(nodes)),
            treq.put('/'.join((url, lbid, 'nodes', node_id)),
                     headers=headers,
                     data=json.dumps({'condition': "DRAINING"})),
            treq.delete('/'.join((url, lbid, 'nodes')), headers=headers,
                        params={'id': node_id}),
            treq.delete('/'.join((url, lbid)), headers=headers),
            treq.get('/'.join((url, lbid, "nodes")), headers=headers)
        ])

        bodies = yield gatherResults(
            [treq.json_content(resp) for resp in resps])

        print "------"
        print bodies[0]['loadBalancer']['status']
        for i, thing in enumerate(["ADD N:    ", "CHANGE N: ",
                                   "DEL N:    ", "DEL LB:   ",
                                   "LIST N:   "]):
            print thing, resps[i + 1].code
            print json.dumps(bodies[i + 1])
            print "------"

    resp = yield treq.post(url, headers=headers, data=json.dumps(lb_config))
    assert resp.code == 202
    lbid = str((yield treq.json_content(resp))['loadBalancer']['id'])
    yield see_how_responds()

    # should be in active state after 60 seconds - add a node
    resp = yield deferLater(
        clock, 60, treq.post,
        '/'.join((url, lbid, 'nodes')), headers=headers,
        data=json.dumps({"nodes": [{"address": "123.1.2.1",
                                    "port": 8080,
                                    "condition": "ENABLED",
                                    "type": "PRIMARY"}]}))
    assert resp.code == 202
    node_id = str((yield treq.json_content(resp))['nodes'][0]['id'])
    yield see_how_responds(node_id)

    # shoudl be in active state again after 60 seconds - deleted CLB
    resp = yield deferLater(clock, 60, treq.delete, '/'.join((url, lbid)),
                            headers=headers)
    yield see_how_responds(node_id)

    # should be in deleted state now
    resp = yield deferLater(clock, 60, lambda: None)
    yield see_how_responds(node_id)

if __name__ == "__main__":
    tenant_id = raw_input("Tenant ID: ")
    auth_token = raw_input("Auth token for " + tenant_id + ": ")
    react(what_happens_when, [tenant_id, auth_token])

I got the following results:

No idea what the error messages are if CLB is in ERROR, since that is not something trigger-able on demand.