Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Azarack committed Mar 15, 2024
2 parents fb4e934 + 24fd286 commit d5f7a5e
Show file tree
Hide file tree
Showing 43 changed files with 1,908 additions and 108 deletions.
1 change: 0 additions & 1 deletion .azure-pipelines/recover_testbed/dut_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def get_ssh_info(sonichost):
host=sonichost.im.get_hosts(pattern='sonic')[0]).get("ansible_altpassword")
sonic_password = [creds['sonicadmin_password'], sonicadmin_alt_password]
sonic_ip = sonichost.im.get_host(sonichost.hostname).vars['ansible_host']
logging.info("sonic username: {}, password: {}".format(sonic_username, sonic_password))
return sonic_username, sonic_password, sonic_ip


Expand Down
28 changes: 13 additions & 15 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,6 @@
line: 'snmp_rocommunity: {{ snmp_rocommunity }}'
become: true

- name: disable automatic minigraph update if we are deploying new minigraph into SONiC
lineinfile:
name: /etc/sonic/updategraph.conf
regexp: '^enabled='
line: 'enabled=false'
become: true
register: updategraph_conf

- name: restart automatic minigraph update service
become: true
service:
name: updategraph
state: restarted
when: updategraph_conf.changed

- name: docker status
shell: docker ps
register: docker_status
Expand All @@ -525,6 +510,19 @@
delay: 10
until: result is not failed

- name: Cleanup /etc/sonic folder before loading new minigraph
block:
- name: Ensure /etc/sonic/acl.json is deleted
become: true
file:
path: /etc/sonic/acl.json
state: absent
- name: Ensure /etc/sonic/port_config.json is deleted
become: true
file:
path: /etc/sonic/port_config.json
state: absent

- name: execute cli "config load_minigraph -y" to apply new minigraph
become: true
shell: config load_minigraph -y
Expand Down
46 changes: 41 additions & 5 deletions ansible/plugins/connection/multi_passwd_ssh.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import imp
import logging
import os

from functools import wraps
from ansible.errors import AnsibleAuthenticationFailure
from ansible.plugins import connection


logger = logging.getLogger(__name__)

