if str(flavor) not in self.plugins:
flavor = self.default_flavor
plugin = self._get_plugin(flavor)
- with context.session.begin(subtransactions=True):
- net = plugin.create_network(context, network)
- LOG.debug(_("Created network: %(net_id)s with flavor "
- "%(flavor)s"), {'net_id': net['id'], 'flavor': flavor})
- try:
- meta_db_v2.add_network_flavor_binding(context.session,
- flavor, str(net['id']))
- except Exception:
- LOG.exception(_('Failed to add flavor bindings'))
- plugin.delete_network(context, net['id'])
- raise FaildToAddFlavorBinding()
+ net = plugin.create_network(context, network)
+ LOG.debug(_("Created network: %(net_id)s with flavor "
+ "%(flavor)s"), {'net_id': net['id'], 'flavor': flavor})
+ try:
+ meta_db_v2.add_network_flavor_binding(context.session,
+ flavor, str(net['id']))
+ except Exception:
+ LOG.exception(_('Failed to add flavor bindings'))
+ plugin.delete_network(context, net['id'])
+ raise FaildToAddFlavorBinding()
LOG.debug(_("Created network: %s"), net['id'])
self._extend_network_dict(context, net)
if str(flavor) not in self.l3_plugins:
flavor = self.default_l3_flavor
plugin = self._get_l3_plugin(flavor)
- with context.session.begin(subtransactions=True):
- r_in_db = plugin.create_router(context, router)
- LOG.debug(_("Created router: %(router_id)s with flavor "
- "%(flavor)s"),
- {'router_id': r_in_db['id'], 'flavor': flavor})
+ r_in_db = plugin.create_router(context, router)
+ LOG.debug(_("Created router: %(router_id)s with flavor "
+ "%(flavor)s"),
+ {'router_id': r_in_db['id'], 'flavor': flavor})
+ try:
meta_db_v2.add_router_flavor_binding(context.session,
flavor, str(r_in_db['id']))
+ except Exception:
+ LOG.exception(_('Failed to add flavor bindings'))
+ plugin.delete_router(context, r_in_db['id'])
+ raise FaildToAddFlavorBinding()
LOG.debug(_("Created router: %s"), r_in_db['id'])
self._extend_router_dict(context, r_in_db)
from neutron.db import models_v2
from neutron.extensions.flavor import (FLAVOR_NETWORK, FLAVOR_ROUTER)
from neutron.openstack.common import uuidutils
+from neutron.plugins.metaplugin.meta_neutron_plugin import (
+ FaildToAddFlavorBinding)
from neutron.plugins.metaplugin.meta_neutron_plugin import FlavorNotFound
from neutron.plugins.metaplugin.meta_neutron_plugin import MetaPluginV2
from neutron.tests import base
self.fail("No Error is not raised")
+ def test_create_network_flavor_fail(self):
+ with mock.patch('neutron.plugins.metaplugin.meta_db_v2.'
+ 'add_network_flavor_binding',
+ side_effect=Exception):
+ network = self._fake_network('fake1')
+ self.assertRaises(FaildToAddFlavorBinding,
+ self.plugin.create_network,
+ self.context,
+ network)
+ count = self.plugin.get_networks_count(self.context)
+ self.assertEqual(count, 0)
+
+ def test_create_router_flavor_fail(self):
+ with mock.patch('neutron.plugins.metaplugin.meta_db_v2.'
+ 'add_router_flavor_binding',
+ side_effect=Exception):
+ router = self._fake_router('fake1')
+ self.assertRaises(FaildToAddFlavorBinding,
+ self.plugin.create_router,
+ self.context,
+ router)
+ count = self.plugin.get_routers_count(self.context)
+ self.assertEqual(count, 0)
+
class MetaNeutronPluginV2TestWithoutL3(MetaNeutronPluginV2Test):
"""Tests without l3_plugin_list configration."""
def test_create_delete_router(self):
self.skipTest("Test case without router")
+
+ def test_create_router_flavor_fail(self):
+ self.skipTest("Test case without router")