Skip to content

Commit

Permalink
pass containerName
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl committed Oct 31, 2023
1 parent 9105d07 commit e188c9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions x-pack/test/osquery_cypress/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import execa from 'execa';

import { getLatestVersion } from './artifact_manager';
import { Manager } from './resource_manager';
import { generateRandomString } from './utils';

export class AgentManager extends Manager {
private log: ToolingLog;
private policyEnrollmentKey: string;
private fleetServerPort: string;
private agentContainerId?: string;

constructor(policyEnrollmentKey: string, fleetServerPort: string, log: ToolingLog) {
super();
Expand All @@ -29,6 +29,7 @@ export class AgentManager extends Manager {

const artifact = `docker.elastic.co/beats/elastic-agent:${await getLatestVersion()}`;
this.log.info(artifact);
const containerName = generateRandomString(12);

const dockerArgs = [
'run',
Expand All @@ -37,6 +38,10 @@ export class AgentManager extends Manager {
'--detach',
'--add-host',
'host.docker.internal:host-gateway',
'--name',
containerName,
'--hostname',
containerName,
'--env',
'FLEET_ENROLL=1',
'--env',
Expand All @@ -50,7 +55,8 @@ export class AgentManager extends Manager {
];

this.agentContainerId = (await execa('docker', dockerArgs)).stdout;
return this.agentContainerId;

return containerName;
}

public cleanup() {
Expand Down
7 changes: 3 additions & 4 deletions x-pack/test/osquery_cypress/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ async function setupFleetAgent({ getService }: FtrProviderContext) {
const policyEnrollmentKeyTwo = await createAgentPolicy(kbnClient, log, 'Osquery policy');

const port = config.get('servers.fleetserver.port');

const agent = await new AgentManager(policyEnrollmentKey, port, log).setup();
const hostname = agent.substring(0, 12);
await waitForHostToEnroll(kbnClient, hostname);
await waitForHostToEnroll(kbnClient, agent);
const agentTwo = await new AgentManager(policyEnrollmentKeyTwo, port, log).setup();
const hostnameTwo = agentTwo.substring(0, 12);
await waitForHostToEnroll(kbnClient, hostnameTwo);
await waitForHostToEnroll(kbnClient, agentTwo);
}

export async function startOsqueryCypress(context: FtrProviderContext) {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/osquery_cypress/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ export const getLatestAvailableAgentVersion = async (kbnClient: KbnClient): Prom

return version;
};

export const generateRandomString = (length) => {
return [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
};

0 comments on commit e188c9c

Please sign in to comment.