SEBA-557 implement xos test service
Change-Id: I21ab4c9139a3be7e68cfff8ef506100f8fe3a2c3
diff --git a/testservice/scripts/cleanup.sh b/testservice/scripts/cleanup.sh
new file mode 100755
index 0000000..ad39431
--- /dev/null
+++ b/testservice/scripts/cleanup.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# 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_URL=http://`hostname`:30007
+RECIPE=../tosca/test_no_constraints.yaml
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @$RECIPE $TOSCA_URL/delete
diff --git a/testservice/scripts/cycle.sh b/testservice/scripts/cycle.sh
new file mode 100755
index 0000000..7426b42
--- /dev/null
+++ b/testservice/scripts/cycle.sh
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+# 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.
+
+pushd ~/cord/orchestration/xos/testservice/scripts
+helm del --purge testservice
+./rebuild.sh
+./deploy.sh
+popd
diff --git a/testservice/scripts/deploy.sh b/testservice/scripts/deploy.sh
new file mode 100755
index 0000000..7909a3c
--- /dev/null
+++ b/testservice/scripts/deploy.sh
@@ -0,0 +1,20 @@
+#! /bin/bash
+
+# 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.
+
+pushd ~/cord/orchestration/xos/testservice/helm-charts
+#helm dep update testservice
+helm install testservice -n testservice -f testservice-devel.yaml
+popd
diff --git a/testservice/scripts/rebuild.sh b/testservice/scripts/rebuild.sh
new file mode 100755
index 0000000..6f6d38b
--- /dev/null
+++ b/testservice/scripts/rebuild.sh
@@ -0,0 +1,19 @@
+#! /bin/bash
+
+# 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.
+
+pushd ~/cord/orchestration/xos/testservice
+sudo docker build -t xosproject/testservice-synchronizer:candidate -f Dockerfile.synchronizer .
+popd
diff --git a/testservice/scripts/test_no_constraints.sh b/testservice/scripts/test_no_constraints.sh
new file mode 100755
index 0000000..dd58a85
--- /dev/null
+++ b/testservice/scripts/test_no_constraints.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CHAMELEON_URL=http://`hostname`:30006/xosapi/v1/testservice/testserviceserviceinstances
+TOSCA_URL=http://`hostname`:30007
+TEST_POD=`kubectl get pods | grep -i testservice | cut -f 1 -d " "`
+RECIPE=../tosca/test_no_constraints.yaml
+
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X post --data-binary @$RECIPE $TOSCA_URL/run
+
+echo "done tosca"
+
+cat <<EOF > wait_for.txt
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-no-constraints' some_integer=0 some_other_integer=0
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-no-constraints' some_integer=0 some_other_integer=0
+EOF
+kubectl logs -f --since=30s $TEST_POD | ansi2txt | python wait_for_lines.py wait_for.txt
+
+python ./verify_model.py $CHAMELEON_URL name=test-no-constraints "updated>=0" "enacted>=@updated" "policed>=@updated"
diff --git a/testservice/scripts/test_policy_after_sync.sh b/testservice/scripts/test_policy_after_sync.sh
new file mode 100755
index 0000000..090b373
--- /dev/null
+++ b/testservice/scripts/test_policy_after_sync.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CHAMELEON_URL=http://`hostname`:30006/xosapi/v1/testservice/testserviceserviceinstances
+TOSCA_URL=http://`hostname`:30007
+TEST_POD=`kubectl get pods | grep -i testservice | cut -f 1 -d " "`
+RECIPE=../tosca/test_policy_after_sync.yaml
+
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X post --data-binary @$RECIPE $TOSCA_URL/run
+
+echo "done tosca"
+
+cat <<EOF > wait_for.txt
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-policy-after-sync' some_integer=0 some_other_integer=0
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-policy-after-sync' some_integer=0 some_other_integer=0
+EOF
+kubectl logs -f --since=30s $TEST_POD | ansi2txt | python wait_for_lines.py wait_for.txt
+
+python ./verify_model.py $CHAMELEON_URL name=test-policy-after-sync "updated>=0" "enacted>=@updated" "policed>=@updated"
diff --git a/testservice/scripts/test_policy_after_sync_update.sh b/testservice/scripts/test_policy_after_sync_update.sh
new file mode 100755
index 0000000..b3cbbfa
--- /dev/null
+++ b/testservice/scripts/test_policy_after_sync_update.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CHAMELEON_URL=http://`hostname`:30006/xosapi/v1/testservice/testserviceserviceinstances
+TOSCA_URL=http://`hostname`:30007
+TEST_POD=`kubectl get pods | grep -i testservice | cut -f 1 -d " "`
+RECIPE=../tosca/test_policy_after_sync_update.yaml
+
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X post --data-binary @$RECIPE $TOSCA_URL/run
+
+echo "done tosca"
+
+cat <<EOF > wait_for.txt
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-policy-after-sync-update' some_integer=0 some_other_integer=0
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-policy-after-sync-update' some_integer=0 some_other_integer=1
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-policy-after-sync-update' some_integer=0 some_other_integer=1
+EOF
+kubectl logs -f --since=30s $TEST_POD | ansi2txt | python wait_for_lines.py wait_for.txt
+
+python ./verify_model.py $CHAMELEON_URL name=test-policy-after-sync-update "updated>=0" "policed>=@updated" "enacted>=@policed" "some_other_integer=1"
diff --git a/testservice/scripts/test_sync_after_policy.sh b/testservice/scripts/test_sync_after_policy.sh
new file mode 100755
index 0000000..2daf7ef
--- /dev/null
+++ b/testservice/scripts/test_sync_after_policy.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CHAMELEON_URL=http://`hostname`:30006/xosapi/v1/testservice/testserviceserviceinstances
+TOSCA_URL=http://`hostname`:30007
+TEST_POD=`kubectl get pods | grep -i testservice | cut -f 1 -d " "`
+RECIPE=../tosca/test_sync_after_policy.yaml
+
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X post --data-binary @$RECIPE $TOSCA_URL/run
+
+echo "done tosca"
+
+cat <<EOF > wait_for.txt
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-sync-after-policy' some_integer=0 some_other_integer=0
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-sync-after-policy' some_integer=0 some_other_integer=0
+EOF
+kubectl logs -f --since=30s $TEST_POD | ansi2txt | python wait_for_lines.py wait_for.txt
+
+python ./verify_model.py $CHAMELEON_URL name=test-sync-after-policy "updated>=0" "enacted>=@updated" "policed>=@updated"
diff --git a/testservice/scripts/test_sync_after_policy_update.sh b/testservice/scripts/test_sync_after_policy_update.sh
new file mode 100755
index 0000000..e7f2112
--- /dev/null
+++ b/testservice/scripts/test_sync_after_policy_update.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CHAMELEON_URL=http://`hostname`:30006/xosapi/v1/testservice/testserviceserviceinstances
+TOSCA_URL=http://`hostname`:30007
+TEST_POD=`kubectl get pods | grep -i testservice | cut -f 1 -d " "`
+RECIPE=../tosca/test_sync_after_policy_update.yaml
+
+curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X post --data-binary @$RECIPE $TOSCA_URL/run
+
+echo "done tosca"
+
+cat <<EOF > wait_for.txt
+TEST:SYNC_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-sync-after-policy-update' some_integer=1 some_other_integer=0
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-sync-after-policy-update' some_integer=0 some_other_integer=0
+TEST:POLICY_DONE id=[0-9]+ model_class=TestserviceServiceInstance model_name=u'test-sync-after-policy-update' some_integer=1 some_other_integer=0
+EOF
+kubectl logs -f --since=30s $TEST_POD | ansi2txt | python wait_for_lines.py wait_for.txt
+
+python ./verify_model.py $CHAMELEON_URL name=test-sync-after-policy-update "updated>=0" "enacted>=@updated" "policed>=@enacted" "some_integer=1"
diff --git a/testservice/scripts/verify_model.py b/testservice/scripts/verify_model.py
new file mode 100755
index 0000000..a895940
--- /dev/null
+++ b/testservice/scripts/verify_model.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+# 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.
+
+from __future__ import absolute_import, print_function
+
+import requests
+import sys
+
+
+def matches(test, item):
+ if ">=" in test:
+ delim = ">="
+ elif ">" in test:
+ delim = ">"
+ elif "=" in test:
+ delim = "="
+ (name, value) = test.split(delim, 1)
+ if value.startswith("@"):
+ value = item[value[1:]]
+
+ if delim == ">":
+ if float(item[name]) > float(value):
+ return True
+
+ if delim == ">=":
+ if float(item[name]) >= float(value):
+ return True
+
+ if delim == "=":
+ if str(item[name]) == str(value):
+ return True
+ return False
+
+
+def main():
+ url = sys.argv[1]
+ tests = sys.argv[2:]
+
+ r = requests.get(url, auth=("admin@opencord.org", "letmein"))
+ for item in r.json()["items"]:
+ okay = True
+ for test in tests:
+ if not matches(test, item):
+ okay = False
+ if okay:
+ print("matched")
+ sys.exit(0)
+
+ print("Not Matched")
+ sys.exit(-1)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/testservice/scripts/wait_for_lines.py b/testservice/scripts/wait_for_lines.py
new file mode 100755
index 0000000..089978f
--- /dev/null
+++ b/testservice/scripts/wait_for_lines.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+# 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.
+
+from __future__ import absolute_import, print_function
+
+import re
+import signal
+import sys
+
+
+def handler(signum, frame):
+ print "Timed Out"
+ sys.exit(-1)
+
+
+signal.signal(signal.SIGALRM, handler)
+signal.alarm(60) # timeout in 60 seconds
+
+waitlines = open(sys.argv[1]).readlines()
+waitlines = [x.strip() for x in waitlines]
+
+while True:
+ if not waitlines:
+ print("all lines matched")
+ break
+ line = sys.stdin.readline()
+ line = line.strip()
+ for pattern in waitlines[:]:
+ if re.match(pattern, line):
+ print("matched", pattern)
+ waitlines.remove(pattern)