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
|
# 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
|
||||||
|
|
||||||
|
@ -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,16 +31,20 @@ 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()
|
||||||
|
process_mock.communicate.assert_called_once_with(input=None)
|
||||||
self.assertEqual('pre', mode)
|
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,
|
||||||
|
retval=(output, ''))
|
||||||
|
with patch.object(subprocess, 'Popen', return_value=process_mock):
|
||||||
mode = utils.get_deployment_mode()
|
mode = utils.get_deployment_mode()
|
||||||
|
process_mock.communicate.assert_called_once_with(input=None)
|
||||||
self.assertEqual('post', mode)
|
self.assertEqual('post', mode)
|
||||||
|
|
||||||
@mock.patch('fuelmenu.common.utils.get_deployment_mode')
|
@mock.patch('fuelmenu.common.utils.get_deployment_mode')
|
||||||
|
Loading…
Reference in New Issue
Block a user