def test_dvs_agent_mode_no_package(self): import_mock = mock.patch('importlib.import_module', side_effect=ValueError) import_patch = import_mock.start() cfg.CONF.set_override('agent_mode', 'dvs', 'OPFLEX') with mock.patch('sys.argv'), mock.patch('sys.exit') as sys_patch: try: gbp_agent.main() except AttributeError: self.assertEqual(1, sys_patch.call_count) self.assertEqual(1, import_patch.call_count) import_mock.stop()
def test_dvs_agent_no_binding_mode(self): mock_dvs_instance = mock.MagicMock() import_mock = mock.patch('importlib.import_module', return_value=mock_dvs_instance) import_patch = import_mock.start() cfg.CONF.set_override('agent_mode', 'dvs_no_binding', 'OPFLEX') with mock.patch('sys.argv'): gbp_agent.main() self.assertEqual(1, import_patch.call_count) self.assertEqual( 1, mock_dvs_instance.create_agent_config_map.call_count) import_mock.stop()
def test_opflex_agent_mode(self): opflex_agent = mock.patch('opflexagent.gbp_agent.GBPOpflexAgent') opflex_patch = opflex_agent.start() metadata_mgr = mock.patch( 'opflexagent.as_metadata_manager.AsMetadataManager') metadata_patch = metadata_mgr.start() cfg.CONF.set_override('agent_mode', 'opflex', 'OPFLEX') with mock.patch('sys.argv'): gbp_agent.main() self.assertEqual(1, opflex_patch.call_count) self.assertEqual(1, metadata_patch.call_count) opflex_agent.stop() metadata_mgr.stop()
def test_dvs_agent_no_binding_mode(self): mock_dvs_instance = mock.MagicMock() import_mock = mock.patch('importlib.import_module', return_value=mock_dvs_instance) import_patch = import_mock.start() cfg.CONF.set_override('agent_mode', 'dvs_no_binding', 'OPFLEX') resources = [mock.patch('os.path.basename'), mock.patch('sys.argv')] with utils.nested_context_manager(*resources): gbp_agent.main() self.assertEqual(1, import_patch.call_count) self.assertEqual( 1, mock_dvs_instance.create_agent_config_map.call_count) import_mock.stop()
def test_opflex_agent_mode(self): opflex_agent = mock.patch('opflexagent.gbp_agent.GBPOpflexAgent') opflex_patch = opflex_agent.start() metadata_mgr = mock.patch( 'opflexagent.as_metadata_manager.AsMetadataManager') metadata_patch = metadata_mgr.start() cfg.CONF.set_override('agent_mode', 'opflex', 'OPFLEX') resources = [mock.patch('os.path.basename'), mock.patch('sys.argv')] with utils.nested_context_manager(*resources): gbp_agent.main() self.assertEqual(1, opflex_patch.call_count) self.assertEqual(1, metadata_patch.call_count) opflex_agent.stop() metadata_mgr.stop()
def test_dvs_agent_mode_no_package(self): import_mock = mock.patch('importlib.import_module', side_effect=ValueError) import_patch = import_mock.start() cfg.CONF.set_override('agent_mode', 'dvs', 'OPFLEX') resources = [ mock.patch('os.path.basename'), mock.patch('sys.argv'), ] with utils.nested_context_manager(*resources): with mock.patch('sys.exit') as sys_patch: try: gbp_agent.main() except AttributeError: self.assertEqual(1, sys_patch.call_count) self.assertEqual(1, import_patch.call_count) import_mock.stop()