Skip to content

Commit

Permalink
add integration tests for new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
internet-diglett committed Oct 16, 2024
1 parent 822953e commit 9ef3456
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 45 deletions.
4 changes: 2 additions & 2 deletions nexus/db-queries/src/db/datastore/bgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl DataStore {
pub async fn bgp_config_delete(
&self,
opctx: &OpContext,
sel: &params::BgpConfigSelector,
sel: &NameOrId,
) -> DeleteResult {
use db::schema::bgp_config;
use db::schema::bgp_config::dsl as bgp_config_dsl;
Expand All @@ -237,7 +237,7 @@ impl DataStore {
.transaction(&conn, |conn| {
let err = err.clone();
async move {
let name_or_id = sel.name_or_id.clone();
let name_or_id = sel.clone();

let id: Uuid = match name_or_id {
NameOrId::Id(id) => bgp_config_dsl::bgp_config
Expand Down
49 changes: 45 additions & 4 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::transaction_retry::OptionalError;
use async_bb8_diesel::{AsyncRunQueryDsl, Connection};
use diesel::CombineDsl;
use diesel::{
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, PgConnection,
QueryDsl, SelectableHelper,
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, OptionalExtension,
PgConnection, QueryDsl, SelectableHelper,
};
use diesel_dtrace::DTraceConnection;
use ipnetwork::IpNetwork;
Expand Down Expand Up @@ -1823,8 +1823,7 @@ impl DataStore {

self.transaction_retry_wrapper(
"switch_port_configuration_bgp_peer_allow_import_add",
)
.transaction(&conn, |conn| {
).transaction(&conn, |conn| {
let parent_configuration = configuration.clone();
let new_settings = prefix.clone();
let err = err.clone();
Expand Down Expand Up @@ -1858,6 +1857,20 @@ impl DataStore {
prefix: new_settings.prefix.into(),
};

let found_config = allow_import::table
.filter(allow_import::port_settings_id.eq(allow_import_config.port_settings_id))
.filter(allow_import::interface_name.eq(allow_import_config.interface_name.clone()))
.filter(allow_import::addr.eq(allow_import_config.addr))
.filter(allow_import::prefix.eq(allow_import_config.prefix))
.select(SwitchPortBgpPeerConfigAllowImport::as_select())
.get_result_async(&conn)
.await
.optional()?;

if let Some(config) = found_config {
return Ok(config)
}

let config = diesel::insert_into(allow_import::table)
.values(allow_import_config)
.returning(SwitchPortBgpPeerConfigAllowImport::as_returning())
Expand Down Expand Up @@ -2048,6 +2061,20 @@ impl DataStore {
prefix: new_settings.prefix.into(),
};

let found_config = allow_export::table
.filter(allow_export::port_settings_id.eq(allow_export_config.port_settings_id))
.filter(allow_export::interface_name.eq(allow_export_config.interface_name.clone()))
.filter(allow_export::addr.eq(allow_export_config.addr))
.filter(allow_export::prefix.eq(allow_export_config.prefix))
.select(SwitchPortBgpPeerConfigAllowExport::as_select())
.get_result_async(&conn)
.await
.optional()?;

if let Some(config) = found_config {
return Ok(config)
}

let config = diesel::insert_into(allow_export::table)
.values(allow_export_config)
.returning(SwitchPortBgpPeerConfigAllowExport::as_returning())
Expand Down Expand Up @@ -2238,6 +2265,20 @@ impl DataStore {
community: new_settings.community.into(),
};

let found_config = communities::table
.filter(communities::port_settings_id.eq(community_config.port_settings_id))
.filter(communities::interface_name.eq(community_config.interface_name.clone()))
.filter(communities::addr.eq(community_config.addr))
.filter(communities::community.eq(community_config.community))
.select(SwitchPortBgpPeerConfigCommunity::as_select())
.get_result_async(&conn)
.await
.optional()?;

if let Some(config) = found_config {
return Ok(config)
}

let config = diesel::insert_into(communities::table)
.values(community_config)
.returning(SwitchPortBgpPeerConfigCommunity::as_returning())
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/bgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl super::Nexus {
pub async fn bgp_config_delete(
&self,
opctx: &OpContext,
sel: &params::BgpConfigSelector,
sel: &NameOrId,
) -> DeleteResult {
opctx.authorize(authz::Action::Modify, &authz::FLEET).await?;
let result = self.db_datastore.bgp_config_delete(opctx, sel).await?;
Expand Down
10 changes: 5 additions & 5 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4940,17 +4940,17 @@ async fn networking_bgp_imported_routes_ipv4(
/// Delete BGP configuration
#[endpoint {
method = DELETE,
path = "/v1/system/networking/bgp",
path = "/v1/system/networking/bgp/{bgp_config}",
tags = ["system/networking"],
}]
async fn networking_bgp_config_delete(
rqctx: RequestContext<ApiContext>,
sel: Query<params::BgpConfigSelector>,
sel: Path<params::BgpConfigSelector>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;
let sel = sel.into_inner();
let sel = sel.into_inner().bgp_config;
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
nexus.bgp_config_delete(&opctx, &sel).await?;
Ok(HttpResponseUpdatedNoContent {})
Expand All @@ -4974,14 +4974,14 @@ async fn networking_bgp_config_delete(
async fn networking_bgp_announce_set_update(
rqctx: RequestContext<ApiContext>,
config: TypedBody<params::BgpAnnounceSetCreate>,
) -> Result<HttpResponseCreated<BgpAnnounceSet>, HttpError> {
) -> Result<HttpResponseOk<BgpAnnounceSet>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;
let config = config.into_inner();
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
let result = nexus.bgp_update_announce_set(&opctx, &config).await?;
Ok(HttpResponseCreated::<BgpAnnounceSet>(result.0.into()))
Ok(HttpResponseOk::<BgpAnnounceSet>(result.0.into()))
};
apictx
.context
Expand Down
Loading

0 comments on commit 9ef3456

Please sign in to comment.