Ejemplo n.º 1
0
 def test_wait_success(self):
     client = Mock()
     client.api_version = '1.21'
     client.wait = Mock(return_value=0)
     dockerng_inspect_container = Mock(side_effect=[{
         'State': {
             'Running': True
         }
     }, {
         'State': {
             'Stopped': True
         }
     }])
     with patch.object(dockerng_mod, 'inspect_container',
                       dockerng_inspect_container):
         with patch.dict(dockerng_mod.__context__,
                         {'docker.client': client}):
             dockerng_mod._clear_context()
             result = dockerng_mod.wait('foo')
     self.assertEqual(
         result, {
             'result': True,
             'exit_status': 0,
             'state': {
                 'new': 'stopped',
                 'old': 'running'
             }
         })
Ejemplo n.º 2
0
 def test_wait_fails_on_exit_status_and_already_stopped(self):
     client = Mock()
     client.api_version = '1.21'
     client.wait = Mock(return_value=1)
     dockerng_inspect_container = Mock(side_effect=[{
         'State': {
             'Stopped': True
         }
     }, {
         'State': {
             'Stopped': True
         }
     }])
     with patch.object(dockerng_mod, 'inspect_container',
                       dockerng_inspect_container):
         with patch.dict(dockerng_mod.__context__,
                         {'docker.client': client}):
             dockerng_mod._clear_context()
             result = dockerng_mod.wait('foo',
                                        ignore_already_stopped=True,
                                        fail_on_exit_status=True)
     self.assertEqual(
         result, {
             'result': False,
             'comment': "Container 'foo' already stopped",
             'exit_status': 1,
             'state': {
                 'new': 'stopped',
                 'old': 'stopped'
             }
         })
Ejemplo n.º 3
0
 def test_wait_success_absent_container(self):
     client = Mock()
     client.api_version = '1.21'
     dockerng_inspect_container = Mock(side_effect=CommandExecutionError)
     with patch.object(dockerng_mod, 'inspect_container',
                       dockerng_inspect_container):
         with patch.dict(dockerng_mod.__context__,
                         {'docker.client': client}):
             dockerng_mod._clear_context()
             result = dockerng_mod.wait('foo', ignore_already_stopped=True)
     self.assertEqual(result, {'result': True,
                               'comment': "Container 'foo' absent"})
Ejemplo n.º 4
0
 def test_images_with_empty_tags(self):
     """
     docker 1.12 reports also images without tags with `null`.
     """
     client = Mock()
     client.api_version = '1.24'
     client.images = Mock(return_value=[{
         'Id': 'sha256:abcde',
         'RepoTags': None
     }, {
         'Id': 'sha256:abcdef'
     }, {
         'Id': 'sha256:abcdefg',
         'RepoTags': ['image:latest']
     }])
     with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
         dockerng_mod._clear_context()
         result = dockerng_mod.images()
     self.assertEqual(result,
                      {'sha256:abcdefg': {
                          'RepoTags': ['image:latest']
                      }})