示例#1
0
    def test_check_environment_unsupported(self, *_):
        dmm = MockDockerManager()
        dmm.command = lambda *a, **kw: raise_exception('Docker not available')
        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        with self.assertRaises(EnvironmentError):
            dmm.check_environment()

        assert not dmm.pull_images.called
        assert not dmm.build_images.called
        assert dmm._env_checked
示例#2
0
    def test_check_environment_none(self, *_):
        dmm = MockDockerManager()
        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        with self.assertRaises(EnvironmentError):
            dmm.check_environment()

        assert not dmm.hypervisor
        assert not dmm.pull_images.called
        assert not dmm.build_images.called
        assert dmm._env_checked
示例#3
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)
示例#4
0
    def test_check_environment_windows_no_hyperv(self, *_):
        dmm = MockDockerManager()
        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        with mock.patch('golem.docker.manager.VirtualBoxHypervisor.instance',
                        mock.Mock(vm_running=mock.Mock(return_value=False))):
            # pylint: disable=no-member

            with mock.patch.object(dmm, 'command'):
                dmm.check_environment()

                assert dmm.hypervisor
                assert dmm.hypervisor.setup.called
                assert dmm.pull_images.called
                assert not dmm.build_images.called
示例#5
0
    def test_check_environment_linux(self, *_):
        dmm = MockDockerManager()
        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        with mock.patch.object(dmm, 'command'):
            assert not dmm.check_environment()
            assert dmm.pull_images.called
            assert not dmm.build_images.called
            assert not dmm.hypervisor
            assert dmm._env_checked
示例#6
0
    def test_check_environment_osx(self, *_):
        dmm = MockDockerManager()
        hypervisor = mock.Mock(
            start_vm=mock.Mock(),
            stop_vm=mock.Mock(),
            vm_running=mock.Mock(return_value=False),
        )

        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        with mock.patch('golem.docker.manager.XhyveHypervisor.instance',
                        hypervisor):
            # pylint: disable=no-member

            with mock.patch.object(dmm, 'command'):
                dmm.check_environment()

                assert not dmm.hypervisor.create.called
                assert dmm.pull_images.called
                assert not dmm.build_images.called
                assert not dmm.hypervisor.start_vm.called
                assert not dmm.hypervisor._set_env.called
示例#7
0
    def test_update_config(self):
        status_switch = [True]

        def status_cb():
            if status_switch[0]:
                status_switch[0] = False
                return True
            else:
                return status_switch[0]

        def done_cb(_):
            pass

        config = ConfigMock(0, 768)

        dmm = MockDockerManager()
        dmm.pull_images = mock.Mock()
        dmm.build_images = mock.Mock()

        hypervisor = mock.Mock()
        hypervisor.constraints.return_value = DEFAULTS

        dmm._select_hypervisor = mock.Mock(return_value=hypervisor)

        with mock.patch.object(dmm, 'command'):
            dmm.build_config(config)
            dmm.check_environment()

        dmm.update_config(status_cb,
                          done_cb,
                          in_background=False,
                          work_dir=None)
        dmm.update_config(status_cb,
                          done_cb,
                          in_background=True,
                          work_dir=None)