Merge "Improve the deployment's creation and deletion"
This commit is contained in:
commit
b4faba7944
@ -22,6 +22,7 @@ import os
|
|||||||
import pprint
|
import pprint
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import jsonschema
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
@ -88,7 +89,12 @@ class DeploymentCommands(object):
|
|||||||
with open(filename, 'rb') as deploy_file:
|
with open(filename, 'rb') as deploy_file:
|
||||||
config = yaml.safe_load(deploy_file.read())
|
config = yaml.safe_load(deploy_file.read())
|
||||||
|
|
||||||
deployment = api.create_deploy(config, name)
|
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])
|
self.list(deployment_list=[deployment])
|
||||||
if do_use:
|
if do_use:
|
||||||
use.UseCommands().deployment(deployment['uuid'])
|
use.UseCommands().deployment(deployment['uuid'])
|
||||||
|
@ -66,7 +66,6 @@ class EngineFactory(object):
|
|||||||
def __init__(self, deployment):
|
def __init__(self, deployment):
|
||||||
self.deployment = deployment
|
self.deployment = deployment
|
||||||
self.config = deployment['config']
|
self.config = deployment['config']
|
||||||
self.validate()
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
# TODO(sskripnick): remove this checking when config schema
|
# TODO(sskripnick): remove this checking when config schema
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import jsonschema
|
||||||
|
|
||||||
from rally.benchmark import engine
|
from rally.benchmark import engine
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import deploy
|
from rally import deploy
|
||||||
@ -33,6 +35,14 @@ def create_deploy(config, name):
|
|||||||
deployment = objects.Deployment(name=name, config=config)
|
deployment = objects.Deployment(name=name, config=config)
|
||||||
deployer = deploy.EngineFactory.get_engine(deployment['config']['type'],
|
deployer = deploy.EngineFactory.get_engine(deployment['config']['type'],
|
||||||
deployment)
|
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:
|
with deployer:
|
||||||
endpoints = deployer.make_deploy()
|
endpoints = deployer.make_deploy()
|
||||||
deployment.update_endpoints(endpoints)
|
deployment.update_endpoints(endpoints)
|
||||||
|
@ -47,8 +47,9 @@ class DevstackEngineTestCase(test.TestCase):
|
|||||||
def test_invalid_config(self):
|
def test_invalid_config(self):
|
||||||
self.deployment = SAMPLE_CONFIG.copy()
|
self.deployment = SAMPLE_CONFIG.copy()
|
||||||
self.deployment['config'] = {'type': 42}
|
self.deployment['config'] = {'type': 42}
|
||||||
|
engine = devstack.DevstackEngine(self.deployment)
|
||||||
self.assertRaises(jsonschema.ValidationError,
|
self.assertRaises(jsonschema.ValidationError,
|
||||||
devstack.DevstackEngine, self.deployment)
|
engine.validate)
|
||||||
|
|
||||||
def test_construct(self):
|
def test_construct(self):
|
||||||
self.assertEqual(self.engine.localrc['ADMIN_PASSWORD'], 'secret')
|
self.assertEqual(self.engine.localrc['ADMIN_PASSWORD'], 'secret')
|
||||||
|
@ -47,10 +47,11 @@ class TestExistingCloud(test.TestCase):
|
|||||||
def test_init(self):
|
def test_init(self):
|
||||||
existing.ExistingCloud(self.deployment)
|
existing.ExistingCloud(self.deployment)
|
||||||
|
|
||||||
def test_init_invalid_config(self):
|
def test_invalid_config(self):
|
||||||
self.deployment["config"]["admin"] = 42
|
self.deployment["config"]["admin"] = 42
|
||||||
|
engine = existing.ExistingCloud(self.deployment)
|
||||||
self.assertRaises(jsonschema.ValidationError,
|
self.assertRaises(jsonschema.ValidationError,
|
||||||
existing.ExistingCloud, self.deployment)
|
engine.validate)
|
||||||
|
|
||||||
def test_deploy(self):
|
def test_deploy(self):
|
||||||
engine = existing.ExistingCloud(self.deployment)
|
engine = existing.ExistingCloud(self.deployment)
|
||||||
|
@ -51,8 +51,9 @@ class FuelEngineTestCase(test.TestCase):
|
|||||||
config = SAMPLE_CONFIG.copy()
|
config = SAMPLE_CONFIG.copy()
|
||||||
config['nodes'].pop('cinder+compute')
|
config['nodes'].pop('cinder+compute')
|
||||||
deployment = {'config': config}
|
deployment = {'config': config}
|
||||||
|
engine = fuel.FuelEngine(deployment)
|
||||||
self.assertRaises(exceptions.ValidationError,
|
self.assertRaises(exceptions.ValidationError,
|
||||||
fuel.FuelEngine, deployment)
|
engine.validate)
|
||||||
|
|
||||||
def test__get_nodes(self):
|
def test__get_nodes(self):
|
||||||
engine = fuel.FuelEngine(self.deployment)
|
engine = fuel.FuelEngine(self.deployment)
|
||||||
|
@ -43,7 +43,7 @@ class FakeDeployment(object):
|
|||||||
return self._values[name]
|
return self._values[name]
|
||||||
|
|
||||||
def update_status(self, status):
|
def update_status(self, status):
|
||||||
pass
|
self._values["status"] = status
|
||||||
|
|
||||||
def set_started(self):
|
def set_started(self):
|
||||||
pass
|
pass
|
||||||
@ -94,19 +94,13 @@ class EngineFake3(EngineFake2):
|
|||||||
class EngineFactoryTestCase(test.TestCase):
|
class EngineFactoryTestCase(test.TestCase):
|
||||||
FAKE_ENGINES = [EngineFake1, EngineFake2, EngineFake3]
|
FAKE_ENGINES = [EngineFake1, EngineFake2, EngineFake3]
|
||||||
|
|
||||||
@mock.patch.object(FakeEngine, 'validate')
|
def test_get_engine_not_found(self):
|
||||||
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):
|
|
||||||
deployment = make_fake_deployment()
|
deployment = make_fake_deployment()
|
||||||
self.assertRaises(exceptions.NoSuchEngine,
|
self.assertRaises(exceptions.NoSuchEngine,
|
||||||
deploy.EngineFactory.get_engine,
|
deploy.EngineFactory.get_engine,
|
||||||
"non_existing_engine", deployment)
|
"non_existing_engine", deployment)
|
||||||
mock_update_status.assert_called_once_with(
|
self.assertEqual(consts.DeployStatus.DEPLOY_FAILED,
|
||||||
consts.DeployStatus.DEPLOY_FAILED)
|
deployment['status'])
|
||||||
|
|
||||||
@mock.patch.object(FakeDeployment, 'set_completed')
|
@mock.patch.object(FakeDeployment, 'set_completed')
|
||||||
@mock.patch.object(FakeDeployment, 'set_started')
|
@mock.patch.object(FakeDeployment, 'set_started')
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
""" Test for orchestrator. """
|
""" Test for orchestrator. """
|
||||||
|
|
||||||
|
|
||||||
|
import jsonschema
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally import consts
|
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_update")
|
||||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
@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_create.return_value = self.deployment
|
||||||
mock_update.return_value = self.deployment
|
mock_update.return_value = self.deployment
|
||||||
api.create_deploy(self.deploy_config, "fake_deploy")
|
api.create_deploy(self.deploy_config, "fake_deploy")
|
||||||
@ -163,10 +165,25 @@ class APITestCase(test.TestCase):
|
|||||||
"name": "fake_deploy",
|
"name": "fake_deploy",
|
||||||
"config": self.deploy_config,
|
"config": self.deploy_config,
|
||||||
})
|
})
|
||||||
|
mock_validate.assert_called_with()
|
||||||
mock_update.assert_has_calls([
|
mock_update.assert_has_calls([
|
||||||
mock.call(self.deploy_uuid, self.endpoints)
|
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_delete")
|
||||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||||
@mock.patch("rally.objects.deploy.db.deployment_get")
|
@mock.patch("rally.objects.deploy.db.deployment_get")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user