Skip to content

Fix info overwriting when retrieving from cache#472

Merged
rnjudge merged 1 commit intotern-tools:masterfrom
nishakm:466-fix-cache-overwrites
Oct 16, 2019
Merged

Fix info overwriting when retrieving from cache#472
rnjudge merged 1 commit intotern-tools:masterfrom
nishakm:466-fix-cache-overwrites

Conversation

@nishakm
Copy link
Copy Markdown
Contributor

@nishakm nishakm commented Oct 15, 2019

When checking to see if information about an image layer is already
cached, the tool will record that information in a notice. When the
cache gets saved at the end of a run, all the notices recorded when
the layer was first processed gets overwritten by the new notice
which just informs you that it got the information about the layer
from the cache. This change fixes this bug.

  • Remove the recording of the notice that the tool has pulled
    information from the cache. It's enough if the tool just logs that
    event.
  • Along with loading the package information from the cache into
    the layer object, also load the notices. Added a new function to
    load the notices from the cache.
  • For the Origin's class method add_notice_origin, check first if
    the origin string already exists in the list of notice origin
    objects before adding it. This prevents multiple instances of the
    class with the same origin string.
  • Made some changes to the message format to make it more
    understandable about what method the tool used to get the
    information
  • Added a function to cache.py to retrieve the 'origins' part of
    the cache which will be used in the load_notices_from_cache
    function in common.py

Resolves #466

Signed-off-by: Nisha K nishak@vmware.com

When checking to see if information about an image layer is already
cached, the tool will record that information in a notice. When the
cache gets saved at the end of a run, all the notices recorded when
the layer was first processed gets overwritten by the new notice
which just informs you that it got the information about the layer
from the cache. This change fixes this bug.

- Remove the recording of the notice that the tool has pulled
information from the cache. It's enough if the tool just logs that
event.
- Along with loading the package information from the cache into
the layer object, also load the notices. Added a new function to
load the notices from the cache.
- For the Origin's class method add_notice_origin, check first if
the origin string already exists in the list of notice origin
objects before adding it. This prevents multiple instances of the
class with the same origin string.
- Made some changes to the message format to make it more
understandable about what method the tool used to get the
information
- Added a function to cache.py to retrieve the 'origins' part of
the cache which will be used in the load_notices_from_cache
function in common.py

Resolves tern-tools#466

Signed-off-by: Nisha K <nishak@vmware.com>
@nishakm nishakm requested a review from rnjudge October 15, 2019 20:57
@nishakm
Copy link
Copy Markdown
Contributor Author

nishakm commented Oct 16, 2019

Tested on my end using:

$ tern -l report -i photon:3.0                                                                                                                                  
2019-10-16 08:49:17,626 - DEBUG - __main__ - Starting...                                                                                                                                                                         
2019-10-16 08:49:17,626 - DEBUG - run - Setting up...                                                                                                                                                                            
2019-10-16 08:49:19,761 - DEBUG - container - Checking if image "photon:3.0" is available on disk...                                                                                                                             
2019-10-16 08:49:19,816 - DEBUG - container - Image "photon:3.0" found                                                                                                                                                           
2019-10-16 08:49:21,340 - DEBUG - rootfs - Running command: tar -tf /home/nisha/.tern/temp.tar                                                                                                                                   
2019-10-16 08:49:21,344 - DEBUG - rootfs - Running command: tar -xf /home/nisha/.tern/temp.tar -C /home/nisha/.tern/temp                                                                                                         
2019-10-16 08:49:21,465 - DEBUG - rootfs - Running command: tar -tf /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce2caae367ea84ee15f697568564bed3a9/layer.tar                                                            
2019-10-16 08:49:21,472 - DEBUG - rootfs - Running command: tar -xf /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce2caae367ea84ee15f697568564bed3a9/layer.tar -C /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce$
caae367ea84ee15f697568564bed3a9/contents                                                                                                                                                                                         
2019-10-16 08:49:21,586 - DEBUG - rootfs - Running command: sudo /home/nisha/terndev/tern/tern/tools/fs_hash.sh /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce2caae367ea84ee15f697568564bed3a9/contents                 
[sudo] password for nisha:                                                                                                                                                                                                       
2019-10-16 08:49:27,328 - DEBUG - rootfs - Running command: sudo mount -o bind /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce2caae367ea84ee15f697568564bed3a9/contents /home/nisha/.tern/temp/mergedir                  
2019-10-16 08:49:27,414 - DEBUG - common - Loaded from cache: layer "8be79183f5"   <--- log message saying we are loading from cache                                                                                                                                         
2019-10-16 08:49:27,415 - DEBUG - rootfs - Running command: sudo umount -rl /home/nisha/.tern/temp/mergedir                                                                                                                      
2019-10-16 08:49:27,508 - DEBUG - generator - Creating a detailed report of components in image...                                                                                                                               
This report was generated by the Tern Project
https://github.com/vmware/tern/commit/d1de4e822dcb7e2dfdade1c5d32407aa7756060b

