Add keystone and swift url to /etc/hosts

It's needed for correct resolving hostname on VMs for Swift access

Closes-bug: #1488488

Change-Id: I234632309b339ac748db96a0c8f8def5a8e2a591
This commit is contained in:
Sergey Reshetnyak 2015-08-25 15:06:31 +03:00
parent 60b3362212
commit b32a72026e
2 changed files with 26 additions and 2 deletions

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from sahara import conductor
from sahara import context
from sahara.tests.unit import base
@ -104,10 +106,17 @@ class UtilsClusterTest(base.SaharaWithDbTestCase):
'internal_ip': str(idx),
})
cluster = self.api.cluster_get(ctx, cluster)
value = cluster_utils.generate_etc_hosts(cluster)
with mock.patch("sahara.utils.openstack.base.url_for") as mock_url:
mock_url.side_effect = ["http://keystone.local:1234/v13",
"http://swift.local:5678/v42"]
with mock.patch("socket.gethostbyname") as mock_get_host:
mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]
value = cluster_utils.generate_etc_hosts(cluster)
expected = ("127.0.0.1 localhost\n"
"1 1.novalocal 1\n"
"2 2.novalocal 2\n"
"3 3.novalocal 3\n"
"4 4.novalocal 4\n")
"4 4.novalocal 4\n"
"1.2.3.4 keystone.local\n"
"5.6.7.8 swift.local\n")
self.assertEqual(expected, value)

View File

@ -13,13 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import socket
from keystoneclient import exceptions as keystone_ex
from oslo_log import log as logging
from six.moves.urllib import parse
from sahara import conductor as c
from sahara import context
from sahara import exceptions as e
from sahara.i18n import _LI
from sahara.utils.notification import sender
from sahara.utils.openstack import base as auth_base
conductor = c.API
LOG = logging.getLogger(__name__)
@ -134,5 +139,15 @@ def generate_etc_hosts(cluster):
hosts += "%s %s %s\n" % (instance.internal_ip,
instance.fqdn(),
instance.hostname())
# add alias for keystone and swift
for service in ["identity", "object-store"]:
try:
hostname = parse.urlparse(
auth_base.url_for(service_type=service,
endpoint_type="publicURL")).hostname
except keystone_ex.EndpointNotFound:
LOG.debug("Endpoint not found for service: \"%s\"", service)
continue
hosts += "%s %s\n" % (socket.gethostbyname(hostname), hostname)
return hosts