6627de4aa5
This changes the use_neutron configuration option default value to True. nova-network has been deprecated since Newton and only runs in a cells v1 configuration now, so it's time to make Neutron the default configuration for new Nova deployments. As far as testing, the unit tests have already been taken care of for use_neutron=True by default. There are several functional tests which are converted over to using Neutron via the fixture in this change. However, the legacy API samples functional tests were written with nova-network stubs so it will take some time to convert over to using Neutron stubs. This patch does not attempt to clean all of those up and just configures nova-network by default. The remaining tests will need to be converted to using Neutron in a later series of changes. Depends-On: I82721b5d10711401b9b0ebc2b0ed07cc8287bbf7 Implements blueprint use-neutron-by-default Change-Id: I8388c29ad310cd8800084b4d5c026013158bfbed
142 lines
5.1 KiB
Python
142 lines
5.1 KiB
Python
# Copyright 2012 Nebula, Inc.
|
|
# Copyright 2013 IBM Corp.
|
|
#
|
|
# 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 nova.tests import fixtures
|
|
from nova.tests.functional.api_sample_tests import test_servers
|
|
import nova.tests.functional.api_samples_test_base as astb
|
|
|
|
|
|
def fake_get(*args, **kwargs):
|
|
nova_group = {}
|
|
nova_group['id'] = 1
|
|
nova_group['description'] = 'default'
|
|
nova_group['name'] = 'default'
|
|
nova_group['project_id'] = astb.PROJECT_ID
|
|
nova_group['rules'] = []
|
|
return nova_group
|
|
|
|
|
|
def fake_get_instances_security_groups_bindings(self, context, servers,
|
|
detailed=False):
|
|
result = {}
|
|
for s in servers:
|
|
result[s.get('id')] = [{'name': 'test'}]
|
|
return result
|
|
|
|
|
|
def fake_add_to_instance(self, context, instance, security_group_name):
|
|
pass
|
|
|
|
|
|
def fake_remove_from_instance(self, context, instance, security_group_name):
|
|
pass
|
|
|
|
|
|
def fake_list(self, context, names=None, ids=None, project=None,
|
|
search_opts=None):
|
|
return [fake_get()]
|
|
|
|
|
|
def fake_get_instance_security_groups(self, context, instance_uuid,
|
|
detailed=False):
|
|
return [fake_get()]
|
|
|
|
|
|
def fake_create_security_group(self, context, name, description):
|
|
return fake_get()
|
|
|
|
|
|
class SecurityGroupsJsonTest(test_servers.ServersSampleBase):
|
|
sample_dir = 'os-security-groups'
|
|
USE_NEUTRON = True
|
|
|
|
def setUp(self):
|
|
self.neutron = fixtures.NeutronFixture(self)
|
|
self.useFixture(self.neutron)
|
|
super(SecurityGroupsJsonTest, self).setUp()
|
|
path = 'nova.network.security_group.neutron_driver.SecurityGroupAPI.'
|
|
self.stub_out(path + 'get', fake_get)
|
|
self.stub_out(path + 'get_instances_security_groups_bindings',
|
|
fake_get_instances_security_groups_bindings)
|
|
self.stub_out(path + 'add_to_instance', fake_add_to_instance)
|
|
self.stub_out(path + 'remove_from_instance', fake_remove_from_instance)
|
|
self.stub_out(path + 'list', fake_list)
|
|
self.stub_out(path + 'get_instance_security_groups',
|
|
fake_get_instance_security_groups)
|
|
self.stub_out(path + 'create_security_group',
|
|
fake_create_security_group)
|
|
|
|
def _get_create_subs(self):
|
|
return {
|
|
'group_name': 'default',
|
|
"description": "default",
|
|
}
|
|
|
|
def _create_security_group(self):
|
|
subs = self._get_create_subs()
|
|
return self._do_post('os-security-groups',
|
|
'security-group-post-req', subs)
|
|
|
|
def _add_group(self, uuid):
|
|
subs = {
|
|
'group_name': 'test'
|
|
}
|
|
return self._do_post('servers/%s/action' % uuid,
|
|
'security-group-add-post-req', subs)
|
|
|
|
def test_security_group_create(self):
|
|
response = self._create_security_group()
|
|
subs = self._get_create_subs()
|
|
self._verify_response('security-groups-create-resp', subs,
|
|
response, 200)
|
|
|
|
def test_security_groups_list(self):
|
|
# Get api sample of security groups get list request.
|
|
response = self._do_get('os-security-groups')
|
|
self._verify_response('security-groups-list-get-resp',
|
|
{}, response, 200)
|
|
|
|
def test_security_groups_get(self):
|
|
# Get api sample of security groups get request.
|
|
security_group_id = '11111111-1111-1111-1111-111111111111'
|
|
response = self._do_get('os-security-groups/%s' % security_group_id)
|
|
self._verify_response('security-groups-get-resp', {}, response, 200)
|
|
|
|
def test_security_groups_list_server(self):
|
|
# Get api sample of security groups for a specific server.
|
|
uuid = self._post_server()
|
|
response = self._do_get('servers/%s/os-security-groups' % uuid)
|
|
self._verify_response('server-security-groups-list-resp',
|
|
{}, response, 200)
|
|
|
|
def test_security_groups_add(self):
|
|
self._create_security_group()
|
|
uuid = self._post_server()
|
|
response = self._add_group(uuid)
|
|
self.assertEqual(202, response.status_code)
|
|
self.assertEqual('', response.content)
|
|
|
|
def test_security_groups_remove(self):
|
|
self._create_security_group()
|
|
uuid = self._post_server()
|
|
self._add_group(uuid)
|
|
subs = {
|
|
'group_name': 'test'
|
|
}
|
|
response = self._do_post('servers/%s/action' % uuid,
|
|
'security-group-remove-post-req', subs)
|
|
self.assertEqual(202, response.status_code)
|
|
self.assertEqual('', response.content)
|