Fix and enable H303 and F403 No wildcard (*) import.

F403 is related the message is:
F403 'from bla import *' used; unable to detect undefined names

Change-Id: I486c0b2fc15a616e3fdf1e7e2eaeae1e45075537
This commit is contained in:
Angus Salkeld 2013-06-20 11:52:53 +10:00
parent 6d7c84dbff
commit 3415564deb
13 changed files with 311 additions and 281 deletions

View File

@ -21,8 +21,13 @@ import functools
import urlparse
import sys
from heat.openstack.common.gettextutils import _
from heat.openstack.common import exception
from heat.openstack.common.exception import *
OpenstackException = exception.OpenstackException
NotFound = exception.NotFound
Error = exception.Error
InvalidContentType = exception.InvalidContentType
class RedirectException(Exception):

View File

@ -16,10 +16,10 @@
'''Implementation of SQLAlchemy backend.'''
from sqlalchemy.orm.session import Session
from heat.common.exception import NotFound
from heat.common import crypt
from heat.common import exception
from heat.db.sqlalchemy import models
from heat.db.sqlalchemy.session import get_session
from heat.common import crypt
def model_query(context, *args):
@ -37,7 +37,8 @@ def raw_template_get(context, template_id):
result = model_query(context, models.RawTemplate).get(template_id)
if not result:
raise NotFound("raw template with id %s not found" % template_id)
raise exception.NotFound('raw template with id %s not found' %
template_id)
return result
@ -46,7 +47,7 @@ def raw_template_get_all(context):
results = model_query(context, models.RawTemplate).all()
if not results:
raise NotFound('no raw templates were found')
raise exception.NotFound('no raw templates were found')
return results
@ -62,7 +63,7 @@ def resource_get(context, resource_id):
result = model_query(context, models.Resource).get(resource_id)
if not result:
raise NotFound("resource with id %s not found" % resource_id)
raise exception.NotFound("resource with id %s not found" % resource_id)
return result
@ -91,7 +92,7 @@ def resource_get_all(context):
results = model_query(context, models.Resource).all()
if not results:
raise NotFound('no resources were found')
raise exception.NotFound('no resources were found')
return results
@ -108,7 +109,8 @@ def resource_get_all_by_stack(context, stack_id):
filter_by(stack_id=stack_id).all()
if not results:
raise NotFound("no resources for stack_id %s were found" % stack_id)
raise exception.NotFound("no resources for stack_id %s were found" %
stack_id)
return results
@ -161,8 +163,8 @@ def stack_update(context, stack_id, values):
stack = stack_get(context, stack_id)
if not stack:
raise NotFound('Attempt to update a stack with id: %s %s' %
(stack_id, 'that does not exist'))
raise exception.NotFound('Attempt to update a stack with id: %s %s' %
(stack_id, 'that does not exist'))
old_template_id = stack.raw_template_id
@ -181,8 +183,8 @@ def stack_update(context, stack_id, values):
def stack_delete(context, stack_id):
s = stack_get(context, stack_id)
if not s:
raise NotFound('Attempt to delete a stack with id: %s %s' %
(stack_id, 'that does not exist'))
raise exception.NotFound('Attempt to delete a stack with id: %s %s' %
(stack_id, 'that does not exist'))
session = Session.object_session(s)
@ -293,8 +295,8 @@ def watch_rule_update(context, watch_id, values):
wr = watch_rule_get(context, watch_id)
if not wr:
raise NotFound('Attempt to update a watch with id: %s %s' %
(watch_id, 'that does not exist'))
raise exception.NotFound('Attempt to update a watch with id: %s %s' %
(watch_id, 'that does not exist'))
wr.update(values)
wr.save(_session(context))
@ -305,8 +307,8 @@ def watch_rule_delete(context, watch_name):
filter_by(name=watch_name).first()
if not wr:
raise NotFound('Attempt to delete a watch_rule with name: %s %s' %
(watch_name, 'that does not exist'))
raise exception.NotFound('Attempt to delete watch_rule: %s %s' %
(watch_name, 'that does not exist'))
session = Session.object_session(wr)
@ -334,8 +336,8 @@ def watch_data_delete(context, watch_name):
filter_by(name=watch_name).all()
if not ds:
raise NotFound('Attempt to delete watch_data with name: %s %s' %
(watch_name, 'that does not exist'))
raise exception.NotFound('Attempt to delete watch_data: %s %s' %
(watch_name, 'that does not exist'))
session = Session.object_session(ds)
for d in ds:

View File

