Example #1
0
    def login(self):
        """Issue login request and update authentication cookie."""
        request_eventlet = (quantum.plugins.nicira.nicira_nvp_plugin.
                            api_client.request_eventlet)
        g = request_eventlet.NvpLoginRequestEventlet(self, self._user,
                                                     self._password)
        g.start()
        ret = g.join()

        if ret:
            if isinstance(ret, Exception):
                LOG.error('NvpApiClient: login error "%s"' % ret)
                raise ret

            self._cookie = None
            cookie = ret.getheader("Set-Cookie")
            if cookie:
                LOG.debug("Saving new authentication cookie '%s'" % cookie)
                self._cookie = cookie
                self._need_login = False

        if not ret:
            return None

        return self._cookie
 def test_session_cookie_not_retrieved(self):
     r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
     r.successful = Mock()
     r.successful.return_value = False
     r.value = Mock()
     r.value.get_header = Mock()
     r.value.get_header.return_value = 'cool'
     self.assertTrue(r.session_cookie() is None)
    def _login(self, conn=None, headers=None):
        '''Issue login request and update authentication cookie.'''
        cookie = None
        g = request_eventlet.NvpLoginRequestEventlet(
            self, self._user, self._password, conn, headers)
        g.start()
        ret = g.join()
        if ret:
            if isinstance(ret, Exception):
                LOG.error(_('NvpApiClient: login error "%s"'), ret)
                raise ret

            cookie = ret.getheader("Set-Cookie")
            if cookie:
                LOG.debug(_("Saving new authentication cookie '%s'"), cookie)

        return cookie
 def test_construct_eventlet_login_request(self):
     r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
     self.assertTrue(r is not None)