def setUp(self): """Run before each test method to initialize test environment""" super(TestCase, self).setUp() # NOTE(vish): We need a better method for creating fixtures for tests # now that we have some required db setup for the system # to work properly. self.start = datetime.datetime.utcnow() ctxt = context.get_admin_context() if db.network_count(ctxt) != 5: network_manager.VlanManager().create_networks(ctxt, FLAGS.fixed_range, 5, 16, FLAGS.fixed_range_v6, FLAGS.vlan_start, FLAGS.vpn_start, ) # emulate some of the mox stuff, we can't use the metaclass # because it screws with our generators self.mox = mox.Mox() self.stubs = stubout.StubOutForTesting() self.flag_overrides = {} self.injected = [] self._monkey_patch_attach() self._original_flags = FLAGS.FlagValuesDict()
def test_too_many_networks(self): """Ensure error is raised if we run out of networks""" projects = [] networks_left = (FLAGS.num_networks - db.network_count(context.get_admin_context())) for i in range(networks_left): project = self.manager.create_project('many%s' % i, self.user) projects.append(project) db.project_get_network(context.get_admin_context(), project.id) project = self.manager.create_project('last', self.user) projects.append(project) self.assertRaises(db.NoMoreNetworks, db.project_get_network, context.get_admin_context(), project.id) for project in projects: self.manager.delete_project(project)