@ -12,108 +12,119 @@
# License for the specific language governing permissions and limitations
# under the License.
from sqlalchemy import *
from migrate import *
import sqlalchemy
def upgrade(migrate_engine):
meta = MetaData()
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
raw_template = Table(
raw_template = sqlalchemy.Table(
'raw_template', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('template', Text),
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True,
nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('template', sqlalchemy.Text),
)
user_creds = Table(
user_creds = sqlalchemy.Table(
'user_creds', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('username', String(255)),
Column('password', String(255)),
Column('service_user', String(255)),
Column('service_password', String(255)),
Column('tenant', String(1024)),
Column('auth_url', Text),
Column('aws_auth_url', Text),
Column('tenant_id', String(256)),
Column('aws_creds', Text),
sqlalchemy.Column('id', sqlalchemy.Integer,
primary_key=True, nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('username', sqlalchemy.String(255)),
sqlalchemy.Column('password', sqlalchemy.String(255)),
sqlalchemy.Column('service_user', sqlalchemy.String(255)),
sqlalchemy.Column('service_password', sqlalchemy.String(255)),
sqlalchemy.Column('tenant', sqlalchemy.String(1024)),
sqlalchemy.Column('auth_url', sqlalchemy.Text),
sqlalchemy.Column('aws_auth_url', sqlalchemy.Text),
sqlalchemy.Column('tenant_id', sqlalchemy.String(256)),
sqlalchemy.Column('aws_creds', sqlalchemy.Text),
)
stack = Table(
stack = sqlalchemy.Table(
'stack', meta,
Column('id', String(36), primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('name', String(255)),
Column('raw_template_id', Integer, ForeignKey('raw_template.id'),
nullable=False),
Column('user_creds_id', Integer, ForeignKey('user_creds.id'),
nullable=False),
Column('username', String(256)),
Column('owner_id', String(36)),
Column('status', String(255)),
Column('status_reason', String(255)),
Column('parameters', Text),
Column('timeout', Integer, nullable=False),
Column('tenant', String(256)),
Column('disable_rollback', Boolean, nullable=False),
sqlalchemy.Column('id', sqlalchemy.String(36),
primary_key=True, nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('name', sqlalchemy.String(255)),
sqlalchemy.Column('raw_template_id',
sqlalchemy.Integer,
sqlalchemy.ForeignKey('raw_template.id'),
nullable=False),
sqlalchemy.Column('user_creds_id', sqlalchemy.Integer,
sqlalchemy.ForeignKey('user_creds.id'),
nullable=False),
sqlalchemy.Column('username', sqlalchemy.String(256)),
sqlalchemy.Column('owner_id', sqlalchemy.String(36)),
sqlalchemy.Column('status', sqlalchemy.String(255)),
sqlalchemy.Column('status_reason', sqlalchemy.String(255)),
sqlalchemy.Column('parameters', sqlalchemy.Text),
sqlalchemy.Column('timeout', sqlalchemy.Integer, nullable=False),
sqlalchemy.Column('tenant', sqlalchemy.String(256)),
sqlalchemy.Column('disable_rollback', sqlalchemy.Boolean,
nullable=False),
)
resource = Table(
resource = sqlalchemy.Table(
'resource', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('nova_instance', String(255)),
Column('name', String(255)),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('state', String(255)),
Column('state_description', String(255)),
Column('stack_id', String(36), ForeignKey('stack.id'),
nullable=False),
Column('rsrc_metadata', Text),
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True,
nullable=False),
sqlalchemy.Column('nova_instance', sqlalchemy.String(255)),
sqlalchemy.Column('name', sqlalchemy.String(255)),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('state', sqlalchemy.String(255)),
sqlalchemy.Column('state_description', sqlalchemy.String(255)),
sqlalchemy.Column('stack_id', sqlalchemy.String(36),
sqlalchemy.ForeignKey('stack.id'), nullable=False),
sqlalchemy.Column('rsrc_metadata', sqlalchemy.Text),
)
event = Table(
event = sqlalchemy.Table(
'event', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('stack_id', String(36), ForeignKey('stack.id'),
nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('name', String(255)),
Column('logical_resource_id', String(255)),
Column('physical_resource_id', String(255)),
Column('resource_status_reason', String(255)),
Column('resource_type', String(255)),
Column('resource_properties', PickleType),
sqlalchemy.Column('id', sqlalchemy.Integer,
primary_key=True, nullable=False),
sqlalchemy.Column('stack_id', sqlalchemy.String(36),
sqlalchemy.ForeignKey('stack.id'), nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('name', sqlalchemy.String(255)),
sqlalchemy.Column('logical_resource_id', sqlalchemy.String(255)),
sqlalchemy.Column('physical_resource_id', sqlalchemy.String(255)),
sqlalchemy.Column('resource_status_reason', sqlalchemy.String(255)),
sqlalchemy.Column('resource_type', sqlalchemy.String(255)),
sqlalchemy.Column('resource_properties', sqlalchemy.PickleType),
)
watch_rule = Table(
watch_rule = sqlalchemy.Table(
'watch_rule', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('name', String(255)),
Column('state', String(255)),
Column('rule', Text),
Column('last_evaluated', DateTime),
Column('stack_id', String(36), ForeignKey('stack.id'),
nullable=False),
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True,
nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('name', sqlalchemy.String(255)),
sqlalchemy.Column('state', sqlalchemy.String(255)),
sqlalchemy.Column('rule', sqlalchemy.Text),
sqlalchemy.Column('last_evaluated', sqlalchemy.DateTime),
sqlalchemy.Column('stack_id', sqlalchemy.String(36),
sqlalchemy.ForeignKey('stack.id'), nullable=False),
)
watch_data = Table(
watch_data = sqlalchemy.Table(
'watch_data', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('data', Text),
Column('watch_rule_id', Integer, ForeignKey('watch_rule.id'),
nullable=False),
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True,
nullable=False),
sqlalchemy.Column('created_at', sqlalchemy.DateTime),
sqlalchemy.Column('updated_at', sqlalchemy.DateTime),
sqlalchemy.Column('data', sqlalchemy.Text),
sqlalchemy.Column('watch_rule_id', sqlalchemy.Integer,
sqlalchemy.ForeignKey('watch_rule.id'),
nullable=False),
)
tables = (

View File

@ -12,21 +12,20 @@
# License for the specific language governing permissions and limitations
# under the License.
from sqlalchemy import *
from migrate import *
import sqlalchemy
def upgrade(migrate_engine):
meta = MetaData()
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
stack = Table('stack', meta, autoload=True)
stack = sqlalchemy.Table('stack', meta, autoload=True)
stack.c.timeout.alter(nullable=True)
def downgrade(migrate_engine):
meta = MetaData()
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
stack = Table('stack', meta, autoload=True)
stack = sqlalchemy.Table('stack', meta, autoload=True)
stack.c.timeout.alter(nullable=False)

View File

@ -12,26 +12,25 @@
# License for the specific language governing permissions and limitations
# under the License.
from sqlalchemy import *
from migrate import *
import sqlalchemy
def upgrade(migrate_engine):
meta = MetaData()
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
event = Table('event', meta, autoload=True)
event = sqlalchemy.Table('event', meta, autoload=True)
# Currently there is a 'name' column which really holds the
# resource status, so rename it and add a separate action column
# action is e.g "CREATE" and status is e.g "IN_PROGRESS"
event.c.name.alter(name='resource_status')
Column('resource_action', String(255)).create(event)
sqlalchemy.Column('resource_action', sqlalchemy.String(255)).create(event)
def downgrade(migrate_engine):
meta = MetaData()
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
event = Table('event', meta, autoload=True)
event = sqlalchemy.Table('event', meta, autoload=True)
event.c.resource_status.alter(name='name')
event.c.resource_action.drop()

View File

@ -12,31 +12,30 @@
# License for the specific language governing permissions and limitations
# under the License.
from sqlalchemy import *
from migrate import *
import sqlalchemy
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
meta = sqlalchemy.MetaData(bind=migrate_engine)
resource = Table('resource', meta, autoload=True)
resource = sqlalchemy.Table('resource', meta, autoload=True)
# Align the current state/state_description with the
# action/status now used in the event table
Column('action', String(length=255,
convert_unicode=False,
assert_unicode=None,
unicode_error=None,
_warn_on_bytestring=False)).create(resource)
action = sqlalchemy.Column('action',
sqlalchemy.String(length=255,
convert_unicode=False,
assert_unicode=None,
unicode_error=None,
_warn_on_bytestring=False))
action.create(resource)
resource.c.state.alter(name='status')
resource.c.state_description.alter(name='status_reason')
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
meta = sqlalchemy.MetaData(bind=migrate_engine)
resource = Table('resource', meta, autoload=True)
resource = sqlalchemy.Table('resource', meta, autoload=True)
resource.c.status.drop()
resource.c.status.alter(name='state')
resource.c.status_reason.alter(name='state_description')

View File

@ -12,26 +12,25 @@
# License for the specific language governing permissions and limitations
# under the License.
from sqlalchemy import *
from migrate import *
import sqlalchemy
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
meta = sqlalchemy.MetaData(bind=migrate_engine)
stack = Table('stack', meta, autoload=True)
stack = sqlalchemy.Table('stack', meta, autoload=True)
# Align with action/status now used in the event/resource tables
Column('action', String(length=255,
convert_unicode=False,
assert_unicode=None,
unicode_error=None,
_warn_on_bytestring=False)).create(stack)
action = sqlalchemy.Column('action',
sqlalchemy.String(length=255,
convert_unicode=False,
assert_unicode=None,
unicode_error=None,
_warn_on_bytestring=False))
action.create(stack)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
meta = sqlalchemy.MetaData(bind=migrate_engine)
stack = Table('stack', meta, autoload=True)
stack = sqlalchemy.Table('stack', meta, autoload=True)
stack.c.action.drop()

View File

@ -15,13 +15,15 @@
SQLAlchemy models for heat data.
"""
from sqlalchemy import *
import sqlalchemy
from sqlalchemy.orm import relationship, backref, object_mapper
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import types as types
from sqlalchemy import types
from json import dumps
from json import loads
from heat.openstack.common import exception
from heat.openstack.common import uuidutils
from heat.openstack.common import timeutils
from heat.db.sqlalchemy.session import get_session
@ -44,8 +46,10 @@ class HeatBase(object):
"""Base class for Heat Models."""
__table_args__ = {'mysql_engine': 'InnoDB'}
__table_initialized__ = False
created_at = Column(DateTime, default=timeutils.utcnow)
updated_at = Column(DateTime, onupdate=timeutils.utcnow)
created_at = sqlalchemy.Column(sqlalchemy.DateTime,
default=timeutils.utcnow)
updated_at = sqlalchemy.Column(sqlalchemy.DateTime,
onupdate=timeutils.utcnow)
def save(self, session=None):
"""Save this object."""
@ -137,8 +141,8 @@ class RawTemplate(BASE, HeatBase):
"""Represents an unparsed template which should be in JSON format."""
__tablename__ = 'raw_template'
id = Column(Integer, primary_key=True)
template = Column(Json)
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
template = sqlalchemy.Column(Json)
class Stack(BASE, HeatBase):
@ -146,26 +150,27 @@ class Stack(BASE, HeatBase):
__tablename__ = 'stack'
id = Column(String, primary_key=True, default=uuidutils.generate_uuid)
name = Column(String)
raw_template_id = Column(
Integer,
ForeignKey('raw_template.id'),
id = sqlalchemy.Column(sqlalchemy.String, primary_key=True,
default=uuidutils.generate_uuid)
name = sqlalchemy.Column(sqlalchemy.String)
raw_template_id = sqlalchemy.Column(
sqlalchemy.Integer,
sqlalchemy.ForeignKey('raw_template.id'),
nullable=False)
raw_template = relationship(RawTemplate, backref=backref('stack'))
username = Column(String)
tenant = Column(String)
action = Column('action', String)
status = Column('status', String)
status_reason = Column('status_reason', String)
parameters = Column('parameters', Json)
user_creds_id = Column(
Integer,
ForeignKey('user_creds.id'),
username = sqlalchemy.Column(sqlalchemy.String)
tenant = sqlalchemy.Column(sqlalchemy.String)
action = sqlalchemy.Column('action', sqlalchemy.String)
status = sqlalchemy.Column('status', sqlalchemy.String)
status_reason = sqlalchemy.Column('status_reason', sqlalchemy.String)
parameters = sqlalchemy.Column('parameters', Json)
user_creds_id = sqlalchemy.Column(
sqlalchemy.Integer,
sqlalchemy.ForeignKey('user_creds.id'),
nullable=False)
owner_id = Column(String, nullable=True)
timeout = Column(Integer)
disable_rollback = Column(Boolean)
owner_id = sqlalchemy.Column(sqlalchemy.String, nullable=True)
timeout = sqlalchemy.Column(sqlalchemy.Integer)
disable_rollback = sqlalchemy.Column(sqlalchemy.Boolean)
class UserCreds(BASE, HeatBase):
@ -176,16 +181,16 @@ class UserCreds(BASE, HeatBase):
__tablename__ = 'user_creds'
id = Column(Integer, primary_key=True)
username = Column(String)
password = Column(String)
service_user = Column(String)
service_password = Column(String)
tenant = Column(String)
auth_url = Column(String)
aws_auth_url = Column(String)
tenant_id = Column(String)
aws_creds = Column(String)
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
username = sqlalchemy.Column(sqlalchemy.String)
password = sqlalchemy.Column(sqlalchemy.String)
service_user = sqlalchemy.Column(sqlalchemy.String)
service_password = sqlalchemy.Column(sqlalchemy.String)
tenant = sqlalchemy.Column(sqlalchemy.String)
auth_url = sqlalchemy.Column(sqlalchemy.String)
aws_auth_url = sqlalchemy.Column(sqlalchemy.String)
tenant_id = sqlalchemy.Column(sqlalchemy.String)
aws_creds = sqlalchemy.Column(sqlalchemy.String)
stack = relationship(Stack, backref=backref('user_creds'))
@ -194,17 +199,19 @@ class Event(BASE, HeatBase):
__tablename__ = 'event'
id = Column(Integer, primary_key=True)
stack_id = Column(String, ForeignKey('stack.id'), nullable=False)
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
stack_id = sqlalchemy.Column(sqlalchemy.String,
sqlalchemy.ForeignKey('stack.id'),
nullable=False)
stack = relationship(Stack, backref=backref('events'))
resource_action = Column(String)
resource_status = Column(String)
logical_resource_id = Column(String)
physical_resource_id = Column(String)
resource_status_reason = Column(String)
resource_type = Column(String)
resource_properties = Column(PickleType)
resource_action = sqlalchemy.Column(sqlalchemy.String)
resource_status = sqlalchemy.Column(sqlalchemy.String)
logical_resource_id = sqlalchemy.Column(sqlalchemy.String)
physical_resource_id = sqlalchemy.Column(sqlalchemy.String)
resource_status_reason = sqlalchemy.Column(sqlalchemy.String)
resource_type = sqlalchemy.Column(sqlalchemy.String)
resource_properties = sqlalchemy.Column(sqlalchemy.PickleType)
class Resource(BASE, HeatBase):
@ -212,16 +219,20 @@ class Resource(BASE, HeatBase):
__tablename__ = 'resource'
id = Column(String, primary_key=True, default=uuidutils.generate_uuid)
action = Column('action', String)
status = Column('status', String)
name = Column('name', String, nullable=False)
nova_instance = Column('nova_instance', String)
status_reason = Column('status_reason', String)
id = sqlalchemy.Column(sqlalchemy.Integer,
primary_key=True,
default=uuidutils.generate_uuid)
action = sqlalchemy.Column('action', sqlalchemy.String)
status = sqlalchemy.Column('status', sqlalchemy.String)
name = sqlalchemy.Column('name', sqlalchemy.String, nullable=False)
nova_instance = sqlalchemy.Column('nova_instance', sqlalchemy.String)
status_reason = sqlalchemy.Column('status_reason', sqlalchemy.String)
# odd name as "metadata" is reserved
rsrc_metadata = Column('rsrc_metadata', Json)
rsrc_metadata = sqlalchemy.Column('rsrc_metadata', Json)
stack_id = Column(String, ForeignKey('stack.id'), nullable=False)
stack_id = sqlalchemy.Column(sqlalchemy.String,
sqlalchemy.ForeignKey('stack.id'),
nullable=False)
stack = relationship(Stack, backref=backref('resources'))
@ -230,13 +241,16 @@ class WatchRule(BASE, HeatBase):
__tablename__ = 'watch_rule'
id = Column(Integer, primary_key=True)
name = Column('name', String, nullable=False)
rule = Column('rule', Json)
state = Column('state', String)
last_evaluated = Column(DateTime, default=timeutils.utcnow)
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
name = sqlalchemy.Column('name', sqlalchemy.String, nullable=False)
rule = sqlalchemy.Column('rule', Json)
state = sqlalchemy.Column('state', sqlalchemy.String)
last_evaluated = sqlalchemy.Column(sqlalchemy.DateTime,
default=timeutils.utcnow)
stack_id = Column(String, ForeignKey('stack.id'), nullable=False)
stack_id = sqlalchemy.Column(sqlalchemy.String,
sqlalchemy.ForeignKey('stack.id'),
nullable=False)
stack = relationship(Stack, backref=backref('watch_rule'))
@ -245,11 +259,11 @@ class WatchData(BASE, HeatBase):
__tablename__ = 'watch_data'
id = Column(Integer, primary_key=True)
data = Column('data', Json)
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
data = sqlalchemy.Column('data', Json)
watch_rule_id = Column(
Integer,
ForeignKey('watch_rule.id'),
watch_rule_id = sqlalchemy.Column(
sqlalchemy.Integer,
sqlalchemy.ForeignKey('watch_rule.id'),
nullable=False)
watch_rule = relationship(WatchRule, backref=backref('watch_data'))

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from heat.rpc.api import *
from heat.rpc import api
from heat.openstack.common import timeutils
from heat.engine import template
@ -29,22 +29,22 @@ def extract_args(params):
'''
kwargs = {}
try:
timeout_mins = int(params.get(PARAM_TIMEOUT, 0))
timeout_mins = int(params.get(api.PARAM_TIMEOUT, 0))
except (ValueError, TypeError):
logger.exception('create timeout conversion')
else:
if timeout_mins > 0:
kwargs[PARAM_TIMEOUT] = timeout_mins
kwargs[api.PARAM_TIMEOUT] = timeout_mins
if PARAM_DISABLE_ROLLBACK in params:
disable_rollback = params.get(PARAM_DISABLE_ROLLBACK)
if api.PARAM_DISABLE_ROLLBACK in params:
disable_rollback = params.get(api.PARAM_DISABLE_ROLLBACK)
if str(disable_rollback).lower() == 'true':
kwargs[PARAM_DISABLE_ROLLBACK] = True
kwargs[api.PARAM_DISABLE_ROLLBACK] = True
elif str(disable_rollback).lower() == 'false':
kwargs[PARAM_DISABLE_ROLLBACK] = False
kwargs[api.PARAM_DISABLE_ROLLBACK] = False
else:
raise ValueError("Unexpected value for parameter %s : %s" %
(PARAM_DISABLE_ROLLBACK, disable_rollback))
(api.PARAM_DISABLE_ROLLBACK, disable_rollback))
return kwargs
@ -54,10 +54,10 @@ def format_stack_outputs(stack, outputs):
that matches the API output expectations.
'''
def format_stack_output(k):
return {OUTPUT_DESCRIPTION: outputs[k].get('Description',
'No description given'),
OUTPUT_KEY: k,
OUTPUT_VALUE: stack.output(k)}
return {api.OUTPUT_DESCRIPTION: outputs[k].get('Description',
'No description given'),
api.OUTPUT_KEY: k,
api.OUTPUT_VALUE: stack.output(k)}
return [format_stack_output(key) for key in outputs]
@ -68,25 +68,25 @@ def format_stack(stack):
expectations.
'''
info = {
STACK_NAME: stack.name,
STACK_ID: dict(stack.identifier()),
STACK_CREATION_TIME: timeutils.isotime(stack.created_time),
STACK_UPDATED_TIME: timeutils.isotime(stack.updated_time),
STACK_NOTIFICATION_TOPICS: [], # TODO Not implemented yet
STACK_PARAMETERS: stack.parameters.map(str),
STACK_DESCRIPTION: stack.t[template.DESCRIPTION],
STACK_TMPL_DESCRIPTION: stack.t[template.DESCRIPTION],
STACK_ACTION: stack.action or '',
STACK_STATUS: stack.status or '',
STACK_STATUS_DATA: stack.status_reason,
STACK_CAPABILITIES: [], # TODO Not implemented yet
STACK_DISABLE_ROLLBACK: stack.disable_rollback,
STACK_TIMEOUT: stack.timeout_mins,
api.STACK_NAME: stack.name,
api.STACK_ID: dict(stack.identifier()),
api.STACK_CREATION_TIME: timeutils.isotime(stack.created_time),
api.STACK_UPDATED_TIME: timeutils.isotime(stack.updated_time),
api.STACK_NOTIFICATION_TOPICS: [], # TODO Not implemented yet
api.STACK_PARAMETERS: stack.parameters.map(str),
api.STACK_DESCRIPTION: stack.t[template.DESCRIPTION],
api.STACK_TMPL_DESCRIPTION: stack.t[template.DESCRIPTION],
api.STACK_ACTION: stack.action or '',
api.STACK_STATUS: stack.status or '',
api.STACK_STATUS_DATA: stack.status_reason,
api.STACK_CAPABILITIES: [], # TODO Not implemented yet
api.STACK_DISABLE_ROLLBACK: stack.disable_rollback,
api.STACK_TIMEOUT: stack.timeout_mins,
}
# only show the outputs on a completely created or updated stack
if (stack.action != stack.DELETE and stack.status == stack.COMPLETE):
info[STACK_OUTPUTS] = format_stack_outputs(stack, stack.outputs)
info[api.STACK_OUTPUTS] = format_stack_outputs(stack, stack.outputs)
return info
@ -98,22 +98,22 @@ def format_stack_resource(resource, detail=True):
'''
last_updated_time = resource.updated_time or resource.created_time
res = {
RES_UPDATED_TIME: timeutils.isotime(last_updated_time),
RES_NAME: resource.name,
RES_PHYSICAL_ID: resource.resource_id or '',
RES_METADATA: resource.metadata,
RES_ACTION: resource.action or '',
RES_STATUS: resource.status or '',
RES_STATUS_DATA: resource.status_reason,
RES_TYPE: resource.t['Type'],
RES_ID: dict(resource.identifier()),
RES_STACK_ID: dict(resource.stack.identifier()),
RES_STACK_NAME: resource.stack.name,
api.RES_UPDATED_TIME: timeutils.isotime(last_updated_time),
api.RES_NAME: resource.name,
api.RES_PHYSICAL_ID: resource.resource_id or '',
api.RES_METADATA: resource.metadata,
api.RES_ACTION: resource.action,
api.RES_STATUS: resource.status,
api.RES_STATUS_DATA: resource.status_reason,
api.RES_TYPE: resource.t['Type'],
api.RES_ID: dict(resource.identifier()),
api.RES_STACK_ID: dict(resource.stack.identifier()),
api.RES_STACK_NAME: resource.stack.name,
}
if detail:
res[RES_DESCRIPTION] = resource.parsed_template('Description', '')
res[RES_METADATA] = resource.metadata
res[api.RES_DESCRIPTION] = resource.parsed_template('Description', '')
res[api.RES_METADATA] = resource.metadata
return res
@ -122,17 +122,17 @@ def format_event(event):
stack_identifier = event.stack.identifier()
result = {
EVENT_ID: dict(event.identifier()),
EVENT_STACK_ID: dict(stack_identifier),
EVENT_STACK_NAME: stack_identifier.stack_name,
EVENT_TIMESTAMP: timeutils.isotime(event.timestamp),
EVENT_RES_NAME: event.resource.name,
EVENT_RES_PHYSICAL_ID: event.physical_resource_id,
EVENT_RES_ACTION: event.action,
EVENT_RES_STATUS: event.status,
EVENT_RES_STATUS_DATA: event.reason,
EVENT_RES_TYPE: event.resource.type(),
EVENT_RES_PROPERTIES: event.resource_properties,
api.EVENT_ID: dict(event.identifier()),
api.EVENT_STACK_ID: dict(stack_identifier),
api.EVENT_STACK_NAME: stack_identifier.stack_name,
api.EVENT_TIMESTAMP: timeutils.isotime(event.timestamp),
api.EVENT_RES_NAME: event.resource.name,
api.EVENT_RES_PHYSICAL_ID: event.physical_resource_id,
api.EVENT_RES_ACTION: event.action,
api.EVENT_RES_STATUS: event.status,
api.EVENT_RES_STATUS_DATA: event.reason,
api.EVENT_RES_TYPE: event.resource.type(),
api.EVENT_RES_PROPERTIES: event.resource_properties,
}
return result
@ -141,29 +141,31 @@ def format_event(event):
def format_watch(watch):
result = {
WATCH_ACTIONS_ENABLED: watch.rule.get(RULE_ACTIONS_ENABLED),
WATCH_ALARM_ACTIONS: watch.rule.get(RULE_ALARM_ACTIONS),
WATCH_TOPIC: watch.rule.get(RULE_TOPIC),
WATCH_UPDATED_TIME: timeutils.isotime(watch.updated_at),
WATCH_DESCRIPTION: watch.rule.get(RULE_DESCRIPTION),
WATCH_NAME: watch.name,
WATCH_COMPARISON: watch.rule.get(RULE_COMPARISON),
WATCH_DIMENSIONS: watch.rule.get(RULE_DIMENSIONS) or [],
WATCH_PERIODS: watch.rule.get(RULE_PERIODS),
WATCH_INSUFFICIENT_ACTIONS: watch.rule.get(RULE_INSUFFICIENT_ACTIONS),
WATCH_METRIC_NAME: watch.rule.get(RULE_METRIC_NAME),
WATCH_NAMESPACE: watch.rule.get(RULE_NAMESPACE),
WATCH_OK_ACTIONS: watch.rule.get(RULE_OK_ACTIONS),
WATCH_PERIOD: watch.rule.get(RULE_PERIOD),
WATCH_STATE_REASON: watch.rule.get(RULE_STATE_REASON),
WATCH_STATE_REASON_DATA: watch.rule.get(RULE_STATE_REASON_DATA),
WATCH_STATE_UPDATED_TIME: timeutils.isotime(
watch.rule.get(RULE_STATE_UPDATED_TIME)),
WATCH_STATE_VALUE: watch.state,
WATCH_STATISTIC: watch.rule.get(RULE_STATISTIC),
WATCH_THRESHOLD: watch.rule.get(RULE_THRESHOLD),
WATCH_UNIT: watch.rule.get(RULE_UNIT),
WATCH_STACK_ID: watch.stack_id
api.WATCH_ACTIONS_ENABLED: watch.rule.get(api.RULE_ACTIONS_ENABLED),
api.WATCH_ALARM_ACTIONS: watch.rule.get(api.RULE_ALARM_ACTIONS),
api.WATCH_TOPIC: watch.rule.get(api.RULE_TOPIC),
api.WATCH_UPDATED_TIME: timeutils.isotime(watch.updated_at),
api.WATCH_DESCRIPTION: watch.rule.get(api.RULE_DESCRIPTION),
api.WATCH_NAME: watch.name,
api.WATCH_COMPARISON: watch.rule.get(api.RULE_COMPARISON),
api.WATCH_DIMENSIONS: watch.rule.get(api.RULE_DIMENSIONS) or [],
api.WATCH_PERIODS: watch.rule.get(api.RULE_PERIODS),
api.WATCH_INSUFFICIENT_ACTIONS:
watch.rule.get(api.RULE_INSUFFICIENT_ACTIONS),
api.WATCH_METRIC_NAME: watch.rule.get(api.RULE_METRIC_NAME),
api.WATCH_NAMESPACE: watch.rule.get(api.RULE_NAMESPACE),
api.WATCH_OK_ACTIONS: watch.rule.get(api.RULE_OK_ACTIONS),
api.WATCH_PERIOD: watch.rule.get(api.RULE_PERIOD),
api.WATCH_STATE_REASON: watch.rule.get(api.RULE_STATE_REASON),
api.WATCH_STATE_REASON_DATA:
watch.rule.get(api.RULE_STATE_REASON_DATA),
api.WATCH_STATE_UPDATED_TIME: timeutils.isotime(
watch.rule.get(api.RULE_STATE_UPDATED_TIME)),
api.WATCH_STATE_VALUE: watch.state,
api.WATCH_STATISTIC: watch.rule.get(api.RULE_STATISTIC),
api.WATCH_THRESHOLD: watch.rule.get(api.RULE_THRESHOLD),
api.WATCH_UNIT: watch.rule.get(api.RULE_UNIT),
api.WATCH_STACK_ID: watch.stack_id
}
return result
@ -183,11 +185,11 @@ def format_watch_data(wd):
return
result = {
WATCH_DATA_ALARM: wd.watch_rule.name,
WATCH_DATA_METRIC: metric_name,
WATCH_DATA_TIME: timeutils.isotime(wd.created_at),
WATCH_DATA_NAMESPACE: namespace,
WATCH_DATA: metric_data
api.WATCH_DATA_ALARM: wd.watch_rule.name,
api.WATCH_DATA_METRIC: metric_name,
api.WATCH_DATA_TIME: timeutils.isotime(wd.created_at),
api.WATCH_DATA_NAMESPACE: namespace,
api.WATCH_DATA: metric_data
}
return result

View File

@ -22,6 +22,7 @@ import webob
from heat.common import context
from heat.db import api as db_api
from heat.engine import api
from heat.rpc import api as rpc_api
from heat.engine import clients
from heat.engine.event import Event
from heat.engine import environment
@ -619,5 +620,5 @@ class EngineService(service.Service):
# Return the watch with the state overriden to indicate success
# We do not update the timestamps as we are not modifying the DB
result = api.format_watch(wr)
result[api.WATCH_STATE_VALUE] = state
result[rpc_api.WATCH_STATE_VALUE] = state
return result

View File

@ -18,7 +18,8 @@
Client side of the heat engine RPC API.
"""
from heat.engine import api
from heat.rpc import api
import heat.openstack.common.rpc.proxy

View File

@ -25,7 +25,7 @@ from heat.common import context
from heat.engine import environment
from heat.common import exception
from heat.tests.v1_1 import fakes
import heat.engine.api as engine_api
import heat.rpc.api as engine_api
import heat.db.api as db_api
from heat.common import identifier
from heat.common import template_format

View File

@ -22,14 +22,12 @@ commands =
python setup.py testr --coverage
[flake8]
# F403 'from sqlalchemy import *' used; unable to detect undefined names
# F841 local variable 'json_template' is assigned to but never used
# H201 no 'except:' at least use 'except Exception:'
# H302 import only modules.'bla..' does not import a module
# H303 No wildcard (*) import.
# H306 imports not in alphabetical order
# H404 multi line docstring should start with a summary
ignore = F403,F841,H201,H302,H303,H306,H404
ignore = F841,H201,H302,H306,H404
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,build