1313# under the License.
1414#
1515
16+ import copy
17+
1618from openstackclient .common import exceptions
1719from openstackclient .compute .v2 import hypervisor
1820from openstackclient .tests .compute .v2 import fakes as compute_fakes
21+ from openstackclient .tests import fakes
1922
2023
2124class TestHypervisor (compute_fakes .TestComputev2 ):
@@ -27,6 +30,10 @@ def setUp(self):
2730 self .hypervisors_mock = self .app .client_manager .compute .hypervisors
2831 self .hypervisors_mock .reset_mock ()
2932
33+ # Get a shortcut to the compute client aggregates mock
34+ self .aggregates_mock = self .app .client_manager .compute .aggregates
35+ self .aggregates_mock .reset_mock ()
36+
3037
3138class TestHypervisorList (TestHypervisor ):
3239
@@ -113,3 +120,101 @@ def test_hypervisor_list_matching_option_not_found(self):
113120 self .assertRaises (exceptions .NotFound ,
114121 self .cmd .take_action ,
115122 parsed_args )
123+
124+
125+ class TestHypervisorShow (TestHypervisor ):
126+
127+ def setUp (self ):
128+ super (TestHypervisorShow , self ).setUp ()
129+
130+ # Fake hypervisors to be listed up
131+ self .hypervisor = compute_fakes .FakeHypervisor .create_one_hypervisor ()
132+
133+ # Return value of utils.find_resource()
134+ self .hypervisors_mock .get .return_value = self .hypervisor
135+
136+ # Return value of compute_client.aggregates.list()
137+ self .aggregates_mock .list .return_value = []
138+
139+ # Return value of compute_client.hypervisors.uptime()
140+ uptime_info = {
141+ 'status' : self .hypervisor .status ,
142+ 'state' : self .hypervisor .state ,
143+ 'id' : self .hypervisor .id ,
144+ 'hypervisor_hostname' : self .hypervisor .hypervisor_hostname ,
145+ 'uptime' : ' 01:28:24 up 3 days, 11:15, 1 user, '
146+ ' load average: 0.94, 0.62, 0.50\n ' ,
147+ }
148+ self .hypervisors_mock .uptime .return_value = fakes .FakeResource (
149+ info = copy .deepcopy (uptime_info ),
150+ loaded = True
151+ )
152+
153+ self .columns = (
154+ 'aggregates' ,
155+ 'cpu_info' ,
156+ 'current_workload' ,
157+ 'disk_available_least' ,
158+ 'free_disk_gb' ,
159+ 'free_ram_mb' ,
160+ 'host_ip' ,
161+ 'hypervisor_hostname' ,
162+ 'hypervisor_type' ,
163+ 'hypervisor_version' ,
164+ 'id' ,
165+ 'local_gb' ,
166+ 'local_gb_used' ,
167+ 'memory_mb' ,
168+ 'memory_mb_used' ,
169+ 'running_vms' ,
170+ 'service_host' ,
171+ 'service_id' ,
172+ 'state' ,
173+ 'status' ,
174+ 'vcpus' ,
175+ 'vcpus_used' ,
176+ )
177+ self .data = (
178+ [],
179+ {'aaa' : 'aaa' },
180+ 0 ,
181+ 50 ,
182+ 50 ,
183+ 1024 ,
184+ '192.168.0.10' ,
185+ self .hypervisor .hypervisor_hostname ,
186+ 'QEMU' ,
187+ 2004001 ,
188+ self .hypervisor .id ,
189+ 50 ,
190+ 0 ,
191+ 1024 ,
192+ 512 ,
193+ 0 ,
194+ 'aaa' ,
195+ 1 ,
196+ 'up' ,
197+ 'enabled' ,
198+ 4 ,
199+ 0 ,
200+ )
201+
202+ # Get the command object to test
203+ self .cmd = hypervisor .ShowHypervisor (self .app , None )
204+
205+ def test_hypervisor_show (self ):
206+ arglist = [
207+ self .hypervisor .hypervisor_hostname ,
208+ ]
209+ verifylist = [
210+ ('hypervisor' , self .hypervisor .hypervisor_hostname ),
211+ ]
212+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
213+
214+ # In base command class ShowOne in cliff, abstractmethod take_action()
215+ # returns a two-part tuple with a tuple of column names and a tuple of
216+ # data to be shown.
217+ columns , data = self .cmd .take_action (parsed_args )
218+
219+ self .assertEqual (self .columns , columns )
220+ self .assertEqual (self .data , data )
0 commit comments