virt: Remove 'reset_network' API

This one is tied into an admin action in the server actions API, which
means we must remove that API action also. Otherwise, this isn't too
crazy.

Change-Id: I58343b94b67915062d044fa0f53aeab01b77738f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-09-01 09:53:10 +01:00
parent 30067be9bd
commit 68bc87876f
17 changed files with 28 additions and 136 deletions

View File

@ -170,16 +170,19 @@ Response
If successful, this method does not return content in the response body. If successful, this method does not return content in the response body.
Reset Networking On A Server (resetNetwork Action) Reset Networking On A Server (resetNetwork Action) (DEPRECATED)
================================================== ===============================================================
.. rest_method:: POST /servers/{server_id}/action .. rest_method:: POST /servers/{server_id}/action
Resets networking on a server. Resets networking on a server.
.. note:: .. warning::
No longer supported by any in-tree virt driver. This action was only supported by the XenAPI virt driver, which was
deprecated in the 20.0.0 (Train) release and removed in the 22.0.0
(Victoria) release. This action should be avoided in new applications. It
was removed in the 23.0.0 (Wallaby) release.
Specify the ``resetNetwork`` action in the request body. Specify the ``resetNetwork`` action in the request body.
@ -190,7 +193,7 @@ through the ``policy.json`` file.
Normal response codes: 202 Normal response codes: 202
Error response codes: unauthorized(401), forbidden(403), itemNotFound(404), Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
conflict(409) conflict(409), gone(410)
Request Request
------- -------

View File

@ -34,19 +34,11 @@ class AdminActionsController(wsgi.Controller):
super(AdminActionsController, self).__init__() super(AdminActionsController, self).__init__()
self.compute_api = compute.API() self.compute_api = compute.API()
@wsgi.response(202) @wsgi.expected_errors(410)
@wsgi.expected_errors((404, 409))
@wsgi.action('resetNetwork') @wsgi.action('resetNetwork')
def _reset_network(self, req, id, body): def _reset_network(self, req, id, body):
"""Permit admins to reset networking on a server.""" """(Removed) Permit admins to reset networking on a server."""
context = req.environ['nova.context'] raise exc.HTTPGone()
instance = common.get_instance(self.compute_api, context, id)
context.can(aa_policies.POLICY_ROOT % 'reset_network',
target={'project_id': instance.project_id})
try:
self.compute_api.reset_network(context, instance)
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
@wsgi.response(202) @wsgi.response(202)
@wsgi.expected_errors((404, 409)) @wsgi.expected_errors((404, 409))

View File

@ -4530,11 +4530,6 @@ class API(base.Base):
action=fields_obj.NotificationAction.UNLOCK, action=fields_obj.NotificationAction.UNLOCK,
source=fields_obj.NotificationSource.API) source=fields_obj.NotificationSource.API)
@check_instance_lock
def reset_network(self, context, instance):
"""Reset networking on the instance."""
self.compute_rpcapi.reset_network(context, instance=instance)
@check_instance_lock @check_instance_lock
def inject_network_info(self, context, instance): def inject_network_info(self, context, instance):
"""Inject network info for the instance.""" """Inject network info for the instance."""

View File

@ -6075,7 +6075,6 @@ class ComputeManager(manager.Manager):
instance, instance,
network_id) network_id)
self._inject_network_info(instance, network_info) self._inject_network_info(instance, network_info)
self.reset_network(context, instance)
# NOTE(russellb) We just want to bump updated_at. See bug 1143466. # NOTE(russellb) We just want to bump updated_at. See bug 1143466.
instance.updated_at = timeutils.utcnow() instance.updated_at = timeutils.utcnow()
@ -6098,7 +6097,6 @@ class ComputeManager(manager.Manager):
instance, instance,
address) address)
self._inject_network_info(instance, network_info) self._inject_network_info(instance, network_info)
self.reset_network(context, instance)
# NOTE(russellb) We just want to bump updated_at. See bug 1143466. # NOTE(russellb) We just want to bump updated_at. See bug 1143466.
instance.updated_at = timeutils.utcnow() instance.updated_at = timeutils.utcnow()
@ -6629,11 +6627,9 @@ class ComputeManager(manager.Manager):
# TODO(stephenfin): Remove this in RPC 6.0 since it's nova-network only # TODO(stephenfin): Remove this in RPC 6.0 since it's nova-network only
@messaging.expected_exceptions(NotImplementedError) @messaging.expected_exceptions(NotImplementedError)
@wrap_instance_fault
def reset_network(self, context, instance): def reset_network(self, context, instance):
"""Reset networking on the given instance.""" """Reset networking on the given instance."""
LOG.debug('Reset network', instance=instance) raise NotImplementedError()
self.driver.reset_network(instance)
def _inject_network_info(self, instance, network_info): def _inject_network_info(self, instance, network_info):
"""Inject network info for the given instance.""" """Inject network info for the given instance."""

