Remove legacy v2 unit tests[a-e]

There are two implementation code for similar API in Nova repository.
One is newer: v2.1 API, another is legacy: v2 API. v2.1 API has been
 used as the default API since Liberty and legacy v2 API has been marked
as deprecated. We have used and tested v2.1 API so well and now is nice
time to remove legacy API code based on the consensus of the design
summit of Austin.

This patch removes unit tests of legacy v2 API[a-e].

NOTE: Two test modules test_extended_rescue_with_image and
      test_extended_virtual_interfaces_net are just removed
      because the corresponding modules exist on legacy v2
      code only. These modules are merged into source modules
      on v2.1 code.

Partially implements blueprint remove-legacy-v2-api-code

Change-Id: Icd57f5b1718faef3ab7afe4acd34e56d4d29a3a8
This commit is contained in:
Ken'ichi Ohmichi 2016-05-01 20:45:29 -07:00
parent 4b6ab39393
commit b5ec25d6ab
25 changed files with 1 additions and 796 deletions

View File

@ -12,13 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import webob
from nova.api.openstack.compute import access_ips
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2 import servers as servers_v20
from nova.api.openstack.compute import servers as servers_v21
from nova.api.openstack import extensions as extensions_v20
from nova.api.openstack import wsgi
from nova import exception
from nova import test
@ -278,39 +274,6 @@ class AccessIPsExtAPIValidationTestV21(test.TestCase):
params)
class AccessIPsExtAPIValidationTestV2(AccessIPsExtAPIValidationTestV21):
validation_error = webob.exc.HTTPBadRequest
def _set_up_controller(self):
self.ext_mgr = extensions_v20.ExtensionManager()
self.ext_mgr.extensions = {}
self.controller = servers_v20.Controller(self.ext_mgr)
def _verify_update_access_ip(self, res_dict, params):
for key, value in params.items():
value = value or ''
self.assertEqual(res_dict['server'][key], value)
# Note(gmann): Below tests are only valid for V2 as
# V2.1 has strong input validation and does not allow
# None or blank access ips.
def test_update_server_access_ipv4_none(self):
params = {access_ips.AccessIPs.v4_key: None}
self._test_update(params)
def test_update_server_access_ipv4_blank(self):
params = {access_ips.AccessIPs.v4_key: ''}
self._test_update(params)
def test_update_server_access_ipv6_none(self):
params = {access_ips.AccessIPs.v6_key: None}
self._test_update(params)
def test_update_server_access_ipv6_blank(self):
params = {access_ips.AccessIPs.v6_key: ''}
self._test_update(params)
class AccessIPsControllerTestV21(test.NoDBTestCase):
def setUp(self):
super(AccessIPsControllerTestV21, self).setUp()

View File

