class OpenStack_1_1_Auth_2_0_MockHttp(OpenStack_1_1_MockHttp): fixtures = ComputeFileFixtures('openstack_v1.1') auth_fixtures = OpenStackFixtures() json_content_headers = {'content-type': 'application/json; charset=UTF-8'} def __init__(self, *args, **kwargs): super(OpenStack_1_1_Auth_2_0_MockHttp, self).__init__(*args, **kwargs) # TODO Figure out why 1.1 tests are using some 1.0 endpoints methods1 = OpenStackMockHttp.__dict__ methods2 = OpenStack_1_1_MockHttp.__dict__ names1 = [m for m in methods1 if m.find('_v1_0') == 0] names2 = [m for m in methods2 if m.find('_v1_1') == 0] for name in names1: method = methods1[name] new_name = name.replace('_v1_0_slug_', '_v1_0_1337_') setattr(self, new_name, method_type(method, self, OpenStack_1_1_Auth_2_0_MockHttp)) for name in names2: method = methods2[name] new_name = name.replace('_v1_1_slug_', '_v1_0_1337_') setattr(self, new_name, method_type(method, self, OpenStack_1_1_Auth_2_0_MockHttp))
class RackspaceMockHttp(MockHttp): fixtures = ComputeFileFixtures('openstack') auth_fixtures = OpenStackFixtures() def _v1_1_auth(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth.json') return (httplib.OK, body, {'content-type': 'application/json; charset=UTF-8'}, httplib.responses[httplib.OK]) # fake auth token response 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_servers_detail(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_deployment_success.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail_1_SECOND_DELAY(self, method, url, body, headers): time.sleep(1) body = self.fixtures.load('v1_slug_servers_detail_deployment_success.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail_TIMEOUT(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_deployment_pending.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail_MISSING(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_deployment_missing.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail_SAME_UUID(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_deployment_same_uuid.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK])
class CloudFilesMockHttp(StorageMockHttp): fixtures = StorageFileFixtures('cloudfiles') auth_fixtures = OpenStackFixtures() base_headers = {'content-type': 'application/json; charset=UTF-8'} # fake auth token response def _v1_0(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) headers.update({ 'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug', 'x-auth-token': 'FE011C19', 'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS', 'x-storage-token': 'FE011C19', 'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS' }) return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_MossoCloudFS_MALFORMED_JSON(self, method, url, body, headers): # test_invalid_json_throws_exception body = 'broken: json /*"' return (httplib.NO_CONTENT, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_EMPTY(self, method, url, body, headers): return (httplib.NO_CONTENT, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'GET': # list_containers body = self.fixtures.load('list_containers.json') status_code = httplib.OK elif method == 'HEAD': # get_meta_data body = self.fixtures.load('meta_data.json') status_code = httplib.NO_CONTENT headers.update({ 'x-account-container-count': 10, 'x-account-object-count': 400, 'x-account-bytes-used': 1234567 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_not_found(self, method, url, body, headers): # test_get_object_not_found if method == 'HEAD': body = '' else: raise ValueError('Invalid method') return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_container_objects_empty.json') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'GET': # list_container_objects if url.find('marker') == -1: body = self.fixtures.load('list_container_objects.json') status_code = httplib.OK else: body = '' status_code = httplib.NO_CONTENT elif method == 'HEAD': # get_container body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers.update({ 'x-container-object-count': 800, 'x-container-bytes-used': 1234568 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_ITERATOR(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) # list_container_objects if url.find('foo-test-3') != -1: body = self.fixtures.load( 'list_container_objects_not_exhausted2.json') status_code = httplib.OK elif url.find('foo-test-5') != -1: body = '' status_code = httplib.NO_CONTENT else: # First request body = self.fixtures.load( 'list_container_objects_not_exhausted1.json') status_code = httplib.OK return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_not_found(self, method, url, body, headers): # test_get_container_not_found if method == 'HEAD': body = '' else: raise ValueError('Invalid method') return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_test_object(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'HEAD': # get_object body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers.update({ 'content-length': 555, 'last-modified': 'Tue, 25 Jan 2011 22:01:49 GMT', 'etag': '6b21c4a111ac178feacf9ec9d0c71f17', 'x-object-meta-foo-bar': 'test 1', 'x-object-meta-bar-foo': 'test 2', 'content-type': 'application/zip' }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container(self, method, url, body, headers): # test_create_container_success headers = copy.deepcopy(self.base_headers) body = self.fixtures.load('list_container_objects_empty.json') headers = copy.deepcopy(self.base_headers) headers.update({ 'content-length': 18, 'date': 'Mon, 28 Feb 2011 07:52:57 GMT' }) status_code = httplib.CREATED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container_ALREADY_EXISTS( self, method, url, body, headers): # test_create_container_already_exists headers = copy.deepcopy(self.base_headers) body = self.fixtures.load('list_container_objects_empty.json') headers.update({'content-type': 'text/plain'}) status_code = httplib.ACCEPTED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_found body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_EMPTY(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_empty body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.CONFLICT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_1_auth(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth.json') return (httplib.OK, body, { 'content-type': 'application/json; charset=UTF-8' }, httplib.responses[httplib.OK])
class OpenStack_1_1_MockHttp(MockHttpTestCase): fixtures = ComputeFileFixtures('openstack_v1.1') auth_fixtures = OpenStackFixtures() json_content_headers = {'content-type': 'application/json; charset=UTF-8'} def _v2_0_tokens(self, method, url, body, headers): body = self.auth_fixtures.load('_v2_0__auth.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_0_(self, method, url, body, headers): headers = { 'x-auth-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06', 'x-server-management-url': 'https://api.example.com/v1.1/slug', } return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_1_slug_servers_detail(self, method, url, body, headers): body = self.fixtures.load('_servers_detail.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_flavors_detail(self, method, url, body, headers): body = self.fixtures.load('_flavors_detail.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_images_detail(self, method, url, body, headers): body = self.fixtures.load('_images_detail.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_servers(self, method, url, body, headers): body = self.fixtures.load('_servers.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_servers_12065_action(self, method, url, body, headers): if method != "POST": self.fail('HTTP method other than POST to action URL') return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) def _v1_1_slug_servers_12064_action(self, method, url, body, headers): if method != "POST": self.fail('HTTP method other than POST to action URL') return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) def _v1_1_slug_servers_12065(self, method, url, body, headers): if method == "DELETE": return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) else: raise NotImplementedError() def _v1_1_slug_servers_12064(self, method, url, body, headers): if method == "GET": body = self.fixtures.load('_servers_12064.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) elif method == "PUT": body = self.fixtures.load('_servers_12064_updated_name_bob.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) elif method == "DELETE": return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) else: raise NotImplementedError() def _v1_1_slug_servers_12062(self, method, url, body, headers): if method == "GET": body = self.fixtures.load('_servers_12064.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_servers_12063_metadata(self, method, url, body, headers): if method == "GET": body = self.fixtures.load('_servers_12063_metadata_two_keys.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) elif method == "PUT": body = self.fixtures.load('_servers_12063_metadata_two_keys.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_flavors_7(self, method, url, body, headers): if method == "GET": body = self.fixtures.load('_flavors_7.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) else: raise NotImplementedError() def _v1_1_slug_images_13(self, method, url, body, headers): if method == "GET": body = self.fixtures.load('_images_13.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) else: raise NotImplementedError() def _v1_1_slug_images_DELETEUUID(self, method, url, body, headers): if method == "DELETE": return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) else: raise NotImplementedError()
class OpenStackMockHttp(MockHttpTestCase): fixtures = ComputeFileFixtures('openstack') auth_fixtures = OpenStackFixtures() json_content_headers = {'content-type': 'application/json; charset=UTF-8'} # fake auth token response 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_UNAUTHORIZED(self, method, url, body, headers): return (httplib.UNAUTHORIZED, "", {}, httplib.responses[httplib.UNAUTHORIZED]) def _v1_0_INTERNAL_SERVER_ERROR(self, method, url, body, headers): return (httplib.INTERNAL_SERVER_ERROR, "<h1>500: Internal Server Error</h1>", {}, httplib.responses[httplib.INTERNAL_SERVER_ERROR]) def _v1_0_UNAUTHORIZED_MISSING_KEY(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' } return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_0_slug_servers_detail_EMPTY(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_empty.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_detail_METADATA(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_detail_metadata.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_images_333111(self, method, url, body, headers): if method != "DELETE": raise NotImplementedError() # this is currently used for deletion of an image # as such it should not accept GET/POST return (httplib.NO_CONTENT, "", "", httplib.responses[httplib.NO_CONTENT]) def _v1_0_slug_images(self, method, url, body, headers): if method != "POST": raise NotImplementedError() # this is currently used for creation of new image with # POST request, don't handle GET to avoid possible confusion body = self.fixtures.load('v1_slug_images_post.xml') return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_images_detail(self, method, url, body, headers): body = self.fixtures.load('v1_slug_images_detail.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers.xml') return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_EX_SHARED_IP_GROUP(self, method, url, body, headers): # test_create_node_ex_shared_ip_group # Verify that the body contains sharedIpGroupId XML element self.assertTrue(body.find('sharedIpGroupId="12345"') != -1) body = self.fixtures.load('v1_slug_servers.xml') return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_METADATA(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_metadata.xml') return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_72258_action(self, method, url, body, headers): if method != "POST" or body[:8] != "<reboot ": raise NotImplementedError() # only used by reboot() right now, but we will need to parse body someday !!!! return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_limits(self, method, url, body, headers): body = self.fixtures.load('v1_slug_limits.xml') return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_72258(self, method, url, body, headers): if method != "DELETE": raise NotImplementedError() # only used by destroy node() return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_72258_ips(self, method, url, body, headers): body = self.fixtures.load('v1_slug_servers_ips.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_shared_ip_groups_5467(self, method, url, body, headers): if method != 'DELETE': raise NotImplementedError() return (httplib.NO_CONTENT, "", {}, httplib.responses[httplib.NO_CONTENT]) def _v1_0_slug_shared_ip_groups(self, method, url, body, headers): fixture = 'v1_slug_shared_ip_group.xml' if method == 'POST' else 'v1_slug_shared_ip_groups.xml' body = self.fixtures.load(fixture) return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_shared_ip_groups_detail(self, method, url, body, headers): body = self.fixtures.load('v1_slug_shared_ip_groups_detail.xml') return (httplib.OK, body, XML_HEADERS, httplib.responses[httplib.OK]) def _v1_0_slug_servers_3445_ips_public_67_23_21_133( self, method, url, body, headers): return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED]) def _v1_0_slug_servers_444222_action(self, method, url, body, headers): if body.find('resize') != -1: # test_ex_resize_server return (httplib.ACCEPTED, "", headers, httplib.responses[httplib.NO_CONTENT]) elif body.find('confirmResize') != -1: # test_ex_confirm_resize return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) elif body.find('revertResize') != -1: # test_ex_revert_resize return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_0_slug_flavors_detail(self, method, url, body, headers): body = self.fixtures.load('v1_slug_flavors_detail.xml') headers = { 'date': 'Tue, 14 Jun 2011 09:43:55 GMT', 'content-length': '529' } headers.update(XML_HEADERS) return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _v1_1__auth(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1__auth_UNAUTHORIZED(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth_unauthorized.json') return (httplib.UNAUTHORIZED, body, self.json_content_headers, httplib.responses[httplib.UNAUTHORIZED]) def _v1_1__auth_UNAUTHORIZED_MISSING_KEY(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth_mssing_token.json') return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1__auth_INTERNAL_SERVER_ERROR(self, method, url, body, headers): return (httplib.INTERNAL_SERVER_ERROR, "<h1>500: Internal Server Error</h1>", { 'content-type': 'text/html' }, httplib.responses[httplib.INTERNAL_SERVER_ERROR])
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(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 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])
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])