Commit ed8a0ed2 authored by Hamza Baqa's avatar Hamza Baqa

s2s interop

parent 17b63dc2
import os
import subprocess
import socket
import re
import json
#subprocess.check_output(['ls','-l']) #all that is technically needed...
retval = os.getcwd()
retval = os.getcwd() + "/SPARQL"
#conf = retval + "/configfile"
print(retval)
query= os.getcwd() + "/SPARQL/s-query"
#queryString = 'SELECT * {?s ?p ?o}'
queryString = 'SELECT * WHERE {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type}'
resp = subprocess.check_output([query,'--service','http://127.0.0.1:3030/ds/query',queryString])
query_resp_1 = json.loads(resp.decode("utf-8"))
print(query_resp_1)
......@@ -58,9 +58,16 @@ run-conf-test: ## runs all unittests
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
$(MAKE) _test_utils_conf
run-s2s-test: ## runs all unittests
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
$(MAKE) _s2s_test
_test_utils_conf:
python3 conf.py
_s2s_test:
python3 s2s.py
_test_utils:
python3 test.py
......@@ -70,6 +77,7 @@ _u2u_test:
install-python-dependencies: ## installs all python pip dependencies
@echo 'installing py3 dependencies...'
@python3 -m pip install ioppytest-utils --user
@python3 -m pip install validators
_check-sudo:
@runner=`whoami` ;\
......
version = 1.0
DOCKER_GW = 172.17.42.1
info:
@echo $(info_message)
version:
@echo SemTest v$(version)
show_env: ## set env vars
@echo "AMQP_URL " $(AMQP_URL) " AMQP_EXCHANGE " $(AMQP_EXCHANGE)
env: ## set env vars
@echo "Creating var env "
export AMQP_URL=$(AMQP_URL)
@echo $(AMQP_URL)
export AMQP_EXCHANGE=$(AMQP_EXCHANGE)
help: ## Help dialog.
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//'`); \
for help_line in $${help_lines[@]}; do \
IFS=$$'#' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf "%-30s %s\n" $$help_command $$help_info ; \
done
build-tools: ## builds all testing tool docker images (only testing tool)
@echo $(info_message)
@echo "Starting to build docker images.. "
$(MAKE) _docker-build-semtest
sniff-bus: ## Listen and echo all messages in the event bus
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
ioppytest-cli connect
stop-all:
@echo "Stop the SemTest cointainer"
docker stop easyglobalmarket-semtest
run-semtest-testing-tool: ## Run SemTest testing tool in docker container
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
docker run -p 9093:8080 -d --rm --env AMQP_EXCHANGE=$(AMQP_EXCHANGE) --env AMQP_URL=$(AMQP_URL) --env DOCKER_GW=$(DOCKER_GW) --name easyglobalmarket-semtest easyglobalmarket-semtest
run-tests: ## runs all unittests
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
$(MAKE) _test_utils
run-u2u-test: ## runs all unittests
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
$(MAKE) _u2u_test
run-conf-test: ## runs all unittests
@echo "Using AMQP env vars: {url : $(AMQP_URL), exchange : $(AMQP_EXCHANGE)}"
$(MAKE) _test_utils_conf
_test_utils_conf:
python3 conf.py
_test_utils:
python3 test.py
_u2u_test:
python3 u2u.py
install-python-dependencies: ## installs all python pip dependencies
@echo 'installing py3 dependencies...'
@python3 -m pip install ioppytest-utils --user
_check-sudo:
@runner=`whoami` ;\
if test $$runner != "root" ;\
then \
echo "(!) You are not root. This command requires 'sudo -E' \n"; \
fi
_docker-build-semtest:
@echo "Starting to build SemTest testing tools.."
# let's build the testing tool image (same for interop and conformance)
docker build --quiet -t easyglobalmarket-semtest$(version) -f semtest/SemTest/Dockerfile .
docker build --quiet -t easyglobalmarket-semtest-launcher$(version) -f semtest/SemTest_launcher/Dockerfile .
# tag all last version images also with a version-less name
docker tag easyglobalmarket-semtest$(version):latest easyglobalmarket-semtest
docker tag easyglobalmarket-semtest-launcher$(version):latest easyglobalmarket-semtest-launcher
info_message = """ \\n\
******************************************************************************************\n\
docker images naming must follow the following conventions: \n\
\n\
resource_type-sub_type-resource_name-version \n\
\n\
resource_type, sub_type and resource_name cannot contain any special character, nor '-' \n\
version format must comply to vx.x \n\
\n\
examples: \n\
\n\
testing_tool-semtest-v$(version) \n\
\n\
******************************************************************************************\n\\n\
"""
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
http://127.0.0.1
3030
http://127.0.0.1
3000
from utils.ioppytest_cli import ioppytest_cli
from tabulate import tabulate
import subprocess
import pika
import requests
import os
import json
import socket
import re
retval = os.getcwd() + "/tmp"
req = ioppytest_cli.MsgUiRequestSessionConfiguration()
ui_reply = ioppytest_cli._amqp_request(req,'dummy_component')
session_user = ui_reply.users
session_user.remove('myslice')
ioppytest_cli.gui_request_file_upload(retval+"/sys1","please upload config file now :D", session_user[0])
ioppytest_cli.gui_request_file_upload(retval+"/sys2","please upload config file now :D", session_user[1])
list_of_files_1 = os.listdir(retval+"/sys1")
list_of_files_1.remove('test')
file_1_to_validate_name = list_of_files_1[0]
list_of_files_2 = os.listdir(retval+"/sys2")
list_of_files_2.remove('test')
file_2_to_validate_name = list_of_files_2[0]
file_1_to_validate_path = retval + "/sys1/" + file_1_to_validate_name
file_2_to_validate_path = retval + "/sys2/" + file_2_to_validate_name
print(file_1_to_validate_path)
print(file_2_to_validate_path)
ioppytest_cli._ui_display_markdown_text(".............Sending queries............ ")
def is_http_url(s):
"""
Returns true if s is valid http url, else false
Arguments:
- `s`:
"""
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
if re.match(regex,s):
return True
else:
return False
def readConfigFile(conf):
filepath = conf
li = [] # ['IP','port']
with open(filepath) as fp:
line = fp.readline()
try:
if is_http_url(line.strip()):
li.append(line.strip())
line = fp.readline()
val = int(line.strip())
li.append(line.strip())
else:
ioppytest_cli._ui_display_markdown_text("Please check your config file: Line 1 is not a legal IP adress")
except ValueError:
ioppytest_cli._ui_display_markdown_text("Please check your config file: Line 2 is not a legal port")
return li
queryScript = os.getcwd() + '/SPARQL/s-query'
#queryString = 'SELECT * {?s ?p ?o}'
queryString = 'SELECT * WHERE {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type}'
#Read config file 1
conf_li_1 = readConfigFile(file_1_to_validate_path)
try:
resp_1 = subprocess.check_output([queryScript,'--service', conf_li_1[0] + ':' + conf_li_1[1] +'/ds/query',queryString])
query_resp_1 = json.loads(resp_1.decode("utf-8"))
except:
ioppytest_cli._ui_display_markdown_text("Please check your Server")
val_1_obj = []
val_1_obj.append("Query result of :"+ conf_li_1[0] + ':' + conf_li_1[1] + " from: " + session_user[0])
val_1_obj.append(query_resp_1)
#Read config file 2
conf_li_2 = readConfigFile(file_2_to_validate_path)
try:
resp_2 = subprocess.check_output([queryScript,'--service', conf_li_2[0] + ':' + conf_li_2[1] +'/ds/query',queryString])
query_resp_2 = json.loads(resp_2.decode("utf-8"))
except:
ioppytest_cli._ui_display_markdown_text("Please check your Server")
val_2_obj = []
val_2_obj.append("Query result of :"+ conf_li_1[0] + ':' + conf_li_1[1] + " from: " + session_user[1])
val_2_obj.append(query_resp_2)
#compare result
val_3_obj = []
val_3_obj.append("Veridict")
if sorted(query_resp_1.items()) == sorted(query_resp_2.items()):
val_3_obj.append("Not interoperable")
else:
val_3_obj.append("Interoperable")
#Remove files
os.remove(file_1_to_validate_path)
os.remove(file_2_to_validate_path)
to_send = []
to_send.append(val_1_obj)
to_send.append(val_2_obj)
to_send.append(val_3_obj)
ioppytest_cli._ui_display_markdown_text(tabulate(to_send, tablefmt="grid"))
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get -y -qq install apt-utils
RUN apt-get -y -qq install python3-dev
RUN apt-get -y -qq install build-essential
RUN apt-get -y -qq install python3-setuptools
RUN apt-get -y -qq install python3-pip
RUN apt-get -y -qq install python-pip
RUN apt-get -y -qq install supervisor
RUN apt-get -y -qq install net-tools
# upgrade pip
RUN python -m pip install --upgrade pip
RUN python3 -m pip install --upgrade pip
ADD semtest/SemTest_launcher/test.py /
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get -y -qq install apt-utils
RUN apt-get -y -qq install python3-dev
RUN apt-get -y -qq install build-essential
RUN apt-get -y -qq install python3-setuptools
RUN apt-get -y -qq install python3-pip
RUN apt-get -y -qq install python-pip
RUN apt-get -y -qq install supervisor
RUN apt-get -y -qq install net-tools
# upgrade pip
RUN python -m pip install --upgrade pip
RUN python3 -m pip install --upgrade pip
ADD semtest/SemTest_launcher/test.py /
import os
import requests
from subprocess import call
import json
#os.environ["AMQP_URL"] = "amqp://2XU190DG:BM7F9VB8@mq.dev.f-interop.eu:443/1db49a57-fe56-45a5-aafa-d00f86a3744f"
#os.environ['AMQP_EXCHANGE'] = "amq.topic"
print(os.environ["AMQP_URL"])
print(os.environ['AMQP_EXCHANGE'])
print(os.environ['DOCKER_GW'])
#call(["ioppytest-cli", "connect"])
DOCKER_GW = os.environ['DOCKER_GW']
retval = os.getcwd() + "/tmp"
#print("Current working directory", retval)
#ioppytest-cli gui_request_file_upload tmp --text-message "please upload file now :D"
call(["ioppytest-cli", "gui_request_file_upload",retval,"--text-message", "please upload file now :D"])
file_to_validate_name = os.listdir(retval)[0]
file_to_validate_path = retval + "/" + file_to_validate_name
print("My file to upload path is: ",file_to_validate_path)
#Upload a the file
URL_to_send = "http://"+DOCKER_GW+":9093/SemTest/ontology"
files = {'file': open(file_to_validate_path, 'rb')}
r = requests.post(URL_to_send, files=files)
j = json.loads(r.text)
JSON_to_Send = json.dumps(
{
"format": j["format"],
"campaign" : "123",
"ErrType": ["Namespace and URI validation", "Literal", "Predicate and Class validation"],
"file_id": j["file_id"],
"ref_ontologies": j["ref_ontologies"]
}
)
#send the file for validation
URL_to_send_validation = "http://"+os.environ['DOCKER_GW']+":9093/SemTest/ontology/test"
res = requests.post(URL_to_send_validation, data=JSON_to_Send)
os.remove(file_to_validate_path)
#Display result
call(["ioppytest-cli", "gui_display_message",res.text])
print(os.environ['AMQP_EXCHANGE'])
print(os.environ['AMQP_URL'])
\ No newline at end of file
---
services:
semtest:
environment:
- GW_DOCKER=http://172.17.42.1:8185/
image: easyglobalmarket/semtest
ports:
- "8185:8080"
version: "2"
import os
from utils.ioppytest_cli import ioppytest_cli
from tabulate import tabulate
#print(tabulate([["value1", "value2"], ["value3", "value4"]], ["column 1", "column 2"], tablefmt="plain"))
ioppytest_cli._ui_display_markdown_text(tabulate([["value1", "value2"], ["value3", "value4"]], ["column 1", "column 2"], tablefmt="plain"))
java -jar start.jar
\ No newline at end of file
This diff is collapsed.
......@@ -13,10 +13,11 @@ print(retval)
req = ioppytest_cli.MsgUiRequestSessionConfiguration()
ui_reply = ioppytest_cli._amqp_request(req,'dummy_component')
session_user = ui_reply.users
session_user.remove('myslice')
ioppytest_cli.gui_request_file_upload(retval+"/user1","please upload file now :D", ui_reply.users[0])
ioppytest_cli.gui_request_file_upload(retval+"/user2","please upload file now :D", ui_reply.users[2])
ioppytest_cli.gui_request_file_upload(retval+"/user1","please upload file now :D", session_user[0])
ioppytest_cli.gui_request_file_upload(retval+"/user2","please upload file now :D", session_user[1])
......@@ -79,14 +80,18 @@ val_1_obj.append("Veridict")
val_1_obj.append(common_onto(dico_to_ont_list_ontopath(j_1),dico_to_ont_list_ontopath(j_2)))
val_2_obj = []
val_2_obj.append("User "+ui_reply.users[0] + " ref ontologies")
val_2_obj.append("User "+session_user[0] + " ref ontologies")
val_2_obj.append(dico_to_ont_list_ontoname(j_1))
val_3_obj = []
val_3_obj.append("User "+ui_reply.users[2] + " ref ontologies")
val_3_obj.append("User "+session_user[2] + " ref ontologies")
val_3_obj.append(dico_to_ont_list_ontoname(j_2))
#Remove files
os.remove(file_1_to_validate_path)
os.remove(file_2_to_validate_path)
to_send = []
to_send.append(val_1_obj)
to_send.append(val_2_obj)
......
from ioppytest_cli import *
import pika
import os
retval = os.getcwd() + "/tmp"
print(retval)
req = ioppytest_cli.MsgUiRequestSessionConfiguration()
ui_reply = ioppytest_cli._amqp_request(req,'dummy_component')
ioppytest_cli.gui_request_file_upload(retval,"please upload file now :D", ui_reply.users[0])
ioppytest_cli.gui_request_file_upload(retval,"please upload file now :D", ui_reply.users[2])
file_1_to_validate_name = os.listdir(retval)[0]
file_2_to_validate_name = os.listdir(retval)[1]
file_1_to_validate_path = retval + "/" + file_to_validate_name
file_2_to_validate_path = retval + "/" + file_to_validate_name
print("My file to upload path is: ",file_1_to_validate_path)
print("My file to upload path is: ",file_2_to_validate_path)
#ui_reply.users
#print(ui_reply.users)
#print(req)
from utils-master.ioppytest_cli import *
import pika
import os
retval = os.getcwd() + "/tmp"
print(retval)
req = ioppytest_cli.MsgUiRequestSessionConfiguration()
ui_reply = ioppytest_cli._amqp_request(req,'dummy_component')
print(ui_reply.users[0])
ioppytest_cli.gui_request_file_upload(retval,"please upload file now :D", ui_reply.users[0])
ioppytest_cli.gui_request_file_upload(retval,"please upload file now :D", ui_reply.users[2])
file_1_to_validate_name = os.listdir(retval)[0]
file_2_to_validate_name = os.listdir(retval)[1]
file_1_to_validate_path = retval + "/" + file_to_validate_name
file_2_to_validate_path = retval + "/" + file_to_validate_name
print("My file to upload path is: ",file_1_to_validate_path)
print("My file to upload path is: ",file_2_to_validate_path)
#ui_reply.users
#print(ui_reply.users)
#print(req)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment