1 # ============LICENSE_START=======================================================
2 # csit-dcaegen2-collectors-hv-ves
3 # ================================================================================
4 # Copyright (C) 2018-2019 NOKIA
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 from VesHvContainersUtilsLibrary import VesHvContainersUtilsLibrary
20 from robot.api import logger
23 DCAE_APP_NAME = "DCAE App Simulator"
25 DCAE_APP_HOST = "dcae-app-simulator"
26 DCAE_APP_PORT = "6063"
27 DCAE_APP_ADDRESS = VesHvContainersUtilsLibrary().get_dcae_app_api_access_url("http://", DCAE_APP_HOST, DCAE_APP_PORT)
29 TOPIC_CONFIGURATION_PATH = DCAE_APP_ADDRESS + "/configuration/topics"
31 MESSAGES_PATH = "/messages/%s"
32 MESSAGES_RESET_PATH = DCAE_APP_ADDRESS + MESSAGES_PATH
33 MESSAGES_COUNT_PATH = DCAE_APP_ADDRESS + MESSAGES_PATH + "/count"
34 MESSAGES_VALIDATION_PATH = DCAE_APP_ADDRESS + MESSAGES_PATH + "/validate"
37 class DcaeAppSimulatorLibrary:
39 def configure_dcae_app_simulator_to_consume_messages_from_topics(self, topics):
40 app_url = TOPIC_CONFIGURATION_PATH
41 logger.info("PUT " + str(topics) + " at: " + app_url)
42 resp = HttpRequests.session_without_env().put(app_url, data=self.not_escaped(topics), timeout=10)
43 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
45 def not_escaped(self, data):
46 return json.dumps(data)
48 def assert_DCAE_app_consumed(self, topic, expected_messages_amount):
49 app_url = MESSAGES_COUNT_PATH % topic
50 logger.info("GET at: " + app_url)
51 resp = HttpRequests.session_without_env().get(app_url, timeout=10)
52 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
54 assert int(resp.content) == int(expected_messages_amount), \
55 "Messages consumed by simulator: " + str(resp.content) + " expecting: " + str(expected_messages_amount)
57 def reset_DCAE_app_simulator(self, topic):
58 app_url = MESSAGES_RESET_PATH % topic
59 logger.info("DELETE at: " + app_url)
60 resp = HttpRequests.session_without_env().delete(app_url, timeout=10)
61 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
63 def assert_DCAE_app_consumed_proper_messages(self, topic, message_filepath):
64 app_url = MESSAGES_VALIDATION_PATH % topic
65 file = open(message_filepath, "rb")
68 logger.info("POST " + str(data) + "at: " + app_url)
70 resp = HttpRequests.session_without_env().post(app_url, data=data, timeout=10)
71 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)