def test_execute(self):
        self.controller.fake_action.return_value = {'fakeTag': 'fake_data'}

        res = self.request.send(self.application)

        self.assertEqual(200, res.status_code)
        self.assertEqual('text/xml', res.content_type)
        expected_xml = fakes.XML_RESULT_TEMPLATE % {
            'action': 'FakeAction',
            'api_version': 'fake_v1',
            'request_id': self.fake_context.request_id,
            'data': '<fakeTag>fake_data</fakeTag>'
        }
        self.assertThat(res.body, matchers.XMLMatches(expected_xml))
        self.controller.fake_action.assert_called_once_with(self.fake_context,
                                                            param='fake_param')
        def do_check(ex, status, code, message):
            self.controller.reset_mock()
            self.controller.fake_action.side_effect = ex

            res = self.request.send(self.application)

            self.assertEqual(status, res.status_code)
            self.assertEqual('text/xml', res.content_type)
            expected_xml = fakes.XML_ERROR_TEMPLATE % {
                'code': code,
                'message': message,
                'request_id': self.fake_context.request_id
            }
            self.assertThat(res.body, matchers.XMLMatches(expected_xml))
            self.controller.fake_action.assert_called_once_with(
                self.fake_context, param='fake_param')
Exemple #3
0
    def test_describe_vpn_connections(self):
        self.set_mock_db_items(fakes.DB_VPN_CONNECTION_1,
                               fakes.DB_VPN_CONNECTION_2,
                               fakes.DB_CUSTOMER_GATEWAY_1,
                               fakes.DB_CUSTOMER_GATEWAY_2,
                               fakes.DB_VPN_GATEWAY_1, fakes.DB_VPN_GATEWAY_2,
                               fakes.DB_VPC_1, fakes.DB_VPC_2)
        self.neutron.list_ikepolicies.return_value = {
            'ikepolicies': [fakes.OS_IKEPOLICY_1, fakes.OS_IKEPOLICY_2]
        }
        self.neutron.list_ipsecpolicies.return_value = {
            'ipsecpolicies': [fakes.OS_IPSECPOLICY_1, fakes.OS_IPSECPOLICY_2]
        }
        self.neutron.list_ipsec_site_connections.return_value = {
            'ipsec_site_connections': []
        }
        self.neutron.list_routers.return_value = {
            'routers': [fakes.OS_ROUTER_1, fakes.OS_ROUTER_2]
        }

        resp = self.execute('DescribeVpnConnections', {})
        vpns = [
            tools.update_dict(vpn,
                              {'customerGatewayConfiguration': 'DONTCARE'})
            for vpn in (fakes.EC2_VPN_CONNECTION_1, fakes.EC2_VPN_CONNECTION_2)
        ]
        self.assertThat(
            resp,
            matchers.DictMatches({'vpnConnectionSet': vpns},
                                 orderless_lists=True))
        for vpn in (fakes.EC2_VPN_CONNECTION_1, fakes.EC2_VPN_CONNECTION_2):
            config = next(v['customerGatewayConfiguration']
                          for v in resp['vpnConnectionSet']
                          if v['vpnConnectionId'] == vpn['vpnConnectionId'])
            self.assertThat(
                config,
                matchers.XMLMatches(vpn['customerGatewayConfiguration'],
                                    orderless_sequence=True))
            self.assertTrue(
                config.startswith(
                    '<?xml version=\'1.0\' encoding=\'UTF-8\'?>'))
        self.neutron.list_ikepolicies.assert_called_once_with(
            tenant_id=fakes.ID_OS_PROJECT)
        self.neutron.list_ipsecpolicies.assert_called_once_with(
            tenant_id=fakes.ID_OS_PROJECT)
        self.neutron.list_ipsec_site_connections.assert_called_once_with(
            tenant_id=fakes.ID_OS_PROJECT)
        self.neutron.list_routers.assert_called_once_with(
            tenant_id=fakes.ID_OS_PROJECT)

        resp = self.execute(
            'DescribeVpnConnections',
            {'VpnConnectionId.1': fakes.ID_EC2_VPN_CONNECTION_1})
        self.assertThat(
            resp,
            matchers.DictMatches({'vpnConnectionSet': [vpns[0]]},
                                 orderless_lists=True))

        self.check_filtering(
            'DescribeVpnConnections', 'vpnConnectionSet',
            [('customer-gateway-configuration',
              '*' + fakes.PRE_SHARED_KEY_1 + '*'),
             ('customer-gateway-id', fakes.ID_EC2_CUSTOMER_GATEWAY_1),
             ('state', 'available'), ('option.static-routes-only', True),
             ('route.destination-cidr-block', fakes.CIDR_VPN_2_PROPAGATED_1),
             ('type', 'ipsec.1'),
             ('vpn-connection-id', fakes.ID_EC2_VPN_CONNECTION_1),
             ('vpn-gateway-id', fakes.ID_EC2_VPN_GATEWAY_1)])

        self.check_tag_support('DescribeVpnConnections', 'vpnConnectionSet',
                               fakes.ID_EC2_VPN_CONNECTION_1,
                               'vpnConnectionId')