Skip to content

Commit 15467de

Browse files
author
Yevhen Miroshnychenko
authored
MCLOUD-5352: [ece-tools] Create a functional test for Split DB functionality (magento#718)
1 parent 7e66df4 commit 15467de

File tree

3 files changed

+549
-0
lines changed

3 files changed

+549
-0
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Test\Functional\Acceptance;
9+
10+
use CliTester;
11+
use Codeception\Example;
12+
use Exception;
13+
use Robo\Exception\TaskException;
14+
15+
/**
16+
* Checks database backup functionality
17+
*/
18+
class BackupDbCest extends AbstractCest
19+
{
20+
/**
21+
* @var array
22+
*/
23+
private $expectedLogs = [
24+
'INFO: Starting backup.',
25+
'NOTICE: Enabling Maintenance mode',
26+
'INFO: Trying to kill running cron jobs and consumers processes',
27+
'INFO: Running Magento cron and consumers processes were not found.',
28+
'INFO: Waiting for lock on db dump.',
29+
'NOTICE: Maintenance mode is disabled.',
30+
'INFO: Backup completed.'
31+
];
32+
33+
/**
34+
* @var array
35+
*/
36+
private $envMagento = ['stage' => ['global' => ['SCD_ON_DEMAND' => true]]];
37+
38+
/**
39+
* {@inheritDoc}
40+
* @param CliTester $I
41+
*/
42+
public function _before(CliTester $I): void
43+
{
44+
// Do nothing
45+
}
46+
47+
/**
48+
* @param CliTester $I
49+
* @param Example $data
50+
* @throws Exception
51+
* @dataProvider dataProviderMagentoCloudVersions
52+
*/
53+
public function testBackUpDb(CliTester $I, Example $data): void
54+
{
55+
56+
$this->prepareWorkplace($I, $data['version']);
57+
58+
// Part of test without 'SplitDB' architecture
59+
$this->partRunDbDumpWithoutSplitDbArch($I);
60+
61+
$I->stopEnvironment(true);
62+
63+
// Part of test with 'SplitDB' architecture
64+
$this->partRunDbDumpWithSplitDbArch($I);
65+
}
66+
67+
/**
68+
* @return array
69+
*/
70+
protected function dataProviderMagentoCloudVersions(): array
71+
{
72+
return [
73+
['version' => 'master'],
74+
['version' => '2.3.4'],
75+
];
76+
}
77+
78+
/**
79+
* Part of test without 'SplitDB' architecture
80+
*
81+
* @param CliTester $I
82+
* @throws TaskException
83+
*/
84+
private function partRunDbDumpWithoutSplitDbArch(CliTester $I)
85+
{
86+
$I->writeEnvMagentoYaml($this->envMagento);
87+
$I->runEceDockerCommand('build:compose --mode=production');
88+
89+
// Running database dump command with invalid database label
90+
$I->runDockerComposeCommand('run build cloud-build');
91+
$I->runDockerComposeCommand('run deploy ece-command db-dump incorrectName');
92+
$I->seeInOutput(
93+
'CRITICAL: Incorrect the database names: [ incorrectName ].'
94+
. ' Available database names: [ main quote sales ]'
95+
);
96+
97+
// Running database dump command with unavailable database label
98+
$I->runDockerComposeCommand('run deploy cloud-deploy');
99+
100+
$I->runDockerComposeCommand('run deploy ece-command db-dump quote');
101+
$I->seeInOutput(
102+
'CRITICAL: Environment does not have connection `checkout` associated with database `quote`'
103+
);
104+
105+
$I->runDockerComposeCommand('run deploy ece-command db-dump sales');
106+
$I->seeInOutput(
107+
'CRITICAL: Environment does not have connection `sales` associated with database `sales`'
108+
);
109+
110+
$I->runDockerComposeCommand('run deploy ece-command db-dump quote sales');
111+
$I->seeInOutput(
112+
'CRITICAL: Environment does not have connection `checkout` associated with database `quote`'
113+
);
114+
115+
// Running database dump command without database label (by default)
116+
$I->runDockerComposeCommand('run deploy ece-command db-dump');
117+
$I->seeInOutput(array_merge(
118+
$this->expectedLogs,
119+
[
120+
'INFO: Start creation DB dump for main database...',
121+
'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main',
122+
]
123+
));
124+
$I->doNotSeeInOutput(['quote', 'sales']);
125+
}
126+
127+
/**
128+
* Part of test with 'SplitDB' architecture
129+
*
130+
* @param CliTester $I
131+
* @throws TaskException
132+
*/
133+
private function partRunDbDumpWithSplitDbArch(CliTester $I)
134+
{
135+
// Deploy 'Split Db' architecture
136+
$services = $I->readServicesYaml();
137+
$appMagento = $I->readAppMagentoYaml();
138+
$services['mysql-quote']['type'] = 'mysql:10.2';
139+
$services['mysql-sales']['type'] = 'mysql:10.2';
140+
$appMagento['relationships']['database-quote'] = 'mysql-quote:mysql';
141+
$appMagento['relationships']['database-sales'] = 'mysql-sales:mysql';
142+
$this->envMagento['stage']['deploy']['SPLIT_DB'] = ['quote', 'sales'];
143+
$I->writeServicesYaml($services);
144+
$I->writeAppMagentoYaml($appMagento);
145+
$I->writeEnvMagentoYaml($this->envMagento);
146+
$I->runEceDockerCommand('build:compose --mode=production');
147+
$I->startEnvironment();
148+
$I->runDockerComposeCommand('run deploy cloud-deploy');
149+
150+
// Running database dump command without database labels (by default)
151+
$I->runDockerComposeCommand('run deploy ece-command db-dump');
152+
$I->seeInOutput(array_merge(
153+
$this->expectedLogs,
154+
[
155+
'INFO: Start creation DB dump for main database...',
156+
'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main',
157+
'INFO: Start creation DB dump for quote database...',
158+
'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote',
159+
'INFO: Start creation DB dump for sales database...',
160+
'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales',
161+
]
162+
));
163+
164+
// Running database dump command with database labels
165+
$I->runDockerComposeCommand('run deploy ece-command db-dump quote sales');
166+
$I->seeInOutput(array_merge(
167+
$this->expectedLogs,
168+
[
169+
'INFO: Start creation DB dump for quote database...',
170+
'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote',
171+
'INFO: Start creation DB dump for sales database...',
172+
'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales',
173+
]
174+
));
175+
$I->doNotSeeInOutput('main');
176+
}
177+
}

0 commit comments

Comments
 (0)