Mimic is an API-compatible mock service for Openstack Compute and Rackspace's implementation of Identity and Cloud Load balancers. It is backed by in-memory data structure rather than a potentially expensive database.
Mimic helps with:
The fastest way to install and start Mimic is:
pip install mimic
twistd -n mimic
You can test the server started successfully by sending this request and checking for the welcome message:
curl http://localhost:8900
>> To get started with Mimic, POST an authentication request to:
>> /identity/v2.0/tokens
You can use the command below to test authentication and see your service catalog. The service catalog contains the endpoints for other available APIs.
curl -s -XPOST -d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"mimic","apiKey":"12345"}}}' http://localhost:8900/identity/v2.0/tokens | python -m json.tool
In order to use Mimic with most other projects you just need to override the Authentication Endpoint. In many projects, including the OpenStack Client CLI or the OpenStack Keystone client you can do that by setting the OS_AUTH_URL
environment variable or the --os-auth-url
option. For example:
keystone --os-username mimic --os-password 1235 --os-auth-url http://localhost:8900/identity/v2.0/ catalog
https://github.com/rackerlabs/mimic/blob/master/mimic/rest/nova_api.py
invalid_image_ref
returns 200. Else returns a 400.invalid_flavor_ref
returns 200. Else returns a 400.Based on the metadata (mimic_presets) provided when a server is being created, a server can be made to behave as follows:
Eg: Request for create server that remains in building for 120 seconds:
{ "server" : { "name" : "api-test-server-1", "imageRef" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001", "flavorRef" : "2", "metadata": {"server_building": 120} } }
https://github.com/rackerlabs/mimic/blob/master/mimic/rest/identity_api.py
https://github.com/rackerlabs/mimic/blob/master/mimic/rest/loadbalancer_api.py
Based on key and value of the metadata (mimic_presets) provided when a load balancer is being created, a load balancer can be made to behave as follows:
Eg: Request for create load balancer that is expected to go into 'PENDING-UPDATE' state on every add/delete node, for 20 seconds:
{"loadBalancer": {"name": "a-new-loadbalancer2", "protocol": "HTTP", "virtualIps": [{"type": "PUBLIC"}], "metadata": [{"key": "lb_pending_update", "value": 20}], "nodes": []}}
Fastly is one of the leading CDN providers with great API support. Fastly is also one of the CDN providers, supported by the Openstack Poppy project. Mimic supports all Fastly API calls needed by Openstack Poppy in its Fastly implementation. See below for the complete list.
https://github.com/rackerlabs/mimic/blob/master/mimic/rest/fastly_api.py
When any of Mimic's included plugins schedule a timeout, you will need to cause Mimic's internal clock to advance for any of those timeouts to fire.
You can do this with the tick
endpoint, like so:
curl -s -XPOST -d '{"amount": 1.0}' http://localhost:8900/mimic/v1.1/tick | python -m json.tool
which should result in output like this:
{
"advanced": 1.0,
"now": "1970-01-01T00:00:04.000000Z"
}
Note that Mimic begins its timekeeping when all time began, in 1970. If you would prefer to advance Mimic to something resembling the present day instead, a command like this right after Mimic starts up will do that:
curl -s -XPOST -d '{"amount": '"$(date +%s)"'}' http://localhost:8900/mimic/v1.1/tick | python -m json.tool
sudo apt-get install python-virtualenv
virtualenv my-mimic-install
. my-mimic-install/bin/activate
pip install mimic
twistd -n mimic
The repository root has a Dockerfile
that does what you want. It exposes Mimic on port 8900 by default.
To play around with Mimic locally, try:
docker build -t mimic . && docker run --restart=no --rm=true -p 8900:8900 mimic
This will expose Mimic on port 8900, so you can access it directly from the host. The default port exposure is intended for communication between containers; see the Docker documentation for more information. If you're using boot2docker
, run boot2docker ip
to find the right IP.