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

Set RABBITMQ_PLUGINS_DIR when starting the server #273

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akaihola
Copy link
Contributor

@akaihola akaihola commented Feb 7, 2022

Only RABBITMQ_ENABLED_PLUGINS_FILE was being set, but and any .ez files in the directory specified using the --rabbitmq-plugindir Pytest option would be ignored.

@akaihola
Copy link
Contributor Author

akaihola commented Feb 8, 2022

@fizyk, tests seem to fail. Could it be that some of the integration tests point to a plugins directory which isn't actually valid for RabbitMQ?

@fizyk
Copy link
Member

fizyk commented Feb 8, 2022

@akaihola by default it points to the tempdir, maybe that's why. It's fine to have there a temporary plugin's file, but ni plugin directory (with some random stuff possibly)
https://github.com/ClearcodeHQ/pytest-rabbitmq/blob/main/src/pytest_rabbitmq/plugin.py#L57

@akaihola
Copy link
Contributor Author

akaihola commented Feb 10, 2022

So creating an empty directory (e.g. with tempfile.TemporaryDirectory()) would probably be more appropriate?

@fizyk
Copy link
Member

fizyk commented Feb 10, 2022

@akaihola yes, I think so, so the default should be a new temporary directory within tempdir, rather than tmpdir itself.

@akaihola
Copy link
Contributor Author

The tests do pass if I run them locally in a container. Any idea what is different in the GitHub Workflows environment?

I'm using this Dockerfile with Podman:

FROM python

