def test_originals_skipped(self): original = dict(Id="a") introduced = dict(Id="b") self.mock_client.containers.return_value = original, introduced cleanup.remove_build_containers(self.mock_client, set([original["Id"]])) self.mock_client.remove_container.assert_called_with("b", force=True)
def test_containers_removed(self): containers = [dict(Id="a"), dict(Id="b")] self.mock_client.containers.return_value = containers cleanup.remove_build_containers(self.mock_client, set([])) assert self.mock_client.remove_container.call_args_list == [ mock.call( "a", force=True), mock.call( "b", force=True) ]
def cleanup(self): '''Cleanup the build context and results of the build process ''' public_log.step = 'cleanup' private_log.step = 'cleanup' try: if self.client: cleanup.remove_build_stage(self.build_code) cleanup.remove_build_containers(self.client, self.original_containers) cleanup.remove_build_tags(self.client, self.original_tags) except Exception: private_log.exception('Unexpected error while cleaning up')
def test_catches_exception(self): tags = [dict(RepoTags=["a"]), dict(RepoTags=["b"])] self.mock_client.images.return_value = tags self.mock_client.remove_tag.side_effect = Exception() cleanup.remove_build_containers(self.mock_client, set([]))
def test_catches_exception(self): containers = [dict(Id="a"), dict(Id="b")] self.mock_client.containers.return_value = containers self.mock_client.remove_container.side_effect = Exception() cleanup.remove_build_containers(self.mock_client, set([]))
def test_bail_on_no_originals(self): cleanup.remove_build_containers(self.mock_client, None) assert self.mock_client.containers.called is False