Commit ff637e6c authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added test implementation for 'vos_group' CLI.

parent 7e7f692a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ RUN useradd -m -s /bin/bash client
RUN mkdir -p /usr/bin/vos_cli
COPY *.py \
     vos_data \
     vos_group \
     vos_import \
     vos_job \
     vos_storage /usr/bin/vos_cli/
+3 −0
Original line number Diff line number Diff line
@@ -17,3 +17,6 @@ rpc_queue = job_queue

[vos_storage]
rpc_queue = storage_queue

[vos_group]
rpc_queue = group_queue

client/vos_group

0 → 100644
+94 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

import os
import sys

from redis_rpc_client import RedisRPCClient
from config import Config 


class VOSGroup(RedisRPCClient):

    def __init__(self):
        config = Config("/etc/vos_cli/vos_cli.conf")
        params = config.loadSection("server")
        self.host = params["host"]
        self.port = params.getint("port")
        self.db = params.getint("db")
        params = config.loadSection("vos_group")
        self.rpcQueue = params["rpc_queue"]
        super(VOSGroup, self).__init__(self.host, self.port, self.db, self.rpcQueue)
        
    def addGroup(self, groupType, groupname, vospacePath):
        addGroupRequest = { "requestType": "GRPR_ADD", "vospacePath": vospacePath, "groupName": groupname }
        addGroupResponse = self.call(addGroupRequest)
        if "responseType" not in addGroupResponse:
            sys.exit("FATAL: Malformed response, storage acknowledge expected.\n")
        elif addGroupResponse["responseType"] == "GRPR_STARTED":
            print("\nThe procedure to change groupRead persmission has started.\nYou'll receive an email at the end of the operation.\n")
        elif addGroupResponse["responseType"] == "ERROR":
            errorCode = addGroupResponse["errorCode"]
            errorMsg = addGroupResponse["errorMsg"]
            sys.exit(f"\nError code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")
            
    def help(self):
        sys.exit("""
NAME
       vos_group

SYNOPSYS
       vos_group  GROUP_TYPE METHOD GROUP_NAME VOSPACE_PATH

DESCRIPTION
       This tool allows to modify 'group_read' and 'group_write'
       parameters of a VOSpace node.

       Two parameters are required:
       
       GROUP_TYPE:
           specifies the group type. can be 'read' or 'write'

       METHOD:
           there are three supported methods:
               1. 'add': adds a group to a node
               2. 'del': removes a group from a node
               3. 'list': lists all groups associated to a node

       GROUP_NAME:
           represents a group of users or a single user.
           In the first case, the syntax is 'gms_' followed
           by the group name.
           In the second case, the syntax is:
           
               people.name\\.surname

       VOSPACE_PATH:
           represents the node VOSpace path.

EXAMPLES
      The following command will import recursively all the nodes contained
      in 'mydir' on the VOSpace for the 'jsmith' user:
      
      Add 'jane.lee' to 'group_read' for the VOSpace node /john.smith/test/foo:
      # vos_group read add people.jane\\.lee /john.smith/test/foo
      
      Add 'my_group' to 'group_write' for the VOSpace node /john.smith/test/foo:
      # vos_group write add gms_mygroup /john.smith/test/foo
      
    """)

# Create new VOSChcrt object
vosGroupCli = VOSGroup()

# Check the number of input args
if len(sys.argv) == 5:
    script, groupType, method, groupname, vospacePath = sys.argv
else:
    vosGroupCli.help()

if method == "add":
    vosGroupCli.addGroup(groupType, groupname, vospacePath)
else:
    vosGroupCli.help()