Store cells credentials in transport_url properly

Looks like we need to store the decoded version in the
database, not the encoded version...ie:
    rabbit://the=user:the=password@hostname:5672//
instead of:
    rabbit://the%3Duser:the%3Dpassword@hostname:5672//

Once we build up the transport_url and transform it into
a string, we just call unquote to convert %xx escapes back
to their single-character equivalent.

Closes-Bug: #1406598
Change-Id: I34be01de08f515c5931ff04e1eaf9815e3c2fa82
This commit is contained in:
Davanum Srinivas 2015-03-26 14:16:36 -04:00 committed by Davanum Srinivas (dims)
parent 6afe84df5a
commit f16dd6ba95
2 changed files with 25 additions and 1 deletions

View File

@ -57,6 +57,7 @@ from __future__ import print_function
import argparse
import os
import sys
import urllib
import decorator
import netaddr
@ -1212,7 +1213,7 @@ class CellCommands(object):
is_parent = True
values = {'name': name,
'is_parent': is_parent,
'transport_url': str(transport_url),
'transport_url': urllib.unquote(str(transport_url)),
'weight_offset': float(woffset),
'weight_scale': float(wscale)}
ctxt = context.get_admin_context()

View File

@ -552,6 +552,29 @@ class CellCommandsTestCase(test.TestCase):
'weight_scale': 0.0}
mock_db_cell_create.assert_called_once_with(ctxt, exp_values)
@mock.patch.object(context, 'get_admin_context')
@mock.patch.object(db, 'cell_create')
def test_create_broker_hosts_with_url_decoding_fix(self,
mock_db_cell_create,
mock_ctxt):
"""Test the create function when broker_hosts is
passed
"""
cell_tp_url = "fake://the=user:the=password@127.0.0.1:5432/"
ctxt = mock.sentinel
mock_ctxt.return_value = mock.sentinel
self.commands.create("test",
broker_hosts='127.0.0.1:5432',
woffset=0, wscale=0,
username="the=user",
password="the=password")
exp_values = {'name': "test",
'is_parent': False,
'transport_url': cell_tp_url,
'weight_offset': 0.0,
'weight_scale': 0.0}
mock_db_cell_create.assert_called_once_with(ctxt, exp_values)
@mock.patch.object(context, 'get_admin_context')
@mock.patch.object(db, 'cell_create')
def test_create_hostname(self, mock_db_cell_create, mock_ctxt):