Move read astute conf to function

move read config function to helper function

Change-Id: I98179a410b212035ab61e9ed491c5527a59759dc
(cherry picked from commit 7ca8402712)
This commit is contained in:
Sergey Abramov 2016-04-08 15:40:55 +03:00
parent 11ba481f98
commit 8746e1af72
5 changed files with 13 additions and 9 deletions

View File

@ -13,10 +13,10 @@
import json
import os
import urlparse
import yaml
from octane.handlers.backup_restore import base
from octane.util import helpers
from octane.util import sql
@ -30,9 +30,7 @@ class NaigunWWWBackup(base.PathArchivator):
raise NotImplementedError
def backup(self):
with open("/etc/fuel/astute.yaml", "r") as current:
current_yaml = yaml.load(current)
ipaddr = current_yaml["ADMIN_NETWORK"]["ipaddress"]
ipaddr = helpers.get_astute_dict()["ADMIN_NETWORK"]["ipaddress"]
rows = sql.run_psql_in_container(self.sql, self.db)
already_backuped = set()
for line in rows:

View File

@ -93,8 +93,7 @@ class NailgunArchivator(PostgresArchivator):
docker.apply_patches(*args, revert=True)
def _create_links_on_remote_logs(self):
with open("/etc/fuel/astute.yaml") as astute:
domain = yaml.load(astute)["DNS_DOMAIN"]
domain = helpers.get_astute_dict()["DNS_DOMAIN"]
dirname = "/var/log/docker-logs/remote/"
with fuel_client.set_auth_context(self.context):
pairs = [(n.data["meta"]["system"]["fqdn"], n.data["ip"])

View File

@ -15,6 +15,7 @@ import tempfile
import yaml
from octane.handlers.backup_restore import base
from octane.util import helpers
from octane.util import puppet
@ -34,8 +35,7 @@ class PuppetApplyHost(base.Base):
prefix=".astute.yaml.octane")
shutil.copy("/etc/fuel/astute.yaml", tmp_file_name)
try:
with open("/etc/fuel/astute.yaml") as current:
data = yaml.load(current)
data = helpers.get_astute_dict()
data["FUEL_ACCESS"]["password"] = self.context.password
with open("/etc/fuel/astute.yaml", "w") as current:
yaml.safe_dump(data, current, default_flow_style=False)

View File

@ -556,7 +556,7 @@ def test_post_restore_puppet_apply_host(mocker, mock_open, exc_on_apply):
archivator.restore()
assert mock_apply.called
assert mock_open.call_args_list == [
mock.call("/etc/fuel/astute.yaml"),
mock.call("/etc/fuel/astute.yaml", "r"),
mock.call("/etc/fuel/astute.yaml", "w"),
]
yaml_load.assert_called_once_with(mock_open.return_value)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import yaml
def merge_dicts(base_dict, update_dict):
result = base_dict.copy()
@ -19,3 +21,8 @@ def merge_dicts(base_dict, update_dict):
else:
result[key] = merge_dicts(result[key], val)
return result
def get_astute_dict():
with open("/etc/fuel/astute.yaml", "r") as current:
return yaml.load(current)