Esempio n. 1
0
 def test_absent(self):
     '''
     Test docker_network.absent
     '''
     docker_remove_network = Mock(return_value='removed')
     docker_disconnect_container_from_network = Mock(
         return_value='disconnected')
     docker_networks = Mock(return_value=[{
         'Name': 'network_foo',
         'Containers': {
             'container': {}
         }
     }])
     __salt__ = {
         'docker.remove_network': docker_remove_network,
         'docker.disconnect_container_from_network':
         docker_disconnect_container_from_network,
         'docker.networks': docker_networks,
     }
     with patch.dict(docker_state.__dict__, {'__salt__': __salt__}):
         ret = docker_state.absent('network_foo')
     docker_disconnect_container_from_network.assert_called_with(
         'container', 'network_foo')
     docker_remove_network.assert_called_with('network_foo')
     self.assertEqual(
         ret, {
             'name': 'network_foo',
             'comment': '',
             'changes': {
                 'disconnected': 'disconnected',
                 'removed': 'removed'
             },
             'result': True
         })
Esempio n. 2
0
 def test_absent_with_matching_network(self):
     '''
     Test docker_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.
     '''
     docker_remove_network = Mock(return_value='removed')
     docker_disconnect_container_from_network = Mock(
         return_value='disconnected')
     docker_networks = Mock(return_value=[{
         'Name': 'network_foobar',
         'Containers': {
             'container': {}
         }
     }])
     __salt__ = {
         'docker.remove_network': docker_remove_network,
         'docker.disconnect_container_from_network':
         docker_disconnect_container_from_network,
         'docker.networks': docker_networks,
     }
     with patch.dict(docker_state.__dict__, {'__salt__': __salt__}):
         ret = docker_state.absent('network_foo')
     docker_disconnect_container_from_network.assert_not_called()
     docker_remove_network.assert_not_called()
     self.assertEqual(
         ret, {
             'name': 'network_foo',
             'comment': 'Network \'network_foo\' already absent',
             'changes': {},
             'result': True
         })