Move tacker to new hacking 4.0.0

Hacking 4.0.0 has introduce new optimal assert checks.
Please refer [1] for more details.

Additionally Hacking has enabled some new checks by default,
and the next update to the new release will introduce failures
in tacker pep8 jobs.
The main impact is from I122d250cab90964c346e9d53046a97c25054bc00.

This patch addresses following -

* Adopt new optimal assert checks.
 * [H211] Change assertTrue(isinstance(A, B)) to assertIsInstance(A, B).
 * [H212] Change assertEqual(type(A), B) to assertIsInstance(A, B).
 * [H214] Change assertTrue(A not in B, message) to the more specific
   assertNotIn(A, B, message)

* On bumping up the hacking version, below mention pep8 jobs failed.
  This patch address these issues now, when the new hacking release
  starts being used it will not cause a disruption.

    ./tacker/tests/unit/vnflcm/test_controller.py:343:33:
     F522 '...'.format(...) has unused named argument(s): expected_type
            expected_message = ("Invalid input for field/attribute "
                                ^
    ./tacker/tests/unit/common/test_csar_utils.py:194:16:
    F504 '...' % ... has unused named argument(s): csar
        msg = (('The filename "%(manifest)s" is an invalid name.'
               ^
    ./tacker/vnfm/nfvo_client.py:191:21:
     F523 '...'.format(...) has unused arguments at position(s): 0
                 "not supported.".format(pipeline_type))
                 ^
[1] https://docs.openstack.org/releasenotes/hacking/unreleased.html#relnotes-4-0-0

Change-Id: Iee059c00df1be212ae69fbc77cb783748da206b1
This commit is contained in:
Manpreet Kaur 2020-12-03 01:30:59 +00:00
parent 9e08ffb31c
commit 2f3dc0a991
12 changed files with 35 additions and 35 deletions

View File

@ -162,7 +162,7 @@ class VnfTestToscaCreateFlavorCreation(base.BaseTackerTest):
nova_flavors = self.novaclient().flavors
flavor = nova_flavors.get(flavor_id)
self.assertIsNotNone(flavor)
self.assertEqual(True, "VDU1_flavor_func_flavor" in flavor.name)
self.assertIn('VDU1_flavor_func_flavor', flavor.name)
# Delete vnf_instance with vnf_id
try:
self.client.delete_vnf(vnf_id)
@ -210,7 +210,7 @@ class VnfTestToscaCreateImageCreation(base.BaseTackerTest):
glanceclient = self.glanceclient()
image = glanceclient.images.get(image_id)
self.assertIsNotNone(image)
self.assertEqual(True, "VNFImage_image_func" in image.name)
self.assertIn('VNFImage_image_func', image.name)
# Delete vnf_instance with vnf_id
try:
self.client.delete_vnf(vnf_id)

View File

@ -311,4 +311,4 @@ class PaginationEmulatedHelperTestcase(base.BaseTestCase):
result = page_previous.get_links(items)
self.assertEqual('previous', result[0]['rel'])
self.assertEqual(True, result[0]['href'] in expect_href)
self.assertIn(result[0]['href'], expect_href)

View File

@ -60,10 +60,10 @@ class TestAttributes(base.BaseTestCase):
self.assertIsNone(msg)
msg = attributes._validate_values(7, [4, 6])
self.assertEqual("'7' is not in [4, 6]", msg)
self.assertNotIn(7, [4, 6], msg)
msg = attributes._validate_values(7, (4, 6))
self.assertEqual("'7' is not in (4, 6)", msg)
self.assertNotIn(7, (4, 6), msg)
def test_validate_not_empty_string(self):
msg = attributes._validate_not_empty_string(' ', None)

View File

@ -194,7 +194,7 @@ class TestCSARUtils(testtools.TestCase):
msg = (('The filename "%(manifest)s" is an invalid name.'
'The name must be the same as the main template '
'file name.') %
{'manifest': manifest_path, 'csar': file_path})
{'manifest': manifest_path})
self.assertEqual(msg, exc.format_message())
@mock.patch('tacker.common.csar_utils.extract_csar_zip_file')

View File

@ -80,7 +80,7 @@ class TestVnfPackage(SqlTestCase):
result = vnf_package._vnf_package_list(
self.context, columns_to_join=[
'vnf_deployment_flavours', 'vnf_artifacts'])
self.assertTrue(isinstance(result, list))
self.assertIsInstance(result, list)
self.assertTrue(result)
def test_vnf_package_update(self):

View File

@ -35,7 +35,7 @@ class TestTerminateVnfRequest(SqlTestCase):
terminate_vnf_request = self._get_terminate_vnf_request()
result = objects.TerminateVnfRequest.obj_from_primitive(
terminate_vnf_request, self.context)
self.assertTrue(isinstance(result, objects.TerminateVnfRequest))
self.assertIsInstance(result, objects.TerminateVnfRequest)
self.assertEqual('GRACEFUL', result.termination_type)
self.assertEqual(terminate_vnf_request['graceful_termination_timeout'],
result.graceful_termination_timeout)
@ -46,6 +46,6 @@ class TestTerminateVnfRequest(SqlTestCase):
result = objects.TerminateVnfRequest.obj_from_primitive(
terminate_vnf_request, self.context)
self.assertTrue(isinstance(result, objects.TerminateVnfRequest))
self.assertIsInstance(result, objects.TerminateVnfRequest)
self.assertEqual('GRACEFUL', result.termination_type)
self.assertEqual(0, result.graceful_termination_timeout)

View File

@ -31,8 +31,8 @@ class TestVnfResource(SqlTestCase):
'vim_type': 'openstack'}
result = objects.VimConnectionInfo.obj_from_primitive(
vim_connection_dict, self.context)
self.assertEqual(True, isinstance(result, objects.VimConnectionInfo))
self.assertIsInstance(result, objects.VimConnectionInfo)
self.assertEqual('openstack', result.vim_type)
vim_connection_dict = result.to_dict()
self.assertEqual(True, isinstance(vim_connection_dict, dict))
self.assertIsInstance(vim_connection_dict, dict)
self.assertEqual('openstack', vim_connection_dict['vim_type'])

View File

@ -202,10 +202,10 @@ class TestInstantiatedVnfInfo(SqlTestCase):
resource_handle = copy.deepcopy(fakes.resource_handle_info)
result = objects.ResourceHandle.obj_from_primitive(
resource_handle, self.context)
self.assertTrue(isinstance(result, objects.ResourceHandle))
self.assertIsInstance(result, objects.ResourceHandle)
self.assertEqual('TEST', result.vim_level_resource_type)
resource_handle_dict = result.to_dict()
self.assertTrue(isinstance(resource_handle_dict, dict))
self.assertIsInstance(resource_handle_dict, dict)
self.assertEqual(
'TEST', resource_handle_dict['vim_level_resource_type'])
@ -214,65 +214,65 @@ class TestInstantiatedVnfInfo(SqlTestCase):
fakes.virtual_storage_resource_info)
result = objects.VirtualStorageResourceInfo.obj_from_primitive(
virtual_storage_resource_info, self.context)
self.assertTrue(isinstance(result,
objects.VirtualStorageResourceInfo))
self.assertIsInstance(result,
objects.VirtualStorageResourceInfo)
virt_strg_res_info_dict = result.to_dict()
self.assertTrue(isinstance(virt_strg_res_info_dict, dict))
self.assertIsInstance(virt_strg_res_info_dict, dict)
def test_vnfc_cp_info_obj_from_primitive_and_obj_to_dict(self):
vnfc_cp_info = copy.deepcopy(fakes.vnfc_cp_info)
result = objects.VnfcCpInfo.obj_from_primitive(
vnfc_cp_info, self.context)
self.assertTrue(isinstance(result, objects.VnfcCpInfo))
self.assertIsInstance(result, objects.VnfcCpInfo)
vnfc_cp_info = result.to_dict()
self.assertTrue(isinstance(vnfc_cp_info, dict))
self.assertIsInstance(vnfc_cp_info, dict)
def test_vnfc_resource_info_obj_from_primitive_and_obj_to_dict(self):
vnfc_resource_info = copy.deepcopy(fakes.vnfc_resource_info)
result = objects.VnfcResourceInfo.obj_from_primitive(
vnfc_resource_info, self.context)
self.assertTrue(isinstance(result, objects.VnfcResourceInfo))
self.assertIsInstance(result, objects.VnfcResourceInfo)
self.assertEqual({'key': 'value'}, result.metadata)
vnfc_resource_info = result.to_dict()
self.assertTrue(isinstance(vnfc_resource_info, dict))
self.assertIsInstance(vnfc_resource_info, dict)
def test_ext_mng_virt_link_obj_from_primitive_and_obj_to_dict(self):
ext_managed_virtual_link_info = copy.deepcopy(
fakes.ext_managed_virtual_link_info)
result = objects.ExtManagedVirtualLinkInfo.obj_from_primitive(
ext_managed_virtual_link_info, self.context)
self.assertTrue(isinstance(result, objects.ExtManagedVirtualLinkInfo))
self.assertIsInstance(result, objects.ExtManagedVirtualLinkInfo)
ext_mng_virt_link = result.to_dict()
self.assertTrue(isinstance(ext_mng_virt_link, dict))
self.assertIsInstance(ext_mng_virt_link, dict)
def test_ext_link_port_info_obj_from_primitive_and_obj_to_dict(self):
ext_link_port_info_data = copy.deepcopy(fakes.ext_link_port_info)
result = objects.ExtLinkPortInfo.obj_from_primitive(
ext_link_port_info_data, self.context)
self.assertTrue(isinstance(result, objects.ExtLinkPortInfo))
self.assertIsInstance(result, objects.ExtLinkPortInfo)
ext_link_port_info = result.to_dict()
self.assertTrue(isinstance(ext_link_port_info, dict))
self.assertIsInstance(ext_link_port_info, dict)
def test_ext_virt_link_info_obj_from_primitive_and_obj_to_dict(self):
ext_virtual_link_info = copy.deepcopy(fakes.ext_virtual_link_info)
result = objects.ExtVirtualLinkInfo.obj_from_primitive(
ext_virtual_link_info, self.context)
self.assertTrue(isinstance(result, objects.ExtVirtualLinkInfo))
self.assertIsInstance(result, objects.ExtVirtualLinkInfo)
ext_virt_link_info = result.to_dict()
self.assertTrue(isinstance(ext_virt_link_info, dict))
self.assertIsInstance(ext_virt_link_info, dict)
def test_vnf_ext_cp_info_obj_from_primitive_and_obj_to_dict(self):
vnf_ext_cp_info = copy.deepcopy(fakes.vnf_ext_cp_info)
result = objects.VnfExtCpInfo.obj_from_primitive(
vnf_ext_cp_info, self.context)
self.assertTrue(isinstance(result, objects.VnfExtCpInfo))
self.assertIsInstance(result, objects.VnfExtCpInfo)
ext_virt_link_info = result.to_dict()
self.assertTrue(isinstance(ext_virt_link_info, dict))
self.assertIsInstance(ext_virt_link_info, dict)
def test_instantiated_info_obj_from_primitive_and_obj_to_dict(self):
instantiated_vnf_info = copy.deepcopy(fakes.instantiated_vnf_info)
result = objects.InstantiatedVnfInfo.obj_from_primitive(
instantiated_vnf_info, self.context)
self.assertTrue(isinstance(result, objects.InstantiatedVnfInfo))
self.assertIsInstance(result, objects.InstantiatedVnfInfo)
instantiated_vnf_info_dict = result.to_dict()
self.assertTrue(isinstance(instantiated_vnf_info_dict, dict))
self.assertIsInstance(instantiated_vnf_info_dict, dict)

View File

@ -342,7 +342,7 @@ class TestController(base.TestCase):
elif expected_type == 'object':
expected_message = ("Invalid input for field/attribute "
"{attribute}. " "Value: {value}. {value} is "
"not of type 'object'".
"not of type {expected_type}".
format(value=value, attribute=attribute,
expected_type=expected_type))

View File

@ -53,7 +53,7 @@ class TestTransformer(base.TestCase):
k8s_obj = fakes.fake_k8s_dict()
kubernetes_objects.append(k8s_obj)
new_k8s_objs = self.transfromer.deploy_k8s(kubernetes_objects)
self.assertEqual(type(new_k8s_objs), list)
self.assertIsInstance(new_k8s_objs, list)
self.assertIsNotNone(new_k8s_objs)
self.assertEqual(new_k8s_objs[0]['status'], 'Creating')

View File

@ -187,8 +187,8 @@ class VnfPackageRequest:
artifact_paths)
else:
raise UndefinedExternalSettingException(
"Vnf package the external setting to 'pipeline=<{}>' " +
"not supported.".format(pipeline_type))
"Vnf package the external setting to 'pipeline=<{}>'"
" not supported.".format(pipeline_type))
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer,

View File

@ -8,7 +8,7 @@ coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT
doc8>=0.6.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
hacking>=3.0.1,<3.1.0 # Apache-2.0
hacking>=4.0.0,<4.1.0 # Apache-2.0
python-subunit>=1.0.0 # Apache-2.0/BSD
python-tackerclient>=0.8.0 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0