Modify operation of scale parameters

Scale command cannot be executed without '--additional-param-file'
option, because there is a problem with branch process. Modify branch
process when using this parameter.

And, I uniform cardinality mismatches of specification definition [1]
in some arguments are resolved. This change has no impact of the order
of setting.

[1]https://specs.openstack.org/openstack/tacker-specs/specs/victoria/support-scale-api-based-on-etsi-nfv-sol.html

Closes-Bug: #1903280
Change-Id: I1dd2c71760112982abd2b4b7da6dbaafd7077614
This commit is contained in:
Wataru Juso
2020-12-09 00:35:18 +09:00
parent c6df687c94
commit bbe6d2c7e0
2 changed files with 66 additions and 30 deletions

View File

@@ -476,46 +476,51 @@ class ScaleVnfLcm(command.Command):
_VNF_INSTANCE,
metavar="<vnf-instance>",
help=_('VNF instance ID to scale'))
parser.add_argument(
'--I',
metavar="<param-file>",
help=_("Specify scale request parameters in a json file."))
parser.add_argument(
'--type',
metavar="<type>",
choices=['SCALE_OUT', 'SCALE_IN'],
help=_("Indicates the type of the scale operation requested"))
parser.add_argument(
'--aspect-id',
metavar="<aspect-id>",
help=_("Identifier of the scaling aspect."))
parser.add_argument(
'--number-of-steps',
metavar="<number-of-steps>",
type=int,
help=_("Number of scaling steps to be executed as part of"
help=_("Number of scaling steps to be executed as part of "
"this Scale VNF operation."))
parser.add_argument(
'--additional-param-file',
metavar="<additional-param-file>",
help=_("Additional parameters passed by the NFVO as input"
help=_("Additional parameters passed by the NFVO as input "
"to the scaling process."))
scale_require_parameters = parser.add_argument_group(
"require arguments"
)
scale_require_parameters.add_argument(
'--type',
metavar="<type>",
required=True,
choices=['SCALE_OUT', 'SCALE_IN'],
help=_("SCALE_OUT or SCALE_IN for type of scale operation."))
scale_require_parameters.add_argument(
'--aspect-id',
required=True,
metavar="<aspect-id>",
help=_("Identifier of the scaling aspect."))
return parser
def args2body(self, file_path=None):
def args2body(self, parsed_args):
"""To store request body, call jsonfile2body.
Args:
file_path ([string], optional): file path of param file(json).
Defaults to None.
parsed_args ([Namespace]): arguments of CLI.
Returns:
body[dict]: [description]
body ([dict]): Request body is stored
"""
body = {}
body = {'type': parsed_args.type, 'aspectId': parsed_args.aspect_id}
if file_path:
return jsonfile2body(file_path)
if parsed_args.number_of_steps:
body['numberOfSteps'] = parsed_args.number_of_steps
if parsed_args.additional_param_file:
body.update(jsonfile2body(parsed_args.additional_param_file))
return body
@@ -523,13 +528,12 @@ class ScaleVnfLcm(command.Command):
"""Execute scale_vnf_instance and output result comment.
Args:
parsed_args ([Namespace]): [description]
parsed_args ([Namespace]): arguments of CLI.
"""
client = self.app.client_manager.tackerclient
if parsed_args.additional_param_file:
result = client.scale_vnf_instance(
parsed_args.vnf_instance,
self.args2body(file_path=parsed_args.additional_param_file))
if not result:
print((_('Scale request for VNF Instance %(id)s has been'
' accepted.') % {'id': parsed_args.vnf_instance}))
result = client.scale_vnf_instance(
parsed_args.vnf_instance,
self.args2body(parsed_args))
if not result:
print((_('Scale request for VNF Instance %s has been accepted.')
% parsed_args.vnf_instance))

View File

@@ -651,6 +651,38 @@ class TestScaleVnfLcm(TestVnfLcm):
self.assertEqual(expected_message, actual_message)
@ddt.data('SCALE_IN', 'SCALE_OUT')
def test_take_action_no_param_file(self, scale_type):
vnf_instance = vnflcm_fakes.vnf_instance_response()
arglist = [vnf_instance['id'],
'--aspect-id', uuidsentinel.aspect_id,
'--number-of-steps', '1',
'--type', scale_type]
verifylist = [('vnf_instance', vnf_instance['id']),
('aspect_id', uuidsentinel.aspect_id),
('number_of_steps', 1),
('type', scale_type)]
parsed_args = self.check_parser(self.scale_vnf_lcm, arglist,
verifylist)
url = os.path.join(self.url, 'vnflcm/v1/vnf_instances',
vnf_instance['id'], 'scale')
self.requests_mock.register_uri(
'POST', url, headers=self.header, json={})
sys.stdout = buffer = StringIO()
self.scale_vnf_lcm.take_action(parsed_args)
actual_message = buffer.getvalue().strip()
expected_message = ("Scale request for VNF Instance %s has been "
"accepted.") % vnf_instance['id']
self.assertEqual(expected_message, actual_message)
@ddt.data('SCALE_IN', 'SCALE_OUT')
def test_take_action_param_file_not_exists(self, scale_type):
vnf_instance = vnflcm_fakes.vnf_instance_response()