* generate new ssh key in the container

* remove useless code
This commit is contained in:
Sheng Chen 2018-02-09 16:04:07 +08:00 коммит произвёл GitHub
Родитель 09fae2bd9e
Коммит ef0bce2fce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 19 добавлений и 62 удалений

Просмотреть файл

@ -167,9 +167,8 @@ export class CloudShell extends BaseShell {
switch (TestType) {
case TestOption.lint:
return "rake -f ../Rakefile build";
case TestOption.e2enossh:
case TestOption.e2ewithssh:
return "rake -f ../Rakefile e2e";
case TestOption.e2e:
return "ssh-keygen -t rsa -b 2048 -C terraformTest -f /root/.ssh/id_rsa -N ''; rake -f ../Rakefile e2e";
case TestOption.custom:
const cmd: string = await vscode.window.showInputBox({
prompt: "Type your custom test command",

Просмотреть файл

@ -63,29 +63,15 @@ resource "azurerm_container_group" "TFTest" {
export function exportTestScript(testType: string, TFConfiguration: string, resoureGroupName: string, storageAccountName: string, fileShareName: string, testDirectory: string): string {
const testScript = `
#!/bin/bash
if [ ! -d "$HOME/clouddrive/${testDirectory}" ]; then
mkdir -p $HOME/clouddrive/${testDirectory}
fi
if [ ! -d "$HOME/clouddrive/${testDirectory}/.ssh" ]; then
mkdir -p $HOME/clouddrive/${testDirectory}/.ssh
fi
mkdir -p $HOME/clouddrive/${testDirectory}
echo -e "${TFConfiguration}" > $HOME/clouddrive/${testDirectory}/testfile.tf
export TF_VAR_storage_account_key=$(az storage account keys list -g ${resoureGroupName} -n ${storageAccountName} | jq '.[0].value')
if [ -f "$HOME/clouddrive/${testDirectory}/.ssh/id_rsa" ]; then
mv $HOME/clouddrive/${testDirectory}/.ssh/id_rsa $HOME/clouddrive/${testDirectory}/.ssh/id_rsa.old
fi
mkdir -p $HOME/clouddrive/${testDirectory}/.azure
if [ -f "$HOME/clouddrive/${testDirectory}/.ssh/id_rsa.pub" ]; then
mv $HOME/clouddrive/${testDirectory}/.ssh/id_rsa.pub $HOME/clouddrive/${testDirectory}/.ssh/id_rsa.pub.old
fi
ssh-keygen -t rsa -b 2048 -C "vscode-testing" -f $HOME/clouddrive/${testDirectory}/.ssh/id_rsa -N ""
cp -r $HOME/.azure/ $HOME/clouddrive/${testDirectory}/
cp $HOME/.azure/*.json $HOME/clouddrive/${testDirectory}/.azure
`;
@ -102,8 +88,6 @@ cp -a /module/${moduleDir}/. /tf-test/module/
echo "Initializing environment..."
mkdir /root/.azure
cp /module/${moduleDir}/.TFTesting/.azure/*.json /root/.azure
mkdir /root/.ssh
cp /module/${moduleDir}/.TFTesting/.ssh/* /root/.ssh/
echo "Starting to Run test task..."
${containerCommand}

Просмотреть файл

@ -68,7 +68,7 @@ export function activate(ctx: vscode.ExtensionContext) {
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.exectest", async () => {
console.log("Testing current module");
const pick: string = await vscode.window.showQuickPick(
[TestOption.lint, TestOption.e2enossh, TestOption.e2ewithssh, TestOption.custom],
[TestOption.lint, TestOption.e2e, TestOption.custom],
{ placeHolder: "Select the type of test that you want to run" },
);
if (!pick) {

Просмотреть файл

@ -68,38 +68,20 @@ export class IntegratedShell extends BaseShell {
}
switch (TestType) {
case TestOption.lint: {
case TestOption.lint:
await runLintInDocker(
workingDirectory + ":/tf-test/module",
containerName,
);
break;
}
case TestOption.e2enossh: {
console.log("Running e2e test in " + process.env["ARM_TEST_LOCATION"]);
case TestOption.e2e:
await runE2EInDocker(
[
workingDirectory + "/logs:/tf-test/module/.kitchen",
workingDirectory + ":/tf-test/module",
],
workingDirectory + ":/tf-test/module",
containerName,
);
break;
}
case TestOption.e2ewithssh: {
console.log("Running e2e test in " + process.env["ARM_TEST_LOCATION"]);
await runE2EInDocker(
[
`${path.join(os.homedir(), ".ssh")}:/root/.ssh/`,
workingDirectory + "/logs:/tf-test/module/.kitchen",
workingDirectory + ":/tf-test/module",
],
containerName,
);
break;
}
case TestOption.custom: {
console.log("Running custom test in " + process.env["ARM_TEST_LOCATION"]);
case TestOption.custom:
const cmd: string = await vscode.window.showInputBox({
prompt: "Type your custom test command",
value: `run -v ${workingDirectory}:/tf-test/module --rm ${containerName} rake -f ../Rakefile build`,
@ -112,11 +94,9 @@ export class IntegratedShell extends BaseShell {
);
}
break;
}
default: {
default:
console.log("Default step in test for Integrated Terminal");
break;
}
}
}

Просмотреть файл

@ -41,8 +41,7 @@ export enum FileSystem {
export enum TestOption {
lint = "lint",
e2enossh = "e2e - no ssh",
e2ewithssh = "e2e - with ssh",
e2e = "end to end",
custom = "custom",
}

Просмотреть файл

@ -45,13 +45,14 @@ export async function runLintInDocker(volumn: string, containerName: string): Pr
}
}
export async function runE2EInDocker(volumn: string[], containerName: string): Promise<void> {
export async function runE2EInDocker(volumn: string, containerName: string): Promise<void> {
try {
await executeCommand(
"docker",
[
"run",
...insertElementIntoArray(volumn, "-v"),
"-v",
volumn,
"-e",
"ARM_CLIENT_ID",
"-e",
@ -66,10 +67,9 @@ export async function runE2EInDocker(volumn: string[], containerName: string): P
"ARM_TEST_LOCATION_ALT",
"--rm",
containerName,
"rake",
"-f",
"../Rakefile",
"e2e",
"/bin/bash",
"-c",
`"ssh-keygen -t rsa -b 2048 -C terraformTest -f /root/.ssh/id_rsa -N ''; rake -f ../Rakefile e2e"`,
],
{ shell: true },
);
@ -77,8 +77,3 @@ export async function runE2EInDocker(volumn: string[], containerName: string): P
promptForOpenOutputChannel("Failed to run end to end tests in Docker. Please open the output channel for more details.", DialogType.error);
}
}
// usage: insertElementIntoArray([1, 2], 0) => [0, 1, 0, 2]
function insertElementIntoArray(array: any[], element: any): any[] {
return array.reduce((pre, cur) => pre.concat(element, cur), []);
}