Fix get_deployment_mode to rely on keys directory
Docker is no longer used, so this is a way to tell if
the system was deployed and block changing risky settings.
Change-Id: Ic78a973ca7e9f16b1f32c98f15f736993615e859
Closes-Bug: #1567300
(cherry picked from commit cc4628c865
)
This commit is contained in:
parent
91a58050ca
commit
52a49236ce
|
@ -12,6 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
import os
|
||||
import random as _random
|
||||
import string
|
||||
import subprocess
|
||||
|
@ -24,16 +25,15 @@ random = _random.SystemRandom()
|
|||
|
||||
|
||||
def get_deployment_mode():
|
||||
"""Report if any fuel containers are already created."""
|
||||
command = ['docker', 'ps', '-a']
|
||||
"""Report post deployment if keys directory exists."""
|
||||
try:
|
||||
_, output, _ = execute(command)
|
||||
if "fuel" in output.lower():
|
||||
result = os.path.isdir('/var/lib/fuel/keys/master')
|
||||
if result:
|
||||
return consts.POST_DEPLOYMENT_MODE
|
||||
else:
|
||||
return consts.PRE_DEPLOYMENT_MODE
|
||||
except OSError:
|
||||
log.warning('Unable to check deployment mode via docker. Assuming'
|
||||
log.warning('Unable to check deployment mode. Assuming'
|
||||
' pre-deployment stage.')
|
||||
return consts.PRE_DEPLOYMENT_MODE
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ from fuelmenu.common import utils
|
|||
|
||||
import mock
|
||||
from mock import patch
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
|
@ -31,21 +30,17 @@ class TestUtils(unittest.TestCase):
|
|||
|
||||
return process_mock
|
||||
|
||||
def test_get_deployment_mode_pre(self):
|
||||
process_mock = self.make_process_mock(return_code=0)
|
||||
with patch.object(subprocess, 'Popen', return_value=process_mock):
|
||||
mode = utils.get_deployment_mode()
|
||||
process_mock.communicate.assert_called_once_with(input=None)
|
||||
self.assertEqual('pre', mode)
|
||||
@mock.patch('fuelmenu.common.utils.os')
|
||||
def test_get_deployment_mode_pre(self, os_mock):
|
||||
os_mock.path.isdir.return_value = False
|
||||
mode = utils.get_deployment_mode()
|
||||
self.assertEqual('pre', mode)
|
||||
|
||||
def test_get_deployment_mode_post(self):
|
||||
output = 'fuel-core-8.0-rabbitmq'
|
||||
process_mock = self.make_process_mock(return_code=0,
|
||||
retval=(output, ''))
|
||||
with patch.object(subprocess, 'Popen', return_value=process_mock):
|
||||
mode = utils.get_deployment_mode()
|
||||
process_mock.communicate.assert_called_once_with(input=None)
|
||||
self.assertEqual('post', mode)
|
||||
@mock.patch('fuelmenu.common.utils.os')
|
||||
def test_get_deployment_mode_post(self, os_mock):
|
||||
os_mock.path.isdir.return_value = True
|
||||
mode = utils.get_deployment_mode()
|
||||
self.assertEqual('post', mode)
|
||||
|
||||
@mock.patch('fuelmenu.common.utils.get_deployment_mode')
|
||||
def test_is_pre_deployment(self, utils_mock):
|
||||
|
|
Loading…
Reference in New Issue