Skip to content

Commit e3b13ca

Browse files
authored
MCLOUD-6937: Deployment is not failed if install Magento 2.4.0 with mysql search engine (magento#782)
1 parent 48ed5d4 commit e3b13ca

File tree

8 files changed

+117
-22
lines changed

8 files changed

+117
-22
lines changed

config/schema.error.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
type: critical
323323
!php/const Magento\MagentoCloud\App\Error::DEPLOY_ES_CANNOT_CONNECT:
324324
title: 'Can not connect to the Elasticsearch service'
325-
suggestion: 'Check that credentials for elasticsearch are correct and service is running'
325+
suggestion: 'Check for valid elasticsearch credentials and verify that the service is running'
326326
stage: deploy
327327
type: critical
328328
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_BRAINTREE_VARIABLE:
@@ -331,12 +331,18 @@
331331
suggestion: 'Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Magento Marketplace instead.'
332332
stage: deploy
333333
type: critical
334-
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_SEARCH_ENGINE:
334+
!php/const Magento\MagentoCloud\App\Error::DEPLOY_ES_SERVICE_NOT_INSTALLED:
335335
step: validate-config
336336
title: 'Magento 2.4.0 requires Elasticsearch service to be installed'
337337
suggestion: 'Install Elasticsearch service'
338338
stage: deploy
339339
type: critical
340+
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_SEARCH_ENGINE:
341+
step: validate-config
342+
title: 'The search engine must be set to Elasticsearch for Magento >= 2.4.0'
343+
suggestion: 'Check the SEARCH_CONFIGURATION variable for the `engine` option. If it is configured, remove the option, or set the value to "elasticsearch".'
344+
stage: deploy
345+
type: critical
340346
!php/const Magento\MagentoCloud\App\Error::PD_DEPLOY_IS_FAILED:
341347
step: is-deploy-failed
342348
title: 'Deploy stage failed'

dist/error-codes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ Critical errors indicate a problem with the Magento Commerce Cloud project confi
7171
| 129 | install-update: reset-password | Unable to read reset password template | |
7272
| 130 | install-update: cache_type | Command failed: `php ./bin/magento cache:enable` | Command `php ./bin/magento cache:enable` runs only when Magento was installed but `./app/etc/env.php` file was absent or empty at the beginning of the deployment. Check the `cloud.log` for more information. Add `VERBOSE_COMMANDS: '-vvv'` into `.magento.env.yaml` for more detailed command output. |
7373
| 131 | install-update | The `crypt/key` key value does not exist in the `./app/etc/env.php` file or the `CRYPT_KEY` cloud environment variable | This error occurs if the `./app/etc/env.php` file is not present when Magento deployment begins, or if the `crypt/key` value is undefined. If you migrated the database from another environment, retrieve the crypt key value from that environment. Then, add the value to the [CRYPT_KEY](https://devdocs.magento.com/cloud/env/variables-deploy.html#crypt_key) cloud environment variable in your current environment. See [Add the Magento encryption key](https://devdocs.magento.com/cloud/setup/first-time-setup-import-import.html#encryption-key). If you accidentally removed the `./app/etc/env.php` file, use the following command to restore it from the backup files created from a previous deployment: `./vendor/bin/ece-tools backup:restore` CLI command ." |
74-
| 132 | | Can not connect to the Elasticsearch service | Check that credentials for elasticsearch are correct and service is running |
74+
| 132 | | Can not connect to the Elasticsearch service | Check for valid elasticsearch credentials and verify that the service is running |
7575
| 133 | validate-config | Remove Magento Braintree module configuration which is no longer supported in Magento 2.4 and later versions. | Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Magento Marketplace instead. |
7676
| 134 | validate-config | Magento 2.4.0 requires Elasticsearch service to be installed | Install Elasticsearch service |
77+
| 135 | validate-config | The search engine must be set to Elasticsearch for Magento >= 2.4.0 | Check the SEARCH_CONFIGURATION variable for the `engine` option. If it is configured, remove the option, or set the value to "elasticsearch". |
7778

7879
### Post-deploy stage
7980

src/App/Error.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class Error
7373
public const DEPLOY_CRYPT_KEY_IS_ABSENT = 131;
7474
public const DEPLOY_ES_CANNOT_CONNECT = 132;
7575
public const DEPLOY_WRONG_BRAINTREE_VARIABLE = 133;
76-
public const DEPLOY_WRONG_SEARCH_ENGINE = 134;
76+
public const DEPLOY_ES_SERVICE_NOT_INSTALLED = 134;
77+
public const DEPLOY_WRONG_SEARCH_ENGINE = 135;
7778

7879
public const PD_DEPLOY_IS_FAILED = 201;
7980
public const PD_ENV_PHP_IS_NOT_WRITABLE = 202;

src/Command/Dev/GenerateSchemaError.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GenerateSchemaError extends Command
5151
width: 200px;
5252
}
5353
</style>
54+
5455
EOT;
5556

5657
/**

src/Config/Validator/Deploy/ElasticSearchIntegrity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function validate(): Validator\ResultInterface
6060
if ($this->magentoVersion->isGreaterOrEqual('2.4.0')
6161
&& !$this->elasticsearch->isInstalled()
6262
) {
63-
return $this->resultFactory->errorByCode(Error::DEPLOY_WRONG_SEARCH_ENGINE);
63+
return $this->resultFactory->errorByCode(Error::DEPLOY_ES_SERVICE_NOT_INSTALLED);
6464
}
6565
} catch (UndefinedPackageException | FileSystemException $exception) {
6666
throw new ValidatorException($exception->getMessage(), $exception->getCode(), $exception);

src/Config/Validator/Deploy/SearchConfiguration.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
namespace Magento\MagentoCloud\Config\Validator\Deploy;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\App\GenericException;
1112
use Magento\MagentoCloud\Config\ConfigMerger;
1213
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1314
use Magento\MagentoCloud\Config\Validator;
1415
use Magento\MagentoCloud\Config\Validator\ResultFactory;
16+
use Magento\MagentoCloud\Config\ValidatorException;
1517
use Magento\MagentoCloud\Config\ValidatorInterface;
18+
use Magento\MagentoCloud\Package\MagentoVersion;
19+
use Magento\MagentoCloud\Service\ElasticSearch;
1620

1721
/**
1822
* Validates SEARCH_CONFIGURATION variable
@@ -34,39 +38,60 @@ class SearchConfiguration implements ValidatorInterface
3438
*/
3539
private $configMerger;
3640

41+
/**
42+
* @var MagentoVersion
43+
*/
44+
private $magentoVersion;
45+
3746
/**
3847
* @param ResultFactory $resultFactory
3948
* @param DeployInterface $stageConfig
4049
* @param ConfigMerger $configMerger
50+
* @param MagentoVersion $magentoVersion
4151
*/
4252
public function __construct(
4353
ResultFactory $resultFactory,
4454
DeployInterface $stageConfig,
45-
ConfigMerger $configMerger
55+
ConfigMerger $configMerger,
56+
MagentoVersion $magentoVersion
4657
) {
4758
$this->resultFactory = $resultFactory;
4859
$this->stageConfig = $stageConfig;
4960
$this->configMerger = $configMerger;
61+
$this->magentoVersion = $magentoVersion;
5062
}
5163

5264
/**
53-
* Checks that SEARCH_CONFIGURATION variable contains at least 'engine' option if _merge was not set
65+
* Checks that SEARCH_CONFIGURATION variable contains at least 'engine' option if _merge was not set.
66+
* Checks that search engine for Magento 2.4 is set to elasticsearch
5467
*
55-
* @return Validator\ResultInterface
68+
* {@inheritDoc}
5669
*/
5770
public function validate(): Validator\ResultInterface
5871
{
59-
$searchConfig = $this->stageConfig->get(DeployInterface::VAR_SEARCH_CONFIGURATION);
60-
if ($this->configMerger->isEmpty($searchConfig) || $this->configMerger->isMergeRequired($searchConfig)) {
61-
return $this->resultFactory->success();
62-
}
72+
try {
73+
$searchConfig = $this->stageConfig->get(DeployInterface::VAR_SEARCH_CONFIGURATION);
74+
75+
if ($this->magentoVersion->isGreaterOrEqual('2.4.0')
76+
&& isset($searchConfig['engine'])
77+
&& $searchConfig['engine'] != ElasticSearch::ENGINE_NAME
78+
) {
79+
return $this->resultFactory->errorByCode(Error::DEPLOY_WRONG_SEARCH_ENGINE);
80+
}
81+
82+
if ($this->configMerger->isEmpty($searchConfig) || $this->configMerger->isMergeRequired($searchConfig)) {
83+
return $this->resultFactory->success();
84+
}
6385

64-
if (!isset($searchConfig['engine'])) {
65-
return $this->resultFactory->error(
66-
sprintf('Variable %s is not configured properly', DeployInterface::VAR_SEARCH_CONFIGURATION),
67-
'At least engine option must be configured',
68-
Error::DEPLOY_WRONG_CONFIGURATION_SEARCH
69-
);
86+
if (!isset($searchConfig['engine'])) {
87+
return $this->resultFactory->error(
88+
sprintf('Variable %s is not configured properly', DeployInterface::VAR_SEARCH_CONFIGURATION),
89+
'At least engine option must be configured',
90+
Error::DEPLOY_WRONG_CONFIGURATION_SEARCH
91+
);
92+
}
93+
} catch (GenericException $exception) {
94+
throw new ValidatorException($exception->getMessage(), $exception->getCode(), $exception);
7095
}
7196

7297
return $this->resultFactory->success();

src/Test/Unit/Config/Validator/Deploy/ElasticsearchIntegrityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testValidateNoElasticSearch(): void
8686
->willReturn(false);
8787
$this->resultFactoryMock->expects($this->once())
8888
->method('errorByCode')
89-
->with(Error::DEPLOY_WRONG_SEARCH_ENGINE);
89+
->with(Error::DEPLOY_ES_SERVICE_NOT_INSTALLED);
9090

9191
$this->validator->validate();
9292
}

src/Test/Unit/Config/Validator/Deploy/SearchConfigurationTest.php

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\MagentoCloud\Config\Validator\Result\Error;
1515
use Magento\MagentoCloud\Config\Validator\Result\Success;
1616
use Magento\MagentoCloud\Config\Validator\ResultFactory;
17+
use Magento\MagentoCloud\Config\ValidatorException;
18+
use Magento\MagentoCloud\Package\MagentoVersion;
19+
use Magento\MagentoCloud\Package\UndefinedPackageException;
1720
use PHPUnit\Framework\MockObject\MockObject;
1821
use PHPUnit\Framework\TestCase;
1922

@@ -37,6 +40,11 @@ class SearchConfigurationTest extends TestCase
3740
*/
3841
private $stageConfigMock;
3942

43+
/**
44+
* @var MagentoVersion|MockObject
45+
*/
46+
private $magentoVersionMock;
47+
4048
/**
4149
* @inheritdoc
4250
*/
@@ -47,11 +55,13 @@ protected function setUp()
4755
'error' => $this->createMock(Error::class)
4856
]);
4957
$this->stageConfigMock = $this->getMockForAbstractClass(DeployInterface::class);
58+
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
5059