RUN apt-get update \
 && apt-get install -y rabbitmq-server \
 && rm -rf /var/lib/apt/lists/*
COPY . /pytest-rabbitmq
WORKDIR /pytest-rabbitmq
RUN python -m pip install --upgrade pip
RUN pip install -r requirements-test.txt
CMD pytest -n 0 --cov-report=xml \
 && pytest -n 1 --cov-report=xml:coverage-xdist.xml

And it indeed runs fine:

$ podman run pytest-rabbitmq
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-7.0.0, pluggy-1.0.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /pytest-rabbitmq, configfile: setup.cfg, testpaths: tests
plugins: forked-1.4.0, xdist-2.5.0, cov-3.0.0, rabbitmq-2.2.0
collecting ... collected 7 items

tests/test_rabbitmq.py::test_rabbitmq PASSED                             [ 14%]
tests/test_rabbitmq.py::test_second_rabbitmq PASSED                      [ 28%]
tests/test_rabbitmq.py::test_rabbitmq_clear_exchanges PASSED             [ 42%]
tests/test_rabbitmq.py::test_rabbitmq_clear_queues PASSED                [ 57%]
tests/test_rabbitmq.py::test_random_port PASSED                          [ 71%]
tests/test_rabbitmq.py::test_random_port_node_names PASSED               [ 85%]
tests/test_rabbitmq.py::test_plugin_directory PASSED                     [100%]

---------- coverage: platform linux, python 3.8.12-final-0 -----------
Coverage XML written to file coverage.xml


============================== 7 passed in 51.57s ==============================
/usr/local/lib/python3.8/site-packages/coverage/inorout.py:535: CoverageWarning: Module pytest_rabbitmq was previously imported, but not measured (module-not-measured)
  self.warn(msg, slug="module-not-measured")
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-7.0.0, pluggy-1.0.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /pytest-rabbitmq, configfile: setup.cfg, testpaths: tests
plugins: forked-1.4.0, xdist-2.5.0, cov-3.0.0, rabbitmq-2.2.0
gw0 I
[gw0] linux Python 3.8.12 cwd: /pytest-rabbitmq
[gw0] Python 3.8.12 (default, Mar  2 2022, 05:04:35)  -- [GCC 10.2.1 20210110]
gw0 [7]

scheduling tests via LoadScheduling

tests/test_rabbitmq.py::test_rabbitmq 
[gw0] [ 14%] PASSED tests/test_rabbitmq.py::test_rabbitmq 
tests/test_rabbitmq.py::test_second_rabbitmq 
[gw0] [ 28%] PASSED tests/test_rabbitmq.py::test_second_rabbitmq 
tests/test_rabbitmq.py::test_rabbitmq_clear_exchanges 
[gw0] [ 42%] PASSED tests/test_rabbitmq.py::test_rabbitmq_clear_exchanges 
tests/test_rabbitmq.py::test_rabbitmq_clear_queues 
[gw0] [ 57%] PASSED tests/test_rabbitmq.py::test_rabbitmq_clear_queues 
tests/test_rabbitmq.py::test_random_port 
[gw0] [ 71%] PASSED tests/test_rabbitmq.py::test_random_port 
tests/test_rabbitmq.py::test_random_port_node_names 
[gw0] [ 85%] PASSED tests/test_rabbitmq.py::test_random_port_node_names 
tests/test_rabbitmq.py::test_plugin_directory 
[gw0] [100%] PASSED tests/test_rabbitmq.py::test_plugin_directory /usr/local/lib/python3.8/site-packages/coverage/inorout.py:535: CoverageWarning: Module pytest_rabbitmq was previously imported, but not measured (module-not-measured)
  self.warn(msg, slug="module-not-measured")


---------- coverage: platform linux, python 3.8.12-final-0 -----------
Coverage XML written to file coverage-xdist.xml


============================== 7 passed in 44.34s ==============================

@fizyk
Copy link
Member

fizyk commented Apr 22, 2022

@akaihola looking at this I think the difference is the lack of administrative privileges.

your local run on docker is being run with root, so it does have all privileges. The github actions run is used with a user without those privileges, and maybe the plugin_path is restricted, or it's creation would require root privileges 🤔
https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#administrative-privileges-of-github-hosted-runners

@akaihola
Copy link
Contributor Author

Thanks @fizyk, I trust you that the lack of admin privileges is indeed the culprit here.

I couldn't find a pre-built Docker image which would claim to be close to GitHub's ubuntu-latest. I would have liked to reproduce and fix the failure locally. Any idea how to do that?

@fizyk
Copy link
Member

fizyk commented Apr 25, 2022

You have to create separate user on your docker, and switch to it prior to requirements installation and run:

https://docs.docker.com/engine/reference/builder/#user

@akaihola
Copy link
Contributor Author

@fizyk, I tried with this Dockerfile, but all tests still pass:

FROM python

RUN apt-get update \
 && apt-get install -y rabbitmq-server \
 && rm -rf /var/lib/apt/lists/*
COPY src /pytest-rabbitmq/src
COPY tests /pytest-rabbitmq/tests
COPY setup.* /pytest-rabbitmq/
COPY requirements-test.txt /pytest-rabbitmq/
WORKDIR /pytest-rabbitmq
RUN useradd -m pyuser \
 && chown -R pyuser /pytest-rabbitmq
USER pyuser
ENV PATH /home/pyuser/.local/bin:$PATH
RUN python -m pip install --upgrade pip
RUN pip install -r requirements-test.txt
CMD pytest -n 0 --cov-report=xml \
 && pytest -n 1 --cov-report=xml:coverage-xdist.xml

@fizyk
Copy link
Member

fizyk commented Apr 28, 2022

@akaihola do you have a branch I could look at when I'll have spare time?
I have somewhat similar problem with running tests on github actions in pytest-elasticsearch with elasticsearch 8, where tests locally pass just fine, but I can not connect to it properly on github-actions 😕

@akaihola
Copy link
Contributor Author

@fizyk, I'm using the very branch of this pull request (akaihola:plugin-dir) with the Dockerfile I pasted above.

Copy link
Member

@fizyk fizyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged main branch and added additional commit removing the default value, however after a bit of thinking I believe there's no real need for default, the default, should be not to use these settings. And only use them if someone will pass the configuration options.

@@ -37,7 +37,8 @@ def __init__(
envvars = {
"RABBITMQ_LOG_BASE": logpath + f"/rabbit-server.{port}.log",
"RABBITMQ_MNESIA_BASE": path + "mnesia",
"RABBITMQ_ENABLED_PLUGINS_FILE": plugin_path + "/plugins",
"RABBITMQ_ENABLED_PLUGINS_FILE": plugin_path + "/enabled",
"RABBITMQ_PLUGINS_DIR": plugin_path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 maybe skip both settings if the plugin's dir does not exists? question, what happens if we'll point to the real files and paths, will it work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my thinking is that there's not much point to point to the default for both of these settings (enabled_plugin_file and plugins_dir) if they are not existing.

@@ -96,7 +96,7 @@ def rabbitmq_proc_fixture(request):
rabbit_port = get_port(port) or get_port(config["port"])

rabbit_path = os.path.join(gettempdir(), f"rabbitmq.{rabbit_port}/")
rabbit_plugin_path = plugindir or config["plugindir"] or rabbit_path
rabbit_plugin_path = plugindir or config["plugindir"] or os.path.join(rabbit_path, "plugins")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the default to None, and pointed to plugins inside the created rabbit_path as created above. However I believe it should no have default

@akaihola
Copy link
Contributor Author

akaihola commented May 3, 2022

It seems /usr/lib/rabbitmq/bin/rabbitmq-server is now crashing in multiple tests with

init terminating in do_boot
({undef,
  [{rabbit_nodes_common,make,test3,[]},
   {rabbit_prelaunch,start,0,[{_},{_}]},
   {init,start_em,1,[]},
   {init,do_boot,3,[]}]
})

Crash dump is being written to: /tmp/rabbit-server.28723.log/erl_crash.dump...

This goes way beyond my expertise unfortunately.

@fizyk
Copy link
Member

fizyk commented May 23, 2022

As most of the Java programs when they crash for me. I won't promise when, but I'll take a look at it someday...

@akaihola
Copy link
Contributor Author

As most of the Java programs when they crash for me. I won't promise when, but I'll take a look at it someday...

Although RabbitMQ isn't written in Java but in Erlang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants