def test_get_plugins_installed_type_south(self, mocker): @asyncio.coroutine def mock_folders(): yield TestPluginDiscovery.mock_south_folders @asyncio.coroutine def mock_c_folders(): yield TestPluginDiscovery.mock_c_south_folders mock_get_folders = mocker.patch.object(PluginDiscovery, "get_plugin_folders", return_value=next( mock_folders())) mock_get_plugin_config = mocker.patch.object( PluginDiscovery, "get_plugin_config", side_effect=TestPluginDiscovery.mock_plugins_south_config) mock_get_c_folders = mocker.patch.object(utils, "find_c_plugin_libs", return_value=next( mock_c_folders())) mock_get_c_plugin_config = mocker.patch.object( utils, "get_plugin_info", side_effect=TestPluginDiscovery.mock_c_plugins_south_config) plugins = PluginDiscovery.get_plugins_installed("south") expected_plugin = TestPluginDiscovery.mock_plugins_south_config expected_plugin.extend(TestPluginDiscovery.mock_c_plugins_south_config) # FIXME: ordering issue # assert expected_plugin == plugins assert 1 == mock_get_folders.call_count assert 2 == mock_get_plugin_config.call_count assert 1 == mock_get_c_folders.call_count assert 1 == mock_get_c_plugin_config.call_count
async def get_plugins_installed(request): """ get list of installed plugins :Example: curl -X GET http://localhost:8081/foglamp/plugins/installed curl -X GET http://localhost:8081/foglamp/plugins/installed?config=true curl -X GET http://localhost:8081/foglamp/plugins/installed?type=north|south|filter|notificationDelivery|notificationRule curl -X 'GET http://localhost:8081/foglamp/plugins/installed?type=north&config=true' """ plugin_type = None is_config = False if 'type' in request.query and request.query['type'] != '': plugin_type = request.query['type'].lower() if request.query['type'] not in ['notificationDelivery', 'notificationRule'] else request.query['type'] if plugin_type is not None and plugin_type not in ['north', 'south', 'filter', 'notificationDelivery', 'notificationRule']: raise web.HTTPBadRequest(reason="Invalid plugin type. Must be 'north' or 'south' or 'filter' or 'notificationDelivery' or 'notificationRule'.") if 'config' in request.query: config = request.query['config'] if config not in ['true', 'false', True, False]: raise web.HTTPBadRequest(reason='Only "true", "false", true, false' ' are allowed for value of config.') is_config = True if ((type(config) is str and config.lower() in ['true']) or ( (type(config) is bool and config is True))) else False plugins_list = PluginDiscovery.get_plugins_installed(plugin_type, is_config) return web.json_response({"plugins": plugins_list})
async def update_plugin(request: web.Request) -> web.Response: """ update plugin :Example: curl -X PUT http://localhost:8081/foglamp/plugins/south/sinusoid/update curl -X PUT http://localhost:8081/foglamp/plugins/north/http_north/update """ _type = request.match_info.get('type', None) name = request.match_info.get('name', None) try: # TODO: FOGL-3063, FOGL-3064 _type = _type.lower() if _type not in ['north', 'south']: raise ValueError("Invalid plugin type. Must be 'north' or 'south'") # Check requested plugin name is installed or not installed_plugins = PluginDiscovery.get_plugins_installed(_type, False) installed_plugin_name = [p_name["name"] for p_name in installed_plugins] if name not in installed_plugin_name: raise KeyError("{} plugin is not yet installed. So update is not possible.".format(name)) # Tracked plugins from asset tracker tracked_plugins = await _get_plugin_and_sch_name_from_asset_tracker(_type) sch_list = [] for p in tracked_plugins: if name == p['plugin']: sch_info = await _get_sch_id_and_enabled_by_name(p['service']) if sch_info[0]['enabled'] == 't': status, reason = await server.Server.scheduler.disable_schedule(uuid.UUID(sch_info[0]['id'])) if status: _logger.warning("{} {} instance is disabled as {} plugin is updating..".format( p['service'], _type, p['plugin'])) sch_list.append(sch_info[0]['id']) # Plugin update is running as a background task loop = request.loop request._type = _type request._name = name request._sch_list = sch_list loop.call_later(1, do_update, request) except KeyError as ex: raise web.HTTPNotFound(reason=ex) except ValueError as ex: raise web.HTTPBadRequest(reason=ex) except Exception as ex: raise web.HTTPInternalServerError(reason=ex) return web.json_response({"message": "{} plugin update in process. Wait for few minutes to complete.".format(name)})
def test_get_c_rules_plugins_installed(self, mocker): @asyncio.coroutine def mock_rule_folders(): yield TestPluginDiscovery.mock_c_rule_folders mock_get_c_rule_folders = mocker.patch.object(utils, "find_c_plugin_libs", return_value=next( mock_rule_folders())) mock_get_c_rule_plugin_config = mocker.patch.object( utils, "get_plugin_info", side_effect=TestPluginDiscovery.mock_c_rule_config) plugins = PluginDiscovery.get_plugins_installed("rule") # expected_plugin = TestPluginDiscovery.mock_c_plugins_config[4] # FIXME: ordering issue # assert expected_plugin == plugins assert 1 == mock_get_c_rule_folders.call_count assert 1 == mock_get_c_rule_plugin_config.call_count
def _get_installed_plugins(): return PluginDiscovery.get_plugins_installed("north", False)