5160
$this->validator = new SearchConfiguration(
5261
$this->resultFactoryMock,
5362
$this->stageConfigMock,
54-
new ConfigMerger()
63+
new ConfigMerger(),
64+
$this->magentoVersionMock
5565
);
5666
}
5767

@@ -75,10 +85,16 @@ public function testErrorCode()
7585
/**
7686
* @param array $searchConfiguration
7787
* @param string $expectedResultClass
88+
* @param bool $isMagento24plus
7889
* @dataProvider validateDataProvider
90+
* @throws ValidatorException
7991
*/
80-
public function testValidate(array $searchConfiguration, string $expectedResultClass)
92+
public function testValidate(array $searchConfiguration, string $expectedResultClass, bool $isMagento24plus = false)
8193
{
94+
$this->magentoVersionMock->expects($this->once())
95+
->method('isGreaterOrEqual')
96+
->with('2.4.0')
97+
->willReturn($isMagento24plus);
8298
$this->stageConfigMock->expects($this->once())
8399
->method('get')
84100
->with(DeployInterface::VAR_SEARCH_CONFIGURATION)
@@ -125,13 +141,58 @@ public function validateDataProvider(): array
125141
Success::class,
126142
],
127143
[
128-
129144
[
130145
'engine' => 'mysql',
131146
'_merge' => true,
132147
],
133148
Success::class,
134149
],
150+
[
151+
[],
152+
Success::class,
153+
true
154+
],
155+
[
156+
[
157+
'engine' => 'mysql',
158+
'_merge' => true,
159+
],
160+
Error::class,
161+
true
162+
],
163+
[
164+
[
165+
'engine' => 'mysql',
166+
],
167+
Error::class,
168+
true
169+
],
170+
[
171+
[
172+
'engine' => 'elasticsearch',
173+
],
174+
Success::class,
175+
true
176+
],
135177
];
136178
}
179+
180+
/**
181+
* @throws ValidatorException
182+
*/
183+
public function testValidateWithException()
184+
{
185+
$this->expectException(ValidatorException::class);
186+
$this->expectExceptionMessage('some error');
187+
188+
$this->stageConfigMock->expects($this->once())
189+
->method('get')
190+
->with(DeployInterface::VAR_SEARCH_CONFIGURATION)
191+
->willReturn(['engine' => 'elasticsearch']);
192+
$this->magentoVersionMock->expects($this->once())
193+
->method('isGreaterOrEqual')
194+
->willThrowException(new UndefinedPackageException('some error'));
195+
196+
$this->validator->validate();
197+
}
137198
}

0 commit comments

Comments
 (0)