[CORD-2561]
Update E-CORD local test to new TOSCA engine, test directory style

Change-Id: Ia373402f7c82ace88decde4b7a8e8dc6c1a2fbfe
diff --git a/docs/dev_guide.md b/docs/dev_guide.md
index d2e0361..ec2f8b3 100644
--- a/docs/dev_guide.md
+++ b/docs/dev_guide.md
@@ -37,12 +37,12 @@
 * *ecord-mock.yml* for local sites, instead of the default value (rcord-mock.yml)
 * *ecord-global-single.yml* to mock global nodes, instead of the default value (rcord-mock.yml)
 
-### CORD-in-a-Box (CiaB) development
+### Virtual Pod (CiaB) development
 
-To understand what CiaB is and what it can help you with, look
+To understand what a Virtual Pod is and what it can help you with, look
 [here](/xos/dev/workflow_pod.md).
 
-To build E-CORD CiaB, follow the steps [here](/install_virtual.md).
+To build E-CORD Virtual Pod, follow the steps [here](/install_virtual.md).
 
 When it’s time to specify the PODCONFIG file, use
 
@@ -68,16 +68,39 @@
 
 ## Run an E-CORD test subscriber
 
-When using local PODs, you can emulate E-CORD test subscribers, doing the
-following.
+When using local PODs, you can emulate E-CORD test subscribers by running:
 
-1. ssh into the the head node
+```shell
+$ make ecord-test-local-subscriber
 
-2. `cd /opt/cord/build/platform-install`
+PLAY [Create E-CORD local test subscriber config and run test] ************************
 
-3. Deploy a test subscriber:
+TASK [Gathering Facts] ****************************************************************
+ok: [head1]
 
-    ```
-    ansible-playbook -i inventory/head-localhost --extra-vars "@/opt/cord_profile/genconfig/config.yml" ecord-test-subscriber-playbook.yml
-    ```
+TASK [test-ecord-local-subscriber : Create test-ecord-local-subsc**********************
+ok: [head1]
+
+TASK [test-ecord-local-subscriber : Read test-ecord-local-subscri**********************
+ok: [head1]
+
+TASK [test-ecord-local-subscriber : Run TOSCA to add E-CORD test-**********************
+ok: [head1]
+
+TASK [test-ecord-local-subscriber : Wait for vEG VM to come up] ***********************
+FAILED - RETRYING: Wait for vEG VM to come up (10 retries left).
+changed: [head1]
+
+TASK [test-ecord-local-subscriber : Get ID of VM] *************************************
+changed: [head1]
+
+TASK [test-ecord-local-subscriber : Get Management IP of VM] **************************
+changed: [head1]
+
+PLAY RECAP ****************************************************************************
+head1                      : ok=7    changed=3    unreachable=0    failed=0
+```
+
+If this completes successfully (no make error) then you've successfully created
+a test subscriber vEG VM.
 
