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

Fix error naming example #101

Merged
merged 5 commits into from
Jul 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/charms/operator_libs_linux/v0/sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def _on_install(self, _):

try:
self.sysctl.configure(config=sysctl_data)
except (sysctl.SysctlPermissionError, sysctl.ValidationError) as e:
except (sysctl.ApplyError, sysctl.ValidationError) as e:
logger.error(f"Error setting values on sysctl: {e.message}")
self.unit.status = BlockedStatus("Sysctl config not possible")
except sysctl.SysctlError:
except sysctl.CommandError:
logger.error("Error on sysctl")

def _on_remove(self, _):
Expand All @@ -84,7 +84,7 @@ def _on_remove(self, _):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 2
LIBPATCH = 3

CHARM_FILENAME_PREFIX = "90-juju-"
SYSCTL_DIRECTORY = Path("/etc/sysctl.d")
Expand Down
14 changes: 3 additions & 11 deletions tests/integration/test_sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@

from charms.operator_libs_linux.v0 import sysctl

EXPECTED_MERGED_RESULT = """# This config file was produced by sysctl lib v0.2
#
# This file represents the output of the sysctl lib, which can combine multiple
# configurations into a single file like.
# test1
net.ipv4.tcp_max_syn_backlog=4096
# test2
net.ipv4.tcp_window_scaling=2
"""


def test_configure():
cfg = sysctl.Config("test1")
Expand Down Expand Up @@ -48,7 +38,9 @@ def test_multiple_configure():
assert test_file_2.exists()

with open(merged_file, "r") as f:
assert f.read() == EXPECTED_MERGED_RESULT
result = f.read()
assert "# test1\nnet.ipv4.tcp_max_syn_backlog=4096" in result
assert "# test2\nnet.ipv4.tcp_window_scaling=2" in result


def test_remove():
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
vm.swappiness=60
net.ipv4.tcp_max_syn_backlog=4096
"""
TEST_OTHER_CHARM_MERGED = """# This config file was produced by sysctl lib v0.2
TEST_OTHER_CHARM_MERGED = f"""# This config file was produced by sysctl lib v{sysctl.LIBAPI}.{sysctl.LIBPATCH}
#
# This file represents the output of the sysctl lib, which can combine multiple
# configurations into a single file like.
# othercharm
vm.swappiness=60
net.ipv4.tcp_max_syn_backlog=4096
"""
TEST_MERGED_FILE = """# This config file was produced by sysctl lib v0.2
TEST_MERGED_FILE = f"""# This config file was produced by sysctl lib v{sysctl.LIBAPI}.{sysctl.LIBPATCH}
#
# This file represents the output of the sysctl lib, which can combine multiple
# configurations into a single file like.
vm.max_map_count = 262144
vm.swappiness=0

"""
TEST_UPDATE_MERGED_FILE = """# This config file was produced by sysctl lib v0.2
TEST_UPDATE_MERGED_FILE = f"""# This config file was produced by sysctl lib v{sysctl.LIBAPI}.{sysctl.LIBPATCH}
#
# This file represents the output of the sysctl lib, which can combine multiple
# configurations into a single file like.
Expand Down