From e26e49af351d6a315c1012551aa73ffd23a4e4e9 Mon Sep 17 00:00:00 2001 From: Pete Vander Giessen Date: Fri, 12 Jul 2019 13:53:34 +0000 Subject: [PATCH] Broke up execution into "setup" and "launch" commands. We present these as seperate invocations of the script, rather than automatically running them one after the other. This allows us to run the setup script once for multiple daemons, then run launch steps individually for the daemons. Change-Id: Ia223f6bd6c1d3b544831652d4a076c4bee13ce43 --- snap_openstack/base.py | 19 ++++++++----- snap_openstack/cmd/run.py | 21 ++++++++++---- snap_openstack/tests/test_snap_openstack.py | 31 ++++++++++----------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/snap_openstack/base.py b/snap_openstack/base.py index 8bba0d5..3cb8f61 100644 --- a/snap_openstack/base.py +++ b/snap_openstack/base.py @@ -170,9 +170,14 @@ class OpenStackSnap(object): utils.snap_env[key] = snap_config[key] def setup(self): - '''Perform any pre-execution snap setup + '''Pre-launch setup. + + Write out templates that might be shared between daemons and + perform other setup tasks. + + This is generally executed during a seperate invocation of the + script, before running "snap-openstack launch foo" - Run this method prior to use of the execute method. ''' utils = SnapUtils() setup = self.configuration['setup'] @@ -207,17 +212,17 @@ class OpenStackSnap(object): else: LOG.debug('Path not found: {}'.format(target_path)) - def execute(self, argv): - '''Execute snap command building out configuration and log options''' + def launch(self, argv): + '''Launch a daemon, building out configuration and log options''' utils = SnapUtils() - entry_point = self.configuration['entry_points'].get(argv[1]) + entry_point = self.configuration['entry_points'].get(argv[2]) if not entry_point: - _msg = 'Unable to find entry point for {}'.format(argv[1]) + _msg = 'Unable to find entry point for {}'.format(argv[2]) LOG.error(_msg) raise ValueError(_msg) - other_args = argv[2:] + other_args = argv[3:] LOG.debug(entry_point) # Build out command to run diff --git a/snap_openstack/cmd/run.py b/snap_openstack/cmd/run.py index 8409a26..866f48e 100644 --- a/snap_openstack/cmd/run.py +++ b/snap_openstack/cmd/run.py @@ -33,11 +33,20 @@ def main(): sys.exit(1) config_path = os.path.join(snap, CONFIG_FILE) - if os.path.exists(config_path): - LOG.debug('Using snap wrapper: {}'.format(config_path)) - s_openstack = OpenStackSnap(config_path) - s_openstack.setup() - s_openstack.execute(sys.argv) - else: + if not os.path.exists(config_path): LOG.error('Unable to find snap-openstack.yaml configuration file') sys.exit(1) + + LOG.debug('Using snap wrapper: {}'.format(config_path)) + s_openstack = OpenStackSnap(config_path) + + if sys.argv[1] == 'setup': + s_openstack.setup() + sys.exit(0) + + if sys.argv[1] == 'launch': + s_openstack.launch(sys.argv) + sys.exit(0) + + LOG.error("Missing argument. Must specific 'setup' or 'launch.'") + sys.exit(1) diff --git a/snap_openstack/tests/test_snap_openstack.py b/snap_openstack/tests/test_snap_openstack.py index 3a16234..d7b65b6 100644 --- a/snap_openstack/tests/test_snap_openstack.py +++ b/snap_openstack/tests/test_snap_openstack.py @@ -90,8 +90,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): mock_os.path.exists.side_effect = self.mock_exists mock_os.environ = {} mock_os.path.basename.side_effect = 'keystone.conf' - snap.execute(['snap-openstack', - 'keystone-manage']) + snap.launch(['snap-openstack', 'launch', 'keystone-manage']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/bin/keystone-manage', ['/snap/keystone/current/bin/keystone-manage', @@ -115,8 +114,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): mock_os.path.exists.side_effect = self.mock_exists_overrides mock_os.environ = {} mock_os.path.basename.side_effect = 'keystone.conf' - snap.execute(['snap-openstack', - 'keystone-manage']) + snap.launch(['snap-openstack', 'launch', 'keystone-manage']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/bin/keystone-manage', ['/snap/keystone/current/bin/keystone-manage', @@ -139,9 +137,10 @@ class TestOpenStackSnapExecute(test_base.TestCase): mock_os.path.exists.side_effect = self.mock_exists mock_os.environ = {} mock_os.path.basename.side_effect = 'keystone.conf' - snap.execute(['snap-openstack', - 'keystone-manage', - 'db', 'sync']) + snap.launch(['snap-openstack', + 'launch', + 'keystone-manage', + 'db', 'sync']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/bin/keystone-manage', ['/snap/keystone/current/bin/keystone-manage', @@ -164,8 +163,9 @@ class TestOpenStackSnapExecute(test_base.TestCase): mock_os.path.exists.side_effect = self.mock_exists mock_os.environ = {} self.assertRaises(ValueError, - snap.execute, + snap.launch, ['snap-openstack', + 'launch', 'keystone-api']) @patch.object(base, 'SnapFileRenderer') @@ -184,8 +184,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): if sys.version_info > (3, 0): builtin = 'builtins' with patch('{}.open'.format(builtin), mock_open(), create=True): - snap.execute(['snap-openstack', - 'keystone-uwsgi']) + snap.launch(['snap-openstack', 'launch', 'keystone-uwsgi']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/bin/uwsgi', ['/snap/keystone/current/bin/uwsgi', '--master', @@ -214,8 +213,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): if sys.version_info > (3, 0): builtin = 'builtins' with patch('{}.open'.format(builtin), mock_open(), create=True): - snap.execute(['snap-openstack', - 'keystone-uwsgi']) + snap.launch(['snap-openstack', 'launch', 'keystone-uwsgi']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/bin/uwsgi', ['/snap/keystone/current/bin/uwsgi', '--master', @@ -236,8 +234,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): 'snap-openstack.yaml')) mock_os.path.exists.side_effect = self.mock_exists mock_os.environ = {} - snap.execute(['snap-openstack', - 'keystone-nginx']) + snap.launch(['snap-openstack', 'launch', 'keystone-nginx']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/usr/sbin/nginx', ['/snap/keystone/current/usr/sbin/nginx', '-g', @@ -257,8 +254,7 @@ class TestOpenStackSnapExecute(test_base.TestCase): 'snap-openstack.yaml')) mock_os.path.exists.side_effect = self.mock_exists_overrides mock_os.environ = {} - snap.execute(['snap-openstack', - 'keystone-nginx']) + snap.launch(['snap-openstack', 'launch', 'keystone-nginx']) mock_os.execvpe.assert_called_with( '/snap/keystone/current/usr/sbin/nginx', ['/snap/keystone/current/usr/sbin/nginx', '-g', @@ -278,8 +274,9 @@ class TestOpenStackSnapExecute(test_base.TestCase): 'snap-openstack.yaml')) mock_os.path.exists.side_effect = self.mock_exists self.assertRaises(ValueError, - snap.execute, + snap.launch, ['snap-openstack', + 'launch', 'keystone-broken'])