Merge "Always declare agent RabbitMQ queues"

This commit is contained in:
Jenkins 2016-11-29 02:57:03 +00:00 committed by Gerrit Code Review
commit 5553aea934
3 changed files with 17 additions and 18 deletions

View File

@ -142,8 +142,6 @@ Methods:
- $.networks.customNetworks.select($this.joinNet($, $securityGroupName))
- $preparedUserData: $.prepareUserData()
# Create MQ queue to communicate with the VM
- $.agent.prepare()
- $properties:
name: $.name
flavor: $.flavor

View File

@ -51,21 +51,25 @@ class Agent(object):
self._enabled = True
env = host.find_owner('io.murano.Environment')
self._queue = str('e%s-h%s' % (env.id, host.id)).lower()
self._initialized = False
@property
def enabled(self):
return self._enabled
def prepare(self):
def _initialize(self):
if self._initialized:
return
# (sjmc7) - turn this into a no-op if agents are disabled
if CONF.engine.disable_murano_agent:
LOG.debug('Use of murano-agent is disallowed '
'by the server configuration')
return
region = dsl.MuranoObjectInterface.create(self._host().getRegion())
with common.create_rmq_client(region) as client:
client.declare(self._queue, enable_ha=True, ttl=86400000)
else:
region = dsl.MuranoObjectInterface.create(self._host().getRegion())
with common.create_rmq_client(region) as client:
client.declare(self._queue, enable_ha=True, ttl=86400000)
self._initialized = True
def queue_name(self):
return self._queue
@ -84,6 +88,7 @@ class Agent(object):
def _send(self, template, wait_results, timeout):
"""Send a message over the MQ interface."""
self._initialize()
region = self._host().getRegion()
msg_id = template.get('ID', uuid.uuid4().hex)
if wait_results:

View File

@ -18,7 +18,6 @@ import datetime
import json
import os
import tempfile
import unittest
import mock
from oslo_config import cfg
@ -77,12 +76,12 @@ class TestAgent(base.MuranoTestCase):
return file.read()
@mock.patch('murano.common.messaging.mqclient.kombu')
def test_prepare(self, mock_kombu):
self.agent.prepare()
def test_send_creates_queue(self, mock_kombu):
self.agent.send_raw({})
# Verify that MQClient was instantiated, by checking whether
# kombu.Connection was called.
mock_kombu.Connection.assert_called_once_with(
mock_kombu.Connection.assert_called_with(
'amqp://{login}:{password}@{host}:{port}/{virtual_host}'.format(
**self.rabbit_mq_settings['agentRabbitMq']
), ssl=None)
@ -93,14 +92,12 @@ class TestAgent(base.MuranoTestCase):
self.assertEqual(1, mock_kombu.Queue.call_count)
@mock.patch('murano.engine.system.agent.LOG')
def test_prepare_with_murano_agent_disabled(self, mock_log):
def test_send_with_murano_agent_disabled(self, mock_log):
CONF.set_override('disable_murano_agent', True, group='engine',
enforce_type=True)
self.agent.prepare()
mock_log.debug.assert_called_once_with(
'Use of murano-agent is disallowed by the server configuration')
self.assertRaises(exceptions.PolicyViolationException,
self.agent.send_raw, {})
@mock.patch('murano.common.messaging.mqclient.kombu')
def test_send(self, mock_kombu):
@ -121,7 +118,6 @@ class TestAgent(base.MuranoTestCase):
body=json.dumps(plan),
message_id=plan['ID'])
@unittest.skipIf(True, 'Skipping until bug #1633176 resolved.')
@mock.patch('murano.engine.system.agent.eventlet.event.Event')
@mock.patch('murano.common.messaging.mqclient.kombu')
def test_is_ready(self, mock_kombu, mock_event):