From 936140de2c42b8e1b4cf1edde1e6fb25bcd75c59 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 25 Jun 2012 21:14:11 +0000 Subject: Re-factor instance DB creation This patch speeds up the DB creation process considerably in deployments with a considerable amount of instances. It also cleans up a lot of the code which ends up creating the instance DB record. The biggest improvement in this patch is removing unnecessary joins in security_groups DB calls. This also reduces the number of DB calls needed to create an instance DB record in general. Side effect of this patch is the default 'display_name' for an instance when it (or hostname) is not specified is now 'Server ' vs 'Server '. Because of the use of 'id', it required creating the DB record, then updating the record later after we new the 'id'. This is gone. Fixes bug 1017722 Change-Id: I9b7d48644a7abe075545c2c11399351b6a37939c --- nova/tests/compute/test_compute.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index c816acc95..e77b0fcdb 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -2159,7 +2159,20 @@ class ComputeAPITestCase(BaseTestCase): len(db.instance_get_all(context.get_admin_context()))) def test_default_hostname_generator(self): - cases = [(None, 'server-1'), ('Hello, Server!', 'hello-server'), + fake_uuids = [str(utils.gen_uuid()) for x in xrange(4)] + + orig_populate = self.compute_api._populate_instance_for_create + + def _fake_populate(base_options, *args, **kwargs): + base_options['uuid'] = fake_uuids.pop(0) + return orig_populate(base_options, *args, **kwargs) + + self.stubs.Set(self.compute_api, + '_populate_instance_for_create', + _fake_populate) + + cases = [(None, 'server-%s' % fake_uuids[0]), + ('Hello, Server!', 'hello-server'), ('<}\x1fh\x10e\x08l\x02l\x05o\x12!{>', 'hello'), ('hello_server', 'hello-server')] for display_name, hostname in cases: -- cgit