Docker image: photon:3.0:
        Layer: 8be79183f5:
                info: Found 'VMware Photon OS/Linux' in /etc/os-release. <--- info messages from actual file processing intact
                info: Layer created by commands: /bin/sh -c #(nop) ADD file:d8455c8bd540783848da4c11c5ad00d558cd72ad502f3ce3df94717d2a71994f in /
                info: Retrieved by invoking listing in command_lib/base.yml
proj_urls:
        in container:
        tdnf check-update > /dev/null
        pkgs=`tdnf list installed | cut -f1 -d"."`
        for p in $pkgs; do tdnf info $p | head -9 | tail -1 | cut -f2-3 -d":" | xargs; done

versions:
        in container:
        tdnf check-update > /dev/null
        list=`tdnf list installed`
        c=0; for l in $list; do if [ $c == 1 ]; then echo $l; fi; c=$(((c+1)%3)); done;

names:
        in container:
        tdnf check-update > /dev/null
        tdnf list installed | cut -f1 -d"."

licenses:
        in container:
        tdnf check-update > /dev/null
        pkgs=`tdnf list installed | cut -f1 -d"."`
        for p in $pkgs; do tdnf info $p | head -10 | tail -1 | cut -f2 -d":" | xargs; done



        Invoking commands from command_lib/base.yml:
                warning: No listing for key copyrights. Consider adding this listing to command_lib/base.yml.
No listing for key srcs. Consider adding this listing to command_lib/base.yml.

        Packages found in Layer:  bash-4.4.18-1.ph3, bzip2-libs-1.0.6-9.ph3, ca-certificates-20180919-1.ph3, ca-certificates-pki-20180919-1.ph3, curl-7.61.1-3.ph3, curl-libs-7.61.1-3.ph3, e2fsprogs-libs-1.44.3-2.ph3, elfutils
-libelf-0.174-2.ph3, expat-libs-2.2.6-1.ph3, filesystem-1.1-4.ph3, glibc-2.28-3.ph3, krb5-1.16.1-1.ph3, libcap-2.25-8.ph3, libdb-5.3.28-2.ph3, libgcc-7.3.0-4.ph3, libsolv-0.6.26-5.ph3, libssh2-1.8.2-1.ph3, ncurses-libs-6.1-1.
ph3, nspr-4.20-1.ph3, nss-libs-3.39-1.ph3, openssl-1.0.2r-1.ph3, photon-release-3.0-3.ph3, photon-repos-3.0-3.ph3, popt-1.16-5.ph3, readline-7.0-2.ph3, rpm-libs-4.14.2-4.ph3, sqlite-libs-3.27.2-2.ph3, tdnf-2.0.0-10.ph3, tdnf-
cli-libs-2.0.0-10.ph3, toybox-0.7.7-1.ph3, xz-libs-5.2.4-1.ph3, zlib-1.2.11-1.ph3
        Licenses found in Layer:  GPLv3, BSD, Custom, MIT, GPLv2+, GPLv2+ or LGPLv3+, LGPLv2+, BSD and LGPLv2 and Sleepycat, MPLv2.0, OpenSSL, Apache License, GPLv3+, Public Domain, LGPLv2.1,GPLv2, GPLv2+ and GPLv3+ and LGPLv
2+, zlib
------------------------------------------------

###########################################
# Summary of licenses found in Container: #
###########################################
GPLv3, BSD, Custom, MIT, GPLv2+, GPLv2+ or LGPLv3+, LGPLv2+, BSD and LGPLv2 and Sleepycat, MPLv2.0, OpenSSL, Apache License, GPLv3+, Public Domain, LGPLv2.1,GPLv2, GPLv2+ and GPLv3+ and LGPLv2+, zlib

2019-10-16 08:49:27,509 - DEBUG - rootfs - Running command: sudo rm -rf /home/nisha/.tern/temp/71f3c88415a96603fdfe49917ba668ce2caae367ea84ee15f697568564bed3a9/contents
2019-10-16 08:49:27,547 - DEBUG - run - Teardown...
2019-10-16 08:49:29,257 - DEBUG - rootfs - Running command: sudo rm -rf /home/nisha/.tern/temp/mergedir
2019-10-16 08:49:29,267 - DEBUG - rootfs - Running command: sudo rm -rf /home/nisha/.tern/temp/workdir
2019-10-16 08:49:29,284 - DEBUG - __main__ - Report completed.
2019-10-16 08:49:29,285 - DEBUG - __main__ - Finished

@rnjudge
Copy link
Copy Markdown
Contributor

rnjudge commented Oct 16, 2019

Overwriting the cache had always bothered me running Tern. Thanks for the fix!

@rnjudge rnjudge merged commit 8fa2f40 into tern-tools:master Oct 16, 2019
@nishakm nishakm deleted the 466-fix-cache-overwrites branch October 17, 2019 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache's notice messages get overwritten

2 participants