From 61d006f2785139bbfa7c08ba33f30de4446e6996 Mon Sep 17 00:00:00 2001 From: Igor Malinovskiy Date: Thu, 28 May 2015 10:50:46 +0300 Subject: [PATCH] Implement tempest tests for share extend API - Add positive and negative share extend test Change-Id: Ibf2416dcc51a547ca384833bbc3dade6e530ca43 --- .../tempest/api/share/test_shares_actions.py | 16 ++++ .../api/share/test_shares_actions_negative.py | 92 +++++++++++++++++++ contrib/tempest/tempest/config_share.py | 5 + .../services/share/json/shares_client.py | 11 +++ 4 files changed, 124 insertions(+) create mode 100644 contrib/tempest/tempest/api/share/test_shares_actions_negative.py diff --git a/contrib/tempest/tempest/api/share/test_shares_actions.py b/contrib/tempest/tempest/api/share/test_shares_actions.py index 53f32a76..a4806a64 100644 --- a/contrib/tempest/tempest/api/share/test_shares_actions.py +++ b/contrib/tempest/tempest/api/share/test_shares_actions.py @@ -378,6 +378,22 @@ class SharesActionsTest(base.BaseSharesTest): sorted_list = [snap['share_id'] for snap in snaps] self.assertEqual(sorted_list, sorted(sorted_list)) + @test.attr(type=["gate", ]) + @testtools.skipUnless( + CONF.share.run_extend_tests, + "Share extend tests are disabled.") + def test_extend_share(self): + share = self.create_share(size=1, cleanup_in_class=False) + new_size = 2 + + # extend share and wait for active status + self.shares_client.extend_share(share['id'], new_size) + self.shares_client.wait_for_share_status(share['id'], 'available') + + # check state and new size + share = self.shares_client.get_share(share['id']) + self.assertEqual(new_size, share['size']) + class SharesRenameTest(base.BaseSharesTest): diff --git a/contrib/tempest/tempest/api/share/test_shares_actions_negative.py b/contrib/tempest/tempest/api/share/test_shares_actions_negative.py new file mode 100644 index 00000000..cdd664e4 --- /dev/null +++ b/contrib/tempest/tempest/api/share/test_shares_actions_negative.py @@ -0,0 +1,92 @@ +# Copyright 2015 Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib import exceptions as lib_exc # noqa +import testtools # noqa + +from tempest.api.share import base +from tempest import clients_share as clients +from tempest import config_share as config +from tempest import test + +CONF = config.CONF + + +class SharesActionsNegativeTest(base.BaseSharesTest): + @classmethod + def resource_setup(cls): + super(SharesActionsNegativeTest, cls).resource_setup() + cls.share = cls.create_share( + size=1, + ) + + @test.attr(type=["negative", ]) + @testtools.skipUnless( + CONF.share.run_extend_tests, + "Share extend tests are disabled.") + def test_share_extend_over_quota(self): + tenant_quotas = self.shares_client.show_quotas( + self.shares_client.tenant_id) + new_size = int(tenant_quotas["gigabytes"]) + 1 + + # extend share with over quota and check result + self.assertRaises(lib_exc.Forbidden, + self.shares_client.extend_share, + self.share['id'], + new_size) + + @test.attr(type=["negative", ]) + @testtools.skipUnless( + CONF.share.run_extend_tests, + "Share extend tests are disabled.") + def test_share_extend_with_less_size(self): + new_size = int(self.share['size']) - 1 + + # extend share with invalid size and check result + self.assertRaises(lib_exc.BadRequest, + self.shares_client.extend_share, + self.share['id'], + new_size) + + @test.attr(type=["negative", ]) + @testtools.skipUnless( + CONF.share.run_extend_tests, + "Share extend tests are disabled.") + def test_share_extend_with_same_size(self): + new_size = int(self.share['size']) + + # extend share with invalid size and check result + self.assertRaises(lib_exc.BadRequest, + self.shares_client.extend_share, + self.share['id'], + new_size) + + @test.attr(type=["negative", ]) + @testtools.skipUnless( + CONF.share.run_extend_tests, + "Share extend tests are disabled.") + def test_share_extend_with_invalid_share_state(self): + share = self.create_share(size=1, cleanup_in_class=False) + new_size = int(share['size']) + 1 + + # set "error" state + admin_client = clients.AdminManager().shares_client + admin_client.reset_state(share['id']) + + # run extend operation on same share and check result + self.assertRaises(lib_exc.BadRequest, + self.shares_client.extend_share, + share['id'], + new_size) \ No newline at end of file diff --git a/contrib/tempest/tempest/config_share.py b/contrib/tempest/tempest/config_share.py index 21f78845..54961a24 100644 --- a/contrib/tempest/tempest/config_share.py +++ b/contrib/tempest/tempest/config_share.py @@ -123,6 +123,11 @@ ShareGroup = [ cfg.StrOpt("image_password", default="ubuntu", help="Image password."), + cfg.BoolOpt("run_extend_tests", + default=True, + help="Defines whether to run share extend tests or not." + "Disable this feature if used driver doesn't " + "support it."), ] diff --git a/contrib/tempest/tempest/services/share/json/shares_client.py b/contrib/tempest/tempest/services/share/json/shares_client.py index cc4b733a..f665b723 100644 --- a/contrib/tempest/tempest/services/share/json/shares_client.py +++ b/contrib/tempest/tempest/services/share/json/shares_client.py @@ -157,6 +157,17 @@ class SharesClient(rest_client.RestClient): self.expected_success(202, resp.status) return body + def extend_share(self, share_id, new_size): + post_body = { + "os-extend": { + "new_size": new_size, + } + } + body = json.dumps(post_body) + resp, body = self.post("shares/%s/action" % share_id, body) + self.expected_success(202, resp.status) + return body + def create_snapshot(self, share_id, name=None, description=None, force=False): if name is None: