Remove deprecated security_groups APIs

These were deprecated in Newton:

aaebeb05a0

The SecurityGroup resource object is left
since the list-secgroup command and
list_security_group servers API code
still uses that object. The
/servers/{server_id}/os-security-groups API
is a proxy to Neutron but was not deprecated
in microversion 2.36 so it's not yet deprecated
here in the client.

Change-Id: I6fa14f43d48f1e035ef54bd2d0078506f0c6d6e0
This commit is contained in:
Matt Riedemann 2017-03-20 18:42:45 -04:00
parent 0896bdc52a
commit a298b29cc7
7 changed files with 7 additions and 372 deletions

View File

@ -1,100 +0,0 @@
# 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 novaclient.tests.unit import fakes
from novaclient.tests.unit.fixture_data import base
class Fixture(base.Fixture):
base_url = 'os-security-groups'
def setUp(self):
super(Fixture, self).setUp()
security_group_1 = {
"name": "test",
"description": "FAKE_SECURITY_GROUP",
"tenant_id": "4ffc664c198e435e9853f2538fbcd7a7",
"id": 1,
"rules": [
{
"id": 11,
"group": {},
"ip_protocol": "TCP",
"from_port": 22,
"to_port": 22,
"parent_group_id": 1,
"ip_range": {"cidr": "10.0.0.0/8"}
},
{
"id": 12,
"group": {
"tenant_id": "272bee4c1e624cd4a72a6b0ea55b4582",
"name": "test2"
},
"ip_protocol": "TCP",
"from_port": 222,
"to_port": 222,
"parent_group_id": 1,
"ip_range": {}
}
]
}
security_group_2 = {
"name": "test2",
"description": "FAKE_SECURITY_GROUP2",
"tenant_id": "272bee4c1e624cd4a72a6b0ea55b4582",
"id": 2,
"rules": []
}
get_groups = {'security_groups': [security_group_1, security_group_2]}
headers = self.json_headers
self.requests_mock.get(self.url(),
json=get_groups,
headers=headers)
get_group_1 = {'security_group': security_group_1}
self.requests_mock.get(self.url(1),
json=get_group_1,
headers=headers)
self.requests_mock.delete(self.url(1),
status_code=202,
headers=headers)
def post_os_security_groups(request, context):
body = request.json()
assert list(body) == ['security_group']
fakes.assert_has_keys(body['security_group'],
required=['name', 'description'])
return {'security_group': security_group_1}
self.requests_mock.post(self.url(),
json=post_os_security_groups,
headers=headers,
status_code=202)
def put_os_security_groups_1(request, context):
body = request.json()
assert list(body) == ['security_group']
fakes.assert_has_keys(body['security_group'],
required=['name', 'description'])
return body
self.requests_mock.put(self.url(1),
json=put_os_security_groups_1,
headers=headers,
status_code=205)

View File

@ -1349,75 +1349,6 @@ class FakeSessionClient(base_client.SessionClient):
'security_groups': 1,
'security_group_rules': 1}})
#
# Security Groups
#
def get_os_security_groups(self, **kw):
return (200, {}, {"security_groups": [
{"name": "test",
"description": "FAKE_SECURITY_GROUP",
"tenant_id": "4ffc664c198e435e9853f2538fbcd7a7",
"id": 1,
"rules": [
{"id": 11,
"group": {},
"ip_protocol": "TCP",
"from_port": 22,
"to_port": 22,
"parent_group_id": 1,
"ip_range":
{"cidr": "10.0.0.0/8"}},
{"id": 12,
"group": {
"tenant_id":
"272bee4c1e624cd4a72a6b0ea55b4582",
"name": "test2"},
"ip_protocol": "TCP",
"from_port": 222,
"to_port": 222,
"parent_group_id": 1,
"ip_range": {}},
{"id": 14,
"group": {
"tenant_id":
"272bee4c1e624cd4a72a6b0ea55b4582",
"name": "test4"},
"ip_protocol": "TCP",
"from_port": -1,
"to_port": -1,
"parent_group_id": 1,
"ip_range": {}}]},
{"name": "test2",
"description": "FAKE_SECURITY_GROUP2",
"tenant_id": "272bee4c1e624cd4a72a6b0ea55b4582",
"id": 2,
"rules": []},
{"name": "test4",
"description": "FAKE_SECURITY_GROUP4",
"tenant_id": "272bee4c1e624cd4a72a6b0ea55b4582",
"id": 4,
"rules": []}
]})
def delete_os_security_groups_1(self, **kw):
return (202, {}, None)
def post_os_security_groups(self, body, **kw):
assert list(body) == ['security_group']
fakes.assert_has_keys(body['security_group'],
required=['name', 'description'])
r = {'security_group':
self.get_os_security_groups()[2]['security_groups'][0]}
return (202, {}, r)
def put_os_security_groups_1(self, body, **kw):
assert list(body) == ['security_group']
fakes.assert_has_keys(body['security_group'],
required=['name', 'description'])
return (205, {}, body)
#
# Tenant Usage
#

