Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephadm: respect --skip-firewalld flag #45399

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -3310,9 +3310,10 @@ class Firewalld(object):

def update_firewalld(ctx, daemon_type):
# type: (CephadmContext, str) -> None
firewall = Firewalld(ctx)
firewall.enable_service_for(daemon_type)
firewall.apply_rules()
if not ('skip_firewalld' in ctx and ctx.skip_firewalld):
firewall = Firewalld(ctx)
firewall.enable_service_for(daemon_type)
firewall.apply_rules()


def install_sysctl(ctx: CephadmContext, fsid: str, daemon_type: str) -> None:
Expand Down Expand Up @@ -4814,9 +4815,10 @@ def prepare_dashboard(
port = int(out)

# Open dashboard port
fw = Firewalld(ctx)
fw.open_ports([port])
fw.apply_rules()
if not ('skip_firewalld' in ctx and ctx.skip_firewalld):
fw = Firewalld(ctx)
fw.open_ports([port])
fw.apply_rules()

logger.info('Ceph Dashboard is now available at:\n\n'
'\t URL: https://%s:%s/\n'
Expand Down
8 changes: 8 additions & 0 deletions src/cephadm/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def _daemon_path():
return os.getcwd()


def mock_bad_firewalld():
def raise_bad_firewalld():
raise Exception('Called bad firewalld')
f = mock.Mock(cd.Firewalld)
f.enable_service_for = lambda _ : raise_bad_firewalld()
f.apply_rules = lambda : raise_bad_firewalld()
f.open_ports = lambda _ : raise_bad_firewalld()

def _mock_scrape_host(obj, interval):
try:
raise ValueError("wah")
Expand Down
36 changes: 35 additions & 1 deletion src/cephadm/tests/test_cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
mock_docker,
mock_podman,
with_cephadm_ctx,
mock_bad_firewalld,
)

with mock.patch('builtins.open', create=True):
Expand Down Expand Up @@ -214,10 +215,43 @@ def wrap_test(address, expected):
for address, expected in tests:
wrap_test(address, expected)

@mock.patch('cephadm.Firewalld', mock_bad_firewalld)
@mock.patch('cephadm.logger')
def test_skip_firewalld(self, logger, cephadm_fs):
"""
test --skip-firewalld actually skips changing firewall
"""

ctx = cd.CephadmContext()
with pytest.raises(Exception):
cd.update_firewalld(ctx, 'mon')

ctx.skip_firewalld = True
cd.update_firewalld(ctx, 'mon')

ctx.skip_firewalld = False
with pytest.raises(Exception):
cd.update_firewalld(ctx, 'mon')

ctx = cd.CephadmContext()
ctx.ssl_dashboard_port = 8888
ctx.dashboard_key = None
ctx.dashboard_password_noupdate = True
ctx.initial_dashboard_password = 'password'
ctx.initial_dashboard_user = 'User'
with pytest.raises(Exception):
cd.prepare_dashboard(ctx, 0, 0, lambda _, extra_mounts=None, ___=None : '5', lambda : None)

ctx.skip_firewalld = True
cd.prepare_dashboard(ctx, 0, 0, lambda _, extra_mounts=None, ___=None : '5', lambda : None)

ctx.skip_firewalld = False
with pytest.raises(Exception):
cd.prepare_dashboard(ctx, 0, 0, lambda _, extra_mounts=None, ___=None : '5', lambda : None)

@mock.patch('cephadm.call_throws')
@mock.patch('cephadm.get_parm')
def test_registry_login(self, get_parm, call_throws):

# test normal valid login with url, username and password specified
call_throws.return_value = '', '', 0
ctx: cd.CephadmContext = cd.cephadm_init_ctx(
Expand Down