def test_exec_docker_inspect(self, *args):
        i = dockerutils.exec_dockerinspect('ididid')

        docker_datetime = dp.parse('2016-07-06')
        epoch_seconds = docker_datetime.strftime('%s')

        assert i == {'Name': '/pensive_rosalind',
                     'Created': epoch_seconds,
                     'RepoTag': 'r',
                     'State': {'Status': 'running',
                               'Running': True,
                               'Pid': '11186'},
                     'Mounts': [],
                     'Config': {'Image': 'ubuntu:trusty',
                                'Cmd': ['bash']},
                     'NetworkSettings': {'Ports': {
                                         '80/tcp': [
                                             {'HostPort': '32768',
                                              'HostIp': '0.0.0.0'}]}},
                     'Image': 'sha256:07c86167cdc4264926fa5d2894e34a339ad27',
                     'LogPath': '/a/b/c/log.json',
                     'HostConfig': {'PortBindings': {
                                    '809/tcp': [{'HostPort': '',
                                                 'HostIp': ''}]}},
                     'Id': 'good_id'}
    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 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)
Exemple #5
0
    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 get_container_namespace(self, long_id, options):
        assert type(long_id) is str or unicode, "long_id is not a string"
        namespace = None
        container_meta = dockerutils.exec_dockerinspect(long_id)
        uuid = container_meta[CONTAINER_META_UUID]
        try:
            tenantId = container_meta[CONTAINER_META_CONFIG][
                CONTAINER_META_LABELS][CONTAINER_META_TENANT]
        except KeyError:
            tenantId = container_meta[CONTAINER_META_CONFIG][
                CONTAINER_META_HOSTNAME]

        namespace = "{TENANT}{SEPERATOR}{UUID}".format(
            TENANT=tenantId, SEPERATOR=NAMESPACE_TAG_SEPERATOR, UUID=uuid)

        logging.debug("namespace created: %s" % (namespace))

        return namespace
    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)
Exemple #8
0
 def test_dockerinspect(self):
     inspect = exec_dockerinspect(self.container['Id'])
     print inspect
     assert self.container['Id'] == inspect['Id']
 def test_exec_docker_inspect_failure(self, *args):
     with self.assertRaises(DockerutilsException):
         dockerutils.exec_dockerinspect('ididid')
def test_dockerinspect(long_id):
    global image
    found = False
    inspect_image = exec_dockerinspect(long_id)['Image']
    found = image_id in inspect_image
    print sys._getframe().f_code.co_name, int(found)
 def test_dockerinspect(self):
     inspect = exec_dockerinspect(self.container['Id'])
     print inspect
     assert self.container['Id'] == inspect['Id']