pytest-dev / pytest-testinfra

Testinfra test your infrastructures
https://testinfra.readthedocs.io
Apache License 2.0
2.37k stars 355 forks source link

Getting content of the file with 0640 permissions leads to Permission denied #191

Closed serhiy-yevtushenko closed 7 years ago

serhiy-yevtushenko commented 7 years ago

Hi,

when trying to do test with filebeat, which obtains the content_str of the file with permission 0o640, I obtain the following exception:

self = <file /etc/filebeat/filebeat.yml>, decode = True

def _get_content(self, decode):
    out = self.run_test("cat -- %s", self.path)
    if out.rc != 0:
      raise RuntimeError("Unexpected output %s" % (out,))

E RuntimeError: Unexpected output CommandResult(command='cat -- /etc/filebeat/filebeat.yml', exit_status=1, stdout=None, stderr='cat: /etc/filebeat/filebeat.yml: Permission denied\n')

Similar test passes without problems, when using serverspec

serhiy-yevtushenko commented 7 years ago

One should use --sudo argument, then it works

philpep commented 7 years ago

Note that you can activate sudo locally with the sudo fixture