Make fake_instance handle security groups
This makes the fake_db_instance() helper create model-like security group objects in the returned instance if a list of names is specified. This is required to test anything that uses security groups on the instance. Related to blueprint compute-api-objects Change-Id: I4a7d91c939af8c0dc4e0b3e29c477a859d85fd3e
This commit is contained in:
parent
68288b9cd2
commit
5c5ddbcb40
@ -18,6 +18,24 @@ import uuid
|
|||||||
from nova.objects import instance as instance_obj
|
from nova.objects import instance as instance_obj
|
||||||
|
|
||||||
|
|
||||||
|
def fake_db_secgroups(instance, names):
|
||||||
|
secgroups = []
|
||||||
|
for i, name in enumerate(names):
|
||||||
|
secgroups.append(
|
||||||
|
{'id': i,
|
||||||
|
'instance_uuid': instance['uuid'],
|
||||||
|
'name': 'secgroup-%i' % i,
|
||||||
|
'description': 'Fake secgroup',
|
||||||
|
'user_id': instance['user_id'],
|
||||||
|
'project_id': instance['project_id'],
|
||||||
|
'deleted': False,
|
||||||
|
'deleted_at': None,
|
||||||
|
'created_at': None,
|
||||||
|
'updated_at': None,
|
||||||
|
})
|
||||||
|
return secgroups
|
||||||
|
|
||||||
|
|
||||||
def fake_db_instance(**updates):
|
def fake_db_instance(**updates):
|
||||||
db_instance = {
|
db_instance = {
|
||||||
'id': 1,
|
'id': 1,
|
||||||
@ -38,4 +56,9 @@ def fake_db_instance(**updates):
|
|||||||
|
|
||||||
if updates:
|
if updates:
|
||||||
db_instance.update(updates)
|
db_instance.update(updates)
|
||||||
|
|
||||||
|
if db_instance.get('security_groups'):
|
||||||
|
db_instance['security_groups'] = fake_db_secgroups(
|
||||||
|
db_instance, db_instance['security_groups'])
|
||||||
|
|
||||||
return db_instance
|
return db_instance
|
||||||
|
Loading…
Reference in New Issue
Block a user