Update for Mockito 1.0 API
This commit is contained in:
parent
25e1eb391b
commit
8947f78e35
@ -0,0 +1,79 @@
|
||||
From f6799a3852ab6145a7bb62b2ec8bc8cd657623b1 Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Gilbert <bgilbert@redhat.com>
|
||||
Date: Mon, 20 Mar 2023 01:08:04 -0400
|
||||
Subject: [PATCH 1/6] providers/packet: use stored client for boot checkin
|
||||
|
||||
Store the retry::Client on the PacketProvider and use it for boot checkin
|
||||
to ease testing.
|
||||
---
|
||||
src/providers/packet/mock_tests.rs | 7 +++++--
|
||||
src/providers/packet/mod.rs | 6 +++---
|
||||
2 files changed, 8 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/providers/packet/mock_tests.rs b/src/providers/packet/mock_tests.rs
|
||||
index d22543ceda92..ef26be4c7759 100644
|
||||
--- a/src/providers/packet/mock_tests.rs
|
||||
+++ b/src/providers/packet/mock_tests.rs
|
||||
@@ -3,6 +3,7 @@ use mockito::{self, Matcher};
|
||||
|
||||
#[test]
|
||||
fn test_boot_checkin() {
|
||||
+ let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
let data = packet::PacketData {
|
||||
id: String::new(),
|
||||
hostname: String::new(),
|
||||
@@ -19,7 +20,10 @@ fn test_boot_checkin() {
|
||||
error: None,
|
||||
phone_home_url: mockito::server_url(),
|
||||
};
|
||||
- let provider = packet::PacketProvider { data };
|
||||
+ let provider = packet::PacketProvider {
|
||||
+ client: client.clone(),
|
||||
+ data,
|
||||
+ };
|
||||
|
||||
let mock = mockito::mock("POST", "/")
|
||||
.match_header(
|
||||
@@ -37,7 +41,6 @@ fn test_boot_checkin() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
packet::PacketProvider::fetch_content(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
diff --git a/src/providers/packet/mod.rs b/src/providers/packet/mod.rs
|
||||
index be180a546583..98a4018581b4 100644
|
||||
--- a/src/providers/packet/mod.rs
|
||||
+++ b/src/providers/packet/mod.rs
|
||||
@@ -90,6 +90,7 @@ struct PacketAddressInfo {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PacketProvider {
|
||||
+ client: retry::Client,
|
||||
data: PacketData,
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ impl PacketProvider {
|
||||
.send()?
|
||||
.ok_or_else(|| anyhow!("metadata endpoint unreachable"))?;
|
||||
|
||||
- Ok(Self { data })
|
||||
+ Ok(Self { client, data })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -386,9 +387,8 @@ impl MetadataProvider for PacketProvider {
|
||||
}
|
||||
|
||||
fn boot_checkin(&self) -> Result<()> {
|
||||
- let client = retry::Client::try_new()?;
|
||||
let url = self.data.phone_home_url.clone();
|
||||
- client.post(retry::Json, url, None).dispatch_post()?;
|
||||
+ self.client.post(retry::Json, url, None).dispatch_post()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
--
|
||||
2.39.2
|
||||
|
@ -0,0 +1,67 @@
|
||||
From 29c4681ccdb7f8b09e4fc12bc98d184c63e1d0b4 Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Gilbert <bgilbert@redhat.com>
|
||||
Date: Mon, 20 Mar 2023 01:33:10 -0400
|
||||
Subject: [PATCH 2/6] providers/microsoft: use stored client for all fetches
|
||||
|
||||
Be sure to use any custom settings on the stored client.
|
||||
---
|
||||
src/providers/microsoft/azure/mod.rs | 8 ++++++--
|
||||
src/providers/microsoft/azurestack/mod.rs | 7 ++++---
|
||||
2 files changed, 10 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/providers/microsoft/azure/mod.rs b/src/providers/microsoft/azure/mod.rs
|
||||
index a3582ae68be7..1d2803c797c3 100644
|
||||
--- a/src/providers/microsoft/azure/mod.rs
|
||||
+++ b/src/providers/microsoft/azure/mod.rs
|
||||
@@ -338,7 +338,9 @@ impl Azure {
|
||||
const NAME_URL: &str = "metadata/instance/compute/name?api-version=2017-08-01&format=text";
|
||||
let url = format!("{}/{}", Self::metadata_endpoint(), NAME_URL);
|
||||
|
||||
- let name = retry::Client::try_new()?
|
||||
+ let name = self
|
||||
+ .client
|
||||
+ .clone()
|
||||
.header(
|
||||
HeaderName::from_static("metadata"),
|
||||
HeaderValue::from_static("true"),
|
||||
@@ -354,7 +356,9 @@ impl Azure {
|
||||
"metadata/instance/compute/vmSize?api-version=2017-08-01&format=text";
|
||||
let url = format!("{}/{}", Self::metadata_endpoint(), VMSIZE_URL);
|
||||
|
||||
- let vmsize = retry::Client::try_new()?
|
||||
+ let vmsize = self
|
||||
+ .client
|
||||
+ .clone()
|
||||
.header(
|
||||
HeaderName::from_static("metadata"),
|
||||
HeaderValue::from_static("true"),
|
||||
diff --git a/src/providers/microsoft/azurestack/mod.rs b/src/providers/microsoft/azurestack/mod.rs
|
||||
index a0552fbc6a69..04974398ee40 100644
|
||||
--- a/src/providers/microsoft/azurestack/mod.rs
|
||||
+++ b/src/providers/microsoft/azurestack/mod.rs
|
||||
@@ -168,10 +168,11 @@ impl AzureStack {
|
||||
.ok_or_else(|| anyhow!("failed to get goal state: not found response"))
|
||||
}
|
||||
|
||||
- fn fetch_identity() -> Result<InstanceMetadata> {
|
||||
+ fn fetch_identity(&self) -> Result<InstanceMetadata> {
|
||||
const NAME_URL: &str = "Microsoft.Compute/identity?api-version=2019-03-11";
|
||||
let url = format!("{}/{}", Self::metadata_endpoint(), NAME_URL);
|
||||
- retry::Client::try_new()?
|
||||
+ self.client
|
||||
+ .clone()
|
||||
.header(
|
||||
HeaderName::from_static("metadata"),
|
||||
HeaderValue::from_static("true"),
|
||||
@@ -306,7 +307,7 @@ impl AzureStack {
|
||||
}
|
||||
|
||||
fn fetch_hostname(&self) -> Result<Option<String>> {
|
||||
- let instance_metadata = AzureStack::fetch_identity()?;
|
||||
+ let instance_metadata = self.fetch_identity()?;
|
||||
Ok(Some(instance_metadata.vm_name))
|
||||
}
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
87
0003-providers-microsoft-import-crate-retry.patch
Normal file
87
0003-providers-microsoft-import-crate-retry.patch
Normal file
@ -0,0 +1,87 @@
|
||||
From 1e46b818717d250dc3e0a43a0680e919f7c1c3df Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Gilbert <bgilbert@redhat.com>
|
||||
Date: Mon, 20 Mar 2023 02:32:15 -0400
|
||||
Subject: [PATCH 3/6] providers/microsoft: import crate::retry
|
||||
|
||||
---
|
||||
src/providers/microsoft/azure/mock_tests.rs | 7 ++++---
|
||||
src/providers/microsoft/azurestack/mock_tests.rs | 7 ++++---
|
||||
2 files changed, 8 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/providers/microsoft/azure/mock_tests.rs b/src/providers/microsoft/azure/mock_tests.rs
|
||||
index 93682012554b..476555dc6368 100644
|
||||
--- a/src/providers/microsoft/azure/mock_tests.rs
|
||||
+++ b/src/providers/microsoft/azure/mock_tests.rs
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::providers::{microsoft::azure, MetadataProvider};
|
||||
+use crate::retry;
|
||||
use mockito::{self, Matcher};
|
||||
|
||||
/// Response body for goalstate (with certificates endpoint).
|
||||
@@ -135,7 +136,7 @@ fn test_boot_checkin() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azure::Azure::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ fn test_hostname() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azure::Azure::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -192,7 +193,7 @@ fn test_vmsize() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azure::Azure::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
diff --git a/src/providers/microsoft/azurestack/mock_tests.rs b/src/providers/microsoft/azurestack/mock_tests.rs
|
||||
index 8c5a0d26399e..655908237337 100644
|
||||
--- a/src/providers/microsoft/azurestack/mock_tests.rs
|
||||
+++ b/src/providers/microsoft/azurestack/mock_tests.rs
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::providers::{microsoft::azurestack, MetadataProvider};
|
||||
+use crate::retry;
|
||||
use mockito::{self, Matcher};
|
||||
|
||||
/// Response body for goalstate (with certificates endpoint).
|
||||
@@ -135,7 +136,7 @@ fn test_boot_checkin() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azurestack::AzureStack::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ fn test_identity() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azurestack::AzureStack::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ fn test_hostname() {
|
||||
mockito::reset();
|
||||
|
||||
// Check error logic, but fail fast without re-trying.
|
||||
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
|
||||
+ let client = retry::Client::try_new().unwrap().max_retries(0);
|
||||
azurestack::AzureStack::with_client(Some(client)).unwrap_err();
|
||||
}
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
@ -0,0 +1,54 @@
|
||||
From feda37277c361a29a67ab2549f8fe292c35429dd Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Gilbert <bgilbert@redhat.com>
|
||||
Date: Sun, 19 Mar 2023 23:55:38 -0400
|
||||
Subject: [PATCH 4/6] retry/client: move URL parsing into helper function
|
||||
|
||||
---
|
||||
src/retry/client.rs | 10 +++++++---
|
||||
1 file changed, 7 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/retry/client.rs b/src/retry/client.rs
|
||||
index a94c4ec7f09b..e113fe4bc69a 100644
|
||||
--- a/src/retry/client.rs
|
||||
+++ b/src/retry/client.rs
|
||||
@@ -213,7 +213,7 @@ where
|
||||
where
|
||||
T: for<'de> serde::Deserialize<'de>,
|
||||
{
|
||||
- let url = reqwest::Url::parse(self.url.as_str()).context("failed to parse uri")?;
|
||||
+ let url = self.parse_url()?;
|
||||
let mut req = blocking::Request::new(Method::GET, url);
|
||||
req.headers_mut().extend(self.headers.clone().into_iter());
|
||||
|
||||
@@ -227,7 +227,7 @@ where
|
||||
where
|
||||
T: for<'de> serde::Deserialize<'de>,
|
||||
{
|
||||
- let url = reqwest::Url::parse(self.url.as_str()).context("failed to parse uri")?;
|
||||
+ let url = self.parse_url()?;
|
||||
|
||||
self.retry.clone().retry(|attempt| {
|
||||
let mut builder = blocking::Client::new()
|
||||
@@ -254,7 +254,7 @@ where
|
||||
}
|
||||
|
||||
pub fn dispatch_post(self) -> Result<reqwest::StatusCode> {
|
||||
- let url = reqwest::Url::parse(self.url.as_str()).context("failed to parse uri")?;
|
||||
+ let url = self.parse_url()?;
|
||||
|
||||
self.retry.clone().retry(|attempt| {
|
||||
let mut builder = blocking::Client::new()
|
||||
@@ -308,6 +308,10 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
+
|
||||
+ fn parse_url(&self) -> Result<reqwest::Url> {
|
||||
+ reqwest::Url::parse(self.url.as_str()).context("failed to parse uri")
|
||||
+ }
|
||||
}
|
||||
|
||||
/// Reqwests Request struct doesn't implement `Clone`,
|
||||
--
|
||||
2.39.2
|
||||
|
1047
0005-providers-move-endpoint-mocking-into-retry-Client.patch
Normal file
1047
0005-providers-move-endpoint-mocking-into-retry-Client.patch
Normal file
File diff suppressed because it is too large
Load Diff
1246
0006-Update-mockito-to-1.0.patch
Normal file
1246
0006-Update-mockito-to-1.0.patch
Normal file
File diff suppressed because it is too large
Load Diff
9
0007-Bump-mockito-version.patch
Normal file
9
0007-Bump-mockito-version.patch
Normal file
@ -0,0 +1,9 @@
|
||||
diff -ur a/Cargo.toml b/Cargo.toml
|
||||
--- a/Cargo.toml 1969-12-31 19:00:01.000000000 -0500
|
||||
+++ b/Cargo.toml 2023-03-20 20:44:02.135392305 -0400
|
||||
@@ -132,4 +132,4 @@
|
||||
version = ">= 2.3, < 4"
|
||||
|
||||
[dev-dependencies.mockito]
|
||||
-version = ">= 0.29, < 0.32"
|
||||
+version = "1"
|
@ -8,7 +8,7 @@
|
||||
|
||||
Name: rust-%{crate}
|
||||
Version: 5.4.0
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
Summary: Simple cloud provider agent
|
||||
|
||||
# Upstream license specification: Apache-2.0
|
||||
@ -18,6 +18,16 @@ Source0: %{crates_source}
|
||||
# not used on Fedora
|
||||
Source1: https://github.com/coreos/%{crate}/releases/download/v%{version}/%{crate}-%{version}-vendor.tar.gz
|
||||
|
||||
# Use rust-mockito 1.0 API
|
||||
# Based on https://github.com/coreos/afterburn/pull/894, fixing merge conflicts
|
||||
Patch0: 0001-providers-packet-use-stored-client-for-boot-checkin.patch
|
||||
Patch1: 0002-providers-microsoft-use-stored-client-for-all-fetche.patch
|
||||
Patch2: 0003-providers-microsoft-import-crate-retry.patch
|
||||
Patch3: 0004-retry-client-move-URL-parsing-into-helper-function.patch
|
||||
Patch4: 0005-providers-move-endpoint-mocking-into-retry-Client.patch
|
||||
Patch5: 0006-Update-mockito-to-1.0.patch
|
||||
Patch6: 0007-Bump-mockito-version.patch
|
||||
|
||||
ExclusiveArch: %{rust_arches}
|
||||
%if 0%{?rhel} && !0%{?eln}
|
||||
BuildRequires: rust-toolset
|
||||
@ -143,6 +153,9 @@ cp -a dracut/* %{buildroot}%{dracutmodulesdir}
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Mon Mar 20 2023 Benjamin Gilbert <bgilbert@redhat.com> - 5.4.0-2
|
||||
- Update for Mockito 1.0 API
|
||||
|
||||
* Fri Feb 03 2023 Benjamin Gilbert <bgilbert@redhat.com> - 5.4.0-1
|
||||
- Update to 5.4.0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user