agent_state['uuid'] = uuidutils.generate_uuid()
kwargs = {
'agent_state': {'agent_state': agent_state},
- 'time': datetime.utcnow().isoformat(),
+ 'time': datetime.utcnow().strftime(constants.ISO8601_TIME_FORMAT),
}
method = cctxt.call if use_call else cctxt.cast
return method(context, 'report_state', **kwargs)
# License for the specific language governing permissions and limitations
# under the License.
+import datetime
import mock
from oslo_context import context as oslo_context
import oslo_messaging
{'agent_state': expected_agent_state})
self.assertIsInstance(mock_cast.call_args[1]['time'], str)
+ def test_plugin_report_state_microsecond_is_0(self):
+ topic = 'test'
+ expected_time = datetime.datetime(2015, 7, 27, 15, 33, 30, 0)
+ expected_time_str = '2015-07-27T15:33:30.000000'
+ expected_agent_state = {'agent': 'test'}
+ with mock.patch('neutron.agent.rpc.datetime') as mock_datetime:
+ reportStateAPI = rpc.PluginReportStateAPI(topic)
+ mock_datetime.utcnow.return_value = expected_time
+ with mock.patch.object(reportStateAPI.client, 'call'), \
+ mock.patch.object(reportStateAPI.client, 'cast'
+ ) as mock_cast, \
+ mock.patch.object(reportStateAPI.client, 'prepare'
+ ) as mock_prepare:
+ mock_prepare.return_value = reportStateAPI.client
+ ctxt = oslo_context.RequestContext('fake_user',
+ 'fake_project')
+ reportStateAPI.report_state(ctxt, expected_agent_state)
+ self.assertEqual(expected_time_str,
+ mock_cast.call_args[1]['time'])
+
class AgentRPCMethods(base.BaseTestCase):
lbaas_hostb = copy.deepcopy(lbaas_hosta)
lbaas_hostb['host'] = LBAAS_HOSTB
callback = agents_db.AgentExtRpcCallback()
- callback.report_state(self.adminContext,
- agent_state={'agent_state': lbaas_hosta},
- time=datetime.utcnow().isoformat())
- callback.report_state(self.adminContext,
- agent_state={'agent_state': lbaas_hostb},
- time=datetime.utcnow().isoformat())
+ callback.report_state(
+ self.adminContext,
+ agent_state={'agent_state': lbaas_hosta},
+ time=datetime.utcnow().strftime(constants.ISO8601_TIME_FORMAT))
+ callback.report_state(
+ self.adminContext,
+ agent_state={'agent_state': lbaas_hostb},
+ time=datetime.utcnow().strftime(constants.ISO8601_TIME_FORMAT))
res += [lbaas_hosta, lbaas_hostb]
return res