Add exceptions to cluster db to show failures
After changing create to async operation, all the exceptions goes hidden and no db entry is created to show the actual failure. One has to go through the logs to find the actual error. This patch creates a db entry in cluster table to show the actual error in column 'status_reason'. Change-Id: Iad6e8bfce7326b34dea04914e4552f87d2796e86 Closes-bug: #1623387
This commit is contained in:
parent
e8dc23c42e
commit
9f7295475d
|
@ -164,9 +164,9 @@ class Handler(object):
|
|||
created_stack = _create_stack(context, osc, cluster,
|
||||
create_timeout)
|
||||
except Exception as e:
|
||||
cert_manager.delete_certificates_from_cluster(cluster,
|
||||
context=context)
|
||||
trust_manager.delete_trustee_and_trust(osc, context, cluster)
|
||||
cluster.status = fields.ClusterStatus.CREATE_FAILED
|
||||
cluster.status_reason = six.text_type(e)
|
||||
cluster.create()
|
||||
conductor_utils.notify_about_cluster_operation(
|
||||
context, taxonomy.ACTION_CREATE, taxonomy.OUTCOME_FAILURE)
|
||||
|
||||
|
|
|
@ -232,6 +232,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager,
|
||||
mock_cluster_create,
|
||||
expected_exception,
|
||||
is_create_cert_called=True,
|
||||
is_create_trust_called=True):
|
||||
|
@ -256,11 +257,9 @@ class TestHandler(db_base.DbTestCase):
|
|||
ctat.assert_called_once_with(osc, self.cluster)
|
||||
else:
|
||||
ctat.assert_not_called()
|
||||
mock_cluster_create.assert_called_once_with()
|
||||
|
||||
mock_cert_manager.delete_certificates_from_cluster(self.cluster)
|
||||
mock_trust_manager.delete_trustee_and_trust.assert_called_once_with(
|
||||
osc, self.context, self.cluster)
|
||||
|
||||
@patch('magnum.objects.Cluster.create')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.trust_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor._create_stack')
|
||||
|
@ -268,13 +267,15 @@ class TestHandler(db_base.DbTestCase):
|
|||
def test_create_handles_bad_request(self, mock_openstack_client_class,
|
||||
mock_create_stack,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager):
|
||||
mock_trust_manager,
|
||||
mock_cluster_create):
|
||||
mock_create_stack.side_effect = exc.HTTPBadRequest
|
||||
|
||||
self._test_create_failed(
|
||||
mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager,
|
||||
mock_cluster_create,
|
||||
exception.InvalidParameterValue
|
||||
)
|
||||
|
||||
|
@ -289,12 +290,14 @@ class TestHandler(db_base.DbTestCase):
|
|||
self.assertEqual(
|
||||
taxonomy.OUTCOME_FAILURE, notifications[1].payload['outcome'])
|
||||
|
||||
@patch('magnum.objects.Cluster.create')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.trust_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
|
||||
@patch('magnum.common.clients.OpenStackClients')
|
||||
def test_create_with_cert_failed(self, mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager):
|
||||
mock_trust_manager,
|
||||
mock_cluster_create):
|
||||
e = exception.CertificatesToClusterFailed(cluster_uuid='uuid')
|
||||
mock_cert_manager.generate_certificates_to_cluster.side_effect = e
|
||||
|
||||
|
@ -302,6 +305,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager,
|
||||
mock_cluster_create,
|
||||
exception.CertificatesToClusterFailed
|
||||
)
|
||||
|
||||
|
@ -312,6 +316,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
self.assertEqual(
|
||||
taxonomy.OUTCOME_FAILURE, notifications[0].payload['outcome'])
|
||||
|
||||
@patch('magnum.objects.Cluster.create')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.trust_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor._create_stack')
|
||||
|
@ -319,7 +324,8 @@ class TestHandler(db_base.DbTestCase):
|
|||
def test_create_with_trust_failed(self, mock_openstack_client_class,
|
||||
mock_create_stack,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager):
|
||||
mock_trust_manager,
|
||||
mock_cluster_create):
|
||||
e = exception.TrusteeOrTrustToClusterFailed(cluster_uuid='uuid')
|
||||
mock_trust_manager.create_trustee_and_trust.side_effect = e
|
||||
|
||||
|
@ -327,6 +333,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager,
|
||||
mock_cluster_create,
|
||||
exception.TrusteeOrTrustToClusterFailed,
|
||||
False
|
||||
)
|
||||
|
@ -338,6 +345,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
self.assertEqual(
|
||||
taxonomy.OUTCOME_FAILURE, notifications[0].payload['outcome'])
|
||||
|
||||
@patch('magnum.objects.Cluster.create')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.trust_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
|
||||
@patch('magnum.conductor.handlers.cluster_conductor._create_stack')
|
||||
|
@ -346,7 +354,8 @@ class TestHandler(db_base.DbTestCase):
|
|||
mock_openstack_client_class,
|
||||
mock_create_stack,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager):
|
||||
mock_trust_manager,
|
||||
mock_cluster_create):
|
||||
error_message = six.u("""Invalid stack name 测试集群-zoyh253geukk
|
||||
must contain only alphanumeric or "_-."
|
||||
characters, must start with alpha""")
|
||||
|
@ -356,6 +365,7 @@ class TestHandler(db_base.DbTestCase):
|
|||
mock_openstack_client_class,
|
||||
mock_cert_manager,
|
||||
mock_trust_manager,
|
||||
mock_cluster_create,
|
||||
exception.InvalidParameterValue
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue