Example #1
0
    def test_start_not_install(self):
        bc = Explorer('e', data=self.valid_data)
        bc._get_container = MagicMock()
        bc.api = MagicMock()
        bc._block_creator.schedule_action = MagicMock()
        bc._write_caddyfile = MagicMock()

        with pytest.raises(StateCheckError):
            bc.start()
Example #2
0
    def test_install_with_value_error(self):
        bc = Explorer('e', data=self.valid_data)

        bc.api = MagicMock()

        bc._create_blockcreator = MagicMock(side_effect=RuntimeError())
        bc._block_creator.schedule_action = MagicMock()

        # TODO: better execption catching.
        with pytest.raises(Exception):
            bc.install()
            bc.state.check('actions', 'install', 'ok')
Example #3
0
    def test_start(self):
        bc = Explorer('e', data=self.valid_data)
        bc.state.set('actions', 'install', 'ok')
        bc._get_container = MagicMock()
        bc.api = MagicMock()
        bc._block_creator.schedule_action = MagicMock()
        bc.write_caddyfile = MagicMock()

        bc.start()

        bc._get_container.assert_called_once()
        assert bc.write_caddyfile.called

        bc.state.check('status', 'running', 'ok')
        bc.state.check('actions', 'start', 'ok')
Example #4
0
    def test_uninstall_with_value_error(self):
        bc = Explorer('e', data=self.valid_data)
        bc.api = MagicMock()
        sp = MagicMock()
        fs = MagicMock()
        fs.path = 'mypath'
        fs.side_effect = ValueError()
        sp.get.return_value = fs
        bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc.state.set("actions", "install", "ok")

        bc.uninstall()
        assert fs.delete.called
        with pytest.raises(StateCheckError):
            bc.state.check('status', 'running', 'ok')
            bc.state.check('actions', 'intsall', 'ok')
Example #5
0
    def test_stop(self):
        bc = Explorer('e', data=self.valid_data)
        bc.state.set('actions', 'start', 'ok')
        bc.state.set('status', 'running', 'ok')

        bc.api = MagicMock()
        bc._container_sal.stop = MagicMock()
        bc._block_creator.schedule_action = MagicMock()

        bc.stop()

        bc._container_sal.stop.assert_called_once()
        bc._block_creator.schedule_action.assert_called_once_with("stop")

        with pytest.raises(StateCheckError):
            bc.state.check('status', 'running', 'ok')
            bc.state.check('actions', 'start', 'ok')
Example #6
0
    def test_uninstall(self):
        bc = Explorer('e', data=self.valid_data)
        sp = MagicMock()
        fs = MagicMock()
        fs.path = 'mypath'
        sp.get.return_value = fs
        bc.api = MagicMock()
        bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc._block_creator.schedule_action = MagicMock()
        bc.state.set("actions", "install", "ok")
        bc.uninstall()
        fs.delete.assert_called_once()

        bc._block_creator.schedule_action.assert_called_once()

        with pytest.raises(StateCheckError):
            bc.state.check('status', 'running', 'ok')
            bc.state.check('actions', 'intsall', 'ok')
Example #7
0
    def test_install(self):
        bc = Explorer('e', data=self.valid_data)
        # sp = MagicMock()
        # fs = MagicMock()
        # fs.path = 'mypath'
        # sp.get.return_value = fs
        # bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc.api = MagicMock()
        waitf = MagicMock()
        bc._block_creator.schedule_action = MagicMock(return_value=waitf)

        bc.install()

        assert bc.api.services.find_or_create.called
        bc._block_creator.schedule_action.assert_called_once_with("install")
        # FIXME CHECK FOR WAITF
        # assert waitf.called

        bc.state.check('actions', 'install', 'ok')
Example #8
0
    def test__get_container_installed(self):
        bc = Explorer('e', data=self.valid_data)
        bc.state.set("actions", "install", "ok")
        sp = MagicMock()
        fs = MagicMock()

        fs.path = 'mypath'
        sp.get = MagicMock(return_value=fs)
        bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc.api = MagicMock()
        bc._node_sal.client.filesystem = MagicMock()

        bc._get_caddyfile = MagicMock()
        bc._write_caddyfile = MagicMock()

        bc._get_container()

        bc._node_sal.client.filesystem.mkdir.assert_has_calls([mock.call('mypath/wallet'),
                                                               mock.call('mypath/caddy-certs')])

        assert bc._node_sal.containers.create.called
        assert bc._get_caddyfile.called