From 380b71066525d13bd30649079caae5ead63f63d1 Mon Sep 17 00:00:00 2001 From: Craig Vyvial Date: Fri, 16 Mar 2012 01:19:00 -0500 Subject: [PATCH] Fixing up the instance creation issues * update gitignore with log file from tests * update the tenant id on the client * change database to instance module * added some logging in the api calls * configuration of nova client values --- .gitignore | 1 + development/development_enviroment.sh | 4 --- development/instance_source.sh | 33 ++++++++++++++++++++ etc/reddwarf/reddwarf.conf.sample | 6 +++- reddwarf/db/sqlalchemy/session.py | 4 +-- reddwarf/{database => instance}/__init__.py | 0 reddwarf/{database => instance}/models.py | 12 ++++--- reddwarf/{database => instance}/service.py | 19 +++++++++-- reddwarf/{database => instance}/views.py | 0 reddwarf/tests/factories/models.py | 2 +- reddwarf/tests/unit/test_database_models.py | 5 +-- reddwarf/tests/unit/test_database_service.py | 5 +-- 12 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 development/instance_source.sh rename reddwarf/{database => instance}/__init__.py (100%) rename reddwarf/{database => instance}/models.py (94%) rename reddwarf/{database => instance}/service.py (88%) rename reddwarf/{database => instance}/views.py (100%) diff --git a/.gitignore b/.gitignore index c8744a4e9b..ef9a631192 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ reddwarf/vcsversion.py .coverage covhtml/ .DS_Store +host-syslog.log diff --git a/development/development_enviroment.sh b/development/development_enviroment.sh index cb08a98817..b0c39e2009 100644 --- a/development/development_enviroment.sh +++ b/development/development_enviroment.sh @@ -37,10 +37,6 @@ REDDWARF_TENANT=reddwarf echo $REDDWARF_TENANT REDDWARF_USER=$(mysql keystone -e "select id from user where name='reddwarf';" | awk 'NR==2') echo $REDDWARF_USER -REDDWARF_ROLE=$(mysql keystone -e "select id from role where name='reddwarf';" | awk 'NR==2') -echo $REDDWARF_ROLE - -# These all need to be set tenant did not work with the id but the name did match in the auth shim. REDDWARF_TOKEN=$(curl -d '{"auth":{"passwordCredentials":{"username": "reddwarf", "password": "REDDWARF-PASS"},"tenantName":"reddwarf"}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens | python -mjson.tool | grep id | tr -s ' ' | cut -d ' ' -f 3 | sed s/\"/''/g | awk 'NR==2' | cut -d ',' -f 1) echo $REDDWARF_TOKEN diff --git a/development/instance_source.sh b/development/instance_source.sh new file mode 100644 index 0000000000..2f0c2e39f7 --- /dev/null +++ b/development/instance_source.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +function reddwarf_auth { + REDDWARF_TENANT=`keystone --endpoint http://localhost:35357/v2.0 --token be19c524ddc92109a224 tenant-list| grep reddwarf | cut -d ' ' -f 2` + REDDWARF_USER=`keystone --endpoint http://localhost:35357/v2.0 --token be19c524ddc92109a224 user-list| grep reddwarf | cut -d ' ' -f 2` + REDDWARF_TOKEN=$(curl -d '{"auth":{"passwordCredentials":{"username": "reddwarf", "password": "REDDWARF-PASS"},"tenantName":"reddwarf"}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens | python -mjson.tool | grep id | tr -s ' ' | cut -d ' ' -f 3 | sed s/\"/''/g | awk 'NR==2' | cut -d ',' -f 1) + export REDDWARF_TENANT + export REDDWARF_USER + export REDDWARF_TOKEN + echo "REDDWARF_TENANT = $REDDWARF_TENANT" + echo "REDDWARF_USER = $REDDWARF_USER" + echo "REDDWARF_TOKEN = $REDDWARF_TOKEN" +} + +function create_instance { + FLAVOR_ID=$1 + curl -H"Content-type:application/json" -H"X-Auth-Token:$REDDWARF_TOKEN" http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances -d '{"instance": {"databases": [{"character_set": "utf8", "collate": "utf8_general_ci", "name": "sampledb"}, {"name": "nextround"}], "flavorRef": "http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/flavors/1", "name": "json_rack_instance"}}' | python -mjson.tool +} + +function list_instances { + curl -H"X-Auth-Token:$REDDWARF_TOKEN" http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances | python -mjson.tool +} + +function delete_instance { + INSTANCE_ID=$1 + curl -H"X-Auth-Token:$REDDWARF_TOKEN" -H"ACCEPT:application/json" http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances/$INSTANCE_ID -X DELETE | python -mjson.tool +} + +function show_instance { + INSTANCE_ID=$1 + curl -H"X-Auth-Token:$REDDWARF_TOKEN" -H"ACCEPT:application/json" http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances/$INSTANCE_ID | python -mjson.tool +} + diff --git a/etc/reddwarf/reddwarf.conf.sample b/etc/reddwarf/reddwarf.conf.sample index de57750c20..d68e768692 100644 --- a/etc/reddwarf/reddwarf.conf.sample +++ b/etc/reddwarf/reddwarf.conf.sample @@ -45,6 +45,10 @@ reddwarf_proxy_admin_pass = 3de4922d8b6ac5a1aad9 reddwarf_proxy_admin_tenant_name = admin reddwarf_auth_url = http://0.0.0.0:5000/v2.0 +nova_region_name = RegionOne +nova_service_type = compute +nova_service_name = Compute Service + # ============ notifer queue kombu connection options ======================== notifier_queue_hostname = localhost @@ -85,7 +89,7 @@ admin_token = be19c524ddc92109a224 paste.filter_factory = reddwarf.common.auth:AuthorizationMiddleware.factory [app:reddwarfapp] -paste.app_factory = reddwarf.database.service:app_factory +paste.app_factory = reddwarf.instance.service:app_factory #Add this filter to log request and response for debugging [filter:debug] diff --git a/reddwarf/db/sqlalchemy/session.py b/reddwarf/db/sqlalchemy/session.py index 17c3641f1e..391c60a04f 100644 --- a/reddwarf/db/sqlalchemy/session.py +++ b/reddwarf/db/sqlalchemy/session.py @@ -21,7 +21,7 @@ from sqlalchemy import create_engine from sqlalchemy import MetaData from sqlalchemy.orm import sessionmaker -from reddwarf import database +from reddwarf import instance from reddwarf.common import config from reddwarf.db.sqlalchemy import mappers @@ -40,7 +40,7 @@ def configure_db(options, models_mapper=None): if models_mapper: models_mapper.map(_ENGINE) else: - mappers.map(_ENGINE, database.models.persisted_models()) + mappers.map(_ENGINE, instance.models.persisted_models()) def configure_sqlalchemy_log(options): diff --git a/reddwarf/database/__init__.py b/reddwarf/instance/__init__.py similarity index 100% rename from reddwarf/database/__init__.py rename to reddwarf/instance/__init__.py diff --git a/reddwarf/database/models.py b/reddwarf/instance/models.py similarity index 94% rename from reddwarf/database/models.py rename to reddwarf/instance/models.py index f878a7b88a..781ae155e0 100644 --- a/reddwarf/database/models.py +++ b/reddwarf/instance/models.py @@ -87,14 +87,18 @@ class RemoteModelBase(ModelBase): 'admin') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') + REGION_NAME = CONFIG.get('nova_region_name', 'RegionOne') + SERVICE_TYPE = CONFIG.get('nova_service_type', 'compute') + SERVICE_NAME = CONFIG.get('nova_service_name', 'Compute Service') + #TODO(cp16net) need to fix this proxy_tenant_id client = Client(PROXY_ADMIN_USER, PROXY_ADMIN_PASS, PROXY_ADMIN_TENANT_NAME, PROXY_AUTH_URL, - proxy_tenant_id=context.tenant, + proxy_tenant_id='reddwarf', proxy_token=context.auth_tok, - region_name='RegionOne', - service_type='compute', - service_name="'Compute Service'") + region_name=REGION_NAME, + service_type=SERVICE_TYPE, + service_name=SERVICE_NAME) client.authenticate() return client diff --git a/reddwarf/database/service.py b/reddwarf/instance/service.py similarity index 88% rename from reddwarf/database/service.py rename to reddwarf/instance/service.py index 2a01aa71f8..12dd65f8d4 100644 --- a/reddwarf/database/service.py +++ b/reddwarf/instance/service.py @@ -19,14 +19,12 @@ import logging import routes import webob.exc -from reddwarf import rpc from reddwarf.common import config from reddwarf.common import context as rd_context from reddwarf.common import exception from reddwarf.common import utils from reddwarf.common import wsgi -from reddwarf.database import models -from reddwarf.database import views +from reddwarf.instance import models, views CONFIG = config.Config LOG = logging.getLogger(__name__) @@ -63,8 +61,16 @@ class BaseController(wsgi.Controller): class InstanceController(BaseController): """Controller for instance functionality""" + def detail(self, req, tenant_id): + """Return all instances.""" + LOG.info("req : '%s'\n\n" % req) + LOG.info("Creating a database instance for tenant '%s'" % tenant_id) + return self.index(req, tenant_id) + def index(self, req, tenant_id): """Return all instances.""" + LOG.info("req : '%s'\n\n" % req) + LOG.info("Creating a database instance for tenant '%s'" % tenant_id) # TODO(hub-cap): turn this into middleware context = rd_context.ReddwarfContext( auth_tok=req.headers["X-Auth-Token"], @@ -75,6 +81,9 @@ class InstanceController(BaseController): def show(self, req, tenant_id, id): """Return a single instance.""" + LOG.info("req : '%s'\n\n" % req) + LOG.info("Creating a database instance for tenant '%s'" % tenant_id) + LOG.info("id : '%s'\n\n" % id) # TODO(hub-cap): turn this into middleware context = rd_context.ReddwarfContext( auth_tok=req.headers["X-Auth-Token"], @@ -91,6 +100,9 @@ class InstanceController(BaseController): def delete(self, req, tenant_id, id): """Delete a single instance.""" + LOG.info("req : '%s'\n\n" % req) + LOG.info("Creating a database instance for tenant '%s'" % tenant_id) + LOG.info("id : '%s'\n\n" % id) # TODO(hub-cap): turn this into middleware context = rd_context.ReddwarfContext( auth_tok=req.headers["X-Auth-Token"], @@ -126,6 +138,7 @@ class InstanceController(BaseController): image_id, body).data() + # Now wait for the response from the create to do additional work #TODO(cp16net): need to set the return code correctly return wsgi.Result(views.InstanceView(server).data(), 201) diff --git a/reddwarf/database/views.py b/reddwarf/instance/views.py similarity index 100% rename from reddwarf/database/views.py rename to reddwarf/instance/views.py diff --git a/reddwarf/tests/factories/models.py b/reddwarf/tests/factories/models.py index 7638bfdf4d..0a3018e955 100644 --- a/reddwarf/tests/factories/models.py +++ b/reddwarf/tests/factories/models.py @@ -19,7 +19,7 @@ import factory from reddwarf.common import context from reddwarf.common import utils -from reddwarf.database import models +from reddwarf.instance import models class Instance(factory.Factory): diff --git a/reddwarf/tests/unit/test_database_models.py b/reddwarf/tests/unit/test_database_models.py index 6117a94ca1..3c826b58aa 100644 --- a/reddwarf/tests/unit/test_database_models.py +++ b/reddwarf/tests/unit/test_database_models.py @@ -18,11 +18,8 @@ import mox import novaclient from reddwarf import tests -from reddwarf.common import exception from reddwarf.common import utils -from reddwarf.database import models -from reddwarf.db import db_query -from reddwarf.tests import unit +from reddwarf.instance import models from reddwarf.tests.factories import models as factory_models diff --git a/reddwarf/tests/unit/test_database_service.py b/reddwarf/tests/unit/test_database_service.py index 028490c780..aaaaea841d 100644 --- a/reddwarf/tests/unit/test_database_service.py +++ b/reddwarf/tests/unit/test_database_service.py @@ -16,15 +16,12 @@ import mox import logging -import json import novaclient from reddwarf import tests from reddwarf.common import config from reddwarf.common import utils -from reddwarf.common import wsgi -from reddwarf.database import models -from reddwarf.database import service +from reddwarf.instance import models from reddwarf.tests import unit