@ -13,8 +13,6 @@
# under the License.
from nova.api.openstack.compute import admin_actions as admin_actions_v21
from nova.api.openstack.compute.legacy_v2.contrib import admin_actions \
as admin_actions_v2
from nova import exception
from nova import test
from nova.tests.unit.api.openstack.compute import admin_only_action_common
@ -58,11 +56,6 @@ class AdminActionsTestV21(admin_only_action_common.CommonTests):
method_translations=method_translations)
class AdminActionsTestV2(AdminActionsTestV21):
admin_actions = admin_actions_v2
_api_version = '2'
class AdminActionsPolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -17,7 +17,6 @@ import mock
import webob
from nova.api.openstack.compute import admin_password as admin_password_v21
from nova.api.openstack.compute.legacy_v2 import servers
from nova import exception
from nova import test
from nova.tests.unit.api.openstack import fakes
@ -131,20 +130,6 @@ class AdminPasswordTestV21(test.NoDBTestCase):
self.fake_req, 'fake', body=body)
class AdminPasswordTestV2(AdminPasswordTestV21):
validiation_error = webob.exc.HTTPBadRequest
def _get_action(self):
class FakeExtManager(object):
def is_loaded(self, ext):
return False
return servers.Controller(ext_mgr=FakeExtManager()).\
_action_change_password
def _check_status(self, expected_status, res, controller_method):
self.assertEqual(expected_status, res.status_int)
class AdminPasswordPolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -16,7 +16,6 @@ import mock
import webob.exc
from nova.api.openstack.compute import agents as agents_v21
from nova.api.openstack.compute.legacy_v2.contrib import agents as agents_v2
from nova import db
from nova.db.sqlalchemy import models
from nova import exception
@ -333,34 +332,6 @@ class AgentsTestV21(test.NoDBTestCase):
self.controller.update, self.req, 1, body=body)
class AgentsTestV2(AgentsTestV21):
controller = agents_v2.AgentController()
validation_error = webob.exc.HTTPBadRequest
def setUp(self):
super(AgentsTestV2, self).setUp()
self.non_admin_req = fakes.HTTPRequest.blank('')
def _get_http_request(self):
return fakes.HTTPRequest.blank('', use_admin_context=True)
def test_agents_update_with_non_admin(self):
self.assertRaises(exception.AdminRequired, self.controller.update,
self.non_admin_req, fakes.FAKE_UUID, body={})
def test_agents_create_with_non_admin(self):
self.assertRaises(exception.AdminRequired, self.controller.create,
self.non_admin_req, body={})
def test_agents_delete_with_non_admin(self):
self.assertRaises(exception.AdminRequired, self.controller.delete,
self.non_admin_req, fakes.FAKE_UUID)
def test_agents_index_with_non_admin(self):
self.assertRaises(exception.AdminRequired, self.controller.index,
self.non_admin_req)
class AgentsPolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -20,8 +20,6 @@ import uuid
from webob import exc
from nova.api.openstack.compute import aggregates as aggregates_v21
from nova.api.openstack.compute.legacy_v2.contrib import aggregates \
as aggregates_v2
from nova.compute import api as compute_api
from nova import context
from nova import exception
@ -745,78 +743,3 @@ class AggregateTestCaseV21(test.NoDBTestCase):
def _assert_agg_data(self, expected, actual):
self.assertTrue(obj_base.obj_equal_prims(expected, actual),
"The aggregate objects were not equal")
class AggregateTestCaseV2(AggregateTestCaseV21):
add_host = 'self.controller.action'
remove_host = 'self.controller.action'
set_metadata = 'self.controller.action'
bad_request = exc.HTTPBadRequest
def _set_up(self):
self.controller = aggregates_v2.AggregateController()
self.req = FakeRequest()
self.user_req = fakes.HTTPRequest.blank('/v2/os-aggregates')
self.context = self.req.environ['nova.context']
def test_add_host_raises_key_error(self):
def stub_add_host_to_aggregate(context, aggregate, host):
raise KeyError
self.stubs.Set(self.controller.api, "add_host_to_aggregate",
stub_add_host_to_aggregate)
# NOTE(mtreinish) The check for a KeyError here is to ensure that
# if add_host_to_aggregate() raises a KeyError it propagates. At
# one point the api code would mask the error as a HTTPBadRequest.
# This test is to ensure that this doesn't occur again.
self.assertRaises(KeyError, eval(self.add_host), self.req, "1",
body={"add_host": {"host": "host1"}})
def test_add_host_to_aggregate_with_non_admin(self):
rule_name = "compute_extension:aggregates"
self.policy.set_rules({rule_name: ""})
self.assertRaises(exception.AdminRequired, self.controller._add_host,
self.user_req, '1', {'host': 'fake_host'})
def test_remove_host_from_aggregate_with_non_admin(self):
rule_name = "compute_extension:aggregates"
self.policy.set_rules({rule_name: ""})
self.assertRaises(exception.AdminRequired,
self.controller._remove_host, self.user_req,
'1', {'host': 'fake_host'})
def test_create_name_with_leading_trailing_spaces(self):
def fake_mock_aggs(context, name, az):
# NOTE(alex_xu): legacy v2 api didn't strip the spaces.
self.assertEqual(' test ', name)
return AGGREGATE
with mock.patch.object(compute_api.AggregateAPI,
'create_aggregate') as mock_aggs:
mock_aggs.side_effect = fake_mock_aggs
self.controller.create(self.req,
body={"aggregate":
{"name": " test ",
"availability_zone": "nova1"}})
def test_create_name_with_leading_trailing_spaces_compat_mode(self):
pass
def test_create_availability_zone_with_leading_trailing_spaces(self):
def fake_mock_aggs(context, name, az):
# NOTE(alex_xu): legacy v2 api didn't strip the spaces.
self.assertEqual(' nova1 ', az)
return AGGREGATE
with mock.patch.object(compute_api.AggregateAPI,
'create_aggregate') as mock_aggs:
mock_aggs.side_effect = fake_mock_aggs
self.controller.create(self.req,
body={"aggregate":
{"name": " test ",
"availability_zone": " nova1 "}})
def test_create_availabiltiy_zone_with_leading_trailing_spaces_compat_mode(
self):
pass

View File

@ -17,8 +17,6 @@ import mock
from nova.api.openstack.compute import attach_interfaces \
as attach_interfaces_v21
from nova.api.openstack.compute.legacy_v2.contrib import attach_interfaces \
as attach_interfaces_v2
from nova.compute import api as compute_api
from nova import exception
from nova.network import api as network_api
@ -454,21 +452,6 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
self._test_attach_interface_with_invalid_parameter(param)
class InterfaceAttachTestsV2(InterfaceAttachTestsV21):
controller_cls = attach_interfaces_v2.InterfaceAttachmentController
validate_exc = exc.HTTPBadRequest
in_use_exc = exc.HTTPBadRequest
def test_attach_interface_instance_with_non_uuid_net_id(self):
pass
def test_attach_interface_instance_with_non_uuid_port_id(self):
pass
def test_attach_interface_instance_with_non_array_fixed_ips(self):
pass
class AttachInterfacesPolicyEnforcementv21(test.NoDBTestCase):
def setUp(self):

View File

@ -17,11 +17,7 @@ import iso8601
from nova.api.openstack.compute import availability_zone as az_v21
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2.contrib import availability_zone \
as az_v2
from nova.api.openstack.compute.legacy_v2 import servers as servers_v2
from nova.api.openstack.compute import servers as servers_v21
from nova.api.openstack import extensions
from nova import availability_zones
from nova.compute import api as compute_api
from nova.compute import flavors
@ -178,19 +174,6 @@ class AvailabilityZoneApiTestV21(test.NoDBTestCase):
matchers.DictMatches(expected_response))
class AvailabilityZoneApiTestV2(AvailabilityZoneApiTestV21):
availability_zone = az_v2
def setUp(self):
super(AvailabilityZoneApiTestV2, self).setUp()
self.req = fakes.HTTPRequest.blank('', use_admin_context=True)
self.non_admin_req = fakes.HTTPRequest.blank('')
def test_availability_zone_detail_with_non_admin(self):
self.assertRaises(exception.AdminRequired,
self.controller.detail, self.non_admin_req)
class ServersControllerCreateTestV21(test.TestCase):
base_url = '/v2/fake/'
@ -339,29 +322,3 @@ class ServersControllerCreateTestV21(test.TestCase):
res = self.controller.create(self.req, body=body).obj
server = res['server']
self.assertEqual(fakes.FAKE_UUID, server['id'])
class ServersControllerCreateTestV2(ServersControllerCreateTestV21):
def _set_up_controller(self):
ext_mgr = extensions.ExtensionManager()
ext_mgr.extensions = {'os-availability-zone': 'fake'}
self.controller = servers_v2.Controller(ext_mgr)
ext_mgr_no_az = extensions.ExtensionManager()
ext_mgr_no_az.extensions = {}
self.no_availability_zone_controller = servers_v2.Controller(
ext_mgr_no_az)
def test_create_instance_with_invalid_availability_zone_too_long(self):
# NOTE: v2.0 API does not check this bad request case.
# So we skip this test for v2.0 API.
pass
def test_create_instance_with_invalid_availability_zone_too_short(self):
# NOTE: v2.0 API does not check this bad request case.
# So we skip this test for v2.0 API.
pass
def test_create_instance_with_invalid_availability_zone_not_str(self):
# NOTE: v2.0 API does not check this bad request case.
# So we skip this test for v2.0 API.
pass

View File

@ -21,9 +21,6 @@ from webob import exc
from nova.api.openstack.compute import baremetal_nodes \
as b_nodes_v21
from nova.api.openstack.compute.legacy_v2.contrib import baremetal_nodes \
as b_nodes_v2
from nova.api.openstack import extensions
from nova import context
from nova import test
from nova.tests.unit.virt.ironic import utils as ironic_utils
@ -216,14 +213,3 @@ class BareMetalNodesTestV21(test.NoDBTestCase):
self.assertRaises(exc.HTTPBadRequest,
self.controller._remove_interface,
self.request, 'fake-id', 'fake-body')
@mock.patch.object(b_nodes_v2, '_get_ironic_client',
lambda *_: FAKE_IRONIC_CLIENT)
class BareMetalNodesTestV2(BareMetalNodesTestV21):
mod = b_nodes_v2
def _setup(self):
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {}
self.controller = b_nodes_v2.BareMetalNodeController(self.ext_mgr)

View File

@ -22,8 +22,6 @@ from webob import exc
from nova.api.openstack.compute import block_device_mapping
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2 import extensions
from nova.api.openstack.compute.legacy_v2 import servers as servers_v2
from nova.api.openstack.compute import servers as servers_v21
from nova import block_device
from nova.compute import api as compute_api
@ -346,42 +344,3 @@ class BlockDeviceMappingTestV21(test.TestCase):
self.assertFalse(self.validation_fail_instance_destroy_called)
self.validation_fail_test_validate_called = False
self.validation_fail_instance_destroy_called = False
class BlockDeviceMappingTestV2(BlockDeviceMappingTestV21):
validation_error = exc.HTTPBadRequest
def _setup_controller(self):
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {'os-volumes': 'fake',
'os-block-device-mapping-v2-boot': 'fake'}
self.controller = servers_v2.Controller(self.ext_mgr)
self.ext_mgr_bdm_v2 = extensions.ExtensionManager()
self.ext_mgr_bdm_v2.extensions = {'os-volumes': 'fake'}
self.no_bdm_v2_controller = servers_v2.Controller(
self.ext_mgr_bdm_v2)
def test_create_instance_with_block_device_mapping_disabled(self):
bdm = [{'device_name': 'foo'}]
old_create = compute_api.API.create
def create(*args, **kwargs):
self.assertIsNone(kwargs['block_device_mapping'], None)
return old_create(*args, **kwargs)
self.stubs.Set(compute_api.API, 'create', create)
params = {block_device_mapping.ATTRIBUTE_NAME: bdm}
self._test_create(params,
override_controller=self.no_bdm_v2_controller)
def test_create_instance_with_destination_type_empty_string(self):
# Add a check whether the destination type is an empty string
# in V2.1 API only. So this test is skipped in V2.0 API
pass
def test_create_instance_with_invalid_destination_type(self):
# Add a check whether the destination type is invalid
# in V2.1 API only. So this test is skipped in V2.0 API
pass

