def _test_run_as_another_namespace_infinite_loop_function(self): try: run_as_another_namespace( self.pid, all_namespaces, func_infinite_loop, "arg") except CrawlTimeoutError: # we should get a TimeoutError exception pass # all good except Exception: assert False
def test_run_as_another_namespace_crashing_function(self): try: run_as_another_namespace( self.pid, all_namespaces, func_crash, "arg") except FooError: # we shuld get a FooError exception pass # all good except Exception: assert False
def crawl(self, container_id=None, avoid_setns=False, root_dir='/', **kwargs): logger.debug('Crawling packages for container %s' % container_id) inspect = exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) if avoid_setns: rootfs_dir = get_docker_container_rootfs_path(container_id) return crawl_packages(root_dir=join_abs_paths( rootfs_dir, root_dir), reload_needed=True) else: # in all other cases, including wrong mode set try: return run_as_another_namespace(pid, ALL_NAMESPACES, crawl_packages, None, root_dir, 0, False) except CrawlError: # Retry the crawl avoiding the setns() syscall. This is # needed for PPC where we can not jump into the container and # run its apt or rpm commands. rootfs_dir = get_docker_container_rootfs_path(container_id) return crawl_packages(root_dir=join_abs_paths( rootfs_dir, root_dir), reload_needed=True)
def _test_run_as_another_namespace_infinite_loop_function(self): try: res = run_as_another_namespace( self.pid, all_namespaces, func_infinite_loop, "arg") except CrawlTimeoutError, e: # we should get a TimeoutError exception pass # all good
def test_run_as_another_namespace_crashing_function(self): try: res = run_as_another_namespace( self.pid, all_namespaces, func_crash, "arg") except FooError, e: # we shuld get a FooError exception pass # all good
def crawl(self, container_id=None, avoid_setns=False, root_dir='/', exclude_dirs=[ '/boot', '/dev', '/proc', '/sys', '/mnt', '/tmp', '/var/cache', '/usr/share/man', '/usr/share/doc', '/usr/share/mime' ], **kwargs): inspect = dockerutils.exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) logger.debug('Crawling file for container %s' % container_id) if avoid_setns: rootfs_dir = dockerutils.get_docker_container_rootfs_path( container_id) exclude_dirs = [ misc.join_abs_paths(rootfs_dir, d) for d in exclude_dirs ] return crawl_files(root_dir=misc.join_abs_paths( rootfs_dir, root_dir), exclude_dirs=exclude_dirs, root_dir_alias=root_dir) else: # in all other cases, including wrong mode set return run_as_another_namespace(pid, ['mnt'], crawl_files, root_dir, exclude_dirs, None)
def crawl(self, container_id, avoid_setns=False, **kwargs): inspect = dockerutils.exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) logger.debug('Crawling OS for container %s' % container_id) if avoid_setns: mp = dockerutils.get_docker_container_rootfs_path(container_id) return crawl_os_mountpoint(mp) else: # in all other cases, including wrong mode set return run_as_another_namespace(pid, ALL_NAMESPACES, crawl_os)
def crawl(self, container_id, avoid_setns=False, **kwargs): inspect = dockerutils.exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) logger.debug('Crawling Processes for container %s' % container_id) if avoid_setns: raise NotImplementedError() return run_as_another_namespace(pid, ALL_NAMESPACES, self._crawl_in_system)
def crawl(self, container_id=None, avoid_setns=False, root_dir='/', exclude_dirs=[ '/dev', '/proc', '/mnt', '/tmp', '/var/cache', '/usr/share/man', '/usr/share/doc', '/usr/share/mime' ], known_config_files=[ '/etc/passwd', '/etc/group', '/etc/hosts', '/etc/hostname', '/etc/mtab', '/etc/fstab', '/etc/aliases', '/etc/ssh/ssh_config', '/etc/ssh/sshd_config', '/etc/sudoers' ], discover_config_files=False, **kwargs): inspect = dockerutils.exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) logger.debug('Crawling config for container %s' % container_id) if avoid_setns: rootfs_dir = dockerutils.get_docker_container_rootfs_path( container_id) exclude_dirs = [ misc.join_abs_paths(rootfs_dir, d) for d in exclude_dirs ] return crawl_config_files( root_dir=misc.join_abs_paths(rootfs_dir, root_dir), exclude_dirs=exclude_dirs, root_dir_alias=root_dir, known_config_files=known_config_files, discover_config_files=discover_config_files) else: # in all other cases, including wrong mode set return run_as_another_namespace(pid, ['mnt'], crawl_config_files, root_dir, exclude_dirs, None, known_config_files, discover_config_files)
def test_run_as_another_namespace_simple_function_no_args(self): res = run_as_another_namespace(self.pid, all_namespaces, func_no_args) assert res == "test default" print sys._getframe().f_code.co_name, 1
def test_run_as_another_namespace_simple_function(self): res = run_as_another_namespace( self.pid, all_namespaces, func, "arg1", "arg2") assert res == "test arg1 arg2" print sys._getframe().f_code.co_name, 1
def test_run_as_another_namespace_infinite_loop_function(pid): try: res = run_as_another_namespace(pid, all_namespaces, func_infinite_loop, "argumento") except CrawlTimeoutError, e: # we should get a timeout error print sys._getframe().f_code.co_name, 1
def test_run_as_another_namespace_crashing_function(pid): try: res = run_as_another_namespace(pid, all_namespaces, func_crash, "argumento") except FooError, e: print sys._getframe().f_code.co_name, 1 return
def test_run_as_another_namespace_simple_function(pid): res = run_as_another_namespace(pid, all_namespaces, func, "argumento1", "argumento2") assert res == "test argumento1 argumento2" print sys._getframe().f_code.co_name, 1