Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ansible/TestbedProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ def makeSonicLabDevices(data, outfile):
makeTestbed(data, outfile)
@:parameter data - the dictionary to look through (devices dictionary)
@:parameter outfile - the file to write to
generates /testbed.csv by pulling confName, groupName, topo, ptf_image_name, ptf_ip, server, vm_base, dut, and comment
generates /testbed.csv by pulling confName, groupName, topo, ptf_image_name, ptf_ip, ptf_ipv6, server, vm_base, dut, and comment
error handling: checks if attribute values are None type or string "None"
"""
def makeTestbed(data, outfile):
csv_columns = "# conf-name,group-name,topo,ptf_image_name,ptf,ptf_ip,server,vm_base,dut,comment"
csv_columns = "# conf-name,group-name,topo,ptf_image_name,ptf,ptf_ip,ptf_ipv6,server,vm_base,dut,comment"
topology = data
csv_file = outfile

Expand Down Expand Up @@ -227,6 +227,8 @@ def makeTestbed(data, outfile):
ptf_image_name = ""
if not ptf_ip:
ptf_ip = ""
if not ptf_ipv6:
ptf_ipv6 = ""
if not server:
server = ""
if not vm_base:
Expand All @@ -238,7 +240,7 @@ def makeTestbed(data, outfile):
if not comment:
comment = ""

row = confName + "," + groupName + "," + topo + "," + ptf_image_name + "," + ptf + "," + ptf_ip + "," + server + "," + vm_base + "," + dut + "," + comment
row = confName + "," + groupName + "," + topo + "," + ptf_image_name + "," + ptf + "," + ptf_ip + "," + ptf_ipv6 + ","+ server + "," + vm_base + "," + dut + "," + comment
f.write(row + "\n")
except IOError:
print("I/O error: issue creating testbed.csv")
Expand Down
8 changes: 4 additions & 4 deletions ansible/lab
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ hwsku="ACS-MSN2700"
iface_speed='40000'

[sonic_s6000]
lab-s6000-01 ansible_host=10.251.0.189
vlab-01 ansible_host=10.250.0.101
vlab-03 ansible_host=10.250.0.105
vlab-04 ansible_host=10.250.0.107
lab-s6000-01 ansible_host=10.251.0.189 ansible_hostv6=fec0::ffff:afa:9
vlab-01 ansible_host=10.250.0.101 ansible_hostv6=fec0::ffff:afa:1
vlab-03 ansible_host=10.250.0.105 ansible_hostv6=fec0::ffff:afa:5
vlab-04 ansible_host=10.250.0.107 ansible_hostv6=fec0::ffff:afa:7

[sonic_s6000:vars]
hwsku="Force10-S6000"
Expand Down
8 changes: 6 additions & 2 deletions ansible/library/test_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

EXAMPLES = '''
Testbed CSV file example:
# conf-name,group-name,topo,ptf_image_name,ptf_ip,server,vm_base,dut,comment
# conf-name,group-name,topo,ptf_image_name,ptf_ip,ptf_ipv6,server,vm_base,dut,comment
ptf1-m,ptf1,ptf32,docker-ptf-sai-mlnx,10.255.0.188/24,server_1,,str-msn2700-01,Tests ptf
vms-t1,vms1-1,t1,docker-ptf-sai-mlnx,10.255.0.178/24,server_1,VM0100,str-msn2700-01,Tests vms
vms-t1-lag,vms1-1,t1-lag,docker-ptf-sai-mlnx,10.255.0.178/24,server_1,VM0100,str-msn2700-01,Tests vms
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, testbed_file):
self.testbed_topo = defaultdict()

def read_testbed_topo(self):
CSV_FIELDS = ('conf-name', 'group-name', 'topo', 'ptf_image_name', 'ptf', 'ptf_ip', 'server', 'vm_base', 'dut', 'comment')
CSV_FIELDS = ('conf-name', 'group-name', 'topo', 'ptf_image_name', 'ptf', 'ptf_ip', 'ptf_ipv6', 'server', 'vm_base', 'dut', 'comment')
with open(self.testbed_filename) as f:
topo = csv.DictReader(f, fieldnames=CSV_FIELDS, delimiter=',')

Expand All @@ -125,6 +125,10 @@ def read_testbed_topo(self):
ptfaddress = ipaddress.IPNetwork(line['ptf_ip'])
line['ptf_ip'] = str(ptfaddress.ip)
line['ptf_netmask'] = str(ptfaddress.netmask)
if line['ptf_ipv6']:
ptfaddress = ipaddress.IPNetwork(line['ptf_ipv6'])
line['ptf_ipv6'] = str(ptfaddress.ip)
line['ptf_netmask_v6'] = str(ptfaddress.netmask)

line['duts'] = line['dut'].translate(string.maketrans("", ""), "[] ").split(';')
del line['dut']
Expand Down
15 changes: 11 additions & 4 deletions ansible/roles/vm_set/library/vm_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- vm_names: list of VMs represented on a current host
- vm_base: which VM consider the first VM in the current vm set
- ptf_mgmt_ip_addr: ip address with prefixlen for the injected docker container
- ptf_mgmt_ipv6_addr: ipv6 address with prefixlen for the injected docker container
- ptf_mgmt_ip_gw: default gateway for the injected docker container
- ptf_bp_ip_addr: ipv6 address with prefixlen for the injected docker container
- ptf_bp_ipv6_addr: ipv6 address with prefixlen for the injected docker container
Expand All @@ -75,6 +76,7 @@
vm_names: "{{ VM_hosts }}"
vm_base: "{{ VM_base }}"
ptf_mgmt_ip_addr: "{{ ptf_ip }}"
ptf_mgmt_ipv6_addr: "{{ ptf_ipv6 }}"
ptf_mgmt_ip_gw: "{{ mgmt_gw }}"
ptf_bp_ip_addr: "{{ ptf_ip }}"
ptf_bp_ipv6_addr: "{{ ptf_ip }}"
Expand Down Expand Up @@ -235,9 +237,9 @@ def add_veth_ports_to_docker(self):

return

def add_mgmt_port_to_docker(self, mgmt_bridge, mgmt_ip, mgmt_gw):
def add_mgmt_port_to_docker(self, mgmt_bridge, mgmt_ip, mgmt_gw, mgmt_ipv6_addr=None):
self.add_br_if_to_docker(mgmt_bridge, PTF_MGMT_IF_TEMPLATE % self.vm_set_name, MGMT_PORT_NAME)
self.add_ip_to_docker_if(MGMT_PORT_NAME, mgmt_ip, mgmt_gw=mgmt_gw)
self.add_ip_to_docker_if(MGMT_PORT_NAME, mgmt_ip, mgmt_ipv6_addr=mgmt_ipv6_addr, mgmt_gw=mgmt_gw)

return

Expand Down Expand Up @@ -672,6 +674,7 @@ def main():
vm_names=dict(required=True, type='list'),
vm_base=dict(required=False, type='str'),
ptf_mgmt_ip_addr=dict(required=False, type='str'),
ptf_mgmt_ipv6_addr=dict(required=False, type='str'),
ptf_mgmt_ip_gw=dict(required=False, type='str'),
ptf_bp_ip_addr=dict(required=False, type='str'),
ptf_bp_ipv6_addr=dict(required=False, type='str'),
Expand Down Expand Up @@ -709,6 +712,7 @@ def main():
check_params(module, ['vm_set_name',
'topo',
'ptf_mgmt_ip_addr',
'ptf_mgmt_ipv6_addr',
'ptf_mgmt_ip_gw',
'ptf_bp_ip_addr',
'ptf_bp_ipv6_addr',
Expand All @@ -733,10 +737,11 @@ def main():
net.init(vm_set_name, topo, vm_base, dut_fp_ports)

ptf_mgmt_ip_addr = module.params['ptf_mgmt_ip_addr']
ptf_mgmt_ipv6_addr = module.params['ptf_mgmt_ipv6_addr']
ptf_mgmt_ip_gw = module.params['ptf_mgmt_ip_gw']
mgmt_bridge = module.params['mgmt_bridge']

net.add_mgmt_port_to_docker(mgmt_bridge, ptf_mgmt_ip_addr, ptf_mgmt_ip_gw)
net.add_mgmt_port_to_docker(mgmt_bridge, ptf_mgmt_ip_addr, ptf_mgmt_ip_gw, ptf_mgmt_ipv6_addr)

ptf_bp_ip_addr = module.params['ptf_bp_ip_addr']
ptf_bp_ipv6_addr = module.params['ptf_bp_ipv6_addr']
Expand Down Expand Up @@ -787,6 +792,7 @@ def main():
check_params(module, ['vm_set_name',
'topo',
'ptf_mgmt_ip_addr',
'ptf_mgmt_ipv6_addr',
'ptf_mgmt_ip_gw',
'ptf_bp_ip_addr',
'ptf_bp_ipv6_addr',
Expand All @@ -811,10 +817,11 @@ def main():
net.init(vm_set_name, topo, vm_base, dut_fp_ports, True)

ptf_mgmt_ip_addr = module.params['ptf_mgmt_ip_addr']
ptf_mgmt_ipv6_addr = module.params['ptf_mgmt_ipv6_addr']
ptf_mgmt_ip_gw = module.params['ptf_mgmt_ip_gw']
mgmt_bridge = module.params['mgmt_bridge']

net.add_mgmt_port_to_docker(mgmt_bridge, ptf_mgmt_ip_addr, ptf_mgmt_ip_gw)
net.add_mgmt_port_to_docker(mgmt_bridge, ptf_mgmt_ip_addr, ptf_mgmt_ip_gw, ptf_mgmt_ipv6_addr)

ptf_bp_ip_addr = module.params['ptf_bp_ip_addr']
ptf_bp_ipv6_addr = module.params['ptf_bp_ipv6_addr']
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/vm_set/tasks/add_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
vm_names: "{{ VM_hosts }}"
vm_base: "{{ VM_base }}"
ptf_mgmt_ip_addr: "{{ ptf_ip }}"
ptf_mgmt_ipv6_addr: "{{ ptf_ipv6 }}"
ptf_mgmt_ip_gw: "{{ mgmt_gw }}"
ptf_bp_ip_addr: "{{ ptf_bp_ip }}"
ptf_bp_ipv6_addr: "{{ ptf_bp_ipv6 }}"
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/vm_set/tasks/renumber_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
vm_names: "{{ VM_hosts }}"
vm_base: "{{ VM_base }}"
ptf_mgmt_ip_addr: "{{ ptf_ip }}"
ptf_mgmt_ipv6_addr: "{{ ptf_ipv6 }}"
ptf_mgmt_ip_gw: "{{ mgmt_gw }}"
mgmt_bridge: "{{ mgmt_bridge }}"
dut_fp_ports: "{{ dut_fp_ports }}"
Expand Down
4 changes: 2 additions & 2 deletions ansible/templates/minigraph_dpg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<Name>V6HostIP</Name>
<AttachTo>eth0</AttachTo>
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
<b:IPPrefix>FC00:2::32/64</b:IPPrefix>
<b:IPPrefix>{{ ansible_hostv6 }}/64</b:IPPrefix>
</a:Prefix>
<a:PrefixStr>FC00:2::32/64</a:PrefixStr>
<a:PrefixStr>{{ ansible_hostv6 }}/64</a:PrefixStr>
</a:ManagementIPInterface>
</ManagementIPInterfaces>
<ManagementVIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
Expand Down
15 changes: 8 additions & 7 deletions ansible/testbed-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ function read_file
ptf_imagename=${line_arr[3]}
ptf=${line_arr[4]}
ptf_ip=${line_arr[5]}
server=${line_arr[6]}
vm_base=${line_arr[7]}
dut=${line_arr[8]//;/,}
ptf_ipv6=${line_arr[6]}
server=${line_arr[7]}
vm_base=${line_arr[8]}
dut=${line_arr[9]//;/,}
duts=${dut//[\[\] ]/}
}

Expand Down Expand Up @@ -153,7 +154,7 @@ function add_topo

read_file ${topology}

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_add_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" $@
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_add_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" -e ptf_ipv6="$ptf_ipv6" $@

ansible-playbook fanout_connect.yml -i $vmfile --limit "$server" --vault-password-file="${passwd}" -e "dut=$duts" $@

Expand All @@ -173,7 +174,7 @@ function remove_topo

read_file ${topology}

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_remove_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" $@
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_remove_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" -e ptf_ipv6="$ptf_ipv6" $@

echo Done
}
Expand All @@ -188,7 +189,7 @@ function renumber_topo

read_file ${topology}

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_renumber_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" $@
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_renumber_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e ptf_ipv6="$ptf_ipv6"$@

ansible-playbook fanout_connect.yml -i $vmfile --limit "$server" --vault-password-file="${passwd}" -e "dut=$duts" $@

Expand All @@ -205,7 +206,7 @@ function refresh_dut

read_file ${topology}

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_refresh_dut.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" $@
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_refresh_dut.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e ptf_ipv6="$ptf_ipv6" $@

echo Done
}
Expand Down
5 changes: 5 additions & 0 deletions ansible/testbed_add_vm_topology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# -e dut_name=str-msn2700-01 - the name of target dut
# -e VM_base=VM0300 - the VM name which is used to as base to calculate VM name for this set
# -e ptf_ip=10.255.0.255/23 - the ip address and prefix of ptf container mgmt interface
# -e ptf_ipv6=fec0::ffff:afa:1/64 - the ipv6 address and prefix of ptf container mgmt interface
# -e topo=t0 - the name of removed topo
# -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container
# -e vm_type=veos|ceos
Expand Down Expand Up @@ -53,6 +54,10 @@
fail: msg="Define ptf ip variable with -e ptf_ip=something"
when: ptf_ip is not defined

- name: Check that variable ptf_ipv6 is defined
fail: msg="Define ptf ipv6 variable with -e ptf_ipv6=something"
when: ptf_ipv6 is not defined

- name: Check that variable topo is defined
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined
Expand Down
5 changes: 5 additions & 0 deletions ansible/testbed_refresh_dut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# -e dut_name=str-msn2700-01 - the name of target dut
# -e VM_base=VM0300 - the VM name which is used to as base to calculate VM name for this set
# -e ptf_ip=10.255.0.255/23 - the ip address and prefix of ptf container mgmt interface
# -e ptf_ipv6=fec0::ffff:afa:1/64 - the ipv6 address and prefix of ptf container mgmt interface
# -e topo=t0 - the name of removed topo
# -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container

Expand Down Expand Up @@ -52,6 +53,10 @@
fail: msg="Define ptf ip variable with -e ptf_ip=something"
when: ptf_ip is not defined

- name: Check that variable ptf_ipv6 is defined
fail: msg="Define ptf ipv6 variable with -e ptf_ipv6=something"
when: ptf_ipv6 is not defined

- name: Check that variable topo is defined
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined
Expand Down
4 changes: 4 additions & 0 deletions ansible/testbed_renumber_vm_topology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
fail: msg="Define ptf ip variable with -e ptf_ip=something"
when: ptf_ip is not defined

- name: Check that variable ptf_ipv6 is defined
fail: msg="Define ptf ipv6 variable with -e ptf_ipv6=something"
when: ptf_ipv6 is not defined

- name: Check that variable topo is defined
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined or topo not in topologies
Expand Down
12 changes: 6 additions & 6 deletions ansible/veos.vtb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ server_1
topologies=['t1', 't1-lag', 't1-64-lag', 't1-64-lag-clet', 't0', 't0-16', 't0-56', 't0-52', 'ptf32', 'ptf64', 't0-64', 't0-64-32', 't0-116']

[sonic]
vlab-01 ansible_host=10.250.0.101 type=kvm hwsku=Force10-S6000 serial_port=9000
vlab-02 ansible_host=10.250.0.102 type=kvm hwsku=Force10-S6100 serial_port=9000
vlab-03 ansible_host=10.250.0.105 type=kvm hwsku=Force10-S6000 serial_port=9001
vlab-04 ansible_host=10.250.0.107 type=kvm hwsku=Force10-S6000 serial_port=9002
vlab-simx-01 ansible_host=10.250.0.103 type=simx hwsku=MSN2700
vlab-simx-02 ansible_host=10.250.0.104 type=simx hwsku=MSN3700
vlab-01 ansible_host=10.250.0.101 ansible_hostv6=fec0::ffff:afa:1 type=kvm hwsku=Force10-S6000 serial_port=9000
vlab-02 ansible_host=10.250.0.102 ansible_hostv6=fec0::ffff:afa:2 type=kvm hwsku=Force10-S6100 serial_port=9000
vlab-03 ansible_host=10.250.0.105 ansible_hostv6=fec0::ffff:afa:5 type=kvm hwsku=Force10-S6000 serial_port=9001
vlab-04 ansible_host=10.250.0.107 ansible_hostv6=fec0::ffff:afa:7 type=kvm hwsku=Force10-S6000 serial_port=9002
vlab-simx-01 ansible_host=10.250.0.103 ansible_hostv6=fec0::ffff:afa:3 type=simx hwsku=MSN2700
vlab-simx-02 ansible_host=10.250.0.104 ansible_hostv6=fec0::ffff:afa:4 type=simx hwsku=MSN3700
10 changes: 5 additions & 5 deletions ansible/vtestbed.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# conf-name,group-name,topo,ptf_image_name,ptf,ptf_ip,server,vm_base,dut,comment
vms-kvm-t0,vms6-1,t0,docker-ptf,ptf-unknown,10.250.0.102/24,server_1,VM0100,[vlab-01],Tests virtual switch vm
vms-kvm-t0-64,vms6-1,t0-64,docker-ptf,ptf-unknown,10.250.0.102/24,server_1,VM0100,[vlab-02],Tests virtual switch vm
vms-kvm-t1-lag,vms6-2,t1-lag,docker-ptf,ptf-unknown,10.250.0.106/24,server_1,VM0104,[vlab-03],Tests virtual switch vm
vms-kvm-t0-2,vms6-3,t0,docker-ptf,ptf-unknown,10.250.0.108/24,server_1,VM0104,[vlab-04],Tests virtual switch vm
# conf-name,group-name,topo,ptf_image_name,ptf,ptf_ip,ptf_ipv6,server,vm_base,dut,comment
vms-kvm-t0,vms6-1,t0,docker-ptf,ptf-unknown,10.250.0.102/24,fec0::ffff:afa:2/64,server_1,VM0100,[vlab-01],Tests virtual switch vm
vms-kvm-t0-64,vms6-1,t0-64,docker-ptf,ptf-unknown,10.250.0.102/24,fec0::ffff:afa:2/64,server_1,VM0100,[vlab-02],Tests virtual switch vm
vms-kvm-t1-lag,vms6-2,t1-lag,docker-ptf,ptf-unknown,10.250.0.106/24,fec0::ffff:afa:6/64,server_1,VM0104,[vlab-03],Tests virtual switch vm
vms-kvm-t0-2,vms6-3,t0,docker-ptf,ptf-unknown,10.250.0.108/24,fec0::ffff:afa:8/64,server_1,VM0104,[vlab-04],Tests virtual switch vm
28 changes: 21 additions & 7 deletions tests/common/plugins/tacacs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest
import crypt

@pytest.fixture(scope="module")
def setup_tacacs(ptfhost, duthost, creds):
def configure_tacacs(ptfhost, duthost, creds, tacacs_server_ip):
"""setup tacacs client and server"""

# disable tacacs server
Expand All @@ -15,9 +14,7 @@ def setup_tacacs(ptfhost, duthost, creds):
config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts']
for tacacs_server in config_facts.get('TACPLUS_SERVER', {}):
duthost.shell("sudo config tacacs delete %s" % tacacs_server)

ptfip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_host']
duthost.shell("sudo config tacacs add %s" % ptfip)
duthost.shell("sudo config tacacs add %s" % tacacs_server_ip)
duthost.shell("sudo config tacacs authtype login")

# enable tacacs+
Expand All @@ -36,15 +33,32 @@ def setup_tacacs(ptfhost, duthost, creds):
# start tacacs server
ptfhost.service(name="tacacs_plus", state="started")

yield

def cleanup_tacacs(ptfhost, duthost, tacacs_server_ip):
# stop tacacs server
ptfhost.service(name="tacacs_plus", state="stopped")

# reset tacacs client configuration
duthost.shell("sudo config tacacs delete %s" % ptfip)
duthost.shell("sudo config tacacs delete %s" % tacacs_server_ip)
duthost.shell("sudo config tacacs default passkey")
duthost.shell("sudo config aaa authentication login default")
duthost.shell("sudo config aaa authentication failthrough default")

@pytest.fixture(scope="module")
def test_tacacs(ptfhost, duthost, creds):
tacacs_server_ip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_host']
configure_tacacs(ptfhost, duthost, creds, tacacs_server_ip)

yield

cleanup_tacacs(ptfhost, duthost, tacacs_server_ip)


@pytest.fixture(scope="module")
def test_tacacs_v6(ptfhost, duthost, creds):
tacacs_server_ip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_hostv6']
configure_tacacs(ptfhost, duthost, creds, tacacs_server_ip)

yield

cleanup_tacacs(ptfhost, duthost, tacacs_server_ip)
Loading