Пример #1
0
    def packet_filter_on_port(self,
                              port=None,
                              fmt=None,
                              do_delete=True,
                              set_portinfo=True,
                              **kwargs):
        with test_plugin.optional_ctx(port, self.port) as port_to_use:
            net_id = port_to_use['port']['network_id']
            port_id = port_to_use['port']['id']

            if set_portinfo:
                portinfo = {
                    'id': port_id,
                    'port_no': kwargs.get('port_no', 123)
                }
                kw = {'added': [portinfo]}
                if 'datapath_id' in kwargs:
                    kw['datapath_id'] = kwargs['datapath_id']
                self.rpcapi_update_ports(**kw)

            kwargs['in_port'] = port_id
            pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
            self.assertEqual(port_id, pf['packet_filter']['in_port'])
            yield pf
            if do_delete:
                self._delete('packet_filters', pf['packet_filter']['id'])
Пример #2
0
 def ssl_vpn_connection(self,
                        name='fake_name',
                        client_address_pool_cidr='10.0.0.0/24',
                        fmt=None,
                        no_delete=False,
                        vpnservice=None,
                        **kwargs):
     if not fmt:
         fmt = self.fmt
     with contextlib.nested(
             test_db_plugin.optional_ctx(vpnservice, self.vpnservice),
             self.vpn_credential()) as (vpnservice, vpn_credential):
         res = self._create_ssl_vpn_connection(
             fmt,
             name,
             credential_id=vpn_credential['vpn_credential']['id'],
             vpnservice_id=vpnservice['vpnservice']['id'],
             client_address_pool_cidr=client_address_pool_cidr,
             **kwargs)
         if res.status_int >= 400:
             raise webob.exc.HTTPClientError(
                 explanation=_("Unexpected error code: %s") %
                 res.status_int)
         try:
             ssl_vpn_connection = self.deserialize(fmt, res)
             yield ssl_vpn_connection
         finally:
             if not no_delete:
                 self._delete(
                     'ssl-vpn-connections',
                     ssl_vpn_connection['ssl_vpn_connection']['id'],
                     expected_code=webob.exc.HTTPNoContent.code)
Пример #3
0
 def ssl_vpn_connection(self, name='fake_name',
                        client_address_pool_cidr='10.0.0.0/24',
                        fmt=None,
                        no_delete=False,
                        vpnservice=None,
                        **kwargs):
     if not fmt:
         fmt = self.fmt
     with contextlib.nested(
         test_db_plugin.optional_ctx(vpnservice, self.vpnservice),
         self.vpn_credential()) as (
             vpnservice, vpn_credential):
         res = self._create_ssl_vpn_connection(
             fmt,
             name,
             credential_id=vpn_credential['vpn_credential']['id'],
             vpnservice_id=vpnservice['vpnservice']['id'],
             client_address_pool_cidr=client_address_pool_cidr,
             **kwargs)
         if res.status_int >= 400:
             raise webob.exc.HTTPClientError(
                 explanation=_("Unexpected error code: %s") %
                 res.status_int
             )
         try:
             ssl_vpn_connection = self.deserialize(fmt, res)
             yield ssl_vpn_connection
         finally:
             if not no_delete:
                 self._delete(
                     'ssl-vpn-connections',
                     ssl_vpn_connection['ssl_vpn_connection']['id'],
                     expected_code=webob.exc.HTTPNoContent.code
                 )
Пример #4
0
 def packet_filter_on_network(self, network=None, fmt=None, **kwargs):
     with test_plugin.optional_ctx(network, self.network) as network_to_use:
         net_id = network_to_use['network']['id']
         pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
         yield pf
         if not network:
             self._delete('networks', network_to_use['network']['id'])
Пример #5
0
 def packet_filter_on_network(self, network=None, fmt=None, do_delete=True,
                              **kwargs):
     with test_plugin.optional_ctx(network, self.network) as network_to_use:
         net_id = network_to_use['network']['id']
         pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
         yield pf
         if do_delete:
             self._delete('packet_filters', pf['packet_filter']['id'])
Пример #6
0
 def packet_filter_on_network(self, network=None, fmt=None, do_delete=True,
                              **kwargs):
     with test_plugin.optional_ctx(network, self.network) as network_to_use:
         net_id = network_to_use['network']['id']
         pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
         try:
             yield pf
         finally:
             if do_delete:
                 self._delete('packet_filters', pf['packet_filter']['id'])
