From 602fdfa26b656562c17023789c7f4a1fb4495e47 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Thu, 8 Nov 2018 10:32:53 +0000 Subject: [PATCH] Remove dependency on bridge-utils bridge-utils is considered legacy and many distributions do not ship it as default. Change-Id: Id2f9d779d12a5135d7d7e7a4783c6f3a0c8647ca Story: 2004302 Task: 27861 --- ansible/roles/veth-pair/README.md | 4 +--- ansible/roles/veth-pair/tasks/absent.yml | 23 ++++++++++--------- ansible/roles/veth-pair/tasks/is-attached.yml | 22 ++++++++++++++++++ ansible/roles/veth-pair/tasks/present.yml | 23 +++++++++++-------- 4 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 ansible/roles/veth-pair/tasks/is-attached.yml diff --git a/ansible/roles/veth-pair/README.md b/ansible/roles/veth-pair/README.md index 918fc12..8bb03d6 100644 --- a/ansible/roles/veth-pair/README.md +++ b/ansible/roles/veth-pair/README.md @@ -15,9 +15,7 @@ This role manages a veth pair. Actions: Requirements ------------ -The host should have the `ip` and `ovs-vsctl` commands accessible. If -`veth_pair_plug_into_source` is enabled, the command `brctl` must also be -accessible. +The host should have the `ip` and `ovs-vsctl` commands accessible. Role Variables -------------- diff --git a/ansible/roles/veth-pair/tasks/absent.yml b/ansible/roles/veth-pair/tasks/absent.yml index dfa4d83..f61cb0a 100644 --- a/ansible/roles/veth-pair/tasks/absent.yml +++ b/ansible/roles/veth-pair/tasks/absent.yml @@ -1,16 +1,17 @@ --- -- name: Unplug veth from source bridge - command: >- - brctl delif {{ veth_pair_source_bridge }} - {{ veth_pair_source_link_name }} - register: res - failed_when: - - res.rc != 0 - # Case where veth is already unplugged. - - not (res.rc == 1 and 'does not exist' in res.stderr) - changed_when: res.rc == 0 +- block: + - include_tasks: is-attached.yml + vars: + bridge: "{{ veth_pair_source_bridge }}" + interface: "{{ veth_pair_source_link_name }}" + + - name: Unplug veth from source bridge + command: >- + ip link set {{ veth_pair_source_link_name }} nomaster + when: + - veth_pair_is_attached + become: true when: veth_pair_plug_into_source | bool - become: true - name: Delete veth pair command: >- diff --git a/ansible/roles/veth-pair/tasks/is-attached.yml b/ansible/roles/veth-pair/tasks/is-attached.yml new file mode 100644 index 0000000..db6d983 --- /dev/null +++ b/ansible/roles/veth-pair/tasks/is-attached.yml @@ -0,0 +1,22 @@ +--- + +# This will determine if interface is attached to bridge and set a fact called +# veth_pair_is_attached containing the result + +- name: Set a default value for veth_pair_is_attached + set_fact: + veth_pair_is_attached: false + +- name: Speculatively check {{ interface }}'s master + command: >- + realpath /sys/class/net/{{ interface }}/master + register: master_result + failed_when: false + changed_when: false + +- name: Determine if {{ interface }} is attached to {{ bridge }} + vars: + master: "{{ master_result.stdout | basename }}" + set_fact: + veth_pair_is_attached: "{{ master == bridge }}" + when: master_result.rc == 0 diff --git a/ansible/roles/veth-pair/tasks/present.yml b/ansible/roles/veth-pair/tasks/present.yml index 2793d96..0cca6ba 100644 --- a/ansible/roles/veth-pair/tasks/present.yml +++ b/ansible/roles/veth-pair/tasks/present.yml @@ -23,14 +23,17 @@ port: "{{ veth_pair_ovs_link_name }}" become: true -- name: Plug veth into source bridge - command: >- - brctl addif {{ veth_pair_source_bridge }} - {{ veth_pair_source_link_name }} - register: res - failed_when: - - res.rc != 0 - - "'already a member of a bridge' not in res.stderr" - changed_when: "'already a member of a bridge' not in res.stderr" +- block: + - include_tasks: is-attached.yml + vars: + bridge: "{{ veth_pair_source_bridge }}" + interface: "{{ veth_pair_source_link_name }}" + + - name: Plug veth into source bridge + command: >- + ip link set {{ veth_pair_source_link_name }} master + {{ veth_pair_source_bridge }} + when: + - not veth_pair_is_attached + become: true when: veth_pair_plug_into_source | bool - become: true