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
4 changes: 3 additions & 1 deletion ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ callback_whitelist = profile_tasks
# wanting to use, for example, IP information from one group of servers
# without having to talk to them in the same playbook run to get their
# current IP information.
fact_caching = memory
fact_caching = jsonfile
fact_caching_connection = ~/.ansible/cache
fact_caching_timeout = 600


# retry files
Expand Down
6 changes: 4 additions & 2 deletions ansible/roles/vm_set/library/vm_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def iface_updown(iface_name, state, pid):
@staticmethod
def cmd(cmdline):
with open(CMD_DEBUG_FNAME, 'a') as fp:
pprint(cmdline, fp)
pprint("CMD: %s" % cmdline, fp)
cmd = cmdline.split(' ')
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
Expand All @@ -453,6 +453,8 @@ def cmd(cmdline):
if ret_code != 0:
raise Exception("ret_code=%d, error message=%s. cmd=%s" % (ret_code, stderr, cmdline))

with open(CMD_DEBUG_FNAME, 'a') as fp:
pprint("OUTPUT: %s" % stdout, fp)
return stdout

@staticmethod
Expand Down Expand Up @@ -486,7 +488,7 @@ def ifconfig(cmdline):
continue
terms = row.split()
if not row[0].isspace():
ifaces.add(terms[0])
ifaces.add(terms[0].rstrip(':'))

return ifaces

Expand Down
3 changes: 2 additions & 1 deletion ansible/roles/vm_set/tasks/add_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
net: none
detach: True
cap_add: NET_ADMIN
become: yes

- name: Bind topology {{ topo }} to VMs. base vm = {{ VM_base }} base vlan = {{ vlan_base }}
vm_topology:
Expand All @@ -24,4 +25,4 @@
mgmt_bridge: "{{ mgmt_bridge }}"
ext_iface: "{{ external_iface }}"
fp_mtu: "{{ fp_mtu_size }}"

become: yes
58 changes: 56 additions & 2 deletions ansible/roles/vm_set/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# - id: sequence number for vm set on the host.
# - external_iface: interface which will be used as parent for vlan interface creation
# - vlan_base: first vlan id for the VMs
# - VMs: a dictionary which contains hostnames of VMs as a key and a dictionary with parameters (num, memory, mgmt_ip) for every VM.
# - VMs: a dictionary which contains hostnames of VMs as a key and a dictionary with parameters (num, memory, mgmt_ip) for every VM.
# - topology: a dictionary which contains hostnames of VMs as a key and vlans value which define a topology (numbers of connected ports for every VM)
# - mgmt_bridge: linux bridge which is used for management interface connections
# - root_path: path where disk images for VMs are created
Expand All @@ -13,8 +13,49 @@
# - vm_images_url: url where base images are located
# - vmimages_saskey: a key for Azure download service. Could be set to ''

# Need latest ubuntu 4.10 kernel to fix a openvswitch bug
# https://bugs.launchpad.net/ubuntu/+source/kernel-package/+bug/1685742
- name: Check if kernel upgrade needed
set_fact:
kernel_upgrade_needed: true
when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_version == "17.04"
- ansible_kernel.find('4.10.0') != -1
- "{{ ansible_kernel | regex_replace('4.10.0-([0-9]+)-.*', '\\1') | int < 25 }}"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to make this kernel upgrade? Can you please leave a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments

- block:
- debug: msg="{{ ansible_kernel }}"

- 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

- name: Add docker repository for 17.04
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu zesty stable
state: present
become: yes
when: ansible_distribution_version == "17.04"

- name: Add docker repository for 16.04
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
become: yes
when: ansible_distribution_version == "16.04"

- name: Install necessary packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
apt: pkg={{ item }} update_cache=yes cache_valid_time=86400
become: yes
with_items:
- qemu
- openvswitch-switch
Expand All @@ -26,11 +67,24 @@
- libvirt-bin
- python-libvirt
- python-pip
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- docker-ce

- name: Install python packages
pip: name=docker-py state=present version=1.7.2
become: yes
environment: "{{ proxy_env | default({}) }}"

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need br_netfilter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in roles/vm_set/test/start.yml

""

  • 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: Ensure {{ root_path }} exists
file: path={{ root_path }} state=directory

- name: Install cleanup script
template: src=cleanup.sh.j2
dest={{ root_path }}/cleanup.sh
Expand Down
3 changes: 2 additions & 1 deletion ansible/roles/vm_set/tasks/remove_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name: ptf_{{ vm_set_name }}
image: "{{ docker_registry_host }}/{{ ptf_imagename }}"
state: absent
become: yes

- name: Unbind topology {{ topo }} to VMs. base vm = {{ VM_base }} base vlan = {{ vlan_base }}
vm_topology:
Expand All @@ -13,4 +14,4 @@
vm_base: "{{ VM_base }}"
vlan_base: "{{ vlan_base }}"
ext_iface: "{{ external_iface }}"

become: yes
4 changes: 3 additions & 1 deletion ansible/roles/vm_set/tasks/renumber_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name: ptf_{{ vm_set_name }}
image: "{{ docker_registry_host }}/{{ ptf_imagename }}"
state: absent
become: yes

- name: Create a docker container ptf_{{ vm_set_name }}
docker:
Expand All @@ -16,6 +17,7 @@
net: none
detach: True
cap_add: NET_ADMIN
become: yes

- name: Renumber topology {{ topo }} to VMs. base vm = {{ VM_base }} base vlan = {{ vlan_base }}
vm_topology:
Expand All @@ -30,4 +32,4 @@
mgmt_bridge: "{{ mgmt_bridge }}"
ext_iface: "{{ external_iface }}"
fp_mtu: "{{ fp_mtu_size }}"

become: yes
3 changes: 3 additions & 0 deletions ansible/roles/vm_set/tasks/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
name: "{{ item }}"
value: 0
sysctl_set: yes
become: yes
with_items:
- net.bridge.bridge-nf-call-arptables
- net.bridge.bridge-nf-call-ip6tables
Expand All @@ -13,6 +14,7 @@
name: "net.core.rmem_max"
value: 509430500
sysctl_set: yes
become: yes

- name: Create directory for vm images and vm disks
file: path={{ item }} state=directory mode=0755 recurse=yes
Expand Down Expand Up @@ -45,6 +47,7 @@
when: not cd_stat.stat.exists and not skip_image_downloading

- name: Create VMs network
become: yes
vm_topology:
cmd: 'create'
vm_names: "{{ VM_hosts }}"
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/vm_set/tasks/stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
vm_topology:
cmd: 'destroy'
vm_names: "{{ VM_hosts }}"

become: yes
1 change: 0 additions & 1 deletion ansible/testbed_add_vm_topology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container

- hosts: servers:&vm_host
gather_facts: no
become: true
vars_files:
- vars/docker_registry.yml
Expand Down
3 changes: 0 additions & 3 deletions ansible/testbed_start_VMs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
#

- hosts: servers:&vm_host
gather_facts: no
become: true
vars_files:
- vars/azure_storage.yml
tasks:
roles:
- { role: vm_set, action: 'start' }