'Test interaction between update and get_pools
This test verifies that each time that get_pools is called it gets the
latest copy of service_capabilities, which is timestamped with the
current date/time.'

@mock.patch('cinder.db.service_get_all')
@mock.patch('cinder.objects.service.Service.is_up', new_callable=mock.PropertyMock)
@mock.patch('oslo_utils.timeutils.utcnow')
def test_update_and_get_pools(self, _mock_utcnow, _mock_service_is_up, _mock_service_get_all):

    context = 'fake_context'
    dates = [datetime.fromtimestamp(400), datetime.fromtimestamp(401), datetime.fromtimestamp(402)]
    _mock_utcnow.side_effect = dates
    services = [dict(id=1, host='host1', topic='volume', disabled=False, availability_zone='zone1', updated_at=timeutils.utcnow())]
    mocked_service_states = {'host1': dict(volume_backend_name='AAA', total_capacity_gb=512, free_capacity_gb=200, timestamp=dates[1], reserved_percentage=0)}
    _mock_service_get_all.return_value = services
    _mock_service_is_up.return_value = True
    _mock_warning = mock.Mock()
    host_manager.LOG.warn = _mock_warning
    host_volume_capabs = dict(free_capacity_gb=4321)
    service_name = 'volume'
    with mock.patch.dict(self.host_manager.service_states, mocked_service_states):
        self.host_manager.update_service_capabilities(service_name, 'host1', host_volume_capabs, None, None)
        res = self.host_manager.get_pools(context)
        self.assertEqual(1, len(res))
        self.assertEqual(dates[1], res[0]['capabilities']['timestamp'])
