First of all, install tox utility. It’s likely to be in your distribution repositories under name of python-tox. Alternatively, you can install it from PyPI.
Next checkout and create environments:
git clone https://github.com/openstack/ironic-inspector.git
cd ironic-inspector
tox
Repeat tox command each time you need to run tests. If you don’t have Python interpreter of one of supported versions (currently 2.7 and 3.4), use -e flag to select only some environments, e.g.
tox -e py27
Note
Support for Python 3 is highly experimental, stay with Python 2 for the production environment for now.
Note
This command also runs tests for database migrations. By default the sqlite backend is used. For testing with mysql or postgresql, you need to set up a db named ‘openstack_citest’ with user ‘openstack_citest’ and password ‘openstack_citest’ on localhost. Use the script tools/test_setup.sh to set the database up the same way as done in the OpenStack CI environment.
Note
Users of Fedora <= 23 will need to run “sudo dnf –releasever=24 update python-virtualenv” to run unit tests
To run the functional tests, use:
tox -e func
Run the service with:
.tox/py27/bin/ironic-inspector --config-file example.conf
Of course you may have to modify example.conf to match your OpenStack environment.
You can develop and test ironic-inspector using DevStack - see DevStack Support for the current status.
DevStack provides a way to quickly build full OpenStack development environment with requested components. There is a plugin for installing ironic-inspector on DevStack.
[[local|localrc]]
disable_service n-net n-novnc
enable_service neutron q-svc q-agt q-dhcp q-l3 q-meta
enable_service s-proxy s-object s-container s-account
disable_service heat h-api h-api-cfn h-api-cw h-eng
disable_service cinder c-sch c-api c-vol
enable_plugin ironic https://github.com/openstack/ironic
enable_plugin ironic-inspector https://github.com/openstack/ironic-inspector
IRONIC_BAREMETAL_BASIC_OPS=True
IRONIC_VM_COUNT=2
IRONIC_VM_SPECS_RAM=1024
IRONIC_BUILD_DEPLOY_RAMDISK=False
IRONIC_INSPECTOR_BUILD_RAMDISK=False
VIRT_DRIVER=ironic
LOGDAYS=1
LOGFILE=~/logs/stack.sh.log
SCREEN_LOGDIR=~/logs/screen
DEFAULT_INSTANCE_TYPE=baremetal
TEMPEST_ALLOW_TENANT_ISOLATION=False
There is a test script included:
source devstack/openrc admin admin
/opt/stack/ironic-inspector/devstack/exercise.sh
Start introspection for a node manually:
source devstack/openrc admin admin
openstack baremetal introspection start <UUID>
Then check status via API:
openstack baremetal introspection status <UUID>
ironic-inspector allows you to hook code into the data processing chain after introspection. Inherit ProcessingHook class defined in ironic_inspector.plugins.base module and overwrite any or both of the following methods:
called before any data processing, providing the raw data. Each plugin in the chain can modify the data, so order in which plugins are loaded matters here. Returns nothing.
called after node is found and ports are created, but before data is updated on a node. Please refer to the docstring for details and examples.
Make your plugin a setuptools entry point under ironic_inspector.hooks.processing namespace and enable it in the configuration file (processing.processing_hooks option).
ironic-inspector allows plugins to override the action when node is not found in node cache. Write a callable with the following signature:
called when node is not found in cache, providing the processed data. Should return a NodeInfo class instance.
Make your plugin a setuptools entry point under ironic_inspector.hooks.node_not_found namespace and enable it in the configuration file (processing.node_not_found_hook option).
ironic-inspector allows more condition types to be added for Introspection Rules. Inherit RuleConditionPlugin class defined in ironic_inspector.plugins.base module and overwrite at least the following method:
called to check that condition holds for a given field. Field value is provided as field argument, params is a dictionary defined at the time of condition creation. Returns boolean value.
The following methods and attributes may also be overridden:
called to validate parameters provided during condition creating. Default implementation requires keys listed in REQUIRED_PARAMS (and only them).
contains set of required parameters used in the default implementation of validate method, defaults to value parameter.
if it’s set to True, missing fields will be passed as None values instead of failing the condition. Defaults to False.
Make your plugin a setuptools entry point under ironic_inspector.rules.conditions namespace.
ironic-inspector allows more action types to be added for Introspection Rules. Inherit RuleActionPlugin class defined in ironic_inspector.plugins.base module and overwrite at least the following method:
called to apply the action.
The following methods and attributes may also be overridden:
called to validate parameters provided during actions creating. Default implementation requires keys listed in REQUIRED_PARAMS (and only them).
contains set of required parameters used in the default implementation of validate method, defaults to no parameters.
Make your plugin a setuptools entry point under ironic_inspector.rules.conditions namespace.
Note
** argument is needed so that we can add optional arguments without breaking out-of-tree plugins. Please make sure to include and ignore it.
In order to make a change to the ironic-inspector database you must update the database models found in ironic_inspector.db and then create a migration to reflect that change.
There are two ways to create a migration which are described below, both of these generate a new migration file. In this file there are two functions:
ironic-inspector-dbsync upgrade is run, and should be populated with code to bring the database up to its new state from the state it was in after the last migration.
upgrade performs, returning the database to the state it would have been in before the migration ran.
For further information on creating a migration, refer to Create a Migration Script from the alembic documentation.
This is the simplest way to create a migration. Alembic will compare the models to an up to date database, and then attempt to write a migration based on the differences. This should generate correct migrations in most cases however there are some cases when it can not detect some changes and may require manual modification, see What does Autogenerate Detect (and what does it not detect?) from the alembic documentation.
ironic-inspector-dbsync upgrade
ironic-inspector-dbsync revision -m "A short description" --autogenerate
This will generate an empty migration file, with the correct revision information already included. However upgrade and downgrade are left empty and must be manually populated in order to perform the correct actions on the database:
ironic-inspector-dbsync revision -m "A short description"