Merge "Adds disabled field for flavors."

This commit is contained in:
Jenkins 2017-06-19 12:09:53 +00:00 committed by Gerrit Code Review
commit 6fec2da0d9
12 changed files with 38 additions and 6 deletions

View File

@ -60,6 +60,9 @@ class Flavor(base.APIBase):
is_public = types.boolean
"""Indicates whether the flavor is public."""
disabled = types.boolean
"""Indicates whether the flavor is disabled."""
extra_specs = {wtypes.text: types.jsontype}
"""The extra specs of the flavor"""

View File

@ -23,6 +23,7 @@ create_flavor = {
'name': parameter_types.name,
'description': parameter_types.description,
'is_public': parameter_types.boolean,
'disabled': parameter_types.boolean,
},
'required': ['name', 'description'],
'additionalProperties': False,

View File

@ -153,7 +153,7 @@ class FlavorAlreadyExists(MoganException):
class FlavorNotFound(NotFound):
_msg_fmt = _("Flavor %(type_id)s could not be found.")
_msg_fmt = _("Flavor %(flavor_id)s could not be found.")
class ServerAlreadyExists(MoganException):

View File

@ -37,6 +37,7 @@ def upgrade():
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('extra_specs', sa.Text(), nullable=True),
sa.Column('is_public', sa.Boolean(), nullable=False),
sa.Column('disabled', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('uuid'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'

View File

@ -136,7 +136,7 @@ class Connection(api.Connection):
return query.one()
except NoResultFound:
raise exception.FlavorNotFound(
type_id=flavor_uuid)
flavor_id=flavor_uuid)
def flavor_update(self, context, flavor_id, values):
with _session_for_write():
@ -146,7 +146,7 @@ class Connection(api.Connection):
ref = query.with_lockmode('update').one()
except NoResultFound:
raise exception.FlavorNotFound(
type_id=flavor_id)
flavor_id=flavor_id)
ref.update(values)
return ref
@ -180,7 +180,7 @@ class Connection(api.Connection):
count = query.delete()
if count != 1:
raise exception.FlavorNotFound(
type_id=flavor_uuid)
flavor_id=flavor_uuid)
def server_create(self, context, values):
if not values.get('uuid'):
@ -808,7 +808,7 @@ def _type_get_id_from_type_query(context, type_id):
def _type_get_id_from_type(context, type_id):
result = _type_get_id_from_type_query(context, type_id).first()
if not result:
raise exception.FlavorNotFound(type_id=type_id)
raise exception.FlavorNotFound(flavor_id=type_id)
return result.uuid

View File

@ -158,6 +158,7 @@ class Flavors(Base):
description = Column(String(255), nullable=True)
extra_specs = Column(db_types.JsonEncodedDict)
is_public = Column(Boolean, default=True)
disabled = Column(Boolean, default=False)
servers = orm.relationship(
Server,
backref=orm.backref('flavor', uselist=False),

View File

@ -81,6 +81,8 @@ class API(object):
requested_networks, user_data,
key_name, max_count):
"""Verify all the input parameters"""
if flavor['disabled']:
raise exception.FlavorNotFound(flavor_id=flavor['uuid'])
if user_data:
l = len(user_data)

View File

@ -36,6 +36,7 @@ class Flavor(base.MoganObject, object_base.VersionedObjectDictCompat):
'name': object_fields.StringField(nullable=True),
'description': object_fields.StringField(nullable=True),
'is_public': object_fields.BooleanField(),
'disabled': object_fields.BooleanField(),
'extra_specs': object_fields.FlexibleDictField(nullable=True),
'projects': object_fields.ListOfStringsField(),
}

View File

@ -56,6 +56,7 @@ class BaremetalComputeAPITest(base.BaseBaremetalComputeTest):
self.assertEqual('mogan flavor description',
resp['description'])
self.assertEqual(True, resp['is_public'])
self.assertEqual(False, resp['disabled'])
self.assertIn('uuid', resp)
self.assertIn('extra_specs', resp)
self.assertIn('links', resp)
@ -68,6 +69,7 @@ class BaremetalComputeAPITest(base.BaseBaremetalComputeTest):
self.assertEqual('mogan flavor description',
resp['description'])
self.assertEqual(True, resp['is_public'])
self.assertEqual(False, resp['disabled'])
self.assertIn('uuid', resp)
self.assertIn('extra_specs', resp)
self.assertIn('links', resp)

View File

@ -166,6 +166,7 @@ def get_test_flavor(**kw):
'name': kw.get('name', 'test'),
'description': kw.get('description', 'test'),
'is_public': kw.get('is_public', 1),
'disabled': kw.get('disabled', 0),
'updated_at': kw.get('updated_at'),
'created_at': kw.get('created_at'),
}

View File

@ -72,6 +72,26 @@ class ComputeAPIUnitTest(base.DbTestCase):
self.assertEqual('test_az', base_opts['availability_zone'])
self.assertIsNone(key_pair)
def test__validate_and_build_base_options_flavor_disabled(self):
flavor = self._create_flavor()
flavor.disabled = True
flavor.save()
self.assertRaises(
exception.FlavorNotFound,
self.engine_api._validate_and_build_base_options,
self.context,
flavor,
'fake-uuid',
'fake-name',
'fake-descritpion',
'test_az',
{'k1', 'v1'},
[{'uuid': 'fake'}],
None,
None,
1)
@mock.patch.object(objects.Server, 'create')
def test__provision_servers(self, mock_server_create):
mock_server_create.return_value = mock.MagicMock()

View File

@ -389,7 +389,7 @@ expected_object_fingerprints = {
'ComputePortList': '1.0-33a2e1bb91ad4082f9f63429b77c1244',
'ServerFault': '1.0-74349ff701259e4834b4e9dc2dac1b12',
'ServerFaultList': '1.0-43e8aad0258652921f929934e9e048fd',
'Flavor': '1.0-2ec0238ca39a3f55201c1eea4e84f280',
'Flavor': '1.0-1ffc02ecf4565f4b5e88b8369cb70553',
'MyObj': '1.1-aad62eedc5a5cc8bcaf2982c285e753f',
'ServerNic': '1.0-ebbd767c2f6a7f14bd524c6067f2b382',
'ServerNics': '1.0-33a2e1bb91ad4082f9f63429b77c1244',