Skip to content

Commit

Permalink
Fix Conda Environment on Hosted Linux Preview (#8427) (#8447)
Browse files Browse the repository at this point in the history
* Make sure `conda` is in PATH before calling `sudo`

* bump patch version

* only pass full path as the arg to sudo

* update tests

* don't need to "mock" temp directory (which breaks mock-task)
  • Loading branch information
brcrista authored Sep 28, 2018
1 parent 61c4345 commit f5b29e1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Tasks/CondaEnvironmentV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('CondaEnvironment L0 Suite', function () {
if (getPlatform() === Platform.Windows) {
assert(testRunner.ran('conda create --quiet --prefix \\miniconda\\envs\\test --mkdir --yes'));
} else {
assert(testRunner.ran('sudo conda create --quiet --prefix /miniconda/envs/test --mkdir --yes'));
assert(testRunner.ran('sudo /miniconda/bin/conda create --quiet --prefix /miniconda/envs/test --mkdir --yes'));
}

assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
Expand All @@ -40,7 +40,7 @@ describe('CondaEnvironment L0 Suite', function () {
if (getPlatform() === Platform.Windows) {
assert(testRunner.ran('conda install python=3 --quiet --yes --json'));
} else {
assert(testRunner.ran('sudo conda install python=3 --quiet --yes --json'));
assert(testRunner.ran('sudo /miniconda/bin/conda install python=3 --quiet --yes --json'));
}

assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
Expand Down
2 changes: 1 addition & 1 deletion Tasks/CondaEnvironmentV1/Tests/L0BaseEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ taskRunner.setAnswers({
'conda': '/miniconda/bin/conda'
},
exec: {
'sudo conda install python=3 --quiet --yes --json': {
'sudo /miniconda/bin/conda install python=3 --quiet --yes --json': {
code: 0
},
'conda install python=3 --quiet --yes --json': {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/CondaEnvironmentV1/Tests/L0CreateEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ taskRunner.setAnswers({
'conda': '/miniconda/bin/conda'
},
exec: {
'sudo conda create --quiet --prefix /miniconda/envs/test --mkdir --yes': {
'sudo /miniconda/bin/conda create --quiet --prefix /miniconda/envs/test --mkdir --yes': {
code: 0
},
'conda create --quiet --prefix \\miniconda\\envs\\test --mkdir --yes': {
Expand Down
10 changes: 8 additions & 2 deletions Tasks/CondaEnvironmentV1/Tests/L0_conda_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ it('finds the Conda installation with PATH', async function () {
});

it('creates Conda environment', async function () {
mockTask.setAnswers({
which: {
'conda': '/miniconda/bin/conda'
}
});

mockery.registerMock('vsts-task-lib/task', mockTask);
mockery.registerMock('vsts-task-lib/toolrunner', mockToolRunner);
const uut = reload('../conda_internal');
Expand All @@ -138,7 +144,7 @@ it('creates Conda environment', async function () {
} else {
mockToolRunner.setAnswers({
exec: {
[`sudo conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
[`sudo /miniconda/bin/conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
code: 0
}
}
Expand All @@ -159,7 +165,7 @@ it('creates Conda environment', async function () {
} else {
mockToolRunner.setAnswers({
exec: {
[`sudo conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
[`sudo /miniconda/bin/conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
code: 1
}
}
Expand Down
11 changes: 8 additions & 3 deletions Tasks/CondaEnvironmentV1/conda_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ function binaryDir(environmentRoot: string, platform: Platform): string {
}
}

function sudo(toolPath: string, platform: Platform): ToolRunner {
/**
* Run a tool with `sudo` on Linux and macOS
* Precondition: `toolName` executable is in PATH
*/
function sudo(toolName: string, platform: Platform): ToolRunner {
if (platform === Platform.Windows) {
return task.tool('conda');
return task.tool(toolName);
} else {
return task.tool('sudo').line('conda');
const toolPath = task.which(toolName);
return task.tool('sudo').line(toolPath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tasks/CondaEnvironmentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 140,
"Patch": 1
"Patch": 2
},
"demands": [],
"instanceNameFormat": "Conda environment $(environmentName)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/CondaEnvironmentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 140,
"Patch": 1
"Patch": 2
},
"demands": [],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down

0 comments on commit f5b29e1

Please sign in to comment.