Example #1
0
    def test_exception(self):
        code_and_exception = {
            400: webob.exc.HTTPBadRequest,
            401: webob.exc.HTTPUnauthorized,
            403: webob.exc.HTTPForbidden,
            404: webob.exc.HTTPNotFound,
            405: webob.exc.HTTPMethodNotAllowed,
            406: webob.exc.HTTPNotAcceptable,
            409: webob.exc.HTTPConflict,
            413: webob.exc.HTTPRequestEntityTooLarge,
            415: webob.exc.HTTPUnsupportedMediaType,
            429: webob.exc.HTTPTooManyRequests,
            501: webob.exc.HTTPNotImplemented,
            503: webob.exc.HTTPServiceUnavailable,
            # Any other thing should be a 500
            500: webob.exc.HTTPInternalServerError,
            507: webob.exc.HTTPInternalServerError,
        }

        for code, exception in six.iteritems(code_and_exception):
            fault = self.get_fault(code)
            resp = fakes.create_fake_json_resp(fault, code)
            ret = helpers.exception_from_response(resp)
            self.assertIsInstance(ret, exception)
            self.assertEqual(fault["computeFault"]["message"], ret.explanation)
    def test_exception(self):
        code_and_exception = {
            400: webob.exc.HTTPBadRequest,
            401: webob.exc.HTTPUnauthorized,
            403: webob.exc.HTTPForbidden,
            404: webob.exc.HTTPNotFound,
            405: webob.exc.HTTPMethodNotAllowed,
            406: webob.exc.HTTPNotAcceptable,
            409: webob.exc.HTTPConflict,
            413: webob.exc.HTTPRequestEntityTooLarge,
            415: webob.exc.HTTPUnsupportedMediaType,
            429: webob.exc.HTTPTooManyRequests,
            501: webob.exc.HTTPNotImplemented,
            503: webob.exc.HTTPServiceUnavailable,
            # Any other thing should be a 500
            500: webob.exc.HTTPInternalServerError,
            507: webob.exc.HTTPInternalServerError,
        }

        for code, exception in six.iteritems(code_and_exception):
            fault = self.get_fault(code)
            resp = fakes.create_fake_json_resp(fault, code)
            ret = helpers.exception_from_response(resp)
            self.assertIsInstance(ret, exception)
            self.assertEqual(fault["computeFault"]["message"], ret.explanation)
