Merge "Revert "Fix get_deployment_mode to rely on fuelclient config""

This commit is contained in:
Jenkins 2016-04-11 12:29:47 +00:00 committed by Gerrit Code Review
commit 625df4d5d5
2 changed files with 21 additions and 15 deletions

View File

@ -12,27 +12,28 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging import logging
import os.path
import random as _random import random as _random
import string import string
import subprocess import subprocess
from fuelmenu import consts from fuelmenu import consts
log = logging.getLogger('fuelmenu.common.utils') log = logging.getLogger('fuelmenu.common.utils')
random = _random.SystemRandom() random = _random.SystemRandom()
def get_deployment_mode(): def get_deployment_mode():
"""Report post deployment if fuelclient config exists.""" """Report if any fuel containers are already created."""
command = ['docker', 'ps', '-a']
try: try:
result = os.path.isfile('/root/.config/fuel/fuel_client.yaml') _, output, _ = execute(command)
if result: if "fuel" in output.lower():
return consts.POST_DEPLOYMENT_MODE return consts.POST_DEPLOYMENT_MODE
else: else:
return consts.PRE_DEPLOYMENT_MODE return consts.PRE_DEPLOYMENT_MODE
except OSError: except OSError:
log.warning('Unable to check deployment mode. Assuming' log.warning('Unable to check deployment mode via docker. Assuming'
' pre-deployment stage.') ' pre-deployment stage.')
return consts.PRE_DEPLOYMENT_MODE return consts.PRE_DEPLOYMENT_MODE

View File

@ -18,6 +18,7 @@ from fuelmenu.common import utils
import mock import mock
from mock import patch from mock import patch
import subprocess
import unittest import unittest
@ -30,17 +31,21 @@ class TestUtils(unittest.TestCase):
return process_mock return process_mock
@mock.patch('fuelmenu.common.utils.os') def test_get_deployment_mode_pre(self):
def test_get_deployment_mode_pre(self, os_mock): process_mock = self.make_process_mock(return_code=0)
os_mock.path.isfile.return_value = False with patch.object(subprocess, 'Popen', return_value=process_mock):
mode = utils.get_deployment_mode() mode = utils.get_deployment_mode()
self.assertEqual('pre', 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):
def test_get_deployment_mode_post(self, os_mock): output = 'fuel-core-8.0-rabbitmq'
os_mock.path.isfile.return_value = True process_mock = self.make_process_mock(return_code=0,
mode = utils.get_deployment_mode() retval=(output, ''))
self.assertEqual('post', mode) 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') @mock.patch('fuelmenu.common.utils.get_deployment_mode')
def test_is_pre_deployment(self, utils_mock): def test_is_pre_deployment(self, utils_mock):