Add processing for different output to clone_env function
because fuelclient may have different output on different servers
(dictionary or array)
Change-Id: I662781e324b44094f86c875aaee5474eab8ac53e
Closes-bug: 1603951
(cherry picked from commit 9c44fad4f4
)
This commit is contained in:
parent
5c443f2d3c
commit
8b65203203
|
@ -9,7 +9,6 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# 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 mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -127,6 +126,32 @@ ENV_SETTINGS = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NORMALIZED_DATA = [
|
||||||
|
{"name": "test", "id": 2},
|
||||||
|
{"name": "test"},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("normalized_data,is_error",
|
||||||
|
zip(NORMALIZED_DATA, [False, True]))
|
||||||
|
def test_clone_env(mocker, normalized_data, is_error):
|
||||||
|
release = mock.Mock(data={'name': "14.04", 'id': 2})
|
||||||
|
mock_fuel_call = mocker.patch('octane.util.env.fuel2_env_call')
|
||||||
|
mock_json_loads = mocker.patch('json.loads')
|
||||||
|
mock_normalized = mocker.patch(
|
||||||
|
'octane.util.helpers.normalized_cliff_show_json'
|
||||||
|
)
|
||||||
|
mock_normalized.return_value = normalized_data
|
||||||
|
orig_id = 1
|
||||||
|
if not is_error:
|
||||||
|
seed_id = env_util.clone_env(orig_id, release)
|
||||||
|
assert seed_id == 2
|
||||||
|
mock_json_loads.assert_called_once_with(mock_fuel_call.return_value)
|
||||||
|
else:
|
||||||
|
with pytest.raises(Exception) as exc_info:
|
||||||
|
assert ("Couldn't find new environment ID in fuel CLI output:"
|
||||||
|
"\n{0}".format(normalized_data)) == exc_info.value.args[0]
|
||||||
|
|
||||||
|
|
||||||
def test_copy_vips(mock_subprocess):
|
def test_copy_vips(mock_subprocess):
|
||||||
env_id = -1
|
env_id = -1
|
||||||
|
|
|
@ -67,3 +67,21 @@ def test_iterate_parameters(source, parameters):
|
||||||
expected_result.append((line,) + params)
|
expected_result.append((line,) + params)
|
||||||
result = list(helpers.iterate_parameters(source))
|
result = list(helpers.iterate_parameters(source))
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
|
DATA = [
|
||||||
|
[{"Field": "id", "Value": 1}, {"Field": "name", "Value": "test"}],
|
||||||
|
{"name": "test", "id": 2}
|
||||||
|
]
|
||||||
|
|
||||||
|
NORMALIZED_DATA = [
|
||||||
|
{"name": "test", "id": 1},
|
||||||
|
{"name": "test", "id": 2}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('data,normalized_data',
|
||||||
|
zip(DATA, NORMALIZED_DATA))
|
||||||
|
def test_normalized_cliff_show_json(data, normalized_data):
|
||||||
|
res = helpers.normalized_cliff_show_json(data)
|
||||||
|
assert res == normalized_data
|
||||||
|
|
|
@ -29,6 +29,7 @@ from octane.helpers import tasks as tasks_helpers
|
||||||
from octane.helpers import transformations
|
from octane.helpers import transformations
|
||||||
from octane import magic_consts
|
from octane import magic_consts
|
||||||
from octane.util import disk
|
from octane.util import disk
|
||||||
|
from octane.util import helpers
|
||||||
from octane.util import ssh
|
from octane.util import ssh
|
||||||
from octane.util import subprocess
|
from octane.util import subprocess
|
||||||
|
|
||||||
|
@ -74,17 +75,16 @@ def get_env_provision_method(env):
|
||||||
|
|
||||||
def clone_env(env_id, release):
|
def clone_env(env_id, release):
|
||||||
LOG.info("Cloning env %s for release %s", env_id, release.data['name'])
|
LOG.info("Cloning env %s for release %s", env_id, release.data['name'])
|
||||||
res = fuel2_env_call(["clone", "-f", "json", str(env_id),
|
res_json = fuel2_env_call(["clone", "-f", "json", str(env_id),
|
||||||
uuid.uuid4().hex, str(release.data['id'])],
|
uuid.uuid4().hex, str(release.data['id'])],
|
||||||
output=True)
|
output=True)
|
||||||
for kv in json.loads(res):
|
res = json.loads(res_json)
|
||||||
if kv['Field'] == 'id':
|
res = helpers.normalized_cliff_show_json(res)
|
||||||
seed_id = kv['Value']
|
if 'id' in res:
|
||||||
break
|
return res['id']
|
||||||
else:
|
|
||||||
raise Exception("Couldn't find new environment ID in fuel CLI output:"
|
raise Exception("Couldn't find new environment ID in fuel CLI output:"
|
||||||
"\n%s" % res)
|
"\n%s" % res)
|
||||||
return seed_id
|
|
||||||
|
|
||||||
|
|
||||||
def clone_ips(orig_id, networks):
|
def clone_ips(orig_id, networks):
|
||||||
|
|
|
@ -49,3 +49,9 @@ def iterate_parameters(fp):
|
||||||
yield line, section, parameter, value
|
yield line, section, parameter, value
|
||||||
continue
|
continue
|
||||||
yield line, section, None, None
|
yield line, section, None, None
|
||||||
|
|
||||||
|
|
||||||
|
def normalized_cliff_show_json(data):
|
||||||
|
if isinstance(data, list):
|
||||||
|
return {i['Field']: i['Value'] for i in data}
|
||||||
|
return data
|
||||||
|
|
Loading…
Reference in New Issue