[8.8] [Fleet] Add integration test for epm install on multiple spaces (#156864) (#157005)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Fleet] Add integration test for epm install on multiple spaces
(#156864)](https://github.com/elastic/kibana/pull/156864)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-05-08T14:39:24Z","message":"[Fleet]
Add integration test for epm install on multiple spaces
(#156864)\n\nCloses
https://github.com/elastic/kibana/issues/150686\r\n\r\n##
Summary\r\n\r\nAdd integration test to cover integration installation in
multiple\r\nspaces\r\n\r\nSteps followed:\r\n- Install System
integration\r\n- Create new space\r\n- Uninstall System integration\r\n-
Install again in the new space\r\n- Verify that integration is added
successfully, assets are created and\r\ntagged with Managed and System
tags\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"de48b5d9aca1e41bcd33534844a49bb4efb7754d","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.8.0","v8.9.0"],"number":156864,"url":"https://github.com/elastic/kibana/pull/156864","mergeCommit":{"message":"[Fleet]
Add integration test for epm install on multiple spaces
(#156864)\n\nCloses
https://github.com/elastic/kibana/issues/150686\r\n\r\n##
Summary\r\n\r\nAdd integration test to cover integration installation in
multiple\r\nspaces\r\n\r\nSteps followed:\r\n- Install System
integration\r\n- Create new space\r\n- Uninstall System integration\r\n-
Install again in the new space\r\n- Verify that integration is added
successfully, assets are created and\r\ntagged with Managed and System
tags\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"de48b5d9aca1e41bcd33534844a49bb4efb7754d"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156864","number":156864,"mergeCommit":{"message":"[Fleet]
Add integration test for epm install on multiple spaces
(#156864)\n\nCloses
https://github.com/elastic/kibana/issues/150686\r\n\r\n##
Summary\r\n\r\nAdd integration test to cover integration installation in
multiple\r\nspaces\r\n\r\nSteps followed:\r\n- Install System
integration\r\n- Create new space\r\n- Uninstall System integration\r\n-
Install again in the new space\r\n- Verify that integration is added
successfully, assets are created and\r\ntagged with Managed and System
tags\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"de48b5d9aca1e41bcd33534844a49bb4efb7754d"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-05-08 12:17:28 -04:00 committed by GitHub
parent d07529fc5b
commit 075a1e380f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 20 deletions

View file

@ -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(

View file

@ -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'));
});
}

View file

@ -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-*');
});
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);
});
});
}

View file

@ -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';
@ -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';
@ -69,10 +67,8 @@ export default function (providerContext: FtrProviderContext) {
});
expectAssetsInstalled({
pkgVersion,
pkgName,
es,
kibanaServer,
space: testSpaceId,
});
});
@ -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({
@ -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');
});