Ejemplo n.º 1
0
def _update_routes_in_associated_subnets(context,
                                         cleaner,
                                         route_table,
                                         default_associations_only=None,
                                         update_target=None):
    if default_associations_only:
        appropriate_rtb_ids = (None, )
    else:
        vpc = db_api.get_item_by_id(context, route_table['vpc_id'])
        if vpc['route_table_id'] == route_table['id']:
            appropriate_rtb_ids = (route_table['id'], None)
        else:
            appropriate_rtb_ids = (route_table['id'], )
    neutron = clients.neutron(context)
    subnets = [
        subnet for subnet in db_api.get_items(context, 'subnet')
        if (subnet['vpc_id'] == route_table['vpc_id']
            and subnet.get('route_table_id') in appropriate_rtb_ids)
    ]
    # NOTE(ft): we need to update host routes for both host and vpn target
    # because vpn-related routes are present in host routes as well
    _update_host_routes(context, neutron, cleaner, route_table, subnets)
    if not update_target or update_target == VPN_TARGET:
        vpn_connection_api._update_vpn_routes(context, neutron, cleaner,
                                              route_table, subnets)
Ejemplo n.º 2
0
    def test_update_vpn_routes(self, reset_vpn_connections):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()

        self.set_mock_db_items()
        vpn_connection_api._update_vpn_routes(
            context, self.neutron, cleaner,
            fakes.DB_ROUTE_TABLE_1, [fakes.DB_SUBNET_1])
        self.assertFalse(reset_vpn_connections.called)

        self.set_mock_db_items(fakes.DB_VPN_GATEWAY_1)
        vpn_connection_api._update_vpn_routes(
            context, self.neutron, cleaner,
            fakes.DB_ROUTE_TABLE_1, [fakes.DB_SUBNET_1])
        reset_vpn_connections.assert_called_once_with(
            context, self.neutron, cleaner, fakes.DB_VPN_GATEWAY_1,
            route_tables=[fakes.DB_ROUTE_TABLE_1], subnets=[fakes.DB_SUBNET_1])
Ejemplo n.º 3
0
def _update_routes_in_associated_subnets(context, cleaner, route_table,
                                         default_associations_only=None,
                                         update_target=None):
    if default_associations_only:
        appropriate_rtb_ids = (None,)
    else:
        vpc = db_api.get_item_by_id(context, route_table['vpc_id'])
        if vpc['route_table_id'] == route_table['id']:
            appropriate_rtb_ids = (route_table['id'], None)
        else:
            appropriate_rtb_ids = (route_table['id'],)
    neutron = clients.neutron(context)
    subnets = [subnet for subnet in db_api.get_items(context, 'subnet')
               if (subnet['vpc_id'] == route_table['vpc_id'] and
                   subnet.get('route_table_id') in appropriate_rtb_ids)]
    # NOTE(ft): we need to update host routes for both host and vpn target
    # because vpn-related routes are present in host routes as well
    _update_host_routes(context, neutron, cleaner, route_table, subnets)
    if not update_target or update_target == VPN_TARGET:
        vpn_connection_api._update_vpn_routes(context, neutron, cleaner,
                                              route_table, subnets)
Ejemplo n.º 4
0
    def test_update_vpn_routes(self, reset_vpn_connections):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()

        self.set_mock_db_items()
        vpn_connection_api._update_vpn_routes(context, self.neutron, cleaner,
                                              fakes.DB_ROUTE_TABLE_1,
                                              [fakes.DB_SUBNET_1])
        self.assertFalse(reset_vpn_connections.called)

        self.set_mock_db_items(fakes.DB_VPN_GATEWAY_1)
        vpn_connection_api._update_vpn_routes(context, self.neutron, cleaner,
                                              fakes.DB_ROUTE_TABLE_1,
                                              [fakes.DB_SUBNET_1])
        reset_vpn_connections.assert_called_once_with(
            context,
            self.neutron,
            cleaner,
            fakes.DB_VPN_GATEWAY_1,
            route_tables=[fakes.DB_ROUTE_TABLE_1],
            subnets=[fakes.DB_SUBNET_1])
Ejemplo n.º 5
0
def _update_subnet_routes(context, cleaner, subnet, route_table):
    neutron = clients.neutron(context)
    _update_host_routes(context, neutron, cleaner, route_table, [subnet])
    vpn_connection_api._update_vpn_routes(context, neutron, cleaner,
                                          route_table, [subnet])
Ejemplo n.º 6
0
def _update_subnet_routes(context, cleaner, subnet, route_table):
    neutron = clients.neutron(context)
    _update_host_routes(context, neutron, cleaner, route_table, [subnet])
    vpn_connection_api._update_vpn_routes(context, neutron, cleaner,
                                          route_table, [subnet])