From 0d1a7cbd73b3a42eb1dc32b598ed78080a7155bc Mon Sep 17 00:00:00 2001 From: Ulas Kozat Date: Thu, 17 Nov 2016 10:57:56 -0800 Subject: Replace toscaparser with native yaml to load published Tosca file into memory Change-Id: I2ab06c97d103f95d53db256675b6949fa2b7b308 Signed-off-by: Ulas Kozat --- DominoServer.py | 9 +++++---- domino_conf.py | 2 +- lib/mapper/label.py | 8 ++++---- tests/logdata/client1.log | 36 +++++++++++++++++++++++++++++++++++ tests/logdata/server.log | 42 +++++++++++++++++++++++++++++++++++++++++ tests/refdata/test1_client1.ref | 4 ++-- 6 files changed, 90 insertions(+), 11 deletions(-) diff --git a/DominoServer.py b/DominoServer.py index 5c5fbd4..9530170 100755 --- a/DominoServer.py +++ b/DominoServer.py @@ -14,7 +14,7 @@ import sys, os, glob, random, errno import getopt, socket import logging, json -import sqlite3 +import sqlite3, yaml #sys.path.append('gen-py') #sys.path.insert(0, glob.glob('./lib/py/build/lib.*')[0]) sys.path.insert(0, glob.glob('./lib')[0]) @@ -257,7 +257,8 @@ class CommunicationHandler: # Load tosca object from file into memory try: - tosca = ToscaTemplate( TOSCADIR+TOSCA_DEFAULT_FNAME ) + #tosca = ToscaTemplate( TOSCADIR+TOSCA_DEFAULT_FNAME ) + tpl = yaml.load(file(TOSCADIR+TOSCA_DEFAULT_FNAME,'r')) except: logging.error('Tosca Parser error: %s', sys.exc_info()[0]) #tosca file could not be read @@ -269,7 +270,7 @@ class CommunicationHandler: return pub_r # Extract Labels - node_labels = label.extract_labels( tosca ) + node_labels = label.extract_labels( tpl ) logging.debug('Node Labels: %s', node_labels) # Map nodes in the template to resource domains @@ -281,7 +282,7 @@ class CommunicationHandler: logging.debug('Selected Sites: %s', node_site) # Create per-domain Tosca files - file_paths = partitioner.partition_tosca('./toscafiles/template',node_site,tosca.tpl) + file_paths = partitioner.partition_tosca('./toscafiles/template',node_site,tpl) logging.debug('Per domain file paths: %s', file_paths) # Create work-flow diff --git a/domino_conf.py b/domino_conf.py index 644158b..146fd44 100644 --- a/domino_conf.py +++ b/domino_conf.py @@ -11,7 +11,7 @@ CLIENT_SEQNO = 0 DOMINO_SERVER_IP = 'localhost' DOMINO_CLI_PORT = 9100 -UDID_DESIRED = 12467 +UDID_DESIRED = 0 LIST_SUPPORTED_TEMPLATES = ['tosca-nfv-v1.0'] DEFAULT_TOSCA_PUBFILE = './tosca-templates/tosca_helloworld_nfv.yaml' TOSCA_RX_DIR = './toscafiles/' diff --git a/lib/mapper/label.py b/lib/mapper/label.py index 8591d7c..3298aea 100644 --- a/lib/mapper/label.py +++ b/lib/mapper/label.py @@ -10,12 +10,12 @@ #Parses policy rules, extracts targets, extracts policy properties #Returns set of policy properties for each target in a dictionary object #e.g., node_labels['VNF1'] = {label1, label2, ..., labeln} -def extract_labels(tosca): +def extract_labels(tpl): node_labels = dict() #stores labels for each node - if tosca.tpl.has_key('topology_template'): - if tosca.tpl['topology_template'].has_key('policies'): - policies = tosca.tpl['topology_template']['policies'] + if tpl.has_key('topology_template'): + if tpl['topology_template'].has_key('policies'): + policies = tpl['topology_template']['policies'] else: return node_labels else: diff --git a/tests/logdata/client1.log b/tests/logdata/client1.log index 665a331..c2ebd4b 100644 --- a/tests/logdata/client1.log +++ b/tests/logdata/client1.log @@ -1,3 +1,4 @@ +<<<<<<< HEAD 09/21/2016 10:08:40 AM Domino Client Starting... 09/21/2016 10:08:40 AM 1 Sending Registration 09/21/2016 10:08:40 AM Registration Response: Response Code: 1 @@ -31,3 +32,38 @@ 09/21/2016 10:08:50 AM subscribing labels ['tosca.policies.Placement.Geolocation:properties:region:us-west-1'] and templates [] 09/21/2016 10:08:50 AM Subscribe Response is received from: 0 ,sequence number: 10 09/21/2016 10:08:51 AM 12467 Received Template File +======= +11/17/2016 10:51:34 AM Domino Client Starting... +11/17/2016 10:51:34 AM 1 Sending Registration +11/17/2016 10:51:34 AM Registration Response: Response Code: 1 +11/17/2016 10:51:34 AM CLI Service is starting +11/17/2016 10:51:34 AM RPC service for CLI is starting... +11/17/2016 10:51:36 AM Received CLI ['heartbeat'] +11/17/2016 10:51:36 AM 0 Sending heartbeat +11/17/2016 10:51:36 AM heart beat received from: 0 ,sequence number: 2 +11/17/2016 10:51:37 AM Received CLI ['subscribe', '-t', 'hot', '-l', 'tosca.policies.Placement:properties:region:nova-1'] +11/17/2016 10:51:37 AM subscribing labels ['tosca.policies.Placement:properties:region:nova-1'] and templates ['hot'] +11/17/2016 10:51:37 AM Subscribe Response is received from: 0 ,sequence number: 3 +11/17/2016 10:51:38 AM Received CLI ['subscribe', '-t', 'dummy1,dummy2', '--top', 'OVERWRITE'] +11/17/2016 10:51:38 AM subscribing labels [] and templates ['dummy1', 'dummy2'] +11/17/2016 10:51:38 AM Subscribe Response is received from: 0 ,sequence number: 4 +11/17/2016 10:51:39 AM Received CLI ['subscribe', '-t', 'dummy1,dummy2', '--top', 'DELETE'] +11/17/2016 10:51:39 AM subscribing labels [] and templates ['dummy1', 'dummy2'] +11/17/2016 10:51:39 AM Subscribe Response is received from: 0 ,sequence number: 5 +11/17/2016 10:51:40 AM Received CLI ['subscribe', '-l', 'tosca.policies.Placement:properties:region:nova-2'] +11/17/2016 10:51:40 AM subscribing labels ['tosca.policies.Placement:properties:region:nova-2'] and templates [] +11/17/2016 10:51:40 AM Subscribe Response is received from: 0 ,sequence number: 6 +11/17/2016 10:51:41 AM Received CLI ['subscribe', '-l', 'tosca.policies.Placement:properties:region:nova-3', '--lop', 'OVERWRITE'] +11/17/2016 10:51:41 AM subscribing labels ['tosca.policies.Placement:properties:region:nova-3'] and templates [] +11/17/2016 10:51:41 AM Subscribe Response is received from: 0 ,sequence number: 7 +11/17/2016 10:51:42 AM Received CLI ['subscribe', '-l', 'tosca.policies.Placement:properties:region:nova-3', '--lop', 'DELETE'] +11/17/2016 10:51:42 AM subscribing labels ['tosca.policies.Placement:properties:region:nova-3'] and templates [] +11/17/2016 10:51:42 AM Subscribe Response is received from: 0 ,sequence number: 8 +11/17/2016 10:51:43 AM Received CLI ['publish', '-t', './tosca-templates/tosca_helloworld_nfv.yaml'] +11/17/2016 10:51:43 AM Publishing the template file: ./tosca-templates/tosca_helloworld_nfv.yaml +11/17/2016 10:51:43 AM Publish Response is received from: 0 ,sequence number: 9 Op. Status: 2 +11/17/2016 10:51:44 AM Received CLI ['subscribe', '-l', 'tosca.policies.Placement.Geolocation:properties:region:us-west-1'] +11/17/2016 10:51:44 AM subscribing labels ['tosca.policies.Placement.Geolocation:properties:region:us-west-1'] and templates [] +11/17/2016 10:51:44 AM Subscribe Response is received from: 0 ,sequence number: 10 +11/17/2016 10:51:45 AM 0 Received Template File +>>>>>>> e746280... Replace toscaparser with native yaml to load published Tosca file into memory diff --git a/tests/logdata/server.log b/tests/logdata/server.log index 0be15dc..9c60101 100644 --- a/tests/logdata/server.log +++ b/tests/logdata/server.log @@ -1,3 +1,4 @@ +<<<<<<< HEAD 09/21/2016 10:08:39 AM Domino Server Starting... 09/21/2016 10:08:40 AM Registration Request received for UDID 12467 from IP: 192.168.252.174 port: 9091 09/21/2016 10:08:41 AM Registration Request received for UDID 12467 from IP: 192.168.252.174 port: 9092 @@ -43,3 +44,44 @@ 09/21/2016 10:08:51 AM Selected Sites: {'VNF2': [], 'VNF3': [], 'VNF1': 12467} 09/21/2016 10:08:51 AM Per domain file paths: {12467: './toscafiles/template_part12467.yaml'} 09/21/2016 10:08:51 AM Push Response received from 12467 +======= +11/17/2016 10:51:33 AM Domino Server Starting... +11/17/2016 10:51:34 AM Registration Request received for UDID 0 from IP: 192.168.255.160 port: 9091 +11/17/2016 10:51:35 AM Registration Request received for UDID 0 from IP: 192.168.255.160 port: 9092 +11/17/2016 10:51:36 AM heartbeat received from 0 +11/17/2016 10:51:37 AM Subscribe Request received from 0 +11/17/2016 10:51:37 AM APPENDING Labels... +11/17/2016 10:51:37 AM Supported Template: set(['hot']) Supported Labels: set(['tosca.policies.Placement:properties:region:nova-1']) +11/17/2016 10:51:38 AM Subscribe Request received from 0 +11/17/2016 10:51:38 AM APPENDING Labels... +11/17/2016 10:51:38 AM Supported Template: set(['dummy2', 'dummy1']) Supported Labels: set(['tosca.policies.Placement:properties:region:nova-1']) +11/17/2016 10:51:39 AM Subscribe Request received from 0 +11/17/2016 10:51:39 AM APPENDING Labels... +11/17/2016 10:51:39 AM Supported Template: set([]) Supported Labels: set(['tosca.policies.Placement:properties:region:nova-1']) +11/17/2016 10:51:40 AM Subscribe Request received from 0 +11/17/2016 10:51:40 AM APPENDING Labels... +11/17/2016 10:51:40 AM Supported Template: set([]) Supported Labels: set(['tosca.policies.Placement:properties:region:nova-2', 'tosca.policies.Placement:properties:region:nova-1']) +11/17/2016 10:51:41 AM Subscribe Request received from 0 +11/17/2016 10:51:41 AM OVERWRITING Labels... +11/17/2016 10:51:41 AM Supported Template: set([]) Supported Labels: set(['tosca.policies.Placement:properties:region:nova-3']) +11/17/2016 10:51:42 AM Subscribe Request received from 0 +11/17/2016 10:51:42 AM DELETING Labels... +11/17/2016 10:51:42 AM Supported Template: set([]) Supported Labels: set([]) +11/17/2016 10:51:43 AM Publish Request received from 0 +11/17/2016 10:51:43 AM ['tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0', '', 'description: Template for deploying a single server with predefined properties.', '', 'metadata:', ' template_name: TOSCA NFV Sample Template', '', 'policy_types:', ' tosca.policies.Placement.Geolocation:', ' description: Geolocation policy', ' derived_from: tosca.policies.Placement', '', 'topology_template:', ' node_templates:', ' VNF1:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf1', ' vendor: acmetelco', ' version: 1.0', '', ' VNF2:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf2', ' vendor: ericsson', ' version: 1.0', '', ' VNF3:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf3', ' vendor: huawei', ' version: 1.0', '', ' policies:', ' - rule1:', ' type: tosca.policies.Placement.Geolocation', ' targets: [ VNF1 ]', ' properties:', ' region: [ us-west-1 ]', ' - rule2:', ' type: tosca.policies.Placement.Geolocation', ' targets: [ VNF2, VNF3 ]', ' properties:', ' region: [ us-west-1 , us-west-2 ]'] +11/17/2016 10:51:43 AM Node Labels: {'VNF2': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1', 'tosca.policies.Placement.Geolocation:properties:region:us-west-2']), 'VNF3': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1', 'tosca.policies.Placement.Geolocation:properties:region:us-west-2']), 'VNF1': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1'])} +11/17/2016 10:51:43 AM Site Maps: {'VNF2': set([]), 'VNF3': set([]), 'VNF1': set([])} +11/17/2016 10:51:43 AM Selected Sites: {'VNF2': [], 'VNF3': [], 'VNF1': []} +11/17/2016 10:51:43 AM Per domain file paths: {} +11/17/2016 10:51:44 AM Subscribe Request received from 0 +11/17/2016 10:51:44 AM APPENDING Labels... +11/17/2016 10:51:44 AM Supported Template: set([]) Supported Labels: set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1']) +11/17/2016 10:51:45 AM Publish Request received from 7835465092099811082 +11/17/2016 10:51:45 AM ['tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0', '', 'description: Template for deploying a single server with predefined properties.', '', 'metadata:', ' template_name: TOSCA NFV Sample Template', '', 'policy_types:', ' tosca.policies.Placement.Geolocation:', ' description: Geolocation policy', ' derived_from: tosca.policies.Placement', '', 'topology_template:', ' node_templates:', ' VNF1:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf1', ' vendor: acmetelco', ' version: 1.0', '', ' VNF2:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf2', ' vendor: ericsson', ' version: 1.0', '', ' VNF3:', ' type: tosca.nodes.nfv.VNF', ' properties:', ' id: vnf3', ' vendor: huawei', ' version: 1.0', '', ' policies:', ' - rule1:', ' type: tosca.policies.Placement.Geolocation', ' targets: [ VNF1 ]', ' properties:', ' region: [ us-west-1 ]', ' - rule2:', ' type: tosca.policies.Placement.Geolocation', ' targets: [ VNF2, VNF3 ]', ' properties:', ' region: [ us-west-1 , us-west-2 ]'] +11/17/2016 10:51:45 AM ERRNO 17; ./toscafiles/ exists. Creating: ./toscafiles/template1.yaml +11/17/2016 10:51:45 AM Node Labels: {'VNF2': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1', 'tosca.policies.Placement.Geolocation:properties:region:us-west-2']), 'VNF3': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1', 'tosca.policies.Placement.Geolocation:properties:region:us-west-2']), 'VNF1': set(['tosca.policies.Placement.Geolocation:properties:region:us-west-1'])} +11/17/2016 10:51:45 AM Site Maps: {'VNF2': set([]), 'VNF3': set([]), 'VNF1': set([0])} +11/17/2016 10:51:45 AM Selected Sites: {'VNF2': [], 'VNF3': [], 'VNF1': 0} +11/17/2016 10:51:45 AM Per domain file paths: {0: './toscafiles/template_part0.yaml'} +11/17/2016 10:51:45 AM Push Response received from 0 +>>>>>>> e746280... Replace toscaparser with native yaml to load published Tosca file into memory diff --git a/tests/refdata/test1_client1.ref b/tests/refdata/test1_client1.ref index 658b0e6..6ede273 100644 --- a/tests/refdata/test1_client1.ref +++ b/tests/refdata/test1_client1.ref @@ -4,7 +4,7 @@ Registration Response: Response Code: 1 CLI Service is starting RPC service for CLI is starting... Received CLI ['heartbeat'] -12467 Sending heartbeat +0 Sending heartbeat heart beat received from: 0 ,sequence number: 2 Received CLI ['subscribe', '-t', 'hot', '-l', 'tosca.policies.Placement:properties:region:nova-1'] subscribing labels ['tosca.policies.Placement:properties:region:nova-1'] and templates ['hot'] @@ -30,4 +30,4 @@ Publish Response is received from: 0 ,sequence number: 9 Op. Status: 2 Received CLI ['subscribe', '-l', 'tosca.policies.Placement.Geolocation:properties:region:us-west-1'] subscribing labels ['tosca.policies.Placement.Geolocation:properties:region:us-west-1'] and templates [] Subscribe Response is received from: 0 ,sequence number: 10 -12467 Received Template File +0 Received Template File -- cgit 1.2.3-korg