~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_libvirt_vif.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    License for the specific language governing permissions and limitations
15
15
#    under the License.
16
16
 
17
 
from xml.etree import ElementTree
 
17
from lxml import etree
18
18
 
19
19
from nova import flags
20
20
from nova import test
21
21
from nova import utils
22
22
from nova.virt import firewall
 
23
from nova.virt.libvirt import config
 
24
from nova.virt.libvirt import connection
23
25
from nova.virt.libvirt import vif
24
 
from nova.virt.libvirt import connection
25
26
 
26
27
FLAGS = flags.FLAGS
27
28
 
51
52
    }
52
53
 
53
54
    instance = {
 
55
        'name': 'instance-name',
54
56
        'uuid': 'instance-uuid'
55
57
    }
56
58
 
64
66
            return None, None
65
67
 
66
68
        self.stubs.Set(utils, 'execute', fake_execute)
67
 
        t = __import__('Cheetah.Template', globals(), locals(),
68
 
                       ['Template'], -1)
69
 
        self.Template = t.Template
70
 
        xml_file = open(FLAGS.libvirt_xml_template)
71
 
        self.xml_template = xml_file.read()
72
 
 
73
 
    def _create_xml_info(self, vif_type, nics):
74
 
        return     {
75
 
                    'type': 'qemu',
76
 
                    'name': 'fake-name',
77
 
                    'uuid': 'fake-uuid',
78
 
                    'memory_kb': 100 * 1024,
79
 
                    'basepath': 'foobar',
80
 
                    'vcpus': 4,
81
 
                    'rescue': False,
82
 
                    'disk_prefix': '/dev/sda',
83
 
                    'driver_type': 'raw',
84
 
                    'root_device_type': 'disk',
85
 
                    'vif_type': vif_type,
86
 
                    'nics': nics,
87
 
                    'ebs_root': True,
88
 
                    'ephemeral_device': False,
89
 
                    'volumes': [],
90
 
                    'use_virtio_for_bridges': False,
91
 
                    'ephemerals': []}
92
 
 
93
 
    def _get_instance_xml(self, driver, vif_type):
94
 
        nic_dict = driver.plug(self.instance, self.net, self.mapping)
95
 
        xml_info = self._create_xml_info(vif_type, [nic_dict])
96
 
        xml = str(self.Template(self.xml_template, searchList=[xml_info]))
97
 
        return xml
 
69
 
 
70
    def _get_instance_xml(self, driver):
 
71
        conf = config.LibvirtConfigGuest()
 
72
        conf.virt_type = "qemu"
 
73
        conf.name = "fake-name"
 
74
        conf.uuid = "fake-uuid"
 
75
        conf.memory = 100 * 1024
 
76
        conf.vcpus = 4
 
77
 
 
78
        nic = driver.plug(self.instance, self.net, self.mapping)
 
79
        conf.add_device(nic)
 
80
        return conf.to_xml()
98
81
 
99
82
    def test_bridge_driver(self):
100
83
        d = vif.LibvirtBridgeDriver()
101
 
        xml = self._get_instance_xml(d, 'bridge')
 
84
        xml = self._get_instance_xml(d)
102
85
 
103
 
        doc = ElementTree.fromstring(xml)
 
86
        doc = etree.fromstring(xml)
104
87
        ret = doc.findall('./devices/interface')
105
88
        self.assertEqual(len(ret), 1)
106
89
        node = ret[0]
114
97
 
115
98
    def test_ovs_ethernet_driver(self):
116
99
        d = vif.LibvirtOpenVswitchDriver()
117
 
        xml = self._get_instance_xml(d, 'ethernet')
 
100
        xml = self._get_instance_xml(d)
118
101
 
119
 
        doc = ElementTree.fromstring(xml)
 
102
        doc = etree.fromstring(xml)
120
103
        ret = doc.findall('./devices/interface')
121
104
        self.assertEqual(len(ret), 1)
122
105
        node = ret[0]
132
115
 
133
116
    def test_ovs_virtualport_driver(self):
134
117
        d = vif.LibvirtOpenVswitchVirtualPortDriver()
135
 
        xml = self._get_instance_xml(d, 'ovs_virtualport')
 
118
        xml = self._get_instance_xml(d)
136
119
 
137
 
        doc = ElementTree.fromstring(xml)
 
120
        doc = etree.fromstring(xml)
138
121
        ret = doc.findall('./devices/interface')
139
122
        self.assertEqual(len(ret), 1)
140
123
        node = ret[0]
158
141
 
159
142
    def test_quantum_bridge_ethernet_driver(self):
160
143
        d = vif.QuantumLinuxBridgeVIFDriver()
161
 
        xml = self._get_instance_xml(d, 'ethernet')
 
144
        xml = self._get_instance_xml(d)
162
145
 
163
 
        doc = ElementTree.fromstring(xml)
 
146
        doc = etree.fromstring(xml)
164
147
        ret = doc.findall('./devices/interface')
165
148
        self.assertEqual(len(ret), 1)
166
149
        node = ret[0]