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 = WorkspaceConfiguration(self.workspace.json_config) files_str = '-f {"file_path":"/dir/file.name", "id":"12300", "workspace":"workspace_1"}' workspace_str = '-w {"workspace_1": %s}' % (config.get_dict()) purge_str = '-p False' with self.assertRaises(SystemExit): django.core.management.call_command('scale_delete_files', files_str, workspace_str, purge_str)
def edit_workspace(self, workspace_id, title=None, description=None, json_config=None, base_url=None, is_active=None): """Edits the given Workspace and saves the changes in the database. All database changes occur in an atomic transaction. An argument of None for a field indicates that the field should not change. :param workspace_id: The unique identifier of the Workspace to edit :type workspace_id: int :param title: The human-readable name of this Workspace :type title: string :param description: A description of this Workspace :type description: string :param json_config: The Workspace configuration :type json_config: dict :param base_url: The URL prefix used to download files stored in the Workspace. :type base_url: string :param is_active: Whether or not the Workspace is available for use. :type is_active: bool :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid """ workspace = Workspace.objects.get(pk=workspace_id) # Validate the configuration, no exception is success if json_config: config = WorkspaceConfiguration(json_config) config.validate_broker() workspace.json_config = config.get_dict() # Update editable fields if title: workspace.title = title if description: workspace.description = description if base_url: workspace.base_url = base_url if is_active is not None: workspace.is_active = is_active workspace.save()
def create_workspace(self, name, title, description, json_config, base_url=None, is_active=True): """Creates a new Workspace with the given configuration and returns the new Workspace model. The Workspace model will be saved in the database and all changes to the database will occur in an atomic transaction. :param name: The identifying name of this Workspace :type name: string :param title: The human-readable name of this Workspace :type title: string :param description: A description of this Workspace :type description: string :param json_config: The Workspace configuration :type json_config: dict :param base_url: The URL prefix used to download files stored in the Workspace. :type base_url: string :param is_active: Whether or not the Workspace is available for use. :type is_active: bool :returns: The new Workspace :rtype: :class:`storage.models.Workspace` :raises :class:`storage.configuration.exceptions.InvalidWorkspaceConfiguration`: If the configuration is invalid """ # Validate the configuration, no exception is success config = WorkspaceConfiguration(json_config) config.validate_broker() workspace = Workspace() workspace.name = name workspace.title = title workspace.description = description workspace.json_config = config.get_dict() workspace.base_url = base_url workspace.is_active = is_active workspace.save() return workspace
def _detect_workspaces(self, workspace_list): """Parses, validates, and returns workspace information for the given workspaces :param workspace_list: The workspace list that was given :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 = WorkspaceConfiguration(workspace[name]) 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