mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 19:16:17 +00:00
mc test ok
This commit is contained in:
+28
-31
@@ -6,9 +6,9 @@ use crate::{
|
||||
global::global_rustfs_port,
|
||||
utils::net::{self, XHost},
|
||||
};
|
||||
use common::error::{Error, Result};
|
||||
use std::io::{Error, Result};
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap, HashSet},
|
||||
collections::{HashMap, HashSet, hash_map::Entry},
|
||||
net::IpAddr,
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ impl<T: AsRef<str>> TryFrom<&[T]> for Endpoints {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
let endpoint = match Endpoint::try_from(arg.as_ref()) {
|
||||
Ok(ep) => ep,
|
||||
Err(e) => return Err(Error::from_string(format!("'{}': {}", arg.as_ref(), e))),
|
||||
Err(e) => return Err(Error::other(format!("'{}': {}", arg.as_ref(), e))),
|
||||
};
|
||||
|
||||
// All endpoints have to be same type and scheme if applicable.
|
||||
@@ -84,15 +84,15 @@ impl<T: AsRef<str>> TryFrom<&[T]> for Endpoints {
|
||||
endpoint_type = Some(endpoint.get_type());
|
||||
schema = Some(endpoint.url.scheme().to_owned());
|
||||
} else if Some(endpoint.get_type()) != endpoint_type {
|
||||
return Err(Error::from_string("mixed style endpoints are not supported"));
|
||||
return Err(Error::other("mixed style endpoints are not supported"));
|
||||
} else if Some(endpoint.url.scheme()) != schema.as_deref() {
|
||||
return Err(Error::from_string("mixed scheme is not supported"));
|
||||
return Err(Error::other("mixed scheme is not supported"));
|
||||
}
|
||||
|
||||
// Check for duplicate endpoints.
|
||||
let endpoint_str = endpoint.to_string();
|
||||
if uniq_set.contains(&endpoint_str) {
|
||||
return Err(Error::from_string("duplicate endpoints found"));
|
||||
return Err(Error::other("duplicate endpoints found"));
|
||||
}
|
||||
|
||||
uniq_set.insert(endpoint_str);
|
||||
@@ -156,7 +156,7 @@ impl PoolEndpointList {
|
||||
/// hostnames and discovers those are local or remote.
|
||||
fn create_pool_endpoints(server_addr: &str, disks_layout: &DisksLayout) -> Result<Self> {
|
||||
if disks_layout.is_empty_layout() {
|
||||
return Err(Error::from_string("invalid number of endpoints"));
|
||||
return Err(Error::other("invalid number of endpoints"));
|
||||
}
|
||||
|
||||
let server_addr = net::check_local_server_addr(server_addr)?;
|
||||
@@ -167,7 +167,7 @@ impl PoolEndpointList {
|
||||
endpoint.update_is_local(server_addr.port())?;
|
||||
|
||||
if endpoint.get_type() != EndpointType::Path {
|
||||
return Err(Error::from_string("use path style endpoint for single node setup"));
|
||||
return Err(Error::other("use path style endpoint for single node setup"));
|
||||
}
|
||||
|
||||
endpoint.set_pool_index(0);
|
||||
@@ -201,7 +201,7 @@ impl PoolEndpointList {
|
||||
}
|
||||
|
||||
if endpoints.as_ref().is_empty() {
|
||||
return Err(Error::from_string("invalid number of endpoints"));
|
||||
return Err(Error::other("invalid number of endpoints"));
|
||||
}
|
||||
|
||||
pool_endpoints.push(endpoints);
|
||||
@@ -227,15 +227,14 @@ impl PoolEndpointList {
|
||||
|
||||
let host = ep.url.host().unwrap();
|
||||
let host_ip_set = host_ip_cache.entry(host.clone()).or_insert({
|
||||
net::get_host_ip(host.clone())
|
||||
.map_err(|e| Error::from_string(format!("host '{}' cannot resolve: {}", host, e)))?
|
||||
net::get_host_ip(host.clone()).map_err(|e| Error::other(format!("host '{}' cannot resolve: {}", host, e)))?
|
||||
});
|
||||
|
||||
let path = ep.get_file_path();
|
||||
match path_ip_map.entry(path) {
|
||||
Entry::Occupied(mut e) => {
|
||||
if e.get().intersection(host_ip_set).count() > 0 {
|
||||
return Err(Error::from_string(format!(
|
||||
return Err(Error::other(format!(
|
||||
"same path '{}' can not be served by different port on same address",
|
||||
path
|
||||
)));
|
||||
@@ -257,7 +256,7 @@ impl PoolEndpointList {
|
||||
|
||||
let path = ep.get_file_path();
|
||||
if local_path_set.contains(path) {
|
||||
return Err(Error::from_string(format!(
|
||||
return Err(Error::other(format!(
|
||||
"path '{}' cannot be served by different address on same server",
|
||||
path
|
||||
)));
|
||||
@@ -285,7 +284,7 @@ impl PoolEndpointList {
|
||||
// If all endpoints have same port number, Just treat it as local erasure setup
|
||||
// using URL style endpoints.
|
||||
if local_port_set.len() == 1 && local_server_host_set.len() > 1 {
|
||||
return Err(Error::from_string("all local endpoints should not have different hostnames/ips"));
|
||||
return Err(Error::other("all local endpoints should not have different hostnames/ips"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +452,7 @@ impl EndpointServerPools {
|
||||
/// both ellipses and without ellipses transparently.
|
||||
pub fn create_server_endpoints(server_addr: &str, disks_layout: &DisksLayout) -> Result<(EndpointServerPools, SetupType)> {
|
||||
if disks_layout.pools.is_empty() {
|
||||
return Err(Error::from_string("Invalid arguments specified"));
|
||||
return Err(Error::other("Invalid arguments specified"));
|
||||
}
|
||||
|
||||
let pool_eps = PoolEndpointList::create_pool_endpoints(server_addr, disks_layout)?;
|
||||
@@ -490,7 +489,7 @@ impl EndpointServerPools {
|
||||
|
||||
for ep in eps.endpoints.as_ref() {
|
||||
if exits.contains(&ep.to_string()) {
|
||||
return Err(Error::from_string("duplicate endpoints found"));
|
||||
return Err(Error::other("duplicate endpoints found"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,8 +663,8 @@ mod test {
|
||||
None,
|
||||
6,
|
||||
),
|
||||
(vec!["d1", "d2", "d3", "d1"], Some(Error::from_string("duplicate endpoints found")), 7),
|
||||
(vec!["d1", "d2", "d3", "./d1"], Some(Error::from_string("duplicate endpoints found")), 8),
|
||||
(vec!["d1", "d2", "d3", "d1"], Some(Error::other("duplicate endpoints found")), 7),
|
||||
(vec!["d1", "d2", "d3", "./d1"], Some(Error::other("duplicate endpoints found")), 8),
|
||||
(
|
||||
vec![
|
||||
"http://localhost/d1",
|
||||
@@ -673,17 +672,17 @@ mod test {
|
||||
"http://localhost/d1",
|
||||
"http://localhost/d4",
|
||||
],
|
||||
Some(Error::from_string("duplicate endpoints found")),
|
||||
Some(Error::other("duplicate endpoints found")),
|
||||
9,
|
||||
),
|
||||
(
|
||||
vec!["ftp://server/d1", "http://server/d2", "http://server/d3", "http://server/d4"],
|
||||
Some(Error::from_string("'ftp://server/d1': invalid URL endpoint format")),
|
||||
Some(Error::other("'ftp://server/d1': invalid URL endpoint format")),
|
||||
10,
|
||||
),
|
||||
(
|
||||
vec!["d1", "http://localhost/d2", "d3", "d4"],
|
||||
Some(Error::from_string("mixed style endpoints are not supported")),
|
||||
Some(Error::other("mixed style endpoints are not supported")),
|
||||
11,
|
||||
),
|
||||
(
|
||||
@@ -693,7 +692,7 @@ mod test {
|
||||
"http://example.net/d1",
|
||||
"https://example.edut/d1",
|
||||
],
|
||||
Some(Error::from_string("mixed scheme is not supported")),
|
||||
Some(Error::other("mixed scheme is not supported")),
|
||||
12,
|
||||
),
|
||||
(
|
||||
@@ -703,7 +702,7 @@ mod test {
|
||||
"192.168.1.210:9000/tmp/dir2",
|
||||
"192.168.110:9000/tmp/dir3",
|
||||
],
|
||||
Some(Error::from_string(
|
||||
Some(Error::other(
|
||||
"'192.168.1.210:9000/tmp/dir0': invalid URL endpoint format: missing scheme http or https",
|
||||
)),
|
||||
13,
|
||||
@@ -811,7 +810,7 @@ mod test {
|
||||
TestCase {
|
||||
num: 1,
|
||||
server_addr: "localhost",
|
||||
expected_err: Some(Error::from_string("address localhost: missing port in address")),
|
||||
expected_err: Some(Error::other("address localhost: missing port in address")),
|
||||
..Default::default()
|
||||
},
|
||||
// Erasure Single Drive
|
||||
@@ -819,7 +818,7 @@ mod test {
|
||||
num: 2,
|
||||
server_addr: "localhost:9000",
|
||||
args: vec!["http://localhost/d1"],
|
||||
expected_err: Some(Error::from_string("use path style endpoint for single node setup")),
|
||||
expected_err: Some(Error::other("use path style endpoint for single node setup")),
|
||||
..Default::default()
|
||||
},
|
||||
TestCase {
|
||||
@@ -859,7 +858,7 @@ mod test {
|
||||
"https://example.com/d1",
|
||||
"https://example.com/d2",
|
||||
],
|
||||
expected_err: Some(Error::from_string("same path '/d1' can not be served by different port on same address")),
|
||||
expected_err: Some(Error::other("same path '/d1' can not be served by different port on same address")),
|
||||
..Default::default()
|
||||
},
|
||||
// Erasure Setup with PathEndpointType
|
||||
@@ -953,7 +952,7 @@ mod test {
|
||||
"http://127.0.0.1/d3",
|
||||
"http://127.0.0.1/d4",
|
||||
],
|
||||
expected_err: Some(Error::from_string("all local endpoints should not have different hostnames/ips")),
|
||||
expected_err: Some(Error::other("all local endpoints should not have different hostnames/ips")),
|
||||
..Default::default()
|
||||
},
|
||||
TestCase {
|
||||
@@ -965,9 +964,7 @@ mod test {
|
||||
case7_endpoint1.as_str(),
|
||||
"http://10.0.0.2:9001/export",
|
||||
],
|
||||
expected_err: Some(Error::from_string(
|
||||
"same path '/export' can not be served by different port on same address",
|
||||
)),
|
||||
expected_err: Some(Error::other("same path '/export' can not be served by different port on same address")),
|
||||
..Default::default()
|
||||
},
|
||||
TestCase {
|
||||
@@ -979,7 +976,7 @@ mod test {
|
||||
"http://10.0.0.1:9000/export",
|
||||
"http://10.0.0.2:9000/export",
|
||||
],
|
||||
expected_err: Some(Error::from_string("path '/export' cannot be served by different address on same server")),
|
||||
expected_err: Some(Error::other("path '/export' cannot be served by different address on same server")),
|
||||
..Default::default()
|
||||
},
|
||||
// DistErasure type
|
||||
|
||||
Reference in New Issue
Block a user