Skip to content

Commit

Permalink
PMM-13506 pmm3 fix cli integration tests (#880)
Browse files Browse the repository at this point in the history
 fix cli integration tests
  • Loading branch information
saikumar-vs authored Nov 5, 2024
1 parent 7cff4c7 commit 44200d8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
6 changes: 3 additions & 3 deletions cli/helpers/cli-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export async function getMetrics(
async () => {
const prefix = dockerContainer ? `sudo docker exec ${dockerContainer} ` : '';
const adminList = (await execute(`${prefix || 'sudo '}pmm-admin list`).assertSuccess()).getStdOutLines();
const serviceId: string = adminList.find((item) => item.includes(serviceName))!
const serviceId: string = adminList.find((item) => item.includes(serviceName))
?.trim()
.split(' ')
.find((item: string) => item.includes('/service_id/'))!
.trim() ?? '';
.pop() ?? ''; // Get the last item in the split result

if (!serviceId) {
throw new Error(`Failed to find '${serviceName}' service is in pmm-admin list output:\n${adminList}`);
Expand Down
32 changes: 16 additions & 16 deletions cli/tests/generic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
await output.assertSuccess();
// there are no request for those urls. but there are requests for /local/status
await output.stderr.containsMany([
'POST /v1/inventory/Services/List HTTP/1.1',
'POST /v1/inventory/Agents/List HTTP/1.1',
'GET /v1/inventory/services',
'GET /v1/inventory/agents',
]);
await output.outContains('.zip created.');
});
Expand All @@ -189,8 +189,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
await output.assertSuccess();
// there are no request for those urls. but there are requests for /local/status
await output.stderr.containsMany([
'(*Runtime).Submit() POST /v1/inventory/Services/List HTTP/1.1',
'(*Runtime).Submit() POST /v1/inventory/Agents/List HTTP/1.1',
'(*Runtime).Submit() GET /v1/inventory/services',
'(*Runtime).Submit() GET /v1/inventory/agents',
]);
await output.outContains('.zip created.');
});
Expand Down Expand Up @@ -267,8 +267,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec('sudo pmm-admin summary --skip-server --trace');
await output.assertSuccess();
await output.stderr.containsMany([
'(*Runtime).Submit() POST /v1/inventory/Services/List HTTP/1.1',
'(*Runtime).Submit() POST /v1/inventory/Agents/List HTTP/1.1']);
'(*Runtime).Submit() GET /v1/inventory/services',
'(*Runtime).Submit() GET /v1/inventory/agents']);
await output.outContains('.zip created.');
});

Expand All @@ -279,8 +279,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec('sudo pmm-admin summary --skip-server --debug');
await output.assertSuccess();
await output.stderr.containsMany([
'POST /v1/inventory/Services/List HTTP/1.1',
'POST /v1/inventory/Agents/List HTTP/1.1']);
'GET /v1/inventory/services',
'GET /v1/inventory/agents']);
await output.outContains('.zip created.');
});

Expand All @@ -292,8 +292,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec(`sudo pmm-admin summary --skip-server --json --debug --filename=${ZIP_FILE_NAME}`);
await output.assertSuccess();
await output.stderr.containsMany([
'POST /v1/inventory/Services/List HTTP/1.1',
'POST /v1/inventory/Agents/List HTTP/1.1']);
'GET /v1/inventory/services',
'GET /v1/inventory/agents']);
});