Example #3
0
 def test_create_server_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     image = uuid.uuid4().hex
     flavor = uuid.uuid4().hex
     user_data = "foo"
     key_name = "wtfoo"
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.create_server,
                       None,
                       name,
                       image,
                       flavor,
                       user_data=user_data,
                       key_name=key_name)
     m.assert_called_with(None,
                          name,
                          image,
                          flavor,
                          user_data=user_data,
                          key_name=key_name)
     m_exc.assert_called_with(resp)
 def test_create_server_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     image = uuid.uuid4().hex
     flavor = uuid.uuid4().hex
     user_data = "foo"
     key_name = "wtfoo"
     bdm = []
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.create_server,
                       None,
                       name,
                       image,
                       flavor,
                       user_data=user_data,
                       key_name=key_name,
                       block_device_mapping_v2=bdm)
     m.assert_called_with(None, name, image, flavor, user_data=user_data,
                          key_name=key_name, block_device_mapping_v2=bdm)
     m_exc.assert_called_with(resp)
 def test_get_flavors(self, m):
     resp = fakes.create_fake_json_resp({"flavors": ["FOO"]}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ret = self.helper.get_flavors(None)
     self.assertEqual(["FOO"], ret)
     m.assert_called_with(None)
Example #6
0
 def test_get_flavors(self, m):
     resp = fakes.create_fake_json_resp({"flavors": ["FOO"]}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ret = self.helper.get_flavors(None)
     self.assertEqual(["FOO"], ret)
     m.assert_called_with(None)
 def test_floating_ip_release(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip_uuid = uuid.uuid4().hex
     ret = self.helper.release_floating_ip(None, ip_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, ip_uuid)
Example #8
0
 def test_volume_delete(self, m):
     resp = fakes.create_fake_json_resp(None, 204)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     vol_uuid = uuid.uuid4().hex
     ret = self.helper.volume_delete(None, vol_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, vol_uuid)
Example #9
0
 def test_floating_ip_allocate(self, m_allocate):
     pool = "foo"
     resp = fakes.create_fake_json_resp({"floating_ip": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m_allocate.return_value = req_mock
     ret = self.helper.allocate_floating_ip(None, pool)
     self.assertEqual("FOO", ret)
     m_allocate.assert_called_with(None, pool)
Example #10
0
 def test_floating_ip_release(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip_uuid = uuid.uuid4().hex
     ret = self.helper.release_floating_ip(None, ip_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, ip_uuid)
 def test_floating_ip_allocate(self, m_allocate):
     pool = "foo"
     resp = fakes.create_fake_json_resp({"floating_ip": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m_allocate.return_value = req_mock
     ret = self.helper.allocate_floating_ip(None, pool)
     self.assertEqual("FOO", ret)
     m_allocate.assert_called_with(None, pool)
 def test_volume_delete(self, m):
     resp = fakes.create_fake_json_resp(None, 204)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     vol_uuid = uuid.uuid4().hex
     ret = self.helper.volume_delete(None, vol_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, vol_uuid)
Example #13
0
 def test_get_volume(self, m):
     resp = fakes.create_fake_json_resp({"volume": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     volume_uuid = uuid.uuid4().hex
     ret = self.helper.get_volume(None, volume_uuid)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, volume_uuid)
Example #14
0
 def test_get_server_volume_links(self, m):
     resp = fakes.create_fake_json_resp({"volumeAttachments": ["FOO"]}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     ret = self.helper.get_server_volumes_link(None, server_uuid)
     self.assertEqual(["FOO"], ret)
     m.assert_called_with(None, server_uuid)
 def test_get_server_volume_links(self, m):
     resp = fakes.create_fake_json_resp({"volumeAttachments": ["FOO"]}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     ret = self.helper.get_server_volumes_link(None, server_uuid)
     self.assertEqual(["FOO"], ret)
     m.assert_called_with(None, server_uuid)
 def test_get_volume(self, m):
     resp = fakes.create_fake_json_resp({"volume": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     volume_uuid = uuid.uuid4().hex
     ret = self.helper.get_volume(None, volume_uuid)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, volume_uuid)
Example #17
0
 def test_floating_ip_release_w_exception(self, m):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip_uuid = uuid.uuid4().hex
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.release_floating_ip, None, ip_uuid)
     m.assert_called_with(None, ip_uuid)
 def test_keypair_create_key_import(self, m):
     resp = fakes.create_fake_json_resp({"keypair": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     public_key = "fookeydata"
     ret = self.helper.keypair_create(None, name, public_key=public_key)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, name, public_key=public_key)
 def test_run_action(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     action = "start"
     ret = self.helper.run_action(None, action, server_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, action, server_uuid)
Example #20
0
 def test_run_action(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     action = "start"
     ret = self.helper.run_action(None, action, server_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, action, server_uuid)
Example #21
0
 def test_remove_floating_ip(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip = "192.168.0.20"
     server = uuid.uuid4().hex
     ret = self.helper.remove_floating_ip(None, server, ip)
     self.assertEqual(None, ret)
     m.assert_called_with(None, server, ip)
Example #22
0
 def test_keypair_create_key_import(self, m):
     resp = fakes.create_fake_json_resp({"keypair": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     public_key = "fookeydata"
     ret = self.helper.keypair_create(None, name, public_key=public_key)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, name, public_key=public_key)
 def test_remove_floating_ip(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip = "192.168.0.20"
     server = uuid.uuid4().hex
     ret = self.helper.remove_floating_ip(None, server, ip)
     self.assertEqual(None, ret)
     m.assert_called_with(None, server, ip)
Example #24
0
 def test_get_flavors_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.get_flavors, None)
     m.assert_called_with(None)
     m_exc.assert_called_with(resp)
Example #25
0
 def test_delete_volume_link(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     vol_uuid = uuid.uuid4().hex
     ret = self.helper.delete_server_volumes_link(None, server_uuid,
                                                  vol_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, server_uuid, vol_uuid)
 def test_get_flavors_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.get_flavors,
                       None)
     m.assert_called_with(None)
     m_exc.assert_called_with(resp)
Example #27
0
 def test_keypair_create_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.keypair_create, None, name, None)
     m.assert_called_with(None, name, public_key=None)
     m_exc.assert_called_with(resp)
 def test_delete_volume_link(self, m):
     resp = fakes.create_fake_json_resp(None, 202)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     vol_uuid = uuid.uuid4().hex
     ret = self.helper.delete_server_volumes_link(None,
                                                  server_uuid,
                                                  vol_uuid)
     self.assertEqual(None, ret)
     m.assert_called_with(None, server_uuid, vol_uuid)
 def test_floating_ip_release_w_exception(self, m):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     ip_uuid = uuid.uuid4().hex
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.release_floating_ip,
                       None,
                       ip_uuid)
     m.assert_called_with(None, ip_uuid)
Example #30
0
 def test_delete_volume_link_w_exception(self, m):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     vol_uuid = uuid.uuid4().hex
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.delete_server_volumes_link, None,
                       server_uuid, vol_uuid)
     m.assert_called_with(None, server_uuid, vol_uuid)
Example #31
0
 def test_run_action_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     action = "bad action"
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.run_action, None, action, server_uuid)
     m.assert_called_with(None, action, server_uuid)
     m_exc.assert_called_with(resp)
 def test_delete_volume_link_w_exception(self, m):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     vol_uuid = uuid.uuid4().hex
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.delete_server_volumes_link,
                       None,
                       server_uuid,
                       vol_uuid)
     m.assert_called_with(None, server_uuid, vol_uuid)
 def test_keypair_create_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.keypair_create,
                       None,
                       name,
                       None)
     m.assert_called_with(None, name, public_key=None)
     m_exc.assert_called_with(resp)
Example #34
0
 def test_create_server(self, m):
     resp = fakes.create_fake_json_resp({"server": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     image = uuid.uuid4().hex
     flavor = uuid.uuid4().hex
     user_data = "foo"
     key_name = "wtfoo"
     ret = self.helper.create_server(None, name, image, flavor,
                                     user_data=user_data,
                                     key_name=key_name)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, name, image, flavor, user_data=user_data,
                          key_name=key_name)
Example #35
0
 def test_create_server(self, m):
     resp = fakes.create_fake_json_resp({"server": "FOO"}, 200)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     name = uuid.uuid4().hex
     image = uuid.uuid4().hex
     flavor = uuid.uuid4().hex
     user_data = "foo"
     key_name = "wtfoo"
     ret = self.helper.create_server(None, name, image, flavor,
                                     user_data=user_data,
                                     key_name=key_name)
     self.assertEqual("FOO", ret)
     m.assert_called_with(None, name, image, flavor, user_data=user_data,
                          key_name=key_name)
 def test_run_action_with_exception(self, m, m_exc):
     fault = {"computeFault": {"message": "bad", "code": 500}}
     resp = fakes.create_fake_json_resp(fault, 500)
     req_mock = mock.MagicMock()
     req_mock.get_response.return_value = resp
     m.return_value = req_mock
     server_uuid = uuid.uuid4().hex
     action = "bad action"
     m_exc.return_value = webob.exc.HTTPInternalServerError()
     self.assertRaises(webob.exc.HTTPInternalServerError,
                       self.helper.run_action,
                       None,
                       action,
                       server_uuid)
     m.assert_called_with(None, action, server_uuid)
     m_exc.assert_called_with(resp)
    def test_create_servervolume_with_exception(self, m):
        server_id = uuid.uuid4().hex
        vol_id = uuid.uuid4().hex

        raw_resp = {"volumeAttachment": {
            "device": "/dev/vdd",
            "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
            "serverId": server_id,
            "volumeId": vol_id,
        }}
        resp = fakes.create_fake_json_resp(raw_resp, 200)
        req_mock = mock.MagicMock()
        req_mock.get_response.return_value = resp
        m.return_value = req_mock
        ret = self.helper.create_server_volumes_link(None, server_id, vol_id)
        self.assertEqual(raw_resp["volumeAttachment"], ret)
        m.assert_called_with(None, server_id, vol_id, dev=None)
Example #38
0
    def test_create_servervolume_with_exception(self, m):
        server_id = uuid.uuid4().hex
        vol_id = uuid.uuid4().hex

        raw_resp = {"volumeAttachment": {
            "device": "/dev/vdd",
            "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
            "serverId": server_id,
            "volumeId": vol_id,
        }}
        resp = fakes.create_fake_json_resp(raw_resp, 200)
        req_mock = mock.MagicMock()
        req_mock.get_response.return_value = resp
        m.return_value = req_mock
        ret = self.helper.create_server_volumes_link(None, server_id, vol_id)
        self.assertEqual(raw_resp["volumeAttachment"], ret)
        m.assert_called_with(None, server_id, vol_id, dev=None)
 def test_error_handling_exception(self):
     fault = {}
     resp = fakes.create_fake_json_resp(fault, 404)
     ret = helpers.exception_from_response(resp)
     self.assertIsInstance(ret, webob.exc.HTTPInternalServerError)
Example #40
0
 def test_error_handling_exception(self):
     fault = {}
     resp = fakes.create_fake_json_resp(fault, 404)
     ret = helpers.exception_from_response(resp)
     self.assertIsInstance(ret, webob.exc.HTTPInternalServerError)