View File

@ -22,8 +22,6 @@ from webob import exc
from nova.api.openstack.compute import block_device_mapping_v1 \
as block_device_mapping
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2 import extensions
from nova.api.openstack.compute.legacy_v2 import servers as servers_v2
from nova.api.openstack.compute import servers as servers_v21
from nova.compute import api as compute_api
from nova import db
@ -352,74 +350,3 @@ class BlockDeviceMappingTestV21(test.TestCase):
'block_device_mapping_v2': bdm_v2}
self.assertRaises(exc.HTTPBadRequest, self._test_create, params,
override_controller=both_controllers)
class BlockDeviceMappingTestV2(BlockDeviceMappingTestV21):
validation_error = exc.HTTPBadRequest
def _setup_controller(self):
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {'os-volumes': 'fake'}
self.controller = servers_v2.Controller(self.ext_mgr)
self.ext_mgr_no_vols = extensions.ExtensionManager()
self.ext_mgr_no_vols.extensions = {}
self.no_volumes_controller = servers_v2.Controller(
self.ext_mgr_no_vols)
def test_create_instance_with_volumes_disabled(self):
bdm = [{'device_name': 'foo'}]
params = {'block_device_mapping': bdm}
old_create = compute_api.API.create
def create(*args, **kwargs):
self.assertIsNone(kwargs['block_device_mapping'])
return old_create(*args, **kwargs)
self.stubs.Set(compute_api.API, 'create', create)
self._test_create(params,
override_controller=self.no_volumes_controller)
def test_create_instance_decide_format_legacy(self):
ext_mgr = extensions.ExtensionManager()
ext_mgr.extensions = {'os-volumes': 'fake',
'os-block-device-mapping-v2-boot': 'fake'}
controller = servers_v2.Controller(self.ext_mgr)
bdm = [{'device_name': 'foo1',
'volume_id': fakes.FAKE_UUID,
'delete_on_termination': 1}]
expected_legacy_flag = True
old_create = compute_api.API.create
def create(*args, **kwargs):
legacy_bdm = kwargs.get('legacy_bdm', True)
self.assertEqual(legacy_bdm, expected_legacy_flag)
return old_create(*args, **kwargs)
def _validate_bdm(*args, **kwargs):
pass
self.stubs.Set(compute_api.API, 'create', create)
self.stubs.Set(compute_api.API, '_validate_bdm',
_validate_bdm)
self._test_create({}, override_controller=controller)
params = {'block_device_mapping': bdm}
self._test_create(params, override_controller=controller)
def test_create_instance_with_size_empty_string(self):
# Add a check whether the size is an empty string
# in V2.1 API only. So this test is skipped in V2.0 API
pass
def test_create_instance_with_size_zero(self):
# Add a check whether the size is zero in V2.1 API only.
# So this test is skipped in V2.0 API
pass
def test_create_instance_with_size_greater_than_limit(self):
# Add a check whether size is greater than the limit
# in V2.1 API only. So this test is skipped in V2.0 API
pass

View File

