Changes handler inherited from abstract

Change-Id: I9f89e3bddc696dfd0a01646e6ee5913717887f12
This commit is contained in:
Nikolay Markov 2014-03-11 19:43:31 +04:00
parent 4a9e4032f1
commit 22b2ab52e3
6 changed files with 33 additions and 57 deletions

View File

@ -258,7 +258,15 @@ class DeferredTaskHandler(BaseHandler):
* 404 (environment is not found)
* 409 (task with such parameters already exists)
"""
cluster = self.get_object_or_404(Cluster, cluster_id)
cluster = self.get_object_or_404(
Cluster,
cluster_id,
log_404=(
u"warning",
u"Error: there is no cluster "
u"with id '{0}' in DB.".format(cluster_id)
)
)
logger.info(self.log_message.format(env_id=cluster_id))

View File

@ -27,10 +27,6 @@ from nailgun.api.handlers.base import DeferredTaskHandler
from nailgun.api.handlers.base import content_json
from nailgun.api.serializers.network_configuration \
import NeutronNetworkConfigurationSerializer
from nailgun.api.serializers.network_configuration \
import NovaNetworkConfigurationSerializer
from nailgun.api.validators.cluster import AttributesValidator
from nailgun.api.validators.cluster import ClusterValidator
from nailgun.db import db
@ -40,7 +36,6 @@ from nailgun.db.sqlalchemy.models import Node
from nailgun.db.sqlalchemy.models import Release
from nailgun.errors import errors
from nailgun.logger import logger
from nailgun.objects import Task
from nailgun.task.manager import ApplyChangesTaskManager
from nailgun.task.manager import ClusterDeletionManager
from nailgun.task.manager import ResetEnvironmentTaskManager
@ -221,54 +216,12 @@ class ClusterCollectionHandler(BaseHandler):
raise web.badrequest(e.message)
class ClusterChangesHandler(BaseHandler):
"""Cluster changes handler
"""
class ClusterChangesHandler(DeferredTaskHandler):
fields = (
"id",
"name",
)
@content_json
def PUT(self, cluster_id):
""":returns: JSONized Task object.
:http: * 200 (task successfully executed)
* 404 (cluster not found in db)
* 400 (failed to execute task)
"""
cluster = self.get_object_or_404(
Cluster,
cluster_id,
log_404=(
"warning",
"Error: there is no cluster "
"with id '{0}' in DB.".format(cluster_id)
)
)
if cluster.net_provider == 'nova_network':
net_serializer = NovaNetworkConfigurationSerializer
elif cluster.net_provider == 'neutron':
net_serializer = NeutronNetworkConfigurationSerializer
try:
network_info = net_serializer.serialize_for_cluster(cluster)
logger.info(
u"Network info:\n{0}".format(
json.dumps(network_info, indent=4)
)
)
task_manager = ApplyChangesTaskManager(
cluster_id=cluster.id
)
task = task_manager.execute()
except Exception as exc:
logger.warn(u'ClusterChangesHandler: error while execution'
' deploy task: {0}'.format(str(exc)))
raise web.badrequest(str(exc))
return Task.to_json(task)
log_message = u"Trying to start deployment at environment '{env_id}'"
log_error = u"Error during execution of deployment " \
u"task on environment '{env_id}': {error}"
task_manager = ApplyChangesTaskManager
class ClusterStopDeploymentHandler(DeferredTaskHandler):

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import traceback
from nailgun.api.serializers.network_configuration \
@ -74,7 +75,21 @@ class ApplyChangesTaskManager(TaskManager):
def execute(self):
logger.info(
u"Trying to start deployment at cluster '{0}'".format(
self.cluster.name or self.cluster.id))
self.cluster.name or self.cluster.id
)
)
if self.cluster.net_provider == 'nova_network':
net_serializer = NovaNetworkConfigurationSerializer
elif self.cluster.net_provider == 'neutron':
net_serializer = NeutronNetworkConfigurationSerializer
network_info = net_serializer.serialize_for_cluster(self.cluster)
logger.info(
u"Network info:\n{0}".format(
json.dumps(network_info, indent=4)
)
)
current_tasks = db().query(Task).filter_by(
cluster_id=self.cluster.id,

View File

@ -515,7 +515,7 @@ class Environment(object):
'ClusterChangesHandler',
kwargs={'cluster_id': self.clusters[0].id}),
headers=self.default_headers)
self.tester.assertEquals(200, resp.status)
self.tester.assertEquals(202, resp.status)
response = json.loads(resp.body)
return self.db.query(Task).filter_by(
uuid=response['uuid']

View File

@ -530,7 +530,7 @@ class TestAdminNetworkConfiguration(BaseIntegrationTest):
def test_deploy_error_when_admin_cidr_match_other_network_cidr(self):
resp = self.env.cluster_changes_put(self.cluster['id'],
expect_errors=True)
self.assertEquals(resp.status, 200)
self.assertEquals(resp.status, 202)
task = json.loads(resp.body)
self.assertEquals(task['status'], 'error')
self.assertEquals(task['progress'], 100)

View File

@ -47,7 +47,7 @@ class TestNetworkChecking(BaseIntegrationTest):
def set_cluster_changes_w_error(self, cluster_id):
resp = self.env.cluster_changes_put(cluster_id,
expect_errors=True)
self.assertEquals(resp.status, 200)
self.assertEquals(resp.status, 202)
task = json.loads(resp.body)
self.assertEquals(task['status'], 'error')
self.assertEquals(task['progress'], 100)