Fix gate problem related to _error_checker() and oslo.log change

Since I84e3be748af10b158037866e1ee4c1375b2c3541, the internal method
_error_checker() is changed and the ceilometer gate is broken.
This patch fixes it.

(cherry picked from commit e6ff08801c)

something changed and expected logs are in stdout rather than stderr
even though it does makes sense as stdout. i have no idea why it
was writing to stderr earlier when it shouldn't have.

Related-Bug: #1635042
(cherry picked from commit 1695b4774e)

Change-Id: I81fe2e60a6fb65e95f477a68267979b8542fa6dc
This commit is contained in:
Ken'ichi Ohmichi 2016-10-21 14:14:25 -07:00 committed by Julien Danjou
parent ae1e1519e2
commit 34b0aff860
2 changed files with 20 additions and 14 deletions

View File

@ -14,6 +14,7 @@
import os
import subprocess
import time
from oslo_utils import fileutils
import six
@ -45,13 +46,13 @@ class BinTestCase(base.BaseTestCase):
subp = subprocess.Popen(['ceilometer-expirer',
'-d',
"--config-file=%s" % self.tempfile],
stderr=subprocess.PIPE)
__, err = subp.communicate()
stdout=subprocess.PIPE)
stdout, __ = subp.communicate()
self.assertEqual(0, subp.poll())
self.assertIn(b"Nothing to clean, database metering "
b"time to live is disabled", err)
b"time to live is disabled", stdout)
self.assertIn(b"Nothing to clean, database event "
b"time to live is disabled", err)
b"time to live is disabled", stdout)
def _test_run_expirer_ttl_enabled(self, ttl_name, data_name):
content = ("[database]\n"
@ -65,13 +66,13 @@ class BinTestCase(base.BaseTestCase):
subp = subprocess.Popen(['ceilometer-expirer',
'-d',
"--config-file=%s" % self.tempfile],
stderr=subprocess.PIPE)
__, err = subp.communicate()
stdout=subprocess.PIPE)
stdout, __ = subp.communicate()
self.assertEqual(0, subp.poll())
msg = "Dropping %s data with TTL 1" % data_name
if six.PY3:
msg = msg.encode('utf-8')
self.assertIn(msg, err)
self.assertIn(msg, stdout)
def test_run_expirer_ttl_enabled(self):
self._test_run_expirer_ttl_enabled('metering_time_to_live',
@ -134,9 +135,16 @@ class BinCeilometerPollingServiceTestCase(base.BaseTestCase):
"compute",
"compute"],
stderr=subprocess.PIPE)
out = self.subp.stderr.read(1024)
self.assertIn(b'Duplicated values: [\'compute\', \'compute\'] '
b'found in CLI options, auto de-duplicated', out)
expected = (b'Duplicated values: [\'compute\', \'compute\'] '
b'found in CLI options, auto de-duplicated')
# NOTE(gordc): polling process won't quit so wait for a bit and check
start = time.time()
while time.time() - start < 5:
output = self.subp.stderr.readline()
if expected in output:
break
else:
self.fail('Did not detect expected warning: %s' % expected)
def test_polling_namespaces_invalid_value_in_config(self):
content = ("[DEFAULT]\n"

View File

@ -109,8 +109,7 @@ class ImagesClient(rest_client.RestClient):
def _create_with_data(self, headers, data):
resp, body_iter = self.http.raw_request('POST', '/v1/images',
headers=headers, body=data)
self._error_checker('POST', '/v1/images', headers, data, resp,
body_iter)
self._error_checker(resp, body_iter)
body = json.loads(''.join([c for c in body_iter]))
return rest_client.ResponseBody(resp, body)
@ -118,8 +117,7 @@ class ImagesClient(rest_client.RestClient):
url = '/v1/images/%s' % image_id
resp, body_iter = self.http.raw_request('PUT', url, headers=headers,
body=data)
self._error_checker('PUT', url, headers, data,
resp, body_iter)
self._error_checker(resp, body_iter)
body = json.loads(''.join([c for c in body_iter]))
return rest_client.ResponseBody(resp, body)