From eb8672978c84e5756d368d03658f16177cb8f126 Mon Sep 17 00:00:00 2001 From: xiexs Date: Thu, 19 Nov 2015 04:07:17 -0500 Subject: [PATCH] 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 --- openstackclient/tests/compute/v2/fakes.py | 11 +- .../tests/compute/v2/test_service.py | 103 +++++++++++++++++- 2 files changed, 109 insertions(+), 5 deletions(-) diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 0d6cd43058..64485e9c66 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -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): diff --git a/openstackclient/tests/compute/v2/test_service.py b/openstackclient/tests/compute/v2/test_service.py index c6db30ac27..380fbc4f3b 100644 --- a/openstackclient/tests/compute/v2/test_service.py +++ b/openstackclient/tests/compute/v2/test_service.py @@ -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, )