def test_plugin_instance_list_success(self): pl_manager = PluginManager() pl_manager.check_apps_exec_server(clearDB=True) self.client.login(username=self.username, password=self.password) response = self.client.get(self.create_read_url) self.assertContains(response, "simplefsapp")
def test_integration_plugin_instance_create_success(self): try: # create test directory where files are created self.test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = self.test_dir if not os.path.exists(self.test_dir): os.makedirs(self.test_dir) # add a plugin to the system though the plugin manager pl_manager = PluginManager() pl_manager.add_plugin('fnndsc/pl-simplefsapp') plugin = Plugin.objects.get(name="simplefsapp") self.create_read_url = reverse("plugininstance-list", kwargs={"pk": plugin.id}) # create a simplefsapp plugin instance user = User.objects.get(username=self.username) PluginInstance.objects.get_or_create(plugin=plugin, owner=user) # make API request self.client.login(username=self.username, password=self.password) response = self.client.post(self.create_read_url, data=self.post, content_type=self.content_type) self.assertEqual(response.status_code, status.HTTP_201_CREATED) finally: # remove test directory shutil.rmtree(self.test_dir, ignore_errors=True) settings.MEDIA_ROOT = os.path.dirname(self.test_dir)
def setUp(self): super(PluginInstanceListViewTests, self).setUp() # create test directory where files are created self.test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = self.test_dir if not os.path.exists(self.test_dir): os.makedirs(self.test_dir) # pudb.set_trace() # add a plugin to the system though the plugin manager pl_manager = PluginManager() # pl_manager.startup_apps_exec_server() pl_manager.add_plugin('fnndsc/pl-simplefsapp') plugin = Plugin.objects.get(name="simplefsapp") self.create_read_url = reverse("plugininstance-list", kwargs={"pk": plugin.id}) self.post = json.dumps( {"template": { "data": [{ "name": "dir", "value": "./" }] }}) # create a plugin instance user = User.objects.get(username=self.username) PluginInstance.objects.get_or_create(plugin=plugin, owner=user)
def setUp(self): self.plugin_fs_docker_image_name = "fnndsc/pl-simplefsapp" self.plugin_fs_name = "simplefsapp" self.plugin_fs_parameters = { 'dir': { 'type': 'string', 'optional': False } } self.plugin_ds_name = "simpledsapp" self.plugin_ds_docker_image_name = "fnndsc/pl-simpledsapp" self.username = '******' self.password = '******' self.pl_manager = PluginManager() # create a plugin (plugin_fs, tf) = Plugin.objects.get_or_create( name=self.plugin_fs_name, dock_image=self.plugin_fs_docker_image_name, type='fs') # add plugin's parameters PluginParameter.objects.get_or_create( plugin=plugin_fs, name='dir', type=self.plugin_fs_parameters['dir']['type'], optional=self.plugin_fs_parameters['dir']['optional']) # create user user = User.objects.create_user(username=self.username, password=self.password)
def test_integration_plugin_instance_detail_success(self): try: # create test directory where files are created self.test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = self.test_dir if not os.path.exists(self.test_dir): os.makedirs(self.test_dir) # add a plugin to the system through the plugin manager pl_manager = PluginManager() pl_manager.add_plugin('fnndsc/pl-simplefsapp', "host") # create a simplefsapp plugin instance plugin = Plugin.objects.get(name='simplefsapp') user = User.objects.get(username=self.username) (pl_inst, tf) = PluginInstance.objects.get_or_create( plugin=plugin, owner=user, compute_resource=plugin.compute_resource) self.read_url = reverse("plugininstance-detail", kwargs={"pk": pl_inst.id}) # run the plugin instance pl_manager.run_plugin_app(pl_inst, {'dir': './'}, service='pfcon', inputDirOverride='/share/incoming', outputDirOverride='/share/outgoing') # make API request self.client.login(username=self.username, password=self.password) response = self.client.get(self.read_url) self.assertContains(response, "simplefsapp") # After submitting run request, wait before checking status # time.sleep(5) # In the following we keep checking the status until the job ends with # 'finishedSuccessfully'. The code runs in a lazy loop poll with a # max number of attempts at 2 second intervals. maxLoopTries = 20 currentLoop = 1 b_checkAgain = True while b_checkAgain: response = self.client.get(self.read_url) str_responseStatus = response.data['status'] if str_responseStatus == 'finishedSuccessfully': b_checkAgain = False else: time.sleep(2) currentLoop += 1 if currentLoop == maxLoopTries: b_checkAgain = False self.assertContains(response, "finishedSuccessfully") finally: # remove test directory shutil.rmtree(self.test_dir, ignore_errors=True) settings.MEDIA_ROOT = os.path.dirname(self.test_dir)
def test_plugin_instance_detail_success(self): user = User.objects.get(username=self.username) plugin = Plugin.objects.get(name="pacspull") (pl_inst, tf) = PluginInstance.objects.get_or_create(plugin=plugin, owner=user) # pudb.set_trace() pl_manager = PluginManager() pl_manager.check_apps_exec_server(clearDB=True) chris2service = charm.Charm(d_args={'dir': './'}, plugin_inst=pl_inst, plugin_repr={ 'selfpath': '/bin', 'selfexec': 'ls', 'execshell': '' }) chris2service.app_manage(method='pfcon') time.sleep(5) self.client.login(username=self.username, password=self.password) response = self.client.get(self.read_url) self.assertContains(response, "pacspull")
def test_integration_plugin_instance_detail_success(self): # create test directory where files are created self.test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = self.test_dir if not os.path.exists(self.test_dir): os.makedirs(self.test_dir) # add a plugin to the system through the plugin manager pl_manager = PluginManager() pl_manager.add_plugin('fnndsc/pl-simplefsapp') # create a simplefsapp plugin instance plugin = Plugin.objects.get(name='simplefsapp') user = User.objects.get(username=self.username) (pl_inst, tf) = PluginInstance.objects.get_or_create(plugin=plugin, owner=user) self.read_url = reverse("plugininstance-detail", kwargs={"pk": pl_inst.id}) # run the plugin instance pl_manager.run_plugin_app(pl_inst, {'dir': './'}, service='pfcon', inputDirOverride='/share/incoming', outputDirOverride='/share/outgoing', IOPhost='host') # make API request self.client.login(username=self.username, password=self.password) response = self.client.get(self.read_url) self.assertContains(response, "simplefsapp") # give time to execute the plugin and repeat request time.sleep(10) response = self.client.get(self.read_url) self.assertContains(response, "finishedSuccessfully") # remove test directory shutil.rmtree(self.test_dir, ignore_errors=True) settings.MEDIA_ROOT = os.path.dirname(self.test_dir)
def test_integration_plugin_instance_detail_success(self): try: # create test directory where files are created self.test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = self.test_dir if not os.path.exists(self.test_dir): os.makedirs(self.test_dir) # add a plugin to the system plugin_repr = { "name": "simplefsapp", "dock_image": "fnndsc/pl-simplefsapp", "authors": "FNNDSC ([email protected])", "type": "fs", "description": "A simple chris fs app demo", "version": "0.1", "title": "Simple chris fs app", "license": "Opensource (MIT)", "parameters": [{ "optional": True, "action": "store", "help": "look up directory", "type": "path", "name": "dir", "flag": "--dir", "default": "./" }], "selfpath": "/usr/src/simplefsapp", "selfexec": "simplefsapp.py", "execshell": "python3" } (compute_resource, tf) = ComputeResource.objects.get_or_create( compute_resource_identifier="host") parameters = plugin_repr['parameters'] data = plugin_repr del data['parameters'] data['compute_resource'] = compute_resource (plugin, tf) = Plugin.objects.get_or_create(**data) # add plugin's parameters PluginParameter.objects.get_or_create(plugin=plugin, name=parameters[0]['name'], type=parameters[0]['type'], flag=parameters[0]['flag']) # create a simplefsapp plugin instance user = User.objects.get(username=self.username) (pl_inst, tf) = PluginInstance.objects.get_or_create( plugin=plugin, owner=user, compute_resource=plugin.compute_resource) self.read_url = reverse("plugininstance-detail", kwargs={"pk": pl_inst.id}) # run the plugin instance pl_manager = PluginManager() pl_manager.run_plugin_app(pl_inst, {'dir': './'}, service='pfcon', inputDirOverride='/share/incoming', outputDirOverride='/share/outgoing') # make API request self.client.login(username=self.username, password=self.password) response = self.client.get(self.read_url) self.assertContains(response, "simplefsapp") # In the following we keep checking the status until the job ends with # 'finishedSuccessfully'. The code runs in a lazy loop poll with a # max number of attempts at 2 second intervals. maxLoopTries = 20 currentLoop = 1 b_checkAgain = True while b_checkAgain: response = self.client.get(self.read_url) str_responseStatus = response.data['status'] if str_responseStatus == 'finishedSuccessfully': b_checkAgain = False else: time.sleep(2) currentLoop += 1 if currentLoop == maxLoopTries: b_checkAgain = False self.assertContains(response, "finishedSuccessfully") finally: # remove test directory shutil.rmtree(self.test_dir, ignore_errors=True) settings.MEDIA_ROOT = os.path.dirname(self.test_dir)
class PluginManagerTests(TestCase): def setUp(self): self.plugin_fs_docker_image_name = "fnndsc/pl-simplefsapp" self.plugin_fs_name = "simplefsapp" self.plugin_fs_parameters = { 'dir': { 'type': 'string', 'optional': False } } self.plugin_ds_name = "simpledsapp" self.plugin_ds_docker_image_name = "fnndsc/pl-simpledsapp" self.username = '******' self.password = '******' self.pl_manager = PluginManager() # create a plugin (plugin_fs, tf) = Plugin.objects.get_or_create( name=self.plugin_fs_name, dock_image=self.plugin_fs_docker_image_name, type='fs') # add plugin's parameters PluginParameter.objects.get_or_create( plugin=plugin_fs, name='dir', type=self.plugin_fs_parameters['dir']['type'], optional=self.plugin_fs_parameters['dir']['optional']) # create user user = User.objects.create_user(username=self.username, password=self.password) def test_mananger_can_get_plugin_app_representation(self): """ Test whether the manager can return a plugin's app representation given the plugin's name. """ plugin = Plugin.objects.get(name=self.plugin_fs_name) app_repr = self.pl_manager.get_plugin_app_representation( self.plugin_fs_docker_image_name) self.assertEquals(plugin.type, app_repr['type']) self.assertIn('parameters', app_repr) def test_mananger_can_get_plugin(self): """ Test whether the manager can return a plugin object. """ plugin = Plugin.objects.get(name=self.plugin_fs_name) self.assertEquals(plugin, self.pl_manager.get_plugin(self.plugin_fs_name)) def test_mananger_can_add_plugin(self): """ Test whether the manager can add a new plugin app to the system. """ self.pl_manager.run(['--add', self.plugin_ds_docker_image_name]) self.assertEquals(Plugin.objects.count(), 2) self.assertTrue(PluginParameter.objects.count() > 1) def test_mananger_can_remove_plugin(self): """ Test whether the manager can remove an existing plugin app from the system. """ self.pl_manager.run(['--remove', self.plugin_fs_name]) self.assertEquals(Plugin.objects.count(), 0) self.assertEquals(PluginParameter.objects.count(), 0) def test_mananger_can_register_plugin_app_modification_date(self): """ Test whether the manager can register a new modification date for an existing plugin app. """ plugin = Plugin.objects.get(name=self.plugin_fs_name) initial_modification_date = plugin.modification_date time.sleep(2) self.pl_manager.run(['--modify', self.plugin_fs_docker_image_name]) plugin = Plugin.objects.get(name=self.plugin_fs_name) self.assertTrue(plugin.modification_date > initial_modification_date) def test_mananger_can_run_registered_plugin_app(self): """ Test whether the manager can run an already registered plugin app. NB: Note the directory overrides on input and output dirs! This is file system space in the plugin container, and thus by hardcoding this here we are relying on totally out-of-band knowledge! This must be fixed in later versions! """ # create test directory where files are created test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = test_dir if not os.path.exists(test_dir): os.makedirs(test_dir) user = User.objects.get(username=self.username) plugin = Plugin.objects.get(name=self.plugin_fs_name) pl_inst = PluginInstance.objects.create(plugin=plugin, owner=user) parameter_dict = {'dir': './'} # pudb.set_trace() self.pl_manager.check_apps_exec_server(clearDB=True, service='pfcon', IOPhost='host') self.pl_manager.run_plugin_app(pl_inst, parameter_dict, service='pfcon', inputDirOverride='/share/incoming', outputDirOverride='/share/outgoing', IOPhost='host') time.sleep(10) # self.assertTrue(os.path.isfile(os.path.join(pl_inst.get_output_path(), 'out.txt'))) # remove test directory shutil.rmtree(test_dir) # and shutdown apps_exec_server -- not necessary in new design. # self.pl_manager.shutdown_apps_exec_server() settings.MEDIA_ROOT = os.path.dirname(test_dir) def test_mananger_can_check_plugin_app_exec_status(self): """ Test whether the manager can check a plugin's app execution status. NB: Note the directory overrides on input and output dirs! This is file system space in the plugin container, and thus by hardcoding this here we are relying on totally out-of-band knowledge! This must be fixed in later versions! """ # create test directory where files are created test_dir = settings.MEDIA_ROOT + '/test' settings.MEDIA_ROOT = test_dir if not os.path.exists(test_dir): os.makedirs(test_dir) user = User.objects.get(username=self.username) plugin = Plugin.objects.get(name=self.plugin_fs_name) pl_inst = PluginInstance.objects.create(plugin=plugin, owner=user) parameter_dict = {'dir': './'} # pudb.set_trace() self.pl_manager.check_apps_exec_server(clearDB=True, service='pfcon', IOPhost='host') self.pl_manager.run_plugin_app(pl_inst, parameter_dict, service='pfcon', inputDirOverride='/share/incoming', outputDirOverride='/share/outgoing', IOPhost='host') time.sleep(10) self.pl_manager.check_plugin_app_exec_status(pl_inst) possibleStatus = ['started', 'finishedSuccessfully'] self.assertTrue(pl_inst.status in possibleStatus) # remove test directory shutil.rmtree(test_dir) # and shutdown apps_exec_server -- not necessary in new design. # self.pl_manager.shutdown_apps_exec_server() settings.MEDIA_ROOT = os.path.dirname(test_dir)