Skip to content

Commit

Permalink
Merge pull request #45399 from adk3798/no-firewall
Browse files Browse the repository at this point in the history
cephadm: respect --skip-firewalld flag

Reviewed-by: Michael Fritch <mfritch@suse.com>
  • Loading branch information
adk3798 committed Mar 24, 2022
2 parents f5d0e61 + d97057f commit 81f31fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -3333,9 +3333,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 @@ -4837,9 +4838,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

0 comments on commit 81f31fd

Please sign in to comment.