Add support for vlan update on ovs bridges (#57168)
This commit adds support for vlan update on openvswitch_bridge module.
This commit is contained in:
parent
72f2d05b6f
commit
091bebcbf7
3 changed files with 61 additions and 4 deletions
|
@ -140,6 +140,12 @@ def map_obj_to_commands(want, have, module):
|
|||
or want['external_ids'][k] != have['external_ids'][k]):
|
||||
command += " " + k + " " + v
|
||||
commands.append(command)
|
||||
|
||||
if want['vlan'] and want['vlan'] != have['vlan']:
|
||||
templatized_command = ("%(ovs-vsctl)s -t %(timeout)s"
|
||||
" set port %(bridge)s tag=%(vlan)s")
|
||||
command = templatized_command % module.params
|
||||
commands.append(command)
|
||||
else:
|
||||
templatized_command = ("%(ovs-vsctl)s -t %(timeout)s add-br"
|
||||
" %(bridge)s")
|
||||
|
@ -169,6 +175,7 @@ def map_obj_to_commands(want, have, module):
|
|||
command = templatized_command % module.params
|
||||
command += " " + k + " " + v
|
||||
commands.append(command)
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- result is changed
|
||||
|
||||
- name: Create bridge again (idempotent)
|
||||
openvswitch_bridge:
|
||||
|
@ -20,7 +20,29 @@
|
|||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
- result is not changed
|
||||
|
||||
- name: Tear down test bridge
|
||||
- name: Add fake bridge
|
||||
openvswitch_bridge:
|
||||
bridge: fake-br-test
|
||||
parent: br-test
|
||||
vlan: 100
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Change fake bridge vlan
|
||||
openvswitch_bridge:
|
||||
bridge: fake-br-test
|
||||
parent: br-test
|
||||
vlan: 300
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Tear down test bridges
|
||||
command: ovs-vsctl del-br br-test
|
||||
|
|
|
@ -20,11 +20,24 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.ovs import openvswitch_bridge
|
||||
from units.compat.mock import patch, MagicMock
|
||||
from units.modules.utils import set_module_args
|
||||
from .ovs_module import TestOpenVSwitchModule, load_fixture
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patched_openvswitch_bridge(monkeypatch):
|
||||
mocked_bridge = MagicMock()
|
||||
mocked_bridge.return_value = {'bridge': 'test-br2', 'parent': 'test-br',
|
||||
'vlan': 200, 'fail_mode': None,
|
||||
'external_ids': None, 'set': None}
|
||||
monkeypatch.setattr(openvswitch_bridge, 'map_config_to_obj', mocked_bridge)
|
||||
return openvswitch_bridge
|
||||
|
||||
|
||||
test_name_side_effect_matrix = {
|
||||
'test_openvswitch_bridge_absent_idempotent': [
|
||||
(0, '', '')],
|
||||
|
@ -51,6 +64,11 @@ test_name_side_effect_matrix = {
|
|||
(0, '', ''),
|
||||
(0, '', ''),
|
||||
(0, '', '')],
|
||||
'test_openvswitch_bridge_updates_vlan': [
|
||||
(0, '', ''),
|
||||
(0, '', ''),
|
||||
(0, '', ''),
|
||||
(0, '', '')],
|
||||
'test_openvswitch_bridge_present_adds_external_id': [
|
||||
(0, 'list_br_test_br.cfg', ''),
|
||||
(0, 'br_to_parent_test_br.cfg', ''),
|
||||
|
@ -155,6 +173,16 @@ class TestOpenVSwitchBridgeModule(TestOpenVSwitchModule):
|
|||
self.execute_module(changed=True, commands=commands,
|
||||
test_name='test_openvswitch_bridge_present_creates_fake_bridge')
|
||||
|
||||
@pytest.mark.usefixtures('patched_openvswitch_bridge')
|
||||
def test_openvswitch_bridge_updates_vlan(self):
|
||||
set_module_args({'state': 'present', 'bridge': 'test-br2', 'parent':
|
||||
'test-br', 'vlan': 300})
|
||||
commands = [
|
||||
'/usr/bin/ovs-vsctl -t 5 set port test-br2 tag=300'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands,
|
||||
test_name='test_openvswitch_bridge_updates_vlan')
|
||||
|
||||
def test_openvswitch_bridge_present_adds_external_id(self):
|
||||
set_module_args(dict(state='present',
|
||||
bridge='test-br',
|
||||
|
|
Loading…
Reference in a new issue