Fix response code for get configdocs API

Includes unit tests verfiying this behavior

Change-Id: I5d00c92668ffa5fb58bd7d26dfb657416f004736
This commit is contained in:
Bryan Strassner 2017-11-21 09:20:15 -06:00
parent b6d7af07fa
commit 7f1f5319d2
7 changed files with 189 additions and 55 deletions

View File

@ -70,7 +70,7 @@ class ConfigDocsResource(BaseResource):
version=version
)
resp.append_header('Content-Type', 'application/x-yaml')
resp.status = falcon.HTTP_201
resp.status = falcon.HTTP_200
def _validate_version_parameter(self, version):
# performs validation of version parameter

View File

@ -0,0 +1,69 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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 logging
from oslo_config import cfg
import shipyard_airflow.control.api as api
from shipyard_airflow import policy
from shipyard_airflow.conf import config
from shipyard_airflow.db import db
CONF = cfg.CONF
def start_shipyard(default_config_files=None):
"""Initializer for shipyard service.
Sets up global options before setting up API endpoints.
"""
# Trigger configuration resolution.
config.parse_args(args=[], default_config_files=default_config_files)
# Setup root logger
base_console_handler = logging.StreamHandler()
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[base_console_handler])
logging.getLogger().info("Setting logging level to: %s",
logging.getLevelName(CONF.logging.log_level))
logging.basicConfig(level=CONF.logging.log_level,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[base_console_handler])
# Specalized format for API logging
logger = logging.getLogger('shipyard.control')
logger.propagate = False
formatter = logging.Formatter(
('%(asctime)s - %(levelname)s - %(user)s - %(req_id)s - '
'%(external_ctx)s - %(message)s'))
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# Setup the RBAC policy enforcer
policy.policy_engine = policy.ShipyardPolicy()
policy.policy_engine.register_policy()
# Upgrade database
if CONF.base.upgrade_db:
# this is a reasonable place to put any online alembic upgrades
# desired. Currently only shipyard db is under shipyard control.
db.SHIPYARD_DB.update_db()
# Start the API
return api.start_api()

View File

@ -11,62 +11,15 @@
# 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 logging
"""Entrypoint module for shipyard.
from oslo_config import cfg
import shipyard_airflow.control.api as api
from shipyard_airflow import policy
from shipyard_airflow.conf import config
from shipyard_airflow.db import db
CONF = cfg.CONF
Bootstraps to the start_shipyard module.
"""
from shipyard_airflow.control.start_shipyard import start_shipyard
def start_shipyard():
# Trigger configuration resolution.
config.parse_args()
# Setup root logger
base_console_handler = logging.StreamHandler()
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[base_console_handler])
logging.getLogger().info("Setting logging level to: %s",
logging.getLevelName(CONF.logging.log_level))
logging.basicConfig(level=CONF.logging.log_level,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[base_console_handler])
# Specalized format for API logging
logger = logging.getLogger('shipyard.control')
logger.propagate = False
formatter = logging.Formatter(
('%(asctime)s - %(levelname)s - %(user)s - %(req_id)s - '
'%(external_ctx)s - %(message)s'))
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# Setup the RBAC policy enforcer
policy.policy_engine = policy.ShipyardPolicy()
policy.policy_engine.register_policy()
# Upgrade database
if CONF.base.upgrade_db:
# this is a reasonable place to put any online alembic upgrades
# desired. Currently only shipyard db is under shipyard control.
db.SHIPYARD_DB.update_db()
# Start the API
return api.start_api()
# Initialization compatible with PasteDeploy
def paste_start_shipyard(global_conf, **kwargs):
"""Paste deploy compatible initializer"""
return shipyard

View File

@ -0,0 +1,36 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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.
AUTH_HEADERS = {
'X-SERVICE-IDENTITY-STATUS': 'Confirmed',
'X-IDENTITY-STATUS': 'Confirmed',
'X-SERVICE-USER-NAME': 'testauth',
'X-USER-NAME': 'testauth',
'X-SERVICE-USER-ID': 'testauth',
'X-USER-ID': 'testauth',
'X-SERVICE-USER-DOMAIN-ID': 'default',
'X-USER-DOMAIN-ID': 'default',
'X-SERVICE-PROJECT-ID': 'default',
'X-PROJECT-ID': 'default',
'X-SERVICE-PROJECT-DOMAIN-ID': 'default',
'X-PROJECT-DOMAIN-NAME': 'default',
'X-SERVICE-ROLES': 'Admin',
'X-ROLES': 'Admin',
'X-IS-ADMIN-PROJECT': 'True'
}
def str_responder(*args, **kwargs):
"""Responds with an empty string"""
return ''

View File

@ -0,0 +1,29 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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 os
from falcon import testing
import pytest
from shipyard_airflow.control.start_shipyard import start_shipyard
@pytest.fixture()
def api_client():
"""Testing client for the Shipyard API"""
cur_dir = os.path.dirname(__file__)
filename = os.path.join(cur_dir, 'test.conf')
return testing.TestClient(
start_shipyard(default_config_files=[filename])
)

View File

@ -0,0 +1,39 @@
[armada]
service_type = armada
[base]
upgrade_db = false
postgresql_airflow_db = postgresql+psycopg2://airflow:password@postgresql.ucp.svc.cluster.local:5432/airflow
postgresql_db = postgresql+psycopg2://shipyard:password@postgresql.ucp.svc.cluster.local:5432/shipyard
web_server = http://airflow-web-int.ucp.svc.cluster.local:8080/
[deckhand]
service_type = deckhand
[drydock]
deploy_node_query_interval = 30
deploy_node_task_timeout = 3600
prepare_node_query_interval = 30
prepare_node_task_timeout = 1800
prepare_site_query_interval = 10
prepare_site_task_timeout = 120
service_type = physicalprovisioner
verify_site_query_interval = 10
verify_site_task_timeout = 60
[healthcheck]
endpoint = /api/v1.0/health
schema = http
[keystone_authtoken]
auth_section = keystone_authtoken
auth_type = password
auth_uri = http://keystone-api.ucp.svc.cluster.local:80/v3
auth_url = http://keystone-api.ucp.svc.cluster.local:80/v3
auth_version = v3
delay_auth_decision = true
memcache_secret_key = zwe6wa59AykCCMk4ucOwEbAkmLSXLOYRharO39FYHY0WYlQnxMwTIJna6NBzJskm
memcache_security_strategy = None
memcached_servers = memcached.ucp.svc.cluster.local:11211
password = password
project_domain_name = default
project_name = service
user_domain_name = default
username = shipyard
[shipyard]
service_type = shipyard

View File

@ -11,12 +11,12 @@
# 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.
""" Tests for the configdocs_api
"""
""" Tests for the configdocs_api"""
from mock import patch
import pytest
from tests.unit.control import common
from shipyard_airflow.control.configdocs.configdocs_api import (
CommitConfigDocsResource,
ConfigDocsResource
@ -147,3 +147,11 @@ def test_commit_configdocs_buffer_err():
helper.is_buffer_empty = lambda: True
helper.get_validations_for_buffer = lambda: {'status': 'Valid'}
ccdr.commit_configdocs(helper, False)
@patch.object(ConfigDocsResource, 'get_collection', common.str_responder)
def test_configdocs_on_get(api_client):
"""Validate the on_get method returns 200 on success"""
result = api_client.simulate_get("/api/v1.0/configdocs/coll1",
headers=common.AUTH_HEADERS)
assert result.status_code == 200