Add overcloud parameters set
to set Heat params in a plan
Closes-Bug: #1616351 Change-Id: Id0fb75c4fd277a6e69df6625f95440aa04e9ab61
This commit is contained in:
parent
c03ed23272
commit
cbd9f748d3
@ -71,6 +71,7 @@ openstack.tripleoclient.v1 =
|
||||
overcloud_node_import = tripleoclient.v1.overcloud_node:ImportNode
|
||||
overcloud_node_introspect = tripleoclient.v1.overcloud_node:IntrospectNode
|
||||
overcloud_node_provide = tripleoclient.v1.overcloud_node:ProvideNode
|
||||
overcloud_parameters_set = tripleoclient.v1.overcloud_parameters:SetParameters
|
||||
overcloud_plan_create = tripleoclient.v1.overcloud_plan:CreatePlan
|
||||
overcloud_plan_delete = tripleoclient.v1.overcloud_plan:DeletePlan
|
||||
overcloud_plan_list = tripleoclient.v1.overcloud_plan:ListPlans
|
||||
|
84
tripleoclient/tests/v1/test_overcloud_parameters.py
Normal file
84
tripleoclient/tests/v1/test_overcloud_parameters.py
Normal file
@ -0,0 +1,84 @@
|
||||
# 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 mock
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from openstackclient.tests import utils
|
||||
import yaml
|
||||
|
||||
from tripleoclient import exceptions
|
||||
from tripleoclient.v1 import overcloud_parameters
|
||||
|
||||
|
||||
class TestSetParameters(utils.TestCommand):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSetParameters, self).setUp()
|
||||
|
||||
self.cmd = overcloud_parameters.SetParameters(self.app, None)
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
|
||||
def _test_set_parameters(self, extension, dumper, data):
|
||||
|
||||
# Setup
|
||||
with tempfile.NamedTemporaryFile(
|
||||
suffix=extension, delete=False, mode="wt") as params_file:
|
||||
self.addCleanup(os.unlink, params_file.name)
|
||||
params_file.write(dumper(data))
|
||||
|
||||
arglist = ['overcast', params_file.name]
|
||||
verifylist = [
|
||||
('name', 'overcast')
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.workflow.action_executions.create.return_value = mock.MagicMock(
|
||||
output=json.dumps({
|
||||
"result": None
|
||||
})
|
||||
)
|
||||
|
||||
# Run
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# Verify
|
||||
self.workflow.action_executions.create.assert_called_once_with(
|
||||
'tripleo.update_parameters',
|
||||
{
|
||||
'container': 'overcast',
|
||||
'parameters': data.get('parameter_defaults', data)
|
||||
})
|
||||
|
||||
def test_json_params_file(self):
|
||||
self._test_set_parameters(".json", json.dumps, {
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
})
|
||||
|
||||
def test_yaml_params_file(self):
|
||||
self._test_set_parameters(".yaml", yaml.dump, {
|
||||
"parameter_defaults": {
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
}
|
||||
})
|
||||
|
||||
def test_invalid_params_file(self):
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.InvalidConfiguration,
|
||||
self._test_set_parameters, ".invalid", yaml.dump, {})
|
64
tripleoclient/v1/overcloud_parameters.py
Normal file
64
tripleoclient/v1/overcloud_parameters.py
Normal file
@ -0,0 +1,64 @@
|
||||
# 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 argparse
|
||||
import json
|
||||
import logging
|
||||
import yaml
|
||||
|
||||
from cliff import command
|
||||
from openstackclient.i18n import _
|
||||
|
||||
from tripleoclient import exceptions
|
||||
from tripleoclient.workflows import parameters
|
||||
|
||||
|
||||
class SetParameters(command.Command):
|
||||
"""Set a parameters for a plan"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".CreatePlan")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetParameters, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'name',
|
||||
help=_('The name of the plan, which is used for the Swift '
|
||||
'container, Mistral environment and Heat stack names.'))
|
||||
parser.add_argument('file_in', type=argparse.FileType('r'))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
if parsed_args.file_in.name.endswith('.json'):
|
||||
params = json.load(parsed_args.file_in)
|
||||
elif parsed_args.file_in.name.endswith('.yaml'):
|
||||
params = yaml.safe_load(parsed_args.file_in)
|
||||
else:
|
||||
raise exceptions.InvalidConfiguration(
|
||||
_("Invalid file extension for %s, must be json or yaml") %
|
||||
parsed_args.file_in.name)
|
||||
|
||||
if 'parameter_defaults' in params:
|
||||
params = params['parameter_defaults']
|
||||
|
||||
clients = self.app.client_manager
|
||||
workflow_client = clients.workflow_engine
|
||||
|
||||
name = parsed_args.name
|
||||
|
||||
parameters.update_parameters(
|
||||
workflow_client,
|
||||
container=name,
|
||||
parameters=params
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user