From fcfed2f9c065ba92f775fb6f4563d5d4b64e7797 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Thu, 28 Apr 2022 15:50:08 +0200 Subject: [PATCH] Feature 10909: Heal operation for VDU Change-Id: I676563f1cc8ed5603032fdf9e722e070329ea249 Signed-off-by: garciadeblas --- devops-stages/stage-test.sh | 4 +- osmclient/scripts/osm.py | 218 ++++++++++++++++++++++++++++++++++++ osmclient/sol005/ns.py | 20 ++++ 3 files changed, 241 insertions(+), 1 deletion(-) diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh index a3f8e18..7d00a00 100755 --- a/devops-stages/stage-test.sh +++ b/devops-stages/stage-test.sh @@ -12,4 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -tox +echo "Launching tox" +tox --parallel=auto + diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index ca79545..a196139 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -5635,6 +5635,224 @@ def update(ctx, ns_name, updatetype, config, timeout, wait): ctx.obj.ns.update(ns_name, op_data, wait=wait) +def process_common_heal_params(ctx, param, value): + logger.debug("") + if not value: + return + logger.debug(f"Param name: {param.name}") + if not ctx.params.get("heal_params", {}).get("healVnfData"): + raise ClientException(f"Expected option --vnf before {param.name}") + if param.name == "cause": + param_dict = ctx.params["heal_params"]["healVnfData"][-1]["cause"] = value + return + # If not "vnf" and not "cause", then the param lies on "additionalParams" + if not ctx.params["heal_params"]["healVnfData"][-1].get("additionalParams"): + ctx.params["heal_params"]["healVnfData"][-1]["additionalParams"] = {} + if param.name == "vdu": + # Check VDU id ? + if not ctx.params["heal_params"]["healVnfData"][-1]["additionalParams"].get( + "vdu" + ): + ctx.params["heal_params"]["healVnfData"][-1]["additionalParams"][ + "vdu" + ] = [] + vdu = {"vdu-id": value} + ctx.params["heal_params"]["healVnfData"][-1]["additionalParams"][ + "vdu" + ].append(vdu) + ctx.params["heal_params"]["current_item"] = "vdu" + else: + current_item = ctx.params["heal_params"]["current_item"] + if current_item == "vnf": + param_dict = ctx.params["heal_params"]["healVnfData"][-1][ + "additionalParams" + ] + else: + # if current_item == "vdu": + param_dict = ctx.params["heal_params"]["healVnfData"][-1][ + "additionalParams" + ]["vdu"][-1] + if param.name == "count_index": + param_name = "count-index" + elif param.name == "run_day1": + param_name = "run-day1" + else: + param_name = param.name + param_dict[param_name] = value + return + + +def process_ns_heal_params(ctx, param, value): + logger.debug("") + if not ctx.params.get("heal_params"): + ctx.params["heal_params"] = {} + ctx.params["heal_params"]["healVnfData"] = [] + if param.name == "vnf" and value: + # Check VNF id ? + logger.debug(f"Param name: {param.name}") + vnf = {"vnfInstanceId": value} + ctx.params["heal_params"]["healVnfData"].append(vnf) + ctx.params["heal_params"]["current_item"] = "vnf" + else: + process_common_heal_params(ctx, param, value) + + +def process_vnf_heal_params(ctx, param, value): + logger.debug("") + if not ctx.params.get("heal_params"): + ctx.params["heal_params"] = {} + ctx.params["heal_params"]["healVnfData"] = [] + vnf = {"vnfInstanceId": "id_to_be_substituted"} + ctx.params["heal_params"]["healVnfData"].append(vnf) + ctx.params["heal_params"]["current_item"] = "vnf" + else: + process_common_heal_params(ctx, param, value) + + +@click.command( + name="ns-heal", short_help="heals (recreates) VNFs or VDUs of a NS instance" +) +@click.argument("ns_name") +@click.option( + "--vnf", + required=True, + default=None, + callback=process_ns_heal_params, + help="vnf-id if the target is a vnf instead of a ns)", +) +@click.option( + "--cause", + default=None, + callback=process_ns_heal_params, + help="human readable cause of the healing", +) +@click.option( + "--run-day1", + is_flag=True, + default=False, + callback=process_ns_heal_params, + help="indicates whether or not to run day1 primitives for the VNF/VDU", +) +@click.option( + "--vdu", + default=None, + callback=process_ns_heal_params, + help="vdu-id", +) +@click.option( + "--count-index", + type=int, + default=None, + callback=process_ns_heal_params, + help="count-index", +) +@click.option( + "--timeout", + type=int, + default=None, + help="timeout in seconds" +) +@click.option( + "--wait", + is_flag=True, + default=False, + help="do not return the control immediately, but keep it until the operation is completed, or timeout", +) +@click.pass_context +def ns_heal( + ctx, + ns_name, + heal_params, + cause, + vnf, + run_day1, + vdu, + count_index, + wait, + timeout, +): + """heals (recreates) VNFs or VDUs of a NS instance + + NS_NAME: name or ID of the NS instance + """ + logger.debug("") + heal_dict = ctx.params["heal_params"] + heal_dict.pop("current_item") + if cause: + heal_dict["cause"] = cause + logger.debug(f"Heal dict: {heal_dict}") + check_client_version(ctx.obj, ctx.command.name) + ctx.obj.ns.heal(ns_name, heal_dict, wait, timeout) + + +@click.command( + name="vnf-heal", + short_help="heals (recreates) a VNF instance or the VDUs of a VNF instance", +) +@click.argument("vnf_name") +@click.option( + "--cause", + default=None, + callback=process_vnf_heal_params, + help="human readable cause of the healing", +) +@click.option( + "--run-day1", + is_flag=True, + default=False, + callback=process_vnf_heal_params, + help="indicates whether or not to run day1 primitives for the VNF/VDU", +) +@click.option( + "--vdu", + default=None, + callback=process_vnf_heal_params, + help="vdu-id", +) +@click.option( + "--count-index", + type=int, + default=None, + callback=process_vnf_heal_params, + help="count-index", +) +@click.option( + "--timeout", + type=int, + default=None, + help="timeout in seconds" +) +@click.option( + "--wait", + default=False, + is_flag=True, + help="do not return the control immediately, but keep it until the operation is completed, or timeout", +) +@click.pass_context +def vnf_heal( + ctx, + vnf_name, + heal_params, + cause, + run_day1, + vdu, + count_index, + wait, + timeout, +): + """heals (recreates) a VNF instance or the VDUs of a VNF instance + + VNF_NAME: name or ID of the VNF instance + """ + logger.debug("") + heal_dict = ctx.params["heal_params"] + heal_dict.pop("current_item") + heal_dict["healVnfData"][-1]["vnfInstanceId"] = vnf_name + logger.debug(f"Heal dict: {heal_dict}") + check_client_version(ctx.obj, ctx.command.name) + ctx.obj.vnf.heal(vnf_name, heal_dict, wait, timeout) + + @cli_osm.command(name="alarm-show", short_help="show alarm details") @click.argument("uuid") @click.pass_context diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index e1a4f69..00d68d6 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -667,3 +667,23 @@ class Ns(object): return nsr[field] raise NotFound("failed to find {} in ns {}".format(field, ns_name)) + + def heal( + self, + ns_name, + heal_dict, + wait=False, + timeout=None, + ): + """Heals a NS""" + self._logger.debug("") + self._client.get_token() + try: + op_data = heal_dict + if timeout: + op_data["timeout_ns_heal"] = timeout + op_id = self.exec_op(ns_name, op_name="heal", op_data=op_data, wait=wait) + print(str(op_id)) + except ClientException as exc: + message = "failed to heal ns {}:\nerror:\n{}".format(ns_name, str(exc)) + raise ClientException(message) -- 2.17.1