Fix various bugs in tests/code that creates

These bugs creates a lot of logs/traces/warnings during unit testing

Release-notes-impact:
CinderVolumes.create_nested_snapshots_and_attach_volume removed
abbility to pass nested_level as a dict, use always int now.

Change-Id: Ie0cd81da00a2a5d9129a9df38d9d5abe5647b695
This commit is contained in:
Boris Pavlovic 2016-04-13 00:41:16 -07:00
parent 15dd4b5aaf
commit c55a196cbb
4 changed files with 50 additions and 32 deletions

View File

@ -364,11 +364,9 @@ class CinderVolumes(cinder_utils.CinderScenario,
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["cinder", "nova"]})
@logging.log_deprecated_args("Use 'nested_level' as an int", "0.1.2",
["nested_level"], once=True)
def create_nested_snapshots_and_attach_volume(self,
size=None,
nested_level=None,
nested_level=1,
**kwargs):
"""Create a volume from snapshot and attach/detach the volume
@ -382,25 +380,12 @@ class CinderVolumes(cinder_utils.CinderScenario,
min - minimum size volumes will be created as;
max - maximum size volumes will be created as.
default values: {"min": 1, "max": 5}
:param nested_level: Nested level - dictionary or int, dictionary
contains two values:
min - minimum number of volumes will be created
from snapshot;
max - maximum number of volumes will be created
from snapshot.
due to its deprecated would be taken min value.
int, means the exact nested level.
default value: 1.
:param nested_level: amount of nested levels
:param kwargs: Optional parameters used during volume
snapshot creation.
"""
if size is None:
size = {"min": 1, "max": 5}
if nested_level is None:
nested_level = 1
nested_level = nested_level or 1
if isinstance(nested_level, dict):
nested_level = nested_level.get("min", 1)
# NOTE: Volume size cannot be smaller than the snapshot size, so
# volume with specified size should be created to avoid

View File

@ -238,8 +238,10 @@ class SeekAndDestroyTestCase(test.TestCase):
expected_queue += [(admin, users[1], x) for x in range(4, 6)]
self.assertEqual(queue, expected_queue)
@mock.patch("%s.LOG" % BASE)
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
def test__gen_publisher_tenant_resource(self, mock__get_cached_client):
def test__gen_publisher_tenant_resource(self, mock__get_cached_client,
mock_log):
mock_mgr = self._manager([Exception, [1, 2, 3],
Exception, Exception, Exception,
["this shouldn't be in results"]],
@ -273,6 +275,8 @@ class SeekAndDestroyTestCase(test.TestCase):
mock.call(users[2])
])
self.assertEqual(queue, [(None, users[0], x) for x in range(1, 4)])
self.assertTrue(mock_log.warning.mock_called)
self.assertTrue(mock_log.exception.mock_called)
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
@mock.patch("%s.SeekAndDestroy._delete_single_resource" % BASE)

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from rally import exceptions
@ -20,16 +21,30 @@ from rally.plugins.openstack.wrappers import cinder as cinder_wrapper
from tests.unit import test
class CinderWrapperTestBase(object):
def test_wrap(self):
@ddt.ddt
class CinderWrapperTestCase(test.ScenarioTestCase):
@ddt.data(
{"version": "1", "expected_class": cinder_wrapper.CinderV1Wrapper},
{"version": "2", "expected_class": cinder_wrapper.CinderV2Wrapper}
)
@ddt.unpack
def test_wrap(self, version, expected_class):
client = mock.MagicMock()
owner = mock.Mock()
client.version = "dummy"
client.choose_version.return_value = version
self.assertIsInstance(cinder_wrapper.wrap(client, mock.Mock()),
expected_class)
@mock.patch("rally.plugins.openstack.wrappers.cinder.LOG")
def test_wrap_wrong_version(self, mock_log):
client = mock.MagicMock()
client.choose_version.return_value = "dummy"
self.assertRaises(exceptions.InvalidArgumentsException,
cinder_wrapper.wrap, client, owner)
cinder_wrapper.wrap, client, mock.Mock())
self.assertTrue(mock_log.warning.mock_called)
class CinderV1WrapperTestCase(test.TestCase, CinderWrapperTestBase):
class CinderV1WrapperTestCase(test.TestCase):
def setUp(self):
super(CinderV1WrapperTestCase, self).setUp()
self.client = mock.MagicMock()
@ -59,7 +74,7 @@ class CinderV1WrapperTestCase(test.TestCase, CinderWrapperTestBase):
display_name=self.owner.generate_random_name.return_value))
class CinderV2WrapperTestCase(test.TestCase, CinderWrapperTestBase):
class CinderV2WrapperTestCase(test.TestCase):
def setUp(self):
super(CinderV2WrapperTestCase, self).setUp()
self.client = mock.MagicMock()

View File

@ -27,17 +27,31 @@ from tests.unit import test
CONF = cfg.CONF
class GlanceWrapperTestBase(object):
def test_wrap(self):
@ddt.ddt
class GlanceWrapperTestCase(test.ScenarioTestCase):
@ddt.data(
{"version": "1", "expected_class": glance_wrapper.GlanceV1Wrapper},
{"version": "2", "expected_class": glance_wrapper.GlanceV2Wrapper}
)
@ddt.unpack
def test_wrap(self, version, expected_class):
client = mock.MagicMock()
owner = mock.Mock()
client.version = "dummy"
client.choose_version.return_value = version
self.assertIsInstance(glance_wrapper.wrap(client, mock.Mock()),
expected_class)
@mock.patch("rally.plugins.openstack.wrappers.glance.LOG")
def test_wrap_wrong_version(self, mock_log):
client = mock.MagicMock()
client.choose_version.return_value = "dummy"
self.assertRaises(exceptions.InvalidArgumentsException,
glance_wrapper.wrap, client, owner)
glance_wrapper.wrap, client, mock.Mock())
self.assertTrue(mock_log.warning.mock_called)
@ddt.ddt
class GlanceV1WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
class GlanceV1WrapperTestCase(test.ScenarioTestCase):
_tempfile = tempfile.NamedTemporaryFile()
def setUp(self):
@ -102,7 +116,7 @@ class GlanceV1WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
@ddt.ddt
class GlanceV2WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
class GlanceV2WrapperTestCase(test.ScenarioTestCase):
_tempfile = tempfile.NamedTemporaryFile()
def setUp(self):