Update ce_evpn_bgp_rr to fix bugs (#61168)

This commit is contained in:
yanzhangi 2019-09-18 10:08:12 +08:00 committed by ansibot
parent 8eec5d2ab2
commit 1a8c1c7365

View file

@ -169,7 +169,7 @@ changed:
import re import re
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, ce_argument_spec from ansible.module_utils.network.cloudengine.ce import exec_command, load_config, ce_argument_spec
def is_config_exist(cmp_cfg, test_cfg): def is_config_exist(cmp_cfg, test_cfg):
@ -259,19 +259,17 @@ class EvpnBgpRr(object):
def get_config_in_bgp_view(self): def get_config_in_bgp_view(self):
"""Get configuration in BGP view""" """Get configuration in BGP view"""
flags = list() cmd = "display current-configuration | section include"
exp = " | section include"
if self.as_number: if self.as_number:
if self.bgp_instance: if self.bgp_instance:
exp += " bgp %s instance %s" % (self.as_number, cmd += " bgp %s instance %s" % (self.as_number,
self.bgp_instance) self.bgp_instance)
else: else:
exp += " bgp %s" % self.as_number cmd += " bgp %s" % self.as_number
rc, out, err = exec_command(self.module, cmd)
flags.append(exp) if rc != 0:
config = get_config(self.module, flags) self.module.fail_json(msg=err)
cmd = 'display current-configuration ' + exp config = out.strip() if out else ""
config = config.strip() if config else ""
if cmd == config: if cmd == config:
return '' return ''
@ -423,27 +421,27 @@ class EvpnBgpRr(object):
self.cli_add_command(view_cmd) self.cli_add_command(view_cmd)
if self.bgp_evpn_enable == 'disable': if self.bgp_evpn_enable == 'disable':
self.cli_add_command(" undo l2vpn-family evpn") self.cli_add_command("undo l2vpn-family evpn")
else: else:
self.cli_add_command(" l2vpn-family evpn") self.cli_add_command("l2vpn-family evpn")
if self.reflect_client and self.reflect_client != self.cur_config['reflect_client']: if self.reflect_client and self.reflect_client != self.cur_config['reflect_client']:
if self.reflect_client == 'enable': if self.reflect_client == 'enable':
self.cli_add_command(" peer %s enable" % self.peer) self.cli_add_command("peer %s enable" % self.peer)
self.cli_add_command( self.cli_add_command(
" peer %s reflect-client" % self.peer) "peer %s reflect-client" % self.peer)
else: else:
self.cli_add_command( self.cli_add_command(
" undo peer %s reflect-client" % self.peer) "undo peer %s reflect-client" % self.peer)
self.cli_add_command(" undo peer %s enable" % self.peer) self.cli_add_command("undo peer %s enable" % self.peer)
if self.cur_config['bgp_evpn_enable'] == 'enable': if self.cur_config['bgp_evpn_enable'] == 'enable':
if self.policy_vpn_target and self.policy_vpn_target != self.cur_config['policy_vpn_target']: if self.policy_vpn_target and self.policy_vpn_target != self.cur_config['policy_vpn_target']:
if self.policy_vpn_target == 'enable': if self.policy_vpn_target == 'enable':
self.cli_add_command(" policy vpn-target") self.cli_add_command("policy vpn-target")
else: else:
self.cli_add_command(" undo policy vpn-target") self.cli_add_command("undo policy vpn-target")
else: else:
if self.policy_vpn_target and self.policy_vpn_target == 'disable': if self.policy_vpn_target and self.policy_vpn_target == 'disable':
self.cli_add_command(" undo policy vpn-target") self.cli_add_command("undo policy vpn-target")
if self.commands: if self.commands:
self.cli_load_config(self.commands) self.cli_load_config(self.commands)