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
This commit is contained in:
parent
ab7e4ce124
commit
e26e49af35
@ -170,9 +170,14 @@ class OpenStackSnap(object):
|
|||||||
utils.snap_env[key] = snap_config[key]
|
utils.snap_env[key] = snap_config[key]
|
||||||
|
|
||||||
def setup(self):
|
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()
|
utils = SnapUtils()
|
||||||
setup = self.configuration['setup']
|
setup = self.configuration['setup']
|
||||||
@ -207,17 +212,17 @@ class OpenStackSnap(object):
|
|||||||
else:
|
else:
|
||||||
LOG.debug('Path not found: {}'.format(target_path))
|
LOG.debug('Path not found: {}'.format(target_path))
|
||||||
|
|
||||||
def execute(self, argv):
|
def launch(self, argv):
|
||||||
'''Execute snap command building out configuration and log options'''
|
'''Launch a daemon, building out configuration and log options'''
|
||||||
utils = SnapUtils()
|
utils = SnapUtils()
|
||||||
|
|
||||||
entry_point = self.configuration['entry_points'].get(argv[1])
|
entry_point = self.configuration['entry_points'].get(argv[2])
|
||||||
if not entry_point:
|
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)
|
LOG.error(_msg)
|
||||||
raise ValueError(_msg)
|
raise ValueError(_msg)
|
||||||
|
|
||||||
other_args = argv[2:]
|
other_args = argv[3:]
|
||||||
LOG.debug(entry_point)
|
LOG.debug(entry_point)
|
||||||
|
|
||||||
# Build out command to run
|
# Build out command to run
|
||||||
|
@ -33,11 +33,20 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
config_path = os.path.join(snap,
|
config_path = os.path.join(snap,
|
||||||
CONFIG_FILE)
|
CONFIG_FILE)
|
||||||
if os.path.exists(config_path):
|
if not 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:
|
|
||||||
LOG.error('Unable to find snap-openstack.yaml configuration file')
|
LOG.error('Unable to find snap-openstack.yaml configuration file')
|
||||||
sys.exit(1)
|
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)
|
||||||
|
@ -90,8 +90,7 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
mock_os.path.exists.side_effect = self.mock_exists
|
mock_os.path.exists.side_effect = self.mock_exists
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
mock_os.path.basename.side_effect = 'keystone.conf'
|
mock_os.path.basename.side_effect = 'keystone.conf'
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-manage'])
|
||||||
'keystone-manage'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/bin/keystone-manage',
|
'/snap/keystone/current/bin/keystone-manage',
|
||||||
['/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.path.exists.side_effect = self.mock_exists_overrides
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
mock_os.path.basename.side_effect = 'keystone.conf'
|
mock_os.path.basename.side_effect = 'keystone.conf'
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-manage'])
|
||||||
'keystone-manage'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/bin/keystone-manage',
|
'/snap/keystone/current/bin/keystone-manage',
|
||||||
['/snap/keystone/current/bin/keystone-manage',
|
['/snap/keystone/current/bin/keystone-manage',
|
||||||
@ -139,7 +137,8 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
mock_os.path.exists.side_effect = self.mock_exists
|
mock_os.path.exists.side_effect = self.mock_exists
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
mock_os.path.basename.side_effect = 'keystone.conf'
|
mock_os.path.basename.side_effect = 'keystone.conf'
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack',
|
||||||
|
'launch',
|
||||||
'keystone-manage',
|
'keystone-manage',
|
||||||
'db', 'sync'])
|
'db', 'sync'])
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
@ -164,8 +163,9 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
mock_os.path.exists.side_effect = self.mock_exists
|
mock_os.path.exists.side_effect = self.mock_exists
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
snap.execute,
|
snap.launch,
|
||||||
['snap-openstack',
|
['snap-openstack',
|
||||||
|
'launch',
|
||||||
'keystone-api'])
|
'keystone-api'])
|
||||||
|
|
||||||
@patch.object(base, 'SnapFileRenderer')
|
@patch.object(base, 'SnapFileRenderer')
|
||||||
@ -184,8 +184,7 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
if sys.version_info > (3, 0):
|
if sys.version_info > (3, 0):
|
||||||
builtin = 'builtins'
|
builtin = 'builtins'
|
||||||
with patch('{}.open'.format(builtin), mock_open(), create=True):
|
with patch('{}.open'.format(builtin), mock_open(), create=True):
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-uwsgi'])
|
||||||
'keystone-uwsgi'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/bin/uwsgi',
|
'/snap/keystone/current/bin/uwsgi',
|
||||||
['/snap/keystone/current/bin/uwsgi', '--master',
|
['/snap/keystone/current/bin/uwsgi', '--master',
|
||||||
@ -214,8 +213,7 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
if sys.version_info > (3, 0):
|
if sys.version_info > (3, 0):
|
||||||
builtin = 'builtins'
|
builtin = 'builtins'
|
||||||
with patch('{}.open'.format(builtin), mock_open(), create=True):
|
with patch('{}.open'.format(builtin), mock_open(), create=True):
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-uwsgi'])
|
||||||
'keystone-uwsgi'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/bin/uwsgi',
|
'/snap/keystone/current/bin/uwsgi',
|
||||||
['/snap/keystone/current/bin/uwsgi', '--master',
|
['/snap/keystone/current/bin/uwsgi', '--master',
|
||||||
@ -236,8 +234,7 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
'snap-openstack.yaml'))
|
'snap-openstack.yaml'))
|
||||||
mock_os.path.exists.side_effect = self.mock_exists
|
mock_os.path.exists.side_effect = self.mock_exists
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-nginx'])
|
||||||
'keystone-nginx'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/usr/sbin/nginx',
|
'/snap/keystone/current/usr/sbin/nginx',
|
||||||
['/snap/keystone/current/usr/sbin/nginx', '-g',
|
['/snap/keystone/current/usr/sbin/nginx', '-g',
|
||||||
@ -257,8 +254,7 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
'snap-openstack.yaml'))
|
'snap-openstack.yaml'))
|
||||||
mock_os.path.exists.side_effect = self.mock_exists_overrides
|
mock_os.path.exists.side_effect = self.mock_exists_overrides
|
||||||
mock_os.environ = {}
|
mock_os.environ = {}
|
||||||
snap.execute(['snap-openstack',
|
snap.launch(['snap-openstack', 'launch', 'keystone-nginx'])
|
||||||
'keystone-nginx'])
|
|
||||||
mock_os.execvpe.assert_called_with(
|
mock_os.execvpe.assert_called_with(
|
||||||
'/snap/keystone/current/usr/sbin/nginx',
|
'/snap/keystone/current/usr/sbin/nginx',
|
||||||
['/snap/keystone/current/usr/sbin/nginx', '-g',
|
['/snap/keystone/current/usr/sbin/nginx', '-g',
|
||||||
@ -278,8 +274,9 @@ class TestOpenStackSnapExecute(test_base.TestCase):
|
|||||||
'snap-openstack.yaml'))
|
'snap-openstack.yaml'))
|
||||||
mock_os.path.exists.side_effect = self.mock_exists
|
mock_os.path.exists.side_effect = self.mock_exists
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
snap.execute,
|
snap.launch,
|
||||||
['snap-openstack',
|
['snap-openstack',
|
||||||
|
'launch',
|
||||||
'keystone-broken'])
|
'keystone-broken'])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user