@ -19,7 +19,6 @@ from oslo_utils import timeutils
from webob import exc
from nova.api.openstack.compute import cells as cells_ext_v21
from nova.api.openstack.compute.legacy_v2.contrib import cells as cells_ext_v2
from nova.api.openstack import extensions
from nova.cells import rpcapi as cells_rpcapi
from nova import context
@ -723,54 +722,3 @@ class CellsTestV21(BaseCellsTest):
req = self._get_request("cells/sync_instances")
self.assertRaises(exc.HTTPNotImplemented,
self.controller.sync_instances, req, {})
class CellsTestV2(CellsTestV21):
cell_extension = 'compute_extension:cells'
bad_request = exc.HTTPBadRequest
def _get_cell_controller(self, ext_mgr):
return cells_ext_v2.Controller(ext_mgr)
def test_cell_create_name_with_invalid_character_raises(self):
pass
def test_cell_create_rpc_port_with_null(self):
body = {'cell': {'name': 'fake',
'username': 'fred',
'password': 'secret',
'rpc_host': 'r3.example.org',
'rpc_port': None,
'type': 'parent'}}
req = self._get_request("cells")
req.environ['nova.context'] = self.context
self.controller.create(req, body=body)
def test_cell_update_rpc_port_with_null(self):
body = {'cell': {'name': 'fake',
'username': 'fred',
'password': 'secret',
'rpc_host': 'r3.example.org',
'rpc_port': None,
'type': 'parent'}}
req = self._get_request("cells")
req.environ['nova.context'] = self.context
self.controller.update(req, 'cell1', body=body)
def test_cell_create_name_with_leading_trailing_spaces_compat_mode(self):
pass
def test_cell_create_name_with_leading_trailing_spaces(self):
body = {'cell': {'name': ' moocow ',
'username': 'fred',
'password': 'secret',
'rpc_host': 'r3.example.org',
'type': 'parent'}}
req = self._get_request("cells")
req.environ['nova.context'] = self.context
resp = self.controller.create(req, body=body)
# NOTE(alex_xu): legacy v2 didn't strip the spaces.
self.assertEqual(' moocow ', resp['cell']['name'])

View File

@ -22,8 +22,6 @@ from oslo_policy import policy as oslo_policy
from nova.api.openstack.compute import certificates \
as certificates_v21
from nova.api.openstack.compute.legacy_v2.contrib import certificates \
as certificates_v2
from nova.cert import rpcapi
from nova import context
from nova import exception
@ -110,9 +108,3 @@ class CertificatesTestV21(test.NoDBTestCase):
exc.HTTPNotFound,
self.controller.show,
self.req, 'root')
class CertificatesTestV2(CertificatesTestV21):
certificates = certificates_v2
certificate_show_extension = 'compute_extension:certificates'
certificate_create_extension = 'compute_extension:certificates'

View File

@ -20,8 +20,6 @@ from oslo_utils import timeutils
from webob import exc
from nova.api.openstack.compute import cloudpipe as cloudpipe_v21
from nova.api.openstack.compute.legacy_v2.contrib import cloudpipe \
as cloudpipe_v2
from nova.compute import utils as compute_utils
from nova import exception
from nova import objects
@ -155,13 +153,6 @@ class CloudpipeTestV21(test.NoDBTestCase):
self.controller.create, req, body=body)
class CloudpipeTestV2(CloudpipeTestV21):
cloudpipe = cloudpipe_v2
def test_cloudpipe_create_with_bad_project_id_failed(self):
pass
class CloudpipePolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -15,8 +15,6 @@
import webob
from nova.api.openstack.compute import cloudpipe as clup_v21
from nova.api.openstack.compute.legacy_v2.contrib import cloudpipe_update \
as clup_v2
from nova import exception
from nova import test
from nova.tests.unit.api.openstack import fakes
@ -88,13 +86,3 @@ class CloudpipeUpdateTestV21(test.NoDBTestCase):
self.assertRaises(self.bad_request,
self.controller.update, self.req,
'configure-project', body=body)
class CloudpipeUpdateTestV2(CloudpipeUpdateTestV21):
bad_request = webob.exc.HTTPBadRequest
def _setup(self):
self.controller = clup_v2.CloudpipeUpdateController()
def _check_status(self, expected_status, res, controller_methord):
self.assertEqual(expected_status, res.status_int)

View File

@ -21,9 +21,7 @@ from oslo_serialization import jsonutils
import webob
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2 import servers as servers_v2
from nova.api.openstack.compute import servers as servers_v21
from nova.api.openstack import extensions
from nova.compute import api as compute_api
from nova.compute import flavors
from nova import exception
@ -78,15 +76,6 @@ class ConfigDriveTestV21(test.TestCase):
self.assertIn('config_drive', server_dict)
class ConfigDriveTestV2(ConfigDriveTestV21):
def _setup_wsgi(self):
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
osapi_compute_ext_list=['Config_drive'])
self.app = fakes.wsgi_app(init_only=('servers',))
class ServersControllerCreateTestV21(test.TestCase):
base_url = '/v2/fake/'
bad_request = exception.ValidationError
@ -230,26 +219,3 @@ class ServersControllerCreateTestV21(test.TestCase):
req, body = self._create_instance_body_of_config_drive(param)
self.assertRaises(exception.ValidationError,
self.controller.create, req, body=body)
class ServersControllerCreateTestV2(ServersControllerCreateTestV21):
bad_request = webob.exc.HTTPBadRequest
def _set_up_controller(self):
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {}
self.controller = servers_v2.Controller(self.ext_mgr)
self.no_config_drive_controller = None
def _verfiy_config_drive(self, **kwargs):
self.assertIsNone(kwargs['config_drive'])
def _initialize_extension(self):
self.ext_mgr.extensions = {'os-config-drive': 'fake'}
def test_create_instance_with_empty_config_drive(self):
param = ''
req, body = self._create_instance_body_of_config_drive(param)
res = self.controller.create(req, body=body).obj
server = res['server']
self.assertEqual(fakes.FAKE_UUID, server['id'])

View File

@ -19,8 +19,6 @@ import webob
from nova.api.openstack.compute import console_auth_tokens \
as console_auth_tokens_v21
from nova.api.openstack.compute.legacy_v2.contrib import console_auth_tokens \
as console_auth_tokens_v2
from nova.consoleauth import rpcapi as consoleauth_rpcapi
from nova import test
from nova.tests.unit.api.openstack import fakes
@ -78,7 +76,3 @@ class ConsoleAuthTokensExtensionTestV21(test.NoDBTestCase):
_fake_check_token_unauthorized)
self.assertRaises(webob.exc.HTTPUnauthorized,
self.controller.show, self.req, fakes.FAKE_UUID)
class ConsoleAuthTokensExtensionTestV2(ConsoleAuthTokensExtensionTestV21):
controller_class = console_auth_tokens_v2

View File

@ -20,8 +20,6 @@ import webob
from nova.api.openstack.compute import console_output \
as console_output_v21
from nova.api.openstack.compute.legacy_v2.contrib import console_output \
as console_output_v2
from nova.compute import api as compute_api
from nova import exception
from nova import test
@ -153,11 +151,6 @@ class ConsoleOutputExtensionTestV21(test.NoDBTestCase):
self._check_console_output_failure(webob.exc.HTTPNotFound, body)
class ConsoleOutputExtensionTestV2(ConsoleOutputExtensionTestV21):
controller_class = console_output_v2
validation_error = webob.exc.HTTPBadRequest
class ConsoleOutpuPolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -22,7 +22,6 @@ from oslo_utils import timeutils
import webob
from nova.api.openstack.compute import consoles as consoles_v21
from nova.api.openstack.compute.legacy_v2 import consoles as consoles_v2
from nova.compute import vm_states
from nova import console
from nova import exception
@ -293,12 +292,3 @@ class ConsolesControllerTestV21(test.NoDBTestCase):
def test_show_console_fail_policy(self):
self._test_fail_policy("os_compute_api:os-consoles:show",
self.controller.show, data='20')
class ConsolesControllerTestV2(ConsolesControllerTestV21):
def _set_up_controller(self):
self.controller = consoles_v2.Controller()
def _test_fail_policy(self, rule, action, data=None):
# V2 API don't have policy
pass

View File

@ -18,8 +18,6 @@ import webob
from nova.api.openstack import common
from nova.api.openstack.compute import create_backup \
as create_backup_v21
from nova.api.openstack.compute.legacy_v2.contrib import admin_actions \
as create_backup_v2
from nova import exception
from nova import test
from nova.tests.unit.api.openstack.compute import admin_only_action_common
@ -328,52 +326,6 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin,
self.req, instance['uuid'], body=body)
class CreateBackupTestsV2(CreateBackupTestsV21):
create_backup = create_backup_v2
controller_name = 'AdminActionsController'
validation_error = webob.exc.HTTPBadRequest
def test_create_backup_with_invalid_create_backup(self):
# NOTE(gmann):V2 API does not raise bad request for below type of
# invalid body in controller method.
body = {
'createBackupup': {
'name': 'Backup 1',
'backup_type': 'daily',
'rotation': 1,
},
}
self.assertRaises(KeyError,
self.controller._create_backup,
self.req, fakes.FAKE_UUID, body=body)
def test_create_backup_non_dict_metadata(self):
pass
def test_create_backup_name_with_leading_trailing_spaces(self):
body = {
'createBackup': {
'name': ' test ',
'backup_type': 'daily',
'rotation': 1,
},
}
image = dict(id='fake-image-id', status='ACTIVE', name='Backup 1',
properties={})
common.check_img_metadata_properties_quota(self.context, {})
instance = self._stub_instance_get()
self.compute_api.backup(self.context, instance, ' test ',
'daily', 1,
extra_properties={}).AndReturn(image)
self.mox.ReplayAll()
self.controller._create_backup(self.req, instance.uuid,
body=body)
def test_create_backup_name_with_leading_trailing_spaces_compat_mode(
self):
pass
class CreateBackupPolicyEnforcementv21(test.NoDBTestCase):
def setUp(self):

View File

