active = 'disabled'
LOG.debug('status, active and update: %s, %s, %s',
status, active, host.updated_at)
+ updated_at = host.updated_at
+ if updated_at:
+ updated_at = timeutils.normalize_time(updated_at)
hosts.append({'host_name': host.host,
'service': host.topic,
'zone': host.availability_zone,
'service-status': status,
'service-state': active,
- 'last-update': timeutils.normalize_time(host.updated_at),
+ 'last-update': updated_at,
})
if service:
hosts = [host for host in hosts
active = 'enabled'
if svc.disabled:
active = 'disabled'
+ if updated_at:
+ updated_at = timeutils.normalize_time(updated_at)
ret_fields = {'binary': svc.binary, 'host': svc.host,
'zone': svc.availability_zone,
'status': active, 'state': art,
- 'updated_at': timeutils.normalize_time(updated_at)}
+ 'updated_at': updated_at}
if detailed:
ret_fields['disabled_reason'] = svc.disabled_reason
svcs.append(ret_fields)
status = 'enabled'
if svc.disabled:
status = 'disabled'
+ updated_at = svc.updated_at
+ if updated_at:
+ updated_at = timeutils.normalize_time(updated_at)
print(print_format % (svc.binary, svc.host.partition('.')[0],
svc.availability_zone, status, art,
- timeutils.normalize_time(svc.updated_at)))
+ updated_at))
@args('binary', type=str,
help='Service to delete from the host.')
'availability_zone': 'cinder'},
{'created_at': created_time, 'updated_at': curr_time,
'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
- 'availability_zone': 'cinder'}]
+ 'availability_zone': 'cinder'},
+ {'created_at': created_time, 'updated_at': None,
+ 'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
+ 'availability_zone': 'cinder'},
+]
LIST_RESPONSE = [{'service-status': 'available', 'service': 'cinder-volume',
'zone': 'cinder', 'service-state': 'enabled',
'host_name': 'test.host.1', 'last-update': curr_time},
{'service-status': 'available', 'service': 'cinder-volume',
'zone': 'cinder', 'service-state': 'enabled',
- 'host_name': 'test.host.1', 'last-update': curr_time}]
+ 'host_name': 'test.host.1', 'last-update': curr_time},
+ {'service-status': 'unavailable', 'service': 'cinder-volume',
+ 'zone': 'cinder', 'service-state': 'enabled',
+ 'host_name': 'test.host.1', 'last-update': None},
+ ]
def stub_utcnow(with_timezone=False):
'created_at': datetime.datetime(2012, 9, 18, 2, 46, 28),
'disabled_reason': '',
'modified_at': datetime.datetime(2012, 9, 18, 8, 1, 38)},
+ {'binary': 'cinder-scheduler',
+ 'host': 'host2',
+ 'availability_zone': 'cinder',
+ 'id': 6,
+ 'disabled': False,
+ 'updated_at': None,
+ 'created_at': datetime.datetime(2012, 9, 18, 2, 46, 28),
+ 'disabled_reason': '',
+ 'modified_at': None},
]
'zone': 'cinder',
'status': 'enabled', 'state': 'down',
'updated_at': datetime.datetime(
- 2012, 9, 18, 8, 3, 38)}]}
+ 2012, 9, 18, 8, 3, 38)},
+ {'binary': 'cinder-scheduler',
+ 'host': 'host2',
+ 'zone': 'cinder',
+ 'status': 'enabled', 'state': 'down',
+ 'updated_at': None},
+ ]}
self.assertEqual(response, res_dict)
def test_services_detail(self):
'status': 'enabled', 'state': 'down',
'updated_at': datetime.datetime(
2012, 9, 18, 8, 3, 38),
- 'disabled_reason': ''}]}
+ 'disabled_reason': ''},
+ {'binary': 'cinder-scheduler',
+ 'host': 'host2',
+ 'zone': 'cinder',
+ 'status': 'enabled', 'state': 'down',
+ 'updated_at': None,
+ 'disabled_reason': ''},
+ ]}
self.assertEqual(response, res_dict)
def test_services_list_with_host(self):
@mock.patch('cinder.utils.service_is_up')
@mock.patch('cinder.db.service_get_all')
@mock.patch('cinder.context.get_admin_context')
- def test_service_commands_list(self, get_admin_context, service_get_all,
- service_is_up):
+ def _test_service_commands_list(self, service, get_admin_context,
+ service_get_all, service_is_up):
ctxt = context.RequestContext('fake-user', 'fake-project')
get_admin_context.return_value = ctxt
- service = {'binary': 'cinder-binary',
- 'host': 'fake-host.fake-domain',
- 'availability_zone': 'fake-zone',
- 'updated_at': '2014-06-30 11:22:33',
- 'disabled': False}
service_get_all.return_value = [service]
service_is_up.return_value = True
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
get_admin_context.assert_called_with()
service_get_all.assert_called_with(ctxt, None)
+ def test_service_commands_list(self):
+ service = {'binary': 'cinder-binary',
+ 'host': 'fake-host.fake-domain',
+ 'availability_zone': 'fake-zone',
+ 'updated_at': '2014-06-30 11:22:33',
+ 'disabled': False}
+ self._test_service_commands_list(service)
+
+ def test_service_commands_list_no_updated_at(self):
+ service = {'binary': 'cinder-binary',
+ 'host': 'fake-host.fake-domain',
+ 'availability_zone': 'fake-zone',
+ 'updated_at': None,
+ 'disabled': False}
+ self._test_service_commands_list(service)
+
def test_get_arg_string(self):
args1 = "foobar"
args2 = "-foo bar"