Skip to content

Commit

Permalink
Fix bash to enable plugins in the fixture in the integration tests (#243
Browse files Browse the repository at this point in the history
)
  • Loading branch information
javierdelapuente authored May 2, 2024
1 parent d12a0d3 commit a2b98dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async def app_fixture(
pytestconfig: Config,
model: Model,
):
# pylint: disable=too-many-locals
"""Discourse charm used for integration testing.
Builds the charm and deploys it and the relations it depends on.
"""
Expand Down Expand Up @@ -202,17 +203,23 @@ async def app_fixture(
model.add_relation(app_name, "nginx-ingress-integrator"),
)
await model.wait_for_idle(status="active")

# Enable plugins calling rake site_settings:import in one of the units.
inline_yaml = "\n".join(f"{plugin}_enabled: true" for plugin in ENABLED_PLUGINS)
enable_plugins_command = (
"pebble exec --user=_daemon_ --context=discourse -w=/srv/discourse/app -ti -- /bin/bash -c "
f""""echo '{inline_yaml}' | """
'''/srv/discourse/app/bin/bundle exec rake site_settings:import -"'''
discourse_rake_command = "/srv/discourse/app/bin/bundle exec rake site_settings:import "
pebble_exec = (
"PEBBLE_SOCKET=/charm/containers/discourse/pebble.socket "
"pebble exec --user=_daemon_ --context=discourse -w=/srv/discourse/app"
)

logger.info("Enabling plugins: %s", enable_plugins_command)
action = await unit.run(f"/bin/bash -c '{enable_plugins_command}'")
full_command = (
"/bin/bash -c "
f"'set -euo pipefail; echo \"{inline_yaml}\" | {pebble_exec} -- {discourse_rake_command}'"
)
logger.info("Enable plugins command: %s", full_command)
action = await unit.run(full_command)
await action.wait()
logger.info(action.results)
assert action.results["return-code"] == 0, "Enable plugins failed"

yield application

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ deps =
isort
juju>=3.0
mypy
ops>=2.6.0
ops==2.12.0
ops-lib-pgsql
pep8-naming
psycopg2-binary
Expand Down

0 comments on commit a2b98dd

Please sign in to comment.