CORD-2858 adding xos-rest-api-test playbook

Change-Id: Ibff445f86e9d921e73a473e76794ac85c811b2dc
diff --git a/roles/xos-rest-api-test/defaults/main.yml b/roles/xos-rest-api-test/defaults/main.yml
new file mode 100644
index 0000000..8b61830
--- /dev/null
+++ b/roles/xos-rest-api-test/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.
+
+credentials_dir: "{{ playbook_dir }}/credentials"
+config_cord_dir: "{{ ( playbook_dir ~ '/../..' ) | realpath }}"
+cord_test_dir: "{{ config_cord_dir }}/test/cord-tester/src/test/cord-api"
+
+xos_admin_user: "xosadmin@opencord.org"
+xos_admin_pass: "{{ lookup('password', credentials_dir ~ '/xosadmin@opencord.org chars=ascii_letters,digits') }}"
+
+api_test_server_ip: "0.0.0.0"
+api_test_server_port: "9101"
diff --git a/roles/xos-rest-api-test/tasks/main.yml b/roles/xos-rest-api-test/tasks/main.yml
new file mode 100644
index 0000000..b6ae394
--- /dev/null
+++ b/roles/xos-rest-api-test/tasks/main.yml
@@ -0,0 +1,62 @@
+---
+# 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.
+
+- name: Replace SERVER_IP in API Properties
+  replace:
+    dest: "{{ cord_test_dir }}/Properties/RestApiProperties.py"
+    regexp: "SERVER_IP = '.+'$"
+    replace: "SERVER_IP = '{{ api_test_server_ip }}'"
+    backup: yes
+
+- name: Replace SERVER_PORT in API Properties
+  replace:
+    dest: "{{ cord_test_dir }}/Properties/RestApiProperties.py"
+    regexp: "SERVER_PORT = '.+'$"
+    replace: "SERVER_PORT = '{{ api_test_server_port }}'"
+
+- name: Replace USER in API Properties
+  replace:
+    dest: "{{ cord_test_dir }}/Properties/RestApiProperties.py"
+    regexp: "USER = '.+'$"
+    replace: "USER = '{{ xos_admin_user }}'"
+
+- name: Replace PASSWD in API Properties
+  lineinfile:
+    dest: "{{ cord_test_dir }}/Properties/RestApiProperties.py"
+    regexp: "^PASSWD"
+    line: "PASSWD = '{{ xos_admin_pass }}'"
+
+- name: Get List of Tests to run
+  find:
+    paths: "{{ cord_test_dir }}/Tests"
+    patterns: '*.robot'
+  register: api_tests
+
+- name: Run Core API Tests
+  command: >
+    pybot
+      -v xos_service:{{ item | regex_replace('.*/(\w+)_service_api.robot$', '\1' ) }}
+      -e ControllerImages
+      -e ContollerUser
+      -e ContollerSlice
+      -e Port
+      -e TenantWithContainer
+      -e AddressManagerServiceInstance {{ item }}
+  args:
+    chdir: "../../test/cord-tester/src/test/cord-api/Tests"
+  with_items: "{{ api_tests.files | map(attribute='path') | list }}"
+  register: cmdout
+  tags:
+    - skip_ansible_lint # pybot execution
diff --git a/xos-api-test-playbook.yml b/xos-api-test-playbook.yml
new file mode 100644
index 0000000..e168f46
--- /dev/null
+++ b/xos-api-test-playbook.yml
@@ -0,0 +1,22 @@
+---
+# 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.
+
+# xos-api-test-playbook.yml
+
+- name: Execute api tests
+  hosts: all
+  roles:
+   - xos-rest-api-test
+