def test_list_zun_services(self, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound service_1 = utils.create_test_zun_service(host='host_1') service_2 = utils.create_test_zun_service(host='host_2') mock_read.side_effect = lambda *args: FakeEtcdMultipleResult( [service_1.as_dict(), service_2.as_dict()]) res = dbapi.list_zun_services(self.context) self.assertEqual(2, len(res)) self.assertEqual('host_1', res[0].host) self.assertEqual('host_2', res[1].host)
def test_destroy_zun_service(self): ms = utils.create_test_zun_service() res = self.dbapi.get_zun_service('fakehost', 'fake-bin') self.assertEqual(res['id'], ms['id']) self.dbapi.destroy_zun_service(ms['host'], ms['binary']) res = self.dbapi.get_zun_service('fakehost', 'fake-bin') self.assertIsNone(res)
def test_list_zun_services_by_binary(self, mock_ins, mock_write, mock_read): mock_ins.return_value = etcd_api.get_backend() mock_read.side_effect = etcd.EtcdKeyNotFound service_1 = utils.create_test_zun_service(host='host_1', binary='binary_1') service_2 = utils.create_test_zun_service(host='host_2', binary='binary_2') mock_read.side_effect = lambda *args: FakeEtcdMultipleResult( [service_1.as_dict(), service_2.as_dict()]) res = dbapi.list_zun_services_by_binary(self.context, 'binary_1') self.assertEqual(1, len(res)) self.assertEqual('host_1', res[0].host) self.assertEqual('binary_1', res[0].binary) res = dbapi.list_zun_services_by_binary(self.context, 'fake-binary') self.assertEqual(0, len(res))
def test_list_zun_services_by_binary(self): fake_ms_params = { 'report_count': 1010, 'host': 'FakeHost', 'binary': 'FakeBin', 'disabled': False, 'disabled_reason': 'FakeReason' } utils.create_test_zun_service(**fake_ms_params) res = self.dbapi.list_zun_services_by_binary( binary=fake_ms_params['binary']) self.assertEqual(1, len(res)) res = res[0] for k, v in fake_ms_params.items(): self.assertEqual(res[k], v) res = self.dbapi.list_zun_services_by_binary(binary='none') self.assertEqual(0, len(res))
def test_destroy_zun_service(self): ms = utils.create_test_zun_service() res = self.dbapi.get_zun_service( 'fakehost', 'fake-bin') self.assertEqual(res['id'], ms['id']) self.dbapi.destroy_zun_service(ms['host'], ms['binary']) res = self.dbapi.get_zun_service( 'fakehost', 'fake-bin') self.assertIsNone(res)
def test_destroy_zun_service(self, mock_delete, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound zun_service = utils.create_test_zun_service() mock_read.side_effect = lambda *args: FakeEtcdResult(zun_service. as_dict()) dbapi.destroy_zun_service(zun_service.host, zun_service.binary) mock_delete.assert_called_once_with('/zun_services/%s' % zun_service.host + '_' + zun_service.binary)
def test_get_zun_service(self, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound zun_service = utils.create_test_zun_service() mock_read.side_effect = lambda *args: FakeEtcdResult(zun_service. as_dict()) res = dbapi.get_zun_service(self.context, zun_service.host, zun_service.binary) self.assertEqual(zun_service.host, res.host) self.assertEqual(zun_service.binary, res.binary)
def test_update_zun_service(self): ms = utils.create_test_zun_service() d2 = True update = {'disabled': d2} ms1 = self.dbapi.update_zun_service(ms['host'], ms['binary'], update) self.assertEqual(ms['id'], ms1['id']) self.assertEqual(d2, ms1['disabled']) res = self.dbapi.get_zun_service('fakehost', 'fake-bin') self.assertEqual(ms1['id'], res['id']) self.assertEqual(d2, res['disabled'])
def test_update_zun_service(self, mock_update, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound service = utils.create_test_zun_service() new_host = 'new-host' mock_read.side_effect = lambda *args: FakeEtcdResult(service.as_dict()) dbapi.update_zun_service(service.host, service.binary, {'host': new_host}) self.assertEqual( new_host, json.loads(mock_update.call_args_list[0][0][0].value)['host'])
def test_update_zun_service(self): ms = utils.create_test_zun_service() d2 = True update = {'disabled': d2} ms1 = self.dbapi.update_zun_service(ms['host'], ms['binary'], update) self.assertEqual(ms['id'], ms1['id']) self.assertEqual(d2, ms1['disabled']) res = self.dbapi.get_zun_service( 'fakehost', 'fake-bin') self.assertEqual(ms1['id'], res['id']) self.assertEqual(d2, res['disabled'])
def test_list_zun_services(self): fake_ms_params = { 'report_count': 1010, 'host': 'FakeHost', 'binary': 'FakeBin', 'disabled': False, 'disabled_reason': 'FakeReason' } utils.create_test_zun_service(**fake_ms_params) res = self.dbapi.list_zun_services() self.assertEqual(1, len(res)) res = res[0] for k, v in fake_ms_params.items(): self.assertEqual(res[k], v) fake_ms_params['binary'] = 'FakeBin1' fake_ms_params['disabled'] = True utils.create_test_zun_service(**fake_ms_params) res = self.dbapi.list_zun_services(filters={'disabled': True}) self.assertEqual(1, len(res)) res = res[0] for k, v in fake_ms_params.items(): self.assertEqual(res[k], v)
def test_get_zun_service_failure(self): utils.create_test_zun_service() res = self.dbapi.get_zun_service('fakehost1', 'fake-bin1') self.assertIsNone(res)
def test_get_zun_service(self): ms = utils.create_test_zun_service() res = self.dbapi.get_zun_service(ms['host'], ms['binary']) self.assertEqual(ms.id, res.id)
def test_create_zun_service_failure_for_dup(self): utils.create_test_zun_service() self.assertRaises(exception.ZunServiceAlreadyExists, utils.create_test_zun_service)
def test_create_zun_service(self): utils.create_test_zun_service()
def test_get_zun_service(self): ms = utils.create_test_zun_service() res = self.dbapi.get_zun_service( ms['host'], ms['binary']) self.assertEqual(ms.id, res.id)
def test_get_zun_service_failure(self): utils.create_test_zun_service() res = self.dbapi.get_zun_service( 'fakehost1', 'fake-bin1') self.assertIsNone(res)
def test_create_zun_service_already_exists(self, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound utils.create_test_zun_service() mock_read.side_effect = lambda *args: None self.assertRaises(exception.ResourceExists, utils.create_test_zun_service)
def test_create_zun_service(self, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound utils.create_test_zun_service()
def test_get_zun_service_not_found(self, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound zun_service = utils.create_test_zun_service() res = dbapi.get_zun_service(self.context, 'wrong_host_name', zun_service.binary) self.assertIsNone(res)