Added heat url in config for heat standalone mode

And use heat url for heat standalone mode in client heat.

Closes-Bug: #1255713

Change-Id: Ibbb0c53bd88b77b4444b652cebbd06034f69cebe
This commit is contained in:
JUN JIE NAN 2013-12-31 12:25:55 +08:00
parent 0c83ac25a9
commit 9684ee4546
4 changed files with 56 additions and 1 deletions

View File

@ -584,6 +584,10 @@
# (boolean value)
#insecure=false
# Optional heat url in format like
# http://0.0.0.0:8004/v1/%(tenant_id)s. (string value)
#url=<None>
[clients_keystone]

View File

@ -151,6 +151,11 @@ def register_clients_opts():
# register opts copy and put it to globals in order to
# generate_sample.sh to work
opts_copy = copy.deepcopy(clients_opts)
if client == 'heat':
opts_copy.append(
cfg.StrOpt('url',
help=_('Optional heat url in format like'
' http://0.0.0.0:8004/v1/%(tenant_id)s.')))
globals()[client_specific_group + '_opts'] = opts_copy
cfg.CONF.register_opts(opts_copy, group=client_specific_group)

View File

@ -270,6 +270,13 @@ class OpenStackClients(object):
cfg.CONF.import_opt(option, 'heat.common.config', group='clients')
return getattr(cfg.CONF.clients, option)
def _get_heat_url(self):
heat_url = self._get_client_option('heat', 'url')
if heat_url:
tenant_id = self.context.tenant_id
heat_url = heat_url % {'tenant_id': tenant_id}
return heat_url
def heat(self):
if self._heat:
return self._heat
@ -290,7 +297,10 @@ class OpenStackClients(object):
'insecure': self._get_client_option('heat', 'insecure')
}
endpoint = self.url_for(service_type='orchestration')
endpoint = self._get_heat_url()
if not endpoint:
endpoint = self.url_for(service_type='orchestration')
self._heat = heatclient.Client('1', endpoint, **args)
return self._heat

View File

@ -12,8 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from heat.engine import clients
from heat.tests.common import HeatTestCase
from heatclient import client as heatclient
class ClientsTest(HeatTestCase):
@ -21,3 +24,36 @@ class ClientsTest(HeatTestCase):
def test_clients_chosen_at_module_initilization(self):
self.assertFalse(hasattr(clients.Clients, 'nova'))
self.assertTrue(hasattr(clients.Clients('fakecontext'), 'nova'))
def test_clients_get_heat_url(self):
con = mock.Mock()
con.tenant_id = "b363706f891f48019483f8bd6503c54b"
obj = clients.Clients(con)
obj._get_client_option = mock.Mock()
obj._get_client_option.return_value = None
self.assertEqual(None, obj._get_heat_url())
heat_url = "http://0.0.0.0:8004/v1/%(tenant_id)s"
obj._get_client_option.return_value = heat_url
tenant_id = "b363706f891f48019483f8bd6503c54b"
result = heat_url % {"tenant_id": tenant_id}
self.assertEqual(result, obj._get_heat_url())
obj._get_client_option.return_value = result
self.assertEqual(result, obj._get_heat_url())
@mock.patch.object(heatclient, 'Client')
def test_clients_heat(self, mock_call):
con = mock.Mock()
con.auth_url = "http://auth.example.com:5000/v2.0"
con.tenant_id = "b363706f891f48019483f8bd6503c54b"
con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155"
obj = clients.Clients(con)
obj._get_heat_url = mock.Mock(name="_get_heat_url")
obj._get_heat_url.return_value = None
obj.url_for = mock.Mock(name="url_for")
obj.url_for.return_value = "url_from_keystone"
obj.heat()
self.assertEqual('url_from_keystone', mock_call.call_args[0][1])
obj._get_heat_url.return_value = "url_from_config"
obj._heat = None
obj.heat()
self.assertEqual('url_from_config', mock_call.call_args[0][1])