Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] enabling flaky tests with endpoint #174679

Merged
merged 9 commits into from
Jan 15, 2024
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export async function ensureFleetDirectories() {

try {
await fs.stat(bundledPackageLocation);
logger.debug(`Bundled package directory ${bundledPackageLocation} exists`);
} catch (error) {
logger.warn(
`Bundled package directory ${bundledPackageLocation} does not exist. All packages will be sourced from ${registryUrl}.`
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/fleet_api_integration/apis/agents/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('es');
let elasticAgentpkgVersion: string;
// Failing: See https://github.com/elastic/kibana/issues/170690
// Failing: See https://github.com/elastic/kibana/issues/170690
// Failing: See https://github.com/elastic/kibana/issues/170690
describe.skip('fleet_list_agent', () => {

describe('fleet_list_agent', () => {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/fleet/agents');
const getPkRes = await supertest
Expand Down Expand Up @@ -159,6 +157,7 @@ export default function ({ getService }: FtrProviderContext) {
dataset: 'elastic_agent.elastic_agent',
},
elastic_agent: { id: 'agent1', process: 'elastic_agent' },
component: { id: 'component1' },
system: {
process: {
memory: {
Expand All @@ -179,6 +178,7 @@ export default function ({ getService }: FtrProviderContext) {
document: {
'@timestamp': new Date(now - 1 * 60 * 1000).toISOString(),
elastic_agent: { id: 'agent1', process: 'elastic_agent' },
component: { id: 'component2' },
data_stream: {
namespace: 'default',
type: 'metrics',
Expand Down
9 changes: 7 additions & 2 deletions x-pack/test/fleet_api_integration/apis/epm/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FtrProviderContext } from '../../../api_integration/ftr_provider_contex
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';
import { testUsers } from '../test_users';
import { bundlePackage, removeBundledPackages } from './install_bundled';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
Expand All @@ -22,6 +23,7 @@ export default function (providerContext: FtrProviderContext) {

const testPkgName = 'apache';
const testPkgVersion = '0.1.4';
const log = getService('log');

const uninstallPackage = async (name: string, version: string) => {
await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx');
Expand All @@ -38,8 +40,7 @@ export default function (providerContext: FtrProviderContext) {
'../fixtures/direct_upload_packages/apache_0.1.4.zip'
);

// FLAKY: https://github.com/elastic/kibana/issues/163203
describe.skip('EPM - get', () => {
describe('EPM - get', () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

Expand Down Expand Up @@ -114,13 +115,17 @@ export default function (providerContext: FtrProviderContext) {
before(async () => {
await installPackage(testPkgName, testPkgVersion);
await installPackage('experimental', '0.1.0');
await bundlePackage('endpoint-8.6.1');
await installPackage('endpoint', '8.6.1');
});
after(async () => {
await uninstallPackage(testPkgName, testPkgVersion);
await uninstallPackage('experimental', '0.1.0');
await uninstallPackage('endpoint', '8.6.1');
});
after(async () => {
await removeBundledPackages(log);
});
it('Allows the fetching of installed packages', async () => {
const res = await supertest.get(`/api/fleet/epm/packages/installed`).expect(200);
const packages = res.body.items;
Expand Down
71 changes: 36 additions & 35 deletions x-pack/test/fleet_api_integration/apis/epm/install_bundled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,59 @@ import expect from '@kbn/expect';
import fs from 'fs/promises';
import path from 'path';

import { ToolingLog } from '@kbn/tooling-log';
import { BUNDLED_PACKAGE_DIR } from '../../config.base';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
const log = getService('log');

const BUNDLED_PACKAGE_FIXTURES_DIR = path.join(
path.dirname(__filename),
'../fixtures/bundled_packages'
const BUNDLED_PACKAGE_FIXTURES_DIR = path.join(
path.dirname(__filename),
'../fixtures/bundled_packages'
);

export const bundlePackage = async (name: string) => {
try {
await fs.access(BUNDLED_PACKAGE_DIR);
} catch (error) {
await fs.mkdir(BUNDLED_PACKAGE_DIR);
}

await fs.copyFile(
path.join(BUNDLED_PACKAGE_FIXTURES_DIR, `${name}.zip`),
path.join(BUNDLED_PACKAGE_DIR, `${name}.zip`)
);
};

const bundlePackage = async (name: string) => {
try {
await fs.access(BUNDLED_PACKAGE_DIR);
} catch (error) {
await fs.mkdir(BUNDLED_PACKAGE_DIR);
}

await fs.copyFile(
path.join(BUNDLED_PACKAGE_FIXTURES_DIR, `${name}.zip`),
path.join(BUNDLED_PACKAGE_DIR, `${name}.zip`)
);
};
export const removeBundledPackages = async (log: ToolingLog) => {
try {
const files = await fs.readdir(BUNDLED_PACKAGE_DIR);

const removeBundledPackages = async () => {
try {
const files = await fs.readdir(BUNDLED_PACKAGE_DIR);
for (const file of files) {
const isFixtureFile = !!(await fs.readFile(path.join(BUNDLED_PACKAGE_FIXTURES_DIR, file)));

for (const file of files) {
const isFixtureFile = !!(await fs.readFile(path.join(BUNDLED_PACKAGE_FIXTURES_DIR, file)));

// Only remove fixture files - leave normal bundled packages in place
if (isFixtureFile) {
await fs.unlink(path.join(BUNDLED_PACKAGE_DIR, file));
}
// Only remove fixture files - leave normal bundled packages in place
if (isFixtureFile) {
await fs.unlink(path.join(BUNDLED_PACKAGE_DIR, file));
}
} catch (error) {
log.error('Error removing bundled packages');
log.error(error);
}
};
} catch (error) {
log.error('Error removing bundled packages');
log.error(error);
}
};

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
const log = getService('log');

describe('installing bundled packages', async () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

afterEach(async () => {
await removeBundledPackages();
await removeBundledPackages(log);
});

describe('without registry', () => {
Expand Down
24 changes: 17 additions & 7 deletions x-pack/test/fleet_api_integration/apis/epm/install_endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';
import { bundlePackage, removeBundledPackages } from './install_bundled';

export default function (providerContext: FtrProviderContext) {
/**
* There are a few features that are only currently supported for the Endpoint
* package due to security concerns.
*/
// Failing: See https://github.com/elastic/kibana/issues/156941
describe.skip('Install endpoint package', () => {
describe('Install endpoint package', () => {
const { getService } = providerContext;
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);
Expand All @@ -25,8 +25,9 @@ export default function (providerContext: FtrProviderContext) {
const dockerServers = getService('dockerServers');
const server = dockerServers.get('registry');
const es = getService('es');
const log = getService('log');
const pkgName = 'endpoint';
let pkgVersion: string;
const pkgVersion = '8.6.1';

const transforms = [
{
Expand All @@ -39,12 +40,21 @@ export default function (providerContext: FtrProviderContext) {
},
];

const installPackage = async (name: string, version: string) => {
await supertest
.post(`/api/fleet/epm/packages/${name}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
};

before(async () => {
if (!server.enabled) return;
// The latest endpoint package is already installed by default in our FTR config,
// just get the most recent version number.
const getResp = await supertest.get(`/api/fleet/epm/packages/${pkgName}`).expect(200);
pkgVersion = getResp.body.response.version;
await bundlePackage('endpoint-8.6.1');
await installPackage('endpoint', '8.6.1');
});
after(async () => {
await uninstallPackage('endpoint', '8.6.1');
await removeBundledPackages(log);
});

describe('install', () => {
Expand Down
9 changes: 7 additions & 2 deletions x-pack/test/fleet_api_integration/apis/epm/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../../api_integration/ftr_provider_contex
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';
import { testUsers } from '../test_users';
import { bundlePackage, removeBundledPackages } from './install_bundled';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
Expand All @@ -21,9 +22,9 @@ export default function (providerContext: FtrProviderContext) {
// because `this` has to point to the Mocha context
// see https://mochajs.org/#arrow-functions

// FLAKY: https://github.com/elastic/kibana/issues/167188
describe.skip('EPM - list', async function () {
describe('EPM - list', async function () {
skipIfNoDockerRegistry(providerContext);
const log = getService('log');

before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/fleet/empty_fleet_server');
Expand All @@ -32,6 +33,9 @@ export default function (providerContext: FtrProviderContext) {
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/fleet/empty_fleet_server');
});
after(async () => {
await removeBundledPackages(log);
});

describe('list api tests', async () => {
it('lists all packages from the registry', async function () {
Expand All @@ -47,6 +51,7 @@ export default function (providerContext: FtrProviderContext) {
});

it('lists all limited packages from the registry', async function () {
await bundlePackage('endpoint-8.6.1');
const fetchLimitedPackageList = async () => {
const response = await supertest
.get('/api/fleet/epm/packages/limited')
Expand Down
Binary file not shown.
Loading