Skip to content

Commit

Permalink
Merge pull request riptano#746 from aweisberg/fix_ccm_tests
Browse files Browse the repository at this point in the history
Fix broken nosetest to pytest fixtures
  • Loading branch information
driftx authored Feb 24, 2023
2 parents c51c655 + dd1c2dd commit f389dd3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ ccm.egg-info/
.tox/
.coverage
dse_creds.txt
.eggs/
50 changes: 44 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,52 @@ localhost.
The goal of ccm and ccmlib is to make it easy to create, manage and destroy a
small Cassandra cluster on a local box. It is meant for testing a Cassandra cluster.

New to Python development?
--------------------------
Python has moved on since CCM started development. `pip` is the new `easy_install`,
Python 3 is the new 2.7, and pyenv and virtualenv are strongly recommended for managing
multiple Python versions and dependencies for specific Python applications.

A typical MacOS setup would be to install [Homebrew](https://docs.brew.sh/Installation),
then `brew install pyenv` to manage Python versions and then use virtualenv to
manage the dependencies for CCM. Make sure to add [brew's bin directory to your path in
your ~/.zshenv](https://www.zerotohero.dev/zshell-startup-files/). This would be
`/usr/local` for MacOS Intel and `/opt/homebrew/` for MacOS on Apple Silicon.

Now you are ready to install Python using pyenv. To avoid getting a bleeding edge version that will fail with
some aspect of CCM you can `pyenv install 3.9.16`.

To create the virtualenv run `python3 -m venv --prompt ccm venv` with your git repo as the
current working directory to create a virtual environment for CCM. Then `source venv/bin/activate` to
enable the venv for the current terminal and `deactivate` to exit.

Now you a ready to set up the venv with CCM and its test dependencies. `pip install -e <path_to_ccm_repo>`
to install CCM, and its runtime dependencies from `requirements.txt`, so that the version of
CCM you are running points to the code you are actively working on. There is no build or package step because you
are editing the Python files being run every time you invoke CCM.

Almost there. Now you just need to add the test dependencies that are not in `requirements.txt`.
`pip install mock pytest` to finish setting up your dev environment!

Another caveat that has recently appeared Cassandra versions 4.0 and below ship with a version of JNA that isn't
compatible with Apple Silicon and there are no plans to update JNA on those versions. One work around if you are
generally building Cassandra from source to use with CCM is to replace the JNA jar in your Maven repo with a [newer
one](https://search.maven.org/artifact/net.java.dev.jna/jna/5.8.0/jar) that supports Apple Silicon.
Which you version you need to replace will vary depending on the Cassandra version, but it will normally be in
`~/.m2/repository/net/java/dev/jna/jna/<someversion>`. You can also replace the library in
`~/.ccm/repository/<whatever>/lib`.

Also don't forget to disable `AirPlay Receiver` on MacOS which also listens on port 7000.

Requirements
------------

- A working python installation (tested to work with python 2.7).
- pyYAML (http://pyyaml.org/ -- `sudo easy_install pyYaml`)
- six (https://pypi.org/project/six/ -- `sudo easy_install six`)
- See `requirements.txt` for runtime requirements
- `mock` and `pytest` for tests
- ant (http://ant.apache.org/, on Mac OS X, `brew install ant`)
- psutil (https://pypi.org/project/psutil/)
- Java (which version depends on the version of Cassandra you plan to use. If
unsure, use Java 7 as it is known to work with current versions of Cassandra).
- Java, Cassandra currently builds with either 8 or 11 and is restricted to JDK 8 language
features and dependencies. There are several sources for the JDK and Azul Zulu is one good option.
- If you want to create multiple node clusters, the simplest way is to use
multiple loopback aliases. On modern linux distributions you probably don't
need to do anything, but on Mac OS X, you will need to create the aliases with
Expand Down Expand Up @@ -85,6 +120,9 @@ Windows only:
link in order to fix the issue (as administrator):
- cmd /c mklink C:\ProgramData\chocolatey\bin\ant.bat C:\ProgramData\chocolatey\bin\ant.exe

MaxOS only:
- Airplay listens for incoming connections on 7000 so disable `Settings` -> `General` -> `AirDrop & Handoff` -> `AirPlay Receiver`

Remote Execution only:
- Using `--config-dir` and `--install-dir` with `create` may not work as
expected; since the configuration directory and the installation directory
Expand Down Expand Up @@ -298,7 +336,7 @@ Create a virtual environment i.e.:

python3 -m venv ccm

Pip install all dependecies and `mock`. You'll also need `nose` if `nosetests` is not installed in your system already. Now cd into the `tests` folder and run `nosetests`.
`pip install` all dependencies as well as `mock` and `pytest`. Run `pytest` from the repository root to run the tests.

Remote debugging
-----------------------
Expand Down
15 changes: 0 additions & 15 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import shutil
import sys


Expand All @@ -8,16 +6,3 @@

if sys.version_info < (3, 0):
FileNotFoundError = OSError


def setup_package():
try:
shutil.rmtree(TEST_DIR)
except FileNotFoundError:
pass

os.makedirs(TEST_DIR)


def teardown_package():
shutil.rmtree(TEST_DIR)
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import pytest
import shutil

from tests import TEST_DIR

@pytest.fixture(scope="package", autouse=True)
def setup_and_package():
try:
shutil.rmtree(TEST_DIR)
except FileNotFoundError:
pass

os.makedirs(TEST_DIR)
yield
shutil.rmtree(TEST_DIR)

0 comments on commit f389dd3

Please sign in to comment.