Skip to content

Commit

Permalink
ceph-volume: print most logging messages to stderr
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Fajerski <jfajerski@suse.com>

Fixes: http://tracker.ceph.com/issues/38548
  • Loading branch information
Jan Fajerski committed Aug 2, 2019
1 parent 647d804 commit 1f8f1e9
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/ceph-volume/ceph_volume/terminal.py
Expand Up @@ -127,27 +127,27 @@ def stdout(msg):


def stderr(msg):
return _Write(prefix=yellow(' stderr: ')).raw(msg)
return _Write(prefix=yellow(' stderr: '), _writer=sys.stderr).raw(msg)


def write(msg):
return _Write().raw(msg)


def error(msg):
return _Write(prefix=red_arrow).raw(msg)
return _Write(prefix=red_arrow, _writer=sys.stderr).raw(msg)


def info(msg):
return _Write(prefix=blue_arrow).raw(msg)
return _Write(prefix=blue_arrow, _writer=sys.stderr).raw(msg)


def debug(msg):
return _Write(prefix=blue_arrow).raw(msg)
return _Write(prefix=blue_arrow, _writer=sys.stderr).raw(msg)


def warning(msg):
return _Write(prefix=yellow_arrow).raw(msg)
return _Write(prefix=yellow_arrow, _writer=sys.stderr).raw(msg)


def success(msg):
Expand Down
Expand Up @@ -283,8 +283,8 @@ def test_does_not_detect_osds(self, capsys, is_root, capture, monkeypatch):
activation = activate.Activate(args)
activation.main()
out, err = capsys.readouterr()
assert 'Was unable to find any OSDs to activate' in out
assert 'Verify OSDs are present with ' in out
assert 'Was unable to find any OSDs to activate' in err
assert 'Verify OSDs are present with ' in err

def test_detects_running_osds(self, capsys, is_root, capture, monkeypatch):
monkeypatch.setattr('ceph_volume.devices.lvm.activate.direct_report', lambda: direct_report)
Expand All @@ -293,8 +293,8 @@ def test_detects_running_osds(self, capsys, is_root, capture, monkeypatch):
activation = activate.Activate(args)
activation.main()
out, err = capsys.readouterr()
assert 'a8789a96ce8b process is active. Skipping activation' in out
assert 'b8218eaa1634 process is active. Skipping activation' in out
assert 'a8789a96ce8b process is active. Skipping activation' in err
assert 'b8218eaa1634 process is active. Skipping activation' in err

def test_detects_osds_to_activate(self, is_root, capture, monkeypatch):
monkeypatch.setattr('ceph_volume.devices.lvm.activate.direct_report', lambda: direct_report)
Expand Down
12 changes: 6 additions & 6 deletions src/ceph-volume/ceph_volume/tests/devices/lvm/test_create.py
Expand Up @@ -21,9 +21,9 @@ def test_excludes_filestore_bluestore_flags(self, capsys, device_info):
device_info()
with pytest.raises(SystemExit):
lvm.create.Create(argv=['--data', '/dev/sdfoo', '--filestore', '--bluestore']).main()
stdout, sterr = capsys.readouterr()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --filestore (filestore) with --bluestore (bluestore)'
assert expected in stdout
assert expected in stderr

def test_excludes_other_filestore_bluestore_flags(self, capsys, device_info):
device_info()
Expand All @@ -32,9 +32,9 @@ def test_excludes_other_filestore_bluestore_flags(self, capsys, device_info):
'--bluestore', '--data', '/dev/sdfoo',
'--journal', '/dev/sf14',
]).main()
stdout, sterr = capsys.readouterr()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --bluestore (bluestore) with --journal (filestore)'
assert expected in stdout
assert expected in stderr

def test_excludes_block_and_journal_flags(self, capsys, device_info):
device_info()
Expand All @@ -43,6 +43,6 @@ def test_excludes_block_and_journal_flags(self, capsys, device_info):
'--bluestore', '--data', '/dev/sdfoo', '--block.db', 'vg/ceph1',
'--journal', '/dev/sf14',
]).main()
stdout, sterr = capsys.readouterr()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --block.db (bluestore) with --journal (filestore)'
assert expected in stdout
assert expected in stderr
6 changes: 3 additions & 3 deletions src/ceph-volume/ceph_volume/tests/devices/lvm/test_prepare.py
Expand Up @@ -68,7 +68,7 @@ def test_excludes_filestore_bluestore_flags(self, capsys, device_info):
lvm.prepare.Prepare(argv=['--data', '/dev/sdfoo', '--filestore', '--bluestore']).main()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --filestore (filestore) with --bluestore (bluestore)'
assert expected in stdout
assert expected in stderr

def test_excludes_other_filestore_bluestore_flags(self, capsys, device_info):
device_info()
Expand All @@ -79,7 +79,7 @@ def test_excludes_other_filestore_bluestore_flags(self, capsys, device_info):
]).main()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --bluestore (bluestore) with --journal (filestore)'
assert expected in stdout
assert expected in stderr

def test_excludes_block_and_journal_flags(self, capsys, device_info):
device_info()
Expand All @@ -90,7 +90,7 @@ def test_excludes_block_and_journal_flags(self, capsys, device_info):
]).main()
stdout, stderr = capsys.readouterr()
expected = 'Cannot use --block.db (bluestore) with --journal (filestore)'
assert expected in stdout
assert expected in stderr

def test_journal_is_required_with_filestore(self, is_root, monkeypatch, device_info):
monkeypatch.setattr("os.path.exists", lambda path: True)
Expand Down
Expand Up @@ -51,10 +51,10 @@ def test_nothing_is_activated(self, tmpfile, is_root, capsys):
activation.activate = lambda x: True
activation.main()
activation.enable_systemd_units('0', '1234')
out, err = capsys.readouterr()
assert 'Skipping enabling of `simple`' in out
assert 'Skipping masking of ceph-disk' in out
assert 'Skipping enabling and starting OSD simple' in out
stdout, stderr = capsys.readouterr()
assert 'Skipping enabling of `simple`' in stderr
assert 'Skipping masking of ceph-disk' in stderr
assert 'Skipping enabling and starting OSD simple' in stderr

def test_no_systemd_flag_is_true(self, tmpfile, is_root):
json_config = tmpfile(contents='{}')
Expand Down Expand Up @@ -145,14 +145,14 @@ def test_filestore_journal_device_found(self, capsys):
with pytest.raises(RuntimeError):
activation.validate_devices({'type': 'filestore', 'journal': {}})
stdout, stderr = capsys.readouterr()
assert "devices found: ['journal']" in stdout
assert "devices found: ['journal']" in stderr

def test_filestore_data_device_found(self, capsys):
activation = activate.Activate([])
with pytest.raises(RuntimeError):
activation.validate_devices({'type': 'filestore', 'data': {}})
stdout, stderr = capsys.readouterr()
assert "devices found: ['data']" in stdout
assert "devices found: ['data']" in stderr

def test_filestore_with_all_devices(self):
activation = activate.Activate([])
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_bluestore_data_device_found(self, capsys):
with pytest.raises(RuntimeError):
activation.validate_devices({'data': {}})
stdout, stderr = capsys.readouterr()
assert "devices found: ['data']" in stdout
assert "devices found: ['data']" in stderr

def test_bluestore_missing_data(self):
activation = activate.Activate([])
Expand All @@ -197,4 +197,4 @@ def test_bluestore_block_device_found(self, capsys):
with pytest.raises(RuntimeError):
activation.validate_devices({'block': {}})
stdout, stderr = capsys.readouterr()
assert "devices found: ['block']" in stdout
assert "devices found: ['block']" in stderr
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/devices/test_zap.py
Expand Up @@ -25,4 +25,4 @@ def test_can_not_zap_mapper_device(self, monkeypatch, device_info, capsys, is_ro
with pytest.raises(SystemExit):
lvm.zap.Zap(argv=[device_name]).main()
stdout, stderr = capsys.readouterr()
assert 'Refusing to zap' in stdout
assert 'Refusing to zap' in stderr
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/test_configuration.py
Expand Up @@ -106,7 +106,7 @@ def test_unable_to_read_configuration(self, tmpdir, capsys):
with pytest.raises(RuntimeError):
configuration.load(ceph_conf)
stdout, stderr = capsys.readouterr()
assert 'File contains no section headers' in stdout
assert 'File contains no section headers' in stderr

@pytest.mark.parametrize('commented', ['colon','hash'])
def test_coment_as_a_value(self, tmpdir, commented):
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/test_process.py
Expand Up @@ -35,7 +35,7 @@ def test_stderr_terminal_and_logfile(self, mock_call, caplog, capsys):
assert 'Running command: ' in log_lines[0]
assert 'ls' in log_lines[0]
assert 'stderr some stderr message' in log_lines[-1]
assert 'some stderr message' in out
assert 'some stderr message' in err

def test_stderr_terminal_and_logfile_off(self, mock_call, caplog, capsys):
mock_call(stdout='stdout\n', stderr='some stderr message\n')
Expand Down
Expand Up @@ -70,7 +70,7 @@ def test_flags_conflict(self, capsys):
self.parser, ['filestore', 'bluestore'], argv=argv
)
stdout, stderr = capsys.readouterr()
assert 'Cannot use --filestore (filestore) with --bluestore (bluestore)' in stdout
assert 'Cannot use --filestore (filestore) with --bluestore (bluestore)' in stderr


class TestValidDevice(object):
Expand Down
4 changes: 2 additions & 2 deletions src/ceph-volume/ceph_volume/tests/util/test_system.py
Expand Up @@ -214,5 +214,5 @@ def test_warnings_when_executable_isnt_matched(self, monkeypatch, capsys):
monkeypatch.setattr(system.os.path, 'exists', lambda x: False)
system.which('exedir')
stdout, stderr = capsys.readouterr()
assert 'Absolute path not found for executable: exedir' in stdout
assert 'Ensure $PATH environment variable contains common executable locations' in stdout
assert 'Absolute path not found for executable: exedir' in stderr
assert 'Ensure $PATH environment variable contains common executable locations' in stderr
13 changes: 6 additions & 7 deletions src/pybind/mgr/test_orchestrator/module.py
Expand Up @@ -170,13 +170,12 @@ def get_inventory(self, node_filter=None, refresh=False):
c_v_out = check_output(cmd.format(tmpdir='.'),shell=True)

for out in c_v_out.splitlines():
if not out.startswith(b'-->') and not out.startswith(b' stderr'):
self.log.error(out)
devs = []
for device in json.loads(out):
dev = orchestrator.InventoryDevice.from_ceph_volume_inventory(device)
devs.append(dev)
return [orchestrator.InventoryNode('localhost', devs)]
self.log.error(out)
devs = []
for device in json.loads(out):
dev = orchestrator.InventoryDevice.from_ceph_volume_inventory(device)
devs.append(dev)
return [orchestrator.InventoryNode('localhost', devs)]
self.log.error('c-v failed: ' + str(c_v_out))
raise Exception('c-v failed')

Expand Down

0 comments on commit 1f8f1e9

Please sign in to comment.