@@ -0,0 +1,3084 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4%0A#%0A#    Copyright 2010 OpenStack LLC%0A#%0A#    Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A#    not use this file except in compliance with the License. You may obtain%0A#    a copy of the License at%0A#%0A#         http://www.apache.org/licenses/LICENSE-2.0%0A#%0A#    Unless required by applicable law or agreed to in writing, software%0A#    distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A#    License for the specific language governing permissions and limitations%0A#    under the License.%0A%0Afrom nova import flags%0Afrom nova import test%0Afrom nova.virt import libvirt_conn%0A%0AFLAGS = flags.FLAGS%0A%0A%0Aclass LibvirtConnTestCase(test.TrialTestCase):%0A    def test_get_uri_and_template(self):%0A        class MockDataModel(object):%0A            def __init__(self):%0A                self.datamodel = %7B 'name' : 'i-cafebabe',%0A                                   'memory_kb' : '1024000',%0A                                   'basepath' : '/some/path',%0A                                   'bridge_name' : 'br100',%0A                                   'mac_address' : '02:12:34:46:56:67',%0A                                   'vcpus' : 2 %7D%0A%0A        type_uri_map = %7B 'qemu' : ('qemu:///system',%0A                                %5Blambda s: '%3Cdomain type=%5C'qemu%5C'%3E' in s,%0A                                 lambda s: 'type%3Ehvm%3C/type' in s,%0A                                 lambda s: 'emulator%3E/usr/bin/kvm' not in s%5D),%0A                         'kvm' : ('qemu:///system',%0A                                %5Blambda s: '%3Cdomain type=%5C'kvm%5C'%3E' in s,%0A                                 lambda s: 'type%3Ehvm%3C/type' in s,%0A                                 lambda s: 'emulator%3E/usr/bin/qemu%3C' not in s%5D),%0A                         'uml' : ('uml:///system',%0A                                %5Blambda s: '%3Cdomain type=%5C'uml%5C'%3E' in s,%0A                                 lambda s: 'type%3Euml%3C/type' in s%5D),%0A                          %7D%0A%0A        for (libvirt_type,(expected_uri, checks)) in type_uri_map.iteritems():%0A            FLAGS.libvirt_type = libvirt_type%0A            conn = libvirt_conn.LibvirtConnection(True)%0A%0A            uri, template = conn.get_uri_and_template()%0A            self.assertEquals(uri, expected_uri)%0A%0A            for i, check in enumerate(checks):%0A                xml = conn.toXml(MockDataModel())%0A                self.assertTrue(check(xml), '%25s failed check %25d' %25 (xml, i))%0A%0A        # Deliberately not just assigning this string to FLAGS.libvirt_uri and%0A        # checking against that later on. This way we make sure the%0A        # implementation doesn't fiddle around with the FLAGS.%0A        testuri = 'something completely different'%0A        FLAGS.libvirt_uri = testuri%0A        for (libvirt_type,(expected_uri, checks)) in type_uri_map.iteritems():%0A            FLAGS.libvirt_type = libvirt_type%0A            conn = libvirt_conn.LibvirtConnection(True)%0A            uri, template = conn.get_uri_and_template()%0A            self.assertEquals(uri, testuri)%0A%0A

Add new libvirt_type option "uml" for user-mode-linux.. This switches the libvirt URI to uml:///system and uses a different template for the libvirt xml.