コード例 #1
0
ファイル: qubesvm.py プロジェクト: xaki23/qubes-core-admin
 def test_600_libvirt_xml_pv(self):
     expected = '''<domain type="xen">
     <name>test-inst-test</name>
     <uuid>7db78950-c467-4863-94d1-af59806384ea</uuid>
     <memory unit="MiB">500</memory>
     <currentMemory unit="MiB">400</currentMemory>
     <vcpu placement="static">2</vcpu>
     <os>
         <type arch="x86_64" machine="xenpv">linux</type>
         <kernel>/tmp/kernel/vmlinuz</kernel>
         <initrd>/tmp/kernel/initramfs</initrd>
         <cmdline>root=/dev/mapper/dmroot ro nomodeset console=hvc0 rd_NO_PLYMOUTH rd.plymouth.enable=0 plymouth.enable=0 nopat</cmdline>
     </os>
     <features>
     </features>
     <clock offset='utc' adjustment='reset'>
         <timer name="tsc" mode="native"/>
     </clock>
     <on_poweroff>destroy</on_poweroff>
     <on_reboot>destroy</on_reboot>
     <on_crash>destroy</on_crash>
     <devices>
         <disk type="block" device="disk">
             <driver name="phy" />
             <source dev="/tmp/kernel/modules.img" />
             <target dev="xvdd" />
             <backenddomain name="dom0" />
         </disk>
         <console type="pty">
             <target type="xen" port="0"/>
         </console>
     </devices>
     </domain>
     '''
     my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
     vm = self.get_vm(uuid=my_uuid)
     vm.netvm = None
     vm.virt_mode = 'pv'
     with unittest.mock.patch('qubes.config.qubes_base_dir',
                              '/tmp/qubes-test'):
         kernel_dir = '/tmp/qubes-test/vm-kernels/dummy'
         os.makedirs(kernel_dir, exist_ok=True)
         open(os.path.join(kernel_dir, 'vmlinuz'), 'w').close()
         open(os.path.join(kernel_dir, 'initramfs'), 'w').close()
         self.addCleanup(shutil.rmtree, '/tmp/qubes-test')
         vm.kernel = 'dummy'
     # tests for storage are later
     vm.volumes['kernel'] = unittest.mock.Mock(
         **{
             'kernels_dir': '/tmp/kernel',
             'block_device.return_value.domain': 'dom0',
             'block_device.return_value.script': None,
             'block_device.return_value.path': '/tmp/kernel/modules.img',
             'block_device.return_value.devtype': 'disk',
             'block_device.return_value.name': 'kernel',
         })
     libvirt_xml = vm.create_config_file()
     self.assertXMLEqual(lxml.etree.XML(libvirt_xml),
                         lxml.etree.XML(expected))
コード例 #2
0
ファイル: qubesvm.py プロジェクト: xaki23/qubes-core-admin
 def test_600_libvirt_xml_hvm(self):
     expected = '''<domain type="xen">
     <name>test-inst-test</name>
     <uuid>7db78950-c467-4863-94d1-af59806384ea</uuid>
     <memory unit="MiB">500</memory>
     <currentMemory unit="MiB">400</currentMemory>
     <vcpu placement="static">2</vcpu>
     <cpu mode='host-passthrough'>
         <!-- disable nested HVM -->
         <feature name='vmx' policy='disable'/>
         <feature name='svm' policy='disable'/>
         <!-- disable SMAP inside VM, because of Linux bug -->
         <feature name='smap' policy='disable'/>
     </cpu>
     <os>
         <type arch="x86_64" machine="xenfv">hvm</type>
             <!--
                  For the libxl backend libvirt switches between OVMF (UEFI)
                  and SeaBIOS based on the loader type. This has nothing to
                  do with the hvmloader binary.
             -->
         <loader type="rom">hvmloader</loader>
         <boot dev="cdrom" />
         <boot dev="hd" />
     </os>
     <features>
         <pae/>
         <acpi/>
         <apic/>
         <viridian/>
     </features>
     <clock offset="variable" adjustment="0" basis="localtime" />
     <on_poweroff>destroy</on_poweroff>
     <on_reboot>destroy</on_reboot>
     <on_crash>destroy</on_crash>
     <devices>
         <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
         <emulator type="stubdom-linux" />
         <input type="tablet" bus="usb"/>
         <video>
             <model type="vga"/>
         </video>
         <graphics type="qubes"/>
     </devices>
     </domain>
     '''
     my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
     vm = self.get_vm(uuid=my_uuid)
     vm.netvm = None
     vm.virt_mode = 'hvm'
     libvirt_xml = vm.create_config_file()
     self.assertXMLEqual(lxml.etree.XML(libvirt_xml),
                         lxml.etree.XML(expected))
