Drop old yaml-modification methods
YamlEditor is now tested and it's possible to replace old docker-related methods with it. Change-Id: I91f68fc92ab6580927027196f9b7de158e5f5a30
This commit is contained in:
parent
42f9342180
commit
1f9e7c0e76
@ -14,7 +14,6 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
from warnings import warn
|
||||
|
||||
from devops.helpers.helpers import wait
|
||||
from devops.models import DiskDevice
|
||||
@ -61,67 +60,6 @@ class BaseActions(object):
|
||||
cmd="systemctl restart {0}".format(service))
|
||||
return result['exit_code'] == 0
|
||||
|
||||
@staticmethod
|
||||
def put_value_to_local_yaml(old_file, new_file, element, value):
|
||||
"""Changes content in old_file at element is given to the new value
|
||||
and creates new file with changed content
|
||||
:param old_file: a path to the file content from to be changed
|
||||
:param new_file: a path to the new file to ve created with new content
|
||||
:param element: tuple with path to element to be changed
|
||||
for example: ['root_elem', 'first_elem', 'target_elem']
|
||||
if there are a few elements with equal names use integer
|
||||
to identify which element should be used
|
||||
:return: nothing
|
||||
"""
|
||||
warn("Function is deprecated, use utils.YamlEditor instead",
|
||||
DeprecationWarning)
|
||||
old_content = YamlEditor(old_file).get_content()
|
||||
open(new_file, "a").close()
|
||||
with YamlEditor(new_file) as editor:
|
||||
editor.content = old_content
|
||||
editor.change_value(element, value)
|
||||
|
||||
@staticmethod
|
||||
def get_value_from_local_yaml(yaml_file, element):
|
||||
"""Get a value of the element from the local yaml file
|
||||
|
||||
:param str yaml_file: a path to the yaml file
|
||||
:param list element:
|
||||
list with path to element to be read
|
||||
for example: ['root_elem', 'first_elem', 'target_elem']
|
||||
if there are a few elements with equal names use integer
|
||||
to identify which element should be used
|
||||
:return obj: value
|
||||
"""
|
||||
warn("Function is deprecated, use utils.YamlEditor instead",
|
||||
DeprecationWarning)
|
||||
return YamlEditor(yaml_file).get_value(element)
|
||||
|
||||
def change_remote_yaml(self, path_to_file, element, value, ip=None):
|
||||
"""Changes values in the yaml file stored
|
||||
There is no need to copy file manually
|
||||
:param path_to_file: absolute path to the file
|
||||
:param element: list with path to the element be changed
|
||||
:param value: new value for element
|
||||
:return: Nothing
|
||||
"""
|
||||
warn("Function is deprecated, use utils.YamlEditor instead",
|
||||
DeprecationWarning)
|
||||
with YamlEditor(path_to_file, self.admin_ip) as editor:
|
||||
editor.change_value(element, value)
|
||||
|
||||
def get_value_from_remote_yaml(self, path_to_file, element):
|
||||
"""Get a value from the yaml file stored
|
||||
on the master node
|
||||
|
||||
:param str path_to_file: absolute path to the file
|
||||
:param list element: list with path to the element
|
||||
:return obj: value
|
||||
"""
|
||||
warn("Function is deprecated, use utils.YamlEditor instead",
|
||||
DeprecationWarning)
|
||||
return YamlEditor(path_to_file, self.admin_ip).get_value(element)
|
||||
|
||||
|
||||
class AdminActions(BaseActions):
|
||||
""" All actions relating to the admin node."""
|
||||
@ -464,10 +402,9 @@ class FuelPluginBuilder(BaseActions):
|
||||
jsonify=True)['stdout_json']
|
||||
fuel_version = [str(output['release'])]
|
||||
openstack_version = str(output['openstack_version'])
|
||||
self.change_remote_yaml(metadata_path, ['fuel_version'], fuel_version)
|
||||
releases = self.get_value_from_remote_yaml(metadata_path, ['releases'])
|
||||
releases[0]['version'] = openstack_version
|
||||
self.change_remote_yaml(metadata_path, ['releases'], releases)
|
||||
with YamlEditor(metadata_path, ip=self.admin_ip) as editor:
|
||||
editor.content['fuel_version'] = fuel_version
|
||||
editor.content['releases'][0]['version'] = openstack_version
|
||||
|
||||
def fpb_validate_plugin(self, path):
|
||||
"""
|
||||
@ -500,10 +437,9 @@ class FuelPluginBuilder(BaseActions):
|
||||
:param new_version: new version to be used for plugin
|
||||
:return: nothing
|
||||
"""
|
||||
self.change_remote_yaml(
|
||||
'/root/{}/metadata.yaml'.format(plugin_name),
|
||||
['version'],
|
||||
new_version)
|
||||
with YamlEditor('/root/{}/metadata.yaml'.format(plugin_name),
|
||||
ip=self.admin_ip) as editor:
|
||||
editor.content['version'] = new_version
|
||||
|
||||
def fpb_change_package_version(self, plugin_name, new_version):
|
||||
"""
|
||||
@ -512,10 +448,9 @@ class FuelPluginBuilder(BaseActions):
|
||||
:param new_version: version to be changed at
|
||||
:return: nothing
|
||||
"""
|
||||
self.change_remote_yaml(
|
||||
'/root/{}/metadata.yaml'.format(plugin_name),
|
||||
['package_version'],
|
||||
new_version)
|
||||
with YamlEditor('/root/{}/metadata.yaml'.format(plugin_name),
|
||||
ip=self.admin_ip) as editor:
|
||||
editor.content['package_version'] = new_version
|
||||
|
||||
def fpb_copy_plugin(self, source, target):
|
||||
"""
|
||||
|
@ -1535,33 +1535,6 @@ class YamlEditor(object):
|
||||
self.original_content = copy.deepcopy(self.content)
|
||||
return self
|
||||
|
||||
def change_value(self, element, value):
|
||||
"""Change 'value' of 'element' (backward compatibility)
|
||||
THIS METHOD WILL BE REMOVED AFTER PLUGIN TESTS REFACTORING!
|
||||
Try to use 'content' field first before executing this method!"""
|
||||
self.content = self.get_content()
|
||||
result_dict = temp_dict = copy.deepcopy(self.content)
|
||||
for k in element[:-1]:
|
||||
temp_dict = temp_dict[k]
|
||||
temp_dict[element[-1]] = value
|
||||
self.content = result_dict
|
||||
return self.content
|
||||
|
||||
def get_value(self, element):
|
||||
"""Return 'value' of 'element' (backward compatibility)
|
||||
THIS METHOD WILL BE REMOVED AFTER PLUGIN TESTS REFACTORING!
|
||||
Try to use 'content' field first before executing this method!"""
|
||||
self.content = self.get_content()
|
||||
temp = self.content
|
||||
for k in element[:-1]:
|
||||
try:
|
||||
temp = temp[k]
|
||||
except (KeyError, IndexError):
|
||||
logger.error("Element {0!r} was not found in the config:\n"
|
||||
"{1!r}".format(k, self.content))
|
||||
raise
|
||||
return temp[element[-1]]
|
||||
|
||||
def __exit__(self, x, y, z):
|
||||
if self.content == self.original_content:
|
||||
return
|
||||
|
@ -19,6 +19,7 @@ from proboscis import test
|
||||
|
||||
from fuelweb_test.helpers import utils
|
||||
from fuelweb_test import logger
|
||||
from fuelweb_test.helpers.utils import YamlEditor
|
||||
from fuelweb_test.settings import DEPLOYMENT_MODE
|
||||
from fuelweb_test.tests.base_test_case import SetupEnvironment
|
||||
from fuelweb_test.tests.base_test_case import TestBasic
|
||||
@ -204,19 +205,19 @@ class RebootPlugin(TestBasic):
|
||||
fpb = FuelPluginBuilder()
|
||||
# install fuel_plugin_builder on master node
|
||||
fpb.fpb_install()
|
||||
# change timeout to a new value '1'
|
||||
fpb.put_value_to_local_yaml(os.path.join(tasks_path, tasks_file),
|
||||
os.path.join('/tmp/', tasks_file),
|
||||
[2, 'parameters', 'timeout'],
|
||||
1)
|
||||
self.show_step(3)
|
||||
# create plugin template on the master node
|
||||
fpb.fpb_create_plugin(source_plugin_path)
|
||||
fpb.fpb_update_release_in_metadata(source_plugin_path)
|
||||
# replace plugin tasks with our file
|
||||
fpb.fpb_replace_plugin_content(
|
||||
os.path.join('/tmp/', tasks_file),
|
||||
os.path.join(tasks_path, tasks_file),
|
||||
os.path.join(source_plugin_path, 'deployment_tasks.yaml'))
|
||||
# change timeout to a new value '1'
|
||||
with YamlEditor(
|
||||
os.path.join(source_plugin_path, 'deployment_tasks.yaml'),
|
||||
fpb.admin_ip) as editor:
|
||||
editor.content[2]['parameters']['timeout'] = 1
|
||||
# build plugin
|
||||
self.show_step(4)
|
||||
packet_name = fpb.fpb_build_plugin(source_plugin_path)
|
||||
|
@ -20,6 +20,7 @@ from proboscis import test
|
||||
|
||||
from fuelweb_test.helpers import utils
|
||||
from fuelweb_test import logger
|
||||
from fuelweb_test.helpers.utils import YamlEditor
|
||||
from fuelweb_test.settings import DEPLOYMENT_MODE
|
||||
from fuelweb_test.tests.base_test_case import SetupEnvironment
|
||||
from fuelweb_test.tests.base_test_case import TestBasic
|
||||
@ -203,14 +204,10 @@ class VipReservation(TestBasic):
|
||||
os.path.join(task_path, metadata_file),
|
||||
os.path.join(source_plugin_path, metadata_file))
|
||||
|
||||
fpb.change_remote_yaml(
|
||||
path_to_file=os.path.join(source_plugin_path, net_role_file),
|
||||
element=[0, 'properties', 'vip', 0, 'namespace'],
|
||||
value=namespace)
|
||||
fpb.change_remote_yaml(
|
||||
os.path.join(source_plugin_path, net_role_file),
|
||||
[1, 'properties', 'vip', 0, 'namespace'],
|
||||
namespace)
|
||||
with YamlEditor(os.path.join(source_plugin_path, net_role_file),
|
||||
ip=fpb.admin_ip) as editor:
|
||||
editor.content[0]['properties']['vip'][0]['namespace'] = namespace
|
||||
editor.content[1]['properties']['vip'][0]['namespace'] = namespace
|
||||
# build plugin
|
||||
self.show_step(4)
|
||||
packet_name = fpb.fpb_build_plugin(source_plugin_path)
|
||||
@ -330,14 +327,10 @@ class VipReservation(TestBasic):
|
||||
os.path.join(task_path, metadata_file),
|
||||
os.path.join(source_plugin_path, metadata_file))
|
||||
|
||||
fpb.change_remote_yaml(
|
||||
os.path.join(source_plugin_path, net_role_file),
|
||||
[0, 'properties', 'vip', 0, 'namespace'],
|
||||
namespace)
|
||||
fpb.change_remote_yaml(
|
||||
os.path.join(source_plugin_path, net_role_file),
|
||||
[1, 'properties', 'vip', 0, 'namespace'],
|
||||
namespace)
|
||||
with YamlEditor(os.path.join(source_plugin_path, net_role_file),
|
||||
ip=fpb.admin_ip) as editor:
|
||||
editor.content[0]['properties']['vip'][0]['namespace'] = namespace
|
||||
editor.content[1]['properties']['vip'][0]['namespace'] = namespace
|
||||
# build plugin
|
||||
self.show_step(4)
|
||||
packet_name = fpb.fpb_build_plugin(source_plugin_path)
|
||||
|
@ -26,6 +26,7 @@ from fuelweb_test.helpers.gerrit.gerrit_info_provider import \
|
||||
from fuelweb_test.helpers.ssh_manager import SSHManager
|
||||
from fuelweb_test import logger
|
||||
from fuelweb_test import settings
|
||||
from fuelweb_test.helpers.utils import YamlEditor
|
||||
from gates_tests.helpers import exceptions
|
||||
|
||||
|
||||
@ -429,12 +430,9 @@ def check_package_version_injected_in_bootstraps(
|
||||
def update_bootstrap_cli_yaml():
|
||||
actions = BaseActions()
|
||||
path = "/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml"
|
||||
element = ['repos']
|
||||
new_repo = {'name': 'auxiliary', 'priority': "1200",
|
||||
'section': 'main restricted',
|
||||
'suite': 'auxiliary', 'type': 'deb',
|
||||
'uri': 'http://127.0.0.1:8080/ubuntu/auxiliary/'}
|
||||
repos = actions.get_value_from_remote_yaml(path, element)
|
||||
repos.append(new_repo)
|
||||
|
||||
actions.change_remote_yaml(path, element, repos)
|
||||
with YamlEditor(path, ip=actions.admin_ip) as editor:
|
||||
editor['repos'].append(new_repo)
|
||||
|
Loading…
Reference in New Issue
Block a user