Skip to content

Commit

Permalink
Nested edge: Fixing iotedge checks (#3611)
Browse files Browse the repository at this point in the history
* Fixing IoT edge check for nested scenarios.

* fixing mistake in version number

* formatting

* Fixing clippy issue

* Fix file name based on comment

* Fixing some more names

* adding diagnostics

Co-authored-by: Ubuntu <iotedgeuser@hug3l3edge.0x1kslxyg1putjewhwmoznt1le.yx.internal.cloudapp.net>
  • Loading branch information
huguesBouvier and Ubuntu authored Sep 30, 2020
1 parent 73bbb9f commit c0bad52
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 56 deletions.
6 changes: 3 additions & 3 deletions edge-modules/iotedge-diagnostics-dotnet/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static async Task MainAsync(string[] args)
case "edge-agent":
await EdgeAgent(config["management-uri"]);
break;
case "iothub":
await Iothub(config["hostname"], config["port"], config["proxy"]);
case "upstream":
await Upstream(config["hostname"], config["port"], config["proxy"]);
break;
case "local-time":
Console.WriteLine(DateTime.Now.ToUnixTimestamp());
Expand Down Expand Up @@ -80,7 +80,7 @@ static async Task EdgeAgent(string managementUri)
}
}

static async Task Iothub(string hostname, string port, string proxy)
static async Task Upstream(string hostname, string port, string proxy)
{
if (proxy != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,54 @@ use crate::check::{
checker::Checker, upstream_protocol_port::UpstreamProtocolPort, Check, CheckResult,
};

pub(crate) fn get_host_container_iothub_tests() -> Vec<Box<dyn Checker>> {
pub(crate) fn get_host_container_upstream_tests() -> Vec<Box<dyn Checker>> {
vec![
#[cfg(unix)]
make_check(
"container-default-connect-iothub-amqp",
"container on the default network can connect to IoT Hub AMQP port",
"container-default-connect-upstream-amqp",
"container on the default network can connect to upstream AMQP port",
UpstreamProtocolPort::Amqp,
false,
),
#[cfg(unix)]
make_check(
"container-default-connect-iothub-https",
"container on the default network can connect to IoT Hub HTTPS / WebSockets port",
"container-default-connect-upstream-https",
"container on the default network can connect to upstream HTTPS / WebSockets port",
UpstreamProtocolPort::Https,
false,
),
#[cfg(unix)]
make_check(
"container-default-connect-iothub-mqtt",
"container on the default network can connect to IoT Hub MQTT port",
"container-default-connect-upstream-mqtt",
"container on the default network can connect to upstream MQTT port",
UpstreamProtocolPort::Mqtt,
false,
),
make_check(
"container-connect-iothub-amqp",
"container on the IoT Edge module network can connect to IoT Hub AMQP port",
"container-connect-upstream-amqp",
"container on the IoT Edge module network can connect to upstream AMQP port",
UpstreamProtocolPort::Amqp,
true,
),
make_check(
"container-connect-iothub-https",
"container on the IoT Edge module network can connect to IoT Hub HTTPS / WebSockets port",
"container-connect-upstream-https",
"container on the IoT Edge module network can connect to upstream HTTPS / WebSockets port",
UpstreamProtocolPort::Https,
true,
),
make_check(
"container-connect-iothub-mqtt",
"container on the IoT Edge module network can connect to IoT Hub MQTT port",
"container-connect-upstream-mqtt",
"container on the IoT Edge module network can connect to upstream MQTT port",
UpstreamProtocolPort::Mqtt,
true,
),
]
}

#[derive(serde_derive::Serialize)]
pub(crate) struct ContainerConnectIotHub {
pub(crate) struct ContainerConnectUpstream {
port_number: u16,
iothub_hostname: Option<String>,
upstream_hostname: Option<String>,
network_name: Option<String>,
diagnostics_image_name: Option<String>,
proxy: Option<String>,
Expand All @@ -63,7 +63,7 @@ pub(crate) struct ContainerConnectIotHub {
use_container_runtime_network: bool,
}

impl Checker for ContainerConnectIotHub {
impl Checker for ContainerConnectUpstream {
fn id(&self) -> &'static str {
self.id
}
Expand All @@ -78,7 +78,7 @@ impl Checker for ContainerConnectIotHub {
serde_json::to_value(self).unwrap()
}
}
impl ContainerConnectIotHub {
impl ContainerConnectUpstream {
fn inner_execute(&mut self, check: &mut Check) -> Result<CheckResult, failure::Error> {
let settings = if let Some(settings) = &check.settings {
settings
Expand All @@ -92,12 +92,12 @@ impl ContainerConnectIotHub {
return Ok(CheckResult::Skipped);
};

let iothub_hostname = if let Some(iothub_hostname) = &check.iothub_hostname {
let upstream_hostname = if let Some(iothub_hostname) = &check.iothub_hostname {
iothub_hostname
} else {
return Ok(CheckResult::Skipped);
};
self.iothub_hostname = Some(iothub_hostname.to_owned());
self.upstream_hostname = Some(upstream_hostname.to_owned());

let network_name = settings.moby_runtime().network().name();
self.network_name = Some(network_name.to_owned());
Expand All @@ -115,9 +115,9 @@ impl ContainerConnectIotHub {
&check.diagnostics_image_name,
"dotnet",
"IotedgeDiagnosticsDotnet.dll",
"iothub",
"upstream",
"--hostname",
iothub_hostname,
upstream_hostname,
"--port",
&port,
]);
Expand All @@ -141,7 +141,7 @@ impl ContainerConnectIotHub {
} else {
"default"
},
iothub_hostname,
upstream_hostname,
port,
))
.into());
Expand All @@ -156,13 +156,13 @@ fn make_check(
description: &'static str,
upstream_protocol_port: UpstreamProtocolPort,
use_container_runtime_network: bool,
) -> Box<ContainerConnectIotHub> {
Box::new(ContainerConnectIotHub {
) -> Box<ContainerConnectUpstream> {
Box::new(ContainerConnectUpstream {
id,
description,
port_number: upstream_protocol_port.as_port(),
use_container_runtime_network,
iothub_hostname: None,
upstream_hostname: None,
network_name: None,
diagnostics_image_name: None,
proxy: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ use crate::check::{
checker::Checker, upstream_protocol_port::UpstreamProtocolPort, Check, CheckResult,
};

pub(crate) fn get_host_connect_iothub_tests() -> Vec<Box<dyn Checker>> {
pub(crate) fn get_host_connect_upstream_tests() -> Vec<Box<dyn Checker>> {
vec![
make_check(
"host-connect-iothub-amqp",
"host can connect to and perform TLS handshake with IoT Hub AMQP port",
"host-connect-upstream-amqp",
"host can connect to and perform TLS handshake with upstream AMQP port",
UpstreamProtocolPort::Amqp,
),
make_check(
"host-connect-iothub-https",
"host can connect to and perform TLS handshake with IoT Hub HTTPS / WebSockets port",
"host-connect-upstream-https",
"host can connect to and perform TLS handshake with upstream HTTPS / WebSockets port",
UpstreamProtocolPort::Https,
),
make_check(
"host-connect-iothub-mqtt",
"host can connect to and perform TLS handshake with IoT Hub MQTT port",
"host-connect-upstream-mqtt",
"host can connect to and perform TLS handshake with upstream MQTT port",
UpstreamProtocolPort::Mqtt,
),
]
}

#[derive(serde_derive::Serialize)]
pub(crate) struct HostConnectIotHub {
pub(crate) struct HostConnectUpstream {
port_number: u16,
iothub_hostname: Option<String>,
upstream_hostname: Option<String>,
proxy: Option<String>,
#[serde(skip)]
id: &'static str,
#[serde(skip)]
description: &'static str,
}

impl Checker for HostConnectIotHub {
impl Checker for HostConnectUpstream {
fn id(&self) -> &'static str {
self.id
}
Expand All @@ -51,18 +51,29 @@ impl Checker for HostConnectIotHub {
}
}

impl HostConnectIotHub {
impl HostConnectUpstream {
fn inner_execute(
&mut self,
check: &mut Check,
runtime: &mut tokio::runtime::Runtime,
) -> Result<CheckResult, failure::Error> {
let iothub_hostname = if let Some(iothub_hostname) = &check.iothub_hostname {
let settings = if let Some(settings) = &check.settings {
settings
} else {
return Ok(CheckResult::Skipped);
};

let parent_hostname: String;
let upstream_hostname = if let Some(upstream_hostname) = settings.parent_hostname() {
parent_hostname = upstream_hostname.to_string();
&parent_hostname
} else if let Some(iothub_hostname) = &check.iothub_hostname {
iothub_hostname
} else {
return Ok(CheckResult::Skipped);
};
self.iothub_hostname = Some(iothub_hostname.clone());

self.upstream_hostname = Some(upstream_hostname.clone());

self.proxy = check
.settings
Expand All @@ -72,16 +83,16 @@ impl HostConnectIotHub {
if let Some(proxy) = &self.proxy {
runtime.block_on(
super::host_connect_dps_endpoint::resolve_and_tls_handshake_proxy(
iothub_hostname.clone(),
upstream_hostname.clone(),
Some(self.port_number),
proxy.clone(),
),
)?;
} else {
super::host_connect_dps_endpoint::resolve_and_tls_handshake(
&(&**iothub_hostname, self.port_number),
iothub_hostname,
&format!("{}:{}", iothub_hostname, self.port_number),
&(&**upstream_hostname, self.port_number),
upstream_hostname,
&format!("{}:{}", upstream_hostname, self.port_number),
)?;
}

Expand All @@ -93,12 +104,12 @@ fn make_check(
id: &'static str,
description: &'static str,
upstream_protocol_port: UpstreamProtocolPort,
) -> Box<HostConnectIotHub> {
Box::new(HostConnectIotHub {
) -> Box<HostConnectUpstream> {
Box::new(HostConnectUpstream {
id,
description,
port_number: upstream_protocol_port.as_port(),
iothub_hostname: None,
upstream_hostname: None,
proxy: None,
})
}
8 changes: 4 additions & 4 deletions edgelet/iotedge/src/check/checks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod certificates_quickstart;
mod connect_management_uri;
mod container_connect_iothub;
mod container_connect_upstream;
mod container_engine_dns;
mod container_engine_installed;
mod container_engine_ipv6;
mod container_engine_is_moby;
mod container_engine_logrotate;
mod container_local_time;
mod host_connect_dps_endpoint;
mod host_connect_iothub;
mod host_connect_upstream;
mod host_local_time;
mod hostname;
mod identity_certificate_expiry;
Expand All @@ -20,15 +20,15 @@ mod windows_host_version;

pub(crate) use self::certificates_quickstart::CertificatesQuickstart;
pub(crate) use self::connect_management_uri::ConnectManagementUri;
pub(crate) use self::container_connect_iothub::get_host_container_iothub_tests;
pub(crate) use self::container_connect_upstream::get_host_container_upstream_tests;
pub(crate) use self::container_engine_dns::ContainerEngineDns;
pub(crate) use self::container_engine_installed::ContainerEngineInstalled;
pub(crate) use self::container_engine_ipv6::ContainerEngineIPv6;
pub(crate) use self::container_engine_is_moby::ContainerEngineIsMoby;
pub(crate) use self::container_engine_logrotate::ContainerEngineLogrotate;
pub(crate) use self::container_local_time::ContainerLocalTime;
pub(crate) use self::host_connect_dps_endpoint::HostConnectDpsEndpoint;
pub(crate) use self::host_connect_iothub::get_host_connect_iothub_tests;
pub(crate) use self::host_connect_upstream::get_host_connect_upstream_tests;
pub(crate) use self::host_local_time::HostLocalTime;
pub(crate) use self::hostname::Hostname;
pub(crate) use self::identity_certificate_expiry::IdentityCertificateExpiry;
Expand Down
6 changes: 3 additions & 3 deletions edgelet/iotedge/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use checker::Checker;

mod checks;
use checks::{
get_host_connect_iothub_tests, get_host_container_iothub_tests, CertificatesQuickstart,
get_host_connect_upstream_tests, get_host_container_upstream_tests, CertificatesQuickstart,
ConnectManagementUri, ContainerEngineDns, ContainerEngineIPv6, ContainerEngineInstalled,
ContainerEngineIsMoby, ContainerEngineLogrotate, ContainerLocalTime, EdgeAgentStorageMounted,
EdgeHubStorageMounted, HostConnectDpsEndpoint, HostLocalTime, Hostname,
Expand Down Expand Up @@ -248,8 +248,8 @@ impl Check {
("Connectivity checks", {
let mut tests: Vec<Box<dyn Checker>> = Vec::new();
tests.push(Box::new(HostConnectDpsEndpoint::default()));
tests.extend(get_host_connect_iothub_tests());
tests.extend(get_host_container_iothub_tests());
tests.extend(get_host_connect_upstream_tests());
tests.extend(get_host_container_upstream_tests());
tests
}),
]
Expand Down
2 changes: 1 addition & 1 deletion edgelet/iotedge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn run() -> Result<(), Error> {
let default_mgmt_uri = option_env!("IOTEDGE_HOST").unwrap_or(&*default_mgmt_uri);

let default_diagnostics_image_name = format!(
"mcr.microsoft.com/azureiotedge-diagnostics:{}",
"/azureiotedge-diagnostics:{}",
edgelet_core::version().replace("~", "-")
);

Expand Down

0 comments on commit c0bad52

Please sign in to comment.