Exemplo n.º 1
0
    def testCpuPinningPerVcpu(self):
        if hv_kvm.psutil is None:
            # FIXME: switch to unittest.skip once python 2.6 is deprecated
            print "skipped 'psutil Python package not found'"
            return
        mock_process = mock.MagicMock()
        mock_process.set_cpu_affinity = mock.MagicMock()
        mock_process.set_cpu_affinity().return_value = True
        mock_process.get_children.return_value = []
        mock_process.reset_mock()

        cpu_mask = "1:2:4:5:10:15-17"
        worker_cpu_mask = self.params['worker_cpu_mask']
        hypervisor = hv_kvm.KVMHypervisor()

        # This is necessary so that it provides the same object each time instead of
        # overwriting it each time.
        def get_mock_process(unused_pid):
            return mock_process

        with nested(mock.patch('psutil.Process', get_mock_process),
                    mock.patch('psutil.cpu_count', return_value=1237)):
            hypervisor._ExecuteCpuAffinity('test_instance', cpu_mask,
                                           worker_cpu_mask)
            self.assertEqual(mock_process.set_cpu_affinity.call_count, 7)
            self.assertEqual(mock_process.set_cpu_affinity.call_args_list[0],
                             mock.call(range(0, 1237)))
            self.assertEqual(mock_process.set_cpu_affinity.call_args_list[6],
                             mock.call([15, 16, 17]))
Exemplo n.º 2
0
    def testCpuPinningEntireInstance(self):
        if hv_kvm.psutil is None:
            # FIXME: switch to unittest.skip once python 2.6 is deprecated
            print "skipped 'psutil Python package not found'"
            return
        mock_process = mock.MagicMock()
        mock_process.set_cpu_affinity = mock.MagicMock()
        mock_process.set_cpu_affinity().return_value = True
        mock_process.get_children.return_value = []
        mock_process.reset_mock()

        cpu_mask = "4"
        worker_cpu_mask = "5"
        hypervisor = hv_kvm.KVMHypervisor()

        def get_mock_process(unused_pid):
            return mock_process

        with mock.patch('psutil.Process', get_mock_process):
            hypervisor._ExecuteCpuAffinity('test_instance', cpu_mask,
                                           worker_cpu_mask)
            self.assertEqual(mock_process.set_cpu_affinity.call_count, 7)
            self.assertEqual(mock_process.set_cpu_affinity.call_args_list[0],
                             mock.call([5]))
            self.assertEqual(mock_process.set_cpu_affinity.call_args_list[1],
                             mock.call([4]))
 def testDirectoriesCreated(self):
   hypervisor = hv_kvm.KVMHypervisor()
   self.mocks['ensure_dirs'].assert_called_with([
       (PostfixMatcher('/run/ganeti/kvm-hypervisor'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/pid'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/uid'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/ctrl'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/conf'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/nic'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/chroot'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/chroot-quarantine'), 0775),
       (PostfixMatcher('/run/ganeti/kvm-hypervisor/keymap'), 0775)])
  def testCpuPinningDefault(self):
    self._skip_if_no_psutil()
    mock_process = mock.MagicMock()
    cpu_mask = self.params['cpu_mask']
    worker_cpu_mask = self.params['worker_cpu_mask']
    hypervisor = hv_kvm.KVMHypervisor()
    with nested(mock.patch('psutil.Process', return_value=mock_process),
                mock.patch('psutil.cpu_count', return_value=1237)):
      hypervisor._ExecuteCpuAffinity('test_instance', cpu_mask, worker_cpu_mask)

    self.assertEqual(mock_process.set_cpu_affinity.call_count, 1)
    self.assertEqual(mock_process.set_cpu_affinity.call_args_list[0],
                     mock.call(range(0,1237)))
Exemplo n.º 5
0
    def testCpuPinningDefault(self):
        if hv_kvm.psutil is None:
            # FIXME: switch to unittest.skip once python 2.6 is deprecated
            print "skipped 'psutil Python package not found'"
            return
        mock_process = mock.MagicMock()
        cpu_mask = self.params['cpu_mask']
        worker_cpu_mask = self.params['worker_cpu_mask']
        hypervisor = hv_kvm.KVMHypervisor()
        with nested(mock.patch('psutil.Process', return_value=mock_process),
                    mock.patch('psutil.cpu_count', return_value=1237)):
            hypervisor._ExecuteCpuAffinity('test_instance', cpu_mask,
                                           worker_cpu_mask)

        self.assertEqual(mock_process.set_cpu_affinity.call_count, 1)
        self.assertEqual(mock_process.set_cpu_affinity.call_args_list[0],
                         mock.call(range(0, 1237)))
 def testStartInstance(self):
   hypervisor = hv_kvm.KVMHypervisor()
   def RunCmd(cmd, **kwargs):
     if '--help' in cmd:
       return mock.Mock(
           failed=False, output=testutils.ReadTestData("kvm_1.1.2_help.txt"))
     if '-S' in cmd:
       self.mocks['pid_alive'].return_value = ('file', -1, True)
       return mock.Mock(failed=False)
     elif '-M' in cmd:
       return mock.Mock(failed=False, output='')
     elif '-device' in cmd:
       return mock.Mock(failed=False, output='name "virtio-blk-pci"')
     else:
       raise errors.ProgrammerError('Unexpected command: %s' % cmd)
   self.mocks['run_cmd'].side_effect = RunCmd
   hypervisor.StartInstance(self.instance, [], False)
Exemplo n.º 7
0
    def testPCI(self):
        """Test the placement of the first PCI device during startup."""
        self.MockOut(mock.patch('ganeti.utils.EnsureDirs'))
        hypervisor = hv_kvm.KVMHypervisor()
        dev_type = constants.HOTPLUG_TARGET_NIC
        kvm_devid = "nic-9e7c85f6-b6e5-4243"
        hv_dev_type = constants.HT_NIC_PARAVIRTUAL
        bus_slots = hypervisor._GetBusSlots()
        hvinfo = hv_kvm._GenerateDeviceHVInfo(dev_type, kvm_devid, hv_dev_type,
                                              bus_slots)
        # NOTE: The PCI slot is zero-based, i.e. 13th slot has addr hex(12)
        expected_hvinfo = {
            "driver": "virtio-net-pci",
            "id": kvm_devid,
            "bus": "pci.0",
            "addr": hex(constants.QEMU_DEFAULT_PCI_RESERVATIONS),
        }

        self.assertTrue(hvinfo == expected_hvinfo)
Exemplo n.º 8
0
    def testSCSI(self):
        """Test the placement of the first SCSI device during startup."""
        self.MockOut(mock.patch('ganeti.utils.EnsureDirs'))
        hypervisor = hv_kvm.KVMHypervisor()
        dev_type = constants.HOTPLUG_TARGET_DISK
        kvm_devid = "disk-932df160-7a22-4067"
        hv_dev_type = constants.HT_DISK_SCSI_BLOCK
        bus_slots = hypervisor._GetBusSlots()
        hvinfo = hv_kvm._GenerateDeviceHVInfo(dev_type, kvm_devid, hv_dev_type,
                                              bus_slots)
        expected_hvinfo = {
            "driver": "scsi-block",
            "id": kvm_devid,
            "bus": "scsi.0",
            "channel": 0,
            "scsi-id": 0,
            "lun": 0,
        }

        self.assertTrue(hvinfo == expected_hvinfo)
  def testCpuPinningEntireInstance(self):
    self._skip_if_no_psutil()
    mock_process = mock.MagicMock()
    mock_process.set_cpu_affinity = mock.MagicMock()
    mock_process.set_cpu_affinity().return_value = True
    mock_process.get_children.return_value = []
    mock_process.reset_mock()

    cpu_mask = "4"
    worker_cpu_mask = "5"
    hypervisor = hv_kvm.KVMHypervisor()

    def get_mock_process(unused_pid):
      return mock_process

    with mock.patch('psutil.Process', get_mock_process):
      hypervisor._ExecuteCpuAffinity('test_instance', cpu_mask, worker_cpu_mask)
      self.assertEqual(mock_process.set_cpu_affinity.call_count, 7)
      self.assertEqual(mock_process.set_cpu_affinity.call_args_list[0],
                       mock.call([5]))
      self.assertEqual(mock_process.set_cpu_affinity.call_args_list[1],
                       mock.call([4]))