if ex.args and isinstance(ex.args[-1][0], dict):
status_code = ex.args[-1][0].get('status_code', None)
message = ex.args[-1][0].get('message', None)
- msg_1 = "Command failed with error code: %s" % status_code or '<missing>'
- msg_2 = "Error message:%s" % message or '<missing>'
+ msg_1 = "Command failed with error code: %s" % (status_code or '<missing>')
+ msg_2 = "Error message:%s" % (message or '<missing>')
LOG.exception(msg_1 + "-" + msg_2)
print msg_1
print msg_2
client.update_network(network_id, data)
LOG.debug("Operation 'update_network' executed.")
# Response has no body. Use data for populating output
- data['id'] = network_id
- output = prepare_output("rename_net", tenant_id, dict(network=data))
+ data['network']['id'] = network_id
+ output = prepare_output("rename_net", tenant_id, data)
print output
except Exception as ex:
_handle_exception(ex)
# under the License.
# @author: Tyler Smith, Cisco Systems
+import logging
import httplib
import socket
import urllib
from quantum.common.wsgi import Serializer
+LOG = logging.getLogger('client')
+
class api_call(object):
"""A Decorator to add support for format and tenant overriding"""
to action
"""
-
+ LOG.debug("Client issuing request: %s", action)
# Ensure we have a tenant id
if not self.tenant:
raise Exception("Tenant ID not set")
if type(params) is dict:
action += '?' + urllib.urlencode(params)
-
try:
connection_type = self.get_connection_type()
headers = headers or {"Content-Type":
"application/%s" % self.format}
-
# Open connection and send request, handling SSL certs
certs = {'key_file': self.key_file, 'cert_file': self.cert_file}
certs = dict((x, certs[x]) for x in certs if certs[x] != None)
c = connection_type(self.host, self.port, **certs)
else:
c = connection_type(self.host, self.port)
-
res = self._send_request(c, method, action, body, headers)
status_code = self.get_status_code(res)
if status_code in (httplib.OK,
return self.deserialize(res)
else:
# Create exception with HTTP status code and message
+ error_message = res.read()
+ LOG.debug("Server returned error: %s", status_code)
+ LOG.debug("Error message: %s", error_message)
ex = Exception("Server returned error: %s" % status_code)
ex.args = ([dict(status_code=status_code,
- message=res.read())],)
+ message=error_message)],)
raise ex
-
except (socket.error, IOError), e:
raise Exception("Unable to connect to "
"server. Got error: %s" % e)
return Serializer().serialize(data, self.content_type())
def deserialize(self, data):
- if self.get_status_code(data) == 202:
+ if self.get_status_code(data) in (202, 204):
return data.read()
return Serializer().deserialize(data.read(), self.content_type())
# Must add newline at the end to match effect of print call
self.assertEquals(self.fake_stdout.make_string(), output + '\n')
- def test_list_networks_api(self):
+ def _verify_rename_network(self):
+ # Verification - get raw result from db
+ nw_list = db.network_list(self.tenant_id)
+ network_data = {'id': nw_list[0].uuid,
+ 'net-name': nw_list[0].name}
+ # Fill CLI template
+ output = cli.prepare_output('rename_net', self.tenant_id,
+ dict(network=network_data))
+ # Verify!
+ # Must add newline at the end to match effect of print call
+ self.assertEquals(self.fake_stdout.make_string(), output + '\n')
+
+ def test_list_networks(self):
try:
# Pre-populate data for testing using db api
db.network_create(self.tenant_id, self.network_name_1)
self._verify_list_networks()
except:
LOG.exception("Exception caught: %s", sys.exc_info())
- self.fail("test_list_network_api failed due to an exception")
+ self.fail("test_list_networks failed due to an exception")
- def test_create_network_api(self):
+ def test_create_network(self):
try:
cli.create_net(self.client, self.tenant_id, "test")
LOG.debug("Operation completed. Verifying result")
self._verify_create_network()
except:
LOG.exception("Exception caught: %s", sys.exc_info())
- self.fail("test_create_network_api failed due to an exception")
+ self.fail("test_create_network failed due to an exception")
- def _prepare_test_delete_network(self):
- # Pre-populate data for testing using db api
- db.network_create(self.tenant_id, self.network_name_1)
- net_id = db.network_list(self.tenant_id)[0]['uuid']
- return net_id
-
- def test_delete_network_api(self):
+ def test_delete_network(self):
try:
- network_id = self._prepare_test_delete_network()
+ db.network_create(self.tenant_id, self.network_name_1)
+ network_id = db.network_list(self.tenant_id)[0]['uuid']
cli.delete_net(self.client, self.tenant_id, network_id)
LOG.debug("Operation completed. Verifying result")
LOG.debug(self.fake_stdout.content)
self._verify_delete_network(network_id)
except:
LOG.exception("Exception caught: %s", sys.exc_info())
- self.fail("test_delete_network_api failed due to an exception")
+ self.fail("test_delete_network failed due to an exception")
+
+ def test_detail_network(self):
+ # Load some data into the datbase
+ net = db.network_create(self.tenant_id, self.network_name_1)
+ db.port_create(net['uuid'])
+ port = db.port_create(net['uuid'])
+ cli.detail_net(self.client, self.tenant_id, net['uuid'])
+ db.port_set_attachment(port['uuid'], net['uuid'], "test_iface_id")
- def test_detail_network_api(self):
- # Load some data into the datbase
+ def test_rename_network(self):
+ try:
net = db.network_create(self.tenant_id, self.network_name_1)
- db.port_create(net['uuid'])
- port = db.port_create(net['uuid'])
- cli.detail_net(self.client, self.tenant_id, net['uuid'])
- db.port_set_attachment(port['uuid'], net['uuid'], "test_iface_id")
+ network_id = net['uuid']
+ cli.rename_net(self.client, self.tenant_id,
+ network_id, self.network_name_2)
+ self._verify_rename_network()
+ except:
+ LOG.exception("Exception caught: %s", sys.exc_info())
+ self.fail("test_rename_network failed due to an exception")