diff options
Diffstat (limited to 'vagrant/tests/generic_simulator')
-rw-r--r-- | vagrant/tests/generic_simulator/Dockerfile | 27 | ||||
-rw-r--r-- | vagrant/tests/generic_simulator/aai/responses.yml | 18 | ||||
-rw-r--r-- | vagrant/tests/generic_simulator/generic_sim.py | 109 | ||||
-rw-r--r-- | vagrant/tests/generic_simulator/requirements.txt | 11 |
4 files changed, 0 insertions, 165 deletions
diff --git a/vagrant/tests/generic_simulator/Dockerfile b/vagrant/tests/generic_simulator/Dockerfile deleted file mode 100644 index 202cafc6..00000000 --- a/vagrant/tests/generic_simulator/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-license-identifier: Apache-2.0 -############################################################################## -# Copyright (c) 2018 -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -FROM python:2.7 - -ARG HTTP_PROXY=${HTTP_PROXY} -ARG HTTPS_PROXY=${HTTPS_PROXY} - -ENV http_proxy $HTTP_PROXY -ENV https_proxy $HTTPS_PROXY - -EXPOSE 8080 - -RUN mkdir -p /{tmp,etc}/generic_sim - -WORKDIR /opt/generic_sim/ - -COPY . . -RUN pip install --no-cache-dir -r requirements.txt - -CMD [ "python", "generic_sim.py" ] diff --git a/vagrant/tests/generic_simulator/aai/responses.yml b/vagrant/tests/generic_simulator/aai/responses.yml deleted file mode 100644 index 041e5207..00000000 --- a/vagrant/tests/generic_simulator/aai/responses.yml +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-license-identifier: Apache-2.0 -############################################################################## -# Copyright (c) 2018 -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne: - GET: - body: '{"cloud-owner":"CloudOwner","cloud-region-id":"RegionOne","cloud-type":"openstack","owner-defined-type":"t1","cloud-region-version":"RegionOne","identity-url":"http://keystone:8080/v3","cloud-zone":"z1","complex-name":"clli1","sriov-automation":false,"cloud-extra-info":"","resource-version":"1524845154715"}' - content_type: application/json - status_code: 200 - PUT: - body: '' - content_type: application/json - status_code: 200 diff --git a/vagrant/tests/generic_simulator/generic_sim.py b/vagrant/tests/generic_simulator/generic_sim.py deleted file mode 100644 index 4392b652..00000000 --- a/vagrant/tests/generic_simulator/generic_sim.py +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2018 Intel Corporation, Inc -# 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. - -import json -import logging - -import web -from web import webapi -import yaml - -urls = ( - '/(.*)','MockController' -) - -def setup_logger(name, log_file, level=logging.DEBUG): - print("Configuring the logger...") - handler = logging.FileHandler(log_file) - formatter = logging.Formatter('%(message)s') - handler.setFormatter(formatter) - - logger = logging.getLogger(name) - logger.setLevel(level) - logger.addHandler(handler) - - return logger - - -class MockResponse: - def __init__(self, http_verb, status_code, - content_type="application/json", body="{}", - headers={}): - self.http_verb = http_verb.lower() - self.status_code = status_code - self.content_type = content_type - self.body = body - self.headers = headers - -def _parse_responses(parsed_responses): - result = {} - for path, responses in parsed_responses.iteritems(): - new_path = path - if path.startswith("/"): - new_path = path[1:] - - result[new_path] = [] - for http_verb, response in responses.iteritems(): - result[new_path].append(MockResponse(http_verb, **response)) - return result - -def load_responses(filename): - print("Loading responses from configuration file..") - with open(filename) as yaml_file: - responses_file = yaml.safe_load(yaml_file) - responses_map = _parse_responses(responses_file) - return responses_map - - -class MockController: - - def _do_action(self, action): - logger.info('{}'.format(web.ctx.env.get('wsgi.input').read())) - action = action.lower() - url = web.ctx['fullpath'] - try: - if url.startswith("/"): - url = url[1:] - response = [ r for r in responses_map[url] if r.http_verb == action][0] - for header, value in response.headers.iteritems(): - web.header(header, value) - web.header('Content-Type', response.content_type) - print(response.body) - return response.body - except: - webapi.NotFound() - - def DELETE(self, url): - return self._do_action("delete") - - def HEAD(self, url): - return self._do_action("head") - - def PUT(self, url): - return self._do_action("put") - - def GET(self, url): - return self._do_action("get") - - def POST(self, url): - return self._do_action("post") - - def PATCH(self, url): - return self._do_action("patch") - - -logger = setup_logger('mock_controller', '/tmp/generic_sim/output.log') -responses_map = load_responses('/etc/generic_sim/responses.yml') -app = web.application(urls, globals()) -if __name__ == "__main__": - app.run() diff --git a/vagrant/tests/generic_simulator/requirements.txt b/vagrant/tests/generic_simulator/requirements.txt deleted file mode 100644 index a0b6aae2..00000000 --- a/vagrant/tests/generic_simulator/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-license-identifier: Apache-2.0 -############################################################################## -# Copyright (c) 2018 -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -PyYAML -web.py |