Esempio n. 1
0
    def _patch_v6(self, request, workspace_id):
        """Edits an existing workspace and returns the updated details

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param workspace_id: The ID for the workspace.
        :type workspace_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        title = rest_util.parse_string(request, 'title', required=False)
        description = rest_util.parse_string(request, 'description', required=False)
        json = rest_util.parse_dict(request, 'configuration', required=False)
        base_url = rest_util.parse_string(request, 'base_url', required=False)
        is_active = rest_util.parse_string(request, 'is_active', required=False)

        configuration = None
        if json:
            try:
                configuration = WorkspaceConfigurationV6(json, do_validate=True).get_configuration()
            except InvalidWorkspaceConfiguration as ex:
                message = 'Workspace configuration invalid'
                logger.exception(message)
                raise BadParameter('%s: %s' % (message, unicode(ex)))

        try:
            Workspace.objects.edit_workspace(workspace_id, title, description, configuration, base_url, is_active)
        except Workspace.DoesNotExist:
            raise Http404
        except InvalidWorkspaceConfiguration as ex:
            logger.exception('Unable to edit workspace: %s', workspace_id)
            raise BadParameter(unicode(ex))

        return HttpResponse(status=204)
Esempio n. 2
0
    def test_scale_delete_files(self, mock_message, mock_delete):
        """Tests calling Scale to delete files"""
        def new_delete(files, volume_path, broker):
            return

        mock_delete.side_effect = new_delete

        config = WorkspaceConfigurationV6(
            self.workspace.json_config).get_configuration()

        os.environ['FILES'] = json.dumps([{
            "file_path": "/dir/file.name",
            "id": "12300",
            "workspace": "workspace_1"
        }])
        os.environ['WORKSPACES'] = json.dumps([{
            "workspace_1": config.get_dict()
        }])
        os.environ['PURGE'] = str(False)
        os.environ['JOB_ID'] = str(self.job_1.id)
        os.environ['TRIGGER_ID'] = str(self.trigger_1.id)
        os.environ['SOURCE_FILE_ID'] = str(self.source_file.id)

        with self.assertRaises(SystemExit):
            django.core.management.call_command('scale_delete_files')
Esempio n. 3
0
    def _create_v6(self, request):
        """Creates a new Workspace and returns it in JSON form

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        title = rest_util.parse_string(request, 'title', required=True)
        name = title_to_name(self.queryset, title)
        description = rest_util.parse_string(request,
                                             'description',
                                             required=False)
        json = rest_util.parse_dict(request, 'configuration')
        base_url = rest_util.parse_string(request, 'base_url', required=False)
        is_active = rest_util.parse_bool(request,
                                         'is_active',
                                         default_value=True,
                                         required=False)

        configuration = None
        if json:
            try:
                configuration = WorkspaceConfigurationV6(
                    json, do_validate=True).get_configuration()
            except InvalidWorkspaceConfiguration as ex:
                message = 'Workspace configuration invalid'
                logger.exception(message)
                raise BadParameter('%s: %s' % (message, unicode(ex)))

        try:
            workspace = Workspace.objects.create_workspace(
                name, title, description, configuration, base_url, is_active)
        except InvalidWorkspaceConfiguration as ex:
            logger.exception('Unable to create new workspace: %s', name)
            raise BadParameter(unicode(ex))

        # Fetch the full workspace with details
        try:
            workspace = Workspace.objects.get_details(workspace.id)
        except Workspace.DoesNotExist:
            raise Http404

        serializer = WorkspaceDetailsSerializerV6(workspace)
        workspace_url = reverse('workspace_details_view',
                                args=[workspace.id],
                                request=request)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=dict(location=workspace_url))
    def test_bad_host_config(self):
        """Tests calling WorkspaceConfiguration constructor with bad host broker configuration."""

        config = WorkspaceConfigurationV1({
            'broker': {
                'type': 'host',
            },
        }).get_configuration()
        self.assertRaises(InvalidWorkspaceConfiguration,
                          config.validate_broker)

        config = WorkspaceConfigurationV6({
            'broker': {
                'type': 'host',
            },
        }).get_configuration()
        self.assertRaises(InvalidWorkspaceConfiguration,
                          config.validate_broker)
Esempio n. 5
0
    def test_successful(self):
        """Tests calling WorkspaceManager.create_workspace() successfully"""

        config_dict = {
            'version': '1.0',
            'broker': {
                'type': 'host',
                'host_path': '/host/path'
            },
        }

        config = WorkspaceConfigurationV6(config_dict, do_validate=True).get_configuration()

        workspace = Workspace.objects.create_workspace('my_name', 'my_title', 'my_description', config)
        self.assertEqual(workspace.name, 'my_name')
        self.assertEqual(workspace.title, 'my_title')
        self.assertEqual(workspace.description, 'my_description')
        self.assertEqual(workspace.json_config['broker']['type'], 'host')
        self.assertTrue(workspace.is_active)
    def test_successful(self):
        """Tests calling WorkspaceConfiguration constructor successfully with all information."""

        # No exception is success
        config = WorkspaceConfigurationV1(
            {
                'broker': {
                    'type': 'host',
                    'host_path': '/host/path',
                },
            },
            do_validate=True).get_configuration()
        config.validate_broker()

        config = WorkspaceConfigurationV6(
            {
                'broker': {
                    'type': 'host',
                    'host_path': '/host/path',
                },
            },
            do_validate=True).get_configuration()
        config.validate_broker()
    def test_bare_min(self):
        """Tests calling WorkspaceConfiguration constructor with bare minimum JSON."""

        # No exception is success
        config = WorkspaceConfigurationV1(
            {
                'broker': {
                    'type': 'host',
                    'host_path': '/the/path',
                },
            },
            do_validate=True).get_configuration()
        config.validate_broker()

        config = WorkspaceConfigurationV6(
            {
                'broker': {
                    'type': 'host',
                    'host_path': '/the/path',
                },
            },
            do_validate=True).get_configuration()
        config.validate_broker()
Esempio n. 8
0
    def _configure_workspaces(self, workspace_list):
        """Parses, validates, and returns workspace information for the given workspaces

        :param workspace_list: The workspace list
        :type workspace_list: [dict]
        :return: All workspaces by given name with associated broker and volume_path
        :rtype: dict
        """

        workspaces = {}
        for workspace in workspace_list:
            name = workspace.keys()[0]
            wrkspc = WorkspaceConfigurationV6(
                workspace[name]).get_configuration()
            wrkspc.validate_broker()
            valid_wrkspc = wrkspc.get_dict()

            workspaces[name] = {
                'broker': get_broker(valid_wrkspc['broker']['type']),
                'volume_path': valid_wrkspc['broker']['host_path']
            }

        return workspaces