示例#1
0
 def test_create_ipsec_site_connection_fail(self,
                                            mock_update_status,
                                            mock_update_ipsec,
                                            mock_gen_new, mock_get_id,
                                            mock_conv_ipsec,
                                            mock_val_conn):
     mock_get_id.return_value = (FAKE_ROUTER_ID, FAKE_EDGE_ID)
     mock_conv_ipsec.return_value = FAKE_IPSEC_VPN_SITE
     mock_gen_new.return_value = FAKE_IPSEC_VPN_SITE
     mock_update_ipsec.side_effect = (
         vcns_exc.VcnsApiException(**FAKE_VCNSAPIEXC))
     self.assertRaises(nsxv_exc.NsxPluginException,
                       self.driver.create_ipsec_site_connection,
                       self.context, FAKE_IPSEC_CONNECTION)
     mock_val_conn.assert_called_with(self.context, FAKE_IPSEC_CONNECTION)
     mock_conv_ipsec.assert_called_with(self.context, FAKE_IPSEC_CONNECTION)
     mock_get_id.assert_called_with(self.context, FAKE_VPNSERVICE_ID)
     mock_gen_new.assert_called_with(FAKE_EDGE_ID, FAKE_IPSEC_VPN_SITE)
     mock_update_ipsec.assert_called_with(FAKE_EDGE_ID,
                                          FAKE_IPSEC_VPN_SITE,
                                          enabled=True)
     mock_update_status.assert_called_with(
         self.context,
         FAKE_IPSEC_CONNECTION["vpnservice_id"],
         FAKE_IPSEC_CONNECTION["id"],
         "ERROR")
示例#2
0
 def test_update_ipsec_fail_with_fw_fail(self, mock_update_fw,
                                         mock_update_ipsec,
                                         mock_update_sites, mock_get_id):
     mock_get_id.return_value = (FAKE_ROUTER_ID, FAKE_EDGE_ID)
     mock_update_fw.side_effect = (
         vcns_exc.VcnsApiException(**FAKE_VCNSAPIEXC))
     self.assertRaises(nsxv_exc.NsxPluginException,
                       self.driver.update_ipsec_site_connection,
                       self.context, FAKE_IPSEC_CONNECTION,
                       FAKE_NEW_CONNECTION)
     mock_update_sites.assert_called_with(self.context, FAKE_EDGE_ID,
                                          FAKE_IPSEC_CONNECTION,
                                          FAKE_NEW_CONNECTION)
     mock_update_fw.assert_called_with(self.context, FAKE_VPNSERVICE_ID)
示例#3
0
    def request(self,
                method,
                uri,
                params=None,
                headers=None,
                encodeparams=True):
        uri = self.address + uri
        if headers is None:
            headers = {}

        headers['Accept'] = 'application/' + self.format
        headers['Authorization'] = 'Basic ' + self.authToken.strip()
        headers['Content-Type'] = 'application/' + self.format

        if params:
            if encodeparams is True:
                data = self.encode(params)
            else:
                data = params
        else:
            data = None

        try:
            response = requests.request(method,
                                        uri,
                                        verify=self.verify_cert,
                                        data=data,
                                        headers=headers,
                                        timeout=self.timeout)
        except requests.exceptions.Timeout:
            raise exceptions.VcnsApiException(uri=uri)

        status = response.status_code

        if 200 <= status < 300:
            return response.headers, response.text

        nsx_errcode = self._get_nsx_errorcode(response.text)
        if nsx_errcode in self.nsx_errors:
            cls = self.nsx_errors[nsx_errcode]
        elif status in self.errors:
            cls = self.errors[status]
        else:
            cls = exceptions.VcnsApiException
        raise cls(uri=uri,
                  status=status,
                  header=response.headers,
                  response=response.text)
示例#4
0
 def test_update_ipsec_fail_with_site_fail(self, mock_update_status,
                                           mock_update_ipsec,
                                           mock_update_sites, mock_get_id):
     mock_get_id.return_value = (FAKE_ROUTER_ID, FAKE_EDGE_ID)
     mock_update_sites.return_value = FAKE_IPSEC_VPN_SITE
     mock_update_ipsec.side_effect = (vcns_exc.VcnsApiException(
         **FAKE_VCNSAPIEXC))
     self.assertRaises(nsxv_exc.NsxPluginException,
                       self.driver.update_ipsec_site_connection,
                       self.context, FAKE_IPSEC_CONNECTION,
                       FAKE_NEW_CONNECTION)
     mock_update_sites.assert_called_with(self.context, FAKE_EDGE_ID,
                                          FAKE_IPSEC_CONNECTION,
                                          FAKE_NEW_CONNECTION)
     mock_update_ipsec.assert_called_with(FAKE_EDGE_ID, FAKE_IPSEC_VPN_SITE)
     mock_update_status.assert_called_with(
         self.context, FAKE_IPSEC_CONNECTION["vpnservice_id"],
         FAKE_IPSEC_CONNECTION["id"], "ERROR")