Example #1
0
 def test_encode_decode_libvirt_node(self):
     """Test encoding/decoding of libvirt node"""
     node = lnode.LibvirtNode("vnode0", "00-START-BY-CLONING-ME",
                              "/mnt/vms")
     node_desc = server.encode_node(node)
     expected = {
         'base_domain': '00-START-BY-CLONING-ME',
         'clustername': 'vnode',
         'before_start': None,
         'after_start': None,
         'after_end': None,
         'cpu': None,
         'host': 'localhost',
         'idx': 0,
         'img_path': '/mnt/vms/vnode0.qcow2',
         'storage_dir': '/mnt/vms',
         'ip': '',
         'mem': None,
         'name': 'vnode0',
         'add_iface': None,
         'status': libvirt.VIR_DOMAIN_NOSTATE
     }
     self.assertDictEqual(expected, node_desc)
     new_node = server.decode_node(node_desc)
     self.assertEqual(node, new_node)
Example #2
0
    def test_set_cpus(self):
        '''Test the cpu setting'''

        dom = """<domain type='kvm' id='9'>
  <name>vnode0</name>
  <uuid>81b20639-dba5-477e-a2da-07c88ad33f86</uuid>
  <memory unit='KiB'>9194496</memory>
  <currentMemory unit='KiB'>9194304</currentMemory>
  <vcpu placement='static'>8</vcpu>
  <cpu mode='host-model'>
    <model fallback='allow'>SandyBridge</model>
    <vendor>Intel</vendor>
    <feature policy='require' name='pdpe1gb'/>
    <feature policy='require' name='ds'/>
    <feature policy='require' name='vme'/>
  </cpu>
</domain>
"""
        node = lnode.LibvirtNode("vnode0",
                                 "00-START-BY-CLONING-ME",
                                 "/mnt/vms",
                                 cpu=2)
        tree = etree.fromstring(dom)
        new_tree = node._set_cpu(tree)
        new_dom = etree.tostring(new_tree)
        self.assertNotIn('<vcpu placement="static">8</vcpu>', new_dom)
        self.assertIn('<vcpu placement="static">2</vcpu>', new_dom)
Example #3
0
 def add_node(self, idx, host):
     """Create new node on host and add it to the cluster"""
     self.cfg['default']['host'] = host
     conf = self.cfg['default'].copy()
     conf.update(self.cfg.get(idx, {}))
     _LOGGER.debug(conf)
     if conf['vtype'] == clustdock.DOCKER_NODE:
         node = dock.DockerNode("%s%d" % (self.name, idx), **conf)
     elif conf['vtype'] == clustdock.LIBVIRT_NODE:
         node = lbv.LibvirtNode("%s%d" % (self.name, idx), **conf)
     self.nodes[node.name] = node
     return node
Example #4
0
    def test_run_hook_libvirt(self):
        """Test run hook for libvirt node"""

        content = """#!/bin/bash
echo -n "$1 $2 $3"
"""
        tmpfile = mktemp(prefix="clustdock-hook-")
        with open(tmpfile, 'w') as myfile:
            myfile.write(content)
        node = lnode.LibvirtNode("vnode0", "00-START-BY-CLONING-ME",
                                 "/mnt/vms")
        rc, stdout, stderr = node.run_hook(tmpfile, clustdock.LIBVIRT_NODE)
        self.assertEqual(rc, 126)
        self.assertEqual(stdout, "")
        self.assertIn("Permission denied", stderr)
        os.chmod(tmpfile, 0755)
        rc, stdout, stderr = node.run_hook(tmpfile, clustdock.LIBVIRT_NODE)
        self.assertEqual(rc, 0)
        self.assertEqual(
            "%s %s %s" % (node.name, clustdock.LIBVIRT_NODE, node.host),
            stdout)
        self.assertEqual("", stderr)
        self.remove_file(tmpfile)
Example #5
0
    def test_build_xml(self):
        '''Test the node xml definition'''

        dom = """<domain type="kvm" id="9">
  <name>00-START-BY-CLONING-ME</name>
  <uuid>81b20639-dba5-477e-a2da-07c88ad33f86</uuid>
  <memory unit="KiB">9194496</memory>
  <currentMemory unit="KiB">9194304</currentMemory>
  <vcpu placement="static">8</vcpu>
  <cpu mode="host-model">
    <model fallback="allow">SandyBridge</model>
    <vendor>Intel</vendor>
    <feature policy="require" name="pdpe1gb"/>
    <feature policy="require" name="ds"/>
    <feature policy="require" name="vme"/>
  </cpu>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="none"/>
      <source file="/mnt/vms/00-START-BY-CLONING-ME.img"/>
      <backingStore/>
      <target dev="vda" bus="virtio"/>
      <alias name="virtio-disk0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
    </disk>
    <interface type="bridge">
      <mac address="52:54:00:d1:e0:44"/>
      <source bridge="br0"/>
      <target dev="vnet0"/>
      <model type="virtio"/>
      <alias name="net0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
    </interface>
  </devices>
</domain>
"""
        expected_dom = """<domain type="kvm" id="9">
  <name>vnode0</name>
  <memory unit="KiB">9194496</memory>
  <currentMemory unit="KiB">9194304</currentMemory>
  <vcpu placement="static">8</vcpu>
  <cpu mode="host-model">
    <model fallback="allow">SandyBridge</model>
    <vendor>Intel</vendor>
    <feature policy="require" name="pdpe1gb"/>
    <feature policy="require" name="ds"/>
    <feature policy="require" name="vme"/>
  </cpu>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="none"/>
      <source file="/mnt/vms/vnode0.qcow2"/>
      <backingStore/>
      <target dev="vda" bus="virtio"/>
      <alias name="virtio-disk0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
    </disk>
    <interface type="bridge">
      <source bridge="br0"/>
      <target dev="vnet0"/>
      <model type="virtio"/>
      <alias name="net0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
    </interface>
  </devices>
</domain>"""
        node = lnode.LibvirtNode("vnode0", "00-START-BY-CLONING-ME",
                                 "/mnt/vms")
        new_dom = node.build_xml(dom)
        self.assertEqual(new_dom, expected_dom)