예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)