Skip to content

Commit 360853b

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add unit tests for "host list" and "host show" commands"
2 parents ab18045 + 5951026 commit 360853b

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

openstackclient/tests/compute/v2/fakes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,13 @@ def create_one_host(attrs=None):
11661166
"stats": "",
11671167
"numa_topology": "",
11681168
"ram_allocation_ratio": 1.0,
1169-
"cpu_allocation_ratio": 1.0
1169+
"cpu_allocation_ratio": 1.0,
1170+
"zone": 'zone-' + uuid.uuid4().hex,
1171+
"host_name": 'name-' + uuid.uuid4().hex,
1172+
"service": 'service-' + uuid.uuid4().hex,
1173+
"cpu": 4,
1174+
"disk_gb": 100,
1175+
'project': 'project-' + uuid.uuid4().hex,
11701176
}
11711177
host_info.update(attrs)
11721178
host = fakes.FakeResource(

openstackclient/tests/compute/v2/test_host.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from openstackclient.compute.v2 import host
1717
from openstackclient.tests.compute.v2 import fakes as compute_fakes
18+
from openstackclient.tests import utils as tests_utils
1819

1920

2021
class TestHost(compute_fakes.TestComputev2):
@@ -27,6 +28,58 @@ def setUp(self):
2728
self.host_mock.reset_mock()
2829

2930

31+
class TestHostList(TestHost):
32+
33+
host = compute_fakes.FakeHost.create_one_host()
34+
35+
columns = (
36+
'Host Name',
37+
'Service',
38+
'Zone',
39+
)
40+
41+
data = [(
42+
host.host_name,
43+
host.service,
44+
host.zone,
45+
)]
46+
47+
def setUp(self):
48+
super(TestHostList, self).setUp()
49+
50+
self.host_mock.list_all.return_value = [self.host]
51+
52+
self.cmd = host.ListHost(self.app, None)
53+
54+
def test_host_list_no_option(self):
55+
arglist = []
56+
verifylist = []
57+
58+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
59+
60+
columns, data = self.cmd.take_action(parsed_args)
61+
62+
self.host_mock.list_all.assert_called_with(None)
63+
self.assertEqual(self.columns, columns)
64+
self.assertEqual(self.data, list(data))
65+
66+
def test_host_list_with_option(self):
67+
arglist = [
68+
'--zone', self.host.zone,
69+
]
70+
verifylist = [
71+
('zone', self.host.zone),
72+
]
73+
74+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
75+
76+
columns, data = self.cmd.take_action(parsed_args)
77+
78+
self.host_mock.list_all.assert_called_with(self.host.zone)
79+
self.assertEqual(self.columns, columns)
80+
self.assertEqual(self.data, list(data))
81+
82+
3083
class TestHostSet(TestHost):
3184

3285
def setUp(self):
@@ -73,3 +126,54 @@ def test_host_set(self):
73126

74127
body = {'status': 'enable', 'maintenance_mode': 'disable'}
75128
self.host_mock.update.assert_called_with(self.host.host, body)
129+
130+
131+
class TestHostShow(TestHost):
132+
133+
host = compute_fakes.FakeHost.create_one_host()
134+
135+
columns = (
136+
'Host',
137+
'Project',
138+
'CPU',
139+
'Memory MB',
140+
'Disk GB',
141+
)
142+
data = [(
143+
host.host,
144+
host.project,
145+
host.cpu,
146+
host.memory_mb,
147+
host.disk_gb,
148+
)]
149+
150+
def setUp(self):
151+
super(TestHostShow, self).setUp()
152+
153+
self.host_mock.get.return_value = [self.host]
154+
155+
self.cmd = host.ShowHost(self.app, None)
156+
157+
def test_host_show_no_option(self):
158+
arglist = []
159+
verifylist = []
160+
161+
# Missing required args should bail here
162+
self.assertRaises(tests_utils.ParserException, self.check_parser,
163+
self.cmd, arglist, verifylist)
164+
165+
def test_host_show_with_option(self):
166+
arglist = [
167+
self.host.host_name,
168+
]
169+
verifylist = [
170+
('host', self.host.host_name),
171+
]
172+
173+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
174+
175+
columns, data = self.cmd.take_action(parsed_args)
176+
177+
self.host_mock.get.assert_called_with(self.host.host_name)
178+
self.assertEqual(self.columns, columns)
179+
self.assertEqual(self.data, list(data))

0 commit comments

Comments
 (0)