diff --git a/test/ecord-test-local-subscriber-playbook.yml b/test/ecord-test-local-subscriber-playbook.yml
new file mode 100644
index 0000000..cbdd135
--- /dev/null
+++ b/test/ecord-test-local-subscriber-playbook.yml
@@ -0,0 +1,23 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# ecord-test-local-subscriber-playbook.yml
+# Configures and enables an E-CORD local subscriber, then runs test
+
+- name: Create E-CORD local test subscriber config and run test
+  hosts: head
+  roles:
+    - test-ecord-local-subscriber
+
diff --git a/test/roles/test-ecord-local-subscriber/defaults/main.yml b/test/roles/test-ecord-local-subscriber/defaults/main.yml
new file mode 100644
index 0000000..4b05773
--- /dev/null
+++ b/test/roles/test-ecord-local-subscriber/defaults/main.yml
@@ -0,0 +1,28 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# test-ecord-local-subscriber/defaults/main.yml
+
+xos_tosca_url: "http://xos-tosca/xos-tosca"
+
+config_credentials_dir: "{{ playbook_dir }}/../../../../build/platform-install/credentials"
+
+head_cord_profile_dir: "/opt/cord_profile"
+
+xos_admin_user: "xosadmin@opencord.org"
+xos_admin_pass: "{{ lookup('password', config_credentials_dir ~ '/xosadmin@opencord.org chars=ascii_letters,digits') }}"
+
+site_name: placeholder-sitename
+
diff --git a/test/roles/test-ecord-local-subscriber/tasks/main.yml b/test/roles/test-ecord-local-subscriber/tasks/main.yml
new file mode 100644
index 0000000..988d13c
--- /dev/null
+++ b/test/roles/test-ecord-local-subscriber/tasks/main.yml
@@ -0,0 +1,64 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# test-ecord-local-subscriber/tasks/main.yml
+
+- name: Create test-ecord-local-subscriber.yaml TOSCA config
+  template:
+    src: test-ecord-local-subscriber.yaml.j2
+    dest: "{{ head_cord_profile_dir }}/test-ecord-local-subscriber.yaml"
+    owner: "{{ ansible_user_id }}"
+    mode: 0644
+
+- name: Read test-ecord-local-subscriber.yaml
+  slurp:
+    src: "{{ head_cord_profile_dir }}/test-ecord-local-subscriber.yaml"
+  register: test_ecord_local_subscriber_slurp
+
+- name: Run TOSCA to add E-CORD test-subscriber
+  uri:
+    url: "{{ xos_tosca_url }}/run"
+    method: POST
+    headers:
+      xos-username: "{{ xos_admin_user }}"
+      xos-password: "{{ xos_admin_pass }}"
+    body: "{{ test_ecord_local_subscriber_slurp['content'] | b64decode }}"
+    status_code: 200
+  register: result
+  until: result | success
+  retries: 50
+  delay: 5
+
+- name: Wait for vEG VM to come up
+  shell: bash -c "source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep 'veg.*ACTIVE' > /dev/null"
+  register: result
+  until: result | success
+  retries: 10
+  delay: 60
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Get ID of VM
+  shell: bash -c "source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep {{ site_name }}_veg|cut -d '|' -f 2"
+  register: nova_id
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Get Management IP of VM
+  shell: bash -c "source /opt/cord_profile/admin-openrc.sh; nova interface-list {{ nova_id.stdout }}|grep -o -m 1 '172\.27\.[[:digit:]]*\.[[:digit:]]*'"
+  register: mgmt_ip
+  tags:
+    - skip_ansible_lint # running a sub job
+
diff --git a/test/roles/test-ecord-local-subscriber/templates/test-ecord-local-subscriber.yaml.j2 b/test/roles/test-ecord-local-subscriber/templates/test-ecord-local-subscriber.yaml.j2
new file mode 100644
index 0000000..7ffc11d
--- /dev/null
+++ b/test/roles/test-ecord-local-subscriber/templates/test-ecord-local-subscriber.yaml.j2
@@ -0,0 +1,127 @@
+---
+{#
+Copyright 2017-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Creates a CORD test subscriber, created by ecord profile
+
+imports:
+   - custom_types/site.yaml
+   - custom_types/slice.yaml
+   - custom_types/user.yaml
+   - custom_types/serviceinstance.yaml
+   - custom_types/serviceinstancelink.yaml
+   - custom_types/vegservice.yaml
+   - custom_types/vegtenant.yaml
+   - custom_types/veeservice.yaml
+   - custom_types/veeserviceinstance.yaml
+
+topology_template:
+  node_templates:
+
+# site, fully created in deployment.yaml
+    {{ site_name }}:
+      type: tosca.nodes.Site
+      properties:
+        name: {{ site_name }}
+        must-exist: true
+
+# veg slice, veg/vee services, fully created in ecord-services.yaml
+    {{ site_name }}_veg:
+      type: tosca.nodes.Slice
+      properties:
+        name: {{ site_name }}_veg
+        must-exist: true
+
+    service#vee:
+      type: tosca.nodes.VEEService
+      properties:
+        name: vee
+        must-exist: true
+
+    service#veg:
+      type: tosca.nodes.VEGService
+      requirements:
+      properties:
+        name: veg
+        must-exist: true
+
+# Test subscriber
+
+    # Let's add a user who can be administrator of the household
+    johndoe@myhouse.com:
+      type: tosca.nodes.User
+      properties:
+        username: johndoe@myhouse.com
+        email: johndoe@myhouse.com
+        password: letmein
+        firstname: john
+        lastname: doe
+      requirements:
+        - site:
+            node: {{ site_name }}
+            relationship: tosca.relationships.BelongsToOne
+
+    # A subscriber
+    my_enterprise:
+      type: tosca.nodes.ServiceInstance
+      properties:
+        name: my_enterprise
+        service_specific_id: "123"
+
+    my_vEG:
+      type: tosca.nodes.VEGTenant
+      properties:
+        name: my_vEG
+        service_specific_id: "123"
+      requirements:
+        - owner:
+            node: service#veg
+            relationship: tosca.relationships.BelongsToOne
+
+    my_vEE:
+      type: tosca.nodes.VEEServiceInstance
+      properties:
+        name: my_vEE
+        service_specific_id: "123"
+        s_tag: 123
+        c_tag: 123
+      requirements:
+        - owner:
+            node: service#vee
+            relationship: tosca.relationships.BelongsToOne
+
+    my_vEG_vEE_link:
+      type: tosca.nodes.ServiceInstanceLink
+      requirements:
+        - provider_service_instance:
+            node: my_vEG
+            relationship: tosca.relationships.BelongsToOne
+        - subscriber_service_instance:
+            node: my_vEE
+            relationship: tosca.relationships.BelongsToOne
+
+    my_vEE_enterprise_link:
+      type: tosca.nodes.ServiceInstanceLink
+      requirements:
+        - provider_service_instance:
+            node: my_vEE
+            relationship: tosca.relationships.BelongsToOne
+        - subscriber_service_instance:
+            node: my_enterprise
+            relationship: tosca.relationships.BelongsToOne
+