/**
Expand All @@ -318,8 +318,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec('sudo pmm-admin summary --pprof --trace');
await output.assertSuccess();
await output.outContainsMany([
'(*Runtime).Submit() POST /v1/inventory/Services/List HTTP/1.1',
'(*Runtime).Submit() POST /v1/inventory/Agents/List HTTP/1.1',
'(*Runtime).Submit() GET /v1/inventory/services',
'(*Runtime).Submit() GET /v1/inventory/agents',
'.zip created.']);
const zipName = output.getStdOutLines().find((item) => item.includes('.zip created.'))!
.split(' ').at(0) ?? '';
Expand All @@ -334,8 +334,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec('sudo pmm-admin summary --pprof --debug');
await output.assertSuccess();
await output.outContainsMany([
'POST /v1/inventory/Services/List HTTP/1.1',
'POST /v1/inventory/Agents/List HTTP/1.1',
'GET /v1/inventory/services',
'GET /v1/inventory/agents',
'.zip created.']);
const zipName = output.getStdOutLines().find((item) => item.includes('.zip created.'))!
.split(' ').at(0) ?? '';
Expand Down Expand Up @@ -402,8 +402,8 @@ test.describe('PMM Client "Generic" CLI tests', async () => {
const output = await cli.exec(`pmm-admin summary --pprof --debug --filename=${zipName} --skip-server`);
await output.assertSuccess();
await output.outContainsMany([
'POST /v1/inventory/Services/List HTTP/1.1',
'POST /v1/inventory/Agents/List HTTP/1.1',
'GET /v1/inventory/services',
'GET /v1/inventory/agents',
`${zipName} created.`]);
expect(readZipFile(zipName), `Verify 'client/pprof/' is present in ${zipName}`).toContain('client/pprof/');
expect(readZipFile(zipName), `Verify there are 8 files in ${zipName}`).toHaveLength(8);
Expand Down
18 changes: 11 additions & 7 deletions cli/tests/mysql-conf-file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { test, expect } from '@playwright/test';
import * as cli from '@helpers/cli-helper';
import {execute} from "@helpers/cli-helper";

const MYSQL_USER = 'msandbox';
const MYSQL_PASSWORD = 'msandbox';
const ipPort = '127.0.0.1:3318';

test.describe('Percona Server MySql (PS) Configuration file test ', async () => {
test.describe('Percona Server MySql (PS) Configuration file test', async () => {
test.beforeAll(async ({}) => {
const result = await cli.exec('docker ps | grep mysql_pmm | awk \'{print $NF}\'');
await result.outContains('mysql_pmm', 'MYSQL docker container should exist. please run pmm-framework with --database mysql');
Expand Down Expand Up @@ -34,19 +35,22 @@ test.describe('Percona Server MySql (PS) Configuration file test ', async () =>
let n = 1;
for (const host of hosts) {
// Add MySQL to monitoring using conf file:
let output = await cli.exec(`sudo pmm-admin add mysql --query-source=perfschema @${confFilePath} mysql_conf_${n++} ${host}`);
let output = await cli.exec(`sudo pmm-admin add mysql --query-source=perfschema @${confFilePath} mysql_conf_${n} ${host}`);
await output.assertSuccess();
await output.outContains('MySQL Service added.');

// Check that MySQL exporter is RUNNING:
const serviceId = output.getStdOutLines().find((item) => item.includes('/service_id/'))!.trim()
.split(':')
.find((item) => item.includes('/service_id/'))!
.trim();
const adminList = (await execute('sudo pmm-admin list').assertSuccess()).getStdOutLines();
// eslint-disable-next-line @typescript-eslint/no-loop-func
const serviceId: string = adminList.find((item: string | string[]) => item.includes(`mysql_conf_${n}`))
?.trim()
.split(' ')
.pop() ?? ''; // Get the last item in the split result

await expect(async () => {
output = await cli.exec(`sudo pmm-admin list | grep _exporter | grep ${serviceId}`);
await output.outContains('Running');
}).toPass({ intervals: [2_000], timeout: 10_000 });
n++;
}
});

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/pmm-client-docker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ test.describe('PMM Client Docker CLI tests', async () => {
test.describe('-promscrape.maxScapeSize tests', async () => {
const defaultScrapeSize = '64';
test.beforeAll(async () => {
await (await cli.exec('docker-compose -f test-setup/docker-compose-scrape-intervals.yml up -d')).assertSuccess();
await (await cli.exec('docker compose -f test-setup/docker-compose-scrape-intervals.yml up -d')).assertSuccess();
});

test.afterAll(async () => {
await (await cli.exec('docker-compose -f test-setup/docker-compose-scrape-intervals.yml down')).assertSuccess();
await (await cli.exec('docker compose -f test-setup/docker-compose-scrape-intervals.yml down')).assertSuccess();
});

test('@PMM-T1664 Verify default value for vm_agents -promscrape.maxScapeSize parameter pmm-client container', async ({}) => {
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/pmm-server-only.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test.describe('PMM Server CLI tests for Docker Environment Variables', async ()
test('PMM-T226 run docker container with all valid environment variables not causing any warning or error message', async ({}) => {
// @ts-ignore
await cli.exec(`docker run -d -p 83:8080 -p 447:8443
--name PMM-T226 -e PMM_DATA_RETENTION=48h -e PMM_DISABLE_UPDATES=true -e PMM_DISABLE_TELEMETRY=false
--name PMM-T226 -e PMM_DATA_RETENTION=48h -e PMM_ENABLE_UPDATES=false -e PMM_ENABLE_TELEMETRY=false
-e PMM_METRICS_RESOLUTION=24h -e PMM_METRICS_RESOLUTION_LR=24h -e PMM_METRICS_RESOLUTION_MR=24h ${DOCKER_IMAGE}`);
stopList.push('PMM-T226');
removeList.push('PMM-T226');
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/proxySql.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from '@playwright/test';
import * as cli from '@helpers/cli-helper';

const PXC_USER = 'admin';
const PXC_PASSWORD = 'admin';
const ipPort = '127.0.0.1:6032';
const PXC_USER = 'proxysql_user';
const PXC_PASSWORD = 'passw0rd';
const ipPort = '127.0.0.1:6033';

test.describe('PMM Client CLI tests for ProxySQL', async () => {
test.beforeAll(async ({}) => {
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/remove.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe('PMM Server CLI tests for Docker Environment Variables', async ()
test.beforeAll(async () => {
await cli.exec(`PMM_SERVER_IMAGE=${PMM_SERVER_IMAGE}
PMM_CLIENT_IMAGE=${PMM_CLIENT_IMAGE}
docker-compose -f test-setup/docker-compose-pmm-admin-remove.yml up -d`);
docker compose -f test-setup/docker-compose-pmm-admin-remove.yml up -d`);
await cli.exec('sleep 10');

for (let i = 0; i < 2; i++) {
Expand All @@ -28,15 +28,15 @@ test.describe('PMM Server CLI tests for Docker Environment Variables', async ()
});

test.afterAll(async () => {
await cli.exec('docker-compose -f test-setup/docker-compose-pmm-admin-remove.yml down -v');
await cli.exec('docker compose -f test-setup/docker-compose-pmm-admin-remove.yml down -v');
});

test('PMM-T1286, PMM-T1287, PMM-T1288, PMM-T1308 - Verify service removal without specifying service name/service id', async ({}) => {
for (let i = 0; i < services.length; i++) {
const output = await cli.exec(`docker exec pmm-client-remove pmm-admin remove ${services[i]}`);
await output.exitCodeEquals(1);
await output.outContains(
'We could not find a service associated with the local node. Please provide "Service ID" or "Service name"',
'We could not find a service associated with the local node. Please provide "Service ID" or "Service name".',
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/remoteInstances/remoteInstancesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ DB_CONFIG = {
MYSQL_SERVER_PORT: '3306',
POSTGRES_SERVER_PORT: '5432',
MONGODB_SERVER_PORT: '27017',
PROXYSQL_SERVER_PORT: '6032',
PROXYSQL_SERVER_PORT: '6033',
};

if (process.env.AMI_UPGRADE_TESTING_INSTANCE === 'true' || process.env.OVF_UPGRADE_TESTING_INSTANCE === 'true') {
Expand Down Expand Up @@ -187,8 +187,8 @@ module.exports = {
proxysql_2_1_1: {
host: (PMM_SERVER_OVF_AMI_SETUP === 'true' ? SERVER_HOST : 'proxysql'),
port: DB_CONFIG.PROXYSQL_SERVER_PORT,
username: 'proxyadmin',
password: 'yxZq!4SGv0A1',
username: 'proxysql_user',
password: 'passw0rd',
environment: 'proxy_env',
clusterName: 'proxy_clstr',
},
Expand Down

0 comments on commit 44200d8

Please sign in to comment.