def call_inspector(data, failures): """Post data to inspector.""" data['error'] = failures.get_error() LOG.info('posting collected data to %s', CONF.inspection_callback_url) LOG.debug('collected data: %s', {k: v for k, v in data.items() if k not in _NO_LOGGING_FIELDS}) encoder = encoding.RESTJSONEncoder() data = encoder.encode(data) verify, cert = utils.get_ssl_client_options(CONF) @tenacity.retry(retry=tenacity.retry_if_exception_type( requests.exceptions.ConnectionError), stop=tenacity.stop_after_attempt(_RETRY_ATTEMPTS), wait=tenacity.wait_fixed(_RETRY_WAIT), reraise=True) def _post_to_inspector(): return requests.post(CONF.inspection_callback_url, data=data, verify=verify, cert=cert) resp = _post_to_inspector() if resp.status_code >= 400: LOG.error('inspector %s error %d: %s, proceeding with lookup', CONF.inspection_callback_url, resp.status_code, resp.content.decode('utf-8')) return return resp.json()
def __init__(self, api_url): self.api_url = api_url.rstrip('/') # Only keep alive a maximum of 2 connections to the API. More will be # opened if they are needed, but they will be closed immediately after # use. adapter = requests.adapters.HTTPAdapter(pool_connections=2, pool_maxsize=2) self.session = requests.Session() self.session.mount(self.api_url, adapter) self.encoder = encoding.RESTJSONEncoder()
def setUp(self): super(TestBaseAgent, self).setUp() self.encoder = encoding.RESTJSONEncoder(indent=4) self.agent = agent.IronicPythonAgent( 'https://fake_api.example.' 'org:8081/', ('203.0.113.1', 9990), ('192.0.2.1', 9999), 3, 10, 'eth0', 300, 1, 'agent_ipmitool', False) self.agent.ext_mgr = extension.ExtensionManager.\ make_test_instance([extension.Extension('fake', None, FakeExtension, FakeExtension())])
def setUp(self): super(TestBaseAgent, self).setUp() self.encoder = encoding.RESTJSONEncoder(indent=4) self.agent = agent.IronicPythonAgent( 'https://fake_api.example.' 'org:8081/', ('203.0.113.1', 9990), ('192.0.2.1', 9999), 3, 10, 'eth0', 300, 1, 'agent_ipmitool', False) self.agent.ext_mgr = extension.ExtensionManager.\ make_test_instance([extension.Extension('fake', None, FakeExtension, FakeExtension())]) self.sample_nw_iface = hardware.NetworkInterface( "eth9", "AA:BB:CC:DD:EE:FF", "1.2.3.4", True)
class TestEncoder(base.IronicAgentTest): encoder = encoding.RESTJSONEncoder() def test_encoder(self): expected = {'jack': 'hello', 'jill': 'world'} obj = SerializableTesting('hello', 'world') self.assertEqual(expected, json.loads(self.encoder.encode(obj))) def test_ironic_lib(self): obj = lib_exc.InstanceDeployFailure(reason='boom') encoded = json.loads(self.encoder.encode(obj)) self.assertEqual(500, encoded['code']) self.assertEqual('InstanceDeployFailure', encoded['type']) self.assertIn('boom', encoded['message'])
def call_inspector(data, failures): """Post data to inspector.""" data['error'] = failures.get_error() LOG.info('posting collected data to %s', CONF.inspection_callback_url) LOG.debug('collected data: %s', data) encoder = encoding.RESTJSONEncoder() data = encoder.encode(data) resp = requests.post(CONF.inspection_callback_url, data=data) if resp.status_code >= 400: LOG.error('inspector error %d: %s, proceeding with lookup', resp.status_code, resp.content.decode('utf-8')) return return resp.json()
def call_inspector(data, failures): """Post data to inspector.""" data['error'] = failures.get_error() LOG.info('posting collected data to %s', CONF.inspection_callback_url) LOG.debug('collected data: %s', {k: v for k, v in data.items() if k not in _NO_LOGGING_FIELDS}) encoder = encoding.RESTJSONEncoder() data = encoder.encode(data) verify, cert = utils.get_ssl_client_options(CONF) resp = requests.post(CONF.inspection_callback_url, data=data, verify=verify, cert=cert) if resp.status_code >= 400: LOG.error('inspector error %d: %s, proceeding with lookup', resp.status_code, resp.content.decode('utf-8')) return return resp.json()
def jsonify(value, status=200): """Convert value to a JSON response using the custom encoder.""" encoder = encoding.RESTJSONEncoder() data = encoder.encode(value) return werkzeug.Response(data, status=status, mimetype='application/json')