Browse Source

Merge "Add health_status and health_status_reason to cluster"

tags/8.0.0.0rc1
Zuul 8 months ago
parent
commit
b881ecd512

+ 8
- 0
magnum/api/controllers/v1/cluster.py View File

@@ -134,6 +134,12 @@ class Cluster(base.APIBase):
134 134
     status_reason = wtypes.text
135 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 143
     discovery_url = wtypes.text
138 144
     """Url used for cluster node discovery"""
139 145
 
@@ -211,6 +217,8 @@ class Cluster(base.APIBase):
211 217
                      stack_id='49dc23f5-ffc9-40c3-9d34-7be7f9e34d63',
212 218
                      status=fields.ClusterStatus.CREATE_COMPLETE,
213 219
                      status_reason="CREATE completed successfully",
220
+                     health_status=fields.ClusterHealthStatus.HEALTHY,
221
+                     health_status_reason='{"api_server": "OK"}',
214 222
                      api_address='172.24.4.3',
215 223
                      node_addresses=['172.24.4.4', '172.24.4.5'],
216 224
                      created_at=timeutils.utcnow(),

+ 38
- 0
magnum/db/sqlalchemy/alembic/versions/cbbc65a86986_add_health_status_to_cluster.py View File

@@ -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
+
16
+Revision ID: cbbc65a86986
17
+Revises: 9a1539f1cd2c
18
+Create Date: 2018-05-15 22:24:49.527558
19
+
20
+"""
21
+
22
+# revision identifiers, used by Alembic.
23
+revision = 'cbbc65a86986'
24
+down_revision = '9a1539f1cd2c'
25
+
26
+from alembic import op
27
+import sqlalchemy as sa
28
+
29
+
30
+def 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 ###

+ 2
- 0
magnum/db/sqlalchemy/models.py View File

@@ -128,6 +128,8 @@ class Cluster(Base):
128 128
     master_count = Column(Integer())
129 129
     status = Column(String(20))
130 130
     status_reason = Column(Text)
131
+    health_status = Column(String(20))
132
+    health_status_reason = Column(JSONEncodedDict)
131 133
     create_timeout = Column(Integer())
132 134
     discovery_url = Column(String(255, mysql_ndb_type=TINYTEXT))
133 135
     master_addresses = Column(JSONEncodedList)

+ 4
- 1
magnum/objects/cluster.py View File

@@ -46,8 +46,9 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
46 46
     # Version 1.15: Added 'labels' field
47 47
     # Version 1.16: Added 'master_flavor_id' field
48 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 53
     dbapi = dbapi.get_instance()
53 54
 
@@ -66,6 +67,8 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
66 67
         'stack_id': fields.StringField(nullable=True),
67 68
         'status': m_fields.ClusterStatusField(nullable=True),
68 69
         'status_reason': fields.StringField(nullable=True),
70
+        'health_status': m_fields.ClusterHealthStatusField(nullable=True),
71
+        'health_status_reason': fields.DictOfStringsField(nullable=True),
69 72
         'create_timeout': fields.IntegerField(nullable=True),
70 73
         'api_address': fields.StringField(nullable=True),
71 74
         'node_addresses': fields.ListOfStringsField(nullable=True),

+ 17
- 0
magnum/objects/fields.py View File

@@ -49,6 +49,19 @@ class ClusterStatus(fields.Enum):
49 49
         super(ClusterStatus, self).__init__(valid_values=ClusterStatus.ALL)
50 50
 
51 51
 
52
+class 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
+
52 65
 class FederationStatus(fields.Enum):
53 66
     CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
54 67
     CREATE_FAILED = 'CREATE_FAILED'
@@ -150,6 +163,10 @@ class ClusterStatusField(fields.BaseEnumField):
150 163
     AUTO_TYPE = ClusterStatus()
151 164
 
152 165
 
166
+class ClusterHealthStatusField(fields.BaseEnumField):
167
+    AUTO_TYPE = ClusterHealthStatus()
168
+
169
+
153 170
 class MagnumServiceField(fields.BaseEnumField):
154 171
     AUTO_TYPE = MagnumServiceState()
155 172
 

+ 2
- 0
magnum/tests/unit/objects/test_cluster.py View File

@@ -40,6 +40,8 @@ class TestClusterObject(base.DbTestCase):
40 40
         self.fake_cluster['keypair'] = 'keypair1'
41 41
         self.fake_cluster['docker_volume_size'] = 3
42 42
         self.fake_cluster['labels'] = {}
43
+        self.fake_cluster['health_status'] = 'HEALTHY'
44
+        self.fake_cluster['health_status_reason'] = {}
43 45
 
44 46
     @mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
45 47
     def test_get_by_id(self, mock_cluster_template_get):

+ 19
- 0
magnum/tests/unit/objects/test_fields.py View File

@@ -50,6 +50,25 @@ class TestClusterStatus(test_fields.TestField):
50 50
         self.assertRaises(ValueError, self.field.stringify, 'DELETE_STOPPED')
51 51
 
52 52
 
53
+class 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
+
53 72
 class TestContainerStatus(test_fields.TestField):
54 73
     def setUp(self):
55 74
         super(TestContainerStatus, self).setUp()

+ 1
- 1
magnum/tests/unit/objects/test_objects.py View File

@@ -355,7 +355,7 @@ class TestObject(test_base.TestCase, _TestObject):
355 355
 # For more information on object version testing, read
356 356
 # https://docs.openstack.org/magnum/latest/contributor/objects.html
357 357
 object_data = {
358
-    'Cluster': '1.17-c32c07425ab0042c7370bef2902b4d21',
358
+    'Cluster': '1.18-9f0dfcc3e898eef2b9a09647b612adb6',
359 359
     'ClusterTemplate': '1.18-7fa94f4fdd027acfb4f022f202afdfb5',
360 360
     'Certificate': '1.1-1924dc077daa844f0f9076332ef96815',
361 361
     'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',

Loading…
Cancel
Save