One day a while back, I started blabbing out loud about some quick ways to experiment with a live placement service and was (very appropriately) reminded that I make a ton of incorrect assumptions about the familiarity people have with things I do most days. Statements like "just spin up the wsgi script against uwsgi and a stubbed out placement.conf and see what happens" are a good example of me being bad.
So, to help, here are some instructions on how to spin up the wsgi script against uwsgi and a stubbed out placement.conf, in case you want to see what happens. The idea here is that you want to experiment with the current placement code, using a live database, but you're not concerned with other services, don't want to deal with devstack, but need a level of interaction with the code and process that something like placedock can't provide.
As ever, even all of the above has lots of assumptions about experience and context. This post assumes you are someone who either is an OpenStack (and probably placement) developer, or would like to be one.
To make this go you need a unix-like OS, with a python3 dev
environment, and git and mysql (or postgresql) installed. We'll be
doing this work from within a virtualenv, built from the
in the placement code.
At the time of writing, some required code is not yet merged into placement, so we'll be using a patch that is currently under review. I'll update this document when that code merges so we can skip a step.
Get The Code and Deps
The placement code lives at https://git.openstack.org/cgit/openstack/placement. We want to clone that:
git clone git://git.openstack.org/openstack/placement cd placement
Then we want to get the extra code mentioned above:
git pull https://git.openstack.org/openstack/placement refs/changes/61/600161/13
Setup The Database
That patch adds a commands to create tables in a database. We need to 1) create the database, 2) create a virtualenv to have the command, 3) use it to create the tables.
The database can have whatever name you like. Whatever you choose,
use it throughout this process. I choose
placement. You may need a
user and password to talk to your database, setting that up is out
of scope for this document. I'm using a machine that has had
devstack on it before so mysql is configured in what might be a
mysql -uroot -psecret -e "DROP DATABASE IF EXISTS placement;" mysql -uroot -psecret -e "CREATE DATABASE placement CHARACTER SET utf8;"
You may also need to set permissions:
mysql -uroot -psecret \ -e "GRANT ALL PRIVILEGES ON placement.* TO 'root'@'%' identified by 'secret';"
Get the table create command by updating the virtualenv:
tox -epy36 --notest
Create a bare minimum placement.conf in the
directory (which you may need to create):
[placement_database] connection = mysql+pymysql://root:firstname.lastname@example.org/placement?charset=utf8
(Note that when this command matures you will be able to name the location of the configuration file on the command line.)
Run the command to create the tables:
.tox/py36/bin/placement-manage db table_create
You can confirm the tables are there with
Run The Service
Now we want to run the service. We need to update
so it will produce debugging output and use the noauth strategy
for authentication (so we don't also have to run Keystone). Make
placement.conf look like this (adjusting for your database
[DEFAULT] debug = True [placement_database] connection = mysql+pymysql://root:email@example.com/placement?charset=utf8 [api] auth_strategy = noauth2
We need to install the uwsgi package into the virtualenv:
.tox/py36/bin/pip install uwsgi
And then use uwsgi to run the service. Start it with:
.tox/py36/bin/uwsgi --http :8000 --wsgi-file .tox/py36/bin/placement-api
If that worked you'll see lots of debug output and
worker 1. Test that things are working from another terminal with
curl -v http://localhost:8000/
Get a list of resource providers with (the
openstack-api-version is optional but makes sure
we are getting the latest functionality):
curl -H 'x-auth-token: admin' \ -H 'openstack-api-version: placement latest' \ http://localhost:8000/resource_providers
The result ought to look something like this:
If it doesn't then something went wrong with the above and there
should be more information in the terminal where
uwsgi is running.
From here you can experiment with creating resource providers and
related placement features. If you change the placement code,
ctrl-c to kill the uwsgi process and start it up again. For
testing, you might might enjoy
Here's a script to do the install for you: