From ea904d09643fecf221b8c47289eb1b5252c97864 Mon Sep 17 00:00:00 2001
From: Alex Schultz <aschultz@redhat.com>
Date: Fri, 3 Aug 2018 09:37:19 -0600
Subject: [PATCH] Remove instack-undercloud and --use-heat

The instack-undercloud method of installing the undercloud was
deprecated in Rocky. We would like to remove the tie in via the
tripleoclient to reduce the overall package requirements when install
tripleoclient.

Depends-On: https://review.openstack.org/#/c/591858/
Change-Id: I3f1055ece3c267540bd4a94d42811b9146a09a86
Blueprint: remove-instack-undercloud
---
 ...e-instack-undercloud-1cd802a8cc437f7c.yaml |  7 ++
 .../tests/v1/undercloud/test_undercloud.py    | 52 ++---------
 tripleoclient/v1/undercloud.py                | 86 ++++++-------------
 3 files changed, 42 insertions(+), 103 deletions(-)
 create mode 100644 releasenotes/notes/retire-instack-undercloud-1cd802a8cc437f7c.yaml

diff --git a/releasenotes/notes/retire-instack-undercloud-1cd802a8cc437f7c.yaml b/releasenotes/notes/retire-instack-undercloud-1cd802a8cc437f7c.yaml
new file mode 100644
index 000000000..4d1a7223e
--- /dev/null
+++ b/releasenotes/notes/retire-instack-undercloud-1cd802a8cc437f7c.yaml
@@ -0,0 +1,7 @@
+---
+upgrade:
+  - The --use-heat option from undercloud install has been removed along with
+    the ability to deploy an undercloud on baremetal using instack-undercloud
+    via 'openstack undercloud install'. Manual deployment may still be possible
+    by directly invoking the instack-undercloud scripts but it is no longer
+    available via the 'openstack undercloud install' command.
diff --git a/tripleoclient/tests/v1/undercloud/test_undercloud.py b/tripleoclient/tests/v1/undercloud/test_undercloud.py
index 8e2024c88..21087962a 100644
--- a/tripleoclient/tests/v1/undercloud/test_undercloud.py
+++ b/tripleoclient/tests/v1/undercloud/test_undercloud.py
@@ -110,17 +110,6 @@ class TestUndercloudInstall(TestPluginV1):
              '/usr/share/openstack-tripleo-heat-templates/'
              'undercloud-stack-vstate-dropin.yaml'])
 
-    @mock.patch('subprocess.check_call', autospec=True)
-    def test_undercloud_install_with_heat_disabled(self, mock_subprocess):
-        arglist = ['--use-heat=False']
-        verifylist = []
-        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
-        # DisplayCommandBase.take_action() returns two tuples
-        self.cmd.take_action(parsed_args)
-
-        mock_subprocess.assert_called_with(['instack-install-undercloud'])
-
     # TODO(cjeanner) drop once we have proper oslo.privsep
     @mock.patch('getpass.getuser', return_value='stack')
     @mock.patch('shutil.copy')
@@ -133,7 +122,7 @@ class TestUndercloudInstall(TestPluginV1):
         self.conf.config(output_dir='/foo')
         self.conf.config(templates='/usertht')
         self.conf.config(roles_file='foo/roles.yaml')
-        arglist = ['--use-heat', '--no-validations', '--force-stack-update']
+        arglist = ['--no-validations', '--force-stack-update']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -270,7 +259,7 @@ class TestUndercloudInstall(TestPluginV1):
         env = mock.Mock()
         env.get_template = mock.Mock(return_value=Template(instack_net_conf))
         mock_get_j2.return_value = (env, None)
-        arglist = ['--use-heat', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -358,7 +347,7 @@ class TestUndercloudInstall(TestPluginV1):
                                                     mock_os, mock_copy,
                                                     mock_open, mock_user):
         self.conf.config(undercloud_log_file='/foo/bar')
-        arglist = ['--use-heat', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -425,7 +414,7 @@ class TestUndercloudInstall(TestPluginV1):
                                                mock_os, mock_copy,
                                                mock_open, mock_user):
         self.conf.config(undercloud_log_file='/foo/bar')