@ -17,7 +17,6 @@ import mock
import webob
from nova.api.openstack.compute import deferred_delete as dd_v21
from nova.api.openstack.compute.legacy_v2.contrib import deferred_delete
from nova.compute import api as compute_api
from nova import context
from nova import exception
@ -143,10 +142,6 @@ class DeferredDeleteExtensionTestV21(test.NoDBTestCase):
self.fake_req, self.fake_uuid, self.fake_input_dict)
class DeferredDeleteExtensionTestV2(DeferredDeleteExtensionTestV21):
ext_ver = deferred_delete.DeferredDeleteController
class DeferredDeletePolicyEnforcementV21(test.NoDBTestCase):
def setUp(self):

View File

@ -19,9 +19,6 @@ import testtools
import webob
from nova.api.openstack.compute import evacuate as evacuate_v21
from nova.api.openstack.compute.legacy_v2.contrib import evacuate \
as evacuate_v2
from nova.api.openstack import extensions
from nova.compute import api as compute_api
from nova.compute import vm_states
import nova.conf
@ -235,43 +232,6 @@ class EvacuateTestV21(test.NoDBTestCase):
self.assertIsNone(res.get('adminPass'))
class EvacuateTestV2(EvacuateTestV21):
validation_error = webob.exc.HTTPBadRequest
def _set_up_controller(self):
ext_mgr = extensions.ExtensionManager()
ext_mgr.extensions = {'os-extended-evacuate-find-host': 'fake'}
self.controller = evacuate_v2.Controller(ext_mgr)
ext_mgr_no_ext = extensions.ExtensionManager()
ext_mgr_no_ext.extensions = {}
self.controller_no_ext = evacuate_v2.Controller(ext_mgr_no_ext)
def test_no_target_fails_if_extension_not_loaded(self):
self._check_evacuate_failure(webob.exc.HTTPBadRequest,
{'onSharedStorage': 'False',
'adminPass': 'MyNewPass'},
controller=self.controller_no_ext)
def test_evacuate_instance_with_too_long_host(self):
pass
def test_evacuate_instance_with_invalid_characters_host(self):
pass
def test_evacuate_instance_with_invalid_on_shared_storage(self):
pass
def test_evacuate_disable_password_return(self):
pass
def test_evacuate_enable_password_return(self):
pass
def tet_evacuate_with_non_admin(self):
self.assertRaises(exception.AdminRequired, self.controller.evacuate,
self.req, fakes.FAKE_UUID, {})
class EvacuatePolicyEnforcementv21(test.NoDBTestCase):
def setUp(self):

View File

@ -18,9 +18,6 @@ import mock
from nova.api.openstack.compute import hypervisors \
as hypervisors_v21
from nova.api.openstack.compute.legacy_v2.contrib import hypervisors \
as hypervisors_v2
from nova.api.openstack import extensions
from nova import exception
from nova import objects
from nova import test
@ -99,19 +96,3 @@ class ExtendedHypervisorsTestV21(test.NoDBTestCase):
result = self.controller.show(req, '1')
self.assertEqual(result, dict(hypervisor=self.DETAIL_HYPERS_DICTS[0]))
class ExtendedHypervisorsTestV2(ExtendedHypervisorsTestV21):
DETAIL_HYPERS_DICTS = copy.deepcopy(test_hypervisors.TEST_HYPERS)
del DETAIL_HYPERS_DICTS[0]['service_id']
del DETAIL_HYPERS_DICTS[1]['service_id']
del DETAIL_HYPERS_DICTS[0]['host']
del DETAIL_HYPERS_DICTS[1]['host']
DETAIL_HYPERS_DICTS[0].update({'service': dict(id=1, host='compute1')})
DETAIL_HYPERS_DICTS[1].update({'service': dict(id=2, host='compute2')})
def _set_up_controller(self):
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {}
self.ext_mgr.extensions['os-extended-hypervisors'] = True
self.controller = hypervisors_v2.HypervisorsController(self.ext_mgr)

View File

@ -17,7 +17,6 @@ from oslo_serialization import jsonutils
import six
import webob
from nova.api.openstack.compute.legacy_v2.contrib import extended_ips_mac
from nova import compute
from nova import objects
from nova import test
@ -106,7 +105,7 @@ def fake_compute_get_all(*args, **kwargs):
class ExtendedIpsMacTestV21(test.TestCase):
content_type = 'application/json'
prefix = '%s:' % extended_ips_mac.Extended_ips_mac.alias
prefix = 'OS-EXT-IPS-MAC:'
def setUp(self):
super(ExtendedIpsMacTestV21, self).setUp()
@ -153,21 +152,3 @@ class ExtendedIpsMacTestV21(test.TestCase):
self.assertEqual(res.status_int, 200)
for _i, server in enumerate(self._get_servers(res.body)):
self.assertServerStates(server)
class ExtendedIpsMacTestV2(ExtendedIpsMacTestV21):
content_type = 'application/json'
prefix = '%s:' % extended_ips_mac.Extended_ips_mac.alias
def setUp(self):
super(ExtendedIpsMacTestV2, self).setUp()
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
osapi_compute_ext_list=['Extended_ips_mac'])
def _make_request(self, url):
req = webob.Request.blank(url)
req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app(init_only=('servers',)))
return res

