Ejemplo n.º 1
0
class BrightboxLBMockHttp(MockHttpTestCase):
    fixtures = LoadBalancerFileFixtures('brightbox')

    def _token(self, method, url, body, headers):
        if method == 'POST':
            return self.response(httplib.OK, self.fixtures.load('token.json'))

    def _1_0_load_balancers(self, method, url, body, headers):
        if method == 'GET':
            return self.response(httplib.OK,
                                 self.fixtures.load('load_balancers.json'))
        elif method == 'POST':
            body = self.fixtures.load('load_balancers_post.json')
            return self.response(httplib.ACCEPTED, body)

    def _1_0_load_balancers_lba_1235f(self, method, url, body, headers):
        if method == 'GET':
            body = self.fixtures.load('load_balancers_lba_1235f.json')
            return self.response(httplib.OK, body)
        elif method == 'DELETE':
            return self.response(httplib.ACCEPTED, '')

    def _1_0_load_balancers_lba_1235f_add_nodes(self, method, url, body,
                                                headers):
        if method == 'POST':
            return self.response(httplib.ACCEPTED, '')

    def _1_0_load_balancers_lba_1235f_remove_nodes(self, method, url, body,
                                                   headers):
        if method == 'POST':
            return self.response(httplib.ACCEPTED, '')

    def response(self, status, body):
        return (status, body, {'content-type': 'application/json'},
                httplib.responses[status])
Ejemplo n.º 2
0
class CloudStackMockHttp(MockHttpTestCase):
    fixtures = LoadBalancerFileFixtures('cloudstack')
    fixture_tag = 'default'

    def _load_fixture(self, fixture):
        body = self.fixtures.load(fixture)
        return body, json.loads(body)

    def _test_path(self, method, url, body, headers):
        url = urlparse.urlparse(url)
        query = dict(parse_qsl(url.query))

        self.assertTrue('apiKey' in query)
        self.assertTrue('command' in query)
        self.assertTrue('response' in query)
        self.assertTrue('signature' in query)

        self.assertTrue(query['response'] == 'json')

        del query['apiKey']
        del query['response']
        del query['signature']
        command = query.pop('command')

        if hasattr(self, '_cmd_' + command):
            return getattr(self, '_cmd_' + command)(**query)
        else:
            fixture = command + '_' + self.fixture_tag + '.json'
            body, obj = self._load_fixture(fixture)
            return (httplib.OK, body, obj, httplib.responses[httplib.OK])

    def _cmd_queryAsyncJobResult(self, jobid):
        fixture = 'queryAsyncJobResult' + '_' + str(jobid) + '.json'
        body, obj = self._load_fixture(fixture)
        return (httplib.OK, body, obj, httplib.responses[httplib.OK])
Ejemplo n.º 3
0
class RackspaceLBMockHttp(MockHttp, unittest.TestCase):
    fixtures = LoadBalancerFileFixtures('rackspace')

    def _v1_0(self, method, url, body, headers):
        headers = {'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug',
                   'x-auth-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
                   'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06',
                   'x-storage-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
                   'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06'}
        return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT])

    def _v1_0_slug_loadbalancers_protocols(self, method, url, body, headers):
        body = self.fixtures.load('v1_slug_loadbalancers_protocols.json')
        return (httplib.ACCEPTED, body, {},
                httplib.responses[httplib.ACCEPTED])

    def _v1_0_slug_loadbalancers(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load('v1_slug_loadbalancers.json')
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
        elif method == "POST":
            body_json = json.loads(body)
            self.assertEqual(body_json['loadBalancer']['protocol'], 'HTTP')
            self.assertEqual(body_json['loadBalancer']['algorithm'], 'ROUND_ROBIN')

            body = self.fixtures.load('v1_slug_loadbalancers_post.json')
            return (httplib.ACCEPTED, body, {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_8155(self, method, url, body, headers):
        if method == "DELETE":
            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_8290(self, method, url, body, headers):
        body = self.fixtures.load('v1_slug_loadbalancers_8290.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _v1_0_slug_loadbalancers_8290_nodes(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load('v1_slug_loadbalancers_8290_nodes.json')
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
        elif method == "POST":
            body = self.fixtures.load('v1_slug_loadbalancers_8290_nodes_post.json')
            return (httplib.ACCEPTED, body, {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_8290_nodes_30944(self, method, url, body, headers):
        if method == "DELETE":
            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError
Ejemplo n.º 4
0
class GoGridLBMockHttp(MockHttpTestCase):
    fixtures = LoadBalancerFileFixtures('gogrid')

    def _api_grid_loadbalancer_list(self, method, url, body, headers):
        body = self.fixtures.load('loadbalancer_list.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _api_grid_ip_list(self, method, url, body, headers):
        body = self.fixtures.load('ip_list.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _api_grid_loadbalancer_add(self, method, url, body, headers):
        query = urlparse.urlparse(url).query
        self.assertTrue(query.find('loadbalancer.type=round+robin') != -1)

        body = self.fixtures.load('loadbalancer_add.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _api_grid_ip_list_UNEXPECTED_ERROR(self, method, url, body, headers):
        return self._api_grid_ip_list(method, url, body, headers)

    def _api_grid_loadbalancer_add_UNEXPECTED_ERROR(self, method, url, body,
                                                    headers):
        body = self.fixtures.load('unexpected_error.json')
        return (httplib.INTERNAL_SERVER_ERROR, body, {},
                httplib.responses[httplib.OK])

    def _api_grid_loadbalancer_delete(self, method, url, body, headers):
        body = self.fixtures.load('loadbalancer_add.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _api_grid_loadbalancer_get(self, method, url, body, headers):
        body = self.fixtures.load('loadbalancer_get.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _api_grid_loadbalancer_edit(self, method, url, body, headers):
        body = self.fixtures.load('loadbalancer_edit.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
Ejemplo n.º 5
0
class RackspaceLBMockHttp(MockHttpTestCase):
    fixtures = LoadBalancerFileFixtures('rackspace')
    auth_fixtures = OpenStackFixtures()

    def _v1_0(self, method, url, body, headers):
        headers = {
            'x-server-management-url':
            'https://servers.api.rackspacecloud.com/v1.0/slug',
            'x-auth-token':
            'FE011C19-CF86-4F87-BE5D-9229145D7A06',
            'x-cdn-management-url':
            'https://cdn.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06',
            'x-storage-token':
            'FE011C19-CF86-4F87-BE5D-9229145D7A06',
            'x-storage-url':
            'https://storage4.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06'
        }
        return (httplib.NO_CONTENT, "", headers,
                httplib.responses[httplib.NO_CONTENT])

    def _v1_0_slug_loadbalancers_protocols(self, method, url, body, headers):
        body = self.fixtures.load('v1_slug_loadbalancers_protocols.json')
        return (httplib.ACCEPTED, body, {},
                httplib.responses[httplib.ACCEPTED])

    def _v1_0_slug_loadbalancers_algorithms(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load('v1_slug_loadbalancers_algorithms.json')
            return (httplib.ACCEPTED, body, {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load('v1_slug_loadbalancers.json')
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
        elif method == "POST":
            body_json = json.loads(body)
            self.assertEqual(body_json['loadBalancer']['protocol'], 'HTTP')
            self.assertEqual(body_json['loadBalancer']['algorithm'],
                             'ROUND_ROBIN')

            body = self.fixtures.load('v1_slug_loadbalancers_post.json')
            return (httplib.ACCEPTED, body, {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_EX_MEMBER_ADDRESS(self, method, url, body,
                                                   headers):
        body = self.fixtures.load('v1_slug_loadbalancers_nodeaddress.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _v1_0_slug_loadbalancers_8155(self, method, url, body, headers):
        if method == "DELETE":
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_8290(self, method, url, body, headers):
        body = self.fixtures.load('v1_slug_loadbalancers_8290.json')
        return (httplib.OK, body, {}, httplib.responses[httplib.OK])

    def _v1_0_slug_loadbalancers_8290_nodes(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load('v1_slug_loadbalancers_8290_nodes.json')
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
        elif method == "POST":
            body = self.fixtures.load(
                'v1_slug_loadbalancers_8290_nodes_post.json')
            return (httplib.ACCEPTED, body, {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_8290_nodes_30944(self, method, url, body,
                                                  headers):
        if method == "DELETE":
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_18940(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_18940_ex_public_ips.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_18945(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_18945_ex_public_ips.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_18940_errorpage(self, method, url, body,
                                                 headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_18940_errorpage.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_18940_accesslist(self, method, url, body,
                                                  headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_18940_accesslist.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_18941(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_18941_ex_private_ips.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94692(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94692_weighted_round_robin.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94693(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94693_weighted_least_connections.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94694(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94694_unknown_algorithm.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94695(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94695_full_details.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94696(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94696_http_health_monitor.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_94697(self, method, url, body, headers):
        if method == "GET":
            body = self.fixtures.load(
                "v1_slug_loadbalancers_94697_https_health_monitor.json")
            return (httplib.OK, body, {}, httplib.responses[httplib.OK])

        raise NotImplementedError

    def _v1_0_slug_loadbalancers_3130(self, method, url, body, headers):
        """ update_balancer(b, protocol='HTTPS'), then get_balancer('3130') """
        if method == "PUT":
            self.assertEqual(json.loads(body), {'protocol': 'HTTPS'})
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])
        elif method == "GET":
            response_body = json.loads(
                self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
            response_body['loadBalancer']['id'] = 3130
            response_body['loadBalancer']['protocol'] = 'HTTPS'
            return (httplib.OK, json.dumps(response_body), {},
                    httplib.responses[httplib.OK])
        raise NotImplementedError

    def _v1_0_slug_loadbalancers_3131(self, method, url, body, headers):
        """ update_balancer(b, port=443), then get_balancer('3131') """
        if method == "PUT":
            self.assertEqual(json.loads(body), {'port': 1337})
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])
        elif method == "GET":
            response_body = json.loads(
                self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
            response_body['loadBalancer']['id'] = 3131
            response_body['loadBalancer']['port'] = 1337
            return (httplib.OK, json.dumps(response_body), {},
                    httplib.responses[httplib.OK])
        raise NotImplementedError

    def _v1_0_slug_loadbalancers_3132(self, method, url, body, headers):
        """ update_balancer(b, name='new_lb_name'), then get_balancer('3132') """
        if method == "PUT":
            self.assertEqual(json.loads(body), {'name': 'new_lb_name'})
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])
        elif method == "GET":
            response_body = json.loads(
                self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
            response_body['loadBalancer']['id'] = 3132
            response_body['loadBalancer']['name'] = 'new_lb_name'
            return (httplib.OK, json.dumps(response_body), {},
                    httplib.responses[httplib.OK])
        raise NotImplementedError

    def _v1_0_slug_loadbalancers_3133(self, method, url, body, headers):
        """ update_balancer(b, algorithm='ROUND_ROBIN'), then get_balancer('3133') """
        if method == "PUT":
            self.assertEqual(json.loads(body), {'algorithm': 'ROUND_ROBIN'})
            return (httplib.ACCEPTED, "", {},
                    httplib.responses[httplib.ACCEPTED])
        elif method == "GET":
            response_body = json.loads(
                self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
            response_body['loadBalancer']['id'] = 3133
            response_body['loadBalancer']['algorithm'] = 'ROUND_ROBIN'
            return (httplib.OK, json.dumps(response_body), {},
                    httplib.responses[httplib.OK])
        raise NotImplementedError

    def _v1_0_slug_loadbalancers_3134(self, method, url, body, headers):
        """ update.balancer(b, algorithm='HAVE_MERCY_ON_OUR_SERVERS') """
        if method == "PUT":
            return (httplib.BAD_REQUEST, "", {},
                    httplib.responses[httplib.BAD_REQUEST])
        raise NotImplementedError

    def _v1_1_auth(self, method, url, body, headers):
        headers = {'content-type': 'application/json; charset=UTF-8'}
        body = self.auth_fixtures.load('_v1_1__auth.json')
        return (httplib.OK, body, headers, httplib.responses[httplib.OK])