コード例 #1
0
 def reboot(self):
     updclient = jsonrpc_http.HttpServiceProxy(
         'http://localhost:8008', bus.cnf.key_path(bus.cnf.DEFAULT_KEY))
     try:
         dont_do_it = updclient.status()['state'].startswith(
             'in-progress')
     except:
         pass
     else:
         if dont_do_it:
             raise Exception(
                 'Reboot not allowed, cause Scalarizr update is in-progress'
             )
     wmi = client.GetObject('winmgmts:')
     for wos in wmi.InstancesOf('Win32_OperatingSystem'):
         if wos.Primary:
             # SCALARIZR-1609
             # XXX: Function call happens without () here for some reason,
             # as just `wos.Reboot`. Then it returns 0 and we try to call it.
             # Check if this strange behavior persists when we upgrade
             # to the latest pywin32 version (219).
             try:
                 wos.Reboot()
             except TypeError:
                 pass
コード例 #2
0
ファイル: app.py プロジェクト: worldline/scalarizr
    def _talk_to_updclient(self):
        try:
            upd = jsonrpc_http.HttpServiceProxy(
                'http://127.0.0.1:8008', bus.cnf.key_path(bus.cnf.DEFAULT_KEY))
            upd_svs = ScalrUpdClientScript()
            if not upd_svs.running:
                upd_svs.start()

            upd_status = {}

            def upd_ready():
                try:
                    self._logger.debug('Fetching UpdateClient status...')
                    upd_status.update(upd.status(cached=True))
                    self._logger.debug('UpdateClient status: %s', upd_status)
                    return upd_status['state'] != 'noop'
                except (IOError, socket.error), exc:
                    self._logger.debug('Failed to get UpdateClient status: %s',
                                       exc)
                except:
                    exc = sys.exc_info()[1]
                    if 'Server-ID header not presented' in str(exc):
                        self._logger.info((
                            'UpdateClient serves previous API version. '
                            'Looks like we are in a process of migration to new update sytem. '
                            'UpdateClient restart will handle this situation. Restarting'
                        ))
                        upd_svs.restart()
                    elif 'No module named' in str(exc):
                        self._logger.info((
                            'Scalarizr was downgraded to previous installer version. '
                            'UpdateClient restart required. Restarting'))
                        upd_svs.restart()
                    else:
                        raise
コード例 #3
0
    def _init_services(self):
        if not bus.db:
            self._init_db()

        if not bus.cnf:
            bus.cnf = config.ScalarizrCnf(self.etc_path)
            bus.cnf.bootstrap()

        if not self.queryenv:

            def init_queryenv():
                try:
                    self._init_queryenv()
                    return True
                except queryenv.InvalidSignatureError:
                    if bus.cnf.state == 'bootstrapping':
                        LOG.debug(
                            'Ignore InvalidSignatureError while Scalarizr is bootstrapping, retrying...'
                        )
                        return False
                    else:
                        raise

            wait_until(init_queryenv, timeout=120, sleep=10)

        if not self.messaging_service:
            LOG.debug('Initializing messaging')
            bus.messaging_service = P2pMessageService(
                server_id=self.server_id,
                crypto_key_path=self.crypto_file,
                producer_url=self.messaging_url,
                producer_retries_progression='1,2,5,10,20,30,60')

        if self.is_client_mode and not self.update_server:
            self.update_server = jsonrpc_http.HttpServiceProxy(
                self.server_url,
                self.crypto_file,
                server_id=self.server_id,
                sign_only=True)

        if not self.scalarizr:
            self.scalarizr = jsonrpc_http.HttpServiceProxy(
                'http://localhost:8010/', self.crypto_file)
コード例 #4
0
    def test_error_in_request_handler(self):
        def app_creator():
            app = jsonrpc_http.WsgiApplication(
                rpc.RequestHandler({'myservice': MyService()}),
                self.crypto_key_path)
            app.req_handler.handle_request = mock.Mock(
                side_effect=Exception('error in handle request'))
            return app

        wsgi_intercept.add_wsgi_intercept('localhost', 8011, app_creator)
        client = jsonrpc_http.HttpServiceProxy('http://localhost:8011',
                                               self.crypto_key_path)
        try:
            client.myservice.foo()
            assert 0, 'Exception expected, but statement passed'
        except:
            assert '500' in str(sys.exc_info()[1])
コード例 #5
0
    def __call__(self, force=False):
        sys.stdout.write('Updating Scalarizr.')
        sys.stdout.flush()
        upd_service = jsonrpc_http.HttpServiceProxy(
            'http://localhost:8008/',
            os.path.join(__node__['etc_dir'], __node__['crypto_key_path']))
        upd_service.update(force=force, async=True)
        update_started = [False]
        status = {}

        def _completed():
            sys.stdout.write('.')
            sys.stdout.flush()
            with open(os.path.join(__node__['private_dir'], 'update.status'),
                      'r') as fp:
                status.update(json.load(fp))
                if status['state'] in ('completed',
                                       'error') and update_started[0]:
                    return status
                elif not update_started[0] and status['state'].startswith(
                        'in-progress'):
                    update_started[0] = True
                return False

        try:
            util.wait_until(_completed,
                            sleep=POLLING_INTERVAL,
                            timeout=POLLING_TIMEOUT)
        except BaseException as e:
            if 'Timeout:' in str(e):
                status['error'] = str(e)
            else:
                raise

        if status['error']:
            print '\nUpdate failed.\n{}\n'.format(status['error'])
        else:
            print '\nDone.\nInstalled: {}\n'.format(status['installed'])
コード例 #6
0
 def test_call(self):
     wsgi_intercept.add_wsgi_intercept('localhost', 8011, self.app_creator)
     client = jsonrpc_http.HttpServiceProxy('http://localhost:8011',
                                            self.crypto_key_path)
     assert_equals(client.myservice.foo(), 'bar')