Playbook for setting up XOS for MWC demo

Change-Id: I43ca514c2d16f757715d8047478b91c35c6ddab7
diff --git a/test/mcord-cavium-test-playbook.yml b/test/mcord-cavium-test-playbook.yml
new file mode 100644
index 0000000..794852a
--- /dev/null
+++ b/test/mcord-cavium-test-playbook.yml
@@ -0,0 +1,69 @@
+
+# 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.
+
+
+---
+# mcord-ng40-test-playbook.yml
+# Tests CiaB cord-pod XOS configuration
+
+- name: Run base M-CORD tests
+  hosts: head
+  become: no
+  # These variables could be elevated to the profile. Think about
+  # doing this after the E2E test framework is complete.
+  vars:
+    test_networks:
+      - management
+      - sgi_network
+      - s11_network
+      - spgw_network
+      - s6a_network
+      - db_network
+      - flat_network_s1mme
+      - flat_network_s1u
+    test_services:
+      - vmme
+      - vhss
+      - hssdb
+      - vspgwc
+      - vspgwu
+    test_ports:
+      - { vm: vmme, network: management }
+      - { vm: vmme, network: s11_network }
+      - { vm: vmme, network: s6a_network }
+      - { vm: vmme, network: flat_network_s1mme }
+      - { vm: vhss, network: management }
+      - { vm: vhss, network: s6a_network }
+      - { vm: vhss, network: db_network }
+      - { vm: hssdb, network: management }
+      - { vm: hssdb, network: db_network }
+      - { vm: vspgwc, network: management }
+      - { vm: vspgwc, network: s11_network }
+      - { vm: vspgwc, network: spgw_network }
+      - { vm: vspgwu, network: management }
+      - { vm: vspgwu, network: flat_network_s1u }
+      - { vm: vspgwu, network: sgi_network }
+      - { vm: vspgwu, network: spgw_network }
+    epc_blueprint: mcord_5
+    epc_sync_objects:
+      - vspgwu/vspgwutenants
+      - vspgwc/vspgwctenants
+      - vmme/vmmetenants
+      - vhss/vhsstenants
+      - hssdb/hssdbserviceinstances
+  roles:
+    - create-epc
+    - test-mcord-base
+    - epc-synced
diff --git a/test/mcord-mwc-demo-playbook.yml b/test/mcord-mwc-demo-playbook.yml
new file mode 100644
index 0000000..71372c5
--- /dev/null
+++ b/test/mcord-mwc-demo-playbook.yml
@@ -0,0 +1,74 @@
+
+# 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.
+
+
+---
+# mcord-mwc-demo-playbook.yml
+# Set up XOS for the MWC 2018 demos
+
+- name: Run base M-CORD tests
+  hosts: head
+  become: no
+  # These variables could be elevated to the profile. Think about
+  # doing this after the E2E test framework is complete.
+  vars:
+    test_networks:
+      - management
+      - sgi_network
+      - s11_network
+      - spgw_network
+      - s6a_network
+      - db_network
+      - flat_network_s1mme
+      - flat_network_s1u
+    test_services:
+      - vmme
+      - vhss
+      - hssdb
+      - vspgwc
+      - vspgwu
+      - internetemulator
+    test_ports:
+      - { vm: vmme, network: management }
+      - { vm: vmme, network: s11_network }
+      - { vm: vmme, network: s6a_network }
+      - { vm: vmme, network: flat_network_s1mme }
+      - { vm: vhss, network: management }
+      - { vm: vhss, network: s6a_network }
+      - { vm: vhss, network: db_network }
+      - { vm: hssdb, network: management }
+      - { vm: hssdb, network: db_network }
+      - { vm: vspgwc, network: management }
+      - { vm: vspgwc, network: s11_network }
+      - { vm: vspgwc, network: spgw_network }
+      - { vm: vspgwu, network: management }
+      - { vm: vspgwu, network: flat_network_s1u }
+      - { vm: vspgwu, network: sgi_network }
+      - { vm: vspgwu, network: spgw_network }
+      - { vm: internetemulator, network: management }
+      - { vm: internetemulator, network: sgi_network }
+    epc_blueprint: mcord_5
+    epc_sync_objects:
+      - internetemulator/internetemulatorserviceinstances
+      - hssdb/hssdbserviceinstances
+      - vhss/vhsstenants
+      - vmme/vmmetenants
+      - vspgwu/vspgwutenants
+      - vspgwc/vspgwctenants
+  roles:
+    - create-internetemulator
+    - create-epc
+    - test-mcord-base
+    - epc-synced
diff --git a/test/mcord-ng40-test-playbook.yml b/test/mcord-ng40-test-playbook.yml
new file mode 100644
index 0000000..2f906a3
--- /dev/null
+++ b/test/mcord-ng40-test-playbook.yml
@@ -0,0 +1,57 @@
+
+# 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.
+
+
+---
+# mcord-ng40-test-playbook.yml
+# Tests CiaB cord-pod XOS configuration
+
+- name: Run base M-CORD tests
+  hosts: head
+  become: no
+  # These variables could be elevated to the profile. Think about
+  # doing this after the E2E test framework is complete.
+  vars:
+    test_networks:
+      - management
+      - sgi_network
+      - s11_network
+      - spgw_network
+    test_services:
+      - venb
+      - vspgwc
+      - vspgwu
+    test_ports:
+      - { vm: venb, network: management }
+      - { vm: venb, network: s11_network }
+      - { vm: venb, network: sgi_network }
+      - { vm: venb, network: s1u_network }
+      - { vm: vspgwc, network: management }
+      - { vm: vspgwc, network: s11_network }
+      - { vm: vspgwc, network: spgw_network }
+      - { vm: vspgwu, network: management }
+      - { vm: vspgwu, network: s1u_network }
+      - { vm: vspgwu, network: sgi_network }
+      - { vm: vspgwu, network: spgw_network }
+    epc_blueprint: build
+    epc_sync_objects:
+      - vspgwu/vspgwutenants
+      - vspgwc/vspgwctenants
+      - venb/venbserviceinstances
+  roles:
+    - create-epc
+    - test-mcord-base
+    - epc-synced
+    - run-ng40
diff --git a/test/roles/create-epc/defaults/main.yml b/test/roles/create-epc/defaults/main.yml
new file mode 100644
index 0000000..6d0c586
--- /dev/null
+++ b/test/roles/create-epc/defaults/main.yml
@@ -0,0 +1,24 @@
+---
+
+# 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.
+
+# roles/create-epc/defaults/main.yml
+
+config_credentials_dir: "{{ playbook_dir }}/../../../../build/platform-install/credentials"
+
+xos_admin_user: "xosadmin@opencord.org"
+xos_admin_pass: "{{ lookup('file', config_credentials_dir ~ '/' ~ xos_admin_user) }}"
+
+epc_blueprint: "build"
diff --git a/test/roles/create-epc/tasks/main.yml b/test/roles/create-epc/tasks/main.yml
new file mode 100644
index 0000000..ddad05f
--- /dev/null
+++ b/test/roles/create-epc/tasks/main.yml
@@ -0,0 +1,47 @@
+---
+
+# 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.
+
+# roles/create-epc/tasks/main.yml
+
+- name: Check for EPC ServiceInstance
+  uri:
+    url: http://localhost/xosapi/v1/vepc/vepcserviceinstances
+    user: "{{ xos_admin_user }}"
+    password: "{{ xos_admin_pass }}"
+    return_content: yes
+  register: result
+
+- name: Get EPC Service ID
+  uri:
+    url: http://localhost/xosapi/v1/vepc/vepcservices
+    user: "{{ xos_admin_user }}"
+    password: "{{ xos_admin_pass }}"
+    return_content: yes
+  register: vepcservice
+  when: not result.json["items"]
+
+- name: Create EPC
+  uri:
+    url: http://localhost/xosapi/v1/vepc/vepcserviceinstances
+    user: "{{ xos_admin_user }}"
+    password: "{{ xos_admin_pass }}"
+    method: POST
+    body:
+      blueprint: "{{ epc_blueprint }}"
+      owner_id: "{{ vepcservice.json['items'][0]['id'] }}"
+      site_id: 1
+    body_format: json
+  when: not result.json["items"]
diff --git a/test/roles/create-internetemulator/defaults/main.yml b/test/roles/create-internetemulator/defaults/main.yml
new file mode 100644
index 0000000..2ef239f
--- /dev/null
+++ b/test/roles/create-internetemulator/defaults/main.yml
@@ -0,0 +1,24 @@
+---
+
+# 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.
+
+# roles/create-internetemulator/defaults/main.yml
+
+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('file', config_credentials_dir ~ '/' ~ xos_admin_user) }}"
+xos_tosca_url: "http://xos-tosca/xos-tosca"
diff --git a/test/roles/create-internetemulator/tasks/main.yml b/test/roles/create-internetemulator/tasks/main.yml
new file mode 100644
index 0000000..94eea1d
--- /dev/null
+++ b/test/roles/create-internetemulator/tasks/main.yml
@@ -0,0 +1,41 @@
+---
+
+# 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.
+
+# roles/create-internetemulator/tasks/main.yml
+
+- name: TOSCA to create internetemulator
+  template:
+    src: "internetemulator.yaml.j2"
+    dest: "{{ head_cord_profile_dir }}/internetemulator.yaml"
+
+- name: Read internetemulator.yaml
+  slurp:
+    src: "{{ head_cord_profile_dir }}/internetemulator.yaml"
+  register: slurpfile
+
+- name: Add InternetEmulatorServiceInstance via TOSCA
+  uri:
+    url: "{{ xos_tosca_url }}/run"
+    method: POST
+    headers:
+      xos-username: "{{ xos_admin_user }}"
+      xos-password: "{{ xos_admin_pass }}"
+    body: "{{ slurpfile['content'] | b64decode }}"
+    status_code: 200
+  register: result
+  until: result | success
+  retries: 50
+  delay: 5
diff --git a/test/roles/create-internetemulator/templates/internetemulator.yaml.j2 b/test/roles/create-internetemulator/templates/internetemulator.yaml.j2
new file mode 100644
index 0000000..3d075e2
--- /dev/null
+++ b/test/roles/create-internetemulator/templates/internetemulator.yaml.j2
@@ -0,0 +1,43 @@
+{#
+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
+
+imports:
+   - custom_types/xos.yaml
+   - custom_types/internetemulatorservice.yaml
+   - custom_types/internetemulatorserviceinstance.yaml
+
+description: configure an internetemulatorserviceinstance
+
+topology_template:
+  node_templates:
+
+    internetemulator:
+      type: tosca.nodes.InternetEmulatorService
+      properties:
+        name: internetemulator
+        must-exist: true
+
+    internetemulator_serviceinstance:
+      type: tosca.nodes.InternetEmulatorServiceInstance
+      properties:
+        name: VLC video server
+      requirements:
+        - owner:
+            node: internetemulator
+            relationship: tosca.relationships.BelongsToOne
diff --git a/test/roles/epc-synced/defaults/main.yml b/test/roles/epc-synced/defaults/main.yml
new file mode 100644
index 0000000..f8747e3
--- /dev/null
+++ b/test/roles/epc-synced/defaults/main.yml
@@ -0,0 +1,24 @@
+---
+
+# 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.
+
+# roles/epc-synced/defaults/main.yml
+
+config_credentials_dir: "{{ playbook_dir }}/../../../../build/platform-install/credentials"
+
+xos_admin_user: "xosadmin@opencord.org"
+xos_admin_pass: "{{ lookup('file', config_credentials_dir ~ '/' ~ xos_admin_user) }}"
+
+epc_sync_objects: []
diff --git a/test/roles/epc-synced/tasks/main.yml b/test/roles/epc-synced/tasks/main.yml
new file mode 100644
index 0000000..996a069
--- /dev/null
+++ b/test/roles/epc-synced/tasks/main.yml
@@ -0,0 +1,29 @@
+---
+
+# 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.
+
+# roles/epc-synced/tasks/main.yml
+
+- name: Wait for synchronizers to run
+  uri:
+    url: http://localhost/xosapi/v1/{{ item }}
+    user: "{{ xos_admin_user }}"
+    password: "{{ xos_admin_pass }}"
+    return_content: yes
+  register: result
+  until: result.json["items"] and result.json["items"][0]["backend_status"] == "OK"
+  retries: 20
+  delay: 30
+  with_items: "{{ epc_sync_objects }}"
diff --git a/test/roles/test-mcord-base/defaults/main.yml b/test/roles/test-mcord-base/defaults/main.yml
new file mode 100644
index 0000000..f4572f7
--- /dev/null
+++ b/test/roles/test-mcord-base/defaults/main.yml
@@ -0,0 +1,48 @@
+---
+# 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-mcord-base/defaults/main.yml
+
+test_networks:
+  - management
+  - sgi_network
+  - s11_network
+  - s1mme_network
+  - sbi_network
+  - nbi_network
+
+test_services:
+  - internetemulator
+  - vmme
+  - vspgwc
+  - sdncontroller
+  - vspgwu
+
+test_ports:
+  - { vm: vmme, network: management }
+  - { vm: vmme, network: s11_network }
+  - { vm: vmme, network: s1mme_network }
+  - { vm: vspgwc, network: management }
+  - { vm: vspgwc, network: s11_network }
+  - { vm: vspgwc, network: nbi_network }
+  - { vm: sdncontroller, network: management }
+  - { vm: sdncontroller, network: nbi_network }
+  - { vm: sdncontroller, network: sbi_network }
+  - { vm: vspgwu, network: management }
+  - { vm: vspgwu, network: s1u_network }
+  - { vm: vspgwu, network: sgi_network }
+  - { vm: vspgwu, network: sbi_network }
+  - { vm: internetemulator, network: management }
+  - { vm: internetemulator, network: sgi_network }
diff --git a/test/roles/test-mcord-base/tasks/main.yml b/test/roles/test-mcord-base/tasks/main.yml
new file mode 100644
index 0000000..111e019
--- /dev/null
+++ b/test/roles/test-mcord-base/tasks/main.yml
@@ -0,0 +1,68 @@
+---
+# 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-mcord-base/tasks/main.yml
+# Run tests to check that the base elements of M-CORD are present
+
+- name: Wait for networks to be synchronized
+  shell: source /opt/cord_profile/admin-openrc.sh; neutron net-list|grep '{{ item }}' > /dev/null
+  args:
+    executable: /bin/bash
+  register: result
+  until: result | success
+  retries: 10
+  delay: 60
+  with_items: "{{ test_networks }}"
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Wait for VMs to appear in Nova
+  shell: source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep '{{ item }}' > /dev/null
+  args:
+    executable: /bin/bash
+  register: result
+  until: result | success
+  retries: 10
+  delay: 60
+  with_items: "{{ test_services }}"
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Delete any VMs that are in ERROR state (XOS will re-create them)
+  shell: source /opt/cord_profile/admin-openrc.sh; for vm in $(nova list --all-tenants|grep 'ERROR'|awk '{ print $2 }'); do nova delete $vm; done
+  args:
+    executable: /bin/bash
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Wait for VMs to come up
+  shell: source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep '{{ item }}.*ACTIVE' > /dev/null
+  args:
+    executable: /bin/bash
+  register: result
+  until: result | success
+  retries: 10
+  delay: 60
+  with_items: "{{ test_services }}"
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Verify that VMs are properly networked
+  shell: source /opt/cord_profile/admin-openrc.sh; nova list --all-tenants|grep '{{ item.vm }}.*ACTIVE.*{{ item.network }}' > /dev/null
+  args:
+    executable: /bin/bash
+  with_items: "{{ test_ports }}"
+  tags:
+    - skip_ansible_lint # running a sub job