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] Add integration test for epm install on multiple spaces #156864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function (providerContext: FtrProviderContext) {
expect(body).to.eql({ data_streams: [] });
});

it('TESTME should return correct basic data stream information', async function () {
it('should return correct basic data stream information', async function () {
await seedDataStreams();
// we can't compare the array directly as the order is unpredictable
const expectedStreamsByDataset = keyBy(
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/fleet_api_integration/apis/epm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ export default function loadTests({ loadTestFile, getService }) {
loadTestFile(require.resolve('./final_pipeline'));
loadTestFile(require.resolve('./custom_ingest_pipeline'));
loadTestFile(require.resolve('./verification_key_id'));
loadTestFile(require.resolve('./install_integration_in_multiple_spaces.ts'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';

const testSpaceId = 'fleet_test_space';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const kibanaServer = getService('kibanaServer');
const supertest = getService('supertest');
const dockerServers = getService('dockerServers');
const server = dockerServers.get('registry');
const pkgName = 'system';
const pkgVersion = '1.27.0';

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

const uninstallPackage = async (pkg: string, version: string) => {
await supertest
.delete(`/api/fleet/epm/packages/${pkg}/${version}`)
.set('kbn-xsrf', 'xxxx')
.expect(200);
};

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

const createSpace = async (spaceId: string) => {
await supertest.post(`/api/spaces/space`).set('kbn-xsrf', 'xxxx').send({
name: spaceId,
id: spaceId,
initials: 's',
color: '#D6BF57',
disabledFeatures: [],
imageUrl: '',
});
};

const deleteSpace = async (spaceId: string) => {
await supertest.delete(`/api/spaces/space/${spaceId}`).set('kbn-xsrf', 'xxxx').send();
};

const getTag = async (id: string, space?: string) =>
kibanaServer.savedObjects
.get({
type: 'tag',
id,
...(space && { space }),
})
.catch(() => {});

describe('When installing system integration in multiple spaces', async () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

before(async () => {
if (!server.enabled) return;
await installPackage(pkgName, pkgVersion);

await createSpace(testSpaceId);
await uninstallPackage(pkgName, pkgVersion);
await installPackageInSpace(pkgName, pkgVersion, testSpaceId);
});

after(async () => {
await deleteSpace(testSpaceId);
});

it('should install kibana assets', async function () {
// These are installed from Fleet along with every package
const resIndexPatternLogs = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'logs-*',
});
expect(resIndexPatternLogs.id).equal('logs-*');
const resIndexPatternMetrics = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'metrics-*',
});
expect(resIndexPatternMetrics.id).equal('metrics-*');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to check that the installed_kibana_space_id is set correctly on the SO. We have seen a support issue recently where this was the problem.

});

it('should correctly set installed_kibana_space_id on the SO', async function () {
const resEPMPackages = await kibanaServer.savedObjects.get({
type: 'epm-packages',
id: pkgName,
});
expect(resEPMPackages.attributes.installed_kibana_space_id).to.eql('fleet_test_space');
});

it('should create managed tag saved objects', async () => {
const defaultTag = await getTag('fleet-managed-default');
expect(defaultTag).not.equal(undefined);

const spaceTag = await getTag('fleet-managed-fleet_test_space', testSpaceId);
expect(spaceTag).not.equal(undefined);
});

it('should create package tag saved objects', async () => {
const spaceTag = await getTag(`fleet-pkg-${pkgName}-fleet_test_space`, testSpaceId);
expect(spaceTag).not.equal(undefined);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { Client } from '@elastic/elasticsearch';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
Expand All @@ -18,7 +17,6 @@ export default function (providerContext: FtrProviderContext) {
const supertest = getService('supertest');
const dockerServers = getService('dockerServers');
const server = dockerServers.get('registry');
const es: Client = getService('es');
const pkgName = 'only_dashboard';
const pkgVersion = '0.1.0';

Expand Down Expand Up @@ -69,10 +67,8 @@ export default function (providerContext: FtrProviderContext) {
});

expectAssetsInstalled({
pkgVersion,
pkgName,
es,
kibanaServer,
space: testSpaceId,
});
});

Expand Down Expand Up @@ -123,17 +119,7 @@ export default function (providerContext: FtrProviderContext) {
});
}

const expectAssetsInstalled = ({
pkgVersion,
pkgName,
es,
kibanaServer,
}: {
pkgVersion: string;
pkgName: string;
es: Client;
kibanaServer: any;
}) => {
const expectAssetsInstalled = ({ kibanaServer, space }: { kibanaServer: any; space: string }) => {
it('should have installed the kibana assets', async function () {
// These are installed from Fleet along with every package
const resIndexPatternLogs = await kibanaServer.savedObjects.get({
Expand All @@ -151,20 +137,20 @@ const expectAssetsInstalled = ({
const resDashboard = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'test_dashboard',
space: testSpaceId,
space,
});
expect(resDashboard.id).equal('test_dashboard');

const resVis = await kibanaServer.savedObjects.get({
type: 'visualization',
id: 'test_visualization',
space: testSpaceId,
space,
});
expect(resVis.id).equal('test_visualization');
const resSearch = await kibanaServer.savedObjects.get({
type: 'search',
id: 'test_search',
space: testSpaceId,
space,
});
expect(resSearch.id).equal('test_search');
});
Expand Down