Skip to content

Commit e74f2d9

Browse files
committed
"hypervisor list --matching" showed the wrong result
Previously, using the "--matching" option shows empty results. Previously, the "--matching" option called the "find_hypervisor method", so we used to call the "hypervisor method" like any other "--limit, --marker" options. Depending on the nova api version, the api that is basically called is as follows 2.53 >= : /os-hypervisors/detail?hypervisor_hostname_pattern=$HOSTNAME 2.53 < : /os-hypervisors/{pattern}/search Hypervisor Type and Host IP are not returned when using microversion 2.52 or lower Co-authored-by: Jipyo Hong <hongsbien@naver.com> Co-authored-by: Jieon Lee <dlwldjs7544@naver.com> Co-authored-by: YoonSoo LIM <msdbtjd123@naver.com> story: 2010670 task: 47726 Change-Id: I7b47acf48def7d4c5f4b74e4dba1c23d8ac7abf2
1 parent 65b667a commit e74f2d9

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

openstackclient/compute/v2/hypervisor.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def get_parser(self, prog_name):
6969
parser.add_argument(
7070
'--matching',
7171
metavar='<hostname>',
72-
help=_("Filter hypervisors using <hostname> substring")
72+
help=_(
73+
"Filter hypervisors using <hostname> substring"
74+
"Hypervisor Type and Host IP are not returned "
75+
"when using microversion 2.52 or lower"
76+
)
7377
)
7478
parser.add_argument(
7579
'--marker',
@@ -128,6 +132,9 @@ def take_action(self, parsed_args):
128132
raise exceptions.CommandError(msg)
129133
list_opts['limit'] = parsed_args.limit
130134

135+
if parsed_args.matching:
136+
list_opts['hypervisor_hostname_pattern'] = parsed_args.matching
137+
131138
column_headers = (
132139
"ID",
133140
"Hypervisor Hostname",
@@ -142,6 +149,7 @@ def take_action(self, parsed_args):
142149
'host_ip',
143150
'state'
144151
)
152+
145153
if parsed_args.long:
146154
if not sdk_utils.supports_microversion(compute_client, '2.88'):
147155
column_headers += (
@@ -157,11 +165,7 @@ def take_action(self, parsed_args):
157165
'memory_size'
158166
)
159167

160-
if parsed_args.matching:
161-
data = compute_client.find_hypervisor(
162-
parsed_args.matching, ignore_missing=False)
163-
else:
164-
data = compute_client.hypervisors(**list_opts, details=True)
168+
data = compute_client.hypervisors(**list_opts, details=True)
165169

166170
return (
167171
column_headers,

openstackclient/tests/unit/compute/v2/test_hypervisor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def test_hypervisor_list_matching_option_found(self):
131131
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
132132

133133
# Fake the return value of search()
134-
self.sdk_client.find_hypervisor.return_value = [self.hypervisors[0]]
134+
self.sdk_client.hypervisors.return_value = [self.hypervisors[0]]
135+
135136
self.data = (
136137
(
137138
self.hypervisors[0].id,
@@ -147,10 +148,9 @@ def test_hypervisor_list_matching_option_found(self):
147148
# containing the data to be listed.
148149
columns, data = self.cmd.take_action(parsed_args)
149150

150-
self.sdk_client.find_hypervisor.assert_called_with(
151-
self.hypervisors[0].name,
152-
ignore_missing=False
153-
)
151+
self.sdk_client.hypervisors.assert_called_with(
152+
hypervisor_hostname_pattern=self.hypervisors[0].name,
153+
details=True)
154154
self.assertEqual(self.columns, columns)
155155
self.assertEqual(self.data, tuple(data))
156156

@@ -164,7 +164,7 @@ def test_hypervisor_list_matching_option_not_found(self):
164164
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
165165

166166
# Fake exception raised from search()
167-
self.sdk_client.find_hypervisor.side_effect = \
167+
self.sdk_client.hypervisors.side_effect = \
168168
exceptions.NotFound(None)
169169

170170
self.assertRaises(exceptions.NotFound,

0 commit comments

Comments
 (0)