From 5c5ddbcb40384ad6f304957b3272fe1870d6bb63 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 22 Jul 2013 14:36:39 -0700 Subject: [PATCH] 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 --- nova/tests/fake_instance.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nova/tests/fake_instance.py b/nova/tests/fake_instance.py index a8004364aac6..48554e6e29a4 100644 --- a/nova/tests/fake_instance.py +++ b/nova/tests/fake_instance.py @@ -18,6 +18,24 @@ import uuid 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): db_instance = { 'id': 1, @@ -38,4 +56,9 @@ def fake_db_instance(**updates): if 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