From 03b8f4dd119f19cd4e9b76616f52e8b370769350 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 17 Aug 2023 14:41:47 -0700 Subject: [PATCH] Revamp Ironic dev-quickstart documentation This is a significant improvement and update to Ironic contributor documentation, as an attempt to make it easier for new Ironic contributors to onboard. It is not perfect, but it's significantly better than the existing documentation. What this change does: - Improve dev-quickstart guide, make it easier to find devstack configurations. - Removes information that can bit-rot over time and replaces with more generic information. - Provides an actual working, tested, Ironic+Nova devstack conf What hasn't been done: - Testing of Ironic BFV or Multitenant networking devstack confs - Validation that the local development method still works - There is a ton more information about how to use these testing envs (both bifrost and devstack) which could be added. - System prerequsities and Python prerequisites under the unit tests section has bitrotted considerably; they have not been significantly modified and will be fixed in a future commit. Change-Id: I0cdfe50042fabb6b65633961fc418aff5d6ebfe3 --- doc/source/contributor/bifrost-dev-guide.rst | 16 + doc/source/contributor/dev-quickstart.rst | 857 +++--------------- doc/source/contributor/devstack-guide.rst | 474 ++++++++++ doc/source/contributor/index.rst | 3 + .../contributor/ironic-boot-from-volume.rst | 2 + .../ironic-multitenant-networking.rst | 1 + doc/source/contributor/local-dev-guide.rst | 228 +++++ 7 files changed, 834 insertions(+), 747 deletions(-) create mode 100644 doc/source/contributor/bifrost-dev-guide.rst create mode 100644 doc/source/contributor/devstack-guide.rst create mode 100644 doc/source/contributor/local-dev-guide.rst diff --git a/doc/source/contributor/bifrost-dev-guide.rst b/doc/source/contributor/bifrost-dev-guide.rst new file mode 100644 index 0000000000..68db44e98c --- /dev/null +++ b/doc/source/contributor/bifrost-dev-guide.rst @@ -0,0 +1,16 @@ +===================================== +Bifrost Development Environment Guide +===================================== + +Bifrost is a project that deploys and operates Ironic using ansible. It is +generally used standalone, without many other services running alongside. This +makes it a good choice for a quick development environment for Ironic features +that may not interact with other OpenStack services, even if you aren't +developing against bifrost directly + +Bifrost maintains it's own documentation on +`building a test environment with bifrost `_. + +The testenv provided is ideal for quickly testing API changes in Ironic or +features for client libraries. It is not the best choice for changes that +interact with one or more OpenStack services or which require tempest testing. diff --git a/doc/source/contributor/dev-quickstart.rst b/doc/source/contributor/dev-quickstart.rst index 6f63104f98..762f249cee 100644 --- a/doc/source/contributor/dev-quickstart.rst +++ b/doc/source/contributor/dev-quickstart.rst @@ -6,37 +6,71 @@ Developer Quick-Start This is a quick walkthrough to get you started developing code for Ironic. This assumes you are already familiar with submitting code reviews to -an OpenStack project. +an OpenStack project. If you are not, please begin by following the steps +in the +`OpenDev infra manual `_ +to get yourself familiar with the general git workflow we use. -The gate currently runs the unit tests under Python 3.6, 3.7, and 3.8. It -is strongly encouraged to run the unit tests locally prior to submitting a -patch. +This guide is primarily technical in nature; for information on how the Ironic +team organizes work, please see `Ironic's contribution guide `_. + +This document covers both :ref:`unit` and :ref:`integrated`. New contributors +are recommended to start with unit tests. + +.. _integrated: + +Integrated Testing Environments +------------------------------- +The ultimate in development environments for Ironic is a working system, with +mock bare metal hardware and a fully functional API service. There are three +ways to get environment, listed below. .. note:: - Do not run unit tests on the same environment as devstack due to - conflicting configuration with system dependencies. + These environments may use automation that assume you are running on a VM. + Please do not use these environments on a system that you are not willing to + have wiped and reinstalled when complete. -.. note:: - This document is compatible with Python (3.6, 3.7, 3.8), Debian - "buster" (10.8), Ubuntu Focal Fossa (20.04 LTS), RHEL8/CentOS Stream, - openSUSE/SLE 15, and Fedora (33). - When referring to different versions of Python and OS distributions, this - is explicitly stated. +.. list-table:: Testing Environments + :widths: 15, 70, 15 -.. seealso:: + * - Environment + - Description/Uses + - How-To + * - Devstack + - Useful for testing Ironic with other OpenStack services. Also the + environment required for running or building Ironic's tempest tests. + Recommended for new contributors. + - :doc:`devstack-guide` + * - Bifrost + - Used for testing Ironic standalone with minimal setup or using real + hardware, or testing bifrost changes directly. + - :doc:`bifrost-dev-guide` + * - Local + - Ironic services running locally, without any other OpenStack services. + This can be useful for rapid prototyping, debugging, or testing database + migrations. + - :doc:`local-dev-guide` - https://docs.openstack.org/infra/manual/developers.html#development-workflow +.. _unit: -Prepare Development System -========================== +Unit Testing Environment +------------------------ +For most people, unit testing is the quickest and easiest way to check +the validity of a change. Unlike a fully integrated testing environment, +unit tests can generally be safely run on a developer's workstation. + +Ironic uses `tox `_ to orchestrate unit +tests and documentation building. Contributors are strongly encouraged to +validate code passes unit tests under a supported version of python before +pushing up a change. See the +`Project Testing Interface `_ +for the exact versions of python supported currently. System Prerequisites --------------------- +==================== The following packages cover the prerequisites for a local development -environment on most current distributions. Instructions for getting set up with -non-default versions of Python and on older distributions are included below as -well. +environment on most current distributions. - Ubuntu/Debian:: @@ -56,7 +90,7 @@ manage your locales, make sure you have enabled ``en_US.UTF8`` in ``/etc/locale.gen`` and rerun ``locale-gen``. Python Prerequisites --------------------- +==================== We suggest to use at least tox 3.9, if your distribution has an older version, you can install it using pip system-wise or better per user using the --user @@ -71,41 +105,63 @@ You may need to explicitly upgrade virtualenv if you've installed the one from your OS distribution and it is too old (tox will complain). You can upgrade it individually, if you need to:: - pip install -U virtualenv --user + pip install --upgrade virtualenv --user Running Unit Tests Locally ========================== If you haven't already, Ironic source code should be pulled directly from git:: - # from your home or source directory - cd ~ + # from a user-writable directory, usually $HOME or $HOME/dev git clone https://opendev.org/openstack/ironic cd ironic -Running Unit and Style Tests ----------------------------- -All unit tests should be run using tox. To run Ironic's entire test suite:: +Most of the time, you will want to run unit tests and pep8 checks. This can be +done with the following command:: - # to run the py3 unit tests, and the style tests - tox + tox -e pep8,py3 -To run a specific test or tests, use the "-e" option followed by the tox target -name. For example:: +Ironic has multiple test environments that can be run by tox. An incomplete +list of environments and what they do is below. Please reference the ``tox.ini`` +file in the project you're working on for a complete, up-to-date list. - # run the unit tests under py36 and also run the pep8 tests - tox -epy36 -epep8 +.. list-table:: Tox Environments + :widths: 20, 80 -You may pass options to the test programs using positional arguments. + * - Environment + - Description + * - pep8 + - Run style checks on code, documentation, and release notes. + * - py + - Run unit tests with the specified python version. For example, ``py310`` will run the unit tests with python 3.10. + * - unit-with-driver-libs + - Run unit tests with the default python3 on the system, but also includes driver-specific libraries and the tests they enable. + * - mysql-migrations + - Run MySQL database migration unit tests. Setup database first using ``tools/test-setup.sh`` in Ironic repo. + * - docs + - Build and validate documentation. + * - releasenotes + - Build and validate release notes using ``reno``. + * - api-ref + - Build and validate API reference documentation. + * - genconfig + - Generates example configuration file. + * - genpolicy + - Generates example policy configuration file. + * - venv + - Creates a venv, with dependencies installed, for running commands in e.g. ``tox -evenv -- reno new my-release-note`` + + +You may also pass options to the test programs using positional arguments. To run a specific unit test, this passes the desired test (regex string) to `stestr `_:: - # run a specific test for Python 3.6 - tox -epy36 -- test_conductor + # run a specific test for Python 3.10 + tox -epy310 -- test_conductor Debugging unit tests --------------------- +==================== In order to break into the debugger from a unit test we need to insert a breaking point to the code: @@ -124,703 +180,15 @@ Then run ``tox`` with the debug environment as one of the following:: For more information see the :oslotest-doc:`oslotest documentation `. -Database Setup --------------- -The unit tests need a local database setup, you can use -``tools/test-setup.sh`` to set up the database the same way as setup -in the OpenStack test systems. - -.. note:: - If you encounter issues executing unit tests, specifically where errors - may indicate that a field is too long, check your database's default - character encoding. Debian specifically sets MariaDB to ``utf8mb4`` - which utilizes 4 byte encoded unicode characters by default, which is - incompatible by default. - -Additional Tox Targets ----------------------- - -There are several additional tox targets not included in the default list, such -as the target which builds the documentation site. See the ``tox.ini`` file -for a complete listing of tox targets. These can be run directly by specifying -the target name:: - - # generate the documentation pages locally - tox -edocs - - # generate the sample configuration file - tox -egenconfig - - -Exercising the Services Locally -=============================== - -In addition to running automated tests, sometimes it can be helpful to actually -run the services locally, without needing a server in a remote datacenter. - -If you would like to exercise the Ironic services in isolation within your local -environment, you can do this without starting any other OpenStack services. For -example, this is useful for rapidly prototyping and debugging interactions over -the RPC channel, testing database migrations, and so forth. - -Here we describe two ways to install and configure the dependencies, either run -directly on your local machine or encapsulated in a virtual machine or -container. - -Step 1: Create a Python virtualenv ----------------------------------- - -#. If you haven't already downloaded the source code, do that first:: - - cd ~ - git clone https://opendev.org/openstack/ironic - cd ironic - -#. Create the Python virtualenv:: - - tox -evenv --notest --develop -r - -#. Activate the virtual environment:: - - . .tox/venv/bin/activate - -#. Install the `openstack` client command utility:: - - pip install python-openstackclient - - -#. Install the `baremetal` client:: - - pip install python-ironicclient - - .. note:: You can install python-ironicclient from source by cloning the git - repository and running `pip install .` while in the root of the - cloned repository. - -#. Export some ENV vars so the client will connect to the local services - that you'll start in the next section:: - - export OS_AUTH_TYPE=none - export OS_ENDPOINT=http://localhost:6385/ - -Next, install and configure system dependencies. - -Step 2: Install System Dependencies Locally --------------------------------------------- - -This step will install MySQL on your local system. This may not be desirable -in some situations (eg, you're developing from a laptop and do not want to run -a MySQL server on it all the time). If you want to use SQLite, skip it and do -not set the ``connection`` option. - -#. Install mysql-server: - - Ubuntu/Debian:: - - sudo apt-get install mysql-server - - RHEL/CentOS/Fedora:: - - sudo dnf install mariadb mariadb-server - sudo systemctl start mariadb.service - - openSUSE/SLE:: - sudo zypper install mariadb - sudo systemctl start mysql.service - - If using MySQL, you need to create the initial database:: - - mysql -u root -pMYSQL_ROOT_PWD -e "create schema ironic" - - .. note:: if you choose not to install mysql-server, ironic will default to - using a local sqlite database. The database will then be stored in - ``ironic/ironic.sqlite``. - - -#. Create a configuration file within the ironic source directory:: - - # generate a sample config - tox -egenconfig - - # copy sample config and modify it as necessary - cp etc/ironic/ironic.conf.sample etc/ironic/ironic.conf.local - - # disable auth since we are not running keystone here - sed -i "s/#auth_strategy = keystone/auth_strategy = noauth/" etc/ironic/ironic.conf.local - - # use the 'fake-hardware' test hardware type - sed -i "s/#enabled_hardware_types = .*/enabled_hardware_types = fake-hardware/" etc/ironic/ironic.conf.local - - # use the 'fake' deploy and boot interfaces - sed -i "s/#enabled_deploy_interfaces = .*/enabled_deploy_interfaces = fake/" etc/ironic/ironic.conf.local - sed -i "s/#enabled_boot_interfaces = .*/enabled_boot_interfaces = fake/" etc/ironic/ironic.conf.local - - # enable both fake and ipmitool management and power interfaces - sed -i "s/#enabled_management_interfaces = .*/enabled_management_interfaces = fake,ipmitool/" etc/ironic/ironic.conf.local - sed -i "s/#enabled_power_interfaces = .*/enabled_power_interfaces = fake,ipmitool/" etc/ironic/ironic.conf.local - - # change the periodic sync_power_state_interval to a week, to avoid getting NodeLocked exceptions - sed -i "s/#sync_power_state_interval = 60/sync_power_state_interval = 604800/" etc/ironic/ironic.conf.local - - # if you opted to install mysql-server, switch the DB connection from sqlite to mysql - sed -i "s/#connection = .*/connection = mysql\+pymysql:\/\/root:MYSQL_ROOT_PWD@localhost\/ironic/" etc/ironic/ironic.conf.local - - # use JSON RPC to avoid installing rabbitmq locally - sed -i "s/#rpc_transport = oslo/rpc_transport = json-rpc/" etc/ironic/ironic.conf.local - -Step 3: Start the Services --------------------------- - -From within the python virtualenv, run the following command to prepare the -database before you start the ironic services:: - - # initialize the database for ironic - ironic-dbsync --config-file etc/ironic/ironic.conf.local create_schema - -Next, open two new terminals for this section, and run each of the examples -here in a separate terminal. In this way, the services will *not* be run as -daemons; you can observe their output and stop them with Ctrl-C at any time. - -#. Start the API service in debug mode and watch its output:: - - cd ~/ironic - . .tox/venv/bin/activate - ironic-api -d --config-file etc/ironic/ironic.conf.local - -#. Start the Conductor service in debug mode and watch its output:: - - cd ~/ironic - . .tox/venv/bin/activate - ironic-conductor -d --config-file etc/ironic/ironic.conf.local - -Step 4: Interact with the running services ------------------------------------------- - -You should now be able to interact with ironic via the python client, which is -present in the python virtualenv, and observe both services' debug outputs in -the other two windows. This is a good way to test new features or play with the -functionality without necessarily starting DevStack. - -To get started, export the following variables to point the client at the -local instance of ironic and disable the authentication:: - - export OS_AUTH_TYPE=none - export OS_ENDPOINT=http://127.0.0.1:6385 - -Then list the available commands and resources:: - - # get a list of available commands - openstack help baremetal - - # get the list of drivers currently supported by the available conductor(s) - baremetal driver list - - # get a list of nodes (should be empty at this point) - baremetal node list - -Here is an example walkthrough of creating a node:: - - MAC="aa:bb:cc:dd:ee:ff" # replace with the MAC of a data port on your node - IPMI_ADDR="1.2.3.4" # replace with a real IP of the node BMC - IPMI_USER="admin" # replace with the BMC's user name - IPMI_PASS="pass" # replace with the BMC's password - - # enroll the node with the fake hardware type and IPMI-based power and - # management interfaces. Note that driver info may be added at node - # creation time with "--driver-info" - NODE=$(baremetal node create \ - --driver fake-hardware \ - --management-interface ipmitool \ - --power-interface ipmitool \ - --driver-info ipmi_address=$IPMI_ADDR \ - --driver-info ipmi_username=$IPMI_USER \ - -f value -c uuid) - - # driver info may also be added or updated later on - baremetal node set $NODE --driver-info ipmi_password=$IPMI_PASS - - # add a network port - baremetal port create $MAC --node $NODE - - # view the information for the node - baremetal node show $NODE - - # request that the node's driver validate the supplied information - baremetal node validate $NODE - - # you have now enrolled a node sufficiently to be able to control - # its power state from ironic! - baremetal node power on $NODE - -If you make some code changes and want to test their effects, simply stop the -services with Ctrl-C and restart them. - -Step 5: Fixing your test environment ------------------------------------- - -If you are testing changes that add or remove python entrypoints, or making -significant changes to ironic's python modules, or simply keep the virtualenv -around for a long time, your development environment may reach an inconsistent -state. It may help to delete cached ".pyc" files, update dependencies, -reinstall ironic, or even recreate the virtualenv. The following commands may -help with that, but are not an exhaustive troubleshooting guide:: - - # clear cached pyc files - cd ~/ironic/ironic - find ./ -name '*.pyc' | xargs rm - - # reinstall ironic modules - cd ~/ironic - . .tox/venv/bin/activate - pip uninstall ironic - pip install -e . - - # install and upgrade ironic and all python dependencies - cd ~/ironic - . .tox/venv/bin/activate - pip install -U -e . - - -.. _`deploy_devstack`: - -Deploying Ironic with DevStack -============================== - -DevStack may be configured to deploy Ironic, setup Nova to use the Ironic -driver and provide hardware resources (network, baremetal compute nodes) -using a combination of OpenVSwitch and libvirt. It is highly recommended -to deploy on an expendable virtual machine and not on your personal work -station. Deploying Ironic with DevStack requires a machine running Ubuntu -16.04 (or later) or Fedora 24 (or later). Make sure your machine is fully -up to date and has the latest packages installed before beginning this process. - -The ironic-tempest-plugin is necessary if you want to run integration tests, -the section `Ironic with ironic-tempest-plugin`_ tells the extra steps you need -to enable it in DevStack. - -.. seealso:: - - https://docs.openstack.org/devstack/latest/ - -.. note:: - The devstack "demo" tenant is now granted the "baremetal_observer" role - and thereby has read-only access to ironic's API. This is sufficient for - all the examples below. Should you want to create or modify bare metal - resources directly (ie. through ironic rather than through nova) you will - need to use the devstack "admin" tenant. - - -Devstack will no longer create the user 'stack' with the desired -permissions, but does provide a script to perform the task:: - - git clone https://opendev.org/openstack/devstack.git devstack - sudo ./devstack/tools/create-stack-user.sh - -.. note:: - In case you receive an error "Could not determine host ip address. - See local.conf for suggestions on setting HOST_IP", you need to manually - add the main ip of your machine to the localrc file under devstack/ using - the HOST_IP variable, e.g. HOST_IP=YOURIP - This could happen when running devstack on virtual machines. - -Switch to the stack user and clone DevStack:: - - sudo su - stack - git clone https://opendev.org/openstack/devstack.git devstack - - -Ironic ------- - -Create devstack/local.conf with minimal settings required to enable Ironic. -An example local.conf that enables the ``direct`` -:doc:`deploy interface ` and uses the ``ipmi`` -hardware type by default:: - - cd devstack - cat >local.conf <` and uses the ``ipmi`` hardware type by default:: - - cd devstack - cat >local.conf <`_ to control the power state of - the virtual baremetal nodes. - -.. note:: - When running QEMU as non-root user (e.g. ``qemu`` on Fedora or ``libvirt-qemu`` on Ubuntu), - make sure ``IRONIC_VM_LOG_DIR`` points to a directory where QEMU will be able to write. - You can verify this with, for example:: - - # on Fedora - sudo -u qemu touch $HOME/ironic-bm-logs/test.log - # on Ubuntu - sudo -u libvirt-qemu touch $HOME/ironic-bm-logs/test.log - -.. note:: - To check out an in-progress patch for testing, you can add a Git ref to the ``enable_plugin`` line. For instance:: - - enable_plugin ironic https://opendev.org/openstack/ironic refs/changes/46/295946/15 - - For a patch in review, you can find the ref to use by clicking the - "Download" button in Gerrit. You can also specify a different git repo, or - a branch or tag:: - - enable_plugin ironic https://github.com/openstack/ironic stable/kilo - - For more details, see the - `devstack plugin interface documentation - `_. - -Run stack.sh:: - - ./stack.sh - -Source credentials, create a key, and spawn an instance as the ``demo`` user:: - - . ~/devstack/openrc - - # query the image id of the default cirros image - image=$(openstack image show $DEFAULT_IMAGE_NAME -f value -c id) - - # create keypair - ssh-keygen - openstack keypair create --public-key ~/.ssh/id_rsa.pub default - - # spawn instance - openstack server create --flavor baremetal --image $image --key-name default testing - -.. note:: - Because devstack create multiple networks, we need to pass an additional parameter - ``--nic net-id`` to the nova boot command when using the admin account, for example:: - - net_id=$(openstack network list | egrep "$PRIVATE_NETWORK_NAME"'[^-]' | awk '{ print $2 }') - - openstack server create --flavor baremetal --nic net-id=$net_id --image $image --key-name default testing - -You should now see a Nova instance building:: - - openstack server list --long - +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ - | ID | Name | Status | Task State | Power State | Networks | Image Name | Image ID | Availability Zone | Host | Properties | - +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ - | a2c7f812 | testing | BUILD | spawning | NOSTATE | | cirros-0.3 | 44d4092a | nova | | | - | -e386-4a | | | | | | .5-x86_64- | -51ac-47 | | | | - | 22-b393- | | | | | | disk | 51-9c50- | | | | - | fe1802ab | | | | | | | fd6e2050 | | | | - | d56e | | | | | | | faa1 | | | | - +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ - -Nova will be interfacing with Ironic conductor to spawn the node. On the -Ironic side, you should see an Ironic node associated with this Nova instance. -It should be powered on and in a 'wait call-back' provisioning state:: - - baremetal node list - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - | UUID | Name | Instance UUID | Power State | Provisioning State | Maintenance | - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - | 9e592cbe-e492-4e4f-bf8f-4c9e0ad1868f | node-0 | None | power off | None | False | - | ec0c6384-cc3a-4edf-b7db-abde1998be96 | node-1 | None | power off | None | False | - | 4099e31c-576c-48f8-b460-75e1b14e497f | node-2 | a2c7f812-e386-4a22-b393-fe1802abd56e | power on | wait call-back | False | - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - -At this point, Ironic conductor has called to libvirt (via virtualbmc) to -power on a virtual machine, which will PXE + TFTP boot from the conductor node and -progress through the Ironic provisioning workflow. One libvirt domain should -be active now:: - - sudo virsh list --all - Id Name State - ---------------------------------------------------- - 2 node-2 running - - node-0 shut off - - node-1 shut off - -This provisioning process may take some time depending on the performance of -the host system, but Ironic should eventually show the node as having an -'active' provisioning state:: - - baremetal node list - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - | UUID | Name | Instance UUID | Power State | Provisioning State | Maintenance | - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - | 9e592cbe-e492-4e4f-bf8f-4c9e0ad1868f | node-0 | None | power off | None | False | - | ec0c6384-cc3a-4edf-b7db-abde1998be96 | node-1 | None | power off | None | False | - | 4099e31c-576c-48f8-b460-75e1b14e497f | node-2 | a2c7f812-e386-4a22-b393-fe1802abd56e | power on | active | False | - +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ - -This should also be reflected in the Nova instance state, which at this point -should be ACTIVE, Running and an associated private IP:: - - openstack server list --long - +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ - | ID | Name | Status | Task State | Power State | Networks | Image Name | Image ID | Availability Zone | Host | Properties | - +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ - | a2c7f812 | testing | ACTIVE | none | Running | private=10.1. | cirros-0.3 | 44d4092a | nova | | | - | -e386-4a | | | | | 0.4, fd7d:1f3 | .5-x86_64- | -51ac-47 | | | | - | 22-b393- | | | | | c:4bf1:0:f816 | disk | 51-9c50- | | | | - | fe1802ab | | | | | :3eff:f39d:6d | | fd6e2050 | | | | - | d56e | | | | | 94 | | faa1 | | | | - +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ - -The server should now be accessible via SSH:: - - ssh cirros@10.1.0.4 - $ - -Running Tempest tests -===================== - -After :ref:`Deploying Ironic with DevStack ` with the -ironic-tempest-plugin enabled, one might want to run integration -tests against the running cloud. The Tempest project is the project -that offers an integration test suite for OpenStack. - -First, navigate to Tempest directory:: - - cd /opt/stack/tempest - -To run all tests from the `Ironic plugin -`_, -execute the following command:: - - tox -e all -- ironic - -To limit the amount of tests that you would like to run, you can use -a regex. For instance, to limit the run to a single test file, the -following command can be used:: - - tox -e all -- ironic_tempest_plugin.tests.scenario.test_baremetal_basic_ops - - -Debugging Tempest tests ------------------------ - -It is sometimes useful to step through the test code, line by line, -especially when the error output is vague. This can be done by -running the tests in debug mode and using a debugger such as `pdb -`_. - -For example, after editing the *test_baremetal_basic_ops* file and -setting up the pdb traces you can invoke the ``run_tempest.sh`` script -in the Tempest directory with the following parameters:: - - ./run_tempest.sh -N -d ironic_tempest_plugin.tests.scenario.test_baremetal_basic_ops - -* The *-N* parameter tells the script to run the tests in the local - environment (without a virtualenv) so it can find the Ironic tempest - plugin. - -* The *-d* parameter enables the debug mode, allowing it to be used - with pdb. - -For more information about the supported parameters see:: - - ./run_tempest.sh --help - -.. note:: - Always be careful when running debuggers in time sensitive code, - they may cause timeout errors that weren't there before. +Other tests +=========== +Ironic also has a number of tests built with Tempest. For more information +about writing or running those tests, see :ref:`tempest`. OSProfiler Tracing in Ironic -============================ +---------------------------- OSProfiler is an OpenStack cross-project profiling library. It is being used among OpenStack projects to look at performance issues and detect @@ -829,32 +197,28 @@ please refer to `OSProfiler Support Documentation `_. Building developer documentation -================================ +-------------------------------- If you would like to build the documentation locally, eg. to test your documentation changes before uploading them for review, run these commands to build the documentation set: -- On your local machine:: +- On the machine with the ironic checkout:: - # activate your development virtualenv - . .tox/venv/bin/activate + # change into the ironic source code directory + cd ~/ironic # build the docs tox -edocs - #Now use your browser to open the top-level index.html located at: +To view the built documentation locally, open up the top level index.html in +your browser. For an example user named ``bob`` with the Ironic checkout in +their homedir, the URL to put in the browser would be:: - ironic/doc/build/html/index.html + file:///home/bob/ironic/doc/build/html/index.html - -- On a remote machine:: - - # Go to the directory that contains the docs - cd ~/ironic/doc/source/ - - # Build the docs - tox -edocs +If you're building docs on a remote VM, you can use python's SimpleHTTPServer +to setup a quick webserver to check your docs build:: # Change directory to the newly built HTML files cd ~/ironic/doc/build/html/ @@ -862,6 +226,5 @@ commands to build the documentation set: # Create a server using python on port 8000 python -m SimpleHTTPServer 8000 - #Now use your browser to open the top-level index.html located at: - - http://your_ip:8000 + # Now use your browser to open the top-level index.html located at: + http://remote_ip:8000 diff --git a/doc/source/contributor/devstack-guide.rst b/doc/source/contributor/devstack-guide.rst new file mode 100644 index 0000000000..f94e2e7a78 --- /dev/null +++ b/doc/source/contributor/devstack-guide.rst @@ -0,0 +1,474 @@ +.. _`deploy_devstack`: + +============================== +Deploying Ironic with DevStack +============================== + +DevStack may be configured to deploy Ironic, setup Nova to use the Ironic +driver and provide hardware resources (network, baremetal compute nodes) +using a combination of OpenVSwitch and libvirt. It is highly recommended +to deploy on an expendable virtual machine and not on your personal work +station. + +.. seealso:: + + https://docs.openstack.org/devstack/latest/ + +.. note:: + The devstack "demo" tenant has read-only access to Ironic's API. This is + sufficient for all the examples below. Should you want to create or modify + bare metal resources directly (ie. through Ironic rather than through Nova) + you will need to use the devstack "admin" tenant. + +Basic process +============= + +Create a stack user with proper permissions using script from devstack:: + + git clone https://opendev.org/openstack/devstack.git devstack + sudo ./devstack/tools/create-stack-user.sh + + +Switch to the stack user and clone DevStack:: + + sudo su - stack + git clone https://opendev.org/openstack/devstack.git devstack + + +From the :ref:`Configurations` section below, create a ``local.conf`` file. + +Once you have the configuration in place and ready to go, you can deploy +devstack with:: + + ./stack.sh + + +.. note:: + Devstack configurations change frequently. If you are having trouble getting + one of the below configs to work, please file a bug against Ironic or ask on + #openstack-ironic in OFTC. + +.. _configurations: + +Configurations +============== + +Ironic +------ + +Create devstack/local.conf with minimal settings required to enable Ironic. +This does not configure Nova to operate with Ironic. + +An example local.conf that enables the ``direct`` +:doc:`deploy interface ` and uses the ``ipmi`` +hardware type by default:: + + cd devstack + cat >local.conf <` +enabled and use the ``ipmi`` hardware type with this config:: + + cd devstack + cat >local.conf <` +* :ref:`Ironic w/Multitenant Networking ` + +Deploying to Ironic node using Nova +=================================== + +This section assumes you already have a working, deployed Ironic with Nova +configured as laid out above. + +Source credentials, create a key, and spawn an instance as the ``demo`` user:: + + . ~/devstack/openrc + + # query the image id of the default cirros image + image=$(openstack image show $DEFAULT_IMAGE_NAME -f value -c id) + + # create keypair + ssh-keygen + openstack keypair create --public-key ~/.ssh/id_rsa.pub default + + # spawn instance + openstack server create --flavor baremetal --image $image --key-name default testing + +.. note:: + Because devstack create multiple networks, we need to pass an additional parameter + ``--nic net-id`` to the nova boot command when using the admin account, for example:: + + net_id=$(openstack network list | egrep "$PRIVATE_NETWORK_NAME"'[^-]' | awk '{ print $2 }') + + openstack server create --flavor baremetal --nic net-id=$net_id --image $image --key-name default testing + +You should now see a Nova instance building:: + + openstack server list --long + +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ + | ID | Name | Status | Task State | Power State | Networks | Image Name | Image ID | Availability Zone | Host | Properties | + +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ + | a2c7f812 | testing | BUILD | spawning | NOSTATE | | cirros-0.3 | 44d4092a | nova | | | + | -e386-4a | | | | | | .5-x86_64- | -51ac-47 | | | | + | 22-b393- | | | | | | disk | 51-9c50- | | | | + | fe1802ab | | | | | | | fd6e2050 | | | | + | d56e | | | | | | | faa1 | | | | + +----------+---------+--------+------------+-------------+----------+------------+----------+-------------------+------+------------+ + +Nova will be interfacing with Ironic conductor to spawn the node. On the +Ironic side, you should see an Ironic node associated with this Nova instance. +It should be powered on and in a 'wait call-back' provisioning state:: + + baremetal node list + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + | UUID | Name | Instance UUID | Power State | Provisioning State | Maintenance | + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + | 9e592cbe-e492-4e4f-bf8f-4c9e0ad1868f | node-0 | None | power off | None | False | + | ec0c6384-cc3a-4edf-b7db-abde1998be96 | node-1 | None | power off | None | False | + | 4099e31c-576c-48f8-b460-75e1b14e497f | node-2 | a2c7f812-e386-4a22-b393-fe1802abd56e | power on | wait call-back | False | + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + +At this point, Ironic conductor has called to libvirt (via virtualbmc) to +power on a virtual machine, which will PXE + TFTP boot from the conductor node and +progress through the Ironic provisioning workflow. One libvirt domain should +be active now:: + + sudo virsh list --all + Id Name State + ---------------------------------------------------- + 2 node-2 running + - node-0 shut off + - node-1 shut off + +This provisioning process may take some time depending on the performance of +the host system, but Ironic should eventually show the node as having an +'active' provisioning state:: + + baremetal node list + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + | UUID | Name | Instance UUID | Power State | Provisioning State | Maintenance | + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + | 9e592cbe-e492-4e4f-bf8f-4c9e0ad1868f | node-0 | None | power off | None | False | + | ec0c6384-cc3a-4edf-b7db-abde1998be96 | node-1 | None | power off | None | False | + | 4099e31c-576c-48f8-b460-75e1b14e497f | node-2 | a2c7f812-e386-4a22-b393-fe1802abd56e | power on | active | False | + +--------------------------------------+--------+--------------------------------------+-------------+--------------------+-------------+ + +This should also be reflected in the Nova instance state, which at this point +should be ACTIVE, Running and an associated private IP:: + + openstack server list --long + +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ + | ID | Name | Status | Task State | Power State | Networks | Image Name | Image ID | Availability Zone | Host | Properties | + +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ + | a2c7f812 | testing | ACTIVE | none | Running | private=10.1. | cirros-0.3 | 44d4092a | nova | | | + | -e386-4a | | | | | 0.4, fd7d:1f3 | .5-x86_64- | -51ac-47 | | | | + | 22-b393- | | | | | c:4bf1:0:f816 | disk | 51-9c50- | | | | + | fe1802ab | | | | | :3eff:f39d:6d | | fd6e2050 | | | | + | d56e | | | | | 94 | | faa1 | | | | + +----------+---------+--------+------------+-------------+---------------+------------+----------+-------------------+------+------------+ + +The server should now be accessible via SSH:: + + ssh cirros@10.1.0.4 + $ + +Testing Ironic with Tempest +=========================== + +.. _tempest: + +Add Ironic Tempest Plugin +------------------------- + +Using the stack user, clone the ironic-tempest-plugin repository in the same +directory you cloned DevStack:: + + git clone https://opendev.org/openstack/ironic-tempest-plugin.git + +Then, add the following configuration to a working Ironic with Nova +devstack configuration:: + + TEMPEST_PLUGINS=/opt/stack/ironic-tempest-plugin + +Running tests +------------- +.. note:: + Some tests may be skipped depending on the configuration of your + environment, they may be reliant on a driver or a capability that you + did not configure. + +After deploying devstack including Ironic with the +ironic-tempest-plugin enabled, one might want to run integration +tests against the running cloud. The Tempest project is the project +that offers an integration test suite for OpenStack. + +First, navigate to Tempest directory:: + + cd /opt/stack/tempest + +To run all tests from the `Ironic plugin +`_, +execute the following command:: + + tox -e all -- ironic + +To limit the amount of tests that you would like to run, you can use +a regex. For instance, to limit the run to a single test file, the +following command can be used:: + + tox -e all -- ironic_tempest_plugin.tests.scenario.test_baremetal_basic_ops + + +Debugging tests +--------------- + +It is sometimes useful to step through the test code, line by line, +especially when the error output is vague. This can be done by +running the tests in debug mode and using a debugger such as `pdb +`_. + +For example, after editing the *test_baremetal_basic_ops* file and +setting up the pdb traces you can invoke the ``run_tempest.sh`` script +in the Tempest directory with the following parameters:: + + ./run_tempest.sh -N -d ironic_tempest_plugin.tests.scenario.test_baremetal_basic_ops + +* The *-N* parameter tells the script to run the tests in the local + environment (without a virtualenv) so it can find the Ironic tempest + plugin. + +* The *-d* parameter enables the debug mode, allowing it to be used + with pdb. + +For more information about the supported parameters see:: + + ./run_tempest.sh --help + +.. note:: + Always be careful when running debuggers in time sensitive code, + they may cause timeout errors that weren't there before. + + +FAQ/Tips for development using devstack +======================================= + +VM logs are missing +------------------- +When running QEMU as non-root user (e.g. ``qemu`` on Fedora or ``libvirt-qemu`` on Ubuntu), +make sure ``IRONIC_VM_LOG_DIR`` points to a directory where QEMU will be able to write. +You can verify this with, for example:: + + # on Fedora + sudo -u qemu touch $HOME/ironic-bm-logs/test.log + # on Ubuntu + sudo -u libvirt-qemu touch $HOME/ironic-bm-logs/test.log + +Downloading an unmerged patch when stacking +------------------------------------------- +To check out an in-progress patch for testing, you can add a Git ref to the +``enable_plugin`` line. For instance:: + + enable_plugin ironic https://opendev.org/openstack/ironic refs/changes/46/295946/15 + +For a patch in review, you can find the ref to use by clicking the +"Download" button in Gerrit. You can also specify a different git repo, or +a branch or tag:: + + enable_plugin ironic https://github.com/openstack/ironic stable/kilo + +For more details, see the +`devstack plugin interface documentation +`_. diff --git a/doc/source/contributor/index.rst b/doc/source/contributor/index.rst index 4221bf751d..4e41642180 100644 --- a/doc/source/contributor/index.rst +++ b/doc/source/contributor/index.rst @@ -47,6 +47,9 @@ reviewers. :hidden: states + bifrost-dev-guide + local-dev-guide + devstack-guide Writing Drivers --------------- diff --git a/doc/source/contributor/ironic-boot-from-volume.rst b/doc/source/contributor/ironic-boot-from-volume.rst index 673a189be3..3291a7a1bb 100644 --- a/doc/source/contributor/ironic-boot-from-volume.rst +++ b/doc/source/contributor/ironic-boot-from-volume.rst @@ -8,6 +8,8 @@ which has been supported from the Pike release. This scenario shows how to setup DevStack to enable nodes to boot from volumes managed by cinder with VMs as baremetal servers. +.. _BFVDevstack: + DevStack Configuration ====================== diff --git a/doc/source/contributor/ironic-multitenant-networking.rst b/doc/source/contributor/ironic-multitenant-networking.rst index 5b4b1db285..7cfc6a3cf5 100644 --- a/doc/source/contributor/ironic-multitenant-networking.rst +++ b/doc/source/contributor/ironic-multitenant-networking.rst @@ -13,6 +13,7 @@ This scenario shows how to setup Devstack to use Ironic/Neutron integration with VMs as baremetal servers and ML2 ``networking-generic-switch`` that interacts with OVS. +.. _DevstackMTNetwork: DevStack Configuration ---------------------- diff --git a/doc/source/contributor/local-dev-guide.rst b/doc/source/contributor/local-dev-guide.rst new file mode 100644 index 0000000000..615da4c464 --- /dev/null +++ b/doc/source/contributor/local-dev-guide.rst @@ -0,0 +1,228 @@ +Exercising Ironic Services Locally +================================== + +It can sometimes be helpful to run Ironic services locally, without needing a +full devstack environment or a server in a remote datacenter. + +If you would like to exercise the Ironic services in isolation within your local +environment, you can do this without starting any other OpenStack services. For +example, this is useful for rapidly prototyping and debugging interactions over +the RPC channel, testing database migrations, and so forth. + +Here we describe two ways to install and configure the dependencies, either run +directly on your local machine or encapsulated in a virtual machine or +container. + +Step 1: Create a Python virtualenv +---------------------------------- + +#. If you haven't already downloaded the source code, do that first:: + + cd ~ + git clone https://opendev.org/openstack/ironic + cd ironic + +#. Create the Python virtualenv:: + + tox -evenv --notest --develop -r + +#. Activate the virtual environment:: + + . .tox/venv/bin/activate + +#. Install the `openstack` client command utility:: + + pip install python-openstackclient + + +#. Install the `baremetal` client:: + + pip install python-ironicclient + + .. note:: You can install python-ironicclient from source by cloning the git + repository and running `pip install .` while in the root of the + cloned repository. + +#. Export some ENV vars so the client will connect to the local services + that you'll start in the next section:: + + export OS_AUTH_TYPE=none + export OS_ENDPOINT=http://localhost:6385/ + +Next, install and configure system dependencies. + +Step 2: Install System Dependencies Locally +-------------------------------------------- + +This step will install MySQL on your local system. This may not be desirable +in some situations (eg, you're developing from a laptop and do not want to run +a MySQL server on it all the time). If you want to use SQLite, skip it and do +not set the ``connection`` option. + +#. Install mysql-server: + + Ubuntu/Debian:: + + sudo apt-get install mysql-server + + RHEL/CentOS/Fedora:: + + sudo dnf install mariadb mariadb-server + sudo systemctl start mariadb.service + + openSUSE/SLE:: + sudo zypper install mariadb + sudo systemctl start mysql.service + + If using MySQL, you need to create the initial database:: + + mysql -u root -pMYSQL_ROOT_PWD -e "create schema ironic" + + .. note:: if you choose not to install mysql-server, ironic will default to + using a local sqlite database. The database will then be stored in + ``ironic/ironic.sqlite``. + + +#. Create a configuration file within the ironic source directory:: + + # generate a sample config + tox -egenconfig + + # copy sample config and modify it as necessary + cp etc/ironic/ironic.conf.sample etc/ironic/ironic.conf.local + + # disable auth since we are not running keystone here + sed -i "s/#auth_strategy = keystone/auth_strategy = noauth/" etc/ironic/ironic.conf.local + + # use the 'fake-hardware' test hardware type + sed -i "s/#enabled_hardware_types = .*/enabled_hardware_types = fake-hardware/" etc/ironic/ironic.conf.local + + # use the 'fake' deploy and boot interfaces + sed -i "s/#enabled_deploy_interfaces = .*/enabled_deploy_interfaces = fake/" etc/ironic/ironic.conf.local + sed -i "s/#enabled_boot_interfaces = .*/enabled_boot_interfaces = fake/" etc/ironic/ironic.conf.local + + # enable both fake and ipmitool management and power interfaces + sed -i "s/#enabled_management_interfaces = .*/enabled_management_interfaces = fake,ipmitool/" etc/ironic/ironic.conf.local + sed -i "s/#enabled_power_interfaces = .*/enabled_power_interfaces = fake,ipmitool/" etc/ironic/ironic.conf.local + + # change the periodic sync_power_state_interval to a week, to avoid getting NodeLocked exceptions + sed -i "s/#sync_power_state_interval = 60/sync_power_state_interval = 604800/" etc/ironic/ironic.conf.local + + # if you opted to install mysql-server, switch the DB connection from sqlite to mysql + sed -i "s/#connection = .*/connection = mysql\+pymysql:\/\/root:MYSQL_ROOT_PWD@localhost\/ironic/" etc/ironic/ironic.conf.local + + # use JSON RPC to avoid installing rabbitmq locally + sed -i "s/#rpc_transport = oslo/rpc_transport = json-rpc/" etc/ironic/ironic.conf.local + +Step 3: Start the Services +-------------------------- + +From within the python virtualenv, run the following command to prepare the +database before you start the ironic services:: + + # initialize the database for ironic + ironic-dbsync --config-file etc/ironic/ironic.conf.local create_schema + +Next, open two new terminals for this section, and run each of the examples +here in a separate terminal. In this way, the services will *not* be run as +daemons; you can observe their output and stop them with Ctrl-C at any time. + +#. Start the API service in debug mode and watch its output:: + + cd ~/ironic + . .tox/venv/bin/activate + ironic-api -d --config-file etc/ironic/ironic.conf.local + +#. Start the Conductor service in debug mode and watch its output:: + + cd ~/ironic + . .tox/venv/bin/activate + ironic-conductor -d --config-file etc/ironic/ironic.conf.local + +Step 4: Interact with the running services +------------------------------------------ + +You should now be able to interact with ironic via the python client, which is +present in the python virtualenv, and observe both services' debug outputs in +the other two windows. This is a good way to test new features or play with the +functionality without necessarily starting DevStack. + +To get started, export the following variables to point the client at the +local instance of ironic and disable the authentication:: + + export OS_AUTH_TYPE=none + export OS_ENDPOINT=http://127.0.0.1:6385 + +Then list the available commands and resources:: + + # get a list of available commands + openstack help baremetal + + # get the list of drivers currently supported by the available conductor(s) + baremetal driver list + + # get a list of nodes (should be empty at this point) + baremetal node list + +Here is an example walkthrough of creating a node:: + + MAC="aa:bb:cc:dd:ee:ff" # replace with the MAC of a data port on your node + IPMI_ADDR="1.2.3.4" # replace with a real IP of the node BMC + IPMI_USER="admin" # replace with the BMC's user name + IPMI_PASS="pass" # replace with the BMC's password + + # enroll the node with the fake hardware type and IPMI-based power and + # management interfaces. Note that driver info may be added at node + # creation time with "--driver-info" + NODE=$(baremetal node create \ + --driver fake-hardware \ + --management-interface ipmitool \ + --power-interface ipmitool \ + --driver-info ipmi_address=$IPMI_ADDR \ + --driver-info ipmi_username=$IPMI_USER \ + -f value -c uuid) + + # driver info may also be added or updated later on + baremetal node set $NODE --driver-info ipmi_password=$IPMI_PASS + + # add a network port + baremetal port create $MAC --node $NODE + + # view the information for the node + baremetal node show $NODE + + # request that the node's driver validate the supplied information + baremetal node validate $NODE + + # you have now enrolled a node sufficiently to be able to control + # its power state from ironic! + baremetal node power on $NODE + +If you make some code changes and want to test their effects, simply stop the +services with Ctrl-C and restart them. + +Step 5: Fixing your test environment +------------------------------------ + +If you are testing changes that add or remove python entrypoints, or making +significant changes to ironic's python modules, or simply keep the virtualenv +around for a long time, your development environment may reach an inconsistent +state. It may help to delete cached ".pyc" files, update dependencies, +reinstall ironic, or even recreate the virtualenv. The following commands may +help with that, but are not an exhaustive troubleshooting guide:: + + # clear cached pyc files + cd ~/ironic/ironic + find ./ -name '*.pyc' | xargs rm + + # reinstall ironic modules + cd ~/ironic + . .tox/venv/bin/activate + pip uninstall ironic + pip install -e . + + # install and upgrade ironic and all python dependencies + cd ~/ironic + . .tox/venv/bin/activate + pip install -U -e . +