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 authored Oct 11, 2023
2 parents 112da65 + 39228d1 commit 4341f17
Show file tree
Hide file tree
Showing 13 changed files with 703 additions and 213 deletions.
8 changes: 5 additions & 3 deletions ansible/roles/vm_set/library/ptf_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ def get_pid(ctn_name):
cli = docker.from_env()
try:
ctn = cli.containers.get(ctn_name)
except Exception:
return None
if ctn.status == 'running':
return ctn.attrs['State']['Pid']
except Exception as e:
logging.debug("Failed to get pid for container %s: %s" % (ctn_name, str(e)))

return ctn.attrs['State']['Pid']
return None

def get_process_pids(self, process):
cmd = 'docker exec -t {} bash -c "pgrep -f \'{}\'"'.format(self.ctn_name, process)
Expand Down
234 changes: 234 additions & 0 deletions ansible/roles/vm_set/tasks/configure_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
- name: Check flag file to see if server is configured
stat:
path: /var/run/sonic/server_ready
register: server_ready

- name: Check if force configure server is set
set_fact:
force_configure_server: false
when: force_configure_server is not defined

- block:
- name: Firstly clear the server ready flag file
file:
path: /var/run/sonic/server_ready
state: absent
become: yes

- name: Set default apt_lock_timeout
set_fact:
support_apt_lock_timeout: false

# Ansible apt module supports argument "lock_timeout" since ansible core version 2.12
# - https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#parameter-lock_timeout
# We can take advantage of this argument to avoid potential apt lock conflicts while running add-topo in parallel
# for multiple testbeds on the same server.
# The problem is that ansible version in sonic-mgmt docker image is not upgraded to 2.12 yet. So, we need to
# check ansible version and set the support_apt_lock_timeout flag accordingly. Then we can use this flag to
# decide whether to use lock_timeout argument in apt module or not. In the future, when ansible version in
# sonic-mgmt docker image is upgraded to 2.12, we can benefit from the lock_timeout argument directly.
- name: Support apt lock_timeout or not
set_fact:
support_apt_lock_timeout: true
when:
- ansible_version.major|int >= 2
- ansible_version.minor|int >= 12

- name: Check if kernel upgrade needed
set_fact:
kernel_upgrade_needed: true
when:
- host_distribution.stdout == "Ubuntu"
- host_distribution_version.stdout == "17.04"
- host_kernel.stdout.find('4.10.0') != -1
- "{{ host_kernel.stdout | regex_replace('4.10.0-([0-9]+)-.*', '\\1') | int < 25 }}"

- block:
- debug: msg="{{ host_kernel.stdout }}"

- name: Upgrade kernel package
apt: pkg={{ item }} state=latest
become: yes
with_items:
- linux-image-generic
- linux-image-extra-virtual
when: not support_apt_lock_timeout|bool

- name: Upgrade kernel package
apt: pkg={{ item }} state=latest lock_timeout=600
become: yes
with_items:
- linux-image-generic
- linux-image-extra-virtual
when: support_apt_lock_timeout|bool

- name: Prompt for rebooting
fail:
msg: "Kernel upgraded, need to reboot!"
when:
- kernel_upgrade_needed is defined
- package_installation|bool

- block:
- name: Install necessary packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=86400
become: yes
with_items:
- ifupdown
- qemu
- openvswitch-switch
- net-tools
- bridge-utils
- util-linux
- iproute2
- vlan
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- libvirt-clients
when: not support_apt_lock_timeout|bool

- name: Install necessary packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=86400 lock_timeout=600
become: yes
with_items:
- ifupdown
- qemu
- openvswitch-switch
- net-tools
- bridge-utils
- util-linux
- iproute2
- vlan
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- libvirt-clients
when: support_apt_lock_timeout|bool

- name: Install necessary packages
apt:
pkg:
- python
- libvirt-bin
- python-libvirt
- python-pip
become: yes
when:
- host_distribution_version.stdout == "18.04"
- not support_apt_lock_timeout|bool

- name: Install necessary packages
apt:
pkg:
- python
- libvirt-bin
- python-libvirt
- python-pip
lock_timeout: 600
become: yes
when:
- host_distribution_version.stdout == "18.04"
- support_apt_lock_timeout|bool

- name: Install necessary packages
apt:
pkg:
- python3-libvirt
- python3-pip
- libvirt-daemon-system
- qemu-system-x86
become: yes
when:
- host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04"
- not support_apt_lock_timeout|bool

- name: Install necessary packages
apt:
pkg:
- python3-libvirt
- python3-pip
- libvirt-daemon-system
- qemu-system-x86
lock_timeout: 600
become: yes
when:
- host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04"
- support_apt_lock_timeout|bool

when: package_installation|bool

- name: remove old python packages
pip: name=docker-py state=absent executable={{ pip_executable }}
environment: "{{ proxy_env | default({}) }}"
ignore_errors: yes

- include_tasks: docker.yml
when: package_installation|bool

