Merge "heat-manage resource_data_list"
This commit is contained in:
commit
b208c1da79
@ -88,6 +88,16 @@ class ServiceManageCommand(object):
|
||||
remove_parser.set_defaults(func=ServiceManageCommand().service_clean)
|
||||
|
||||
|
||||
def do_resource_data_list():
|
||||
ctxt = context.get_admin_context()
|
||||
data = db_api.resource_data_get_all(ctxt, CONF.command.resource_id)
|
||||
|
||||
print_format = "%-16s %-64s"
|
||||
|
||||
for k in data.keys():
|
||||
print(print_format % (k, data[k]))
|
||||
|
||||
|
||||
def purge_deleted():
|
||||
"""Remove database records that have been previously soft deleted."""
|
||||
utils.purge_deleted(CONF.command.age, CONF.command.granularity)
|
||||
@ -135,6 +145,11 @@ def add_command_parsers(subparsers):
|
||||
help=_('Provide old encryption key. New encryption'
|
||||
' key would be used from config file.'))
|
||||
|
||||
parser = subparsers.add_parser('resource_data_list')
|
||||
parser.set_defaults(func=do_resource_data_list)
|
||||
parser.add_argument('resource_id',
|
||||
help=_('Stack resource id'))
|
||||
|
||||
ServiceManageCommand.add_service_parsers(subparsers)
|
||||
|
||||
command_opt = cfg.SubCommandOpt('command',
|
||||
|
@ -58,8 +58,8 @@ def raw_template_delete(context, template_id):
|
||||
return IMPL.raw_template_delete(context, template_id)
|
||||
|
||||
|
||||
def resource_data_get_all(resource, data=None):
|
||||
return IMPL.resource_data_get_all(resource, data)
|
||||
def resource_data_get_all(context, resource_id, data=None):
|
||||
return IMPL.resource_data_get_all(context, resource_id, data)
|
||||
|
||||
|
||||
def resource_data_get(resource, key):
|
||||
|
@ -182,14 +182,14 @@ def resource_update(context, resource_id, values, atomic_key,
|
||||
return bool(rows_updated)
|
||||
|
||||
|
||||
def resource_data_get_all(resource, data=None):
|
||||
def resource_data_get_all(context, resource_id, data=None):
|
||||
"""Looks up resource_data by resource.id.
|
||||
|
||||
If data is encrypted, this method will decrypt the results.
|
||||
"""
|
||||
if data is None:
|
||||
data = (model_query(resource.context, models.ResourceData)
|
||||
.filter_by(resource_id=resource.id)).all()
|
||||
data = (model_query(context, models.ResourceData)
|
||||
.filter_by(resource_id=resource_id)).all()
|
||||
|
||||
if not data:
|
||||
raise exception.NotFound(_('no resource data found'))
|
||||
|
@ -50,7 +50,10 @@ class ResourceData(
|
||||
@classmethod
|
||||
def get_all(cls, resource, *args, **kwargs):
|
||||
# this method only returns dict, so we won't use objects mechanism here
|
||||
return db_api.resource_data_get_all(resource, *args, **kwargs)
|
||||
return db_api.resource_data_get_all(resource.context,
|
||||
resource.id,
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
@classmethod
|
||||
def get_obj(cls, resource, key):
|
||||
|
@ -1914,7 +1914,8 @@ class DBAPIStackTest(common.HeatTestCase):
|
||||
ctx, stacks[s].id)
|
||||
for r in stacks[s].resources:
|
||||
self.assertRaises(exception.NotFound,
|
||||
db_api.resource_data_get_all(r))
|
||||
db_api.resource_data_get_all(r.context,
|
||||
r.id))
|
||||
self.assertEqual([],
|
||||
db_api.event_get_all_by_stack(ctx,
|
||||
stacks[s].id))
|
||||
@ -2183,13 +2184,14 @@ class DBAPIResourceDataTest(common.HeatTestCase):
|
||||
self.assertEqual('test_value', val)
|
||||
|
||||
# get all by querying for data
|
||||
vals = db_api.resource_data_get_all(self.resource)
|
||||
vals = db_api.resource_data_get_all(self.resource.context,
|
||||
self.resource.id)
|
||||
self.assertEqual(2, len(vals))
|
||||
self.assertEqual('foo', vals.get('test_resource_key'))
|
||||
self.assertEqual('test_value', vals.get('encryped_resource_key'))
|
||||
|
||||
# get all by using associated resource data
|
||||
vals = db_api.resource_data_get_all(None, self.resource.data)
|
||||
vals = db_api.resource_data_get_all(None, None, self.resource.data)
|
||||
self.assertEqual(2, len(vals))
|
||||
self.assertEqual('foo', vals.get('test_resource_key'))
|
||||
self.assertEqual('test_value', vals.get('encryped_resource_key'))
|
||||
@ -2207,7 +2209,8 @@ class DBAPIResourceDataTest(common.HeatTestCase):
|
||||
self.assertIsNotNone(res_data)
|
||||
|
||||
self.assertRaises(exception.NotFound, db_api.resource_data_get_all,
|
||||
self.resource)
|
||||
self.resource.context,
|
||||
self.resource.id)
|
||||
|
||||
|
||||
class DBAPIEventTest(common.HeatTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user