Exemplo n.º 1
0
    def test_read_file_as_root(self):
        def fake_execute(*args, **kwargs):
            if args[1] == 'bad':
                raise processutils.ProcessExecutionError()
            return 'fakecontents', None

        self.stubs.Set(utils, 'execute', fake_execute)
        contents = utils.read_file_as_root('good')
        self.assertEqual(contents, 'fakecontents')
        self.assertRaises(exception.FileNotFound, utils.read_file_as_root,
                          'bad')
Exemplo n.º 2
0
    def test_read_file_as_root(self):
        def fake_execute(*args, **kwargs):
            if args[1] == 'bad':
                raise processutils.ProcessExecutionError()
            return 'fakecontents', None

        self.stubs.Set(utils, 'execute', fake_execute)
        contents = utils.read_file_as_root('good')
        self.assertEqual(contents, 'fakecontents')
        self.assertRaises(exception.FileNotFound,
                          utils.read_file_as_root, 'bad')
Exemplo n.º 3
0
def get_iscsi_initiator():
    """Get iscsi initiator name for this machine."""
    # NOTE(vish) openiscsi stores initiator name in a file that
    #            needs root permission to read.
    try:
        contents = utils.read_file_as_root('/etc/iscsi/initiatorname.iscsi')
    except exception.FileNotFound:
        return ''

    for l in contents.split('\n'):
        if l.startswith('InitiatorName='):
            return l[l.index('=') + 1:].strip()
    return ''
Exemplo n.º 4
0
    def read_file(self, path):
        LOG.debug("Read file path=%s", path)
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)
Exemplo n.º 5
0
    def read_file(self, path):
        LOG.debug("Read file path=%s", path)
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)