Skip to content

Commit 658164e

Browse files
authored
MCLOUD-9059: 2.4.5 RabbitMQ issues with fresh installation on fresh environments (#92)
1 parent 8aceb7f commit 658164e

File tree

6 files changed

+183
-23
lines changed

6 files changed

+183
-23
lines changed

src/Step/Deploy/InstallUpdate/ConfigUpdate/Amqp/Config.php src/Config/Amqp.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp;
8+
namespace Magento\MagentoCloud\Config;
99

10-
use Magento\MagentoCloud\Config\ConfigMerger;
1110
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1211
use Magento\MagentoCloud\Service\RabbitMq;
1312
use Magento\MagentoCloud\Package\MagentoVersion;
1413

1514
/**
1615
* Returns queue configuration.
1716
*/
18-
class Config
17+
class Amqp
1918
{
2019
/**
2120
* @var RabbitMq
@@ -61,9 +60,9 @@ public function __construct(
6160
* @return array
6261
* @throws \Magento\MagentoCloud\Package\UndefinedPackageException
6362
*/
64-
public function get(): array
63+
public function getConfig(): array
6564
{
66-
$config = $this->getConfig();
65+
$config = $this->getMergedConfig();
6766

6867
if ($this->magentoVersion->isGreaterOrEqual('2.2')) {
6968
$config['consumers_wait_for_messages'] = $this->stageConfig->get(
@@ -79,7 +78,7 @@ public function get(): array
7978
*
8079
* @return array
8180
*/
82-
private function getConfig(): array
81+
private function getMergedConfig(): array
8382
{
8483
$envQueueConfig = $this->stageConfig->get(DeployInterface::VAR_QUEUE_CONFIGURATION);
8584
$mqConfig = $this->getAmqpConfig();

src/Step/Deploy/InstallUpdate/ConfigUpdate/Amqp.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\MagentoCloud\Config\Magento\Env\ReaderInterface as ConfigReader;
1616
use Magento\MagentoCloud\Config\Magento\Env\WriterInterface as ConfigWriter;
1717
use Psr\Log\LoggerInterface;
18-
use Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp\Config as AmqpConfig;
18+
use Magento\MagentoCloud\Config\Amqp as AmqpConfig;
1919

2020
/**
2121
* @inheritdoc
@@ -75,7 +75,7 @@ public function execute()
7575
{
7676
try {
7777
$config = $this->configReader->read();
78-
$amqpConfig = $this->amqpConfig->get();
78+
$amqpConfig = $this->amqpConfig->getConfig();
7979
} catch (GenericException $e) {
8080
throw new StepException($e->getMessage(), $e->getCode(), $e);
8181
}

src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\MagentoCloud\Util\UrlManager;
2424
use Magento\MagentoCloud\Util\PasswordGenerator;
2525
use Magento\MagentoCloud\Config\RemoteStorage;
26+
use Magento\MagentoCloud\Config\Amqp as AmqpConfig;
2627

2728
/**
2829
* Generates command for magento installation
@@ -90,6 +91,11 @@ class InstallCommandFactory
9091
*/
9192
private $remoteStorage;
9293

94+
/**
95+
* @var AmqpConfig
96+
*/
97+
private $amqpConfig;
98+
9399
/**
94100
* @param UrlManager $urlManager
95101
* @param AdminDataInterface $adminData
@@ -102,6 +108,7 @@ class InstallCommandFactory
102108
* @param ElasticSearch $elasticSearch
103109
* @param OpenSearch $openSearch
104110
* @param RemoteStorage $remoteStorage
111+
* @param AmqpConfig $amqpConfig
105112
*
106113
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
107114
*/
@@ -116,7 +123,8 @@ public function __construct(
116123
MagentoVersion $magentoVersion,
117124
ElasticSearch $elasticSearch,
118125
OpenSearch $openSearch,
119-
RemoteStorage $remoteStorage
126+
RemoteStorage $remoteStorage,
127+
AmqpConfig $amqpConfig
120128
) {
121129
$this->urlManager = $urlManager;
122130
$this->adminData = $adminData;
@@ -129,6 +137,7 @@ public function __construct(
129137
$this->elasticSearch = $elasticSearch;
130138
$this->openSearch = $openSearch;
131139
$this->remoteStorage = $remoteStorage;
140+
$this->amqpConfig = $amqpConfig;
132141
}
133142

134143
/**
@@ -148,7 +157,8 @@ public function create(): string
148157
$this->getBaseOptions(),
149158
$this->getAdminOptions(),
150159
$this->getEsOptions(),
151-
$this->getRemoteStorageOptions()
160+
$this->getRemoteStorageOptions(),
161+
$this->getAmqpOptions()
152162
);
153163
} catch (GenericException $exception) {
154164
throw new ConfigException($exception->getMessage(), $exception->getCode(), $exception);
@@ -334,4 +344,27 @@ private function getConnectionData(): ConnectionInterface
334344

335345
return $this->connectionData;
336346
}
347+
348+
/**
349+
* Returns AMQP optional config options.
350+
*
351+
* @return array
352+
* @throws UndefinedPackageException
353+
*/
354+
private function getAmqpOptions(): array
355+
{
356+
$options = [];
357+
$config = $this->amqpConfig->getConfig();
358+
$map = ['host', 'port', 'user', 'password', 'virtualhost'];
359+
360+
if (!empty($config['amqp']['host'])) {
361+
foreach ($map as $option) {
362+
if (!empty($config['amqp'][$option])) {
363+
$options['--amqp-' . $option] = (string)$config['amqp'][$option];
364+
}
365+
}
366+
}
367+
368+
return $options;
369+
}
337370
}

src/Test/Unit/Step/Deploy/InstallUpdate/ConfigUpdate/Amqp/ConfigTest.php src/Test/Unit/Config/AmqpTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MagentoCloud\Test\Unit\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp;
8+
namespace Magento\MagentoCloud\Test\Unit\Config;
99

1010
use Magento\MagentoCloud\Config\ConfigMerger;
1111
use Magento\MagentoCloud\Package\MagentoVersion;
1212
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1313
use Magento\MagentoCloud\Package\UndefinedPackageException;
14-
use Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp\Config;
14+
use Magento\MagentoCloud\Config\Amqp;
1515
use Magento\MagentoCloud\Service\RabbitMq;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
2020
* @inheritdoc
2121
*/
22-
class ConfigTest extends TestCase
22+
class AmqpTest extends TestCase
2323
{
2424
/**
25-
* @var Config
25+
* @var Amqp
2626
*/
2727
protected $config;
2828

@@ -50,7 +50,7 @@ protected function setUp(): void
5050
$this->stageConfigMock = $this->getMockForAbstractClass(DeployInterface::class);
5151
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
5252

53-
$this->config = new Config(
53+
$this->config = new Amqp(
5454
$this->rabbitMq,
5555
$this->stageConfigMock,
5656
new ConfigMerger(),
@@ -67,9 +67,9 @@ protected function setUp(): void
6767
* @param array $expectedQueueConfig
6868
* @throws UndefinedPackageException
6969
*
70-
* @dataProvider getDataProvider
70+
* @dataProvider getConfigDataProvider
7171
*/
72-
public function testGet(
72+
public function testGetConfig(
7373
array $customQueueConfig,
7474
array $amqpServiceConfig,
7575
bool $isGreaterOrEqualReturns,
@@ -92,15 +92,15 @@ public function testGet(
9292
->with('2.2')
9393
->willReturn($isGreaterOrEqualReturns);
9494

95-
$this->assertEquals($expectedQueueConfig, $this->config->get());
95+
$this->assertEquals($expectedQueueConfig, $this->config->getConfig());
9696
}
9797

9898
/**
9999
* @return array
100100
*
101101
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
102102
*/
103-
public function getDataProvider(): array
103+
public function getConfigDataProvider(): array
104104
{
105105
return [
106106
'queue configuration does not exist' => [

src/Test/Unit/Step/Deploy/InstallUpdate/ConfigUpdate/AmqpTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\MagentoCloud\Config\Magento\Env\WriterInterface as ConfigWriter;
1818
use Psr\Log\LoggerInterface;
1919
use Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp;
20-
use Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate\Amqp\Config as AmqpConfig;
20+
use Magento\MagentoCloud\Config\Amqp as AmqpConfig;
2121

2222
/**
2323
* @inheritdoc
@@ -78,7 +78,7 @@ public function testExecuteWithoutAmqp(): void
7878
->method('read')
7979
->willReturn($config);
8080
$this->amqpConfigMock->expects($this->once())
81-
->method('get')
81+
->method('getConfig')
8282
->willReturn([]);
8383
$this->loggerMock->expects($this->never())
8484
->method('info');
@@ -113,7 +113,7 @@ public function testExecuteAddUpdate(): void
113113
->method('read')
114114
->willReturn($config);
115115
$this->amqpConfigMock->expects($this->once())
116-
->method('get')
116+
->method('getConfig')
117117
->willReturn($amqpConfig);
118118
$this->loggerMock->expects($this->once())
119119
->method('info')

0 commit comments

Comments
 (0)