lock: Return message text on success
Since the lock API is intended to be used from command-line utilities and shell scripts, we should return a helpful message when successful.master
parent
4bb72900fa
commit
2ea03c6670
|
@ -119,7 +119,7 @@ async fn wait_lease(client: Client, name: &str) -> Result<(), kube::Error> {
|
|||
pub async fn lock_v1(
|
||||
lockheader: Result<LockRequestHeader, InvalidHeader>,
|
||||
data: rocket::form::Result<'_, Form<LockRequest>>,
|
||||
) -> Result<(), LockError> {
|
||||
) -> Result<String, LockError> {
|
||||
lockheader?;
|
||||
let data = data?;
|
||||
let client = Client::try_default().await.inspect_err(|e| {
|
||||
|
@ -159,7 +159,10 @@ pub async fn lock_v1(
|
|||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(format!(
|
||||
"Acquired reboot lock for group {}, host {}\n",
|
||||
data.group, data.hostname
|
||||
))
|
||||
}
|
||||
|
||||
#[rocket::post("/api/v1/unlock", data = "<data>")]
|
||||
|
|
|
@ -43,7 +43,12 @@ async fn test_lock_v1_success() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
assert_eq!(
|
||||
response.into_string().await.as_deref(),
|
||||
Some(
|
||||
"Acquired reboot lock for group default, host test1.example.org\n"
|
||||
)
|
||||
);
|
||||
let lease = get_lease("reboot-lock-default").await.unwrap();
|
||||
assert_eq!(
|
||||
lease.spec.unwrap().holder_identity.as_deref(),
|
||||
|
@ -65,7 +70,12 @@ async fn test_lock_v1_custom_group() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
assert_eq!(
|
||||
response.into_string().await.as_deref(),
|
||||
Some(
|
||||
"Acquired reboot lock for group testgroup, host test1.example.org\n"
|
||||
)
|
||||
);
|
||||
let lease = get_lease("reboot-lock-testgroup").await.unwrap();
|
||||
assert_eq!(
|
||||
lease.spec.unwrap().holder_identity.as_deref(),
|
||||
|
@ -88,7 +98,12 @@ async fn test_lock_v1_conflict() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
assert_eq!(
|
||||
response.into_string().await.as_deref(),
|
||||
Some(
|
||||
"Acquired reboot lock for group default, host test1.example.org\n"
|
||||
)
|
||||
);
|
||||
let response = client
|
||||
.post("/api/v1/lock")
|
||||
.header(Header::new("K8s-Reboot-Lock", "lock"))
|
||||
|
@ -129,7 +144,12 @@ async fn test_lock_v1_conflict_wait() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
assert_eq!(
|
||||
response.into_string().await.as_deref(),
|
||||
Some(
|
||||
"Acquired reboot lock for group default, host test1.example.org\n"
|
||||
)
|
||||
);
|
||||
let lease = get_lease("reboot-lock-default").await.unwrap();
|
||||
assert_eq!(
|
||||
lease.spec.unwrap().holder_identity.as_deref(),
|
||||
|
@ -153,7 +173,12 @@ async fn test_lock_v1_conflict_wait() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
assert_eq!(
|
||||
response.into_string().await.as_deref(),
|
||||
Some(
|
||||
"Acquired reboot lock for group default, host test2.example.org\n"
|
||||
)
|
||||
);
|
||||
let duration = timer.elapsed().as_millis();
|
||||
assert!(duration > 1000 && duration < 2000);
|
||||
let lease = get_lease("reboot-lock-default").await.unwrap();
|
||||
|
@ -213,7 +238,6 @@ async fn test_unlock_v1_success() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
let lease = get_lease("reboot-lock-default").await.unwrap();
|
||||
assert_eq!(
|
||||
lease.spec.unwrap().holder_identity.as_deref(),
|
||||
|
@ -269,7 +293,6 @@ async fn test_unlock_v1_not_mine() {
|
|||
.dispatch()
|
||||
.await;
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string().await, None);
|
||||
let lease = get_lease("reboot-lock-default").await.unwrap();
|
||||
assert_eq!(
|
||||
lease.spec.unwrap().holder_identity.as_deref(),
|
||||
|
|
Loading…
Reference in New Issue