diff --git a/nspepi/nspepi2/check_classic_configs.py b/nspepi/nspepi2/check_classic_configs.py index b7f73c9..e97ec33 100644 --- a/nspepi/nspepi2/check_classic_configs.py +++ b/nspepi/nspepi2/check_classic_configs.py @@ -134,8 +134,8 @@ def check_pos_expr(commandParseTree, pos, check_removed_expr = True): rule_expr = rule_node.value converted_expr = check_classic_expr.check_classic_expr(rule_expr) if converted_expr is None: - logging.error('Error in checking command : ' + - str(commandParseTree)) + logging.error(('Error in checking command : [{}]').format(str(commandParseTree))) + elif converted_expr == "Invalid Expression": commandParseTree.set_invalid() else: @@ -168,8 +168,7 @@ def check_keyword_expr(commandParseTree, keywordName): rule_expr = rule_node[0].value converted_expr = check_classic_expr.check_classic_expr(rule_expr) if converted_expr is None: - logging.error('Error in checking command : ' + - str(commandParseTree)) + logging.error(('Error in checking command : [{}]').format(str(commandParseTree))) elif converted_expr == "Invalid Expression": commandParseTree.set_invalid() else: @@ -519,14 +518,14 @@ def check_policy_expr(self, commandParseTree): " and shouldn't be name of another policy entity" "; words reserved for policy use may not be used;" " underscores will be substituted for any invalid" - " characters in corresponding advanced name") - .format(expr_name)) + " characters in corresponding advanced name : [{}]") + .format(expr_name, str(commandParseTree))) if commandParseTree.keyword_exists('clientSecurityMessage'): NamedExpression.register_classic_entity_name(commandParseTree) logging.warning(("Client security expressions are deprecated" - " using this command [{}], please use the" - " the advanced authentication policy command") + " using this command, please use the" + " the advanced authentication policy command. : [{}]") .format(str(commandParseTree).strip())) return [] @@ -542,8 +541,8 @@ def check_policy_expr(self, commandParseTree): """ NamedExpression.register_policy_entity_name(commandParseTree) NamedExpression.register_classic_entity_name(original_tree) - logging.warning(("Classic expression has been deprecated in" - " command [{}], please use the advanced expression") + logging.warning(("Classic expression has been deprecated in the" + " following command, please use the advanced expression : [{}]") .format(str(commandParseTree).strip())) else: NamedExpression.register_policy_entity_name(original_tree) @@ -911,7 +910,7 @@ def check_deprecated_classic_policy(self, commandParseTree): commandParseTree = Deprecation.check_pos_expr(commandParseTree, 1, False) if commandParseTree.invalid: logging.warning(("Classic expression in the rule field has been deprecated" - " for command [{}], please use the advanced expression") + " for the following command, please use the advanced expression : [{}]") .format(str(commandParseTree).strip())) elif is_advanced_removed_expr_present(rule_expr): commandParseTree.set_invalid() @@ -932,8 +931,8 @@ def check_authentication_commands(self, commandParseTree): """ Check the Authentication commands which have been deprecated """ - logging.warning(("[{}] command has been deprecated," - " please use the advanced authentication policy command") + logging.warning(("Following command has been deprecated," + " please use the advanced authentication policy command : [{}]") .format(str(commandParseTree).strip())) return [] @@ -942,8 +941,8 @@ def check_ns_traffic_domain(self, commandParseTree): """ Check the traffic domain command """ - logging.warning(("[{}] command has been deprecated," - " please use the admin partition feature") + logging.warning(("Command has been deprecated," + " please use the admin partition feature. : [{}]") .format(str(commandParseTree).strip())) return [] @@ -955,8 +954,8 @@ def check_aaa_preauth_params(self, commandParseTree): """ if commandParseTree.keyword_exists('rule'): logging.warning(("Client security expressions are deprecated" - " using this command [{}], please use the" - " the advanced authentication policy command") + " using this command, please use the" + " the advanced authentication policy command : [{}]") .format(str(commandParseTree).strip())) return [] @@ -968,8 +967,8 @@ def check_vpn_sessionaction(self, commandParseTree): """ if commandParseTree.keyword_exists('clientSecurity'): logging.warning(("Client security expressions are deprecated" - " using this command [{}], please use the" - " the advanced authentication policy command") + " using this command, please use the" + " the advanced authentication policy command : [{}]") .format(str(commandParseTree).strip())) return [] @@ -982,7 +981,7 @@ def check_vpn_url(self, commandParseTree): sso_type = commandParseTree.keyword_value("ssotype")[0].value.lower() if sso_type == "selfauth": logging.warning("Selfauth type has been deprecated" - " in command [{}]".format(str(commandParseTree).strip())) + " in command : [{}]".format(str(commandParseTree).strip())) return [] @common.register_for_cmd("add", "vpn", "portaltheme") @@ -996,8 +995,8 @@ def check_vpn_portaltheme(self, commandParseTree): if base_theme == "Default" or base_theme == "X1" \ or base_theme == "Greenbubble": logging.warning(("Default, GreenBubble and X1 themes" - " have been deprecated in command [{}]," - " please use RfWebUI theme or RfWebUI based custom theme") + " have been deprecated in the command," + " please use RfWebUI theme or RfWebUI based custom theme : [{}]") .format(str(commandParseTree).strip())) return [] @@ -1013,8 +1012,8 @@ def check_vpn_commands(self, commandParseTree): if base_theme == "Default" or base_theme == "X1" \ or base_theme == "Greenbubble": logging.warning(("Default, GreenBubble and X1 themes" - " have been deprecated in command [{}]," - " please use RfWebUI theme or RfWebUI based custom theme") + " have been deprecated in the command," + " please use RfWebUI theme or RfWebUI based custom theme : [{}]") .format(str(commandParseTree).strip())) return [] @@ -1027,13 +1026,13 @@ def check_dns_action(self, commandParseTree): action_type = commandParseTree.positional_value(1).value.lower() if action_type == "rewrite_response": logging.warning(("Rewrite_Response action type is deprecated in" - " command [{}], please use the replace_dns_answer_section" - " action type under Rewrite feature.") + " the command, please use the replace_dns_answer_section" + " action type under Rewrite feature. : [{}]") .format(str(commandParseTree).strip())) elif action_type == "drop": logging.warning(("Drop action type is deprecated in" - " command [{}], please use the Drop" - " action type under Responder feature.") + " the command, please use the Drop" + " action type under Responder feature. : [{}]") .format(str(commandParseTree).strip())) return [] @@ -1049,8 +1048,8 @@ def check_ns_feature(self, commandParseTree): feature_name = feature_node.value if feature_name in features_to_remove: logging.warning("SC, PQ, HDOSP, and CF features" - " have been deprecated in command [{}], please" - " use the APPQOE, REWRITE, and RESPONDER features" + " have been deprecated in the command, please" + " use the APPQOE, REWRITE, and RESPONDER features : [{}]" .format(str(commandParseTree).strip())) break return [] @@ -1070,7 +1069,7 @@ def check_deprecated_pacingcommands(self, commandParseTree): commandParseTree.set_invalid() return [commandParseTree] - logging.warning(("[{}] command has been deprecated") + logging.warning(("Command has been deprecated : [{}]") .format(str(commandParseTree).strip())) return [] @@ -1096,7 +1095,7 @@ def check_lsn_commands(self, commandParseTree): Check the Authentication commands which have been deprecated """ if (int(build_version.split(".")[0]) > 13): - logging.warning(("[{}] command has been deprecated") + logging.warning(("Command has been deprecated : [{}]") .format(str(commandParseTree).strip())) return [] @@ -1120,5 +1119,5 @@ def check_responder_action(self, commandParseTree): action_type = commandParseTree.positional_value(1).value.lower() if action_type is "noop": logging.warning("NOOP action type has been deprecated" - " for command [{}]".format(str(commandParseTree).strip())) + " for the command : [{}]".format(str(commandParseTree).strip())) return [] diff --git a/nspepi/nspepi2/check_classic_expr.py b/nspepi/nspepi2/check_classic_expr.py index 53635d7..d9867b4 100644 --- a/nspepi/nspepi2/check_classic_expr.py +++ b/nspepi/nspepi2/check_classic_expr.py @@ -26,10 +26,8 @@ def check_classic_expr(classic_expr): of the converted string, so remove that character.""" nspepi_tool_output = nspepi_tool_output.rstrip() except subprocess.CalledProcessError as exc: - # Log the command which is failing - logging.error(exc) - # Log the error message - logging.error(exc.output) + # Log the command which is failing and also the error message + logging.error(exc.output + " : [" + exc + "]") return None nspepi_tool_output = nspepi_tool_output.decode() if nspepi_tool_output.startswith('ERROR:'): diff --git a/nspepi/nspepi2/cli_lex.py b/nspepi/nspepi2/cli_lex.py index 7e39e38..60b6a6c 100644 --- a/nspepi/nspepi2/cli_lex.py +++ b/nspepi/nspepi2/cli_lex.py @@ -176,8 +176,7 @@ def token(self): else: self.advance_token(self._length) token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Unbalanced closed parenthesis") + logging.error("Unbalanced closed parenthesis : [{}]".format(self._data)) break elif self._data[self._lex_pos] == "\\": # backslashes are escapes inside quotes @@ -187,9 +186,7 @@ def token(self): self.advance_and_append_token( self._data[self._lex_pos]) token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Blackslashes inside quotes are " - "followed by end of the command") + logging.error("Blackslashes inside quotes are followed by end of the command : [{}]".format(self._data)) break if self._data[self._lex_pos + 1] == 't': self.advance_and_append_token('\t', 2) @@ -211,8 +208,7 @@ def token(self): if state in "\"'" or parenthesis_counter > 0: # error token for not matching with any rule token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Unbalanced parenthesis or quotes") + logging.error("Unbalanced parenthesis or quotes : [{}]".format(self._data)) next_token = LexToken(token_type, self._token_value, 1, self._lex_pos - 1) return next_token @@ -333,9 +329,7 @@ def adv_expr_token(self): self.advance_and_append_token( self._data[self._lex_pos]) token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Blackslashes inside quotes are " - "followed by end of the expression") + logging.error("Blackslashes inside quotes are followed by end of the expression : [{}]".format(self._data)) break if self._data[self._lex_pos + 1] == 't': self.advance_and_append_token('\t', 2) @@ -357,13 +351,11 @@ def adv_expr_token(self): if state in "\"'": # error token for not matching with any rule token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Unbalanced quotes") + logging.error("Unbalanced quotes : [{}]".format(self._data)) elif state == "REGEX": # error token for not matching with any rule token_type = "ERROR" - logging.error("Data: {}".format(self._data)) - logging.error("Unterminated regex") + logging.error("Unterminated regex : [{}]".format(self._data)) next_token = LexToken(token_type, self._token_value, 1, self._lex_pos - 1) return next_token diff --git a/nspepi/nspepi2/convert_classic_expr.py b/nspepi/nspepi2/convert_classic_expr.py index d3cafd4..9f4c5de 100644 --- a/nspepi/nspepi2/convert_classic_expr.py +++ b/nspepi/nspepi2/convert_classic_expr.py @@ -53,10 +53,8 @@ def convert_classic_expr(classic_expr, ignore_csec_expr = False): of the converted string, so remove that character.""" nspepi_tool_output = nspepi_tool_output.rstrip() except subprocess.CalledProcessError as exc: - # Log the command which is failing - logging.error(exc) - # Log the error message - logging.error(exc.output) + # Log the command which is failing and also the reason + logging.error(str(exc) + " : [" + str(exc.output) + "]") return None nspepi_tool_output = nspepi_tool_output.decode() if nspepi_tool_output.startswith('ERROR:'): @@ -102,7 +100,7 @@ def convert_adv_expr(advanced_expr): body_expr_without_arg = is_body_expr_without_arg_present(advanced_expr) if body_expr_without_arg: logging.error("Body size needs to process is not present " - "in HTTP.REQ.BODY expression, please privoide the body size.") + "in HTTP.REQ.BODY expression, please provide the body size. : [{}]".format(advanced_expr)) return None advanced_expr = convert_q_s_expr(advanced_expr) return convert_sys_eval_classic_expr(advanced_expr) @@ -169,7 +167,7 @@ def convert_sys_eval_classic_expr(advanced_expr): classic_exp_info = PILex.get_pi_string( advanced_expr[arg_start_index:]) if classic_exp_info is None: - logging.error("Error in converting expression: {}".format( + logging.error("Error in converting expression : [{}]".format( original_expr)) return None classic_expr = classic_exp_info[0] @@ -184,7 +182,7 @@ def convert_sys_eval_classic_expr(advanced_expr): sys_end_index += 1 if (sys_end_index >= advanced_expr_length or advanced_expr[sys_end_index] != ')'): - logging.error("Error in converting expression: {}".format( + logging.error("Error in converting expression : [{}]".format( original_expr)) return None converted_expr = convert_classic_expr(classic_expr) @@ -192,7 +190,7 @@ def convert_sys_eval_classic_expr(advanced_expr): # Result from convert_classic_expr will have enclosing quotes. converted_expr = cli_commands.remove_quotes(converted_expr) if converted_expr is None or converted_expr == classic_expr: - logging.error("Error in converting expression: {}".format( + logging.error("Error in converting expression: [{}]".format( original_expr)) return None # Converted expression should be enclosed in braces because diff --git a/nspepi/nspepi2/convert_cli_commands.py b/nspepi/nspepi2/convert_cli_commands.py index 2db3727..1c77122 100644 --- a/nspepi/nspepi2/convert_cli_commands.py +++ b/nspepi/nspepi2/convert_cli_commands.py @@ -151,8 +151,8 @@ def print_csec_error_message(expr_list): """ for expr_name in expr_list: if not NamedExpression.csec_expr_list[expr_name]["error_displayed"]: - logging.error(("Conversion of clientSecurityMessage based expression [{}] " - "is not supported, please do the conversion manually.") + logging.error(("Conversion of clientSecurityMessage based expression " + "is not supported, please do the conversion manually. : [{}]") .format(str(NamedExpression.csec_expr_list[expr_name]["tree"]).strip())) NamedExpression.csec_expr_list[expr_name]["error_displayed"] = True @@ -196,19 +196,16 @@ def convert_pos_expr(commandParseTree, pos, ignore_csec_expr = False): csec_expr_info = has_client_security_expressions(rule_expr) if csec_expr_info[0]: print_csec_error_message(csec_expr_info[1]) - logging.error('Error in converting command : ' + - str(commandParseTree).strp()) + logging.error('Error in converting command : [' + + str(commandParseTree).strp() + ']') return commandParseTree converted_expr = convert_classic_expr.convert_classic_expr(rule_expr, ignore_csec_expr) if converted_expr is None: - logging.error('Error in converting command : ' + - str(commandParseTree).strip()) + logging.error('Error in converting command : [' + + str(commandParseTree).strip() + ']') converted_expr = rule_expr else: - if (converted_expr == "Ignoring Client security Expression"): - commandParseTree.set_has_csec_expr() - return commandParseTree # converted_expr will have quotes and rule_expr will not have # quotes. Since we are comparing these 2 expressions, removing # quotes from converted_expr. @@ -240,14 +237,14 @@ def convert_keyword_expr(commandParseTree, keywordName): csec_expr_info = has_client_security_expressions(rule_expr) if csec_expr_info[0]: print_csec_error_message(csec_expr_info[1]) - logging.error('Error in converting command : ' + - str(commandParseTree).strip()) + logging.error('Error in converting command : [' + + str(commandParseTree).strip() + ']') return commandParseTree converted_expr = convert_classic_expr.convert_classic_expr(rule_expr) if converted_expr is None: - logging.error('Error in converting command : ' + - str(commandParseTree).strip()) + logging.error('Error in converting command : [' + + str(commandParseTree).strip() + ']') converted_expr = rule_expr else: # converted_expr will have quotes and rule_expr will not have @@ -286,8 +283,8 @@ def convert_adv_expr_list(tree, param_list): continue converted_expr = convert_classic_expr.convert_adv_expr(adv_expr) if converted_expr is None: - logging.error('Error in converting command : ' + - str(original_tree).strip()) + logging.error('Error in converting command : [' + + str(original_tree).strip() + ']') return original_tree else: converted_expr = remove_quotes(converted_expr) @@ -763,10 +760,10 @@ def reprioritize_binds(self, binds): self.update_tree_arg(bind_info.parse_tree, bind_info.bind_arg_goto, new_goto) elif goto.upper() not in ("NEXT", "END", "USE_INVOCATION_RESULT"): - logging.error("gotoPriorityExpression in {} uses an" + logging.error("gotoPriorityExpression in this CLI command uses an" " expression. Since the priorities for this" " bindpoint have been renumbered, this" - " expression will need to be modified manually." + " expression will need to be modified manually. : [{}]" "".format(str(bind_info.parse_tree))) return new_binds @@ -792,10 +789,11 @@ def reprioritize_and_emit_global_binds(self): " converted as [{}]. If the command is required" " please take a backup because comments are not" " saved in ns.conf after triggering" - "'save ns config'.{}" + "'save ns config'.{} : [{}]" "".format(bind_info.orig_cmd.strip(), str(bind_info.parse_tree).strip(), - common.CMD_MOD_ERR_MSG)) + common.CMD_MOD_ERR_MSG, + bind_info.orig_cmd.strip())) bind_cmd_trees.append( "# {}".format(str(bind_info.parse_tree))) else: @@ -863,10 +861,11 @@ def reprioritize_and_emit_4_level_dict(self, bind_dict): " required please take a backup because" " comments are not saved in ns.conf" " after triggering 'save ns config'." - "{}".format( + "{} : [{}]".format( bind_info.orig_cmd.strip(), str(bind_info.parse_tree).strip(), - common.CMD_MOD_ERR_MSG)) + common.CMD_MOD_ERR_MSG, + bind_info.orig_cmd.strip())) bind_cmd_trees.append( "# {}".format(str(bind_info.parse_tree))) else: @@ -1214,7 +1213,7 @@ def convert_tunnel_global(self, commandParseTree): " with the advanced configuration, so if we convert this" " config then functionality will change. If command is" " required please take a backup because comments will" - " not be saved in ns.conf after triggering 'save ns config': {}"). + " not be saved in ns.conf after triggering 'save ns config' : [{}]"). format(str(commandParseTree).strip()) ) return ['#' + str(commandParseTree)] @@ -1459,7 +1458,7 @@ def convert_appfw_global_bind(self, commandParseTree): " with the advanced configuration, so if we convert this" " config then functionality will change. If command is" " required please take a backup because comments will" - " not be saved in ns.conf after triggering 'save ns config': {}"). + " not be saved in ns.conf after triggering 'save ns config' : [{}]"). format(str(commandParseTree).strip())) return ['#' + str(commandParseTree)] @@ -1591,7 +1590,7 @@ def register_name(self, commandParseTree): """ logging.error(("HTTP callout name {} is conflicting with" " named expression entity name, please resolve" - " the conflict.").format(callout_name)) + " the conflict. : [{}]").format(callout_name, str(commandParseTree))) else: HTTP_CALLOUT.register_policy_entity_name(commandParseTree) commandParseTree = HTTP_CALLOUT.convert_adv_expr_list( @@ -1759,7 +1758,7 @@ def convert_policy(self, commandParseTree): NamedExpression.csec_expr_list[lower_expr_name]["error_displayed"] = False NamedExpression.register_classic_entity_name(commandParseTree) return [commandParseTree] - + if ((lower_expr_name in reserved_word_list) or (re.match('^[a-z_][a-z0-9_]*$', lower_expr_name) is None)): logging.error(("Expression name {} is invalid for advanced " @@ -1972,8 +1971,8 @@ def convert_policy(self, commandParseTree): converted_expr = convert_classic_expr.convert_classic_expr( rule_expr) if converted_expr is None: - logging.error('Error in converting command : ' + - str(commandParseTree).strip()) + logging.error('Error in converting command : [' + + str(commandParseTree).strip() + ']') return [commandParseTree] converted_expr = converted_expr.strip('"') domain_name = commandParseTree.keyword_value('domain')[0] \ @@ -2137,7 +2136,7 @@ def convert_cs_bind_command(self, commandParseTree): # CS policies without action issue. if cs_vserver_name not in self._cs_policy_binding_info: self._cs_policy_binding_info[cs_vserver_name] = [] - + if commandParseTree.keyword_exists("targetLBVserver"): vserver_name = commandParseTree.keyword_value( "targetLBVserver")[0].value @@ -2165,7 +2164,7 @@ def convert_cs_bind_command(self, commandParseTree): ci_search = cs_vserver_name in self._cs_vserver_info_ci if vserver_bind_info["case_insensitive"] != ci_search: vserver_bind_info["diff_case_search"] = True - + self._cs_policy_binding_info[cs_vserver_name].append( commandParseTree) return [] @@ -2207,7 +2206,7 @@ def convert_cs_policy_entity_bind( # to process the bindings. if not self._classic_policy_exists: return [commandParseTree] - + policy_type = self.__class__.__name__ if policy_name in self._policy_bind_info: cs_vserver_name = commandParseTree.positional_value(0).value @@ -2215,7 +2214,7 @@ def convert_cs_policy_entity_bind( # CS policies without action issue. if cs_vserver_name not in self._cs_policy_binding_info: self._cs_policy_binding_info[cs_vserver_name] = [] - + vserver_name = commandParseTree.keyword_value("policyName")[1].value if "vserver_bind_info" not in self._policy_bind_info[policy_name]: vserver_bind_info = {} @@ -2292,12 +2291,13 @@ def get_converted_cmds(self): "bind cr vserver"): vserver_name = bind_tree.keyword_value( "policyName")[1].value - + set_ci_rule = False + if (is_cs_vserver and (cs_cr_vserver_name in self._cs_vserver_info_ci) and - (policy_name in self._policy_url_info)): + (policy_name in self._policy_url_info)): set_ci_rule = True - + vserver_bind_info = self._policy_bind_info[policy_name]["vserver_bind_info"] need_new_policy = False need_new_action = False @@ -2319,7 +2319,7 @@ def get_converted_cmds(self): # Check action name length. Max allowed length is 127 if len(action_name) > 127: truncated_act_name, overlength_action_counter = \ - self.truncate_name(action_name, + self.truncate_name(action_name, overlength_action_names, overlength_action_counter) pos = CLIPositionalParameter(truncated_act_name) @@ -2336,7 +2336,6 @@ def get_converted_cmds(self): if action_name in overlength_action_names: truncated_act_name = overlength_action_names[ action_name] - if need_new_policy: new_policy_name = "nspepi_adv_" + policy_name + '_' + \ vserver_name @@ -2738,9 +2737,9 @@ def convert_policy(self, commandParseTree): original_tree = copy.deepcopy(commandParseTree) convertedParseTree = SSL.convert_keyword_expr(commandParseTree, 'rule') if convertedParseTree.upgraded: - logging.error(("Classic SSL policy [{}] is not working from 10.1 release, " + logging.error(("Classic SSL policy is not working from 10.1 release, " "please remove the classic SSL policy configuration " - "from the config file").format(str(original_tree).strip())) + "from the config file : [{}]").format(str(original_tree).strip())) return [original_tree] return [commandParseTree] @@ -2753,9 +2752,9 @@ class SureConnect(ConvertConfig): @common.register_for_cmd("add", "sc", "policy") @common.register_for_cmd("set", "sc", "parameter") def convert_policy(self, commandParseTree): - logging.error(("SureConnect feature command [{}] conversion " + logging.error(("SureConnect feature command conversion " "is not supported, please do the conversion " - "manually").format(str(commandParseTree).strip())) + "manually : [{}]").format(str(commandParseTree).strip())) return [commandParseTree] @@ -2766,9 +2765,9 @@ class PriorityQueuing(ConvertConfig): """ @common.register_for_cmd("add", "pq", "policy") def convert_policy(self, commandParseTree): - logging.error(("PriorityQueuing feature command [{}] conversion " + logging.error(("PriorityQueuing feature command conversion " "is not supported, please do the conversion " - "manually").format(str(commandParseTree).strip())) + "manually : [{}]").format(str(commandParseTree).strip())) return [commandParseTree] @@ -2779,9 +2778,9 @@ class HDoSP(ConvertConfig): """ @common.register_for_cmd("add", "dos", "policy") def convert_policy(self, commandParseTree): - logging.error(("HDoSP feature command [{}] conversion " + logging.error(("HDoSP feature command conversion " "is not supported, please do the conversion " - "manually").format(str(commandParseTree).strip())) + "manually : [{}]").format(str(commandParseTree).strip())) return [commandParseTree] diff --git a/nspepi/nspepi2/convert_cmp_cmd.py b/nspepi/nspepi2/convert_cmp_cmd.py index 2936010..7760744 100644 --- a/nspepi/nspepi2/convert_cmp_cmd.py +++ b/nspepi/nspepi2/convert_cmp_cmd.py @@ -208,7 +208,7 @@ def convert_cmp_global_bind(self, bind_cmd_tree): " with the advanced configuration, so if we convert this" " config then functionality will change. If command is" " required please take a backup because comments will" - " not be saved in ns.conf after triggering 'save ns config': {}"). + " not be saved in ns.conf after triggering 'save ns config' : [{}]"). format(str(bind_cmd_tree).strip()) ) return ["#" + str(bind_cmd_tree)] @@ -223,7 +223,6 @@ def convert_cmp_global_bind(self, bind_cmd_tree): if ((policy_info[0] == priority) and (policy_info[1] == next_prio_expr)): return [bind_cmd_tree] - self.replace_builtin_policy(bind_cmd_tree, policy_name, 0) bind_point = "" self.update_bind_info(bind_cmd_tree, bind_point) @@ -373,7 +372,7 @@ def check_functionality(self): " Now classic policies are converted to advanced. " "This will change the functionality. CMP policy bindings " "are commented out. Modify the bindings of CMP policies " - "manually.").format(bind_point) + "manually. : [{}]").format(bind_point, bind_point) ) conflict_exists = True elif self._cmp_bind_info[global_bind_point][ @@ -386,7 +385,7 @@ def check_functionality(self): "converted to advanced. This will change the " "functionality. CMP policy bindings are commented out. " "Modify the bindings of CMP policies " - "manually.").format(bind_point) + "manually. : [{}]").format(bind_point, bind_point) ) conflict_exists = True return conflict_exists @@ -562,4 +561,4 @@ def get_cmp_policy_bindings(self): tree_list += self.convert_entity_policy_bind( tree, tree, policy_name, policy_type, priority_arg, goto_arg) - return tree_list + return tree_list \ No newline at end of file diff --git a/nspepi/nspepi2/convert_filter_command.py b/nspepi/nspepi2/convert_filter_command.py index 6fc4d30..d911417 100644 --- a/nspepi/nspepi2/convert_filter_command.py +++ b/nspepi/nspepi2/convert_filter_command.py @@ -190,6 +190,7 @@ bind rewrite global pol2 NEXT -type RES_DEFAULT bind vserver -policyName pol1 [-priority ]) -gotoPriorityExpression NEXT -TYPE REQUEST bind vserver -policyName pol2 [-priority ]) -gotoPriorityExpression NEXT -TYPE RESPONSE + ''' import re @@ -395,7 +396,7 @@ def convert_filter_action(self, action_parse_tree): "command [{}] is not supported in this tool." "".format(str(original_cmd).strip())) return [action_parse_tree] - + else: # Prebody/postbody value indicates that this config is # being used for HTMLinjection feature, and conversion @@ -409,9 +410,8 @@ def convert_filter_action(self, action_parse_tree): self._htmlInjection["action"].append(actionName) action_parse_tree_list = [original_cmd] logging.error( - "Conversion of HTMLInjection feature related" - " command [{}] is not supported in this tool." - "".format(str(original_cmd).strip())) + "Conversion of [{}] not supported in this tool. : [{}]" + "".format(str(original_cmd).strip(), str(original_cmd).strip())) elif (action_type == "corrupt"): """ Transformation for filter action of CORRUPT as actionType @@ -532,7 +532,6 @@ def convert_filter_action(self, action_parse_tree): self._action_command[lower_actionName].append(responder_action) self._action_command[lower_actionName].append(rewrite_action) - # Store actionType and actionName self._actionTypeName[action_type].append(str( rewrite_action.positional_value(0).value.lower())) @@ -556,8 +555,8 @@ def convert_filter_action(self, action_parse_tree): action_parse_tree_list = [original_cmd] self._forward["action"].append(actionName) logging.error( - "Conversion of FORWARD action type related command" - " [{}] not supported in this tool".format(str(original_cmd).strip())) + "Conversion of [{}] not supported in this tool. : [{}]" + "".format(str(original_cmd).strip(), str(original_cmd).strip())) else: """ @@ -568,7 +567,7 @@ def convert_filter_action(self, action_parse_tree): action_parse_tree_list = [original_cmd] logging.error( 'Error in converting original command since' + - ' CLI context of filter feature is invalid: ' + + ' CLI context of filter feature is invalid : ' + '[{}]'.format(str(original_cmd))) return action_parse_tree_list @@ -621,7 +620,7 @@ def convert_filter_policy(self, policy_parse_tree): "not supported in this tool.".format(str(original_cmd).strip())) self._forward["policy"].append(policyName) return [original_cmd] - + for dict_key, dict_value in self._actionTypeName.items(): """ Extract key and value from stored _actionTypeName dictionary through action convertion """ @@ -734,7 +733,7 @@ def convert_filter_vserver_bindings( if policy_type == "advanced": # Return same if policy_type is marked advanced return [bind_parse_tree] - + if policy_name in self._forward["policy"]: logging.error( "Conversion of FORWARD action type related command [{}]" @@ -746,7 +745,7 @@ def convert_filter_vserver_bindings( "Conversion of HTMLInjection feature related command [{}]" "not supported in this tool.".format(str(bind_parse_tree).strip())) return [bind_parse_tree] - + vs_name = bind_parse_tree.positional_value(0).value.lower() if cli_cmds.vserver_protocol_dict[vs_name] not in ("HTTP", "SSL"): logging.error("Filter policy doesn't work with the non-http protocol" @@ -754,7 +753,7 @@ def convert_filter_vserver_bindings( " policy to the non-http vserver, then either the" " config will fail or the functionality will change," " so please review and remove such config" - " command [{}].".format(str(bind_parse_tree).strip())) + " command : [{}]".format(str(bind_parse_tree).strip())) return ['#' + str(bind_parse_tree)] flow_type = ("RESPONSE" if (self._converted_pol_param[ policy_name][0] == "resAction") else "REQUEST") @@ -795,7 +794,7 @@ def convert_filter_global_bindings(self, bind_parse_tree): " with the advanced configuration, so if we convert this" " config then functionality will change. If command is" " required please take a backup because comments will" - " not be saved in ns.conf after triggering 'save ns config': {}"). + " not be saved in ns.conf after triggering 'save ns config' : [{}]"). format(str(bind_parse_tree).strip()) ) return ["#" + str(bind_parse_tree)] @@ -812,7 +811,7 @@ def convert_filter_global_bindings(self, bind_parse_tree): "Conversion of HTMLInjection feature related command [{}]" "not supported in this tool.".format(str(bind_parse_tree).strip())) return [bind_parse_tree] - + policy_type = common.pols_binds.policies[policy_name].policy_type if policy_type == "advanced": # Return input if policy_type is marked with "advanced" @@ -855,7 +854,7 @@ def convert_filter_htmlinjection_command(self, commandParseTree): logging.error("Conversion of HTMLInjection feature" " related command [{}] is not supported".format(str(commandParseTree).strip())) return [commandParseTree] - + @common.register_for_final_call def get_converted_cmds(self): """ @@ -961,7 +960,7 @@ def return_bind_cmd_error(self, cmd): logging.error("In ns.conf, existing advanced feature policies's bind commands have" " gotoPriorityExpression as END/USE_INVOCATION_RESULT for HTTP/S." " Priorities and gotoPriorityExpression will need to" - " be added modified/added manually in [{}].".format(str(cmd).strip())) + " be added modified/added manually. : [{}]".format(str(cmd).strip())) bind_cmd = '#' + str(cmd) return bind_cmd @@ -1046,7 +1045,7 @@ def add_policy_invoke_policylabel(self, label_name, vserver_name, the policylabel label_name - rewrite policy label name vserver_name - vserver name in which filter policy is bound - vserver_group - vserver group: lb, cs or cr + vserver_group - vserver group: lb, cs or cr is_req_flow_type - True if binding is for request side, otherwise False """ diff --git a/nspepi/nspepi2/convert_lb_cmd.py b/nspepi/nspepi2/convert_lb_cmd.py index 927c18e..af88c97 100644 --- a/nspepi/nspepi2/convert_lb_cmd.py +++ b/nspepi/nspepi2/convert_lb_cmd.py @@ -128,7 +128,7 @@ def convert_lb_rule(self, add_lbvserver_parse_tree): # CONTENTS exists but not a simple expression. # Throw error and don't convert. logging.error(("-rule in the following command has to be " - "converted manually: {}").format( + "converted manually : [{}]").format( str(add_lbvserver_parse_tree).strip())) return [add_lbvserver_parse_tree] @@ -169,10 +169,10 @@ def convert_lb_rule(self, add_lbvserver_parse_tree): "format. This will result in functionality " "change when rule is used for persistenceType" " or lbMethod. To aviod the functionality " - "change, {} command is modified by removing " - "the following keywords: {}.").format( - str(original_tree).strip(), - ", ".join(removed_keywords))) + "change, command is modified by removing " + "the following keywords : {} : [{}]").format( + ", ".join(removed_keywords), + str(original_tree).strip())) return [add_lbvserver_parse_tree] def search_pattern(self, rule, index, found_expr_list): diff --git a/nspepi/nspepi2/nspepi_common.py b/nspepi/nspepi2/nspepi_common.py index ac48618..74850dc 100644 --- a/nspepi/nspepi2/nspepi_common.py +++ b/nspepi/nspepi2/nspepi_common.py @@ -21,8 +21,7 @@ import nspepi_parse_tree -currentfile = os.path.abspath(inspect.getfile(inspect.currentframe())) -currentdir = os.path.dirname(currentfile) +currentdir = os.path.dirname(os.path.abspath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) @@ -935,9 +934,9 @@ def do_priority_analysis_for_all_users_groups(self, user_list, group_list): for v in weights.values(): same_weight_group_set = set([o.entity_name for o in v]) if len(same_weight_group_set) > 1: - logging.error("Groups: {} having the same weight and bindings" + logging.error("Groups having the same weight and bindings" " have no defined ordering in Advanced Policy" - " evaluation.".format( + " evaluation. : {}".format( ", ".join(sorted(same_weight_group_set)))) res.update(v) logging.debug("do_priority_analysis_for_all_users_groups(): ") diff --git a/nspepi/nspepi2/nspepi_parse_tree.py b/nspepi/nspepi2/nspepi_parse_tree.py index 4591242..432f2cd 100644 --- a/nspepi/nspepi2/nspepi_parse_tree.py +++ b/nspepi/nspepi2/nspepi_parse_tree.py @@ -210,7 +210,7 @@ def set_invalid(self): @property def invalid(self): return self._invalid - + def set_has_csec_expr(self): """ Flags that this command has diff --git a/nspepi/nspepi2/pi_lex.py b/nspepi/nspepi2/pi_lex.py index 0875a7f..367f9cf 100644 --- a/nspepi/nspepi2/pi_lex.py +++ b/nspepi/nspepi2/pi_lex.py @@ -58,7 +58,7 @@ def get_pi_string(expr): hex_digits = int(hex_digits, 16) if hex_digits > 127: logging.error("Invalid hex value is used. Maximum " - "hex value allowed is 7f.") + "hex value allowed is 7f. : [{}]".format(expr)) return None value += chr(hex_digits) else: @@ -73,7 +73,7 @@ def get_pi_string(expr): oct_digits = int(oct_digits, 8) if oct_digits > 127: logging.error("Invalid octal value is used. Maximum " - "octal value allowed is 177.") + "octal value allowed is 177. : [{}]".format(expr)) return None value += chr(oct_digits) else: