Merge "nova-net: Remove use of legacy 'SecurityGroup' object"
This commit is contained in:
@@ -845,11 +845,6 @@ def instance_get_all_by_host_and_not_type(context, host, type_id=None):
|
||||
return IMPL.instance_get_all_by_host_and_not_type(context, host, type_id)
|
||||
|
||||
|
||||
def instance_get_all_by_grantee_security_groups(context, group_ids):
|
||||
"""Get instances with rules granted to them by a list of secgroups ids."""
|
||||
return IMPL.instance_get_all_by_grantee_security_groups(context, group_ids)
|
||||
|
||||
|
||||
def instance_floating_address_get_all(context, instance_uuid):
|
||||
"""Get all floating IP addresses of an instance."""
|
||||
return IMPL.instance_floating_address_get_all(context, instance_uuid)
|
||||
|
||||
@@ -2654,18 +2654,6 @@ def instance_get_all_by_host_and_not_type(context, host, type_id=None):
|
||||
filter(models.Instance.instance_type_id != type_id).all())
|
||||
|
||||
|
||||
@pick_context_manager_reader
|
||||
def instance_get_all_by_grantee_security_groups(context, group_ids):
|
||||
if not group_ids:
|
||||
return []
|
||||
return _instances_fill_metadata(context,
|
||||
_instance_get_all_query(context).
|
||||
join(models.Instance.security_groups).
|
||||
filter(models.SecurityGroup.rules.any(
|
||||
models.SecurityGroupIngressRule.group_id.in_(group_ids))).
|
||||
all())
|
||||
|
||||
|
||||
@require_context
|
||||
@pick_context_manager_reader
|
||||
def instance_floating_address_get_all(context, instance_uuid):
|
||||
|
||||
@@ -1446,9 +1446,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
||||
# TODO(stephenfin): Remove this as it's related to nova-network
|
||||
@base.remotable_classmethod
|
||||
def get_by_grantee_security_group_ids(cls, context, security_group_ids):
|
||||
db_instances = db.instance_get_all_by_grantee_security_groups(
|
||||
context, security_group_ids)
|
||||
return _make_instance_list(context, cls(), db_instances, [])
|
||||
raise NotImplementedError()
|
||||
|
||||
def fill_faults(self):
|
||||
"""Batch query the database for our instances' faults.
|
||||
|
||||
@@ -2510,65 +2510,6 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
self.assertEqual(sorted(['metadata', 'system_metadata']),
|
||||
sorted(mock_fill.call_args[1]['manual_joins']))
|
||||
|
||||
def _get_base_values(self):
|
||||
return {
|
||||
'name': 'fake_sec_group',
|
||||
'description': 'fake_sec_group_descr',
|
||||
'user_id': 'fake',
|
||||
'project_id': 'fake',
|
||||
'instances': []
|
||||
}
|
||||
|
||||
def _get_base_rule_values(self):
|
||||
return {
|
||||
'protocol': "tcp",
|
||||
'from_port': 80,
|
||||
'to_port': 8080,
|
||||
'cidr': None,
|
||||
'deleted': 0,
|
||||
'deleted_at': None,
|
||||
'grantee_group': None,
|
||||
'updated_at': None
|
||||
}
|
||||
|
||||
def _create_security_group(self, values):
|
||||
v = self._get_base_values()
|
||||
v.update(values)
|
||||
return db.security_group_create(self.ctxt, v)
|
||||
|
||||
def _create_security_group_rule(self, values):
|
||||
v = self._get_base_rule_values()
|
||||
v.update(values)
|
||||
return db.security_group_rule_create(self.ctxt, v)
|
||||
|
||||
def test_instance_get_all_by_grantee_security_groups(self):
|
||||
instance1 = self.create_instance_with_args()
|
||||
instance2 = self.create_instance_with_args()
|
||||
instance3 = self.create_instance_with_args()
|
||||
secgroup1 = self._create_security_group(
|
||||
{'name': 'fake-secgroup1', 'instances': [instance1]})
|
||||
secgroup2 = self._create_security_group(
|
||||
{'name': 'fake-secgroup2', 'instances': [instance1]})
|
||||
secgroup3 = self._create_security_group(
|
||||
{'name': 'fake-secgroup3', 'instances': [instance2]})
|
||||
secgroup4 = self._create_security_group(
|
||||
{'name': 'fake-secgroup4', 'instances': [instance2, instance3]})
|
||||
self._create_security_group_rule({'grantee_group': secgroup1,
|
||||
'parent_group': secgroup3})
|
||||
self._create_security_group_rule({'grantee_group': secgroup2,
|
||||
'parent_group': secgroup4})
|
||||
group_ids = [secgroup['id'] for secgroup in [secgroup1, secgroup2]]
|
||||
instances = db.instance_get_all_by_grantee_security_groups(self.ctxt,
|
||||
group_ids)
|
||||
instance_uuids = [instance['uuid'] for instance in instances]
|
||||
self.assertEqual(len(instances), 2)
|
||||
self.assertIn(instance2['uuid'], instance_uuids)
|
||||
self.assertIn(instance3['uuid'], instance_uuids)
|
||||
|
||||
def test_instance_get_all_by_grantee_security_groups_empty_group_ids(self):
|
||||
results = db.instance_get_all_by_grantee_security_groups(self.ctxt, [])
|
||||
self.assertEqual([], results)
|
||||
|
||||
def test_instance_get_all_hung_in_rebooting(self):
|
||||
# Ensure no instances are returned.
|
||||
results = db.instance_get_all_hung_in_rebooting(self.ctxt, 10)
|
||||
|
||||
@@ -1928,23 +1928,6 @@ class _TestInstanceListObject(object):
|
||||
inst.destroy()
|
||||
self.assertFalse(db.security_group_in_use(self.context, db_sg.id))
|
||||
|
||||
def test_get_by_grantee_security_group_ids(self):
|
||||
fake_instances = [
|
||||
fake_instance.fake_db_instance(id=1),
|
||||
fake_instance.fake_db_instance(id=2)
|
||||
]
|
||||
|
||||
with mock.patch.object(
|
||||
db, 'instance_get_all_by_grantee_security_groups') as igabgsg:
|
||||
igabgsg.return_value = fake_instances
|
||||
secgroup_ids = [1]
|
||||
instances = objects.InstanceList.get_by_grantee_security_group_ids(
|
||||
self.context, secgroup_ids)
|
||||
igabgsg.assert_called_once_with(self.context, secgroup_ids)
|
||||
|
||||
self.assertEqual(2, len(instances))
|
||||
self.assertEqual([1, 2], [x.id for x in instances])
|
||||
|
||||
@mock.patch('nova.db.api.instance_get_all_uuids_by_hosts')
|
||||
def test_get_uuids_by_host_no_match(self, mock_get_all):
|
||||
mock_get_all.return_value = collections.defaultdict(list)
|
||||
|
||||
Reference in New Issue
Block a user