View File

@ -1,62 +0,0 @@
# Copyright 2014 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from nova.api.openstack import common
from nova.api.openstack.compute.legacy_v2.contrib import rescue
from nova.api.openstack import extensions
from nova import compute
import nova.conf
import nova.context as context
from nova import test
CONF = nova.conf.CONF
class FakeRequest(object):
def __init__(self, context):
self.environ = {"nova.context": context}
class ExtendedRescueWithImageTest(test.NoDBTestCase):
def setUp(self):
super(ExtendedRescueWithImageTest, self).setUp()
ext_mgr = extensions.ExtensionManager()
ext_mgr.extensions = {'os-extended-rescue-with-image': 'fake'}
self.controller = rescue.RescueController(ext_mgr)
@mock.patch.object(common, 'get_instance',
return_value="instance")
@mock.patch.object(compute.api.API, "rescue")
def _make_rescue_request_with_image_ref(self, body, mock_rescue,
mock_get_instance):
instance = "instance"
self.controller._get_instance = mock.Mock(return_value=instance)
fake_context = context.RequestContext('fake', 'fake')
req = FakeRequest(fake_context)
self.controller._rescue(req, "id", body)
rescue_image_ref = body["rescue"].get("rescue_image_ref")
mock_rescue.assert_called_with(mock.ANY, mock.ANY,
rescue_password=mock.ANY, rescue_image_ref=rescue_image_ref)
def test_rescue_with_image_specified(self):
body = dict(rescue={
"rescue_image_ref": "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"})
self._make_rescue_request_with_image_ref(body)
def test_rescue_without_image_specified(self):
body = dict(rescue={})
self._make_rescue_request_with_image_ref(body)

View File

@ -1,111 +0,0 @@
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_serialization import jsonutils
import webob
from nova.api.openstack.compute.legacy_v2.contrib import \
extended_virtual_interfaces_net
from nova import compute
from nova import network
from nova.objects import virtual_interface as vif_obj
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests import uuidsentinel as uuids
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
EXPECTED_NET_UUIDS = [123,
456]
def _generate_fake_vifs(context):
vif = vif_obj.VirtualInterface(context=context)
vif.address = '00-00-00-00-00-00'
vif.net_uuid = 123
vif.uuid = uuids.vif1_uuid
fake_vifs = [vif]
vif = vif_obj.VirtualInterface(context=context)
vif.address = '11-11-11-11-11-11'
vif.net_uuid = 456
vif.uuid = uuids.vif2_uuid
fake_vifs.append(vif)
return fake_vifs
def compute_api_get(self, context, instance_id, expected_attrs=None,
want_objects=False):
return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
def get_vifs_by_instance(self, context, instance_id):
return _generate_fake_vifs(context)
def get_vif_by_mac_address(self, context, mac_address):
if mac_address == "00-00-00-00-00-00":
return _generate_fake_vifs(context)[0]
else:
return _generate_fake_vifs(context)[1]
class ExtendedServerVIFNetTest(test.NoDBTestCase):
content_type = 'application/json'
prefix = "%s:" % extended_virtual_interfaces_net. \
Extended_virtual_interfaces_net.alias
def setUp(self):
super(ExtendedServerVIFNetTest, self).setUp()
self.stubs.Set(compute.api.API, "get",
compute_api_get)
self.stubs.Set(network.api.API, "get_vifs_by_instance",
get_vifs_by_instance)
self.stubs.Set(network.api.API, "get_vif_by_mac_address",
get_vif_by_mac_address)
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
osapi_compute_ext_list=['Virtual_interfaces',
'Extended_virtual_interfaces_net'])
def _make_request(self, url):
req = webob.Request.blank(url)
req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app(init_only=(
'os-virtual-interfaces', 'OS-EXT-VIF-NET')))
return res
def _get_vifs(self, body):
return jsonutils.loads(body).get('virtual_interfaces')
def _get_net_id(self, vifs):
for vif in vifs:
yield vif['%snet_id' % self.prefix]
def assertVIFs(self, vifs):
result = []
for net_id in self._get_net_id(vifs):
result.append(net_id)
sorted(result)
for i, net_uuid in enumerate(result):
self.assertEqual(net_uuid, EXPECTED_NET_UUIDS[i])
def test_get_extend_virtual_interfaces_list(self):
res = self._make_request('/v2/fake/servers/abcd/os-virtual-interfaces')
self.assertEqual(res.status_int, 200)
self.assertVIFs(self._get_vifs(res.body))