-        arglist = ['--use-heat=True', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -485,7 +474,7 @@ class TestUndercloudInstall(TestPluginV1):
     def test_undercloud_install_with_swift_encryption(self, mock_subprocess,
                                                       mock_wr, mock_os,
                                                       mock_copy, mock_user):
-        arglist = ['--use-heat', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         self.conf.set_default('enable_swift_encryption', True)
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -618,29 +607,6 @@ class TestUndercloudUpgrade(TestPluginV1):
              '/usr/share/openstack-tripleo-heat-templates/'
              'undercloud-stack-vstate-dropin.yaml'])
 
-    @mock.patch('os.mkdir')
-    @mock.patch('tripleoclient.utils.write_env_file', autospec=True)
-    @mock.patch('subprocess.check_call', autospec=True)
-    def test_undercloud_upgrade_with_heat_disabled(self, mock_subprocess,
-                                                   mock_wr, mock_os):
-        arglist = ['--use-heat=False']
-        verifylist = []
-        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
-        # DisplayCommandBase.take_action() returns two tuples
-        self.cmd.take_action(parsed_args)
-
-        mock_subprocess.assert_has_calls(
-            [
-                mock.call(['sudo', 'yum', 'update', '-y',
-                           'instack-undercloud']),
-                mock.call('instack-pre-upgrade-undercloud'),
-                mock.call('instack-upgrade-undercloud'),
-                mock.call(['sudo', 'systemctl', 'restart',
-                          'openstack-nova-api'])
-            ]
-        )
-
     # TODO(cjeanner) drop once we have proper oslo.privsep
     @mock.patch('getpass.getuser', return_value='stack')
     @mock.patch('shutil.copy')
@@ -650,7 +616,7 @@ class TestUndercloudUpgrade(TestPluginV1):
     def test_undercloud_upgrade_with_heat_enabled(self, mock_subprocess,
                                                   mock_wr, mock_os,
                                                   mock_copy, mock_user):
