diff --git a/rally/plugins/openstack/scenarios/ceilometer/events.py b/rally/plugins/openstack/scenarios/ceilometer/events.py index b5b98dc6..4c3755dc 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/events.py +++ b/rally/plugins/openstack/scenarios/ceilometer/events.py @@ -17,7 +17,6 @@ Scenarios for Ceilometer Events API. """ from rally import consts -from rally import exceptions from rally.plugins.openstack import scenario from rally.plugins.openstack.scenarios.ceilometer import utils as cutils from rally.plugins.openstack.scenarios.keystone import basic as kbasic @@ -45,10 +44,9 @@ class CeilometerEventsCreateUserAndListEvents(cutils.CeilometerScenario, """ self.admin_keystone.create_user() events = self._list_events() - if not events: - raise exceptions.RallyException( - "Events list is empty, but it should include at least one " - "event about user creation") + msg = ("Events list is empty, but it should include at least one " + "event about user creation") + self.assertTrue(events, msg) @validation.required_services(consts.Service.CEILOMETER, @@ -68,10 +66,9 @@ class CeilometerEventsCreateUserAndListEventTypes(cutils.CeilometerScenario, """ self.admin_keystone.create_user() event_types = self._list_event_types() - if not event_types: - raise exceptions.RallyException( - "Event types list is empty, but it should include at least one" - " type about user creation") + msg = ("Event types list is empty, but it should include at least one" + " type about user creation") + self.assertTrue(event_types, msg) @validation.required_services(consts.Service.CEILOMETER, @@ -91,9 +88,7 @@ class CeilometerEventsCreateUserAndGetEvent(cutils.CeilometerScenario, """ self.admin_keystone.create_user() events = self._list_events() - if not events: - raise exceptions.RallyException( - "Events list is empty, but it should include at least one " - "event about user creation") - event = events[0] - self._get_event(event_id=event.message_id) + msg = ("Events list is empty, but it should include at least one " + "event about user creation") + self.assertTrue(events, msg) + self._get_event(event_id=events[0].message_id) diff --git a/rally/plugins/openstack/scenarios/ceilometer/resources.py b/rally/plugins/openstack/scenarios/ceilometer/resources.py index a331716c..834a5a19 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/resources.py +++ b/rally/plugins/openstack/scenarios/ceilometer/resources.py @@ -13,7 +13,6 @@ # under the License. from rally import consts -from rally import exceptions from rally.plugins.openstack import scenario from rally.plugins.openstack.scenarios.ceilometer import utils as ceiloutils from rally.task import validation @@ -67,10 +66,9 @@ class GetTenantResources(ceiloutils.CeilometerScenario): GET /v2/resources/(resource_id) """ resources = self.context["tenant"].get("resources", []) - if not resources: - msg = ("No resources found for tenant: %s" - % self.context["tenant"].get("name")) - raise exceptions.NotFoundException(message=msg) + msg = ("No resources found for tenant: %s" + % self.context["tenant"].get("name")) + self.assertTrue(resources, msg) for res_id in resources: self._get_resource(res_id) diff --git a/rally/plugins/openstack/scenarios/designate/basic.py b/rally/plugins/openstack/scenarios/designate/basic.py index 7043f877..5de22a7d 100644 --- a/rally/plugins/openstack/scenarios/designate/basic.py +++ b/rally/plugins/openstack/scenarios/designate/basic.py @@ -42,8 +42,11 @@ class CreateAndListDomains(utils.DesignateScenario): performance of the "designate domain-list" command depending on the number of domains owned by users. """ - self._create_domain() - self._list_domains() + domain = self._create_domain() + msg = "Domain isn't created" + self.assertTrue(domain, msg) + list_domains = self._list_domains() + self.assertIn(domain, list_domains) @validation.required_services(consts.Service.DESIGNATE) @@ -170,11 +173,14 @@ class CreateAndListRecords(utils.DesignateScenario): domain = self._create_domain() key = "designate.create_%s_records" % records_per_domain + records = [] with atomic.ActionTimer(self, key): for i in range(records_per_domain): - self._create_record(domain, atomic_action=False) + records.append( + self._create_record(domain, atomic_action=False)) - self._list_records(domain["id"]) + list_records = self._list_records(domain["id"]) + self.assertEqual(records, list_records) @validation.required_services(consts.Service.DESIGNATE) @@ -192,8 +198,10 @@ class CreateAndListServers(utils.DesignateScenario): performance of the "designate server-list" command depending on the number of servers owned by users. """ - self._create_server() - self._list_servers() + server = self._create_server() + self.assertTrue(server) + list_servers = self._list_servers() + self.assertIn(server, list_servers) @validation.required_services(consts.Service.DESIGNATE) @@ -245,8 +253,10 @@ class CreateAndListZones(utils.DesignateScenario): performance of the "openstack zone list" command depending on the number of zones owned by users. """ - self._create_zone() - self._list_zones() + zone = self._create_zone() + self.assertTrue(zone) + list_zones = self._list_zones() + self.assertIn(zone, list_zones) @validation.required_services(consts.Service.DESIGNATE) diff --git a/rally/plugins/openstack/scenarios/glance/images.py b/rally/plugins/openstack/scenarios/glance/images.py index 172e1ca4..bc5efd5a 100644 --- a/rally/plugins/openstack/scenarios/glance/images.py +++ b/rally/plugins/openstack/scenarios/glance/images.py @@ -51,11 +51,13 @@ class CreateAndListImage(utils.GlanceScenario, nova_utils.NovaScenario): ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso :param kwargs: optional parameters to create image """ - self._create_image(container_format, - image_location, - disk_format, - **kwargs) - self._list_images() + image = self._create_image(container_format, + image_location, + disk_format, + **kwargs) + self.assertTrue(image) + image_list = self._list_images() + self.assertIn(image.id, [i.id for i in image_list]) @validation.required_services(consts.Service.GLANCE) @@ -137,6 +139,5 @@ class CreateImageAndBootInstances(utils.GlanceScenario, image_location, disk_format, **create_image_kwargs) - image_id = image.id - self._boot_servers(image_id, flavor, number_instances, + self._boot_servers(image.id, flavor, number_instances, **boot_server_kwargs) diff --git a/rally/plugins/openstack/scenarios/heat/stacks.py b/rally/plugins/openstack/scenarios/heat/stacks.py index 66919a67..0c9d6559 100644 --- a/rally/plugins/openstack/scenarios/heat/stacks.py +++ b/rally/plugins/openstack/scenarios/heat/stacks.py @@ -44,8 +44,11 @@ class CreateAndListStack(utils.HeatScenario): :param files: files used in template :param environment: stack environment definition """ - self._create_stack(template_path, parameters, files, environment) - self._list_stacks() + stack = self._create_stack(template_path, parameters, + files, environment) + self.assertTrue(stack) + list_stacks = self._list_stacks() + self.assertIn(stack.id, [i.id for i in list_stacks]) @validation.required_services(consts.Service.HEAT) diff --git a/rally/plugins/openstack/scenarios/ironic/nodes.py b/rally/plugins/openstack/scenarios/ironic/nodes.py index 3cc3ed0c..ae959c69 100644 --- a/rally/plugins/openstack/scenarios/ironic/nodes.py +++ b/rally/plugins/openstack/scenarios/ironic/nodes.py @@ -61,11 +61,12 @@ class CreateAndListNode(utils.IronicScenario): :param kwargs: Optional additional arguments for node creation """ - self._create_node(**kwargs) - - self._list_nodes( + node = self._create_node(**kwargs) + self.assertTrue(node) + list_nodes = self._list_nodes( associated=associated, maintenance=maintenance, marker=marker, limit=limit, detail=detail, sort_key=sort_key, sort_dir=sort_dir) + self.assertIn(node, list_nodes) @validation.required_parameters("driver") diff --git a/rally/plugins/openstack/scenarios/keystone/basic.py b/rally/plugins/openstack/scenarios/keystone/basic.py index cbc16a6f..431e550a 100644 --- a/rally/plugins/openstack/scenarios/keystone/basic.py +++ b/rally/plugins/openstack/scenarios/keystone/basic.py @@ -153,6 +153,7 @@ class CreateAndListUsers(KeystoneBasic): :param kwargs: Other optional parameters to create users like "tenant_id", "enabled". """ + kwargs.pop("name", None) self.admin_keystone.create_user(**kwargs) self.admin_keystone.list_users() diff --git a/rally/plugins/openstack/scenarios/magnum/clusters.py b/rally/plugins/openstack/scenarios/magnum/clusters.py index f3f0fabf..a4d6618e 100644 --- a/rally/plugins/openstack/scenarios/magnum/clusters.py +++ b/rally/plugins/openstack/scenarios/magnum/clusters.py @@ -61,5 +61,8 @@ class CreateAndListClusters(utils.MagnumScenario): cluster_template_uuid = kwargs.get("cluster_template_uuid", None) if cluster_template_uuid is None: cluster_template_uuid = self.context["tenant"]["cluster_template"] - self._create_cluster(cluster_template_uuid, node_count, **kwargs) - self._list_clusters(**kwargs) + cluster = self._create_cluster(cluster_template_uuid, + node_count, **kwargs) + self.assertTrue(cluster) + list_clusters = self._list_clusters(**kwargs) + self.assertIn(cluster, list_clusters) diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py index 85dbcd9f..506f4cac 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py @@ -104,4 +104,4 @@ class CeilometerResourcesTestCase(test.ScenarioTestCase): context = {"user": {"tenant_id": "fake"}, "tenant": {"id": "fake", "resources": resource_list}} scenario.context = context - self.assertRaises(exceptions.NotFoundException, scenario.run) + self.assertRaises(exceptions.RallyAssertionError, scenario.run) diff --git a/tests/unit/plugins/openstack/scenarios/designate/test_basic.py b/tests/unit/plugins/openstack/scenarios/designate/test_basic.py index e7439220..e35b5db7 100644 --- a/tests/unit/plugins/openstack/scenarios/designate/test_basic.py +++ b/tests/unit/plugins/openstack/scenarios/designate/test_basic.py @@ -16,6 +16,7 @@ import mock +from rally import exceptions from rally.plugins.openstack.scenarios.designate import basic from tests.unit import test @@ -29,10 +30,31 @@ class DesignateBasicTestCase(test.ScenarioTestCase): def test_create_and_list_domains(self, mock__create_domain, mock__list_domains): + mock__create_domain.return_value = "fake_domain.xyz" + mock__list_domains.return_value = (["fake_domain.org", + "fake_domain.xyz", + "ultimate_question.net"]) basic.CreateAndListDomains(self.context).run() mock__create_domain.assert_called_once_with() mock__list_domains.assert_called_once_with() + @mock.patch("%s.CreateAndListDomains._list_domains" % BASE) + @mock.patch("%s.CreateAndListDomains._create_domain" % BASE) + def test_create_and_list_domains_fails(self, + mock__create_domain, + mock__list_domains): + mock__list_domains.return_value = (["fake_domain.org", + "fake_domain.xyz", + "ultimate_question.net"]) + scenario = basic.CreateAndListDomains(self.context) + self.assertRaises(exceptions.RallyAssertionError, scenario.run) + mock__create_domain.assert_called_once_with() + + mock__create_domain.return_value = "fake_not_existed_domain.xyz" + self.assertRaises(exceptions.RallyAssertionError, scenario.run) + mock__create_domain.assert_called_with() + mock__list_domains.assert_called_with() + @mock.patch("%s.CreateAndDeleteDomain._delete_domain" % BASE) @mock.patch("%s.CreateAndDeleteDomain._create_domain" % BASE, return_value={"id": "123"}) @@ -76,12 +98,16 @@ class DesignateBasicTestCase(test.ScenarioTestCase): "id": "123"} mock__create_domain.return_value = domain records_per_domain = 5 + return_value = mock.call(domain, atomic_action=False) + mock__create_record.return_value = return_value + mock__list_records.return_value = [return_value] * records_per_domain basic.CreateAndListRecords(self.context).run( records_per_domain=records_per_domain) mock__create_domain.assert_called_once_with() + self.assertEqual(mock__create_record.mock_calls, - [mock.call(domain, atomic_action=False)] + [return_value] * records_per_domain) mock__list_records.assert_called_once_with(domain["id"]) @@ -122,11 +148,32 @@ class DesignateBasicTestCase(test.ScenarioTestCase): def test_create_and_list_servers(self, mock__create_server, mock__list_servers): + mock__create_server.return_value = "fake_server" + mock__list_servers.return_value = ["fake_srv1", + "fake_srv2", + "fake_server"] + + # Positive case: basic.CreateAndListServers(self.context).run() mock__create_server.assert_called_once_with() mock__list_servers.assert_called_once_with() + # Negative case: server isn't created + mock__create_server.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + basic.CreateAndListServers(self.context).run) + + mock__create_server.assert_called_with() + + # Negative case: server not found in the list of existed servers + mock__create_server.return_value = "The_main_server_of_the_universe" + self.assertRaises(exceptions.RallyAssertionError, + basic.CreateAndListServers(self.context).run) + + mock__create_server.assert_called_with() + mock__list_servers.assert_called_with() + @mock.patch("%s.CreateAndDeleteServer._delete_server" % BASE) @mock.patch("%s.CreateAndDeleteServer._create_server" % BASE, return_value={"id": "123"}) @@ -149,10 +196,28 @@ class DesignateBasicTestCase(test.ScenarioTestCase): def test_create_and_list_zones(self, mock__create_zone, mock__list_zones): + mock__create_zone.return_value = "Area_51" + mock__list_zones.return_value = ["Area_51", + "Siachen", + "Bagram"] + # Positive case: basic.CreateAndListZones(self.context).run() mock__create_zone.assert_called_once_with() mock__list_zones.assert_called_once_with() + # Negative case: zone isn't created + mock__create_zone.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + basic.CreateAndListZones(self.context).run) + mock__create_zone.assert_called_with() + + # Negative case: created zone not in the list of available zones + mock__create_zone.return_value = "HAARP" + self.assertRaises(exceptions.RallyAssertionError, + basic.CreateAndListZones(self.context).run) + mock__create_zone.assert_called_with() + mock__list_zones.assert_called_with() + @mock.patch("%s.CreateAndDeleteZone._delete_zone" % BASE) @mock.patch("%s.CreateAndDeleteZone._create_zone" % BASE, return_value={"id": "123"}) diff --git a/tests/unit/plugins/openstack/scenarios/glance/test_images.py b/tests/unit/plugins/openstack/scenarios/glance/test_images.py index 59a03bcb..9feb3d3a 100644 --- a/tests/unit/plugins/openstack/scenarios/glance/test_images.py +++ b/tests/unit/plugins/openstack/scenarios/glance/test_images.py @@ -15,6 +15,7 @@ import mock +from rally import exceptions from rally.plugins.openstack.scenarios.glance import images from tests.unit import fakes from tests.unit import test @@ -26,18 +27,43 @@ class GlanceImagesTestCase(test.ScenarioTestCase): @mock.patch("%s.CreateAndListImage._list_images" % BASE) @mock.patch("%s.CreateAndListImage._create_image" % BASE) - @mock.patch("%s.CreateAndListImage.generate_random_name" % BASE, - return_value="test-rally-image") def test_create_and_list_image(self, - mock_random_name, mock_create_image, mock_list_images): + + fake_image = fakes.FakeImage(id=1, name="img_name1") + mock_create_image.return_value = fake_image + mock_list_images.return_value = [ + fakes.FakeImage(id=0, name="img_name1"), + fake_image, + fakes.FakeImage(id=2, name="img_name1") + ] + + # Positive case images.CreateAndListImage(self.context).run( "cf", "url", "df", fakearg="f") mock_create_image.assert_called_once_with( "cf", "url", "df", fakearg="f") mock_list_images.assert_called_once_with() + # Negative case: image isn't created + mock_create_image.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + images.CreateAndListImage(self.context).run, + "cf", "url", "df", fakearg="f") + mock_create_image.assert_called_with( + "cf", "url", "df", fakearg="f") + + # Negative case: created image n ot in the list of available images + mock_create_image.return_value = fakes.FakeImage( + id=12, name="img_nameN") + self.assertRaises(exceptions.RallyAssertionError, + images.CreateAndListImage(self.context).run, + "cf", "url", "df", fakearg="f") + mock_create_image.assert_called_with( + "cf", "url", "df", fakearg="f") + mock_list_images.assert_called_with() + @mock.patch("%s.ListImages._list_images" % BASE) def test_list_images(self, mock_list_images__list_images): images.ListImages(self.context).run() diff --git a/tests/unit/plugins/openstack/scenarios/heat/test_stacks.py b/tests/unit/plugins/openstack/scenarios/heat/test_stacks.py index 29562fd6..a6acae0f 100644 --- a/tests/unit/plugins/openstack/scenarios/heat/test_stacks.py +++ b/tests/unit/plugins/openstack/scenarios/heat/test_stacks.py @@ -15,6 +15,7 @@ import mock +from rally import exceptions from rally.plugins.openstack.scenarios.heat import stacks from tests.unit import test @@ -33,12 +34,14 @@ class HeatStacksTestCase(test.ScenarioTestCase): @mock.patch("%s.CreateAndListStack._list_stacks" % BASE) @mock.patch("%s.CreateAndListStack._create_stack" % BASE) - @mock.patch("%s.CreateAndListStack.generate_random_name" % BASE, - return_value="test-rally-stack") def test_create_and_list_stack(self, - mock_generate_random_name, mock__create_stack, mock__list_stacks): + stack = mock.Mock() + mock__create_stack.return_value = stack + mock__list_stacks.return_value = [stack] * 3 + + # Positive case: stacks.CreateAndListStack(self.context).run( template_path=self.default_template, parameters=self.default_parameters, @@ -50,6 +53,34 @@ class HeatStacksTestCase(test.ScenarioTestCase): self.default_files, self.default_environment) mock__list_stacks.assert_called_once_with() + # Negative case1: stack isn't created + mock__create_stack.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + stacks.CreateAndListStack(self.context).run, + template_path=self.default_template, + parameters=self.default_parameters, + files=self.default_files, + environment=self.default_environment) + + mock__create_stack.assert_called_with( + self.default_template, self.default_parameters, + self.default_files, self.default_environment) + + # Negative case2: created stack not in the list of available stacks + fake_stack = mock.Mock() + mock__create_stack.return_value = fake_stack + self.assertRaises(exceptions.RallyAssertionError, + stacks.CreateAndListStack(self.context).run, + template_path=self.default_template, + parameters=self.default_parameters, + files=self.default_files, + environment=self.default_environment) + + mock__create_stack.assert_called_with( + self.default_template, self.default_parameters, + self.default_files, self.default_environment) + mock__list_stacks.assert_called_with() + @mock.patch("%s.ListStacksAndResources._list_stacks" % BASE) def test_list_stack_and_resources(self, mock__list_stacks): stack = mock.Mock() diff --git a/tests/unit/plugins/openstack/scenarios/ironic/test_nodes.py b/tests/unit/plugins/openstack/scenarios/ironic/test_nodes.py index 406059c8..3cef0d2c 100644 --- a/tests/unit/plugins/openstack/scenarios/ironic/test_nodes.py +++ b/tests/unit/plugins/openstack/scenarios/ironic/test_nodes.py @@ -15,6 +15,7 @@ import mock +from rally import exceptions from rally.plugins.openstack.scenarios.ironic import nodes from tests.unit import test @@ -23,8 +24,10 @@ class IronicNodesTestCase(test.ScenarioTestCase): def test_create_and_list_node(self): scenario = nodes.CreateAndListNode(self.context) - scenario._create_node = mock.Mock() - scenario._list_nodes = mock.Mock() + scenario._create_node = mock.Mock(return_value="node_obj1") + scenario._list_nodes = mock.Mock(return_value=["node_obj1", + "node_obj2", + "node_obj3"]) fake_params = { "sort_dir": "foo1", "associated": "foo2", @@ -35,6 +38,8 @@ class IronicNodesTestCase(test.ScenarioTestCase): "marker": "foo6", "fake_parameter1": "foo7" } + + # Positive case: scenario.run(**fake_params) scenario._create_node.assert_called_once_with(fake_parameter1="foo7") @@ -42,6 +47,25 @@ class IronicNodesTestCase(test.ScenarioTestCase): sort_dir="foo1", associated="foo2", sort_key="foo3", detail=True, limit="foo4", maintenance="foo5", marker="foo6") + # Negative case1: node isn't created + scenario._create_node = mock.Mock(return_value=None) + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, + **fake_params) + + scenario._create_node.assert_called_with(fake_parameter1="foo7") + + # Negative case2: cretaed node not in the list of available nodes + scenario._create_node = mock.Mock() + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, + **fake_params) + + scenario._create_node.assert_called_with(fake_parameter1="foo7") + scenario._list_nodes.assert_called_with( + sort_dir="foo1", associated="foo2", sort_key="foo3", detail=True, + limit="foo4", maintenance="foo5", marker="foo6") + def test_create_and_delete_node(self): fake_node = mock.Mock(uuid="fake_uuid") scenario = nodes.CreateAndDeleteNode(self.context) diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py index 0774f4e9..bfcc369e 100755 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py @@ -129,7 +129,6 @@ class KeystoneBasicTestCase(test.ScenarioTestCase): def test_create_and_list_tenants(self): identity_service = self.mock_identity.return_value scenario = basic.CreateAndListTenants(self.context) - scenario.run(enabled=True) identity_service.create_project.assert_called_once_with(enabled=True) identity_service.list_projects.assert_called_once_with() diff --git a/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py b/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py index 037106a6..ec81bda8 100644 --- a/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py +++ b/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py @@ -15,6 +15,7 @@ import ddt import mock +from rally import exceptions from rally.plugins.openstack.scenarios.magnum import clusters from tests.unit import test @@ -50,24 +51,60 @@ class MagnumClustersTestCase(test.ScenarioTestCase): "fakearg": "f"} fake_cluster = mock.Mock() scenario._create_cluster = mock.Mock(return_value=fake_cluster) - scenario._list_clusters = mock.Mock() + scenario._list_clusters = mock.Mock(return_value=[fake_cluster, + mock.Mock(), + mock.Mock()]) + # Positive case scenario.run(2, **kwargs) scenario._create_cluster.assert_called_once_with( "existing_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs) + # Negative case1: cluster isn't created + scenario._create_cluster.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, 2, **kwargs) + scenario._create_cluster.assert_called_with( + "existing_cluster_template_uuid", 2, **kwargs) + + # Negative case2: created cluster not in the list of available clusters + scenario._create_cluster.return_value = mock.MagicMock() + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, 2, **kwargs) + scenario._create_cluster.assert_called_with( + "existing_cluster_template_uuid", 2, **kwargs) + scenario._list_clusters.assert_called_with(**kwargs) + def test_create_and_list_clusters(self): context = self._get_context() scenario = clusters.CreateAndListClusters(context) fake_cluster = mock.Mock() kwargs = {"fakearg": "f"} scenario._create_cluster = mock.Mock(return_value=fake_cluster) - scenario._list_clusters = mock.Mock() + scenario._list_clusters = mock.Mock(return_value=[fake_cluster, + mock.Mock(), + mock.Mock()]) + # Positive case scenario.run(2, **kwargs) scenario._create_cluster.assert_called_once_with( "rally_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs) + + # Negative case1: cluster isn't created + scenario._create_cluster.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, 2, **kwargs) + scenario._create_cluster.assert_called_with( + "rally_cluster_template_uuid", 2, **kwargs) + + # Negative case2: created cluster not in the list of available clusters + scenario._create_cluster.return_value = mock.MagicMock() + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, 2, **kwargs) + scenario._create_cluster.assert_called_with( + "rally_cluster_template_uuid", 2, **kwargs) + scenario._list_clusters.assert_called_with(**kwargs) diff --git a/tests/unit/plugins/openstack/scenarios/manila/test_shares.py b/tests/unit/plugins/openstack/scenarios/manila/test_shares.py index 4dc7faa9..4d6c49ba 100644 --- a/tests/unit/plugins/openstack/scenarios/manila/test_shares.py +++ b/tests/unit/plugins/openstack/scenarios/manila/test_shares.py @@ -106,8 +106,13 @@ class ManilaSharesTestCase(test.ScenarioTestCase): ) def test_create_share_network_and_list(self, params): scenario = shares.CreateShareNetworkAndList(self.context) - scenario._create_share_network = mock.MagicMock() - scenario._list_share_networks = mock.MagicMock() + fake_network = mock.Mock() + scenario._create_share_network = mock.Mock( + return_value=fake_network) + scenario._list_share_networks = mock.Mock( + return_value=[fake_network, + mock.Mock(), + mock.Mock()]) expected_create_params = { "description": params.get("description"), "neutron_net_id": params.get("neutron_net_id"),