Merge "Revert "Fix get_deployment_mode to rely on fuelclient config""
This commit is contained in:
commit
625df4d5d5
@ -12,27 +12,28 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
import os.path
|
||||
import random as _random
|
||||
import string
|
||||
import subprocess
|
||||
|
||||
from fuelmenu import consts
|
||||
|
||||
|
||||
log = logging.getLogger('fuelmenu.common.utils')
|
||||
random = _random.SystemRandom()
|
||||
|
||||
|
||||
def get_deployment_mode():
|
||||
"""Report post deployment if fuelclient config exists."""
|
||||
"""Report if any fuel containers are already created."""
|
||||
command = ['docker', 'ps', '-a']
|
||||
try:
|
||||
result = os.path.isfile('/root/.config/fuel/fuel_client.yaml')
|
||||
if result:
|
||||
_, output, _ = execute(command)
|
||||
if "fuel" in output.lower():
|
||||
return consts.POST_DEPLOYMENT_MODE
|
||||
else:
|
||||
return consts.PRE_DEPLOYMENT_MODE
|
||||
except OSError:
|
||||
log.warning('Unable to check deployment mode. Assuming'
|
||||
log.warning('Unable to check deployment mode via docker. Assuming'
|
||||
' pre-deployment stage.')
|
||||
return consts.PRE_DEPLOYMENT_MODE
|
||||
|
||||
|
@ -18,6 +18,7 @@ from fuelmenu.common import utils
|
||||
|
||||
import mock
|
||||
from mock import patch
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
@ -30,17 +31,21 @@ class TestUtils(unittest.TestCase):
|
||||
|
||||
return process_mock
|
||||
|
||||
@mock.patch('fuelmenu.common.utils.os')
|
||||
def test_get_deployment_mode_pre(self, os_mock):
|
||||
os_mock.path.isfile.return_value = False
|
||||
mode = utils.get_deployment_mode()
|
||||
self.assertEqual('pre', mode)
|
||||
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_post(self, os_mock):
|
||||
os_mock.path.isfile.return_value = True
|
||||
mode = utils.get_deployment_mode()
|
||||
self.assertEqual('post', 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.get_deployment_mode')
|
||||
def test_is_pre_deployment(self, utils_mock):
|
||||
|
Loading…
Reference in New Issue
Block a user