Example #1
0
    def _import_callback(self, deployment_id, bundle_id, future):
        """Callback called when a deployment process is completed.

        This callback, scheduled in self.import_bundle(), receives the
        deployment_id identifying one specific deployment job, and the fired
        future returned by the executor.
        """
        if future.cancelled():
            # Notify a deployment has been cancelled.
            self._observer.notify_cancelled(deployment_id)
            success = False
        else:
            error = None
            success = True
            exception = future.exception()
            if exception is not None:
                error = utils.message_from_error(exception)
                success = False
            # Notify a deployment completed.
            self._observer.notify_completed(deployment_id, error=error)
        # Remove the completed deployment job from the queue.
        self._queue.remove(deployment_id)
        del self._futures[deployment_id]
        # Notify the new position of all remaining deployments in the queue.
        for position, deploy_id in enumerate(self._queue):
            self._observer.notify_position(deploy_id, position)
        # Increment the Charmworld deployment count upon successful
        # deployment.
        if success and bundle_id is not None:
            utils.increment_deployment_counter(bundle_id, self._charmworldurl)
Example #2
0
    def _import_callback(self, deployment_id, bundle_id, future):
        """Callback called when a deployment process is completed.

        This callback, scheduled in self.import_bundle(), receives the
        deployment_id identifying one specific deployment job, and the fired
        future returned by the executor.
        """
        if future.cancelled():
            # Notify a deployment has been cancelled.
            self._observer.notify_cancelled(deployment_id)
            success = False
        else:
            error = None
            success = True
            exception = future.exception()
            if exception is not None:
                error = utils.message_from_error(exception)
                success = False
            # Notify a deployment completed.
            self._observer.notify_completed(deployment_id, error=error)
        # Remove the completed deployment job from the queue.
        self._queue.remove(deployment_id)
        del self._futures[deployment_id]
        # Notify the new position of all remaining deployments in the queue.
        for position, deploy_id in enumerate(self._queue):
            self._observer.notify_position(deploy_id, position)
        # Increment the Charmworld deployment count upon successful
        # deployment.
        if success and bundle_id is not None:
            utils.increment_deployment_counter(
                bundle_id, self._charmworldurl)
Example #3
0
 def test_no_cw_url_returns_true(self):
     bundle_id = '~bac/muletrain/wiki'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, None)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #4
0
 def test_no_cw_url_returns_true(self):
     bundle_id = '~bac/muletrain/wiki'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, None)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #5
0
 def test_increment_errors(self):
     bundle_id = '~bac/muletrain/wiki'
     cw_url = 'http://my.charmworld.example.com/'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     mock_fetch = mock_fetch_factory(404)
     with mock.patch(mock_path, mock_fetch):
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
Example #6
0
 def test_increment_nonstring_cwurl(self):
     bundle_id = u'~bac/muletrain/wiki'
     cw_url = 7
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #7
0
 def test_increment_nonstring_bundle_id(self):
     bundle_id = 4
     cw_url = 'http://my.charmworld.example.com/'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #8
0
 def test_increment_errors(self):
     bundle_id = '~bac/muletrain/wiki'
     cw_url = 'http://my.charmworld.example.com/'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     mock_fetch = mock_fetch_factory(404)
     with mock.patch(mock_path, mock_fetch):
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
Example #9
0
 def test_increment_nonstring_cwurl(self):
     bundle_id = u'~bac/muletrain/wiki'
     cw_url = 7
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #10
0
 def test_increment_nonstring_bundle_id(self):
     bundle_id = 4
     cw_url = 'http://my.charmworld.example.com/'
     mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
     with mock.patch(mock_path) as mock_fetch:
         ok = yield utils.increment_deployment_counter(bundle_id, cw_url)
     self.assertFalse(ok)
     self.assertFalse(mock_fetch.called)
Example #11
0
 def test_increment_url_logged(self):
     bundle_id = '~bac/muletrain/wiki'
     cw_url = 'http://my.charmworld.example.com/'
     url = u'{}api/3/bundle/{}/metric/deployments/increment'.format(
         cw_url, bundle_id)
     expected = 'Incrementing bundle.+'
     called_with = []
     mock_fetch = mock_fetch_factory(200, called_with)
     with ExpectLog('', expected, required=True):
         mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
         with mock.patch(mock_path, mock_fetch):
             ok = yield utils.increment_deployment_counter(
                 bundle_id, cw_url)
     self.assertTrue(ok)
     called_args, called_kwargs = called_with[0]
     self.assertEqual(url, urllib.unquote(called_args[0]))
     self.assertEqual(dict(callback=None), called_kwargs)
Example #12
0
 def test_increment_url_logged(self):
     bundle_id = '~bac/muletrain/wiki'
     cw_url = 'http://my.charmworld.example.com/'
     url = u'{}api/3/bundle/{}/metric/deployments/increment'.format(
         cw_url, bundle_id)
     expected = 'Incrementing bundle.+'
     called_with = []
     mock_fetch = mock_fetch_factory(200, called_with)
     with ExpectLog('', expected, required=True):
         mock_path = 'tornado.httpclient.AsyncHTTPClient.fetch'
         with mock.patch(mock_path, mock_fetch):
             ok = yield utils.increment_deployment_counter(
                 bundle_id, cw_url)
     self.assertTrue(ok)
     called_args, called_kwargs = called_with[0]
     self.assertEqual(url, urllib.unquote(called_args[0]))
     self.assertEqual(dict(callback=None), called_kwargs)