Merge "Adding "health verification --show" CLI call"

This commit is contained in:
Jenkins
2016-02-29 10:40:59 +00:00
committed by Gerrit Code Review
2 changed files with 116 additions and 24 deletions

View File

@@ -45,14 +45,15 @@ def _format_cluster_output(data):
def _prepare_health_checks(data):
additional_data = {}
ver = data.get('verification', {})
additional_fields = ['verification_status']
data['verification_status'] = ver.get('status', 'UNKNOWN')
additional_data['verification_status'] = ver.get('status', 'UNKNOWN')
for check in ver.get('checks', []):
row_name = "Health check (%s)" % check['name']
data[row_name] = check['status']
additional_data[row_name] = check['status']
additional_fields.append(row_name)
return data, additional_fields
return additional_data, additional_fields
def _get_plugin_version(cluster_template, client):
@@ -323,7 +324,8 @@ class ShowCluster(show.ShowOne):
_format_cluster_output(data)
fields = []
if parsed_args.verification:
data, fields = _prepare_health_checks(data)
ver_data, fields = _prepare_health_checks(data)
data.update(ver_data)
fields.extend(CLUSTER_FIELDS)
data = utils.prepare_data(data, fields)
@@ -581,12 +583,18 @@ class VerificationUpdateCluster(show.ShowOne):
metavar="<cluster>",
help="Name or ID of the cluster",
)
status = parser.add_mutually_exclusive_group()
status = parser.add_mutually_exclusive_group(required=True)
status.add_argument(
'--start',
action='store_true',
help='Start the cluster verification',
dest='is_start'
action='store_const',
const='START',
help='Start health verification for the cluster',
dest='status'
)
status.add_argument(
'--show',
help='Show health of the cluster',
action='store_true'
)
return parser
@@ -594,20 +602,22 @@ class VerificationUpdateCluster(show.ShowOne):
self.log.debug("take_action(%s)" % parsed_args)
client = self.app.client_manager.data_processing
cluster_id = utils.get_resource_id(
client.clusters, parsed_args.cluster)
if parsed_args.is_start:
status = 'START'
if parsed_args.show:
data = utils.get_resource(
client.clusters, parsed_args.cluster).to_dict()
ver_data, ver_fields = _prepare_health_checks(data)
data = utils.prepare_data(ver_data, ver_fields)
return self.dict2columns(data)
else:
raise exceptions.CommandError("--start should be provided")
data = client.clusters.verification_update(
cluster_id, status).cluster
cluster_id = utils.get_resource_id(
client.clusters, parsed_args.cluster)
client.clusters.verification_update(
cluster_id, parsed_args.status)
if parsed_args.status == 'START':
print_status = 'started'
sys.stdout.write(
'Cluster "{cluster}" health verification has been '
'{status}.'.format(cluster=parsed_args.cluster,
status=print_status))
data, fields = _prepare_health_checks(data)
fields.extend(CLUSTER_FIELDS)
_format_cluster_output(data)
data = utils.prepare_data(data, fields)
return self.dict2columns(data)
return {}, {}

View File

@@ -50,7 +50,18 @@ CLUSTER_INFO = {
"neutron_management_network": "net_id",
"user_keypair_id": "test",
"status": 'Active',
"default_image_id": "img_id"
"default_image_id": "img_id",
'verification': {
'status': 'GREEN',
'id': 'ver_id',
'cluster_id': 'cluster_id',
'checks': [
{
'status': 'GREEN',
'name': 'Some check'
}
]
}
}
CT_INFO = {
@@ -287,6 +298,34 @@ class TestShowCluster(TestClusters):
'0.1')
self.assertEqual(expected_data, data)
def test_cluster_show_verification(self):
arglist = ['fake', '--verification']
verifylist = [('cluster', 'fake'), ('verification', True)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Check that correct arguments were passed
self.cl_mock.find_unique.assert_called_once_with(name='fake')
# Check that columns are correct
expected_columns = ('Anti affinity', 'Cluster template id',
'Description', 'Health check (some check)', 'Id',
'Image', 'Is protected', 'Is public', 'Name',
'Neutron management network', 'Node groups',
'Plugin name', 'Status', 'Use autoconfig',
'User keypair id', 'Verification status',
'Version')
self.assertEqual(expected_columns, columns)
# Check that data is correct
expected_data = ('', 'ct_id', 'Cluster template for tests', 'GREEN',
'cluster_id', 'img_id', False, False, 'fake',
'net_id', 'fakeng:2', 'fake', 'Active', True, 'test',
'GREEN', '0.1')
self.assertEqual(expected_data, data)
class TestDeleteCluster(TestClusters):
def setUp(self):
@@ -464,3 +503,46 @@ class TestScaleCluster(TestClusters):
'node_group_template_id': 'new_id',
'name': 'new'}
]})
class TestVerificationUpdateCluster(TestClusters):
def setUp(self):
super(TestVerificationUpdateCluster, self).setUp()
self.cl_mock.find_unique.return_value = api_cl.Cluster(
None, CLUSTER_INFO)
self.cl_mock.verification_update.return_value = api_cl.Cluster(
None, CLUSTER_INFO)
# Command to test
self.cmd = osc_cl.VerificationUpdateCluster(self.app, None)
def test_verification_show(self):
arglist = ['fake', '--show']
verifylist = [('cluster', 'fake'), ('show', True)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Check that correct arguments were passed
self.cl_mock.find_unique.assert_called_once_with(name='fake')
# Check that columns are correct
expected_columns = ('Health check (some check)', 'Verification status')
self.assertEqual(expected_columns, columns)
# Check that data is correct
expected_data = ('GREEN', 'GREEN')
self.assertEqual(expected_data, data)
def test_verification_start(self):
arglist = ['fake', '--start']
verifylist = [('cluster', 'fake'), ('status', 'START')]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
# Check that correct arguments were passed
self.cl_mock.verification_update.assert_called_once_with(
'cluster_id', 'START')