def test_get_real_component(self): with patch.dict(os.environ, {'NAGIOS__SERVICEHOST_COMPONENT': 'SUPERVISOR'}, clear=True): component = mm_wrapper.get_real_component() self.assertEqual(component, 'SUPERVISOR') with patch.dict(os.environ, {'NAGIOS__SERVICEHOST_COMPONENT': 'JOBHISTORY'}, clear=True): component = mm_wrapper.get_real_component() self.assertEqual(component, 'MAPREDUCE2')
def test_outfile_location(self): # # Test without $AMBARI_AGENT_OUT_DIR # out_folder = '/var/log/ambari-agent' out_file = 'ambari-agent.out' with patch.dict('os.environ', {}): self.assertEqual(os.path.join(out_folder, out_file), AmbariConfig.AmbariConfig.getOutFile()) # # Test with $AMBARI_AGENT_OUT_DIR # out_folder = '/myoutlocation/out' out_file = 'ambari-agent.out' with patch.dict('os.environ', {'AMBARI_AGENT_LOG_DIR': out_folder}): self.assertEqual(os.path.join(out_folder, out_file), AmbariConfig.AmbariConfig.getOutFile()) pass
def test_logfile_location(self): # # Test without $AMBARI_AGENT_LOG_DIR # log_folder = '/var/log/ambari-agent' log_file = 'ambari-agent.log' with patch.dict('os.environ', {}): self.assertEqual(os.path.join(log_folder, log_file), AmbariConfig.AmbariConfig.getLogFile()) # # Test with $AMBARI_AGENT_LOG_DIR # log_folder = '/myloglocation/log' log_file = 'ambari-agent.log' with patch.dict('os.environ', {'AMBARI_AGENT_LOG_DIR': log_folder}): self.assertEqual(os.path.join(log_folder, log_file), AmbariConfig.AmbariConfig.getLogFile()) pass
def test_outfile_location(self): # # Test without $AMBARI_AGENT_OUT_DIR # out_folder = '/var/log/ambari-agent' out_file = 'ambari-agent.out' with patch.dict('os.environ', {}): self.assertEqual(os.path.join(out_folder, out_file), AmbariConfig.AmbariConfig.getOutFile()) # # Test with $AMBARI_AGENT_OUT_DIR # out_folder = '/myoutlocation/out' out_file = 'ambari-agent.out' with patch.dict('os.environ', {'AMBARI_AGENT_LOG_DIR': out_folder}): self.assertEqual(os.path.join(out_folder, out_file), AmbariConfig.AmbariConfig.getOutFile()) pass
def test_logfile_location(self): # # Test without $AMBARI_AGENT_LOG_DIR # log_folder = '/var/log/ambari-agent' log_file = 'ambari-agent.log' with patch.dict('os.environ', {}): self.assertEqual(os.path.join(log_folder, log_file), AmbariConfig.AmbariConfig.getLogFile()) # # Test with $AMBARI_AGENT_LOG_DIR # log_folder = '/myloglocation/log' log_file = 'ambari-agent.log' with patch.dict('os.environ', {'AMBARI_AGENT_LOG_DIR': log_folder}): self.assertEqual(os.path.join(log_folder, log_file), AmbariConfig.AmbariConfig.getLogFile()) pass
def test_get_jumpstart_content_bucket_override(): with patch.dict( os.environ, {ENV_VARIABLE_JUMPSTART_CONTENT_BUCKET_OVERRIDE: "some-val"}): with patch("logging.Logger.info") as mocked_info_log: random_region = "random_region" assert "some-val" == utils.get_jumpstart_content_bucket( random_region) mocked_info_log.assert_called_once_with( "Using JumpStart bucket override: '%s'", "some-val", )
def setUp(self): self._adafruit_mock = Mock() self._pwm = self._adafruit_mock.PCA9685.return_value = Mock() self._module_patcher = patch.dict('sys.modules', Adafruit_PCA9685=self._adafruit_mock) self._module_patcher.start()