Follow-up on 751234 and 750072
Change-Id: I4a9acf9d08791411ccbd0f00dcb1bc053daea6ce
This commit is contained in:
parent
190966a331
commit
64ca078ef3
@ -67,10 +67,12 @@ class Proxy(proxy.Proxy):
|
||||
|
||||
:param name_or_id: The name or ID of a flavor.
|
||||
:param bool ignore_missing: When set to ``False``
|
||||
:class:`~openstack.exceptions.ResourceNotFound` will be
|
||||
raised when the resource does not exist.
|
||||
When set to ``True``, None will be returned when
|
||||
attempting to find a nonexistent resource.
|
||||
:class:`~openstack.exceptions.ResourceNotFound` will be raised when
|
||||
the resource does not exist. When set to ``True``, None will be
|
||||
returned when attempting to find a nonexistent resource.
|
||||
:param bool get_extra_specs: When set to ``True`` and extra_specs not
|
||||
present in the response will invoke additional API call to fetch
|
||||
extra_specs.
|
||||
:returns: One :class:`~openstack.compute.v2.flavor.Flavor` or None
|
||||
"""
|
||||
flavor = self._find(_flavor.Flavor, name_or_id,
|
||||
@ -110,11 +112,14 @@ class Proxy(proxy.Proxy):
|
||||
"""Get a single flavor
|
||||
|
||||
:param flavor: The value can be the ID of a flavor or a
|
||||
:class:`~openstack.compute.v2.flavor.Flavor` instance.
|
||||
:class:`~openstack.compute.v2.flavor.Flavor` instance.
|
||||
:param bool get_extra_specs: When set to ``True`` and extra_specs not
|
||||
present in the response will invoke additional API call to fetch
|
||||
extra_specs.
|
||||
|
||||
:returns: One :class:`~openstack.compute.v2.flavor.Flavor`
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
when no resource can be found.
|
||||
"""
|
||||
flavor = self._get(_flavor.Flavor, flavor)
|
||||
if get_extra_specs and not flavor.extra_specs:
|
||||
|
@ -104,9 +104,9 @@ class Flavor(resource.Resource):
|
||||
self._action(session, body)
|
||||
|
||||
def get_access(self, session):
|
||||
"""Lists tenants who have access to a private flavor and adds private
|
||||
flavor access to and removes private flavor access from tenants. By
|
||||
default, only administrators can manage private flavor access. A
|
||||
"""Lists tenants who have access to a private flavor
|
||||
|
||||
By default, only administrators can manage private flavor access. A
|
||||
private flavor has is_public set to false while a public flavor has
|
||||
is_public set to true.
|
||||
|
||||
@ -119,8 +119,9 @@ class Flavor(resource.Resource):
|
||||
|
||||
def fetch_extra_specs(self, session):
|
||||
"""Fetch extra_specs of the flavor
|
||||
|
||||
Starting with 2.61 extra_specs are returned with the flavor details,
|
||||
before that a separate call is required
|
||||
before that a separate call is required.
|
||||
"""
|
||||
url = utils.urljoin(Flavor.base_path, self.id, 'os-extra_specs')
|
||||
microversion = self._get_microversion_for(session, 'fetch')
|
||||
|
@ -487,7 +487,7 @@ class Server(resource.Resource, metadata.MetadataMixin, resource.TagMixin):
|
||||
def get_console_url(self, session, console_type):
|
||||
action = CONSOLE_TYPE_ACTION_MAPPING.get(console_type)
|
||||
if not action:
|
||||
raise ValueError("Unsupported console type")
|
||||
raise ValueError("Unsupported console type %s" % console_type)
|
||||
body = {action: {'type': console_type}}
|
||||
resp = self._action(session, body)
|
||||
return resp.json().get('console')
|
||||
|
@ -719,38 +719,45 @@ class TestCompute(TestComputeProxy):
|
||||
method_args=["value", "console_type"],
|
||||
expected_args=["console_type"])
|
||||
|
||||
def test_create_console(self):
|
||||
with \
|
||||
mock.patch('openstack.utils.supports_microversion') as smv, \
|
||||
mock.patch('openstack.compute.v2._proxy.Proxy._create') as rcc, \
|
||||
mock.patch('openstack.compute.v2.server.Server.get_console_url') \
|
||||
as sgc:
|
||||
console_fake = {
|
||||
'url': 'a',
|
||||
'type': 'b',
|
||||
'protocol': 'c'
|
||||
}
|
||||
smv.return_value = False
|
||||
sgc.return_value = console_fake
|
||||
ret = self.proxy.create_console('fake_server', 'fake_type')
|
||||
smv.assert_called_once_with(self.proxy, '2.6')
|
||||
rcc.assert_not_called()
|
||||
sgc.assert_called_with(self.proxy, 'fake_type')
|
||||
self.assertDictEqual(console_fake, ret)
|
||||
@mock.patch('openstack.utils.supports_microversion', autospec=True)
|
||||
@mock.patch('openstack.compute.v2._proxy.Proxy._create', autospec=True)
|
||||
@mock.patch('openstack.compute.v2.server.Server.get_console_url',
|
||||
autospec=True)
|
||||
def test_create_console_mv_old(self, sgc, rcc, smv):
|
||||
console_fake = {
|
||||
'url': 'a',
|
||||
'type': 'b',
|
||||
'protocol': 'c'
|
||||
}
|
||||
smv.return_value = False
|
||||
sgc.return_value = console_fake
|
||||
ret = self.proxy.create_console('fake_server', 'fake_type')
|
||||
smv.assert_called_once_with(self.proxy, '2.6')
|
||||
rcc.assert_not_called()
|
||||
sgc.assert_called_with(mock.ANY, self.proxy, 'fake_type')
|
||||
self.assertDictEqual(console_fake, ret)
|
||||
|
||||
smv.reset_mock()
|
||||
sgc.reset_mock()
|
||||
rcc.reset_mock()
|
||||
@mock.patch('openstack.utils.supports_microversion', autospec=True)
|
||||
@mock.patch('openstack.compute.v2._proxy.Proxy._create', autospec=True)
|
||||
@mock.patch('openstack.compute.v2.server.Server.get_console_url',
|
||||
autospec=True)
|
||||
def test_create_console_mv_2_6(self, sgc, rcc, smv):
|
||||
console_fake = {
|
||||
'url': 'a',
|
||||
'type': 'b',
|
||||
'protocol': 'c'
|
||||
}
|
||||
|
||||
# Test server_remote_console is triggered when mv>=2.6
|
||||
smv.return_value = True
|
||||
rcc.return_value = server_remote_console.ServerRemoteConsole(
|
||||
**console_fake)
|
||||
ret = self.proxy.create_console('fake_server', 'fake_type')
|
||||
smv.assert_called_once_with(self.proxy, '2.6')
|
||||
sgc.assert_not_called()
|
||||
rcc.assert_called_with(server_remote_console.ServerRemoteConsole,
|
||||
server_id='fake_server',
|
||||
type='fake_type',
|
||||
protocol=None)
|
||||
self.assertEqual(console_fake['url'], ret['url'])
|
||||
# Test server_remote_console is triggered when mv>=2.6
|
||||
smv.return_value = True
|
||||
rcc.return_value = server_remote_console.ServerRemoteConsole(
|
||||
**console_fake)
|
||||
ret = self.proxy.create_console('fake_server', 'fake_type')
|
||||
smv.assert_called_once_with(self.proxy, '2.6')
|
||||
sgc.assert_not_called()
|
||||
rcc.assert_called_with(mock.ANY,
|
||||
server_remote_console.ServerRemoteConsole,
|
||||
server_id='fake_server',
|
||||
type='fake_type',
|
||||
protocol=None)
|
||||
self.assertEqual(console_fake['url'], ret['url'])
|
||||
|
@ -1,7 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add additional compute flavor operations (flavor_add_tenant_access, flavor_remove_tenant_access, get_flavor_access, extra_specs fetching/updating).
|
||||
other:
|
||||
- |
|
||||
Merge FlavorDetails into Flavor class.
|
||||
Add additional compute flavor operations (flavor_add_tenant_access,
|
||||
flavor_remove_tenant_access, get_flavor_access, extra_specs fetching/updating).
|
||||
|
@ -1,4 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Optimizes compute server console creation by addind older get_server_console method to the server and create_console proxy method calling appropriate method depending on the suported microversion.
|
||||
Optimizes compute server console creation by adding older
|
||||
get_server_console method to the server and create_console proxy method
|
||||
calling appropriate method depending on the supported microversion.
|
||||
|
Loading…
x
Reference in New Issue
Block a user