-        arglist = ['--use-heat', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -713,7 +679,7 @@ class TestUndercloudUpgrade(TestPluginV1):
     def test_undercloud_upgrade_with_heat_true(self, mock_subprocess,
                                                mock_wr, mock_os,
                                                mock_copy, mock_user):
-        arglist = ['--use-heat=True', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -776,7 +742,7 @@ class TestUndercloudUpgrade(TestPluginV1):
     def test_undercloud_upgrade_with_heat_and_yes(self, mock_subprocess,
                                                   mock_wr, mock_os,
                                                   mock_user, mock_copy):
-        arglist = ['--use-heat', '--no-validations', '-y']
+        arglist = ['--no-validations', '-y']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
@@ -840,7 +806,7 @@ class TestUndercloudUpgrade(TestPluginV1):
     def test_undercloud_upgrade_with_heat_and_debug(self, mock_subprocess,
                                                     mock_wr, mock_os,
                                                     mock_copy, mock_user):
-        arglist = ['--use-heat', '--no-validations']
+        arglist = ['--no-validations']
         verifylist = []
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 
diff --git a/tripleoclient/v1/undercloud.py b/tripleoclient/v1/undercloud.py
index 555132e18..cbf5b1584 100644
--- a/tripleoclient/v1/undercloud.py
+++ b/tripleoclient/v1/undercloud.py
@@ -84,16 +84,6 @@ class InstallUndercloud(command.Command):
             prog=prog_name,
             add_help=False
         )
-        parser.add_argument(
-            '--use-heat',
-            dest='use_heat',
-            nargs='?',
-            default=None,
-            const="true",
-            help=_('This option is deprecated in Rocky. It makes sure that we '
-                   'perform undercloud deploy using ephemeral '
-                   '(one-time create and forget) heat stack and ansible.'),
-        )
         parser.add_argument('--force-stack-update',
                             dest='force_stack_update',
                             action='store_true',
@@ -130,21 +120,12 @@ class InstallUndercloud(command.Command):
         self.log.debug("take_action(%s)" % parsed_args)
 
         utils.ensure_run_as_normal_user()
-        if parsed_args.use_heat is not None:
-            self.log.warning('--use-heat is deprecated in Rocky')
-        if parsed_args.use_heat is not None and \
-                parsed_args.use_heat.lower() == "false":
-            self.log.warning(_('Non-containerized undercloud deployment is '
-                             'deprecated in Rocky cycle.'))
-            cmd = ["instack-install-undercloud"]
-        else:
-            no_validations = parsed_args.dry_run or parsed_args.no_validations
-            cmd = undercloud_config.\
-                prepare_undercloud_deploy(
-                    no_validations=no_validations,
-                    verbose_level=self.app_args.verbose_level,
-                    force_stack_update=parsed_args.force_stack_update,
-                    dry_run=parsed_args.dry_run)
+        no_validations = parsed_args.dry_run or parsed_args.no_validations
+        cmd = undercloud_config.prepare_undercloud_deploy(
+            no_validations=no_validations,
+            verbose_level=self.app_args.verbose_level,
+            force_stack_update=parsed_args.force_stack_update,
+            dry_run=parsed_args.dry_run)
 
         self.log.warning("Running: %s" % ' '.join(cmd))
         if not parsed_args.dry_run:
@@ -175,38 +156,23 @@ class UpgradeUndercloud(InstallUndercloud):
         self.log.debug("take action(%s)" % parsed_args)
 
         utils.ensure_run_as_normal_user()
-        if parsed_args.use_heat is not None:
-            self.log.warning('--use-heat is deprecated in Rocky')
-        if parsed_args.use_heat is not None and \
-                parsed_args.use_heat.lower() == "false":
-            self.log.warning(_('Non-containerized undercloud deployment is '
-                             'deprecated in Rocky cycle.'))
-            subprocess.check_call(['sudo', 'yum', 'update', '-y',
-                                  'instack-undercloud'])
-            subprocess.check_call("instack-pre-upgrade-undercloud")
-            subprocess.check_call("instack-upgrade-undercloud")
-            # restart nova-api
-            # https://bugzilla.redhat.com/show_bug.cgi?id=1315467
-            subprocess.check_call(['sudo', 'systemctl', 'restart',
-                                  'openstack-nova-api'])
-        else:
-            cmd = undercloud_config.\
-                prepare_undercloud_deploy(
-                    upgrade=True,
-                    yes=parsed_args.yes,
-                    no_validations=parsed_args.
-                    no_validations,
-                    verbose_level=self.app_args.verbose_level,
-                    force_stack_update=parsed_args.force_stack_update)
-            self.log.warning("Running: %s" % ' '.join(cmd))
-            if not parsed_args.dry_run:
-                try:
-                    subprocess.check_call(cmd)
-                    self.log.warning(
-                        UNDERCLOUD_UPGRADE_COMPLETION_MESSAGE.format(
-                            '~/undercloud-passwords.conf',
-                            '~/stackrc'))
-                except Exception as e:
-                    self.log.error(UNDERCLOUD_FAILURE_MESSAGE)
-                    self.log.error(e)
-                    raise exceptions.DeploymentError(e)
+        cmd = undercloud_config.\
+            prepare_undercloud_deploy(
+                upgrade=True,
+                yes=parsed_args.yes,
+                no_validations=parsed_args.
+                no_validations,
+                verbose_level=self.app_args.verbose_level,
+                force_stack_update=parsed_args.force_stack_update)
+        self.log.warning("Running: %s" % ' '.join(cmd))
+        if not parsed_args.dry_run:
+            try:
+                subprocess.check_call(cmd)
+                self.log.warning(
+                    UNDERCLOUD_UPGRADE_COMPLETION_MESSAGE.format(
+                        '~/undercloud-passwords.conf',
+                        '~/stackrc'))
+            except Exception as e:
+                self.log.error(UNDERCLOUD_FAILURE_MESSAGE)
+                self.log.error(e)
+                raise exceptions.DeploymentError(e)