{"action":"created","issue":{"url":"https://api.github.com/repos/philpep/testinfra/issues/114","repository_url":"https://api.github.com/repos/philpep/testinfra","labels_url":"https://api.github.com/repos/philpep/testinfra/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/philpep/testinfra/issues/114/comments","events_url":"https://api.github.com/repos/philpep/testinfra/issues/114/events","html_url":"https://github.com/philpep/testinfra/issues/114","id":163975342,"node_id":"MDU6SXNzdWUxNjM5NzUzNDI=","number":114,"title":"File.contains behavior","user":{"login":"alop","id":1679454,"node_id":"MDQ6VXNlcjE2Nzk0NTQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1679454?v=4","gravatar_id":"","url":"https://api.github.com/users/alop","html_url":"https://github.com/alop","followers_url":"https://api.github.com/users/alop/followers","following_url":"https://api.github.com/users/alop/following{/other_user}","gists_url":"https://api.github.com/users/alop/gists{/gist_id}","starred_url":"https://api.github.com/users/alop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alop/subscriptions","organizations_url":"https://api.github.com/users/alop/orgs","repos_url":"https://api.github.com/users/alop/repos","events_url":"https://api.github.com/users/alop/events{/privacy}","received_events_url":"https://api.github.com/users/alop/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-07-06T00:32:15Z","updated_at":"2018-06-04T19:42:20Z","closed_at":"2016-07-06T22:03:54Z","author_association":"NONE","body":"I recently wrote a test to check grub.cfg for serial console settings. The test looks like\n\n```\ndef test_grub(File):\n    grub = File('/boot/grub2/grub.cfg')\n\n    assert grub.contains('console=tty0')\n    assert grub.contains('vga=normal')\n    assert grub.contains('consoleblank=0')\n    assert grub.contains('nofb')\n    assert grub.contains('nomodeset')\n    assert grub.contains('video=vesafb:off')\n    assert grub.contains('gfxpayload=text')\n    assert grub.contains('text')\n```\n\nI can't understand how this is failing\n\n```\nFile = <class 'testinfra.modules.base.GNUFile'>\n\n    def test_grub(File):\n        grub = File('/boot/grub2/grub.cfg')\n\n>       assert grub.contains('console=tty0')\nE       assert <bound method GNUFile.contains of <file /boot/grub2/grub.cfg>>('console=tty0')\nE        +  where <bound method GNUFile.contains of <file /boot/grub2/grub.cfg>> = <file /boot/grub2/grub.cfg>.contains\n\ntests/test_default.py:52: AssertionError\n```\n\nI looked at the code, looks like it's just grep, which is passing on the command line\n\n```\n[root@mhv1 ~]# grep -qs -- console=tty0 /boot/grub2/grub.cfg \n[root@mhv1 ~]# echo $?\n0\n[root@mhv1 ~]# \n```\n\nI _am_ running with sudo\n\nThe actual match looks like\n\n```\ngrep console=tty0 /boot/grub2/grub.cfg \n    linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet net.ifnames=0 biosdevname=0 console=tty0 vga=normal consoleblank=0 nofb nomodeset video=vesafb:off gfxpayload=text text\n    linux16 /vmlinuz-0-rescue-ba64f73a96244ba0a0ce1673be601765 root=/dev/mapper/rhel-root ro crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet net.ifnames=0 biosdevname=0 console=tty0 vga=normal consoleblank=0 nofb nomodeset video=vesafb:off gfxpayload=text text\n```\n"},"comment":{"url":"https://api.github.com/repos/philpep/testinfra/issues/comments/394474509","html_url":"https://github.com/philpep/testinfra/issues/114#issuecomment-394474509","issue_url":"https://api.github.com/repos/philpep/testinfra/issues/114","id":394474509,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NDQ3NDUwOQ==","user":{"login":"corbyshaner","id":10066580,"node_id":"MDQ6VXNlcjEwMDY2NTgw","avatar_url":"https://avatars0.githubusercontent.com/u/10066580?v=4","gravatar_id":"","url":"https://api.github.com/users/corbyshaner","html_url":"https://github.com/corbyshaner","followers_url":"https://api.github.com/users/corbyshaner/followers","following_url":"https://api.github.com/users/corbyshaner/following{/other_user}","gists_url":"https://api.github.com/users/corbyshaner/gists{/gist_id}","starred_url":"https://api.github.com/users/corbyshaner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corbyshaner/subscriptions","organizations_url":"https://api.github.com/users/corbyshaner/orgs","repos_url":"https://api.github.com/users/corbyshaner/repos","events_url":"https://api.github.com/users/corbyshaner/events{/privacy}","received_events_url":"https://api.github.com/users/corbyshaner/received_events","type":"User","site_admin":false},"created_at":"2018-06-04T19:42:20Z","updated_at":"2018-06-04T19:42:20Z","author_association":"NONE","body":"This trick also works for cases where you're searching for content that has quotes in it.\r\nIf you have `LogFormat \"%t %{X-Forwarded-For}i %l %u \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" \\\"%D\\\" \\\"%T\\\" combined` in an Apache config, this code will match it:\r\n`def test_ssl_conf_custom(host):\r\n    conf = host.file('/etc/httpd/conf.d/ssl.conf').content\r\n    assert b'LogFormat \"%t %{X-Forwarded-For}i %l %u \\\\\"%r\\\\\" %>s %b \\\\\"%{Referer}i\\\\\" \\\\\"%{User-Agent}i\\\\\" \\\\\"%D\\\\\" \\\\\"%T\\\\\" combined' in conf`"}}
{"actor":{"display_login":"corbyshaner"}}