Merge "Improve the deployment's creation and deletion"

This commit is contained in:
Jenkins 2014-10-13 18:16:10 +00:00 committed by Gerrit Code Review
commit b4faba7944
8 changed files with 46 additions and 17 deletions

View File

@ -22,6 +22,7 @@ import os
import pprint
import sys
import jsonschema
import yaml
from rally.cmd import cliutils
@ -88,7 +89,12 @@ class DeploymentCommands(object):
with open(filename, 'rb') as deploy_file:
config = yaml.safe_load(deploy_file.read())
try:
deployment = api.create_deploy(config, name)
except jsonschema.ValidationError:
print(_("Config schema validation error: %s.") % sys.exc_info()[1])
return(1)
self.list(deployment_list=[deployment])
if do_use:
use.UseCommands().deployment(deployment['uuid'])

View File

@ -66,7 +66,6 @@ class EngineFactory(object):
def __init__(self, deployment):
self.deployment = deployment
self.config = deployment['config']
self.validate()
def validate(self):
# TODO(sskripnick): remove this checking when config schema

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import jsonschema
from rally.benchmark import engine
from rally import consts
from rally import deploy
@ -33,6 +35,14 @@ def create_deploy(config, name):
deployment = objects.Deployment(name=name, config=config)
deployer = deploy.EngineFactory.get_engine(deployment['config']['type'],
deployment)
try:
deployer.validate()
except jsonschema.ValidationError:
LOG.error(_('Deployment %(uuid)s: Schema validation error.') %
{'uuid': deployment['uuid']})
deployment.update_status(consts.DeployStatus.DEPLOY_FAILED)
raise
with deployer:
endpoints = deployer.make_deploy()
deployment.update_endpoints(endpoints)

View File

@ -47,8 +47,9 @@ class DevstackEngineTestCase(test.TestCase):
def test_invalid_config(self):
self.deployment = SAMPLE_CONFIG.copy()
self.deployment['config'] = {'type': 42}
engine = devstack.DevstackEngine(self.deployment)
self.assertRaises(jsonschema.ValidationError,
devstack.DevstackEngine, self.deployment)
engine.validate)
def test_construct(self):
self.assertEqual(self.engine.localrc['ADMIN_PASSWORD'], 'secret')

View File

@ -47,10 +47,11 @@ class TestExistingCloud(test.TestCase):
def test_init(self):
existing.ExistingCloud(self.deployment)
def test_init_invalid_config(self):
def test_invalid_config(self):
self.deployment["config"]["admin"] = 42
engine = existing.ExistingCloud(self.deployment)
self.assertRaises(jsonschema.ValidationError,
existing.ExistingCloud, self.deployment)
engine.validate)
def test_deploy(self):
engine = existing.ExistingCloud(self.deployment)

View File

@ -51,8 +51,9 @@ class FuelEngineTestCase(test.TestCase):
config = SAMPLE_CONFIG.copy()
config['nodes'].pop('cinder+compute')
deployment = {'config': config}
engine = fuel.FuelEngine(deployment)
self.assertRaises(exceptions.ValidationError,
fuel.FuelEngine, deployment)
engine.validate)
def test__get_nodes(self):
engine = fuel.FuelEngine(self.deployment)

View File

@ -43,7 +43,7 @@ class FakeDeployment(object):
return self._values[name]
def update_status(self, status):
pass
self._values["status"] = status
def set_started(self):
pass
@ -94,19 +94,13 @@ class EngineFake3(EngineFake2):
class EngineFactoryTestCase(test.TestCase):
FAKE_ENGINES = [EngineFake1, EngineFake2, EngineFake3]
@mock.patch.object(FakeEngine, 'validate')
def test_init(self, fake_validate):
FakeEngine({'config': {}})
fake_validate.assert_called_once_with()
@mock.patch.object(FakeDeployment, 'update_status')
def test_get_engine_not_found(self, mock_update_status):
def test_get_engine_not_found(self):
deployment = make_fake_deployment()
self.assertRaises(exceptions.NoSuchEngine,
deploy.EngineFactory.get_engine,
"non_existing_engine", deployment)
mock_update_status.assert_called_once_with(
consts.DeployStatus.DEPLOY_FAILED)
self.assertEqual(consts.DeployStatus.DEPLOY_FAILED,
deployment['status'])
@mock.patch.object(FakeDeployment, 'set_completed')
@mock.patch.object(FakeDeployment, 'set_started')

View File

@ -16,6 +16,7 @@
""" Test for orchestrator. """
import jsonschema
import mock
from rally import consts
@ -155,7 +156,8 @@ class APITestCase(test.TestCase):
@mock.patch("rally.objects.deploy.db.deployment_update")
@mock.patch("rally.objects.deploy.db.deployment_create")
def test_create_deploy(self, mock_create, mock_update):
@mock.patch("rally.deploy.engine.EngineFactory.validate")
def test_create_deploy(self, mock_validate, mock_create, mock_update):
mock_create.return_value = self.deployment
mock_update.return_value = self.deployment
api.create_deploy(self.deploy_config, "fake_deploy")
@ -163,10 +165,25 @@ class APITestCase(test.TestCase):
"name": "fake_deploy",
"config": self.deploy_config,
})
mock_validate.assert_called_with()
mock_update.assert_has_calls([
mock.call(self.deploy_uuid, self.endpoints)
])
@mock.patch("rally.objects.deploy.db.deployment_update")
@mock.patch("rally.objects.deploy.db.deployment_create")
@mock.patch("rally.deploy.engine.EngineFactory.validate",
side_effect=jsonschema.ValidationError('ValidationError'))
def test_create_deploy_validation_error(self, mock_validate, mock_create,
mock_update):
mock_create.return_value = self.deployment
self.assertRaises(jsonschema.ValidationError,
api.create_deploy,
self.deploy_config, "fake_deploy")
mock_update.assert_called_once_with(
self.deploy_uuid,
{'status': consts.DeployStatus.DEPLOY_FAILED})
@mock.patch("rally.objects.deploy.db.deployment_delete")
@mock.patch("rally.objects.deploy.db.deployment_update")
@mock.patch("rally.objects.deploy.db.deployment_get")