Пример #7
0
    def vip(
        self,
        fmt=None,
        name="vip1",
        pool=None,
        subnet=None,
        protocol="HTTP",
        protocol_port=80,
        admin_state_up=True,
        no_delete=False,
        **kwargs
    ):
        if not fmt:
            fmt = self.fmt

        with test_db_plugin.optional_ctx(subnet, self.subnet) as tmp_subnet:
            with test_db_plugin.optional_ctx(pool, self.pool) as tmp_pool:
                pool_id = tmp_pool["pool"]["id"]
                res = self._create_vip(
                    fmt,
                    name,
                    pool_id,
                    protocol,
                    protocol_port,
                    admin_state_up,
                    subnet_id=tmp_subnet["subnet"]["id"],
                    **kwargs
                )
                if res.status_int >= 400:
                    raise webob.exc.HTTPClientError(explanation=_("Unexpected error code: %s") % res.status_int)
                try:
                    vip = self.deserialize(fmt or self.fmt, res)
                    yield vip
                finally:
                    if not no_delete:
                        self._delete("vips", vip["vip"]["id"])
Пример #8
0
    def floatingip_with_assoc(self,
                              port_id=None,
                              fixed_ip=None,
                              set_context=False,
                              arg_list=None,
                              **kwargs):
        with self.subnet(cidr='11.0.0.0/24') as public_sub:
            self._set_net_external(public_sub['subnet']['network_id'])
            private_port = None
            if port_id:
                private_port = self._show('ports', port_id)
            with test_db_plugin.optional_ctx(private_port,
                                             self.port) as private_port:
                with self.router() as r:
                    sid = private_port['port']['fixed_ips'][0]['subnet_id']
                    private_sub = {'subnet': {'id': sid}}
                    floatingip = None

                    self._add_external_gateway_to_router(
                        r['router']['id'], public_sub['subnet']['network_id'])
                    self._router_interface_action('add', r['router']['id'],
                                                  private_sub['subnet']['id'],
                                                  None)

                    floatingip = self._make_floatingip(
                        self.fmt,
                        public_sub['subnet']['network_id'],
                        port_id=private_port['port']['id'],
                        fixed_ip=fixed_ip,
                        set_context=set_context,
                        arg_list=arg_list,
                        **kwargs)
                    yield floatingip

                    if floatingip:
                        self._delete('floatingips',
                                     floatingip['floatingip']['id'])
                    self._router_interface_action('remove', r['router']['id'],
                                                  private_sub['subnet']['id'],
                                                  None)
                    self._remove_external_gateway_from_router(
                        r['router']['id'], public_sub['subnet']['network_id'])
Пример #9
0
    def packet_filter_on_port(self, port=None, fmt=None, do_delete=True,
                              set_portinfo=True, **kwargs):
        with test_plugin.optional_ctx(port, self.port) as port_to_use:
            net_id = port_to_use['port']['network_id']
            port_id = port_to_use['port']['id']

            if set_portinfo:
                portinfo = {'id': port_id,
                            'port_no': kwargs.get('port_no', 123)}
                kw = {'added': [portinfo]}
                if 'datapath_id' in kwargs:
                    kw['datapath_id'] = kwargs['datapath_id']
                self.rpcapi_update_ports(**kw)

            kwargs['in_port'] = port_id
            pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
            self.assertEqual(port_id, pf['packet_filter']['in_port'])
            yield pf
            if do_delete:
                self._delete('packet_filters', pf['packet_filter']['id'])
    def floatingip_with_assoc(self, port_id=None, fixed_ip=None,
                              set_context=False, arg_list=None, **kwargs):
        with self.subnet(cidr='11.0.0.0/24') as public_sub:
            self._set_net_external(public_sub['subnet']['network_id'])
            private_port = None
            if port_id:
                private_port = self._show('ports', port_id)
            with test_db_plugin.optional_ctx(private_port,
                                             self.port) as private_port:
                with self.router() as r:
                    sid = private_port['port']['fixed_ips'][0]['subnet_id']
                    private_sub = {'subnet': {'id': sid}}
                    floatingip = None

                    self._add_external_gateway_to_router(
                        r['router']['id'],
                        public_sub['subnet']['network_id'])
                    self._router_interface_action(
                        'add', r['router']['id'],
                        private_sub['subnet']['id'], None)

                    floatingip = self._make_floatingip(
                        self.fmt,
                        public_sub['subnet']['network_id'],
                        port_id=private_port['port']['id'],
                        fixed_ip=fixed_ip,
                        set_context=set_context,
                        arg_list=arg_list,
                        **kwargs)
                    yield floatingip

                    if floatingip:
                        self._delete('floatingips',
                                     floatingip['floatingip']['id'])
                    self._router_interface_action(
                        'remove', r['router']['id'],
                        private_sub['subnet']['id'], None)
                    self._remove_external_gateway_from_router(
                        r['router']['id'],
                        public_sub['subnet']['network_id'])