~ubuntu-branches/ubuntu/vivid/neutron/vivid-proposed

« back to all changes in this revision

Viewing changes to neutron/db/securitygroups_db.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Corey Byrant
  • Date: 2015-10-15 08:56:04 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20151015085604-zmf42dhshxz2qjad
Tags: 1:2015.1.2-0ubuntu1
[ Chuck Short ]
* Resynchronize with stable/kilo (7dbaa12) (LP: #1506058):
  - [7dbaa12] Changed filter field to router_id
  - [6c55f58] Do not log an error when deleting a linuxbridge does not exist
  - [118a76f] metadata: don't crash proxy on non-unicode user data
  - [eec8c50] Only get host data for floating ips on DVR routers
  - [9950ce2] Update dhcp host portbinding on failover
  - [1c87d72] func: Don't use private method of AsyncProcess
  - [834279c] Allow setting Agents description to None
  - [2f85b22] Process user iptables rules before INVALID
  - [f232475] Execute ipset command using check_exit_code
  - [d78899d] Don't write DHCP opts for SLAAC entries
  - [cb0554f] Check idl.run() return value before blocking
  - [2224851] Stop sending gratuitous arp when ip version is 6
  - [96276d5] Fix _ensure_default_security_group logic
  - [66a5116] Remove hack for sending gratuitous arp from fip ns
  - [2394418] populate port security default into network
  - [fc1c812] Remove early yields in _iter_hosts in dhcp agent
  - [2ead51a] Enable servicing lbaasV2 vip by DVR
  - [9498ea2] Descheduling DVR routers when ports are unbound from VM
  - [c74b05e] Bug-Fix for unexpected DHCP agent redundant
  - [e6a0e7d] Switch to dictionary for iptables find
  - [c377330] Add configurable options for HA networks
  - [114949b] Fix ipset can't be destroyed when last rule is deleted
  - [aba5e82] Updated NSXv plugin parameter descriptions
  - [d1a48f7] ovs: don't use ARP responder for IPv6 addresses
  - [4d15b6f] Configure gw_iface for RAs only in Master HA Router
  - [6975b2b] Register extraroute extension
  - [19d5ba4] Broadcast service port's arp in DVR
  - [767cea2] Stop device_owner from being set to 'network:*'
  - [2a6b34e] Fix a wrong condition for the _purge_metering_info function
  - [bf28c72] Add ARP spoofing protection for LinuxBridge agent
  - [635d5cf] Correct neutron-ns-metadata-proxy command when watch_log is
              False
  - [cc791b0] Fix usage of netaddr '.broadcast'
  - [f57a90a] Switch to using os-testr's copy of subunit2html
  - [c1201a2] Add optional file permission argument to replace_file()
  - [533900c] Adding loadbalanacerv2 device owner constant to neutron
              constants
  - [2a00016] Don't fatal error during initialization for missing service
              providers
  - [7c2727c] Update port bindings for master router
  - [6298a90] Setup reference service providers for API test runs
  - [6167d44] Move away nested transaction from _ensure_default_security_group
  - [c129bfa] Reject router-interface-add with a port which doesn't have any
              addresses
  - [770a105] SR-IOV: Fix SR-IOV agent to run ip link commands as root
  - [a0632d7] Catch ObjectDeletedError and skip port or subnet removal
  - [c4c8686] Cleanup stale metadata processes on l3 agent sync
  - [0c22d15] Bump stable/kilo next version to 2015.1.2
  - [4f9409d] lb-agent: ensure tap mtu is the same as physical device
  - [5d38dc5] Adds garp_master_repeat and garp_master_refresh to
              keepalived.conf
  - [e759c1c] Lower log level of errors caused by user requests to INFO
  - [1a1cc3d] Fix race condition by using lock on enable_radvd
  - [5827664] Remove bridge cleanup call
  - [23f5134] Added networking-plumgrid in plugin requirements

[ Corey Byrant ]
* d/rules: Prevent dh_python2 from guessing dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    under the License.
14
14
 
15
15
import netaddr
16
 
from oslo_db import exception
 
16
from oslo_db import exception as db_exc
17
17
from oslo_log import log as logging
18
18
import sqlalchemy as sa
19
19
from sqlalchemy import orm
149
149
        if not default_sg:
150
150
            self._ensure_default_security_group(context, tenant_id)
151
151
 
152
 
        with context.session.begin(subtransactions=True):
 
152
        with db_api.autonested_transaction(context.session):
153
153
            security_group_db = SecurityGroup(id=s.get('id') or (
154
154
                                              uuidutils.generate_uuid()),
155
155
                                              description=s['description'],
646
646
    def _ensure_default_security_group(self, context, tenant_id):
647
647
        """Create a default security group if one doesn't exist.
648
648
 
649
 
        :returns: the default security group id.
 
649
        :returns: the default security group id for given tenant.
650
650
        """
651
 
        query = self._model_query(context, DefaultSecurityGroup)
652
 
        # the next loop should do 2 iterations at max
653
 
        while True:
 
651
        # Make no more than two attempts
 
652
        for attempts in (1, 2):
654
653
            try:
 
654
                query = self._model_query(context, DefaultSecurityGroup)
655
655
                default_group = query.filter_by(tenant_id=tenant_id).one()
656
 
            except exc.NoResultFound:
 
656
                return default_group['security_group_id']
 
657
            except exc.NoResultFound as ex:
 
658
                if attempts > 1:
 
659
                    # the second iteration means that attempt to add default
 
660
                    # group failed with duplicate error. Since we're still
 
661
                    # not seeing this group we're most probably inside a
 
662
                    # transaction with REPEATABLE READ isolation level ->
 
663
                    # need to restart the whole transaction
 
664
                    raise db_exc.RetryRequest(ex)
 
665
 
657
666
                security_group = {
658
667
                    'security_group':
659
668
                        {'name': 'default',
661
670
                         'description': _('Default security group')}
662
671
                }
663
672
                try:
664
 
                    with db_api.autonested_transaction(context.session):
665
 
                        ret = self.create_security_group(
666
 
                            context, security_group, default_sg=True)
667
 
                except exception.DBDuplicateEntry as ex:
 
673
                    security_group = self.create_security_group(
 
674
                        context, security_group, default_sg=True)
 
675
                    return security_group['id']
 
676
                except db_exc.DBDuplicateEntry as ex:
 
677
                    # default security group was created concurrently
668
678
                    LOG.debug("Duplicate default security group %s was "
669
679
                              "not created", ex.value)
670
 
                    continue
671
 
                else:
672
 
                    return ret['id']
673
 
            else:
674
 
                return default_group['security_group_id']
675
680
 
676
681
    def _get_security_groups_on_port(self, context, port):
677
682
        """Check that all security groups on port belong to tenant.