CORD-2117 configure exampleservice using new tosca engine

Change-Id: I211ffb9eb85dcf58c9eeab5b7a5669fb9877a169
diff --git a/roles/exampleservice-config/templates/test-exampleservice.yaml.j2 b/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
index c7c9af8..a5c7708 100644
--- a/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
+++ b/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
@@ -1,4 +1,3 @@
-
 {#
 Copyright 2017-present Open Networking Foundation
 
@@ -18,121 +17,146 @@
 
 tosca_definitions_version: tosca_simple_yaml_1_0
 
-description: Setup the ExampleService on the pod
-
 imports:
    - custom_types/xos.yaml
+   - custom_types/slice.yaml
+   - custom_types/site.yaml
+   - custom_types/image.yaml
+   - custom_types/flavor.yaml
+   - custom_types/network.yaml
+   - custom_types/networktemplate.yaml
+   - custom_types/networkslice.yaml
    - custom_types/exampleservice.yaml
+   - custom_types/exampleserviceinstance.yaml
+
+description: configure exampleservice
 
 topology_template:
   node_templates:
 
-# image/flavor are hardcoded - FIXME if/when they change
+# site, image, fully created in deployment.yaml
+    {{ site_name }}:
+      type: tosca.nodes.Site
+      properties:
+        must-exist: true
+        name: {{ site_humanname }}
+
     m1.small:
       type: tosca.nodes.Flavor
+      properties:
+        name: m1.small
+        must-exist: true
 
     trusty-server-multi-nic:
       type: tosca.nodes.Image
+      properties:
+        name: trusty-server-multi-nic
+        must-exist: true
 
-# private network template, created in fixtures.yml
-    Private:
+# private network template, fully created somewhere else
+    private:
       type: tosca.nodes.NetworkTemplate
-
-# site, fully created in deployment.yaml
-    {{ site_name }}:
-      type: tosca.nodes.Site
-
-# management network, fully created in management-net.yaml
-    management:
-      type: tosca.nodes.network.Network.XOS
       properties:
-        no-create: true
-        no-delete: true
-        no-update: true
+        must-exist: true
+        name: Private
 
-# public network, fully created in public-net.yaml
-    public:
-      type: tosca.nodes.network.Network.XOS
+# management networks, fully created in management-net.yaml
+    management_network:
+      type: tosca.nodes.Network
       properties:
-        no-create: true
-        no-delete: true
-        no-update: true
+        must-exist: true
+        name: management
 
-# vrouter service, fully created in cord-service.yaml
-    service#vrouter:
-      type: tosca.nodes.Service
+# public network, fully created somewhere else
+    public_network:
+      type: tosca.nodes.Network
       properties:
-        no-create: true
-        no-delete: true
-        no-update: true
+        must-exist: true
+        name: public
 
-# ExampleService/ExampleTenant
     exampleservice_network:
-      type: tosca.nodes.network.Network.XOS
+      type: tosca.nodes.Network
       properties:
-          ip_version: 4
+          name: exampleservice_network
           labels: exampleservice_private_network
       requirements:
-          - network_template:
-              node: Private
-              relationship: tosca.relationships.UsesNetworkTemplate
+          - template:
+              node: private
+              relationship: tosca.relationships.BelongsToOne
           - owner:
               node: {{ site_name }}_exampleservice
-              relationship: tosca.relationships.MemberOfSlice
-          - connection:
-              node: {{ site_name }}_exampleservice
-              relationship: tosca.relationships.ConnectsToSlice
+              relationship: tosca.relationships.BelongsToOne
 
-
+# CORD Slices
     {{ site_name }}_exampleservice:
-      description: This slice holds the ExampleService
+      description: Example Service Slice
       type: tosca.nodes.Slice
       properties:
-        network: noauto
+          name: {{ site_name }}_exampleservice
+          default_isolation: vm
+          network: noauto
       requirements:
-        - site:
-            node: {{ site_name }}
-            relationship: tosca.relationships.MemberOfSite
-        - management:
-            node: management
-            relationship: tosca.relationships.ConnectsToNetwork
-        - public:
-            node: public
-            relationship: tosca.relationships.ConnectsToNetwork
-        - exmapleserver:
-            node: service#exampleservice
-            relationship: tosca.relationships.MemberOfService
-        - image:
-            node: trusty-server-multi-nic
-            relationship: tosca.relationships.DefaultImage
-        - default_flavor:
-            node: m1.small
-            relationship: tosca.relationships.DefaultFlavor
+          - site:
+              node: mysite
+              relationship: tosca.relationships.BelongsToOne
+          - service:
+              node: exampleservice
+              relationship: tosca.relationships.BelongsToOne
+          - default_image:
+              node: trusty-server-multi-nic
+              relationship: tosca.relationships.BelongsToOne
+          - default_flavor:
+              node: m1.small
+              relationship: tosca.relationships.BelongsToOne
 
-    service#exampleservice:
-      type: tosca.nodes.ExampleService
+# CORD NetworkSlices
+    exampleservice_slice_management_network:
+      type: tosca.nodes.NetworkSlice
       requirements:
-        - management:
-            node: management
-            relationship: tosca.relationships.UsesNetwork
+        - network:
+            node: management_network
+            relationship: tosca.relationships.BelongsToOne
+        - slice:
+            node: {{ site_name }}_exampleservice
+            relationship: tosca.relationships.BelongsToOne
+
+    exampleservice_slice_public_network:
+      type: tosca.nodes.NetworkSlice
+      requirements:
+        - network:
+            node: public_network
+            relationship: tosca.relationships.BelongsToOne
+        - slice:
+            node: {{ site_name }}_exampleservice
+            relationship: tosca.relationships.BelongsToOne
+
+    exampleservice_slice_exampleservice_network:
+      type: tosca.nodes.NetworkSlice
+      requirements:
+        - network:
+            node: exampleservice_network
+            relationship: tosca.relationships.BelongsToOne
+        - slice:
+            node: {{ site_name }}_exampleservice
+            relationship: tosca.relationships.BelongsToOne
+
+    exampleservice:
+      type: tosca.nodes.ExampleService
       properties:
-        view_url: /admin/exampleservice/exampleservice/$id$/
-        kind: exampleservice
-        public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
+        name: exampleservice
+        public_key: {{ lookup('file', config_cord_profile_dir + '/key_import/exampleservice_rsa.pub') }}
         private_key_fn: /opt/xos/services/exampleservice/keys/exampleservice_rsa
         service_message: hello
       artifacts:
         pubkey: /opt/cord_profile/key_import/exampleservice_rsa.pub
 
-    tenant#exampletenant1:
-      type: tosca.nodes.ExampleTenant
+    exampletenant1:
+      type: tosca.nodes.ExampleServiceInstance
       properties:
+        name: exampletenant1
         tenant_message: world
       requirements:
-        - tenant:
-            node: service#exampleservice
-            relationship: tosca.relationships.TenantOfService
-        - dependency:
-            node: {{ site_name }}_exampleservice
-            relationship: tosca.relationships.DependsOn
+        - owner:
+            node: exampleservice
+            relationship: tosca.relationships.BelongsToOne
 
diff --git a/roles/test-exampleservice/defaults/main.yml b/roles/test-exampleservice/defaults/main.yml
index c6c615f..7e9c125 100644
--- a/roles/test-exampleservice/defaults/main.yml
+++ b/roles/test-exampleservice/defaults/main.yml
@@ -19,6 +19,12 @@
 
 xos_ui_port: 9000
 
+xos_tosca_host: "xos-tosca"
+
+head_credentials_dir: "/opt/credentials"
+
 xos_admin_user: "xosadmin@opencord.org"
+xos_admin_pass: "{{ lookup('password', head_credentials_dir ~ '/xosadmin@opencord.org chars=ascii_letters,digits') }}"
+
 maas_xos_admin_pass: "{{ lookup('file', '/opt/credentials/xosadmin@opencord.org') }}"
 
diff --git a/roles/test-exampleservice/tasks/main.yml b/roles/test-exampleservice/tasks/main.yml
index 168697f..c5bc324 100644
--- a/roles/test-exampleservice/tasks/main.yml
+++ b/roles/test-exampleservice/tasks/main.yml
@@ -18,12 +18,17 @@
 # test-examplservice/tasks/main.yml
 # Run tests to check that the single-node deployment has worked
 
-- name: Load TOSCA to apply test config for ExampleService, over REST
-  xostosca:
-    url: "http://xos.{{ site_suffix }}:{{ xos_ui_port }}/api/utility/tosca/run/"
-    user: "{{ xos_admin_user }}"
-    password:  "{{ maas_xos_admin_pass }}"
-    recipe: "{{ lookup('file', head_cord_profile_dir + '/test-exampleservice.yaml' ) }}"
+- name: Configure XOS with profile specific TOSCA (new Engine)
+  uri:
+    url: "http://{{ xos_tosca_host }}/xos-tosca/run"
+    method: POST
+    headers:
+      xos-username: "{{ xos_admin_user }}"
+      xos-password: "{{ xos_admin_pass }}"
+    body: "{{ lookup('file', head_cord_profile_dir + '/test-exampleservice.yaml' ) }}"
+    status_code: 200
+  tags:
+    - skip_ansible_lint # TOSCA loading should be idempotent
 
 - name: Wait for ExampleService VM to come up
   shell: bash -c "source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep 'exampleservice.*ACTIVE' > /dev/null"