示例#1
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
示例#2
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
示例#3
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
示例#4
0
    def test_pull_images(self):
        pulls = [0]

        def command(key, *args, **kwargs):
            if key == 'images':
                return ''
            elif key == 'pull':
                pulls[0] += 1
                return True

        with mock.patch.object(MockDockerManager,
                               'command',
                               side_effect=command):
            dmm = MockDockerManager()
            dmm.pull_images()

        from apps.core import nvgpu
        if nvgpu.is_supported():
            expected = 5
        else:
            expected = 3

        assert pulls[0] == expected
示例#5
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
示例#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)