# HACK: workaround to import the SSH connection plugin
_ssh_mod = os.path.join(os.path.dirname(connection.__file__), "ssh.py")
_ssh = imp.load_source("_ssh", _ssh_mod)
Expand All @@ -26,17 +29,20 @@
vars:
- name: ansible_altpasswords
- name: ansible_ssh_altpasswords
hostv6:
description: IPv6 address
vars:
- name: ansible_hostv6
""".lstrip("\n")


def _password_retry(func):
"""
Decorator to retry ssh/scp/sftp in the case of invalid password
Will retry with IPv6 addr if IPv4 addr is unavailable
Will retry for password in (ansible_password, ansible_altpassword, ansible_altpasswords):
"""
@wraps(func)
def wrapped(self, *args, **kwargs):
def _conn_with_multi_pwd(self, *args, **kwargs):
password = self.get_option("password") or self._play_context.password
conn_passwords = [password]
altpassword = self.get_option("altpassword")
Expand All @@ -45,7 +51,6 @@ def wrapped(self, *args, **kwargs):
altpasswds = self.get_option("altpasswords")
if altpasswds:
conn_passwords.extend(altpasswds)

while conn_passwords:
conn_password = conn_passwords.pop(0)
# temporarily replace `password` for this trial
Expand All @@ -61,8 +66,39 @@ def wrapped(self, *args, **kwargs):
# reset `password` to its original state
self.set_option("password", password)
self._play_context.password = password
# retry here, need create a new pipe for sshpass
# This is a retry, so the fd/pipe for sshpass is closed, and we need a new one
self.sshpass_pipe = os.pipe()

@wraps(func)
def wrapped(self, *args, **kwargs):
try:
# First, try with original host(generally IPv4) with multi-password
return _conn_with_multi_pwd(self, *args, **kwargs)
except BaseException as e:
# If a non-authentication related exception is raised and IPv6 host is set,
# Retry with IPv6 host with multi-password
try:
hostv6 = self.get_option("hostv6")
except KeyError:
hostv6 = None
if (type(e) != AnsibleAuthenticationFailure) and hostv6:
# This is a retry, so the fd/pipe for sshpass is closed, and we need a new one
self.sshpass_pipe = os.pipe()
self._play_context.remote_addr = hostv6
# args sample:
# ( [b'sshpass', b'-d18', b'ssh', b'-o', b'ControlMaster=auto', b'-o', b'ControlPersist=120s', b'-o', b'UserKnownHostsFile=/dev/null', b'-o', b'StrictHostKeyChecking=no', b'-o', b'StrictHostKeyChecking=no', b'-o', b'User="admin"', b'-o', b'ConnectTimeout=60', b'-o', b'ControlPath="/home/user/.ansible/cp/376bdcc730"', 'fc00:1234:5678:abcd::2', b'/bin/sh -c \'echo PLATFORM; uname; echo FOUND; command -v \'"\'"\'python3.10\'"\'"\'; command -v \'"\'"\'python3.9\'"\'"\'; command -v \'"\'"\'python3.8\'"\'"\'; command -v \'"\'"\'python3.7\'"\'"\'; command -v \'"\'"\'python3.6\'"\'"\'; command -v \'"\'"\'python3.5\'"\'"\'; command -v \'"\'"\'/usr/bin/python3\'"\'"\'; command -v \'"\'"\'/usr/libexec/platform-python\'"\'"\'; command -v \'"\'"\'python2.7\'"\'"\'; command -v \'"\'"\'/usr/bin/python\'"\'"\'; command -v \'"\'"\'python\'"\'"\'; echo ENDFOUND && sleep 0\''], None) # noqa: E501
# args[0] are the parameters of ssh connection
ssh_args = args[0]
# Change the IPv4 host in the ssh_args to IPv6
for idx in range(len(ssh_args)):
if type(ssh_args[idx]) == bytes and ssh_args[idx].decode() == self.host:
ssh_args[idx] = hostv6
self.host = hostv6
self.set_option("host", hostv6)
return _conn_with_multi_pwd(self, *args, **kwargs)
else:
raise e

return wrapped


Expand Down
5 changes: 5 additions & 0 deletions ansible/roles/fanout/tasks/sonic/fanout_sonic_202012.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@
shell: "bcmcmd 'fp detach' && bcmcmd 'fp init'"
become: yes
when: "'broadcom' in fanout_sonic_version.asic_type"

- name: Run config qos reload command to load qos settings in order to fix 9332 Wdrr testcase failure
shell: config qos reload
become: yes
when: "'DellEMC-Z9332f-O32' in device_info[inventory_hostname]['HwSku']"
2 changes: 0 additions & 2 deletions ansible/roles/test/files/ptftests/py3/dhcp_relay_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,5 @@ def runTest(self):

# Below verification will be done only when client port is set in ptf_runner
if not self.dual_tor and 'other_client_port' in self.test_params:
self.verify_dhcp_relay_pkt_on_other_client_port_with_no_padding(
self.dest_mac_address, self.client_udp_src_port)
self.verify_dhcp_relay_pkt_on_server_port_with_no_padding(
self.dest_mac_address, self.client_udp_src_port)
17 changes: 4 additions & 13 deletions ansible/roles/vm_set/library/sonic_kickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,10 @@ def logout(self):


def session(new_params):
if new_params['disable_updategraph']:
seq = [
('while true; do if [ $(systemctl is-active swss) == "active" ]; then break; fi; '
'echo $(systemctl is-active swss); '
'sed -i -e "s/enabled=true/enabled=false/" /etc/sonic/updategraph.conf; '
'systemctl restart updategraph; sleep 1; done', [r'#'], 180),
]
else:
seq = [
('while true; do if [ $(systemctl is-active swss) == "active" ]; then break; fi; '
'echo $(systemctl is-active swss); sleep 1; done', [r'#'], 180),
]
seq = [
('while true; do if [ $(systemctl is-active swss) == "active" ]; then break; fi; '
'echo $(systemctl is-active swss); sleep 1; done', [r'#'], 180),
]

seq.extend([
('pkill dhclient', [r'#']),
Expand Down Expand Up @@ -145,7 +137,6 @@ def main():
mgmt_gw=dict(required=True),
new_password=dict(required=True),
num_asic=dict(required=True),
disable_updategraph=dict(required=True, type='bool'),
))

try:
Expand Down
6 changes: 0 additions & 6 deletions ansible/roles/vm_set/tasks/kickstart_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
respin_vms: []
when: respin_vms is not defined

- set_fact:
disable_updategraph: False
when: disable_updategraph is not defined

- set_fact:
skip_this_vm: True

Expand Down Expand Up @@ -65,7 +61,6 @@
mgmt_gw={{ vm_mgmt_gw | default(mgmt_gw) }}
new_password={{ sonic_password }}
num_asic={{ num_asic }}
disable_updategraph={{ disable_updategraph }}
register: kickstart_output
until: '"kickstart_code" in kickstart_output and kickstart_output.kickstart_code == 0'
retries: 5
Expand Down Expand Up @@ -97,7 +92,6 @@
mgmt_gw={{ vm_mgmt_gw | default(mgmt_gw) }}
new_password={{ sonic_password }}
num_asic={{ num_asic }}
disable_updategraph={{ disable_updategraph }}
register: kickstart_output_final
until: '"kickstart_code" in kickstart_output_final and kickstart_output_final.kickstart_code == 0'
retries: 5
Expand Down
5 changes: 0 additions & 5 deletions ansible/roles/vm_set/tasks/start_sonic_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
sonic_vm_storage_location: "{{ home_path }}/sonic-vm"
when: sonic_vm_storage_location is not defined

- set_fact:
disable_updategraph: False
when: disable_updategraph is not defined

- name: Create directory for vm images and vm disks
file: path={{ item }} state=directory mode=0755
with_items:
Expand Down Expand Up @@ -66,7 +62,6 @@
mgmt_gw={{ vm_mgmt_gw | default(mgmt_gw) }}
new_password={{ sonic_password }}
num_asic={{ num_asic }}
disable_updategraph={{ disable_updategraph }}
register: kickstart_output

- name: Fail if kickstart gives error for {{ dut_name }}
Expand Down
1 change: 0 additions & 1 deletion ansible/testbed-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function usage
echo "To deploy topology for specified testbed on a server: $0 add-topo 'testbed-name' ~/.password"
echo " Optional argument for add-topo:"
echo " -e ptf_imagetag=<tag> # Use PTF image with specified tag for creating PTF container"
echo " -e disable_updategraph=<true|false> # Disable updategraph service when deploying testbed"
echo "To deploy topology with the help of the last cached deployed topology for the specified testbed on a server:"
echo " $0 deploy-topo-with-cache 'testbed-name' 'inventory' ~/.password"
echo "To remove topology for specified testbed on a server: $0 remove-topo 'testbed-name' ~/.password"
Expand Down
26 changes: 13 additions & 13 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,19 @@ stages:
KVM_IMAGE_BRANCH: $(BUILD_BRANCH)
MGMT_BRANCH: $(BUILD_BRANCH)

- job: dpu_elastictest
displayName: "kvmtest-dpu by Elastictest"
timeoutInMinutes: 240
continueOnError: false
pool: ubuntu-20.04
steps:
- template: .azure-pipelines/run-test-elastictest-template.yml
parameters:
TOPOLOGY: dpu
MIN_WORKER: $(T0_SONIC_INSTANCE_NUM)
MAX_WORKER: $(T0_SONIC_INSTANCE_NUM)
KVM_IMAGE_BRANCH: $(BUILD_BRANCH)
MGMT_BRANCH: $(BUILD_BRANCH)
# - job: dpu_elastictest
# displayName: "kvmtest-dpu by Elastictest"
# timeoutInMinutes: 240
# continueOnError: false
# pool: ubuntu-20.04
# steps:
# - template: .azure-pipelines/run-test-elastictest-template.yml
# parameters:
# TOPOLOGY: dpu
# MIN_WORKER: $(T0_SONIC_INSTANCE_NUM)
# MAX_WORKER: $(T0_SONIC_INSTANCE_NUM)
# KVM_IMAGE_BRANCH: $(BUILD_BRANCH)
# MGMT_BRANCH: $(BUILD_BRANCH)

# - job: wan_elastictest
# displayName: "kvmtest-wan by Elastictest"
Expand Down
2 changes: 2 additions & 0 deletions docs/api_wiki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def test_fun(duthosts, rand_one_dut_hostname, ptfhost):

- [get_vlan_intfs](sonichost_methods/get_vlan_intfs.md) - Retrieves list of interfaces belonging to a VLAN.

- [get_vlan_brief](sonichost_methods/get_vlan_brief.md) - Returns a dict contians all vlans with their brief information

- [hostname](sonichost_methods/hostname.md) - Provides hostname for device.

- [is_backend_portchannel](sonichost_methods/is_backend_portchannel.md) - Returns whether or not a provided portchannel is a backend portchannel.
Expand Down
48 changes: 48 additions & 0 deletions docs/api_wiki/sonichost_methods/get_vlan_brief.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# get_vlan_brief

- [Overview](#overview)
- [Examples](#examples)
- [Arguments](#arguments)
- [Expected Output](#expected-output)
- [Potential Exception](#potential-exception)

## Overview

Read vlan brief information from running config.

## Examples

```python
def test_fun(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
vlan_brief = duthost.get_vlan_brief()
```

## Arguments

None

## Expected Output

Returns an dict, key is vlan name and value is brief information.

Example output:

```
{
"Vlan1000": {
"interface_ipv4": [ "192.168.0.1/24" ],
"interface_ipv6": [ "fc02:1000::1/64" ],
"members": ["Ethernet0", "Ethernet1"]
},
"Vlan2000": {
"interface_ipv4": [ "192.168.1.1/24" ],
"interface_ipv6": [ "fc02:1001::1/64" ],
"members": ["Ethernet3", "Ethernet4"]
}
}
```

## Potential Exception

- [Exception from function get_running_config_facts](get_running_config_facts.md)
Loading

0 comments on commit d5f7a5e

Please sign in to comment.