Add CT tags field to the database and API

We noticed that from the user perspective it is hard
to know when a cluster_template provided by the cloud
admin is mature enough for a production release.
This field will allow the administrator to add an
annotation to the cluster template like
{deprecated, recommended, testing} giving further
usefull information to the end user about the
template's life cycle

This patch adds the necessary database column and
API objects to handle the new argument.

story: 2007857
task: 40160

Change-Id: I5d1c4221f089bc5cd12b25f620aa01771a029df9
Signed-off-by: Diogo Guerra <diogo.filipe.tomas.guerra@cern.ch>
This commit is contained in:
Diogo Guerra 2020-06-24 15:41:22 +02:00 committed by Bharat Kunwar
parent 3db9265392
commit 332e2b6fe4
12 changed files with 71 additions and 5 deletions

View File

@ -57,6 +57,7 @@ Request
- dns_nameserver: dns_nameserver
- floating_ip_enabled: floating_ip_enabled
- hidden: hidden
- tags: tags
Request Example
----------------
@ -102,6 +103,7 @@ Response
- master_lb_enabled: master_lb_enabled
- dns_nameserver: dns_nameserver
- hidden: hidden
- tags: tags
Response Example
----------------
@ -167,6 +169,7 @@ Response
- master_lb_enabled: master_lb_enabled
- dns_nameserver: dns_nameserver
- hidden: hidden
- tags: tags
Response Example
----------------
@ -240,6 +243,7 @@ Response
- master_lb_enabled: master_lb_enabled
- dns_nameserver: dns_nameserver
- hidden: hidden
- tags: tags
Response Example
----------------
@ -364,9 +368,10 @@ Return new cluster templates with updated attributes.
- master_lb_enabled: master_lb_enabled
- dns_nameserver: dns_nameserver
- hidden: hidden
- tags: tags
Response Example
----------------
.. literalinclude:: samples/clustertemplate-create-resp.json
:language: javascript
:language: javascript

View File

@ -559,6 +559,12 @@ status_reason:
in: body
required: true
type: string
tags:
description: |
Administrator tags for the cluster template.
in: body
required: false
type: array
tls_disabled:
description: |
Transport Layer Security (TLS) is normally enabled to secure the

View File

@ -141,6 +141,9 @@ class BayModel(base.APIBase):
hidden = wsme.wsattr(types.boolean, default=False)
"""Indicates whether the Baymodel is hidden or not."""
tags = wtypes.StringType(min_length=0, max_length=255)
"""A comma separated list of tags."""
def __init__(self, **kwargs):
self.fields = []
for field in objects.ClusterTemplate.fields:

View File

@ -156,6 +156,9 @@ class ClusterTemplate(base.APIBase):
hidden = wsme.wsattr(types.boolean, default=False)
"""Indicates whether the ClusterTemplate is hidden or not."""
tags = wtypes.StringType(min_length=0, max_length=255)
"""A comma separated list of tags."""
def __init__(self, **kwargs):
self.fields = []
for field in objects.ClusterTemplate.fields:

View File

@ -0,0 +1,31 @@
# 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.
"""added_tags_to_cluster_template
Revision ID: f1d8b0ab8b8d
Revises: 95096e2334ee
Create Date: 2020-08-26 08:38:11.567618
"""
# revision identifiers, used by Alembic.
revision = 'f1d8b0ab8b8d'
down_revision = '95096e2334ee'
from alembic import op # noqa: E402
import sqlalchemy as sa # noqa: E402
def upgrade():
op.add_column('cluster_template',
sa.Column('tags',
sa.String(length=255), nullable=True))

View File

@ -389,7 +389,8 @@ class Connection(api.Connection):
def _is_publishing_cluster_template(self, values):
if (len(values) == 1 and (
('public' in values and values['public'] is True) or
('hidden' in values))):
('hidden' in values) or
('tags' in values and values['tags'] is not None))):
return True
return False

View File

@ -191,6 +191,7 @@ class ClusterTemplate(Base):
master_lb_enabled = Column(Boolean, default=False)
floating_ip_enabled = Column(Boolean, default=True)
hidden = Column(Boolean, default=False)
tags = Column(String(255))
class X509KeyPair(Base):

View File

@ -43,7 +43,8 @@ class ClusterTemplate(base.MagnumPersistentObject, base.MagnumObject,
# Version 1.17: 'coe' field type change to ClusterTypeField
# Version 1.18: DockerStorageDriver is a StringField (was an Enum)
# Version 1.19: Added 'hidden' field
VERSION = '1.19'
# Version 1.20: Added 'tags' field
VERSION = '1.20'
dbapi = dbapi.get_instance()
@ -80,6 +81,7 @@ class ClusterTemplate(base.MagnumPersistentObject, base.MagnumObject,
'master_lb_enabled': fields.BooleanField(default=False),
'floating_ip_enabled': fields.BooleanField(default=True),
'hidden': fields.BooleanField(default=False),
'tags': fields.StringField(nullable=True),
}
@staticmethod

View File

@ -64,7 +64,8 @@ class TestListClusterTemplate(api_base.FunctionalTest):
'image_id', 'registry_enabled', 'no_proxy',
'keypair_id', 'https_proxy', 'tls_disabled',
'public', 'labels', 'master_flavor_id',
'volume_driver', 'insecure_registry', 'hidden')
'volume_driver', 'insecure_registry', 'hidden',
'tags',)
def test_empty(self):
response = self.get_json('/clustertemplates')

View File

@ -57,6 +57,7 @@ def get_test_cluster_template(**kw):
'master_lb_enabled': kw.get('master_lb_enabled', True),
'floating_ip_enabled': kw.get('floating_ip_enabled', True),
'hidden': kw.get('hidden', False),
'tags': kw.get('tags', ""),
}

View File

@ -356,7 +356,7 @@ class TestObject(test_base.TestCase, _TestObject):
# https://docs.openstack.org/magnum/latest/contributor/objects.html
object_data = {
'Cluster': '1.22-39ae1aa9ed1e90ee05f67f64b5fce4bb',
'ClusterTemplate': '1.19-3b0b2b3933d0955abf3ab40111744960',
'ClusterTemplate': '1.20-85469623f678e916f26e3cb5924ae664',
'Certificate': '1.1-1924dc077daa844f0f9076332ef96815',
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',
'X509KeyPair': '1.2-d81950af36c59a71365e33ce539d24f9',

View File

@ -0,0 +1,12 @@
---
features:
- |
When creating a cluster template the administrator can
use --tags <text> argument to add any information
that he considers important. The received text is a
comma separated list with the pretended tags.
This information is also shown when the user lists all
the available cluster templates.
upgrade:
- |
A new column was added to the cluster_templates DB table.