Skip to content

Commit

Permalink
virt: Remove 'reset_network' API
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stephenfin committed Nov 23, 2020
1 parent 30067be commit 68bc878
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 136 deletions.
13 changes: 8 additions & 5 deletions api-ref/source/servers-admin-action.inc
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,19 @@ Response
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

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.

Expand All @@ -190,7 +193,7 @@ through the ``policy.json`` file.
Normal response codes: 202

Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
conflict(409)
conflict(409), gone(410)

Request
-------
Expand Down
14 changes: 3 additions & 11 deletions nova/api/openstack/compute/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,11 @@ def __init__(self):
super(AdminActionsController, self).__init__()
self.compute_api = compute.API()

@wsgi.response(202)
@wsgi.expected_errors((404, 409))
@wsgi.expected_errors(410)
@wsgi.action('resetNetwork')
def _reset_network(self, req, id, body):
"""Permit admins to reset networking on a server."""
context = req.environ['nova.context']
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())
"""(Removed) Permit admins to reset networking on a server."""
raise exc.HTTPGone()

@wsgi.response(202)
@wsgi.expected_errors((404, 409))
Expand Down
5 changes: 0 additions & 5 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4530,11 +4530,6 @@ def unlock(self, context, instance):
action=fields_obj.NotificationAction.UNLOCK,
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
def inject_network_info(self, context, instance):
"""Inject network info for the instance."""
Expand Down
6 changes: 1 addition & 5 deletions nova/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6075,7 +6075,6 @@ def add_fixed_ip_to_instance(self, context, network_id, instance):
instance,
network_id)
self._inject_network_info(instance, network_info)
self.reset_network(context, instance)

# NOTE(russellb) We just want to bump updated_at. See bug 1143466.
instance.updated_at = timeutils.utcnow()
Expand All @@ -6098,7 +6097,6 @@ def remove_fixed_ip_from_instance(self, context, address, instance):
instance,
address)
self._inject_network_info(instance, network_info)
self.reset_network(context, instance)

# NOTE(russellb) We just want to bump updated_at. See bug 1143466.
instance.updated_at = timeutils.utcnow()
Expand Down Expand Up @@ -6629,11 +6627,9 @@ def _unshelve_instance(self, context, instance, image, filter_properties,

# TODO(stephenfin): Remove this in RPC 6.0 since it's nova-network only
@messaging.expected_exceptions(NotImplementedError)
@wrap_instance_fault
def reset_network(self, context, instance):
"""Reset networking on the given instance."""
LOG.debug('Reset network', instance=instance)
self.driver.reset_network(instance)
raise NotImplementedError()

def _inject_network_info(self, instance, network_info):
"""Inject network info for the given instance."""
Expand Down
7 changes: 0 additions & 7 deletions nova/compute/rpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,6 @@ def rescue_instance(self, ctxt, instance, rescue_password,
server=_compute_host(None, instance), version=version)
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,
request_spec, clean_shutdown=True):
msg_args = {'instance': instance, 'migration': migration,
Expand Down
11 changes: 0 additions & 11 deletions nova/policies/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@
}
],
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'])
]


Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions nova/tests/functional/api_sample_tests/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def setUp(self):

def test_post_reset_network(self):
# Get api samples to reset server network request.
response = self._do_post('servers/%s/action' % self.uuid,
'admin-actions-reset-network', {})
self.assertEqual(202, response.status_code)
self.api.api_post(
'servers/%s/action' % self.uuid, {'resetNetwork': None},
check_response_status=[410])

def test_post_inject_network_info(self):
# Get api samples to inject network info request.
Expand Down
16 changes: 7 additions & 9 deletions nova/tests/unit/api/openstack/compute/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ def setUp(self):
lambda *a, **k: self.controller)

def test_actions(self):
actions = ['_reset_network', '_inject_network_info']
method_translations = {'_reset_network': 'reset_network',
'_inject_network_info': 'inject_network_info'}
actions = ['_inject_network_info']
method_translations = {'_inject_network_info': 'inject_network_info'}

self._test_actions(actions, method_translations)

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)

