

@mock.patch('nova.compute.utils.refresh_info_cache_for_instance')
def test_delete_security_group_in_use(self, refresh_info_cache_mock):
    sg = self._create_sg_template().get('security_group')
    self._create_network()
    db_inst = fakes.stub_instance(id=1, nw_cache=[], security_groups=[])
    _context = context.get_admin_context()
    instance = instance_obj.Instance._from_db_object(_context, instance_obj.Instance(), db_inst, expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
    neutron = neutron_api.API()
    with mock.patch.object(nova.db, 'instance_get_by_uuid', return_value=db_inst):
        neutron.allocate_for_instance(_context, instance, security_groups=[sg['id']])
    req = fakes.HTTPRequest.blank(('/v2/fake/os-security-groups/%s' % sg['id']))
    self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, req, sg['id'])

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py TestNeutronSecurityGroupsV21.test_delete_security_group_in_use/original