View File

@ -1124,13 +1124,6 @@ class ComputeAPI(object):
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'rescue_instance', **msg_args) cctxt.cast(ctxt, 'rescue_instance', **msg_args)
# Remove as it only supports nova network
def reset_network(self, ctxt, instance):
version = '5.0'
cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'reset_network', instance=instance)
def resize_instance(self, ctxt, instance, migration, image, instance_type, def resize_instance(self, ctxt, instance, migration, image, instance_type,
request_spec, clean_shutdown=True): request_spec, clean_shutdown=True):
msg_args = {'instance': instance, 'migration': migration, msg_args = {'instance': instance, 'migration': migration,

View File

@ -44,17 +44,6 @@ admin_actions_policies = [
} }
], ],
scope_types=['system', 'project']), scope_types=['system', 'project']),
policy.DocumentedRuleDefault(
name=POLICY_ROOT % 'reset_network',
check_str=base.SYSTEM_ADMIN,
description="Reset networking on a server",
operations=[
{
'method': 'POST',
'path': '/servers/{server_id}/action (resetNetwork)'
}
],
scope_types=['system', 'project'])
] ]

View File

@ -31,9 +31,9 @@ class AdminActionsSamplesJsonTest(test_servers.ServersSampleBase):
def test_post_reset_network(self): def test_post_reset_network(self):
# Get api samples to reset server network request. # Get api samples to reset server network request.
response = self._do_post('servers/%s/action' % self.uuid, self.api.api_post(
'admin-actions-reset-network', {}) 'servers/%s/action' % self.uuid, {'resetNetwork': None},
self.assertEqual(202, response.status_code) check_response_status=[410])
def test_post_inject_network_info(self): def test_post_inject_network_info(self):
# Get api samples to inject network info request. # Get api samples to inject network info request.

View File

@ -29,20 +29,18 @@ class AdminActionsTestV21(admin_only_action_common.CommonTests):
lambda *a, **k: self.controller) lambda *a, **k: self.controller)
def test_actions(self): def test_actions(self):
actions = ['_reset_network', '_inject_network_info'] actions = ['_inject_network_info']
method_translations = {'_reset_network': 'reset_network', method_translations = {'_inject_network_info': 'inject_network_info'}
'_inject_network_info': 'inject_network_info'}
self._test_actions(actions, method_translations) self._test_actions(actions, method_translations)
def test_actions_with_non_existed_instance(self): def test_actions_with_non_existed_instance(self):
actions = ['_reset_network', '_inject_network_info'] actions = ['_inject_network_info']
self._test_actions_with_non_existed_instance(actions) self._test_actions_with_non_existed_instance(actions)
def test_actions_with_locked_instance(self): def test_actions_with_locked_instance(self):
actions = ['_reset_network', '_inject_network_info'] actions = ['_inject_network_info']
method_translations = {'_reset_network': 'reset_network', method_translations = {'_inject_network_info': 'inject_network_info'}
'_inject_network_info': 'inject_network_info'}
self._test_actions_with_locked_instance(actions, self._test_actions_with_locked_instance(
method_translations=method_translations) actions, method_translations=method_translations)

View File