def test_actions_with_locked_instance(self):
actions = ['_reset_network', '_inject_network_info']
method_translations = {'_reset_network': 'reset_network',
'_inject_network_info': 'inject_network_info'}
actions = ['_inject_network_info']
method_translations = {'_inject_network_info': 'inject_network_info'}

self._test_actions_with_locked_instance(actions,
method_translations=method_translations)
self._test_actions_with_locked_instance(
actions, method_translations=method_translations)
39 changes: 4 additions & 35 deletions nova/tests/unit/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3360,26 +3360,6 @@ def fake_driver_inject_network(self, instance, network_info):
self.assertTrue(called['inject'])
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):
# Ensure instance can be snapshotted.
instance = self._create_fake_instance_obj()
Expand Down Expand Up @@ -4250,10 +4230,8 @@ def test_add_fixed_ip_usage_notification(self):
def dummy(*args, **kwargs):
pass

self.stub_out('nova.compute.manager.ComputeManager.'
'inject_network_info', dummy)
self.stub_out('nova.compute.manager.ComputeManager.'
'reset_network', dummy)
self.stub_out(
'nova.compute.manager.ComputeManager.inject_network_info', dummy)

instance = self._create_fake_instance_obj()

Expand All @@ -4270,10 +4248,8 @@ def test_remove_fixed_ip_usage_notification(self):
def dummy(*args, **kwargs):
pass

self.stub_out('nova.compute.manager.ComputeManager.'
'inject_network_info', dummy)
self.stub_out('nova.compute.manager.ComputeManager.'
'reset_network', dummy)
self.stub_out(
'nova.compute.manager.ComputeManager.inject_network_info', dummy)

instance = self._create_fake_instance_obj()

Expand Down Expand Up @@ -11213,13 +11189,6 @@ def test_inject_network_info(self):
instance = self.compute_api.get(self.context, instance['uuid'])
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.context.RequestContext.elevated')
@mock.patch('nova.compute.api.API._record_action_start')
Expand Down
21 changes: 0 additions & 21 deletions nova/tests/unit/compute/test_compute_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5136,27 +5136,6 @@ def do_test(save_mock, power_off_mock, notify_mock,

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,
'_do_rebuild_instance_with_claim')
Expand Down
4 changes: 0 additions & 4 deletions nova/tests/unit/compute/test_rpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,6 @@ def test_rescue_instance(self):
rescue_image_ref='fake_image_ref',
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):
self._test_compute_api('resize_instance', 'cast',
instance=self.fake_instance_obj, migration={'id': 'fake_id'},
Expand Down
1 change: 0 additions & 1 deletion nova/tests/unit/fake_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"os_compute_api:servers:migrations:show": "",
"os_compute_api:servers:migrations:delete": "",
"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-password": "",
"os_compute_api:os-aggregates:set_metadata": "",
Expand Down
8 changes: 0 additions & 8 deletions nova/tests/unit/policies/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ def test_inject_network_info_policy(self):
self.controller._inject_network_info,
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):
"""Test Admin Actions APIs policies with system scope enabled.
Expand Down
1 change: 0 additions & 1 deletion nova/tests/unit/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ def setUp(self):
"os_compute_api:servers:show:host_status:unknown-only",
"os_compute_api:servers:migrations:force_complete",
"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:reset_state",
"os_compute_api:os-aggregates:index",
Expand Down
7 changes: 0 additions & 7 deletions nova/virt/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,13 +1347,6 @@ def get_instance_disk_info(self, instance,
"""
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):
"""Set the root password on the specified instance.

Expand Down
2 changes: 2 additions & 0 deletions releasenotes/notes/remove-xenapi-driver-194756049f22dc9e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ upgrade:
* ``POST /os-agents``
* ``PUT /os-agents/{agent_id}``
* ``DELETE /os-agents/{agent_id}``
* ``POST /servers/{server_id}/action (resetNetwork)``

The ``XenAPI`` specific policies have been removed:

Expand All @@ -20,6 +21,7 @@ upgrade:
* ``os_compute_api:os-agents:create``
* ``os_compute_api:os-agents:update``
* ``os_compute_api:os-agents:delete``
* ``os_compute_api:os-admin-actions:reset_network``

The ``XenAPI`` specific configuration options have been removed.

Expand Down

0 comments on commit 68bc878

Please sign in to comment.