def test_no_fetch_ec2_meta_data_when_cloud_retries_is_max(self): """ Do not fetch EC2 info when C{_cloud_retries} is C{METADATA_RETRY_MAX} """ self.config.cloud = True self.mstore.set_accepted_types(["cloud-instance-metadata"]) plugin = ComputerInfo(fetch_async=self.fetch_func) plugin._cloud_retries = METADATA_RETRY_MAX self.monitor.add(plugin) plugin.exchange() messages = self.mstore.get_pending_messages() self.assertEqual(0, len(messages))
def test_fetch_ec2_meta_data_bad_result_max_retry(self): """ L{_fetch_ec2_meta_data} returns C{None} and logs an error when crossing the retry threshold C{METADATA_RETRY_MAX}. """ self.log_helper.ignore_errors(HTTPCodeError) self.add_query_result("ami-id", HTTPCodeError(404, "notfound")) plugin = ComputerInfo(fetch_async=self.fetch_func) plugin._cloud_retries = METADATA_RETRY_MAX result = yield plugin._fetch_ec2_meta_data() self.assertIn( "INFO: No cloud meta-data available. Server returned " "HTTP code 404", self.logfile.getvalue()) self.assertEqual(None, result)
def test_fetch_ec2_meta_data_no_cloud_api_max_retry(self): """ L{_fetch_ec2_meta_data} returns C{None} when faced with no EC2 cloud API service and reports the specific C{PyCurlError} upon message exchange when L{_cloud_retries} equals C{METADATA_RETRY_MAX}. """ self.log_helper.ignore_errors(PyCurlError) self.add_query_result("instance-id", PyCurlError(60, "pycurl error")) plugin = ComputerInfo(fetch_async=self.fetch_func) plugin._cloud_retries = METADATA_RETRY_MAX result = yield plugin._fetch_ec2_meta_data() self.assertIn( "INFO: No cloud meta-data available. " "Error 60: pycurl error\n", self.logfile.getvalue()) self.assertEqual(None, result)