def test_list_docker_containers_with_input(self, mock_get_rootfs, mock_inspect, mocked_get_runtime_env, mocked_dockerps): ids = [c.short_id for c in get_docker_containers(user_list='1,2,8')] assert set(ids) == set(['1', '2', '8']) assert mocked_get_runtime_env.call_count == 3 ids = [c.long_id for c in get_docker_containers(user_list='5,3')] assert set(ids) == set(['3', '5'])
def test_list_docker_containers_with_input( self, mock_get_rootfs, mock_inspect, mocked_get_runtime_env, mocked_dockerps): ids = [c.short_id for c in get_docker_containers(user_list='1,2,8')] assert set(ids) == set(['1', '2', '8']) assert mocked_get_runtime_env.call_count == 3 ids = [c.long_id for c in get_docker_containers(user_list='5,3')] assert set(ids) == set(['3', '5'])
def list_all_containers(user_list='ALL', host_namespace='', ignore_raw_containers=True): """ Returns a list of all running containers in the host. :param user_list: list of Docker container IDs. TODO: include rkt Ids. :param host_namespace: string representing the host name (e.g. host IP) :param ignore_raw_containers: if True, only include Docker or rkt. An example of a non-docker container is a chromium-browser process. :return: a list of Container objects """ visited_ns = set() # visited PID namespaces for _container in get_docker_containers(host_namespace=host_namespace, user_list=user_list): curr_ns = _container.process_namespace if curr_ns not in visited_ns: visited_ns.add(curr_ns) yield _container # XXX get list of rkt containers if ignore_raw_containers: return for _container in container.list_raw_containers(user_list): curr_ns = _container.process_namespace if curr_ns not in visited_ns: visited_ns.add(curr_ns) yield _container
def test_list_docker_containers(self, mock_get_rootfs, mock_inspect, mocked_get_runtime_env, mocked_dockerps): n = 0 for c in get_docker_containers(): assert c.long_id == 'good_id' n += 1 assert mocked_get_runtime_env.call_count == 3 assert n == 2