View File

@ -1,84 +0,0 @@
#
# 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 novaclient.tests.unit.fixture_data import client
from novaclient.tests.unit.fixture_data import security_groups as data
from novaclient.tests.unit import utils
from novaclient.tests.unit.v2 import fakes
from novaclient.v2 import security_groups
class SecurityGroupsTest(utils.FixturedTestCase):
client_fixture_class = client.V1
data_fixture_class = data.Fixture
def _do_test_list_security_groups(self, search_opts, path):
sgs = self.cs.security_groups.list(search_opts=search_opts)
self.assert_request_id(sgs, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('GET', path)
for sg in sgs:
self.assertIsInstance(sg, security_groups.SecurityGroup)
def test_list_security_groups_all_tenants_on(self):
self._do_test_list_security_groups(
None, '/os-security-groups')
def test_list_security_groups_all_tenants_on_with_search_opts(self):
self._do_test_list_security_groups(
{'all_tenants': 1}, '/os-security-groups?all_tenants=1')
def test_list_security_groups_all_tenants_off(self):
self._do_test_list_security_groups(
{'all_tenants': 0}, '/os-security-groups')
def test_get_security_groups(self):
sg = self.cs.security_groups.get(1)
self.assert_request_id(sg, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('GET', '/os-security-groups/1')
self.assertIsInstance(sg, security_groups.SecurityGroup)
self.assertEqual('1', str(sg))
def test_delete_security_group(self):
sg = self.cs.security_groups.list()[0]
ret = sg.delete()
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('DELETE', '/os-security-groups/1')
ret = self.cs.security_groups.delete(1)
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('DELETE', '/os-security-groups/1')
ret = self.cs.security_groups.delete(sg)
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('DELETE', '/os-security-groups/1')
def test_create_security_group(self):
sg = self.cs.security_groups.create("foo", "foo barr")
self.assert_request_id(sg, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('POST', '/os-security-groups')
self.assertIsInstance(sg, security_groups.SecurityGroup)
def test_update_security_group(self):
sg = self.cs.security_groups.list()[0]
secgroup = self.cs.security_groups.update(sg, "update", "update")
self.assert_request_id(secgroup, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('PUT', '/os-security-groups/1')
self.assertIsInstance(secgroup, security_groups.SecurityGroup)
def test_refresh_security_group(self):
sg = self.cs.security_groups.get(1)
sg2 = self.cs.security_groups.get(1)
self.assertEqual(sg.name, sg2.name)
sg2.name = "should be test"
self.assertNotEqual(sg.name, sg2.name)
sg2.get()
self.assertEqual(sg.name, sg2.name)

View File

@ -43,7 +43,6 @@ from novaclient.v2 import migrations
from novaclient.v2 import networks
from novaclient.v2 import quota_classes
from novaclient.v2 import quotas
from novaclient.v2 import security_groups
from novaclient.v2 import server_external_events
from novaclient.v2 import server_groups
from novaclient.v2 import server_migrations
@ -163,7 +162,6 @@ class Client(object):
self.neutron = networks.NeutronManager(self)
self.quota_classes = quota_classes.QuotaClassSetManager(self)
self.quotas = quotas.QuotaSetManager(self)
self.security_groups = security_groups.SecurityGroupManager(self)
self.usage = usage.UsageManager(self)
self.virtual_interfaces = \
virtual_interfaces.VirtualInterfaceManager(self)

View File

@ -1,115 +0,0 @@
# Copyright 2011 OpenStack Foundation
# 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.
"""
Security group interface (1.1 extension).
"""
from six.moves.urllib import parse
from novaclient import api_versions
from novaclient import base
class SecurityGroup(base.Resource):
"""DEPRECATED"""
def __str__(self):
return str(self.id)
def delete(self):
"""
DEPRECATED: Delete this security group.
:returns: An instance of novaclient.base.TupleWithMeta
"""
return self.manager.delete(self)
def update(self):
"""
DEPRECATED: Update this security group.
:returns: :class:`SecurityGroup`
"""
return self.manager.update(self)
class SecurityGroupManager(base.ManagerWithFind):
"""DEPRECATED"""
resource_class = SecurityGroup
@api_versions.deprecated_after('2.35')
def create(self, name, description):
"""
DEPRECATED: Create a security group
:param name: name for the security group to create
:param description: description of the security group
:rtype: the security group object
"""
body = {"security_group": {"name": name, 'description': description}}
return self._create('/os-security-groups', body, 'security_group')
@api_versions.deprecated_after('2.35')
def update(self, group, name, description):
"""
DEPRECATED: Update a security group
:param group: The security group to update (group or ID)
:param name: name for the security group to update
:param description: description for the security group to update
:rtype: the security group object
"""
body = {"security_group": {"name": name, 'description': description}}
return self._update('/os-security-groups/%s' % base.getid(group),
body, 'security_group')
@api_versions.deprecated_after('2.35')
def delete(self, group):
"""
DEPRECATED: Delete a security group
:param group: The security group to delete (group or ID)
:returns: An instance of novaclient.base.TupleWithMeta
"""
return self._delete('/os-security-groups/%s' % base.getid(group))
@api_versions.deprecated_after('2.35')
def get(self, group_id):
"""
DEPRECATED: Get a security group
:param group_id: The security group to get by ID
:rtype: :class:`SecurityGroup`
"""
return self._get('/os-security-groups/%s' % group_id,
'security_group')
@api_versions.deprecated_after('2.35')
def list(self, search_opts=None):
"""
DEPRECATED: Get a list of all security_groups
:rtype: list of :class:`SecurityGroup`
"""
search_opts = search_opts or {}
qparams = dict((k, v) for (k, v) in search_opts.items() if v)
query_string = '?%s' % parse.urlencode(qparams) if qparams else ''
return self._list('/os-security-groups%s' % query_string,
'security_groups')

View File

@ -30,7 +30,6 @@ from novaclient import base
from novaclient import crypto
from novaclient import exceptions
from novaclient.i18n import _
from novaclient.v2 import security_groups
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
@ -632,6 +631,11 @@ class NetworkInterface(base.Resource):
return '<NetworkInterface: %s>' % self.id
class SecurityGroup(base.Resource):
def __str__(self):
return str(self.id)
class ServerManager(base.BootingManagerWithFind):
resource_class = Server
@ -1780,7 +1784,7 @@ class ServerManager(base.BootingManagerWithFind):
"""
return self._list('/servers/%s/os-security-groups' %
base.getid(server), 'security_groups',
security_groups.SecurityGroup)
SecurityGroup)
@api_versions.wraps("2.0", "2.13")
def evacuate(self, server, host=None, on_shared_storage=True,

View File

@ -61,6 +61,7 @@ upgrade:
* novaclient.v2.fping
* novaclient.v2.security_group_default_rules
* novaclient.v2.security_group_rules
* novaclient.v2.security_groups
deprecations:
- |