|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import expect from '@kbn/expect'; |
| 8 | +import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; |
| 9 | +import { skipIfNoDockerRegistry } from '../../helpers'; |
| 10 | + |
| 11 | +export default function (providerContext: FtrProviderContext) { |
| 12 | + const { getService } = providerContext; |
| 13 | + const kibanaServer = getService('kibanaServer'); |
| 14 | + const supertest = getService('supertest'); |
| 15 | + const es = getService('es'); |
| 16 | + const pkgName = 'all_assets'; |
| 17 | + const pkgVersion = '0.1.0'; |
| 18 | + const pkgKey = `${pkgName}-${pkgVersion}`; |
| 19 | + const logsTemplateName = `logs-${pkgName}.test_logs`; |
| 20 | + const metricsTemplateName = `metrics-${pkgName}.test_metrics`; |
| 21 | + |
| 22 | + const uninstallPackage = async (pkg: string) => { |
| 23 | + await supertest.delete(`/api/ingest_manager/epm/packages/${pkg}`).set('kbn-xsrf', 'xxxx'); |
| 24 | + }; |
| 25 | + const installPackage = async (pkg: string) => { |
| 26 | + await supertest |
| 27 | + .post(`/api/ingest_manager/epm/packages/${pkg}`) |
| 28 | + .set('kbn-xsrf', 'xxxx') |
| 29 | + .send({ force: true }); |
| 30 | + }; |
| 31 | + |
| 32 | + describe('installs and uninstalls all assets', async () => { |
| 33 | + describe('installs all assets when installing a package for the first time', async () => { |
| 34 | + skipIfNoDockerRegistry(providerContext); |
| 35 | + before(async () => { |
| 36 | + await installPackage(pkgKey); |
| 37 | + }); |
| 38 | + it('should have installed the ILM policy', async function () { |
| 39 | + const resPolicy = await es.transport.request({ |
| 40 | + method: 'GET', |
| 41 | + path: `/_ilm/policy/all_assets`, |
| 42 | + }); |
| 43 | + expect(resPolicy.statusCode).equal(200); |
| 44 | + }); |
| 45 | + it('should have installed the index templates', async function () { |
| 46 | + const resLogsTemplate = await es.transport.request({ |
| 47 | + method: 'GET', |
| 48 | + path: `/_index_template/${logsTemplateName}`, |
| 49 | + }); |
| 50 | + expect(resLogsTemplate.statusCode).equal(200); |
| 51 | + |
| 52 | + const resMetricsTemplate = await es.transport.request({ |
| 53 | + method: 'GET', |
| 54 | + path: `/_index_template/${metricsTemplateName}`, |
| 55 | + }); |
| 56 | + expect(resMetricsTemplate.statusCode).equal(200); |
| 57 | + }); |
| 58 | + it('should have installed the pipelines', async function () { |
| 59 | + const res = await es.transport.request({ |
| 60 | + method: 'GET', |
| 61 | + path: `/_ingest/pipeline/${logsTemplateName}-${pkgVersion}`, |
| 62 | + }); |
| 63 | + expect(res.statusCode).equal(200); |
| 64 | + }); |
| 65 | + it('should have installed the template components', async function () { |
| 66 | + const res = await es.transport.request({ |
| 67 | + method: 'GET', |
| 68 | + path: `/_component_template/${logsTemplateName}-mappings`, |
| 69 | + }); |
| 70 | + expect(res.statusCode).equal(200); |
| 71 | + const resSettings = await es.transport.request({ |
| 72 | + method: 'GET', |
| 73 | + path: `/_component_template/${logsTemplateName}-settings`, |
| 74 | + }); |
| 75 | + expect(resSettings.statusCode).equal(200); |
| 76 | + }); |
| 77 | + it('should have installed the kibana assets', async function () { |
| 78 | + const resIndexPatternLogs = await kibanaServer.savedObjects.get({ |
| 79 | + type: 'index-pattern', |
| 80 | + id: 'logs-*', |
| 81 | + }); |
| 82 | + expect(resIndexPatternLogs.id).equal('logs-*'); |
| 83 | + const resIndexPatternMetrics = await kibanaServer.savedObjects.get({ |
| 84 | + type: 'index-pattern', |
| 85 | + id: 'metrics-*', |
| 86 | + }); |
| 87 | + expect(resIndexPatternMetrics.id).equal('metrics-*'); |
| 88 | + const resDashboard = await kibanaServer.savedObjects.get({ |
| 89 | + type: 'dashboard', |
| 90 | + id: 'sample_dashboard', |
| 91 | + }); |
| 92 | + expect(resDashboard.id).equal('sample_dashboard'); |
| 93 | + const resDashboard2 = await kibanaServer.savedObjects.get({ |
| 94 | + type: 'dashboard', |
| 95 | + id: 'sample_dashboard2', |
| 96 | + }); |
| 97 | + expect(resDashboard2.id).equal('sample_dashboard2'); |
| 98 | + const resVis = await kibanaServer.savedObjects.get({ |
| 99 | + type: 'visualization', |
| 100 | + id: 'sample_visualization', |
| 101 | + }); |
| 102 | + expect(resVis.id).equal('sample_visualization'); |
| 103 | + const resSearch = await kibanaServer.savedObjects.get({ |
| 104 | + type: 'search', |
| 105 | + id: 'sample_search', |
| 106 | + }); |
| 107 | + expect(resSearch.id).equal('sample_search'); |
| 108 | + }); |
| 109 | + it('should have installed placeholder indices', async function () { |
| 110 | + const resLogsIndexPatternPlaceholder = await es.transport.request({ |
| 111 | + method: 'GET', |
| 112 | + path: `/logs-index_pattern_placeholder`, |
| 113 | + }); |
| 114 | + expect(resLogsIndexPatternPlaceholder.statusCode).equal(200); |
| 115 | + const resMetricsIndexPatternPlaceholder = await es.transport.request({ |
| 116 | + method: 'GET', |
| 117 | + path: `/metrics-index_pattern_placeholder`, |
| 118 | + }); |
| 119 | + expect(resMetricsIndexPatternPlaceholder.statusCode).equal(200); |
| 120 | + }); |
| 121 | + it('should have created the correct saved object', async function () { |
| 122 | + const res = await kibanaServer.savedObjects.get({ |
| 123 | + type: 'epm-packages', |
| 124 | + id: 'all_assets', |
| 125 | + }); |
| 126 | + expect(res.attributes).eql({ |
| 127 | + installed_kibana: [ |
| 128 | + { |
| 129 | + id: 'sample_dashboard', |
| 130 | + type: 'dashboard', |
| 131 | + }, |
| 132 | + { |
| 133 | + id: 'sample_dashboard2', |
| 134 | + type: 'dashboard', |
| 135 | + }, |
| 136 | + { |
| 137 | + id: 'sample_search', |
| 138 | + type: 'search', |
| 139 | + }, |
| 140 | + { |
| 141 | + id: 'sample_visualization', |
| 142 | + type: 'visualization', |
| 143 | + }, |
| 144 | + ], |
| 145 | + installed_es: [ |
| 146 | + { |
| 147 | + id: 'logs-all_assets.test_logs-0.1.0', |
| 148 | + type: 'ingest_pipeline', |
| 149 | + }, |
| 150 | + { |
| 151 | + id: 'logs-all_assets.test_logs', |
| 152 | + type: 'index_template', |
| 153 | + }, |
| 154 | + { |
| 155 | + id: 'metrics-all_assets.test_metrics', |
| 156 | + type: 'index_template', |
| 157 | + }, |
| 158 | + ], |
| 159 | + es_index_patterns: { |
| 160 | + test_logs: 'logs-all_assets.test_logs-*', |
| 161 | + test_metrics: 'metrics-all_assets.test_metrics-*', |
| 162 | + }, |
| 163 | + name: 'all_assets', |
| 164 | + version: '0.1.0', |
| 165 | + internal: false, |
| 166 | + removable: true, |
| 167 | + }); |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + describe('uninstalls all assets when uninstalling a package', async () => { |
| 172 | + skipIfNoDockerRegistry(providerContext); |
| 173 | + before(async () => { |
| 174 | + await uninstallPackage(pkgKey); |
| 175 | + }); |
| 176 | + it('should have uninstalled the index templates', async function () { |
| 177 | + const resLogsTemplate = await es.transport.request( |
| 178 | + { |
| 179 | + method: 'GET', |
| 180 | + path: `/_index_template/${logsTemplateName}`, |
| 181 | + }, |
| 182 | + { |
| 183 | + ignore: [404], |
| 184 | + } |
| 185 | + ); |
| 186 | + expect(resLogsTemplate.statusCode).equal(404); |
| 187 | + |
| 188 | + const resMetricsTemplate = await es.transport.request( |
| 189 | + { |
| 190 | + method: 'GET', |
| 191 | + path: `/_index_template/${metricsTemplateName}`, |
| 192 | + }, |
| 193 | + { |
| 194 | + ignore: [404], |
| 195 | + } |
| 196 | + ); |
| 197 | + expect(resMetricsTemplate.statusCode).equal(404); |
| 198 | + }); |
| 199 | + it('should have uninstalled the pipelines', async function () { |
| 200 | + const res = await es.transport.request( |
| 201 | + { |
| 202 | + method: 'GET', |
| 203 | + path: `/_ingest/pipeline/${logsTemplateName}-${pkgVersion}`, |
| 204 | + }, |
| 205 | + { |
| 206 | + ignore: [404], |
| 207 | + } |
| 208 | + ); |
| 209 | + expect(res.statusCode).equal(404); |
| 210 | + }); |
| 211 | + it('should have uninstalled the kibana assets', async function () { |
| 212 | + let resDashboard; |
| 213 | + try { |
| 214 | + resDashboard = await kibanaServer.savedObjects.get({ |
| 215 | + type: 'dashboard', |
| 216 | + id: 'sample_dashboard', |
| 217 | + }); |
| 218 | + } catch (err) { |
| 219 | + resDashboard = err; |
| 220 | + } |
| 221 | + expect(resDashboard.response.data.statusCode).equal(404); |
| 222 | + let resDashboard2; |
| 223 | + try { |
| 224 | + resDashboard2 = await kibanaServer.savedObjects.get({ |
| 225 | + type: 'dashboard', |
| 226 | + id: 'sample_dashboard2', |
| 227 | + }); |
| 228 | + } catch (err) { |
| 229 | + resDashboard2 = err; |
| 230 | + } |
| 231 | + expect(resDashboard2.response.data.statusCode).equal(404); |
| 232 | + let resVis; |
| 233 | + try { |
| 234 | + resVis = await kibanaServer.savedObjects.get({ |
| 235 | + type: 'visualization', |
| 236 | + id: 'sample_visualization', |
| 237 | + }); |
| 238 | + } catch (err) { |
| 239 | + resVis = err; |
| 240 | + } |
| 241 | + expect(resVis.response.data.statusCode).equal(404); |
| 242 | + let resSearch; |
| 243 | + try { |
| 244 | + resVis = await kibanaServer.savedObjects.get({ |
| 245 | + type: 'search', |
| 246 | + id: 'sample_search', |
| 247 | + }); |
| 248 | + } catch (err) { |
| 249 | + resSearch = err; |
| 250 | + } |
| 251 | + expect(resSearch.response.data.statusCode).equal(404); |
| 252 | + }); |
| 253 | + it('should have removed the saved object', async function () { |
| 254 | + let res; |
| 255 | + try { |
| 256 | + res = await kibanaServer.savedObjects.get({ |
| 257 | + type: 'epm-packages', |
| 258 | + id: 'all_assets', |
| 259 | + }); |
| 260 | + } catch (err) { |
| 261 | + res = err; |
| 262 | + } |
| 263 | + expect(res.response.data.statusCode).equal(404); |
| 264 | + }); |
| 265 | + }); |
| 266 | + }); |
| 267 | +} |
0 commit comments