Skip to content

Commit 060057c

Browse files
author
Yong Sheng Gong
committed
deal with -c option when the list result is empty.
bug #1033123 Change-Id: Idd10e9ae8fd57e6173ef7f92411176834efebff5
1 parent defb548 commit 060057c

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

quantum_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ quantum net-show $network_id || die "fail to show network $network_id"
2525
quantum net-update $network --admin_state_up False || die "fail to update network $network"
2626
quantum net-update $network_id --admin_state_up True || die "fail to update network $network_id"
2727

28+
quantum net-list -c id -- --id fakeid || die "fail to list networks with column selection on empty list"
29+
2830
# test the CRUD of subnet
2931
subnet=mysubnet1
3032
cidr=10.0.1.3/24

quantumclient/quantum/v2_0/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ def get_data(self, parsed_args):
362362
if collection in data:
363363
info = data[collection]
364364
_columns = len(info) > 0 and sorted(info[0].keys()) or []
365+
if not _columns:
366+
parsed_args.columns = []
365367
return (_columns, (utils.get_item_properties(
366368
s, _columns, formatters=self._formatters, )
367369
for s in info), )

quantumclient/tests/unit/test_cli20_network.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sys
1919

2020
from quantumclient.common import exceptions
21+
from quantumclient.tests.unit import test_cli20
2122
from quantumclient.tests.unit.test_cli20 import CLITestV20Base
2223
from quantumclient.tests.unit.test_cli20 import MyApp
2324
from quantumclient.quantum.v2_0.network import CreateNetwork
@@ -79,6 +80,35 @@ def test_create_network_state(self):
7980
position_names, position_values,
8081
admin_state_up=False)
8182

83+
def test_lsit_nets_empty_with_column(self):
84+
resources = "networks"
85+
cmd = ListNetwork(MyApp(sys.stdout), None)
86+
self.mox.StubOutWithMock(cmd, "get_client")
87+
self.mox.StubOutWithMock(self.client.httpclient, "request")
88+
cmd.get_client().MultipleTimes().AndReturn(self.client)
89+
reses = {resources: []}
90+
resstr = self.client.serialize(reses)
91+
# url method body
92+
query = "id=myfakeid"
93+
args = ['-c', 'id', '--', '--id', 'myfakeid']
94+
path = getattr(self.client, resources + "_path")
95+
self.client.httpclient.request(
96+
test_cli20.end_url(path, query), 'GET',
97+
body=None,
98+
headers=test_cli20.ContainsKeyValue(
99+
'X-Auth-Token',
100+
test_cli20.TOKEN)).AndReturn(
101+
(test_cli20.MyResp(200), resstr))
102+
self.mox.ReplayAll()
103+
cmd_parser = cmd.get_parser("list_" + resources)
104+
105+
parsed_args = cmd_parser.parse_args(args)
106+
cmd.run(parsed_args)
107+
self.mox.VerifyAll()
108+
self.mox.UnsetStubs()
109+
_str = self.fake_stdout.make_string()
110+
self.assertEquals('\n', _str)
111+
82112
def test_list_nets_detail(self):
83113
"""list nets: -D."""
84114
resources = "networks"

0 commit comments

Comments
 (0)