OCF resource agents based on inqbus.ocf.generic
Project description
- Version:
- 0.1
- Download:
- Keywords:
python, OCF, resource agents, pacemaker, openvpn, daemon process
Overview
OCF compatible resource agent classes programmed in python. Usually OCF-Agents are written as unix shell-script. We are running lots of high avaible python processes which are controlled by pacemaker. Using shell for controlling Python processes feels awkward, so we builded a python integration framework for OCF compatible agents.
What do you get
This package gives you some generic OCF agent classes for PID controlled daemons:
pidagent
openvpn
based on the inqbus.ocf.generic framework.
The inqbus.ocf.generic framework keeps away from you the gory details you have to go into writing an OCF compatible resource agent. Powerfull base classes bring to you:
A good test coverage of the agent code (How to test a shell script?)
Support of the complete set of OCF exitcodes and their respective business logik
OCF Paramter classes for integer, string, etc. values
Predefined generic OCF handlers (meta-data, validate)
The generation of the XML meta data is done for you automagically
Easy addition of handlers for e.g. start/stop/status
Inheritance of resource agents: encapsulate agent business logic and share it among similiar reasource agents
Inqbus.ocf.agents in addition brings the following functionality
the business logic for controlling the PID file
checking for the running state of the PID
starting and stopping the daemon (with checking for zombies and staggered kill signals to bring a process really down if it has to die)
checking for the PID status
in the base class PIDBaseAgent.
What is missing
We did not implement any business logic for the actions:
notify
demote
promote
master/slave
reload
but inqbus.ocf.generic framework can represent any OCF action that is specified yet or in the future - just implement a handler for the desired action:
class MyAgent(Agent): def config(self): """ Register my actions """ self.handlers['notify'] = Handler(MyAgent.do_notify, 10) self.handlers['future'] = Handler(MyAgent.do_future, 10)
Implementation
The PIDAgent and Openvpn classes are derived from PIDBaseAgent with minimal programming efford:
from pidbaseagent import PIDBaseAgent from inqbus.ocf.generic.parameter import OCFString class PIDAgent(PIDBaseAgent): def add_params(self): self.add_parameter(OCFString("executable", longdesc="Path to the executable", shortdesc="executable", required= True) ) self.add_parameter(OCFString( "pid_file", longdesc="Path to the pid file", shortdesc="executable", required= True) ) def get_pid_file(self): """tell the base class to find the PID file in the parameter 'pid_file'""" return self.params.pid_file.value def get_executable(self): """tell the base class how to find the executable path in the parameter 'executable'""" return self.params.executable.value def main(): """Entry point for the reasource agent shellscript""" import sys PIDAgent().run(sys.argv) if __name__ == "__main__" : main() """Entry point for the command line"""
To use the inqbus.ocf.agents agent classes you need to set only one symlink per agent class into your Pacemaker (or other OCF HA) system.
Building arbitrary resource agent classes e.g. for IP addresses is easy utilizing the inqbus.ocf.generic <http://pypi.python.org/inqbus.ocf.generic>_ framework.
Documentation
This file and the source files for openvpn and the PIDAgent classes serve as a simple introduction to inqbus.ocf.agents. For more in depth documentation on writing your own reasource agents with the inqbus.ocf framework, have a look at
Requirements
Python >=2.7 or Python 3.x
Installation
We recomment a buildout based installation into a virtual environment but you may install inqbus.ocf.agents via pip or easy_install as well.
Installation via buildout
Build a virtual environment:
:/opt$ virtualenv --no-site-packages ocf :/opt$ cd ocf :/opt/ocf$ source bin/activate (ocf):/opt/ocf$
Install the make environment buildout and initialize it:
(ocf):/opt/ocf$ easy_install zc.buildout (ocf):/opt/ocf$ ./bin/buildout init
Create a buildout.cfg:
[buildout] parts = app pidagent openvpn # Buildout directories to use. eggs-directory = eggs ############################################################################### # Download links for packages # ----------------------------------------------------------------------------- # Add additional egg download sources here. # Note that pypi.propertyshelf.com and mypypi.inqbus.de require authentication. find-links = http://mypypi.inqbus.de/privateEggs ############################################################################### # Extensions # ----------------------------------------------------------------------------- # Load several extensions. extensions = lovely.buildouthttp [app] recipe = z3c.recipe.scripts eggs = inqbus.ocf.agents interpreter = python_ocf [openvpn] recipe = collective.recipe.template output = ${buildout:directory}/bin/openvpn.sh inline = #!/bin/bash ${buildout:directory}/../bin/python ${buildout:directory}/bin/openvpn $* mode = 755 [pidagent] recipe = collective.recipe.template output = ${buildout:directory}/bin/pidagent.sh inline = #!/bin/bash ${buildout:directory}/../bin/python ${buildout:directory}/bin/pidagent $* mode = 755
run buildout to install the package:
(ocf):/opt/ocf$ ./bin/buildout
Configuration
First check the installation:
(ocf):/opt/ocf$ ./bin/openvpn.sh Usage: openvpn.py <start|validate-all|stop|monitor|meta-data>
Integrating the openvpn agent class into Pacemaker:
:/opt/ocf$ cd /usr/lib/ocf/resource.d/ :/usr/lib/ocf/resource.d/$ mkdir inqbus :/usr/lib/ocf/resource.d/$ cd inqbus :/usr/lib/ocf/resource.d/inqbus$ ln -s /opt/ocf/bin/openvpn.sh .
Now the configuration is complete an you can use the OCF python resource agents as the others that came with heartbeat or pacemaker.
Running the tests
The test are formulated using the nose testing framework.
To run the tests you need the source code. There are two ways to obtain it.
Clone the Mercurial repository from BitBucket:
$ hg clone https://bitbucket.org/inqbus/inqbus.ocf.agents
Download the package from PyPI and unpack it:
$ wget http://pypi.python.org/packages/source/i/inqbus.ocf.agents/inqbus.ocf.agents-0.1.tar.gz $ tar xzvf inqbus.ocf.agents-0.1.tar.gz
Testing with buildout
The easiest way to test is with buildout:
$ ./bin/buildout ... $ ./bin/nose --with-coverage ... inqbus.ocf.agents.openvpn 91% inqbus.ocf.agents.pidagent 83% inqbus.ocf.agents.pidbaseagent 74% inqbus.ocf.generic.agent 88% inqbus.ocf.generic.container 100% inqbus.ocf.generic.exits 84% inqbus.ocf.generic.handlers 96% inqbus.ocf.generic.parameter 83%
The test coverage is high. We includet the ocf-tester testcases in our test suite. Maximum testcoverage is only possible if running the tests as root since most of the tests are integration tests, which steer real unix daemons. In case of the openvpn agent a real openvpn instance is brought up.
Dispite the high level of testing there is still a portion of 10 to 26% of untested code. This code mainly attributes to the many plausability exits that are not easily tested. How should we test for a broken filesystem or a process that has become a zombie? If you think you have the answer to that questions, you are warmest welcome in the development team.
Testing with ocf-tester
Independently of the python tests pacemaker comes with the ocf-tester script. You may use the dummy_daemon that comes with inqbus.ocf.agents to test the pidagent:
:/opt/ocf/buildout$ ocf-tester -n test \ -o pid_file=/tmp/dummy_daemon.pid \ -o executable=./bin/dummy_daemon \ `pwd`/bin/pidagent.sh
Bugs and Issues
This software is work in progress. Please help us to improve it: https://bitbucket.org/inqbus/inqbus.ocf.agents
Please contact volker.jaenisch@inqbus.de if you have any question.
License
This software is licensed under the New BSD License. See the LICENSE.txt file in the top distribution directory for the full license text. Changelog =========
0.1 (unreleased)
Initial release
0.11 (bugfix-release)
added “cd to config dir” paramter for openvpn agent.
introduced ovpn_pid_dir paramter for openvpn agent.
fixed some flaws in README.txt
fixed that temporary files are deletetd from /tmp after tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file inqbus.ocf.agents-0.11.tar.gz
.
File metadata
- Download URL: inqbus.ocf.agents-0.11.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7968d893e0d9c3ad14482d1a232cdfa2c9c5fc6ab697201e3a5e7b900202cda8 |
|
MD5 | f0786df1d7e7402d8606be482de949c8 |
|
BLAKE2b-256 | 85a207b0a55bff32a5a077ab19ae9cd5d96dca83a55156a444a5c35f77124312 |
File details
Details for the file inqbus.ocf.agents-0.11-py2.6.egg
.
File metadata
- Download URL: inqbus.ocf.agents-0.11-py2.6.egg
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc452ced6d7673e19189accaf46b2ab366d6fce16e18d24665589ebafebc72c3 |
|
MD5 | 4701d9d56ce9aee8ae96e6c9211e38c7 |
|
BLAKE2b-256 | 26ecb370ccfe5f67a1418bef23eee43e4c2b4438d94fa0167b4b060e056c5944 |