devel:hacking
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:hacking [2012/05/07 11:17] – fix url morten | devel:hacking [2014/11/05 10:57] (current) – morten | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Hacker' | ====== Hacker' | ||
- | If you are contributing code to Network Administration Visualized, | + | This document has moved to https:// |
- | please read this first. | + | |
- | + | ||
- | + | ||
- | ====== Contributing to NAV ====== | + | |
- | Originally, NAV was a closed source project, initiated by the | + | |
- | Norwegian University of Science and Technology (NTNU), and eventually | + | |
- | sponsored by UNINETT on behalf of the Norwegian higher education | + | |
- | community. | + | |
- | NAV under the GNU General Public License, making it a truly free | + | |
- | software system. | + | |
- | + | ||
- | While UNINETT and NTNU are still the main contributors to NAV, | + | |
- | developing NAV to support the needs of the Norwegian higher education | + | |
- | community, contributions from third parties is highly appreciated. | + | |
- | + | ||
- | We communicate mainly through mailing lists, | + | |
- | [[https:// | + | |
- | on // | + | |
- | gatherings for its customers: Norwegian universities, | + | |
- | colleges and research institutions. | + | |
- | + | ||
- | To contribute: | + | |
- | + | ||
- | Go to http:// | + | |
- | + | ||
- | * Join the mailing lists. | + | |
- | particular is for discussing NAV development. | + | |
- | low traffic list. We can only hope this will change ;-) | + | |
- | * Get a copy of the latest development sources by cloning the | + | |
- | Mercurial repository at http:// | + | |
- | Most new development takes place on this branch. | + | |
- | * Take a look at the [[: | + | |
- | development projects at NTNU]] (NAVMe, NAVMore, tigaNAV and | + | |
- | others) - design specifications and other useful bits of historic | + | |
- | NAV information is mostly to be found in these. | + | |
- | some of the oldest project documentation is in Norwegian only. Do | + | |
- | not hesitate to ask for help on the mailing lists. | + | |
- | + | ||
- | If you wish to contribute code to the project, see the [[# | + | |
- | + | ||
- | ====== Directory layout ====== | + | |
- | A rough guide to the source tree: | + | |
- | + | ||
- | | bin/ | NAV ' | + | |
- | | contrib/ | + | |
- | | doc/ | User and developer documentation | | + | |
- | | etc/ | Example/ | + | |
- | | java/ | Java source code | | + | |
- | | media/ | + | |
- | | packages/ | + | |
- | | python/ | + | |
- | | sql/ | SQL schema definitions and installation/ | + | |
- | | templates/ | Django HTML templates | | + | |
- | | tests/ | + | |
- | | tools/ | + | |
- | + | ||
- | ====== Development languages and frameworks ====== | + | |
- | + | ||
- | Historically, | + | |
- | (Perl, Java, PHP and Python). | + | |
- | impact on integration and maintenance over the years, we've managed to | + | |
- | reduce this to just Python and Java in later years. We have a | + | |
- | long-term goal to rewrite the remaining Java backend code to Python. | + | |
- | + | ||
- | Currently (as of February 2011), NAV consists mostly of Python code, | + | |
- | with a few remaining backend systems written in Java (there' | + | |
- | Netmap Java Applet). | + | |
- | + | ||
- | * We will only accept new code written in Python (except when it | + | |
- | involves patches to the existing Java code). | + | |
- | * When you contribute additions to the web interface, use the Django framework. | + | |
- | + | ||
- | If you wish to contribute something really useful that doesn' | + | |
- | Python, we may consider including it in the //contrib// directory. | + | |
- | + | ||
- | If **YOU** are willing to invest in porting some of the existing Java | + | |
- | code to Python, then you will be celebrated as a NAV hero! | + | |
- | + | ||
- | ====== Coding style ====== | + | |
- | Much of the legacy NAV code was written without using any coding style | + | |
- | guidelines. | + | |
- | which we hope to reduce in the future. | + | |
- | these guidelines: | + | |
- | + | ||
- | * For Java code, please refer to SUN's "Code conventions for the | + | |
- | Java Programming Language": | + | |
- | * For Python code, please refer to PEP-8, "Style Guide for Python | + | |
- | Code" http:// | + | |
- | + | ||
- | If you see violations of these guidelines, don't hesitate to fix them. | + | |
- | If you fix file-wide indentation problems etc., please submit this as | + | |
- | a separate patch to make your other patches look clean and readable. | + | |
- | + | ||
- | ===== Python boilerplate headers ===== | + | |
- | We will generally only accept code into NAV if it is licensed under | + | |
- | GPL v2, but we may make individual exceptions for code licensed under | + | |
- | compatible licenses. | + | |
- | following boilerplate at the top: | + | |
- | + | ||
- | <code python> | + | |
- | # | + | |
- | # Copyright (C) 2008,2009 Somebody | + | |
- | # | + | |
- | # This file is part of Network Administration Visualized (NAV). | + | |
- | # | + | |
- | # NAV is free software: you can redistribute it and/or modify it under the | + | |
- | # terms of the GNU General Public License version 2 as published by the Free | + | |
- | # Software Foundation. | + | |
- | # | + | |
- | # This program is distributed in the hope that it will be useful, but WITHOUT | + | |
- | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + | |
- | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | + | |
- | # more details. | + | |
- | # License along with NAV. If not, see < | + | |
- | # | + | |
- | </ | + | |
- | + | ||
- | If a file uses non-ASCII characters, it **must** be encoded as UTF-8, and an | + | |
- | encoding statement should be inserted at the top: | + | |
- | + | ||
- | <code python> | + | |
- | # -*- coding: utf-8 -*- | + | |
- | </ | + | |
- | + | ||
- | ====== Database ====== | + | |
- | NAV uses PostgreSQL as its database backend. | + | |
- | employed to logically group tables and relations. | + | |
- | to 3.5 employed separate PostgreSQL databases instead of namespaces. | + | |
- | + | ||
- | The namespaces currently in use are: | + | |
- | + | ||
- | | '' | + | |
- | | '' | + | |
- | | '' | + | |
- | | '' | + | |
- | | '' | + | |
- | + | ||
- | ===== Connecting to the database (Python) ==== | + | |
- | ==== Raw SQL ==== | + | |
- | + | ||
- | To obtain a connection to the NAV database, use the API accordingly, | + | |
- | e.g.: | + | |
- | + | ||
- | <code python> | + | |
- | import nav.db | + | |
- | # Get a connection to the NAV database | + | |
- | connection = nav.db.getConnection(' | + | |
- | </ | + | |
- | + | ||
- | The above code will open a connection to NAV's database, or, if a | + | |
- | previous connection with these parameters is already open, returns the | + | |
- | already existing connection from a connection cache. | + | |
- | + | ||
- | The '' | + | |
- | the name of a subsystem. | + | |
- | separate database users for each subsystem (known as a '' | + | |
- | '' | + | |
- | database user for a subsystem called '' | + | |
- | the same database user for all known subsystem names. | + | |
- | using a subsystem name that is not configured in '' | + | |
- | + | ||
- | ==== Django models ==== | + | |
- | NAV 3.5 and on includes Django models for most database tables. | + | |
- | SQL magic is needed to perform your database voodoo, it is recommended | + | |
- | that you use these models, located in the module '' | + | |
- | do not need to explicitly establish a database connection to use these | + | |
- | models, as Django takes care of all that. | + | |
- | + | ||
- | The models are defined in modules of the '' | + | |
- | + | ||
- | ===== Changing the schema ==== | + | |
- | + | ||
- | The baseline schema is located in '' | + | |
- | is responsible for running this when creating a new database. To make a schema | + | |
- | change, you **do not** change the baseline, but go to the '' | + | |
- | directory and create a new schema change script there. | + | |
- | + | ||
- | Schema change scripts as numbered, using the following pattern: | + | |
- | + | ||
- | * '' | + | |
- | + | ||
- | The ''< | + | |
- | minor number of the next NAV release. | + | |
- | - pick the next free number when creating a schema change script. | + | |
- | + | ||
- | Remember these points when creating a schema change script: | + | |
- | + | ||
- | * Create separate change scripts for unrelated schema changes. | + | |
- | * Remember to write SQL to //migrate// existing data, if necessary. | + | |
- | * Do not use transactional statements - the '' | + | |
- | care of that. | + | |
- | + | ||
- | To apply your change scripts, just run '' | + | |
- | '' | + | |
- | applied, and it will detect your new change script and apply this to the | + | |
- | database. | + | |
- | + | ||
- | :!: When changing the schema, don't forget to update the Django models in the | + | |
- | '' | + | |
- | models can at least be used to run proper SELECTs against the database. | + | |
- | + | ||
- | ====== Legacy web code ====== | + | |
- | Legacy web code interfaces directly with | + | |
- | [[http:// | + | |
- | [[http:// | + | |
- | + | ||
- | All Cheetah templates are located in the '' | + | |
- | directory. | + | |
- | + | ||
- | ===== Legacy database connections in web code ===== | + | |
- | Use the '' | + | |
- | existing database connection. | + | |
- | interpreter and namespace per Apache process, which also means that | + | |
- | database connections will be shared between the modules running in | + | |
- | each process. | + | |
- | connections obtained from '' | + | |
- | + | ||
- | * **Do not, under any circumstances**, | + | |
- | connection between client requests. | + | |
- | connection at the start of each request cycle - the API will cache | + | |
- | connections between requests, and will automagically re-open | + | |
- | broken connections. | + | |
- | modules, retained references may be invalid in the next request | + | |
- | cycle. | + | |
- | * **Do not explicitly close database connections.** | + | |
- | will try to reopen any closed or broken connections, | + | |
- | extra overhead, and you don't play nice with the other web | + | |
- | modules. | + | |
- | * **The obtained connections will use an isolation level of //read | + | |
- | committed// | + | |
- | current transaction if you modify any data. A mod_python | + | |
- | '' | + | |
- | transactions as the request cycle ends, but this may change | + | |
- | in the future, so you must not rely on it. | + | |
- | * **Do not change the isolation level of a connection** without | + | |
- | restoring it to its original value before the end of the request | + | |
- | cycle. | + | |
- | + | ||
- | ===== The " | + | |
- | '' | + | |
- | placed in the Apache foundation' | + | |
- | tools that interface directly with '' | + | |
- | + | ||
- | We do, however, aim to refactor existing mod_python-interfacing code | + | |
- | into working as Django views. | + | |
- | + | ||
- | * Each '' | + | |
- | URL parsing and view dispatch. | + | |
- | Django URL configuration and separate view functions first. | + | |
- | * Usage of '' | + | |
- | must be refactored to use the '' | + | |
- | objects of a Django '' | + | |
- | objects behave like dictionaries, | + | |
- | class does. | + | |
- | * Conversion from Cheetah to Django templates is not necessary to | + | |
- | refactor a mod_python handler into a Django view. It is desirable | + | |
- | to do so in later refactorings, | + | |
- | * NAV's authentication and authorization scheme hooks into Apache' | + | |
- | request cycle using a '' | + | |
- | also adds session data as an attribute to the '' | + | |
- | request object. | + | |
- | directly with '' | + | |
- | must be refactored to work in a pure Django setting before NAV can | + | |
- | be free of its dependence on '' | + | |
- | + | ||
- | ====== Writing new web code ====== | + | |
- | If you are writing a new web application / tool for NAV, please use | + | |
- | the Django framework. | + | |
- | primer on how Django integrates with legacy NAV]]. | + | |
- | + | ||
- | ====== Version Control ====== | + | |
- | NAV uses [[http:// | + | |
- | distributed version control. | + | |
- | http:// | + | |
- | + | ||
- | ===== Guide to the repository jungle ===== | + | |
- | The official repositories represent three types of branches | + | |
- | + | ||
- | ==== Unstable (default) ==== | + | |
- | New, bleeding edge development occurs on the | + | |
- | // | + | |
- | considered unstable (although we try to always keep it buildable). | + | |
- | + | ||
- | ==== Feature branches ==== | + | |
- | New features that take a while (and a lot of changesets) to implement | + | |
- | and test will often be published as separate feature branches. | + | |
- | all intents and purposes, the feature branches will look like the | + | |
- | //default// branch with some added feature. | + | |
- | from the //default// branch regularly. | + | |
- | " | + | |
- | + | ||
- | ==== Stable (series) ==== | + | |
- | Once we are nearing a new series release of NAV (such as 3.5 or 3.6), | + | |
- | a new [[http:// | + | |
- | created from the //default// branch. | + | |
- | the first version is tagged and released. | + | |
- | only bug fixes in this branch. | + | |
- | are tagged on this branch, and all changes are merged back onto the | + | |
- | //default// branch. | + | |
- | + | ||
- | When someone writes a patch for a bug, this should usually be | + | |
- | committed to the latest active series branch which is affected by the | + | |
- | bug. Once a new series is released, we do not usually maintain the | + | |
- | older series branches. | + | |
- | we are unlikely to create a new point release from it. | + | |
- | + | ||
- | ===== Push access ===== | + | |
- | Push access to the official repositories is limited to developers | + | |
- | employed or commisioned by UNINETT. | + | |
- | + | ||
- | ====== Testing and Continuous Integration ====== | + | |
- | Much of NAV is **legacy code**, as defined by //Michael C. Feathers//: | + | |
- | Code that has no tests. | + | |
- | automated tests into the codebase the past couple of years, and hope | + | |
- | to improve coverage in time. | + | |
- | + | ||
- | There are no tests for the legacy Java code, but many unit tests and | + | |
- | integration tests now reside in the '' | + | |
- | + | ||
- | ===== Running tests ===== | + | |
- | We use '' | + | |
- | included as '' | + | |
- | used to run the unit tests only when a '' | + | |
- | issued in the '' | + | |
- | + | ||
- | Some of the test requirements aren't available on the Debian systems | + | |
- | we use for development, | + | |
- | // | + | |
- | can be created thus: | + | |
- | + | ||
- | <code bash> | + | |
- | virtualenv .env | + | |
- | . .env/ | + | |
- | easy_install pip | + | |
- | pip install -r tests/ | + | |
- | </ | + | |
- | + | ||
- | There' | + | |
- | database initialization. | + | |
- | following will configure and build NAV automatically, | + | |
- | into a directory called '' | + | |
- | suitable virtualenv in '' | + | |
- | before running tests: | + | |
- | + | ||
- | <code bash> | + | |
- | export PGDATABASE=testdb | + | |
- | export PGUSER=testuser | + | |
- | tests/ | + | |
- | </ | + | |
- | + | ||
- | ===== Hudson/ | + | |
- | We use //Hudson// (soon-to-be // | + | |
- | of NAV. All the automated tests are run each time new changesets are | + | |
- | pushed to the NAV repositories. | + | |
- | stats on code quality. | + | |
- | + | ||
- | Our Hudson installation is available on http:// | + | |
- | + | ||
- | + | ||
- | ====== Submitting patches ====== | + | |
- | Unless you are submitting one-off fixes for bugs and small issues, | + | |
- | please take the time to discuss your change proposals on the | + | |
- | //nav-dev// mailing list. This will increase the chances of having | + | |
- | your patches accepted. | + | |
- | + | ||
- | Base your patches on the relevant Mercurial branches. | + | |
- | submitting a patch for an issue that affects the latest stable series, | + | |
- | base your patch on that series branch. | + | |
- | containing new features, base them on the default branch. | + | |
- | + | ||
- | There are three common options for submitting patches: | + | |
- | + | ||
- | * The best way to submit your patches would be using Mercurial. Publish | + | |
- | your own Mercurial branch, and mail its URL to the //nav-dev// mailing | + | |
- | list. | + | |
- | * If unable to host a public Mercurial branch, export your changes | + | |
- | as a Mercurial bundle and attach it to an email addressed to the | + | |
- | //nav-dev// mailing list. | + | |
- | * If you have a single patch to submit, attach it to an email | + | |
- | addressed to the //nav-dev// mailing list. Please **do not | + | |
- | patchbomb** the mailing list with multiple emails. | + |
devel/hacking.1336389448.txt.gz · Last modified: by morten