Fix unittests after new releases of libraries

ironic-lib and galnceclient releases caused some of unittests to fail,
this change fixes them.

Two unittests in the test_glance_service.py module was depending on
getting an instance of the real glanceclient and it was failing due a
new glanceclient release. This patch is fixing the problem by mocking
the client instanciation.

In case of ironic-lib, new argument was added to make_partitions
function, and the mocks need to be changed.

Closes-bug: #1552839
Closes-Bug: #1552834
Co-Authored-By: Lucas Alvares Gomes <lucasagomes@gmail.com>
Change-Id: Ic9dc3f1016667c6d7ec5ee324d5fff48af82c581
This commit is contained in:
Vladyslav Drok
2016-03-03 20:09:33 +02:00
parent 1f90d8cb2b
commit 036b959b92
2 changed files with 34 additions and 12 deletions

View File

@@ -17,6 +17,7 @@
import datetime
import time
from glanceclient import client as glance_client
from glanceclient import exc as glance_exc
import mock
from oslo_config import cfg
@@ -606,28 +607,44 @@ class TestGlanceImageService(base.TestCase):
wrapped_func = base_image_service.check_image_service(func)
self.assertTrue(wrapped_func(self.service))
def test_check_image_service__no_client_set_http(self):
@mock.patch.object(glance_client, 'Client', autospec=True)
def test_check_image_service__no_client_set_http(self, mock_gclient):
def func(service, *args, **kwargs):
return (self.endpoint, args, kwargs)
endpoint = 'http://123.123.123.123:9292'
mock_gclient.return_value.endpoint = endpoint
self.service.client = None
params = {'image_href': 'http://123.123.123.123:9292/image_uuid'}
params = {'image_href': '%s/image_uuid' % endpoint}
self.config(auth_strategy='keystone', group='glance')
wrapped_func = base_image_service.check_image_service(func)
self.assertEqual(('http://123.123.123.123:9292', (), params),
self.assertEqual((endpoint, (), params),
wrapped_func(self.service, **params))
mock_gclient.assert_called_once_with(
1, endpoint,
**{'insecure': CONF.glance.glance_api_insecure,
'token': self.context.auth_token})
def test_get_image_service__no_client_set_https(self):
@mock.patch.object(glance_client, 'Client', autospec=True)
def test_get_image_service__no_client_set_https(self, mock_gclient):
def func(service, *args, **kwargs):
return (self.endpoint, args, kwargs)
endpoint = 'https://123.123.123.123:9292'
mock_gclient.return_value.endpoint = endpoint
self.service.client = None
params = {'image_href': 'https://123.123.123.123:9292/image_uuid'}
params = {'image_href': '%s/image_uuid' % endpoint}
self.config(auth_strategy='keystone', group='glance')
wrapped_func = base_image_service.check_image_service(func)
self.assertEqual(('https://123.123.123.123:9292', (), params),
self.assertEqual((endpoint, (), params),
wrapped_func(self.service, **params))
mock_gclient.assert_called_once_with(
1, endpoint,
**{'insecure': CONF.glance.glance_api_insecure,
'token': self.context.auth_token})
def _create_failing_glance_client(info):

View File

@@ -375,7 +375,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
make_partitions_expected_args = [dev, root_mb, swap_mb, ephemeral_mb,
configdrive_mb, node_uuid]
make_partitions_expected_kwargs = {'commit': True}
make_partitions_expected_kwargs = {'commit': True, 'disk_label': None}
deploy_kwargs = {}
if boot_option:
@@ -536,7 +536,8 @@ class PhysicalWorkTestCase(tests_base.TestCase):
node_uuid,
commit=True,
boot_option="local",
boot_mode="uefi"),
boot_mode="uefi",
disk_label=None),
mock.call.is_block_device(root_part),
mock.call.is_block_device(swap_part),
mock.call.is_block_device(
@@ -614,7 +615,8 @@ class PhysicalWorkTestCase(tests_base.TestCase):
node_uuid,
commit=True,
boot_option="netboot",
boot_mode="bios"),
boot_mode="bios",
disk_label=None),
mock.call.is_block_device(root_part),
mock.call.populate_image(
image_path, root_part),
@@ -685,7 +687,8 @@ class PhysicalWorkTestCase(tests_base.TestCase):
node_uuid,
commit=True,
boot_option="netboot",
boot_mode="bios"),
boot_mode="bios",
disk_label=None),
mock.call.is_block_device(root_part),
mock.call.is_block_device(swap_part),
mock.call.is_block_device(ephemeral_part),
@@ -764,7 +767,8 @@ class PhysicalWorkTestCase(tests_base.TestCase):
node_uuid,
commit=False,
boot_option="netboot",
boot_mode="bios"),
boot_mode="bios",
disk_label=None),
mock.call.is_block_device(root_part),
mock.call.is_block_device(swap_part),
mock.call.is_block_device(ephemeral_part),
@@ -843,7 +847,8 @@ class PhysicalWorkTestCase(tests_base.TestCase):
node_uuid,
commit=True,
boot_option="netboot",
boot_mode="bios"),
boot_mode="bios",
disk_label=None),
mock.call.is_block_device(root_part),
mock.call.is_block_device(
configdrive_part),