Fix dump for PostgreSQL is missing in a snapshot

This issue was introduced by
https://review.openstack.org/241271. Actually the changes in that
patch doesn't allow to execute a command (or file/dir operation) on a
local host.

This patch fixes:

* execution of a command on a local host (when neither address nor
hostname is specified)
* missing dump for PostgreSQL in a snapshot
* getting network address (address may be absent, but hostname could be
  present, so we need to use hostname in that case)

Change-Id: Iafecfa458372458963abd1e16890fe225454a612
Partial-bug: #1519303
This commit is contained in:
Andrey Tykhonov 2015-11-24 13:34:03 +02:00
parent 25a0cc461a
commit a0bd065080
2 changed files with 41 additions and 9 deletions

View File

@ -17,6 +17,8 @@ import copy
import logging
import time
import six
from shotgun import settings
@ -30,11 +32,13 @@ class Config(object):
self.offline_hosts = set()
self.objs = deque()
self.try_again = deque()
for properties in self.data.get("dump", {}).itervalues():
for host in properties.get("hosts", []):
for object_ in properties.get("objects", []):
object_["host"] = host
self.objs.append(copy.copy(object_))
for properties in six.itervalues(self.data.get('dump', {})):
hosts = properties.get('hosts') or [{}]
for obj in properties.get('objects', []):
for h in hosts:
obj_new = copy.deepcopy(obj)
obj_new['host'] = h
self.objs.append(obj_new)
def _timestamp(self, name):
return "{0}-{1}".format(
@ -68,7 +72,7 @@ class Config(object):
@staticmethod
def get_network_address(obj):
"""Returns network address of object."""
return obj["host"].get('address', '127.0.0.1')
return obj['host'].get('address') or obj['host'].get('hostname')
def on_network_error(self, obj):
"""Lets the object to have another attempt for being proccessed."""

View File

@ -94,7 +94,8 @@ class TestConfig(base.BaseTestCase):
obj = conf.objects.next()
self.assertEqual('10.109.2.2', conf.get_network_address(obj))
def test_get_network_address_default(self):
def test_get_network_address_hostname(self):
hostname = "fuel.tld"
data = {
"dump": {
"master": {
@ -103,12 +104,39 @@ class TestConfig(base.BaseTestCase):
"type": "dir"},
],
"hosts": [{"ssh-key": "/root/.ssh/id_rsa",
"hostname": "fuel.tld"}]},
"hostname": hostname}]},
}
}
conf = Config(data)
obj = conf.objects.next()
self.assertEqual('127.0.0.1', conf.get_network_address(obj))
self.assertEqual(hostname, conf.get_network_address(obj))
def test_get_network_address_absent_address_and_hostname(self):
data = {
"dump": {
"master": {
"objects":
[{"path": "/etc/nailgun",
"type": "dir"}]},
}
}
conf = Config(data)
obj = conf.objects.next()
self.assertIsNone(conf.get_network_address(obj))
def test_obj_without_hosts(self):
data = {
"dump": {
"fake_role1": {
"objects":
[{"fake_obj_1": '1'}, {"fake_obj_2": '2'}]},
}
}
conf = Config(data)
expected_objs = [
{'host': {}, 'fake_obj_1': '1'},
{'host': {}, 'fake_obj_2': '2'}]
self.assertItemsEqual(expected_objs, conf.objs)
def test_init(self):
data = {