From 88ec87caf625f3a28382c484ec93ebdae1fe33b6 Mon Sep 17 00:00:00 2001 From: John Fulton Date: Fri, 14 Jan 2022 15:19:46 +0000 Subject: [PATCH] Add --standalone to overcloud ceph user and deploy Both 'openstack overcloud ceph user enable' and 'openstack overcloud ceph deploy' currently use Ansible and require an inventory with hosts matching those in the Ceph spec. The inventory is created in the working directory when 'openstack overcloud node provision' runs but for a standalone deployment the user would need to create it manually. Abstract this detail away by providing a --standalone option for single node deploys which do not use metalsmith. Depends-On: Idfe4f334f59a3a40363b7127f33ed4996f09362f Change-Id: Icb785f015ee69d45dd513aef09fac625de421250 --- .../v2/overcloud_ceph/test_overcloud_ceph.py | 2 + tripleoclient/utils.py | 23 ++++++++++++ tripleoclient/v2/overcloud_ceph.py | 37 ++++++++++++++++--- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/tripleoclient/tests/v2/overcloud_ceph/test_overcloud_ceph.py b/tripleoclient/tests/v2/overcloud_ceph/test_overcloud_ceph.py index 4bc995ff9..49e7d5b10 100644 --- a/tripleoclient/tests/v2/overcloud_ceph/test_overcloud_ceph.py +++ b/tripleoclient/tests/v2/overcloud_ceph/test_overcloud_ceph.py @@ -65,6 +65,7 @@ class TestOvercloudCephDeploy(fakes.FakePlaybookExecution): "deployed_ceph_tht_path": mock.ANY, "working_dir": mock.ANY, "stack_name": 'overcloud', + "tripleo_cephadm_standalone": False, 'tripleo_cephadm_ssh_user': 'jimmy', 'tripleo_cephadm_first_mon_ip': '127.0.0.1', 'tripleo_roles_path': mock.ANY, @@ -106,6 +107,7 @@ class TestOvercloudCephDeploy(fakes.FakePlaybookExecution): "deployed_ceph_tht_path": mock.ANY, "working_dir": mock.ANY, "stack_name": 'overcloud', + "tripleo_cephadm_standalone": False, 'tripleo_roles_path': mock.ANY, 'tripleo_cephadm_first_mon_ip': '127.0.0.1', 'dynamic_ceph_spec': False, diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index f76bf2997..9b5573d43 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -3430,3 +3430,26 @@ def ceph_spec_standalone(ceph_spec_path, mon_ip, osd_spec_path=None): with open(ceph_spec_path, 'a') as f: f.write('---\n') f.write(yaml.dump(spec)) + + +def standalone_ceph_inventory(working_dir): + """return an ansible inventory for deployed ceph standalone + :param working_dir: directory where inventory should be written + :return string: the path to the inventory + """ + host = get_hostname() + inv = \ + {'Standalone': + {'hosts': {host: {}, + 'undercloud': {}}, + 'vars': {'ansible_connection': 'local', + 'ansible_host': host, + 'ansible_python_interpreter': sys.executable}}, + 'allovercloud': + {'children': {'Standalone': {}}}} + + path = os.path.join(working_dir, + constants.TRIPLEO_STATIC_INVENTORY) + with open(path, 'w') as f: + f.write(yaml.safe_dump(inv)) + return path diff --git a/tripleoclient/v2/overcloud_ceph.py b/tripleoclient/v2/overcloud_ceph.py index 97922fd34..e2f788da1 100644 --- a/tripleoclient/v2/overcloud_ceph.py +++ b/tripleoclient/v2/overcloud_ceph.py @@ -189,6 +189,11 @@ class OvercloudCephDeploy(command.Command): "Path to an existing crush hierarchy spec " "file. "), default=None) + parser.add_argument('--standalone', default=False, + action='store_true', + help=_("Use single host Ansible inventory. " + "Used only for development or testing " + "environments.")) parser.add_argument('--container-image-prepare', help=_( "Path to an alternative " @@ -259,8 +264,11 @@ class OvercloudCephDeploy(command.Command): working_dir = os.path.abspath(parsed_args.working_dir) oooutils.makedirs(working_dir) - inventory = os.path.join(working_dir, - constants.TRIPLEO_STATIC_INVENTORY) + if parsed_args.standalone: + inventory = oooutils.standalone_ceph_inventory(working_dir) + else: + inventory = os.path.join(working_dir, + constants.TRIPLEO_STATIC_INVENTORY) if not os.path.exists(inventory): raise oscexc.CommandError( "Inventory file not found in working directory: " @@ -273,6 +281,7 @@ class OvercloudCephDeploy(command.Command): "deployed_ceph_tht_path": output_path, "working_dir": working_dir, "stack_name": parsed_args.stack, + "tripleo_cephadm_standalone": parsed_args.standalone } # optional paths to pass to playbook if parsed_args.ceph_spec is None and \ @@ -459,6 +468,11 @@ class OvercloudCephUserDisable(command.Command): metavar='', required=True, help=_("The FSID of the Ceph cluster to be " "disabled. Required for disable option.")) + parser.add_argument('--standalone', default=False, + action='store_true', + help=_("Use single host Ansible inventory. " + "Used only for development or testing " + "environments.")) return parser @@ -494,8 +508,11 @@ class OvercloudCephUserDisable(command.Command): working_dir = os.path.abspath(parsed_args.working_dir) oooutils.makedirs(working_dir) - inventory = os.path.join(working_dir, - constants.TRIPLEO_STATIC_INVENTORY) + if parsed_args.standalone: + inventory = oooutils.standalone_ceph_inventory(working_dir) + else: + inventory = os.path.join(working_dir, + constants.TRIPLEO_STATIC_INVENTORY) if not os.path.exists(inventory): raise oscexc.CommandError( "Inventory file not found in working directory: " @@ -578,6 +595,11 @@ class OvercloudCephUserEnable(command.Command): "so that cephadm will be re-enabled " "for the Ceph cluster idenified " "by the FSID.")) + parser.add_argument('--standalone', default=False, + action='store_true', + help=_("Use single host Ansible inventory. " + "Used only for development or testing " + "environments.")) parser = arg_parse_common(parser) return parser @@ -608,8 +630,11 @@ class OvercloudCephUserEnable(command.Command): working_dir = os.path.abspath(parsed_args.working_dir) oooutils.makedirs(working_dir) - inventory = os.path.join(working_dir, - constants.TRIPLEO_STATIC_INVENTORY) + if parsed_args.standalone: + inventory = oooutils.standalone_ceph_inventory(working_dir) + else: + inventory = os.path.join(working_dir, + constants.TRIPLEO_STATIC_INVENTORY) if not os.path.exists(inventory): raise oscexc.CommandError( "Inventory file not found in working directory: "