Test configuration working
diff --git a/.gitignore b/.gitignore
index 2083af5..4adf44a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@
npm-debug.log
xos/core/static/*.css
!xos/core/static/xos.css
+.DS_Store
\ No newline at end of file
diff --git a/xos/configurations/test-standalone/Makefile b/xos/configurations/test-standalone/Makefile
index 0a8def6..c67b495 100644
--- a/xos/configurations/test-standalone/Makefile
+++ b/xos/configurations/test-standalone/Makefile
@@ -1,23 +1,22 @@
MYIP:=$(shell hostname -i)
-test: frontend
- # MOCK CORD
- # MOVE THIS TO FIXTURES inside dredd hooks
- #sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
- #sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/mocks/cord.yaml
-
- # INSTALL DEPS
- sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm install --production"
- sudo docker exec teststandalone_xos_1 pip install dredd_hooks
-
- # RUN TESTS
- sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm test"
-
-frontend:
+xos:
sudo make -f ../common/Makefile.prereqs
sudo docker-compose up -d
bash ../common/wait_for_xos.sh
sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
+ sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
+
+prepare:
+ # INSTALL DEPS
+ # RUN ONCE BEFORE RUNNING TESTS
+ sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm install --production"
+ sudo docker exec teststandalone_xos_1 pip install dredd_hooks
+
+
+test:
+ # RUN TESTS
+ sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm test"
base-container:
cd ../../../containers/xos; make devel
diff --git a/xos/configurations/test-standalone/README.md b/xos/configurations/test-standalone/README.md
new file mode 100644
index 0000000..bbee0ec
--- /dev/null
+++ b/xos/configurations/test-standalone/README.md
@@ -0,0 +1,10 @@
+# API Test Configuration
+
+This configuration is intended to be used to test the API,
+to use it:
+
+- `make containers` //rebuild the container with current code
+- `make xos` //start the container with fixtures data
+- `make prepare` //install test dependencies
+
+Then anytime is needed `make test` (`xos/api` folder is shared with the container)
\ No newline at end of file
diff --git a/xos/configurations/test-standalone/docker-compose.yml b/xos/configurations/test-standalone/docker-compose.yml
index b3be0ba..5039f08 100644
--- a/xos/configurations/test-standalone/docker-compose.yml
+++ b/xos/configurations/test-standalone/docker-compose.yml
@@ -25,3 +25,4 @@
- ../../templates/admin:/opt/xos/templates/admin
- ../../configurations:/opt/xos/configurations
- ../../tests:/opt/xos/tests
+ - ../../api:/opt/xos/api
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index 7adc4cc..07c169d 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -647,6 +647,7 @@
def get_slice(self):
if not self.provider_service.slices.count():
+ print self, "dio porco"
raise XOSConfigurationError("The service has no slices")
slice = self.provider_service.slices.all()[0]
return slice
diff --git a/xos/tests/api/apiary.apib b/xos/tests/api/apiary.apib
index e6092cb..62ec236 100644
--- a/xos/tests/api/apiary.apib
+++ b/xos/tests/api/apiary.apib
@@ -329,8 +329,8 @@
[
{
- "humanReadableName": "vOLT-tenant-3",
- "id": 3,
+ "humanReadableName": "vOLT-tenant-1",
+ "id": 1,
"service_specific_id": "123",
"s_tag": "222",
"c_tag": "432",
@@ -358,7 +358,7 @@
+ Response 200 (application/json)
{
- "humanReadableName": "vOLT-tenant-3",
+ "humanReadableName": "vOLT-tenant-1",
"id": 1,
"service_specific_id": "123",
"s_tag": "222",
@@ -378,15 +378,15 @@
A virtual volt is complete once is_synced equal true
+ Parameters
- + volt_id: 3 (number) - ID of the vOLT in the form of an integer
+ + volt_id: 1 (number) - ID of the vOLT in the form of an integer
### View a vOLT Detail [GET]
+ Response 200 (application/json)
{
- "humanReadableName": "vOLT-tenant-3",
- "id": 3,
+ "humanReadableName": "vOLT-tenant-1",
+ "id": 1,
"service_specific_id": "123",
"s_tag": "222",
"c_tag": "432",
diff --git a/xos/tests/api/helpers/subscriber.py b/xos/tests/api/helpers/subscriber.py
index eaae294..8e6d004 100644
--- a/xos/tests/api/helpers/subscriber.py
+++ b/xos/tests/api/helpers/subscriber.py
@@ -1,3 +1,5 @@
+# NOT used, see https://github.com/apiaryio/dredd-hooks-python/issues/17#issuecomment-206950166
+
import os
import sys
sys.path.append("/opt/xos")
@@ -8,13 +10,115 @@
from services.cord.models import *
django.setup()
-def createTestSubscriber():
+
+def cleanDB():
# deleting all subscribers
for s in CordSubscriberRoot.objects.all():
- print(s.name)
s.delete(purge=True)
-
+
+ # deleting all slices
+ for s in Slice.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Services
+ for s in Service.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Tenants
+ for s in Tenant.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Networks
+ for s in Network.objects.all():
+ s.delete(purge=True)
+
+ # deleting all NetworkTemplates
+ for s in NetworkTemplate.objects.all():
+ s.delete(purge=True)
+
+ for s in NetworkSlice.objects.all():
+ s.delete(purge=True)
+
+
+def createTestSubscriber():
+
+ cleanDB()
+
+ # load user
+ user = User.objects.get(email="padmin@vicci.org")
+
+ # network template
+ private_template = NetworkTemplate()
+ private_template.name = 'Private Network'
+ private_template.save()
+
# creating the test subscriber
- subscriber = CordSubscriberRoot(name='Test Subscriber 1')
+ subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1)
subscriber.save()
+
+ # Site
+ site = Site.objects.get(name='MySite')
+
+ # vSG service
+ vsg_service = VSGService()
+ vsg_service.name = 'service_vsg'
+
+ # vSG slice
+ vsg_slice = Slice()
+ vsg_slice.name = site.login_base + "_testVsg"
+ vsg_slice.service = vsg_service.id
+ vsg_slice.site = site
+ vsg_slice.caller = user
+
+ vsg_slice.save()
+
+ vsg_service.save()
+
+ # volt service
+ volt_service = VOLTService()
+ volt_service.name = 'service_volt'
+ volt_service.save()
+
+ # vcpe slice
+ vcpe_slice = Slice()
+ vcpe_slice.name = site.login_base + "_testVcpe"
+ vcpe_slice.service = Service.objects.get(kind='vCPE')
+ vcpe_slice.site = site
+ vcpe_slice.caller = user
+ vcpe_slice.save()
+
+ print 'vcpe_slice created'
+
+ # create a lan network
+ lan_net = Network()
+ lan_net.name = 'lan_network'
+ lan_net.owner = vcpe_slice
+ lan_net.template = private_template
+ lan_net.save()
+
+ print 'lan_network created'
+
+ # add relation between vcpe slice and lan network
+ vcpe_network = NetworkSlice()
+ vcpe_network.network = lan_net
+ vcpe_network.slice = vcpe_slice
+ vcpe_network.save()
+
+ print 'vcpe network relation added'
+
+ # vbng service
+ vbng_service = VBNGService()
+ vbng_service.name = 'service_vbng'
+ vbng_service.save()
+
+ # volt tenant
+ vt = VOLTTenant(subscriber=subscriber.id, id=1)
+ vt.s_tag = "222"
+ vt.c_tag = "432"
+ vt.provider_service_id = volt_service.id
+ vt.caller = user
+ vt.save()
+
print "Subscriber Created"
+
+createTestSubscriber()
diff --git a/xos/tests/api/hooks.py b/xos/tests/api/hooks.py
index 3ad996e..f806cb1 100644
--- a/xos/tests/api/hooks.py
+++ b/xos/tests/api/hooks.py
@@ -2,15 +2,133 @@
import sys
# HELPERS
-from helpers import subscriber
+# NOTE move in separated module
+import os
+import sys
+sys.path.append("/opt/xos")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
+import django
+from core.models import *
+from services.cord.models import *
+django.setup()
-restoreSubscriber = "sudo docker exec teststandalone_xos_1_db psql -U postgres -d xos -c \"UPDATE core_tenantroot SET deleted=false WHERE id=1;\""
+
+def cleanDB():
+ # deleting all subscribers
+ for s in CordSubscriberRoot.objects.all():
+ s.delete(purge=True)
+
+ # deleting all slices
+ for s in Slice.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Services
+ for s in Service.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Tenants
+ for s in Tenant.objects.all():
+ s.delete(purge=True)
+
+ # deleting all Networks
+ for s in Network.objects.all():
+ s.delete(purge=True)
+
+ # deleting all NetworkTemplates
+ for s in NetworkTemplate.objects.all():
+ s.delete(purge=True)
+
+ for s in NetworkSlice.objects.all():
+ s.delete(purge=True)
+
+
+def createTestSubscriber():
+
+ cleanDB()
+
+ # load user
+ user = User.objects.get(email="padmin@vicci.org")
+
+ # network template
+ private_template = NetworkTemplate()
+ private_template.name = 'Private Network'
+ private_template.save()
+
+ # creating the test subscriber
+ subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1)
+ subscriber.save()
+
+ # Site
+ site = Site.objects.get(name='MySite')
+
+ # vSG service
+ vsg_service = VSGService()
+ vsg_service.name = 'service_vsg'
+
+ # vSG slice
+ vsg_slice = Slice()
+ vsg_slice.name = site.login_base + "_testVsg"
+ vsg_slice.service = vsg_service.id
+ vsg_slice.site = site
+ vsg_slice.caller = user
+
+ vsg_slice.save()
+
+ vsg_service.save()
+
+ # volt service
+ volt_service = VOLTService()
+ volt_service.name = 'service_volt'
+ volt_service.save()
+
+ # vcpe slice
+ vcpe_slice = Slice()
+ vcpe_slice.name = site.login_base + "_testVcpe"
+ vcpe_slice.service = Service.objects.get(kind='vCPE')
+ vcpe_slice.site = site
+ vcpe_slice.caller = user
+ vcpe_slice.save()
+
+ # print 'vcpe_slice created'
+
+ # create a lan network
+ lan_net = Network()
+ lan_net.name = 'lan_network'
+ lan_net.owner = vcpe_slice
+ lan_net.template = private_template
+ lan_net.save()
+
+ # print 'lan_network created'
+
+ # add relation between vcpe slice and lan network
+ vcpe_network = NetworkSlice()
+ vcpe_network.network = lan_net
+ vcpe_network.slice = vcpe_slice
+ vcpe_network.save()
+
+ # print 'vcpe network relation added'
+
+ # vbng service
+ vbng_service = VBNGService()
+ vbng_service.name = 'service_vbng'
+ vbng_service.save()
+
+ # volt tenant
+ vt = VOLTTenant(subscriber=subscriber.id, id=1)
+ vt.s_tag = "222"
+ vt.c_tag = "432"
+ vt.provider_service_id = volt_service.id
+ vt.caller = user
+ vt.save()
+
+ # print "Subscriber Created"
+
@hooks.before_each
def my_before_each_hook(transaction):
# print('before each restore', transaction['name'])
# commands.getstatusoutput(restoreSubscriber)
- Subs.createTestSubscriber()
+ createTestSubscriber()
sys.stdout.flush()
diff --git a/xos/tests/api/source/tenant/cord/volt.md b/xos/tests/api/source/tenant/cord/volt.md
index b9879ad..8f045f7 100644
--- a/xos/tests/api/source/tenant/cord/volt.md
+++ b/xos/tests/api/source/tenant/cord/volt.md
@@ -10,8 +10,8 @@
[
{
- "humanReadableName": "vOLT-tenant-3",
- "id": 3,
+ "humanReadableName": "vOLT-tenant-1",
+ "id": 1,
"service_specific_id": "123",
"s_tag": "222",
"c_tag": "432",
@@ -39,7 +39,7 @@
+ Response 200 (application/json)
{
- "humanReadableName": "vOLT-tenant-3",
+ "humanReadableName": "vOLT-tenant-1",
"id": 1,
"service_specific_id": "123",
"s_tag": "222",
@@ -59,15 +59,15 @@
A virtual volt is complete once is_synced equal true
+ Parameters
- + volt_id: 3 (number) - ID of the vOLT in the form of an integer
+ + volt_id: 1 (number) - ID of the vOLT in the form of an integer
### View a vOLT Detail [GET]
+ Response 200 (application/json)
{
- "humanReadableName": "vOLT-tenant-3",
- "id": 3,
+ "humanReadableName": "vOLT-tenant-1",
+ "id": 1,
"service_specific_id": "123",
"s_tag": "222",
"c_tag": "432",