Add --stack to update, upgrade and ffwd-upgrade 'run' CLI.

We need to be able to define the stack name if it
is different than 'overcloud', for the ansible inventory
used with the upgrade playbooks.

Change-Id: I0499eabc5c6f15cb32b2471c86245578c71a2a60
Closes-Bug: 1767379
This commit is contained in:
Carlos Camacho
2018-04-27 16:03:33 +02:00
parent 52fc966709
commit 01f5fd25aa
5 changed files with 63 additions and 4 deletions

View File

@@ -738,3 +738,32 @@ class ProcessMultipleEnvironments(TestCase):
mock_yaml_dump.assert_has_calls([mock.call(rewritten_env,
default_flow_style=False)])
class GetTripleoAnsibleInventory(TestCase):
def setUp(self):
super(GetTripleoAnsibleInventory, self).setUp()
self.inventory_file = ''
self.ssh_user = 'heat_admin'
self.stack = 'foo-overcloud'
@mock.patch('tripleoclient.utils.get_tripleo_ansible_inventory',
autospec=True)
def test_get_tripleo_ansible_inventory(self, mock_inventory):
with mock.patch('os.path.exists') as mock_exists:
mock_exists.return_value = True
self.cmd = utils.get_tripleo_ansible_inventory(
inventory_file=self.inventory_file,
ssh_user=self.ssh_user,
stack=self.stack)
self.cmd.take_action()
mock_inventory.assert_called_once_with(
inventory_file='',
ssh_user='heat_admin',
stack='foo-overcloud'
)

View File

@@ -816,13 +816,16 @@ def load_environment_directories(directories):
return environments
def get_tripleo_ansible_inventory(inventory_file='', ssh_user='heat-admin'):
def get_tripleo_ansible_inventory(inventory_file='',
ssh_user='heat-admin',
stack='overcloud'):
if not inventory_file:
inventory_file = '%s/%s' % (os.path.expanduser('~'),
'tripleo-ansible-inventory.yaml')
try:
processutils.execute(
'/usr/bin/tripleo-ansible-inventory',
'--stack', stack,
'--ansible_ssh_user', ssh_user,
'--static-yaml-inventory', inventory_file)
except processutils.ProcessExecutionError as e:

View File

@@ -15,6 +15,7 @@
import logging
from osc_lib.i18n import _
from osc_lib import utils
from tripleoclient import command
from tripleoclient import constants
@@ -112,14 +113,22 @@ class FFWDUpgradeRun(command.Command):
help=_("The ssh user name for connecting to "
"the overcloud nodes.")
)
parser.add_argument('--stack', dest='stack',
help=_('Name or ID of heat stack '
'(default=Env: OVERCLOUD_STACK_NAME)'),
default=utils.env('OVERCLOUD_STACK_NAME',
default='overcloud')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
stack = parsed_args.stack
# Run ansible:
inventory = oooutils.get_tripleo_ansible_inventory(
parsed_args.static_inventory)
parsed_args.static_inventory, stack)
# Don't expost limit_hosts. We need this on the whole overcloud.
limit_hosts = ''
oooutils.run_update_ansible_action(

View File

@@ -16,6 +16,7 @@
import logging
from osc_lib.i18n import _
from osc_lib import utils
from tripleoclient import command
from tripleoclient import constants
@@ -138,11 +139,19 @@ class UpdateRun(command.Command):
'generated in '
'~/tripleo-ansible-inventory.yaml')
)
parser.add_argument('--stack', dest='stack',
help=_('Name or ID of heat stack '
'(default=Env: OVERCLOUD_STACK_NAME)'),
default=utils.env('OVERCLOUD_STACK_NAME',
default='overcloud')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
stack = parsed_args.stack
# Run ansible:
nodes = parsed_args.nodes
@@ -151,7 +160,7 @@ class UpdateRun(command.Command):
nodes = None
playbook = parsed_args.playbook
inventory = oooutils.get_tripleo_ansible_inventory(
parsed_args.static_inventory, parsed_args.ssh_user)
parsed_args.static_inventory, parsed_args.ssh_user, stack)
oooutils.run_update_ansible_action(self.log, clients, nodes, inventory,
playbook, constants.UPDATE_QUEUE,
constants.MINOR_UPDATE_PLAYBOOKS,

View File

@@ -15,6 +15,7 @@
import logging
from osc_lib.i18n import _
from osc_lib import utils
from tripleoclient import command
from tripleoclient import constants
@@ -170,6 +171,12 @@ class UpgradeRun(command.Command):
'upgrade and some services cannot be '
'started. ')
)
parser.add_argument('--stack', dest='stack',
help=_('Name or ID of heat stack '
'(default=Env: OVERCLOUD_STACK_NAME)'),
default=utils.env('OVERCLOUD_STACK_NAME',
default='overcloud'))
return parser
def _validate_skip_tags(self, skip_tags):
@@ -185,13 +192,15 @@ class UpgradeRun(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
stack = parsed_args.stack
# Run ansible:
roles = parsed_args.roles
nodes = parsed_args.nodes
limit_hosts = roles or nodes
playbook = parsed_args.playbook
inventory = oooutils.get_tripleo_ansible_inventory(
parsed_args.static_inventory, parsed_args.ssh_user)
parsed_args.static_inventory, parsed_args.ssh_user, stack)
skip_tags = self._validate_skip_tags(parsed_args.skip_tags)
oooutils.run_update_ansible_action(self.log, clients, limit_hosts,
inventory, playbook,