- name: Ensure {{ ansible_user }} in docker,sudo group
user:
name: "{{ ansible_user }}"
append: yes
groups: docker,sudo
become: yes

- name: Ensure {{ ansible_user }} in libvirt group
user:
name: "{{ ansible_user }}"
append: yes
groups: libvirt
become: yes
when: host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04"

- name: Install br_netfilter kernel module
become: yes
modprobe: name=br_netfilter state=present

- name: Set sysctl bridge parameters for testbed
sysctl:
name: "{{ item }}"
value: "0"
sysctl_set: yes
become: yes
with_items:
- net.bridge.bridge-nf-call-arptables
- net.bridge.bridge-nf-call-ip6tables
- net.bridge.bridge-nf-call-iptables

- name: Set sysctl RCVBUF max parameter for testbed
sysctl:
name: "net.core.rmem_max"
value: "509430500"
sysctl_set: yes
become: yes

- name: Set sysctl RCVBUF default parameter for testbed
sysctl:
name: "net.core.rmem_default"
value: "31457280"
sysctl_set: yes
become: yes

- name: Setup external front port
include_tasks: external_port.yml
when: external_port is defined

- name: Setup internal management network
include_tasks: internal_mgmt_network.yml
when: internal_mgmt_network is defined and internal_mgmt_network == True

- name: Prepare parent directory
shell:
cmd: "mkdir -p /var/run/sonic"
become: yes

- name: Set the server ready flag file
file:
path: /var/run/sonic/server_ready
state: touch
become: yes

when: not server_ready.stat.exists or force_configure_server|bool
128 changes: 3 additions & 125 deletions ansible/roles/vm_set/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,72 +35,6 @@
register: host_kernel
changed_when: False

- name: Check if kernel upgrade needed
set_fact:
kernel_upgrade_needed: true
when:
- host_distribution.stdout == "Ubuntu"
- host_distribution_version.stdout == "17.04"
- host_kernel.stdout.find('4.10.0') != -1
- "{{ host_kernel.stdout | regex_replace('4.10.0-([0-9]+)-.*', '\\1') | int < 25 }}"

- block:
- debug: msg="{{ host_kernel.stdout }}"

- name: Upgrade kernel package
apt: pkg={{ item }} state=latest
become: yes
with_items:
- linux-image-generic
- linux-image-extra-virtual

- name: Prompt for rebooting
fail:
msg: "Kernel upgraded, need to reboot!"
when:
- kernel_upgrade_needed is defined
- package_installation|bool

- block:
- name: Install necessary packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=86400
become: yes
with_items:
- ifupdown
- qemu
- openvswitch-switch
- net-tools
- bridge-utils
- util-linux
- iproute2
- vlan
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- libvirt-clients

- name: Install necessary packages
apt:
pkg:
- python
- libvirt-bin
- python-libvirt
- python-pip
become: yes
when: host_distribution_version.stdout == "18.04"

- name: Install necessary packages
apt:
pkg:
- python3-libvirt
- python3-pip
- libvirt-daemon-system
- qemu-system-x86
become: yes
when: host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04"
when: package_installation|bool

- name: Get default pip_executable
set_fact:
pip_executable: pip
Expand All @@ -111,65 +45,9 @@
pip_executable: pip3
when: pip_executable is not defined and (host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04")

- name: remove old python packages
pip: name=docker-py state=absent executable={{ pip_executable }}
environment: "{{ proxy_env | default({}) }}"
ignore_errors: yes

- include_tasks: docker.yml
when: package_installation|bool

- name: Ensure {{ ansible_user }} in docker,sudo group
user:
name: "{{ ansible_user }}"
append: yes
groups: docker,sudo
become: yes

- name: Ensure {{ ansible_user }} in libvirt group
user:
name: "{{ ansible_user }}"
append: yes
groups: libvirt
become: yes
when: host_distribution_version.stdout == "20.04" or host_distribution_version.stdout == "22.04"

- name: Install br_netfilter kernel module
become: yes
modprobe: name=br_netfilter state=present

- name: Set sysctl bridge parameters for testbed
sysctl:
name: "{{ item }}"
value: "0"
sysctl_set: yes
become: yes
with_items:
- net.bridge.bridge-nf-call-arptables
- net.bridge.bridge-nf-call-ip6tables
- net.bridge.bridge-nf-call-iptables

- name: Set sysctl RCVBUF max parameter for testbed
sysctl:
name: "net.core.rmem_max"
value: "509430500"
sysctl_set: yes
become: yes

- name: Set sysctl RCVBUF default parameter for testbed
sysctl:
name: "net.core.rmem_default"
value: "31457280"
sysctl_set: yes
become: yes

- name: Setup external front port
include_tasks: external_port.yml
when: external_port is defined

- name: Setup internal management network
include_tasks: internal_mgmt_network.yml
when: internal_mgmt_network is defined and internal_mgmt_network == True
- name: Configure server
include_tasks: configure_server.yml
when: action == 'configure_server'

- block:
- getent:
Expand Down
Loading

0 comments on commit 4341f17

Please sign in to comment.