Allow settings --task-state without value (to send null) or None

The osc commands `openstack share set <share-id> --task-state` and
`openstack share server set <share-server-id> --task-state` were
failing when no value was provided, or when None was passed as an
argument, leading to the API receive the string "null" instead of
the JSON null value.

This change makes the --task-state argument optional, allowing it
to be specified without a value or with the string "None".
In both cases, the command correctly interprets these inputs as a
request to clear the task state by sending a proper null value to
the API.

Test Plan:
- Added unittests for --task-state argument handling both share set
and share server set commands.
- Verified cases when --task-state is provided without a value
(interpreted as None) or with value "None" (ensuring it is properly
converted to None).

Closes-Bug: #2108991
Change-Id: Ic2a9eed81154bfbe8517c7411da72f1e4d0e1e64
Signed-off-by: llmtech-dev <llm.tech.developer@gmail.com>
This commit is contained in:
llmtech-dev
2025-10-22 16:32:28 +00:00
parent 4bde7759b6
commit d0060a45a9
5 changed files with 85 additions and 4 deletions

View File

@@ -796,6 +796,7 @@ class SetShare(command.Command):
metavar="<task-state>",
required=False,
default=None,
nargs='?',
help=_("Indicate which task state to assign the share. Options "
"include migration_starting, migration_in_progress, "
"migration_completing, migration_success, migration_error, "
@@ -844,9 +845,12 @@ class SetShare(command.Command):
LOG.error(_(
"Failed to set status for the share: %s"), e)
result += 1
if parsed_args.task_state:
if hasattr(parsed_args, 'task_state'):
task_state = parsed_args.task_state
if task_state and task_state.lower() == "none":
task_state = None
try:
share_obj.reset_task_state(parsed_args.task_state)
share_obj.reset_task_state(task_state)
except Exception as e:
LOG.error(_("Failed to update share task state "
"%s"), e)

View File

@@ -435,6 +435,7 @@ class SetShareServer(command.Command):
metavar="<task-state>",
required=False,
default=None,
nargs='?',
help=_("Indicate which task state to assign the share server. "
"Options include migration_starting, migration_in_progress,"
" migration_completing, migration_success, migration_error,"
@@ -471,16 +472,19 @@ class SetShareServer(command.Command):
LOG.error(msg)
raise exceptions.CommandError(msg)
if parsed_args.task_state:
if hasattr(parsed_args, 'task_state'):
if share_client.api_version < api_versions.APIVersion("2.57"):
raise exceptions.CommandError(
"Setting the state of a share server is only available "
"with manila API version >= 2.57")
else:
task_state = parsed_args.task_state
if task_state and task_state.lower() == "none":
task_state = None
result = 0
try:
share_client.share_servers.reset_task_state(
share_server, parsed_args.task_state)
share_server, task_state)
except Exception as e:
LOG.error(_("Failed to update share server task state "
"%s"), e)

View File

@@ -1406,6 +1406,34 @@ class TestShareSet(TestShare):
self._share.reset_task_state.assert_called_with(new_task_state)
self.assertIsNone(result)
def test_share_set_task_state_none(self):
arglist = [
self._share.id,
'--task-state'
]
verifylist = [
('share', self._share.id),
('task_state', None)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self._share.reset_task_state.assert_called_with(None)
self.assertIsNone(result)
def test_share_set_task_state_string_none(self):
arglist = [
self._share.id,
'--task-state', 'None'
]
verifylist = [
('share', self._share.id),
('task_state', 'None')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self._share.reset_task_state.assert_called_with(None)
self.assertIsNone(result)
class TestShareUnset(TestShare):

View File

@@ -564,6 +564,44 @@ class TestSetShareServer(TestShareServer):
parsed_args.task_state)
self.assertIsNone(result)
def test_share_server_set_task_state_none(self):
arglist = [
self.share_server.id,
'--task-state',
]
verifylist = [
('share_server', self.share_server.id),
('task_state', None)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.servers_mock.reset_task_state.assert_called_with(
self.share_server,
None)
self.assertIsNone(result)
def test_share_server_set_task_state_string_none(self):
arglist = [
self.share_server.id,
'--task-state', 'None'
]
verifylist = [
('share_server', self.share_server.id),
('task_state', 'None')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.servers_mock.reset_task_state.assert_called_with(
self.share_server,
None)
self.assertIsNone(result)
def test_share_server_set_status_exception(self):
arglist = [
self.share_server.id,

View File

@@ -0,0 +1,7 @@
---
fixes:
- |
The `openstack share set` and `openstack share server set` commands now
properly handle the `--task-state` argument when given no value or "None",
sending a proper null value to the API. For more details, please refer to
`Launchpad bug #2108991 <https://bugs.launchpad.net/python-manilaclient/+bug/2108991>`_.