Add testcases for compute.v2.service

Add a set of testcases to test the classes of
ListService and SetService in the compute.v2.service.
And to be consistent with cinder term, use service_binary
to represent the service binary.

Change-Id: I9fe740f07c9ce3afdba7b7cca152d614170abb96
This commit is contained in:
xiexs 2015-11-19 04:07:17 -05:00
parent 27869c0f3f
commit eb8672978c
2 changed files with 109 additions and 5 deletions

View File

@ -25,8 +25,6 @@ from openstackclient.tests import utils
from openstackclient.tests.volume.v2 import fakes as volume_fakes
service_id = '1'
extension_name = 'Multinic'
extension_namespace = 'http://docs.openstack.org/compute/ext/'\
'multinic/api/v1.1'
@ -80,6 +78,15 @@ QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
block_device_mapping = 'vda=' + volume_fakes.volume_name + ':::0'
service_host = 'host_test'
service_binary = 'compute_test'
service_status = 'enabled'
SERVICE = {
'host': service_host,
'binary': service_binary,
'status': service_status,
}
class FakeComputev2Client(object):
def __init__(self, **kwargs):

View File

@ -13,8 +13,11 @@
# under the License.
#
import copy
from openstackclient.compute.v2 import service
from openstackclient.tests.compute.v2 import fakes as compute_fakes
from openstackclient.tests import fakes
class TestService(compute_fakes.TestComputev2):
@ -39,10 +42,10 @@ class TestServiceDelete(TestService):
def test_service_delete_no_options(self):
arglist = [
compute_fakes.service_id,
compute_fakes.service_binary,
]
verifylist = [
('service', compute_fakes.service_id),
('service', compute_fakes.service_binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -50,5 +53,99 @@ class TestServiceDelete(TestService):
self.cmd.take_action(parsed_args)
self.service_mock.delete.assert_called_with(
compute_fakes.service_id,
compute_fakes.service_binary,
)
class TestServiceList(TestService):
def setUp(self):
super(TestServiceList, self).setUp()
self.service_mock.list.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
# Get the command object to test
self.cmd = service.ListService(self.app, None)
def test_service_list(self):
arglist = [
'--host', compute_fakes.service_host,
'--service', compute_fakes.service_binary,
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.service_mock.list.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)
class TestServiceSet(TestService):
def setUp(self):
super(TestServiceSet, self).setUp()
self.service_mock.enable.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
self.service_mock.disable.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
self.cmd = service.SetService(self.app, None)
def test_service_set_enable(self):
arglist = [
compute_fakes.service_host,
compute_fakes.service_binary,
'--enable',
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
('enabled', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)
def test_service_set_disable(self):
arglist = [
compute_fakes.service_host,
compute_fakes.service_binary,
'--disable',
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
('enabled', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.service_mock.disable.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)