diff --git a/releasenotes/notes/deployment_user-bc451a45754035b9.yaml b/releasenotes/notes/deployment_user-bc451a45754035b9.yaml new file mode 100644 index 000000000..87126b65e --- /dev/null +++ b/releasenotes/notes/deployment_user-bc451a45754035b9.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Introduce deployment_user parameter, default to the current user, + will feed DeploymentUser parameter in THT, primarly used to add the + user to the 'docker' group, so our operators can run the `overcloud + container` commands when the undercloud is containerized. diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index d7ac3bd61..4fe5b3ae2 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -204,6 +204,12 @@ class TestEnsureRunAsNormalUser(TestCase): self.assertRaises(exceptions.RootUserExecution, utils.ensure_run_as_normal_user) + @mock.patch('getpass.getuser') + def test_get_deployment_user(self, mock_getpass): + mock_getpass.return_value = 'stack' + u = utils.get_deployment_user() + self.assertEqual('stack', u) + class TestCreateOvercloudRC(TestCase): diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index a29dce50f..6344ae25f 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -16,6 +16,7 @@ from __future__ import print_function import csv import datetime +import getpass import glob import hashlib import logging @@ -428,6 +429,11 @@ def ensure_run_as_normal_user(): ' Switch to a normal user.') +def get_deployment_user(): + """Return the user name which is used to deploy the cloud""" + return getpass.getuser() + + def capabilities_to_dict(caps): """Convert the Node's capabilities into a dictionary.""" if not caps: diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index e2aecd640..734a37e64 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -23,6 +23,7 @@ import logging import netaddr import os from oslo_config import cfg +from tripleoclient import utils from tripleoclient.v1 import undercloud_preflight import yaml @@ -65,6 +66,11 @@ PATHS = Paths() # When adding new options to the lists below, make sure to regenerate the # sample config by running "tox -e genconfig" in the project root. _opts = [ + cfg.StrOpt('deployment_user', + help=('User used to run openstack undercloud install command ' + 'which will be used to add the user to the docker group, ' + 'required to upload containers'), + ), cfg.StrOpt('undercloud_hostname', help=('Fully qualified hostname (including domain) to set on ' 'the Undercloud. If left unset, the ' @@ -602,6 +608,9 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=False): tht_templates, 'environments/services-docker/undercloud-keepalived.yaml')] + u = CONF.get('deployment_user') or utils.get_deployment_user() + env_data['DeploymentUser'] = u + deploy_args += [ "-e", os.path.join(tht_templates, "environments/docker.yaml"), "-e",