Addressing comments from Dan
Also solved issue with output from plug_iface and unplug_iface
This commit is contained in:
parent
f4405229e6
commit
673edc3141
8
bin/cli
8
bin/cli
@ -55,8 +55,8 @@ commands = {
|
|||||||
"delete_net": {
|
"delete_net": {
|
||||||
"func": cli_lib.delete_net,
|
"func": cli_lib.delete_net,
|
||||||
"args": ["tenant-id", "net-id"]},
|
"args": ["tenant-id", "net-id"]},
|
||||||
"detail_net": {
|
"show_net": {
|
||||||
"func": cli_lib.detail_net,
|
"func": cli_lib.show_net,
|
||||||
"args": ["tenant-id", "net-id"]},
|
"args": ["tenant-id", "net-id"]},
|
||||||
"rename_net": {
|
"rename_net": {
|
||||||
"func": cli_lib.rename_net,
|
"func": cli_lib.rename_net,
|
||||||
@ -73,8 +73,8 @@ commands = {
|
|||||||
"set_port_state": {
|
"set_port_state": {
|
||||||
"func": cli_lib.set_port_state,
|
"func": cli_lib.set_port_state,
|
||||||
"args": ["tenant-id", "net-id", "port-id", "new_state"]},
|
"args": ["tenant-id", "net-id", "port-id", "new_state"]},
|
||||||
"detail_port": {
|
"show_port": {
|
||||||
"func": cli_lib.detail_port,
|
"func": cli_lib.show_port,
|
||||||
"args": ["tenant-id", "net-id", "port-id"]},
|
"args": ["tenant-id", "net-id", "port-id"]},
|
||||||
"plug_iface": {
|
"plug_iface": {
|
||||||
"func": cli_lib.plug_iface,
|
"func": cli_lib.plug_iface,
|
||||||
|
@ -95,22 +95,14 @@ def delete_net(client, *args):
|
|||||||
_handle_exception(ex)
|
_handle_exception(ex)
|
||||||
|
|
||||||
|
|
||||||
def detail_net(client, *args):
|
def show_net(client, *args):
|
||||||
tenant_id, network_id = args
|
tenant_id, network_id = args
|
||||||
try:
|
try:
|
||||||
#NOTE(salvatore-orlando): Implementing non-efficient version
|
#NOTE(salvatore-orlando) changed for returning exclusively
|
||||||
#for now, at least until plugins will not provide correct behaviour
|
# output for GET /networks/{net-id} API operation
|
||||||
#for the show_network_details operation
|
|
||||||
res = client.show_network_details(network_id)["network"]
|
res = client.show_network_details(network_id)["network"]
|
||||||
LOG.debug("Operation 'show_network_details' executed.")
|
LOG.debug("Operation 'show_network_details' executed.")
|
||||||
ports = client.list_ports(network_id)
|
output = prepare_output("show_net", tenant_id, dict(network=res))
|
||||||
LOG.debug("Operation 'list_ports' executed.")
|
|
||||||
res.update(ports)
|
|
||||||
for port in ports['ports']:
|
|
||||||
att_data = client.show_port_attachment(network_id, port['id'])
|
|
||||||
LOG.debug("Operation 'show_port_attachment' executed.")
|
|
||||||
port['attachment'] = att_data['attachment'].get('id', None)
|
|
||||||
output = prepare_output("detail_net", tenant_id, dict(network=res))
|
|
||||||
print output
|
print output
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
_handle_exception(ex)
|
_handle_exception(ex)
|
||||||
@ -171,7 +163,7 @@ def delete_port(client, *args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def detail_port(client, *args):
|
def show_port(client, *args):
|
||||||
tenant_id, network_id, port_id = args
|
tenant_id, network_id, port_id = args
|
||||||
try:
|
try:
|
||||||
port = client.show_port_details(network_id, port_id)["port"]
|
port = client.show_port_details(network_id, port_id)["port"]
|
||||||
@ -180,7 +172,7 @@ def detail_port(client, *args):
|
|||||||
#return attachment with GET operation on port. Once API alignment
|
#return attachment with GET operation on port. Once API alignment
|
||||||
#branch is merged, update client to use the detail action
|
#branch is merged, update client to use the detail action
|
||||||
port['attachment'] = '<unavailable>'
|
port['attachment'] = '<unavailable>'
|
||||||
output = prepare_output("detail_port", tenant_id,
|
output = prepare_output("show_port", tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port=port))
|
port=port))
|
||||||
print output
|
print output
|
||||||
@ -209,7 +201,7 @@ def plug_iface(client, *args):
|
|||||||
data = {'attachment': {'id': '%s' % attachment}}
|
data = {'attachment': {'id': '%s' % attachment}}
|
||||||
client.attach_resource(network_id, port_id, data)
|
client.attach_resource(network_id, port_id, data)
|
||||||
LOG.debug("Operation 'attach_resource' executed.")
|
LOG.debug("Operation 'attach_resource' executed.")
|
||||||
output = prepare_output("plug_interface", tenant_id,
|
output = prepare_output("plug_iface", tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port_id=port_id,
|
port_id=port_id,
|
||||||
attachment=attachment))
|
attachment=attachment))
|
||||||
@ -223,7 +215,7 @@ def unplug_iface(client, *args):
|
|||||||
try:
|
try:
|
||||||
client.detach_resource(network_id, port_id)
|
client.detach_resource(network_id, port_id)
|
||||||
LOG.debug("Operation 'detach_resource' executed.")
|
LOG.debug("Operation 'detach_resource' executed.")
|
||||||
output = prepare_output("unplug_interface", tenant_id,
|
output = prepare_output("unplug_iface", tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port_id=port_id))
|
port_id=port_id))
|
||||||
print output
|
print output
|
||||||
|
@ -1,45 +1,48 @@
|
|||||||
## Cheetah template for cli output
|
## Cheetah template for cli output
|
||||||
#if $cmd == 'list_nets'
|
#if $cmd == 'list_nets'
|
||||||
Virtual Networks on Tenant $tenant_id
|
Virtual Networks for Tenant $tenant_id
|
||||||
#for $network in $networks
|
#for $network in $networks
|
||||||
Network ID: $network.id
|
Network ID: $network.id
|
||||||
#end for
|
#end for
|
||||||
#elif $cmd == 'create_net'
|
#elif $cmd == 'create_net'
|
||||||
Created a new Virtual Network with ID: $network_id for Tenant $tenant_id
|
Created a new Virtual Network with ID: $network_id
|
||||||
|
for Tenant $tenant_id
|
||||||
#elif $cmd == 'delete_net'
|
#elif $cmd == 'delete_net'
|
||||||
Deleted Virtual Network with ID: $network_id for Tenant $tenant_id
|
Deleted Virtual Network with ID: $network_id
|
||||||
#elif $cmd == 'detail_net'
|
for Tenant $tenant_id
|
||||||
Network: $network.name ($network.id)
|
#elif $cmd == 'show_net'
|
||||||
Remote Interfaces on Virtual Network
|
Network ID: $network.id
|
||||||
#for $port in $network.ports
|
Network Name: $network.name
|
||||||
Logical Port $port.id: $port.attachment
|
for Tenant: $tenant_id
|
||||||
#end for
|
|
||||||
#elif $cmd == 'rename_net'
|
#elif $cmd == 'rename_net'
|
||||||
Renamed Virtual Network with ID: $network.id for Tenant $tenant_id,
|
Renamed Virtual Network with ID: $network.id
|
||||||
New name is: $network.name
|
New name is: $network.name
|
||||||
|
for Tenant $tenant_id,
|
||||||
#elif $cmd == 'list_ports'
|
#elif $cmd == 'list_ports'
|
||||||
Ports on Virtual Network: $network_id
|
Ports on Virtual Network: $network_id
|
||||||
|
for Tenant: $tenant_id
|
||||||
#for $port in $ports
|
#for $port in $ports
|
||||||
Logical Port: $port.id
|
Logical Port: $port.id
|
||||||
#end for
|
#end for
|
||||||
#elif $cmd == 'create_port'
|
#elif $cmd == 'create_port'
|
||||||
Created new Logical Port with ID: $port_id
|
Created new Logical Port with ID: $port_id
|
||||||
on Virtual Network: $network_id
|
on Virtual Network: $network_id
|
||||||
for tenant: $tenant_id
|
for Tenant: $tenant_id
|
||||||
#elif $cmd == 'delete_port'
|
#elif $cmd == 'delete_port'
|
||||||
Deleted Logical Port with ID: $port_id
|
Deleted Logical Port with ID: $port_id
|
||||||
on Virtual Network: $network_id
|
on Virtual Network: $network_id
|
||||||
for tenant: $tenant_id
|
for Tenant: $tenant_id
|
||||||
#elif $cmd == 'set_port_state'
|
#elif $cmd == 'set_port_state'
|
||||||
Updated state for Logical Port with ID: $port.id
|
Updated state for Logical Port with ID: $port.id
|
||||||
New state is: $port.state
|
new state is: $port.state
|
||||||
on Virtual Network: $network_id
|
on Virtual Network: $network_id
|
||||||
for tenant: $tenant_id
|
for tenant: $tenant_id
|
||||||
#elif $cmd == 'detail_port'
|
#elif $cmd == 'show_port'
|
||||||
Logical Port ID: $port.id
|
Logical Port ID: $port.id
|
||||||
On Virtual Network: $network_id
|
administrative State: $port.state
|
||||||
Administrative State: $port.state
|
interface: $port.attachment
|
||||||
Remote Interface: $port.attachment
|
on Virtual Network: $network_id
|
||||||
|
for Tenant: $tenant_id
|
||||||
#elif $cmd == 'plug_iface'
|
#elif $cmd == 'plug_iface'
|
||||||
Plugged interface $attachment
|
Plugged interface $attachment
|
||||||
into Logical Port: $port_id
|
into Logical Port: $port_id
|
||||||
|
@ -230,7 +230,6 @@ class Client(object):
|
|||||||
"""
|
"""
|
||||||
if status_code in (202, 204):
|
if status_code in (202, 204):
|
||||||
return data
|
return data
|
||||||
#server.networks.Controller._serialization_metadata
|
|
||||||
return Serializer(self._serialization_metadata).\
|
return Serializer(self._serialization_metadata).\
|
||||||
deserialize(data, self.content_type())
|
deserialize(data, self.content_type())
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class FakeHTTPConnection:
|
|||||||
res = self._req.get_response(self._api)
|
res = self._req.get_response(self._api)
|
||||||
|
|
||||||
def _fake_read():
|
def _fake_read():
|
||||||
""" Trick for macking a webob.Response look like a
|
""" Trick for making a webob.Response look like a
|
||||||
httplib.Response
|
httplib.Response
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -107,19 +107,12 @@ class CLITest(unittest.TestCase):
|
|||||||
# Must add newline at the end to match effect of print call
|
# Must add newline at the end to match effect of print call
|
||||||
self.assertEquals(self.fake_stdout.make_string(), output + '\n')
|
self.assertEquals(self.fake_stdout.make_string(), output + '\n')
|
||||||
|
|
||||||
def _verify_detail_network(self):
|
def _verify_show_network(self):
|
||||||
# Verification - get raw result from db
|
# Verification - get raw result from db
|
||||||
nw = db.network_list(self.tenant_id)[0]
|
nw = db.network_list(self.tenant_id)[0]
|
||||||
network = dict(id=nw.uuid, name=nw.name)
|
network = dict(id=nw.uuid, name=nw.name)
|
||||||
ports = db.port_list(nw['uuid'])
|
|
||||||
for port in ports:
|
|
||||||
port = db.port_get(port['uuid'], nw['uuid'])
|
|
||||||
network['ports'] = [dict(id=port['uuid'],
|
|
||||||
state=port['state'],
|
|
||||||
attachment=port['interface_id'])
|
|
||||||
for port in ports]
|
|
||||||
# Fill CLI template
|
# Fill CLI template
|
||||||
output = cli.prepare_output('detail_net', self.tenant_id,
|
output = cli.prepare_output('show_net', self.tenant_id,
|
||||||
dict(network=network))
|
dict(network=network))
|
||||||
# Verify!
|
# Verify!
|
||||||
# Must add newline at the end to match effect of print call
|
# Must add newline at the end to match effect of print call
|
||||||
@ -177,7 +170,7 @@ class CLITest(unittest.TestCase):
|
|||||||
# Must add newline at the end to match effect of print call
|
# Must add newline at the end to match effect of print call
|
||||||
self.assertEquals(self.fake_stdout.make_string(), output + '\n')
|
self.assertEquals(self.fake_stdout.make_string(), output + '\n')
|
||||||
|
|
||||||
def _verify_detail_port(self, network_id, port_id):
|
def _verify_show_port(self, network_id, port_id):
|
||||||
# Verification - get raw result from db
|
# Verification - get raw result from db
|
||||||
# TODO(salvatore-orlando): Must resolve this issue with
|
# TODO(salvatore-orlando): Must resolve this issue with
|
||||||
# attachment in separate bug fix.
|
# attachment in separate bug fix.
|
||||||
@ -185,7 +178,7 @@ class CLITest(unittest.TestCase):
|
|||||||
port_data = {'id': port.uuid, 'state': port.state,
|
port_data = {'id': port.uuid, 'state': port.state,
|
||||||
'attachment': '<unavailable>'}
|
'attachment': '<unavailable>'}
|
||||||
# Fill CLI template
|
# Fill CLI template
|
||||||
output = cli.prepare_output('detail_port', self.tenant_id,
|
output = cli.prepare_output('show_port', self.tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port=port_data))
|
port=port_data))
|
||||||
# Verify!
|
# Verify!
|
||||||
@ -196,7 +189,7 @@ class CLITest(unittest.TestCase):
|
|||||||
# Verification - get raw result from db
|
# Verification - get raw result from db
|
||||||
port = db.port_get(port_id, network_id)
|
port = db.port_get(port_id, network_id)
|
||||||
# Fill CLI template
|
# Fill CLI template
|
||||||
output = cli.prepare_output("plug_interface", self.tenant_id,
|
output = cli.prepare_output("plug_iface", self.tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port_id=port['uuid'],
|
port_id=port['uuid'],
|
||||||
attachment=port['interface_id']))
|
attachment=port['interface_id']))
|
||||||
@ -208,7 +201,7 @@ class CLITest(unittest.TestCase):
|
|||||||
# Verification - get raw result from db
|
# Verification - get raw result from db
|
||||||
port = db.port_get(port_id, network_id)
|
port = db.port_get(port_id, network_id)
|
||||||
# Fill CLI template
|
# Fill CLI template
|
||||||
output = cli.prepare_output("unplug_interface", self.tenant_id,
|
output = cli.prepare_output("unplug_iface", self.tenant_id,
|
||||||
dict(network_id=network_id,
|
dict(network_id=network_id,
|
||||||
port_id=port['uuid']))
|
port_id=port['uuid']))
|
||||||
# Verify!
|
# Verify!
|
||||||
@ -254,22 +247,18 @@ class CLITest(unittest.TestCase):
|
|||||||
LOG.debug(self.fake_stdout.content)
|
LOG.debug(self.fake_stdout.content)
|
||||||
self._verify_delete_network(network_id)
|
self._verify_delete_network(network_id)
|
||||||
|
|
||||||
def test_detail_network(self):
|
def test_show_network(self):
|
||||||
try:
|
try:
|
||||||
# Load some data into the datbase
|
# Load some data into the datbase
|
||||||
net = db.network_create(self.tenant_id, self.network_name_1)
|
net = db.network_create(self.tenant_id, self.network_name_1)
|
||||||
db.port_create(net['uuid'])
|
cli.show_net(self.client, self.tenant_id, net['uuid'])
|
||||||
# Create a 2nd port and plug attachment in it
|
|
||||||
port = db.port_create(net['uuid'])
|
|
||||||
db.port_set_attachment(port['uuid'], net['uuid'], "test_iface_id")
|
|
||||||
cli.detail_net(self.client, self.tenant_id, net['uuid'])
|
|
||||||
except:
|
except:
|
||||||
LOG.exception("Exception caught: %s", sys.exc_info())
|
LOG.exception("Exception caught: %s", sys.exc_info())
|
||||||
self.fail("test_detail_network failed due to an exception")
|
self.fail("test_detail_network failed due to an exception")
|
||||||
|
|
||||||
LOG.debug("Operation completed. Verifying result")
|
LOG.debug("Operation completed. Verifying result")
|
||||||
LOG.debug(self.fake_stdout.content)
|
LOG.debug(self.fake_stdout.content)
|
||||||
self._verify_detail_network()
|
self._verify_show_network()
|
||||||
|
|
||||||
def test_rename_network(self):
|
def test_rename_network(self):
|
||||||
try:
|
try:
|
||||||
@ -351,7 +340,7 @@ class CLITest(unittest.TestCase):
|
|||||||
LOG.debug(self.fake_stdout.content)
|
LOG.debug(self.fake_stdout.content)
|
||||||
self._verify_set_port_state(network_id, port_id)
|
self._verify_set_port_state(network_id, port_id)
|
||||||
|
|
||||||
def test_detail_port(self):
|
def test_show_port(self):
|
||||||
network_id = None
|
network_id = None
|
||||||
port_id = None
|
port_id = None
|
||||||
try:
|
try:
|
||||||
@ -360,14 +349,14 @@ class CLITest(unittest.TestCase):
|
|||||||
network_id = net['uuid']
|
network_id = net['uuid']
|
||||||
port = db.port_create(network_id)
|
port = db.port_create(network_id)
|
||||||
port_id = port['uuid']
|
port_id = port['uuid']
|
||||||
cli.detail_port(self.client, self.tenant_id, network_id, port_id)
|
cli.show_port(self.client, self.tenant_id, network_id, port_id)
|
||||||
except:
|
except:
|
||||||
LOG.exception("Exception caught: %s", sys.exc_info())
|
LOG.exception("Exception caught: %s", sys.exc_info())
|
||||||
self.fail("test_detail_port failed due to an exception")
|
self.fail("test_detail_port failed due to an exception")
|
||||||
|
|
||||||
LOG.debug("Operation completed. Verifying result")
|
LOG.debug("Operation completed. Verifying result")
|
||||||
LOG.debug(self.fake_stdout.content)
|
LOG.debug(self.fake_stdout.content)
|
||||||
self._verify_detail_port(network_id, port_id)
|
self._verify_show_port(network_id, port_id)
|
||||||
|
|
||||||
def test_plug_iface(self):
|
def test_plug_iface(self):
|
||||||
network_id = None
|
network_id = None
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
eventlet>=0.9.12
|
eventlet>=0.9.12
|
||||||
Routes>=1.12.3
|
Routes>=1.12.3
|
||||||
Cheetah>=2.0.1
|
Cheetah>=2.0.1
|
||||||
mox==0.5.3
|
|
||||||
nose
|
nose
|
||||||
Paste
|
Paste
|
||||||
PasteDeploy
|
PasteDeploy
|
||||||
|
Loading…
x
Reference in New Issue
Block a user