コード例 #3
0
ファイル: qubesvm.py プロジェクト: xaki23/qubes-core-admin
 def test_610_libvirt_xml_network(self):
     expected = '''<domain type="xen">
     <name>test-inst-test</name>
     <uuid>7db78950-c467-4863-94d1-af59806384ea</uuid>
     <memory unit="MiB">500</memory>
     <currentMemory unit="MiB">400</currentMemory>
     <vcpu placement="static">2</vcpu>
     <cpu mode='host-passthrough'>
         <!-- disable nested HVM -->
         <feature name='vmx' policy='disable'/>
         <feature name='svm' policy='disable'/>
         <!-- disable SMAP inside VM, because of Linux bug -->
         <feature name='smap' policy='disable'/>
     </cpu>
     <os>
         <type arch="x86_64" machine="xenfv">hvm</type>
             <!--
                  For the libxl backend libvirt switches between OVMF (UEFI)
                  and SeaBIOS based on the loader type. This has nothing to
                  do with the hvmloader binary.
             -->
         <loader type="rom">hvmloader</loader>
         <boot dev="cdrom" />
         <boot dev="hd" />
     </os>
     <features>
         <pae/>
         <acpi/>
         <apic/>
         <viridian/>
     </features>
     <clock offset="variable" adjustment="0" basis="localtime" />
     <on_poweroff>destroy</on_poweroff>
     <on_reboot>destroy</on_reboot>
     <on_crash>destroy</on_crash>
     <devices>
         <interface type="ethernet">
             <mac address="00:16:3E:5E:6C:00" />
             <ip address="10.137.0.1" />
             {extra_ip}
             <backenddomain name="test-inst-netvm" />
             <script path="vif-route-qubes" />
         </interface>
         <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
         <emulator type="stubdom-linux" />
         <input type="tablet" bus="usb"/>
         <video>
             <model type="vga"/>
         </video>
         <graphics type="qubes"/>
     </devices>
     </domain>
     '''
     my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
     netvm = self.get_vm(qid=2, name='netvm', provides_network=True)
     vm = self.get_vm(uuid=my_uuid)
     vm.netvm = netvm
     vm.virt_mode = 'hvm'
     with self.subTest('ipv4_only'):
         libvirt_xml = vm.create_config_file()
         self.assertXMLEqual(lxml.etree.XML(libvirt_xml),
                             lxml.etree.XML(expected.format(extra_ip='')))
     with self.subTest('ipv6'):
         netvm.features['ipv6'] = True
         libvirt_xml = vm.create_config_file()
         self.assertXMLEqual(
             lxml.etree.XML(libvirt_xml),
             lxml.etree.XML(
                 expected.format(
                     extra_ip='<ip address="{}::a89:1" family=\'ipv6\'/>'.
                     format(
                         qubes.config.qubes_ipv6_prefix.replace(
                             ':0000', '')))))
コード例 #4
0
ファイル: qubesvm.py プロジェクト: xaki23/qubes-core-admin
 def test_600_libvirt_xml_hvm_dom0_kernel(self):
     expected = '''<domain type="xen">
     <name>test-inst-test</name>
     <uuid>7db78950-c467-4863-94d1-af59806384ea</uuid>
     <memory unit="MiB">500</memory>
     <currentMemory unit="MiB">400</currentMemory>
     <vcpu placement="static">2</vcpu>
     <cpu mode='host-passthrough'>
         <!-- disable nested HVM -->
         <feature name='vmx' policy='disable'/>
         <feature name='svm' policy='disable'/>
         <!-- disable SMAP inside VM, because of Linux bug -->
         <feature name='smap' policy='disable'/>
     </cpu>
     <os>
         <type arch="x86_64" machine="xenfv">hvm</type>
             <!--
                  For the libxl backend libvirt switches between OVMF (UEFI)
                  and SeaBIOS based on the loader type. This has nothing to
                  do with the hvmloader binary.
             -->
         <loader type="rom">hvmloader</loader>
         <boot dev="cdrom" />
         <boot dev="hd" />
         <cmdline>root=/dev/mapper/dmroot ro nomodeset console=hvc0 rd_NO_PLYMOUTH rd.plymouth.enable=0 plymouth.enable=0 nopat</cmdline>
     </os>
     <features>
         <pae/>
         <acpi/>
         <apic/>
         <viridian/>
     </features>
     <clock offset="variable" adjustment="0" basis="localtime" />
     <on_poweroff>destroy</on_poweroff>
     <on_reboot>destroy</on_reboot>
     <on_crash>destroy</on_crash>
     <devices>
         <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
         <emulator type="stubdom-linux" />
         <input type="tablet" bus="usb"/>
         <video>
             <model type="vga"/>
         </video>
         <graphics type="qubes"/>
     </devices>
     </domain>
     '''
     my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
     vm = self.get_vm(uuid=my_uuid)
     vm.netvm = None
     vm.virt_mode = 'hvm'
     with unittest.mock.patch('qubes.config.qubes_base_dir',
                              '/tmp/qubes-test'):
         kernel_dir = '/tmp/qubes-test/vm-kernels/dummy'
         os.makedirs(kernel_dir, exist_ok=True)
         open(os.path.join(kernel_dir, 'vmlinuz'), 'w').close()
         open(os.path.join(kernel_dir, 'initramfs'), 'w').close()
         self.addCleanup(shutil.rmtree, '/tmp/qubes-test')
         vm.kernel = 'dummy'
     libvirt_xml = vm.create_config_file()
     self.assertXMLEqual(lxml.etree.XML(libvirt_xml),
                         lxml.etree.XML(expected))