예제 #1
0
 def test_init(self):
     with mock.patch.object(service, 'run_status_reporter') as rsr:
         service.register_service('test_binary', self.nb_api)
         self.nb_api.create.assert_called_once_with(service_model.Service(
             chassis=cfg.CONF.host, binary='test_binary'),
                                                    skip_send_event=True)
         rsr.assert_called_once()
예제 #2
0
def register_service(service_name, nb_api, instance=None):
    if instance:
        service_names[id(instance)] = service_name
    chassis_id = cfg.CONF.host
    nb_api.create(service.Service(chassis=chassis_id, binary=service_name),
                  skip_send_event=True)
    callback = functools.partial(service.Service.update_last_seen, nb_api,
                                 chassis_id, service_name)
    run_status_reporter(callback)
예제 #3
0
 def test_alive(self):
     s = service_model.Service(chassis='test_host1', binary='test_binary')
     timeout = cfg.CONF.df.service_down_time
     s.last_seen_up = 3 * timeout
     with mock.patch.object(time, 'time') as t:
         t.return_value = 3.5 * timeout
         self.assertTrue(s.alive)
         t.return_value = 5 * timeout
         self.assertFalse(s.alive)
예제 #4
0
def register_service(service_name, nb_api):
    chassis_id = cfg.CONF.host
    #创建此service在nb中的记录,跳过事件发送
    nb_api.create(service.Service(chassis=chassis_id, binary=service_name),
                  skip_send_event=True)
    #构造周期性report回调,并启动reporter(实际上就是周期性的触发nb的update event)
    callback = functools.partial(service.Service.update_last_seen, nb_api,
                                 chassis_id, service_name)
    run_status_reporter(callback)
예제 #5
0
 def test_update_last_seen(self):
     s = service_model.Service(chassis='test_host1', binary='test_binary')
     self.nb_api.get.return_value = s
     now = time.time()
     service_model.Service.update_last_seen(self.nb_api, 'test_host1',
                                            'test_binary')
     self.nb_api.update.assert_called_once()
     update_call_args = self.nb_api.update.call_args_list[0]
     updated_service = update_call_args[0][0]
     self.assertLessEqual(now, updated_service.last_seen_up)
     self.assertTrue(update_call_args[1]['skip_send_event'])
예제 #6
0
 def test_on_create_pre(self):
     """
     Verify that the id exists after on_create_pre, and that it is not
     random.
     """
     s = service_model.Service(chassis='test_host1', binary='test_binary')
     self.assertRaises(errors.ValidationError, lambda: s.id)
     s.on_create_pre()
     expected_uuid = str(
         uuid.uuid5(service_model.SERVICE_ID_NAMESPACE,
                    'test_host1test_binary'))
     self.assertEqual(expected_uuid, s.id)
예제 #7
0
 def test_refresh_last_seen(self):
     s = service_model.Service(chassis='test_host1', binary='test_binary')
     self.assertIsNone(s.last_seen_up)
     now = time.time()
     s.refresh_last_seen()
     self.assertLessEqual(now, s.last_seen_up)