Esempio n. 1
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)
     docker_inspect_container = Mock(side_effect=[{
         'State': {
             'Stopped': True
         }
     }, {
         'State': {
             'Stopped': True
         }
     }])
     with patch.object(docker_mod, 'inspect_container',
                       docker_inspect_container):
         with patch.dict(docker_mod.__context__, {'docker.client': client}):
             docker_mod._clear_context()
             result = docker_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'
             }
         })
Esempio n. 2
0
    def test_wait_fails_on_exit_status(self):
        client = Mock()
        client.api_version = '1.21'
        client.wait = Mock(return_value=1)
        get_client_mock = MagicMock(return_value=client)

        docker_inspect_container = Mock(side_effect=[{
            'State': {
                'Running': True
            }
        }, {
            'State': {
                'Stopped': True
            }
        }])
        with patch.object(docker_mod, 'inspect_container',
                          docker_inspect_container):
            with patch.object(docker_mod, '_get_client', get_client_mock):
                docker_mod._clear_context()
                result = docker_mod.wait('foo', fail_on_exit_status=True)
        self.assertEqual(
            result, {
                'result': False,
                'exit_status': 1,
                'state': {
                    'new': 'stopped',
                    'old': 'running'
                }
            })
Esempio n. 3
0
 def test_wait_success(self):
     client = Mock()
     client.api_version = '1.21'
     client.wait = Mock(return_value=0)
     docker_inspect_container = Mock(side_effect=[{
         'State': {
             'Running': True
         }
     }, {
         'State': {
             'Stopped': True
         }
     }])
     with patch.object(docker_mod, 'inspect_container',
                       docker_inspect_container):
         with patch.dict(docker_mod.__context__, {'docker.client': client}):
             docker_mod._clear_context()
             result = docker_mod.wait('foo')
     self.assertEqual(
         result, {
             'result': True,
             'exit_status': 0,
             'state': {
                 'new': 'stopped',
                 'old': 'running'
             }
         })
Esempio n. 4
0
    def test_wait_success_already_stopped(self):
        client = Mock()
        client.api_version = '1.21'
        client.wait = Mock(return_value=0)
        get_client_mock = MagicMock(return_value=client)

        docker_inspect_container = Mock(side_effect=[
            {
                'State': {
                    'Stopped': True
                }
            },
            {
                'State': {
                    'Stopped': True
                }
            },
        ])
        with patch.object(docker_mod, 'inspect_container',
                          docker_inspect_container):
            with patch.object(docker_mod, '_get_client', get_client_mock):
                docker_mod._clear_context()
                result = docker_mod.wait('foo', ignore_already_stopped=True)
        self.assertEqual(
            result, {
                'result': True,
                'comment': "Container 'foo' already stopped",
                'exit_status': 0,
                'state': {
                    'new': 'stopped',
                    'old': 'stopped'
                }
            })
Esempio n. 5
0
def test_images_with_empty_tags():
    """
    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"]
        },
    ])
    get_client_mock = MagicMock(return_value=client)

    with patch.object(docker_mod, "_get_client", get_client_mock):
        docker_mod._clear_context()
        result = docker_mod.images()
    assert result == {"sha256:abcdefg": {"RepoTags": ["image:latest"]}}
Esempio n. 6
0
def test_wait_fails_on_exit_status_and_already_stopped():
    client = Mock()
    client.api_version = "1.21"
    client.wait = Mock(return_value=1)
    get_client_mock = MagicMock(return_value=client)

    docker_inspect_container = Mock(side_effect=[{
        "State": {
            "Stopped": True
        }
    }, {
        "State": {
            "Stopped": True
        }
    }])
    with patch.object(docker_mod, "inspect_container",
                      docker_inspect_container):
        with patch.object(docker_mod, "_get_client", get_client_mock):
            docker_mod._clear_context()
            result = docker_mod.wait("foo",
                                     ignore_already_stopped=True,
                                     fail_on_exit_status=True)
    assert result == {
        "result": False,
        "comment": "Container 'foo' already stopped",
        "exit_status": 1,
        "state": {
            "new": "stopped",
            "old": "stopped"
        },
    }
Esempio n. 7
0
def test_wait_success():
    client = Mock()
    client.api_version = "1.21"
    client.wait = Mock(return_value=0)
    get_client_mock = MagicMock(return_value=client)

    docker_inspect_container = Mock(side_effect=[{
        "State": {
            "Running": True
        }
    }, {
        "State": {
            "Stopped": True
        }
    }])
    with patch.object(docker_mod, "inspect_container",
                      docker_inspect_container):
        with patch.object(docker_mod, "_get_client", get_client_mock):
            docker_mod._clear_context()
            result = docker_mod.wait("foo")
    assert result == {
        "result": True,
        "exit_status": 0,
        "state": {
            "new": "stopped",
            "old": "running"
        },
    }
Esempio n. 8
0
def test_wait_success_absent_container():
    client = Mock()
    client.api_version = "1.21"
    get_client_mock = MagicMock(return_value=client)

    docker_inspect_container = Mock(side_effect=CommandExecutionError)
    with patch.object(docker_mod, "inspect_container",
                      docker_inspect_container):
        with patch.object(docker_mod, "_get_client", get_client_mock):
            docker_mod._clear_context()
            result = docker_mod.wait("foo", ignore_already_stopped=True)
    assert result == {"result": True, "comment": "Container 'foo' absent"}
Esempio n. 9
0
    def test_wait_success_absent_container(self):
        client = Mock()
        client.api_version = '1.21'
        get_client_mock = MagicMock(return_value=client)

        docker_inspect_container = Mock(side_effect=CommandExecutionError)
        with patch.object(docker_mod, 'inspect_container',
                          docker_inspect_container):
            with patch.object(docker_mod, '_get_client', get_client_mock):
                docker_mod._clear_context()
                result = docker_mod.wait('foo', ignore_already_stopped=True)
        self.assertEqual(result, {'result': True,
                                  'comment': "Container 'foo' absent"})
Esempio n. 10
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']}])
        get_client_mock = MagicMock(return_value=client)

        with patch.object(docker_mod, '_get_client', get_client_mock):
            docker_mod._clear_context()
            result = docker_mod.images()
        self.assertEqual(result,
                         {'sha256:abcdefg': {'RepoTags': ['image:latest']}})
Esempio n. 11
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(docker_mod.__context__, {'docker.client': client}):
         docker_mod._clear_context()
         result = docker_mod.images()
     self.assertEqual(result,
                      {'sha256:abcdefg': {
                          'RepoTags': ['image:latest']
                      }})