This page contains a variety of information for those intending to work on Candlepin and its associated sub-projects.
Our canonical reference for code style is the
which stores all the Checkstyle configuration.
Also see the Java Coding Conventions
For Python, stick to the guidelines in PEP8.
make stylish to run pep8, pyflakes, pyqver, rpmlint, and a few
subman specific code checks.
For C, run this on your code before you commit:
indent -linux -pcs -psl -ci8
-cs -cli8 -cp0 yourawesomefile.c. Note that you may need to double-check that
the “*” is on the right line, and feed in arguments to indent as appropriate.
General commit messages should follow the following format:
A short one line description of what you did. Then a newline, and optionally provide any extra information here.
When committing a bug fix from bugzilla (BZ), the following format should be used:
\<Bug Number\>: Short one line description of what was done. Then optionally a newline and other information.
712415: Make the names consistent between list --installed and list --consumed
We use these for changelogs when tagging builds. It may seem pedantic but when you need to process a few hundred lines it’s very helpful if they’re typo free, changelog friendly, and have the bz’s automatically detected.
A general git guide can be found here.
Testing is extremely important for the team. We have a variety of test suites on the go, all of which should be kept passing before you commit to any given codebase.
Java unit tests: Standard JUnit tests which can be run from within Eclipse or from the CLI.
$ ./gradlew test
A specific suite can be run with:
$ ./gradlew test --tests EntitlementCuratorTest
Functional rspec tests (from
$ ./gradlew rspec
The safest bet, in addition to rspec, is to run check (includes all lint tasks, test, validate_translation) before committing:
$ ./gradlew check
When possible, we try to leverage mocks in unit tests to skip complicated/costly setup of objects we’re not interested in, and instead just focus on testing the component we are interested in. This is a bit of an art form in itself and can be quite tricky to get the hang of, and when it goes wrong you can end up with an un-maintainable mess. Look for good examples, experiment, chat with the team, and in general just try to leverage this when possible. We’re all still learning how this works. :)
In the Java unit tests this is accomplished with Mockito.
In subscription-manager and python-rhsm we use the python-mock module: http://www.voidspace.org.uk/python/mock/
Candlepin can be a confusing beast. Some pointers that may help to understand how things work and why they are the way they are.
Central to Candlepin’s design is the use of adapters to abstract services which may or may not be provided by Candlepin components. Objects such as Subscriptions, Products, and Users all may live in external systems depending on the deployment.
These two objects are almost the exact same thing. They both exist because we may not be the canonical source for Subscription data. As such we use the Subscription service adapter to query subscription data, and use this to create/update/delete our own Pool objects (which are always in our database). The Pool’s are then used to track consumption.
Buildr can auto-generate candlepin.conf for you. This is very useful when you are constantly switching between databases. See the AutoConf page.
It can be helpful for developers to save a postgresql database for later use particularly when they’re loaded with a complex or large amount of data.
$ pg_dump -U candlepin candlepin > candlepindb.sql
To restore an old database:
$ sudo service tomcat6 stop $ dropdb -U candlepin candlepin && createdb -U candlepin candlepin $ psql -U candlepin candlepin < ~/src/candlepin/candlepindb.sql $ buildconf/scripts/deploy -g -t
To enable remote debugging in Tomcat, you must pass the JVM values telling it to enable JDWP.
Add the following to the
Now you will be able to connect a debugger to port 8000.
-Xdebugger -Xrunjdwp version of enabling the debugger has been
deprecated as of Java 5.
Candlepin uses Tito to build the rpms, see here.
To use the logging JDBC driver with Candlepin see the log driver page
CREATE FUNCTION pg_temp.sortarray(int2) returns int2 as ' SELECT ARRAY( SELECT $1[i] FROM generate_series(array_lower($1, 1), array_upper($1, 1)) i ORDER BY 1 ) ' language sql; SELECT conrelid::regclass ,conname ,reltuples::bigint FROM pg_constraint JOIN pg_class ON (conrelid = pg_class.oid) WHERE contype = 'f' AND NOT EXISTS ( SELECT 1 FROM pg_index WHERE indrelid = conrelid AND pg_temp.sortarray(conkey) = pg_temp.sortarray(indkey) ) ORDER BY reltuples DESC ;