Fix for netaddr v1.3.0 upgrade and pep8 error

It is necessary to specify "expand_partial=True" in IPNetwork init
to expand partial addresses from netaddr v1.3.0.
This patch fixes it so that "expand_partial" can be specified
in IPNetwork init.

And bump the hacking version to 7.0.0 and fix the pep8
error:
 - AttributeError: 'EntryPoints' object has no attribute 'get'

Closes-Bug: #2089815
Closes-Bug: #2088356
Change-Id: I2deb71242f555bbae5ee7c798add18490cb38344
This commit is contained in:
Ai Hamano 2024-11-28 15:05:48 +09:00
parent 7cb7070df4
commit 068909080a
17 changed files with 41 additions and 36 deletions

View File

@ -719,7 +719,7 @@ class KubernetesMgmtDriver(vnflcm_abstract_driver.VnflcmMgmtAbstractDriver):
stderr = result[1]
unnecessary_msg = "WARNING! Using --password via the CLI"
err_info = (
[line for line in stderr if not(unnecessary_msg in line)])
[line for line in stderr if not (unnecessary_msg in line)])
err_msg = ("Failed to login Docker private registry. "
"ErrInfo:{}".format(err_info))
LOG.error(err_msg)

View File

@ -291,10 +291,11 @@ def _validate_ip_address_or_none(data, valid_values=None):
return _validate_ip_address(data, valid_values)
def _validate_subnet(data, valid_values=None):
def _validate_subnet(data, valid_values=None, expand_partial_value=False):
msg = None
try:
net = netaddr.IPNetwork(_validate_no_whitespace(data))
net = netaddr.IPNetwork(_validate_no_whitespace(data),
expand_partial=expand_partial_value)
if '/' not in data:
msg = _("'%(data)s' isn't a recognized IP subnet cidr,"
" '%(cidr)s' is recommended") % {"data": data,
@ -308,7 +309,8 @@ def _validate_subnet(data, valid_values=None):
return msg
def _validate_subnet_list(data, valid_values=None):
def _validate_subnet_list(data, valid_values=None,
expand_partial_value=False):
if not isinstance(data, list):
msg = _("'%s' is not a list") % data
LOG.debug(msg)
@ -320,15 +322,16 @@ def _validate_subnet_list(data, valid_values=None):
return msg
for item in data:
msg = _validate_subnet(item)
msg = _validate_subnet(item, valid_values, expand_partial_value)
if msg:
return msg
def _validate_subnet_or_none(data, valid_values=None):
def _validate_subnet_or_none(data, valid_values=None,
expand_partial_value=False):
if data is None:
return
return _validate_subnet(data, valid_values)
return _validate_subnet(data, valid_values, expand_partial_value)
def _validate_regex(data, valid_values=None):

View File

@ -553,7 +553,7 @@ class VnfLcmController(wsgi.Controller):
except nfvo.VimDefaultNotDefined as exc:
raise webob.exc.HTTPBadRequest(explanation=str(exc))
except(sqlexc.SQLAlchemyError, Exception) as exc:
except (sqlexc.SQLAlchemyError, Exception) as exc:
raise webob.exc.HTTPInternalServerError(
explanation=str(exc))
except webob.exc.HTTPNotFound as e:

View File

@ -516,7 +516,7 @@ class _AuthValidateManager:
class AuthValidatorExecution(base.ConfigurableMiddleware):
@ webob.dec.wsgify
@webob.dec.wsgify
def __call__(self, req):
auth_validator_manager.auth_main(req, self.application)
return self.application

View File

@ -912,9 +912,9 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook):
except Exception as ex:
# with excutils.save_and_reraise_exception():
error_msg = "Failed to add additional vnf info to vnf {}. Details -\
{}".format(
vnf_instance.id, str(ex))
error_msg = (
"Failed to add additional vnf info to vnf {}. Details - {}".
format(vnf_instance.id, str(ex)))
LOG.error("_add_additional_vnf_info error {}".format(error_msg))
raise exceptions.TackerException(message=error_msg)
@ -1784,7 +1784,7 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook):
'href': self._get_vnf_lcm_op_occs_href(
vnf_lcm_op_occs_id)}}}
if(operation_state == fields.LcmOccsOperationState.COMPLETED or
if (operation_state == fields.LcmOccsOperationState.COMPLETED or
operation_state == fields.LcmOccsOperationState.FAILED_TEMP or
operation_state == fields.LcmOccsOperationState.FAILED):
affected_resources = vnflcm_utils._get_affected_resources(

View File

@ -132,7 +132,7 @@ class ContextBase(oslo_context.RequestContext):
return context
def can(self, action, target=None, fatal=True):
"""Verifies that the given action is valid on the target in this context.
"""Verifies that the given action is valid on the target.
:param action: string representing the action to be checked.
:param target: dictionary representing the object of the action

View File

@ -273,7 +273,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
"is not permitted. Please contact your "
"Administrator.")
raise vnfm.VNFDeleteFailed(reason=error_reason)
if(vnf_db.status in [constants.PENDING_UPDATE,
if (vnf_db.status in [constants.PENDING_UPDATE,
constants.PENDING_HEAL]):
raise vnfm.VNFInUse(vnf_id=vnf_id)
return True

View File

@ -37,11 +37,11 @@ log_translation = re.compile(
@core.flake8ext
def validate_log_translations(physical_line, logical_line, filename):
def validate_log_translations(logical_line, filename):
# Translations are not required in the test directory
if "tacker/tests" in filename:
return
if pycodestyle.noqa(physical_line):
if pycodestyle.noqa(logical_line):
return
msg = "N320: Log messages require translations!"
if log_translation.match(logical_line):

View File

@ -94,7 +94,7 @@ def _make_vnf_lcm_op_occs_list(context, op_occ_list,
op_occ_list.objects = []
for db_op_occ in db_op_occ_list:
if(db_op_occ['changed_info'] and
if (db_op_occ['changed_info'] and
isinstance(db_op_occ['changed_info'], str)):
db_op_occ['changed_info'] = jsonutils.loads(
db_op_occ['changed_info'])

View File

@ -45,7 +45,7 @@ def PrepareRequestHandler(manager):
for objChkUrl in func_uri_list:
# Check which requested path is in our list.
LOG.debug('path for check:%s' % objChkUrl)
if(self.path.startswith(objChkUrl)):
if (self.path.startswith(objChkUrl)):
return True
return False

View File

@ -48,7 +48,7 @@ class VnfPmThresholdTest(base_v2.BaseVnfLcmKubernetesV2Test):
response_headers={"Content-Type": "text/plain"})
def test_pm_threshold_autoscaling_min(self):
"""Test PM Threshold operations with omitting except for required attributes
"""Test PM Threshold operations with omitting except for required attr
* About attributes:
Omit except for required attributes.

View File

@ -455,7 +455,9 @@ class TestAttributes(base.BaseTestCase):
# Valid - abbreviated ipv4 address
cidr = "10/24"
msg = validator(cidr, None)
# Note: It is necessary to specify "expand_partial=True" for "10/24"
# from netaddr 1.3.0.
msg = validator(cidr, None, True)
self.assertIsNone(msg)
# Invalid - IPv4 missing mask

View File

@ -230,8 +230,8 @@ class TestConductor(SqlTestCase, unit_base.FixturedTestCase):
mock_prepare):
mock_prepare.return_value = self.cctxt_mock
address_information = "http://test.zip"
mock_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
self.conductor.upload_vnf_package_from_uri(self.context,
self.vnf_package,
address_information,

View File

@ -61,8 +61,8 @@ class TestSyncVnfPackage(base.TestCase):
mock_glance_store):
# glance_store mock Settings
mock_glance_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_glance_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
updates = {'additionalArtifacts': [
{
@ -254,8 +254,8 @@ class TestSyncVnfPackage(base.TestCase):
mock_glance_store):
# glance_store mock Settings
mock_glance_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_glance_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
# vnf_package mock Settings
mock_save_vnf_package.side_effect = Exception
@ -291,8 +291,8 @@ class TestSyncVnfPackage(base.TestCase):
mock_glance_store):
# glance_store mock Settings
mock_glance_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_glance_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
mock_upload_vnf_package_content.side_effect = Exception
# SyncVnfPackage.create_package
@ -327,8 +327,8 @@ class TestSyncVnfPackage(base.TestCase):
mock_glance_store):
# glance_store mock Settings
mock_glance_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_glance_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
# vnf_package_vnfd mock Settings
mock_get_by_id.side_effect = Exception

View File

@ -735,8 +735,8 @@ class TestController(base.TestCase):
vnf_package_obj = objects.VnfPackage(**vnf_package_dict)
mock_vnf_by_id.return_value = vnf_package_obj
mock_vnf_pack_save.return_value = vnf_package_obj
mock_glance_store.return_value = 'location', 0, 'checksum',\
'multihash', 'loc_meta'
mock_glance_store.return_value = (
'location', 0, 'checksum', 'multihash', 'loc_meta')
req.headers['Content-Type'] = 'application/zip'
req.method = 'PUT'
req.body = jsonutils.dump_as_bytes({'dummy': {'val': 'foo'}})

View File

@ -1250,13 +1250,13 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
if not additional_params:
return False
use_helm = additional_params.get('use_helm')
if type(use_helm) == str:
if isinstance(use_helm, str):
return use_helm.lower() == 'true'
return bool(use_helm)
def _is_exthelmchart(self, helm_install_params):
exthelmchart = helm_install_params.get('exthelmchart')
if type(exthelmchart) == str:
if isinstance(exthelmchart, str):
return exthelmchart.lower() == 'true'
return bool(exthelmchart)

View File

@ -8,7 +8,7 @@ coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT
doc8>=0.9.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
hacking>=4.0.0,<4.1.0 # Apache-2.0
hacking>=7.0.0,<7.1.0 # Apache-2.0
python-subunit>=1.0.0 # Apache-2.0/BSD
python-tackerclient>=0.8.0 # Apache-2.0
python-cinderclient>=8.0.0 # Apache-2.0