mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Add regression tests for #41982
These test the scenarios where another network with a similar name already exists, verifying that network_absent doesn't attempt to remove a network which isn't specified, and network_present still attempts to create the specified network despite a similarly named network already being present.
This commit is contained in:
parent
3369f0072f
commit
9eea796da8
@ -698,10 +698,18 @@ class DockerngTestCase(TestCase):
|
||||
dockerng_create_network = Mock(return_value='created')
|
||||
dockerng_connect_container_to_network = Mock(return_value='connected')
|
||||
dockerng_inspect_container = Mock(return_value={'Id': 'abcd'})
|
||||
# Get dockerng.networks to return a network with a name which is a superset of the name of
|
||||
# the network which is to be created, despite this network existing we should still expect
|
||||
# that the new network will be created.
|
||||
# Regression test for #41982.
|
||||
dockerng_networks = Mock(return_value=[{
|
||||
'Name': 'network_foobar',
|
||||
'Containers': {'container': {}}
|
||||
}])
|
||||
__salt__ = {'dockerng.create_network': dockerng_create_network,
|
||||
'dockerng.inspect_container': dockerng_inspect_container,
|
||||
'dockerng.connect_container_to_network': dockerng_connect_container_to_network,
|
||||
'dockerng.networks': Mock(return_value=[]),
|
||||
'dockerng.networks': dockerng_networks,
|
||||
}
|
||||
with patch.dict(dockerng_state.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
@ -746,6 +754,36 @@ class DockerngTestCase(TestCase):
|
||||
'removed': 'removed'},
|
||||
'result': True})
|
||||
|
||||
def test_network_absent_with_matching_network(self):
|
||||
'''
|
||||
Test dockerng.network_absent when the specified network does not exist,
|
||||
but another network with a name which is a superset of the specified
|
||||
name does exist. In this case we expect there to be no attempt to remove
|
||||
any network.
|
||||
Regression test for #41982.
|
||||
'''
|
||||
dockerng_remove_network = Mock(return_value='removed')
|
||||
dockerng_disconnect_container_from_network = Mock(return_value='disconnected')
|
||||
dockerng_networks = Mock(return_value=[{
|
||||
'Name': 'network_foobar',
|
||||
'Containers': {'container': {}}
|
||||
}])
|
||||
__salt__ = {'dockerng.remove_network': dockerng_remove_network,
|
||||
'dockerng.disconnect_container_from_network': dockerng_disconnect_container_from_network,
|
||||
'dockerng.networks': dockerng_networks,
|
||||
}
|
||||
with patch.dict(dockerng_state.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
ret = dockerng_state.network_absent(
|
||||
'network_foo',
|
||||
)
|
||||
dockerng_disconnect_container_from_network.assert_not_called()
|
||||
dockerng_remove_network.assert_not_called()
|
||||
self.assertEqual(ret, {'name': 'network_foo',
|
||||
'comment': 'Network \'network_foo\' already absent',
|
||||
'changes': {},
|
||||
'result': True})
|
||||
|
||||
def test_volume_present(self):
|
||||
'''
|
||||
Test dockerng.volume_present
|
||||
|
Loading…
Reference in New Issue
Block a user