summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-09-03 09:28:07 +0000
committerGerrit Code Review <review@openstack.org>2018-09-03 09:28:07 +0000
commitb881ecd51285a19410fc72d0f3a736a4b632ee1f (patch)
tree6bb43e989eb719d1db666fa5396010679d630ac5
parentfff1d722df5386a523576baf404165014d29585b (diff)
parentd80febb3842c3bad11cd6a01bae2fb593f0f7812 (diff)
Merge "Add health_status and health_status_reason to cluster"
-rwxr-xr-xmagnum/api/controllers/v1/cluster.py8
-rw-r--r--magnum/db/sqlalchemy/alembic/versions/cbbc65a86986_add_health_status_to_cluster.py38
-rw-r--r--magnum/db/sqlalchemy/models.py2
-rw-r--r--magnum/objects/cluster.py5
-rw-r--r--magnum/objects/fields.py17
-rw-r--r--magnum/tests/unit/objects/test_cluster.py2
-rw-r--r--magnum/tests/unit/objects/test_fields.py19
-rw-r--r--magnum/tests/unit/objects/test_objects.py2
8 files changed, 91 insertions, 2 deletions
diff --git a/magnum/api/controllers/v1/cluster.py b/magnum/api/controllers/v1/cluster.py
index 1cb245c..23c924a 100755
--- a/magnum/api/controllers/v1/cluster.py
+++ b/magnum/api/controllers/v1/cluster.py
@@ -134,6 +134,12 @@ class Cluster(base.APIBase):
134 status_reason = wtypes.text 134 status_reason = wtypes.text
135 """Status reason of the cluster from the heat stack""" 135 """Status reason of the cluster from the heat stack"""
136 136
137 health_status = wtypes.Enum(str, *fields.ClusterStatus.ALL)
138 """Health status of the cluster from the native COE API"""
139
140 health_status_reason = wtypes.DictType(str, str)
141 """Health status reason of the cluster from the native COE API"""
142
137 discovery_url = wtypes.text 143 discovery_url = wtypes.text
138 """Url used for cluster node discovery""" 144 """Url used for cluster node discovery"""
139 145
@@ -211,6 +217,8 @@ class Cluster(base.APIBase):
211 stack_id='49dc23f5-ffc9-40c3-9d34-7be7f9e34d63', 217 stack_id='49dc23f5-ffc9-40c3-9d34-7be7f9e34d63',
212 status=fields.ClusterStatus.CREATE_COMPLETE, 218 status=fields.ClusterStatus.CREATE_COMPLETE,
213 status_reason="CREATE completed successfully", 219 status_reason="CREATE completed successfully",
220 health_status=fields.ClusterHealthStatus.HEALTHY,
221 health_status_reason='{"api_server": "OK"}',
214 api_address='172.24.4.3', 222 api_address='172.24.4.3',
215 node_addresses=['172.24.4.4', '172.24.4.5'], 223 node_addresses=['172.24.4.4', '172.24.4.5'],
216 created_at=timeutils.utcnow(), 224 created_at=timeutils.utcnow(),
diff --git a/magnum/db/sqlalchemy/alembic/versions/cbbc65a86986_add_health_status_to_cluster.py b/magnum/db/sqlalchemy/alembic/versions/cbbc65a86986_add_health_status_to_cluster.py
new file mode 100644
index 0000000..e350aac
--- /dev/null
+++ b/magnum/db/sqlalchemy/alembic/versions/cbbc65a86986_add_health_status_to_cluster.py
@@ -0,0 +1,38 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14"""Add health_status and health_status_reason to cluster
15
16Revision ID: cbbc65a86986
17Revises: 9a1539f1cd2c
18Create Date: 2018-05-15 22:24:49.527558
19
20"""
21
22# revision identifiers, used by Alembic.
23revision = 'cbbc65a86986'
24down_revision = '9a1539f1cd2c'
25
26from alembic import op
27import sqlalchemy as sa
28
29
30def upgrade():
31 # ### commands auto generated by Alembic - please adjust! ###
32 op.add_column('cluster', sa.Column('health_status',
33 sa.String(20),
34 nullable=True))
35 op.add_column('cluster', sa.Column('health_status_reason',
36 sa.Text,
37 nullable=True))
38 # ### end Alembic commands ###
diff --git a/magnum/db/sqlalchemy/models.py b/magnum/db/sqlalchemy/models.py
index 5e56a7a..378f4b4 100644
--- a/magnum/db/sqlalchemy/models.py
+++ b/magnum/db/sqlalchemy/models.py
@@ -128,6 +128,8 @@ class Cluster(Base):
128 master_count = Column(Integer()) 128 master_count = Column(Integer())
129 status = Column(String(20)) 129 status = Column(String(20))
130 status_reason = Column(Text) 130 status_reason = Column(Text)
131 health_status = Column(String(20))
132 health_status_reason = Column(JSONEncodedDict)
131 create_timeout = Column(Integer()) 133 create_timeout = Column(Integer())
132 discovery_url = Column(String(255, mysql_ndb_type=TINYTEXT)) 134 discovery_url = Column(String(255, mysql_ndb_type=TINYTEXT))
133 master_addresses = Column(JSONEncodedList) 135 master_addresses = Column(JSONEncodedList)
diff --git a/magnum/objects/cluster.py b/magnum/objects/cluster.py
index 01f704d..5110d8a 100644
--- a/magnum/objects/cluster.py
+++ b/magnum/objects/cluster.py
@@ -46,8 +46,9 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
46 # Version 1.15: Added 'labels' field 46 # Version 1.15: Added 'labels' field
47 # Version 1.16: Added 'master_flavor_id' field 47 # Version 1.16: Added 'master_flavor_id' field
48 # Version 1.17: Added 'flavor_id' field 48 # Version 1.17: Added 'flavor_id' field
49 # Version 1.18: Added 'health_status' and 'health_status_reason' field
49 50
50 VERSION = '1.17' 51 VERSION = '1.18'
51 52
52 dbapi = dbapi.get_instance() 53 dbapi = dbapi.get_instance()
53 54
@@ -66,6 +67,8 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
66 'stack_id': fields.StringField(nullable=True), 67 'stack_id': fields.StringField(nullable=True),
67 'status': m_fields.ClusterStatusField(nullable=True), 68 'status': m_fields.ClusterStatusField(nullable=True),
68 'status_reason': fields.StringField(nullable=True), 69 'status_reason': fields.StringField(nullable=True),
70 'health_status': m_fields.ClusterHealthStatusField(nullable=True),
71 'health_status_reason': fields.DictOfStringsField(nullable=True),
69 'create_timeout': fields.IntegerField(nullable=True), 72 'create_timeout': fields.IntegerField(nullable=True),
70 'api_address': fields.StringField(nullable=True), 73 'api_address': fields.StringField(nullable=True),
71 'node_addresses': fields.ListOfStringsField(nullable=True), 74 'node_addresses': fields.ListOfStringsField(nullable=True),
diff --git a/magnum/objects/fields.py b/magnum/objects/fields.py
index 07b3a48..6bb88b9 100644
--- a/magnum/objects/fields.py
+++ b/magnum/objects/fields.py
@@ -49,6 +49,19 @@ class ClusterStatus(fields.Enum):
49 super(ClusterStatus, self).__init__(valid_values=ClusterStatus.ALL) 49 super(ClusterStatus, self).__init__(valid_values=ClusterStatus.ALL)
50 50
51 51
52class ClusterHealthStatus(fields.Enum):
53 HEALTHY = 'HEALTHY'
54 UNHEALTHY = 'UNHEALTHY'
55
56 ALL = (HEALTHY, UNHEALTHY)
57
58 STATUS_FAILED = (UNHEALTHY)
59
60 def __init__(self):
61 super(ClusterHealthStatus, self).__init__(
62 valid_values=ClusterHealthStatus.ALL)
63
64
52class FederationStatus(fields.Enum): 65class FederationStatus(fields.Enum):
53 CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS' 66 CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
54 CREATE_FAILED = 'CREATE_FAILED' 67 CREATE_FAILED = 'CREATE_FAILED'
@@ -150,6 +163,10 @@ class ClusterStatusField(fields.BaseEnumField):
150 AUTO_TYPE = ClusterStatus() 163 AUTO_TYPE = ClusterStatus()
151 164
152 165
166class ClusterHealthStatusField(fields.BaseEnumField):
167 AUTO_TYPE = ClusterHealthStatus()
168
169
153class MagnumServiceField(fields.BaseEnumField): 170class MagnumServiceField(fields.BaseEnumField):
154 AUTO_TYPE = MagnumServiceState() 171 AUTO_TYPE = MagnumServiceState()
155 172
diff --git a/magnum/tests/unit/objects/test_cluster.py b/magnum/tests/unit/objects/test_cluster.py
index 698c138..c8deed7 100644
--- a/magnum/tests/unit/objects/test_cluster.py
+++ b/magnum/tests/unit/objects/test_cluster.py
@@ -40,6 +40,8 @@ class TestClusterObject(base.DbTestCase):
40 self.fake_cluster['keypair'] = 'keypair1' 40 self.fake_cluster['keypair'] = 'keypair1'
41 self.fake_cluster['docker_volume_size'] = 3 41 self.fake_cluster['docker_volume_size'] = 3
42 self.fake_cluster['labels'] = {} 42 self.fake_cluster['labels'] = {}
43 self.fake_cluster['health_status'] = 'HEALTHY'
44 self.fake_cluster['health_status_reason'] = {}
43 45
44 @mock.patch('magnum.objects.ClusterTemplate.get_by_uuid') 46 @mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
45 def test_get_by_id(self, mock_cluster_template_get): 47 def test_get_by_id(self, mock_cluster_template_get):
diff --git a/magnum/tests/unit/objects/test_fields.py b/magnum/tests/unit/objects/test_fields.py
index 89b7f1e..836c959 100644
--- a/magnum/tests/unit/objects/test_fields.py
+++ b/magnum/tests/unit/objects/test_fields.py
@@ -50,6 +50,25 @@ class TestClusterStatus(test_fields.TestField):
50 self.assertRaises(ValueError, self.field.stringify, 'DELETE_STOPPED') 50 self.assertRaises(ValueError, self.field.stringify, 'DELETE_STOPPED')
51 51
52 52
53class TestClusterHealthStatus(test_fields.TestField):
54 def setUp(self):
55 super(TestClusterHealthStatus, self).setUp()
56 self.field = fields.ClusterHealthStatusField()
57 self.coerce_good_values = [('HEALTHY', 'HEALTHY'),
58 ('UNHEALTHY', 'UNHEALTHY')]
59 self.coerce_bad_values = ['FAKE']
60
61 self.to_primitive_values = self.coerce_good_values[0:1]
62 self.from_primitive_values = self.coerce_good_values[0:1]
63
64 def test_stringify(self):
65 self.assertEqual("'UNHEALTHY'",
66 self.field.stringify('UNHEALTHY'))
67
68 def test_stringify_invalid(self):
69 self.assertRaises(ValueError, self.field.stringify, 'FAKE')
70
71
53class TestContainerStatus(test_fields.TestField): 72class TestContainerStatus(test_fields.TestField):
54 def setUp(self): 73 def setUp(self):
55 super(TestContainerStatus, self).setUp() 74 super(TestContainerStatus, self).setUp()
diff --git a/magnum/tests/unit/objects/test_objects.py b/magnum/tests/unit/objects/test_objects.py
index 03444a6..e6e0914 100644
--- a/magnum/tests/unit/objects/test_objects.py
+++ b/magnum/tests/unit/objects/test_objects.py
@@ -355,7 +355,7 @@ class TestObject(test_base.TestCase, _TestObject):
355# For more information on object version testing, read 355# For more information on object version testing, read
356# https://docs.openstack.org/magnum/latest/contributor/objects.html 356# https://docs.openstack.org/magnum/latest/contributor/objects.html
357object_data = { 357object_data = {
358 'Cluster': '1.17-c32c07425ab0042c7370bef2902b4d21', 358 'Cluster': '1.18-9f0dfcc3e898eef2b9a09647b612adb6',
359 'ClusterTemplate': '1.18-7fa94f4fdd027acfb4f022f202afdfb5', 359 'ClusterTemplate': '1.18-7fa94f4fdd027acfb4f022f202afdfb5',
360 'Certificate': '1.1-1924dc077daa844f0f9076332ef96815', 360 'Certificate': '1.1-1924dc077daa844f0f9076332ef96815',
361 'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd', 361 'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',