示例#1
0
    def test_recover_vm_connectivity(self):
        callback = mock.Mock()

        dmm = MockDockerManager()
        dmm._save_and_resume = mock.Mock()
        dmm.check_environment = mock.Mock()

        def reset():
            callback.called = False
            dmm.check_environment.called = False
            dmm._save_and_resume.called = False

        dmm._env_checked = True

        dmm.recover_vm_connectivity(callback, in_background=False)
        assert not dmm._save_and_resume.called

        reset()

        dmm._env_checked = False

        dmm.recover_vm_connectivity(callback, in_background=False)
        assert not dmm._save_and_resume.called

        reset()

        dmm._env_checked = True
        dmm.hypervisor = MockHypervisor(dmm)

        dmm.recover_vm_connectivity(callback, in_background=False)
        assert dmm._save_and_resume.called

        reset()
        dmm.recover_vm_connectivity(callback, in_background=True)
示例#2
0
    def test_constrain_not_called(self):
        dmm = MockDockerManager()
        dmm._diff_constraints = mock.Mock(return_value=dict())

        dmm.hypervisor = MockHypervisor(dmm)

        dmm.constrain()
        assert not dmm.hypervisor.constrain.called
示例#3
0
    def test_save_and_resume(self):
        dmm = MockDockerManager()
        dmm.hypervisor = MockHypervisor(dmm)
        dmm.hypervisor.command = mock.Mock()
        dmm.hypervisor._set_env_from_output = mock.Mock()
        dmm.hypervisor._set_env()

        callback = mock.Mock()
        dmm._save_and_resume(callback)
        assert callback.called
示例#4
0
    def test_constrain_called(self):
        diff = dict(cpu_count=0)
        dmm = MockDockerManager()
        dmm._diff_constraints = mock.Mock(return_value=diff)

        dmm.hypervisor = MockHypervisor(dmm)
        dmm.hypervisor._set_env = mock.Mock()

        dmm.constrain()
        assert dmm.hypervisor.constrain.called

        _, kwargs = dmm.hypervisor.constrain.call_args_list.pop()

        assert len(kwargs) == len(diff)
        assert kwargs['cpu_count'] == DEFAULTS['cpu_count']
        assert kwargs['memory_size'] == DEFAULTS['memory_size']
示例#5
0
 def test_build_config_odd_memory_size(self):
     manager = MockDockerManager()
     manager.hypervisor = MockHypervisor(manager)
     config = ConfigMock(None, 1025 * 1024)
     manager.build_config(config)
     self.assertEqual(manager.get_config()['memory_size'], 1024)