Add support to reset checkpoint state
This patch added clinet support for doing checkpoint state reset. Implements: bp checkpoint-status-reset Change-Id: Id34501bd4d43c6ae0e9d0d789be7e92581cbff8c
This commit is contained in:
parent
262799e3c0
commit
048b3a0bd9
|
@ -20,6 +20,7 @@ mock_request_return = ({}, {'checkpoint': {}})
|
|||
|
||||
FAKE_PROVIDER_ID = "2220f8b1-975d-4621-a872-fa9afb43cb6c"
|
||||
FAKE_PLAN_ID = "3330f8b1-975d-4621-a872-fa9afb43cb6c"
|
||||
FAKE_CHECKPOINT_ID = "e4381b1a-905e-4fec-8104-b4419ccaf963"
|
||||
|
||||
|
||||
class CheckpointsTest(base.TestCaseShell):
|
||||
|
@ -100,3 +101,17 @@ class CheckpointsTest(base.TestCaseShell):
|
|||
data={
|
||||
'checkpoint': {'plan_id': FAKE_PLAN_ID, 'extra-info': None}},
|
||||
headers={})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_reset_checkpoint_state(self, mock_request):
|
||||
mock_request.return_value = ({}, {})
|
||||
cs.checkpoints.reset_state(
|
||||
FAKE_PROVIDER_ID, FAKE_CHECKPOINT_ID, 'error')
|
||||
mock_request.assert_called_with(
|
||||
'PUT',
|
||||
'/providers/{provider_id}/checkpoints/{checkpoint_id}'.format(
|
||||
provider_id=FAKE_PROVIDER_ID,
|
||||
checkpoint_id=FAKE_CHECKPOINT_ID
|
||||
),
|
||||
data={'os-resetState': {'state': 'error'}},
|
||||
headers={})
|
||||
|
|
|
@ -43,6 +43,15 @@ class CheckpointManager(base.ManagerWithFind):
|
|||
"checkpoints" .format(provider_id=provider_id)
|
||||
return self._create(url, body, 'checkpoint')
|
||||
|
||||
def reset_state(self, provider_id, checkpoint_id, state):
|
||||
body = {'os-resetState': {'state': state}}
|
||||
return self.update(provider_id, checkpoint_id, body)
|
||||
|
||||
def update(self, provider_id, checkpoint_id, values):
|
||||
url = '/providers/{provider_id}/checkpoints/{checkpoint_id}'.format(
|
||||
provider_id=provider_id, checkpoint_id=checkpoint_id)
|
||||
return self._update(url, values)
|
||||
|
||||
def delete(self, provider_id, checkpoint_id):
|
||||
path = '/providers/{provider_id}/checkpoints/' \
|
||||
'{checkpoint_id}'.format(provider_id=provider_id,
|
||||
|
|
|
@ -866,6 +866,45 @@ def do_checkpoint_delete(cs, args):
|
|||
"specified checkpoint.")
|
||||
|
||||
|
||||
@utils.arg('provider_id',
|
||||
metavar='<provider_id>',
|
||||
help='Id of provider.')
|
||||
@utils.arg('checkpoint',
|
||||
metavar='<checkpoint>',
|
||||
nargs="+",
|
||||
help='ID of checkpoint.')
|
||||
@utils.arg('--available',
|
||||
action='store_const',
|
||||
dest='state',
|
||||
default='error',
|
||||
const='available',
|
||||
help='Request the checkpoint be reset to "available" state instead '
|
||||
'of "error" state(the default).')
|
||||
def do_checkpoint_reset_state(cs, args):
|
||||
"""Reset state of a checkpoint."""
|
||||
failure_count = 0
|
||||
|
||||
for checkpoint_id in args.checkpoint:
|
||||
try:
|
||||
cs.checkpoints.reset_state(args.provider_id, checkpoint_id,
|
||||
args.state)
|
||||
except exceptions.NotFound:
|
||||
failure_count += 1
|
||||
print("Failed to reset state of '{0}'; checkpoint not found".
|
||||
format(checkpoint_id))
|
||||
except exceptions.Forbidden:
|
||||
failure_count += 1
|
||||
print("Failed to reset state of '{0}'; not allowed".
|
||||
format(checkpoint_id))
|
||||
except exceptions.BadRequest:
|
||||
failure_count += 1
|
||||
print("Failed to reset state of '{0}'; invalid input or "
|
||||
"current checkpoint state".format(checkpoint_id))
|
||||
if failure_count == len(args.checkpoint):
|
||||
raise exceptions.CommandError("Unable to find or reset any of the "
|
||||
"specified checkpoint's state.")
|
||||
|
||||
|
||||
@utils.arg('--all-tenants',
|
||||
dest='all_tenants',
|
||||
metavar='<0|1>',
|
||||
|
|
Loading…
Reference in New Issue