@ -20,11 +20,26 @@
from __future__ import ( absolute_import , division , print_function )
__metaclass__ = type
from units . compat . mock import patch
from ansible . modules . network . ovs import openvswitch_db
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_db ( monkeypatch ) :
mocked_ovs_db = MagicMock ( )
mocked_ovs_db . return_value = { ' table ' : ' open_vswitch ' ,
' record ' : ' . ' ,
' col ' : ' other_config ' ,
' key ' : ' pmd-cpu-mask ' ,
' value ' : ' 0xaaa00000000 ' }
monkeypatch . setattr ( openvswitch_db , ' map_config_to_obj ' , mocked_ovs_db )
return openvswitch_db
test_name_side_effect_matrix = {
' test_openvswitch_db_absent_idempotent ' : [
( 0 , ' openvswitch_db_disable_in_band_missing.cfg ' , None ) ,
@ -35,6 +50,8 @@ test_name_side_effect_matrix = {
' test_openvswitch_db_present_idempotent ' : [
( 0 , ' openvswitch_db_disable_in_band_true.cfg ' , None ) ,
( 0 , None , None ) ] ,
' test_openvswitch_db_present_idempotent_value ' : [
( 0 , None , None ) ] ,
' test_openvswitch_db_present_adds_key ' : [
( 0 , ' openvswitch_db_disable_in_band_missing.cfg ' , None ) ,
( 0 , None , None ) ] ,
@ -86,62 +103,71 @@ class TestOpenVSwitchDBModule(TestOpenVSwitchModule):
set_module_args ( dict ( state = ' absent ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' , key = ' disable-in-band ' ,
value = ' T rue' ) )
value = ' t rue' ) )
self . execute_module ( test_name = ' test_openvswitch_db_absent_idempotent ' )
def test_openvswitch_db_absent_removes_key ( self ) :
set_module_args ( dict ( state = ' absent ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' , key = ' disable-in-band ' ,
value = ' T rue' ) )
value = ' t rue' ) )
self . execute_module (
changed = True ,
commands = [ ' /usr/bin/ovs-vsctl -t 5 remove Bridge test-br other_config '
' disable-in-band= T rue' ] ,
' disable-in-band= t rue' ] ,
test_name = ' test_openvswitch_db_absent_removes_key ' )
def test_openvswitch_db_present_idempotent ( self ) :
set_module_args ( dict ( state = ' present ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' , key = ' disable-in-band ' ,
value = ' T rue' ) )
value = ' t rue' ) )
self . execute_module ( test_name = ' test_openvswitch_db_present_idempotent ' )
@pytest.mark.usefixtures ( ' patched_openvswitch_db ' )
def test_openvswitch_db_present_idempotent_value ( self ) :
set_module_args ( { " col " : " other_config " ,
" key " : " pmd-cpu-mask " ,
" record " : " . " ,
" table " : " open_vswitch " ,
" value " : " 0xaaa00000000 " } )
self . execute_module ( test_name = ' test_openvswitch_db_present_idempotent_value ' )
def test_openvswitch_db_present_adds_key ( self ) :
set_module_args ( dict ( state = ' present ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' , key = ' disable-in-band ' ,
value = ' True ' ) )
value = ' t rue' ) )
self . execute_module (
changed = True ,
commands = [ ' /usr/bin/ovs-vsctl -t 5 set Bridge test-br other_config '
' :disable-in-band=True ' ] ,
' :disable-in-band= t rue' ] ,
test_name = ' test_openvswitch_db_present_adds_key ' )
def test_openvswitch_db_present_updates_key ( self ) :
set_module_args ( dict ( state = ' present ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' , key = ' disable-in-band ' ,
value = ' F alse' ) )
value = ' f alse' ) )
self . execute_module (
changed = True ,
commands = [ ' /usr/bin/ovs-vsctl -t 5 set Bridge test-br other_config '
' :disable-in-band= F alse' ] ,
' :disable-in-band= f alse' ] ,
test_name = ' test_openvswitch_db_present_updates_key ' )
def test_openvswitch_db_present_missing_key_on_map ( self ) :
set_module_args ( dict ( state = ' present ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' other_config ' ,
value = ' F alse' ) )
value = ' f alse' ) )
self . execute_module (
failed = True ,
test_name = ' test_openvswitch_db_present_ idempotent ' )
test_name = ' test_openvswitch_db_present_ missing_key_on_map ' )
def test_openvswitch_db_present_stp_enable ( self ) :
set_module_args ( dict ( state = ' present ' ,
table = ' Bridge ' , record = ' test-br ' ,
col = ' stp_enable ' ,
value = ' Fals e' ) )
value = ' tru e' ) )
self . execute_module ( changed = True ,
test_name = ' test_openvswitch_db_present_stp_enable ' )