diff --git a/rally-jobs/rally-manila.yaml b/rally-jobs/rally-manila.yaml index c9037bd513..bddc172492 100644 --- a/rally-jobs/rally-manila.yaml +++ b/rally-jobs/rally-manila.yaml @@ -32,3 +32,22 @@ sla: failure_rate: max: 0 + + ManilaShares.create_share_network_and_delete: + - + args: + name: "rally" + runner: + type: "constant" + times: 10 + concurrency: 10 + context: + quotas: + manila: + share_networks: -1 + users: + tenants: 2 + users_per_tenant: 1 + sla: + failure_rate: + max: 0 diff --git a/rally/plugins/openstack/context/cleanup/resources.py b/rally/plugins/openstack/context/cleanup/resources.py index a9d940bd17..421fa9b10d 100644 --- a/rally/plugins/openstack/context/cleanup/resources.py +++ b/rally/plugins/openstack/context/cleanup/resources.py @@ -261,6 +261,12 @@ class ManilaShare(base.ResourceManager): pass +@base.resource("manila", "share_networks", order=next(_manila_order), + tenant_resource=True) +class ManilaShareNetwork(base.ResourceManager): + pass + + # GLANCE @base.resource("glance", "images", order=500, tenant_resource=True) diff --git a/rally/plugins/openstack/scenarios/manila/shares.py b/rally/plugins/openstack/scenarios/manila/shares.py index b32b0f8be3..16c77ae193 100644 --- a/rally/plugins/openstack/scenarios/manila/shares.py +++ b/rally/plugins/openstack/scenarios/manila/shares.py @@ -60,3 +60,29 @@ class ManilaShares(utils.ManilaScenario): "name", "host", "share_type", etc. """ self._list_shares(detailed=detailed, search_opts=search_opts) + + @validation.required_services(consts.Service.MANILA) + @validation.required_openstack(users=True) + @base.scenario(context={"cleanup": ["manila"]}) + def create_share_network_and_delete(self, + neutron_net_id=None, + neutron_subnet_id=None, + nova_net_id=None, + name=None, + description=None): + """Creates share network and then deletes. + + :param neutron_net_id: ID of Neutron network + :param neutron_subnet_id: ID of Neutron subnet + :param nova_net_id: ID of Nova network + :param name: share network name + :param description: share network description + """ + share_network = self._create_share_network( + neutron_net_id=neutron_net_id, + neutron_subnet_id=neutron_subnet_id, + nova_net_id=nova_net_id, + name=name, + description=description, + ) + self._delete_share_network(share_network) diff --git a/rally/plugins/openstack/scenarios/manila/utils.py b/rally/plugins/openstack/scenarios/manila/utils.py index c03f4b9096..11dd1a9b36 100644 --- a/rally/plugins/openstack/scenarios/manila/utils.py +++ b/rally/plugins/openstack/scenarios/manila/utils.py @@ -111,3 +111,38 @@ class ManilaScenario(base.Scenario): """ return self.clients("manila").shares.list( detailed=detailed, search_opts=search_opts) + + @base.atomic_action_timer("manila.create_share_network") + def _create_share_network(self, neutron_net_id=None, + neutron_subnet_id=None, + nova_net_id=None, name=None, description=None): + """Create share network. + + :param neutron_net_id: ID of Neutron network + :param neutron_subnet_id: ID of Neutron subnet + :param nova_net_id: ID of Nova network + :param name: share network name + :param description: share network description + :returns: instance of :class:`ShareNetwork` + """ + name = name or self._generate_random_name() + share_network = self.clients("manila").share_networks.create( + neutron_net_id=neutron_net_id, + neutron_subnet_id=neutron_subnet_id, + nova_net_id=nova_net_id, + name=name, + description=description) + return share_network + + @base.atomic_action_timer("manila.delete_share_network") + def _delete_share_network(self, share_network): + """Delete share network. + + :param share_network: instance of :class:`ShareNetwork`. + """ + share_network.delete() + bench_utils.wait_for_delete( + share_network, + update_resource=bench_utils.get_from_manager(), + timeout=CONF.benchmark.manila_share_delete_timeout, + check_interval=CONF.benchmark.manila_share_delete_poll_interval) diff --git a/samples/tasks/scenarios/manila/create-share-network-and-delete.json b/samples/tasks/scenarios/manila/create-share-network-and-delete.json new file mode 100644 index 0000000000..7ec3d85798 --- /dev/null +++ b/samples/tasks/scenarios/manila/create-share-network-and-delete.json @@ -0,0 +1,25 @@ +{ + "ManilaShares.create_share_network_and_delete": [ + { + "args": { + "name": "rally" + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 10 + }, + "context": { + "quotas": { + "manila": { + "share_networks": -1 + } + }, + "users": { + "tenants": 2, + "users_per_tenant": 1 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/manila/create-share-network-and-delete.yaml b/samples/tasks/scenarios/manila/create-share-network-and-delete.yaml new file mode 100644 index 0000000000..8693c87864 --- /dev/null +++ b/samples/tasks/scenarios/manila/create-share-network-and-delete.yaml @@ -0,0 +1,16 @@ +--- + ManilaShares.create_share_network_and_delete: + - + args: + name: "rally" + runner: + type: "constant" + times: 10 + concurrency: 10 + context: + quotas: + manila: + share_networks: -1 + users: + tenants: 2 + users_per_tenant: 1 diff --git a/tests/unit/plugins/openstack/context/cleanup/test_resources.py b/tests/unit/plugins/openstack/context/cleanup/test_resources.py index 039501f9b5..1aa729cd84 100644 --- a/tests/unit/plugins/openstack/context/cleanup/test_resources.py +++ b/tests/unit/plugins/openstack/context/cleanup/test_resources.py @@ -458,3 +458,26 @@ class ManilaShareTestCase(test.TestCase): self.assertEqual("shares", share_resource._resource) share_resource._manager.return_value.delete.assert_called_once_with( "fake_id") + + +class ManilaShareNetworkTestCase(test.TestCase): + + def test_list(self): + sn_resource = resources.ManilaShareNetwork() + sn_resource._manager = mock.MagicMock() + + sn_resource.list() + + self.assertEqual("share_networks", sn_resource._resource) + sn_resource._manager.return_value.list.assert_called_once_with() + + def test_delete(self): + sn_resource = resources.ManilaShareNetwork() + sn_resource._manager = mock.MagicMock() + sn_resource.id = lambda: "fake_id" + + sn_resource.delete() + + self.assertEqual("share_networks", sn_resource._resource) + sn_resource._manager.return_value.delete.assert_called_once_with( + "fake_id") diff --git a/tests/unit/plugins/openstack/scenarios/manila/test_shares.py b/tests/unit/plugins/openstack/scenarios/manila/test_shares.py index 418156fdbf..3a9118dbb2 100644 --- a/tests/unit/plugins/openstack/scenarios/manila/test_shares.py +++ b/tests/unit/plugins/openstack/scenarios/manila/test_shares.py @@ -62,3 +62,36 @@ class ManilaSharesTestCase(test.TestCase): scenario._list_shares.assert_called_once_with( detailed=detailed, search_opts=search_opts) + + @ddt.data( + {}, + {"name": "foo_name"}, + {"description": "foo_description"}, + {"neutron_net_id": "foo_neutron_net_id"}, + {"neutron_subnet_id": "foo_neutron_subnet_id"}, + {"nova_net_id": "foo_nova_net_id"}, + {"name": "foo_name", + "description": "foo_description", + "neutron_net_id": "foo_neutron_net_id", + "neutron_subnet_id": "foo_neutron_subnet_id", + "nova_net_id": "foo_nova_net_id"}, + ) + def test_create_share_network_and_delete(self, params): + fake_sn = mock.MagicMock() + scenario = shares.ManilaShares() + scenario._create_share_network = mock.MagicMock(return_value=fake_sn) + scenario._delete_share_network = mock.MagicMock() + expected_params = { + "name": None, + "description": None, + "neutron_net_id": None, + "neutron_subnet_id": None, + "nova_net_id": None, + } + expected_params.update(params) + + scenario.create_share_network_and_delete(**params) + + scenario._create_share_network.assert_called_once_with( + **expected_params) + scenario._delete_share_network.assert_called_once_with(fake_sn) diff --git a/tests/unit/plugins/openstack/scenarios/manila/test_utils.py b/tests/unit/plugins/openstack/scenarios/manila/test_utils.py index 7d1a6dc88f..33578b5954 100644 --- a/tests/unit/plugins/openstack/scenarios/manila/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/manila/test_utils.py @@ -81,3 +81,35 @@ class ManilaScenarioTestCase(test.ClientsTestCase): self.clients("manila").shares.list.assert_called_once_with( detailed=params.get("detailed", True), search_opts=params.get("search_opts", None)) + + @ddt.data(None, "", "SomeName") + def test__create_share_network(self, name): + fake_sn = mock.Mock() + self.scenario._generate_random_name = mock.Mock() + self.clients("manila").share_networks.create.return_value = fake_sn + data = { + "neutron_net_id": "fake_neutron_net_id", + "neutron_subnet_id": "fake_neutron_subnet_id", + "nova_net_id": "fake_nova_net_id", + "name": name or self.scenario._generate_random_name.return_value, + "description": "fake_description", + } + + result = self.scenario._create_share_network(**data) + + self.assertEqual(fake_sn, result) + self.clients("manila").share_networks.create.assert_called_once_with( + **data) + + @mock.patch(BM_UTILS + "get_from_manager") + @mock.patch(BM_UTILS + "wait_for_delete") + def test__delete_share_network(self, mock_wait_for_delete, + mock_get_from_manager): + fake_sn = mock.MagicMock() + + self.scenario._delete_share_network(fake_sn) + + fake_sn.delete.assert_called_once_with() + mock_get_from_manager.assert_called_once_with() + mock_wait_for_delete.assert_called_once_with( + fake_sn, update_resource=mock.ANY, timeout=180, check_interval=2)