@ -3360,26 +3360,6 @@ class ComputeTestCase(BaseTestCase,
self.assertTrue(called['inject']) self.assertTrue(called['inject'])
self.compute.terminate_instance(self.context, instance, []) self.compute.terminate_instance(self.context, instance, [])
def test_reset_network(self):
# Ensure we can reset networking on an instance.
called = {'count': 0}
def fake_driver_reset_network(self, instance):
called['count'] += 1
self.stub_out('nova.virt.fake.FakeDriver.reset_network',
fake_driver_reset_network)
instance = self._create_fake_instance_obj()
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
block_device_mapping=[])
self.compute.reset_network(self.context, instance)
self.assertEqual(called['count'], 1)
self.compute.terminate_instance(self.context, instance, [])
def _get_snapshotting_instance(self): def _get_snapshotting_instance(self):
# Ensure instance can be snapshotted. # Ensure instance can be snapshotted.
instance = self._create_fake_instance_obj() instance = self._create_fake_instance_obj()
@ -4250,10 +4230,8 @@ class ComputeTestCase(BaseTestCase,
def dummy(*args, **kwargs): def dummy(*args, **kwargs):
pass pass
self.stub_out('nova.compute.manager.ComputeManager.' self.stub_out(
'inject_network_info', dummy) 'nova.compute.manager.ComputeManager.inject_network_info', dummy)
self.stub_out('nova.compute.manager.ComputeManager.'
'reset_network', dummy)
instance = self._create_fake_instance_obj() instance = self._create_fake_instance_obj()
@ -4270,10 +4248,8 @@ class ComputeTestCase(BaseTestCase,
def dummy(*args, **kwargs): def dummy(*args, **kwargs):
pass pass
self.stub_out('nova.compute.manager.ComputeManager.' self.stub_out(
'inject_network_info', dummy) 'nova.compute.manager.ComputeManager.inject_network_info', dummy)
self.stub_out('nova.compute.manager.ComputeManager.'
'reset_network', dummy)
instance = self._create_fake_instance_obj() instance = self._create_fake_instance_obj()
@ -11213,13 +11189,6 @@ class ComputeAPITestCase(BaseTestCase):
instance = self.compute_api.get(self.context, instance['uuid']) instance = self.compute_api.get(self.context, instance['uuid'])
self.compute_api.inject_network_info(self.context, instance) self.compute_api.inject_network_info(self.context, instance)
def test_reset_network(self):
instance = self._create_fake_instance_obj()
self.compute.build_and_run_instance(self.context,
instance, {}, {}, {}, block_device_mapping=[])
instance = self.compute_api.get(self.context, instance['uuid'])
self.compute_api.reset_network(self.context, instance)
@mock.patch('nova.compute.utils.notify_about_instance_action') @mock.patch('nova.compute.utils.notify_about_instance_action')
@mock.patch('nova.context.RequestContext.elevated') @mock.patch('nova.context.RequestContext.elevated')
@mock.patch('nova.compute.api.API._record_action_start') @mock.patch('nova.compute.api.API._record_action_start')

View File

@ -5136,27 +5136,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
do_test() do_test()
def test_reset_network_driver_not_implemented(self):
instance = fake_instance.fake_instance_obj(self.context)
@mock.patch.object(self.compute.driver, 'reset_network',
side_effect=NotImplementedError())
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
def do_test(mock_add_fault, mock_reset):
self.assertRaises(messaging.ExpectedException,
self.compute.reset_network,
self.context,
instance)
self.compute = utils.ExceptionHelper(self.compute)
self.assertRaises(NotImplementedError,
self.compute.reset_network,
self.context,
instance)
do_test()
@mock.patch.object(manager.ComputeManager, '_set_migration_status') @mock.patch.object(manager.ComputeManager, '_set_migration_status')
@mock.patch.object(manager.ComputeManager, @mock.patch.object(manager.ComputeManager,
'_do_rebuild_instance_with_claim') '_do_rebuild_instance_with_claim')

View File

@ -776,10 +776,6 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
rescue_image_ref='fake_image_ref', rescue_image_ref='fake_image_ref',
clean_shutdown=True, version='5.0') clean_shutdown=True, version='5.0')
def test_reset_network(self):
self._test_compute_api('reset_network', 'cast',
instance=self.fake_instance_obj)
def test_resize_instance(self): def test_resize_instance(self):
self._test_compute_api('resize_instance', 'cast', self._test_compute_api('resize_instance', 'cast',
instance=self.fake_instance_obj, migration={'id': 'fake_id'}, instance=self.fake_instance_obj, migration={'id': 'fake_id'},

View File

@ -51,7 +51,6 @@ policy_data = """
"os_compute_api:servers:migrations:show": "", "os_compute_api:servers:migrations:show": "",
"os_compute_api:servers:migrations:delete": "", "os_compute_api:servers:migrations:delete": "",
"os_compute_api:os-admin-actions:inject_network_info": "", "os_compute_api:os-admin-actions:inject_network_info": "",
"os_compute_api:os-admin-actions:reset_network": "",
"os_compute_api:os-admin-actions:reset_state": "", "os_compute_api:os-admin-actions:reset_state": "",
"os_compute_api:os-admin-password": "", "os_compute_api:os-admin-password": "",
"os_compute_api:os-aggregates:set_metadata": "", "os_compute_api:os-aggregates:set_metadata": "",

View File

@ -75,14 +75,6 @@ class AdminActionsPolicyTest(base.BasePolicyTest):
self.controller._inject_network_info, self.controller._inject_network_info,
self.req, self.instance.uuid, body={}) self.req, self.instance.uuid, body={})
def test_reset_network_policy(self):
rule_name = "os_compute_api:os-admin-actions:reset_network"
with mock.patch.object(self.controller.compute_api, "reset_network"):
self.common_policy_check(self.admin_authorized_contexts,
self.admin_unauthorized_contexts,
rule_name, self.controller._reset_network,
self.req, self.instance.uuid, body={})
class AdminActionsScopeTypePolicyTest(AdminActionsPolicyTest): class AdminActionsScopeTypePolicyTest(AdminActionsPolicyTest):
"""Test Admin Actions APIs policies with system scope enabled. """Test Admin Actions APIs policies with system scope enabled.

View File

@ -326,7 +326,6 @@ class RealRolePolicyTestCase(test.NoDBTestCase):
"os_compute_api:servers:show:host_status:unknown-only", "os_compute_api:servers:show:host_status:unknown-only",
"os_compute_api:servers:migrations:force_complete", "os_compute_api:servers:migrations:force_complete",
"os_compute_api:servers:migrations:delete", "os_compute_api:servers:migrations:delete",
"os_compute_api:os-admin-actions:reset_network",
"os_compute_api:os-admin-actions:inject_network_info", "os_compute_api:os-admin-actions:inject_network_info",
"os_compute_api:os-admin-actions:reset_state", "os_compute_api:os-admin-actions:reset_state",
"os_compute_api:os-aggregates:index", "os_compute_api:os-aggregates:index",

View File

@ -1347,13 +1347,6 @@ class ComputeDriver(object):
""" """
raise NotImplementedError() raise NotImplementedError()
# TODO(stephenfin): This was only implemented (properly) for XenAPI and
# should be removed.
def reset_network(self, instance):
"""reset networking for specified instance."""
# TODO(Vek): Need to pass context in for access to auth_token
pass
def set_admin_password(self, instance, new_pass): def set_admin_password(self, instance, new_pass):
"""Set the root password on the specified instance. """Set the root password on the specified instance.

View File

@ -12,6 +12,7 @@ upgrade:
* ``POST /os-agents`` * ``POST /os-agents``
* ``PUT /os-agents/{agent_id}`` * ``PUT /os-agents/{agent_id}``
* ``DELETE /os-agents/{agent_id}`` * ``DELETE /os-agents/{agent_id}``
* ``POST /servers/{server_id}/action (resetNetwork)``
The ``XenAPI`` specific policies have been removed: The ``XenAPI`` specific policies have been removed:
@ -20,6 +21,7 @@ upgrade:
* ``os_compute_api:os-agents:create`` * ``os_compute_api:os-agents:create``
* ``os_compute_api:os-agents:update`` * ``os_compute_api:os-agents:update``
* ``os_compute_api:os-agents:delete`` * ``os_compute_api:os-agents:delete``
* ``os_compute_api:os-admin-actions:reset_network``
The ``XenAPI`` specific configuration options have been removed. The ``XenAPI`` specific configuration options have been removed.