Skip to content

Commit

Permalink
fun nas init with auto nas config (alibaba#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
SquatsTonight authored Aug 5, 2019
1 parent bb07095 commit 593ea03
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/nas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { sleep } = require('./time');
const fs = require('fs-extra');
const definition = require('./definition');
const path = require('path');

const constants = require('./nas/constants');
const requestOption = {
method: 'POST'
};
Expand Down Expand Up @@ -189,6 +189,11 @@ async function createNasFileSystem(nasClient, region) {
async function generateAutoNasConfig(serviceName, vpcId, vswitchId) {
const mountPointDomain = await createDefaultNasIfNotExist(vpcId, vswitchId);

//fun nas 创建的服务名比其对应的服务多了 '_FUN_NAS_' 前缀
//对于 nas 的挂载目录,要去掉这个前缀,保证 fun nas 的服务与对应的服务使用的是同样的挂载目录
if (serviceName.startsWith(constants.FUN_NAS_SERVICE_PREFIX)) {
serviceName = serviceName.substring(constants.FUN_NAS_SERVICE_PREFIX.length);
}
return {
UserId: 10003,
GroupId: 10003,
Expand Down
2 changes: 1 addition & 1 deletion lib/nas/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = {
FUN_NAS_SERVICE_PREFIX: 'fun-nas-',
FUN_NAS_SERVICE_PREFIX: '_FUN_NAS_',
FUN_NAS_FUNCTION: 'fun-nas-function',
FUN_NAS_TIMEOUT: 600 * 1000,
FUN_NAS_UPLOAD_POOL_SIZE: 1
Expand Down
5 changes: 3 additions & 2 deletions test/nas/cp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire');
const path = require('path');
const constants = require('../../lib/nas/constants');
const sandbox = sinon.createSandbox();
const assert = sinon.assert;

Expand Down Expand Up @@ -31,8 +32,8 @@ describe('nas cp test', () => {

await cpStub(srcPath, dstPath, false);
const mntDir = path.join('/', 'mnt', 'nas');

assert.calledWith(upload, srcPath, mntDir, '/proxy/fun-nas-fun-nas-test/fun-nas-function/', false);
const nasHttpTriggerPath = `/proxy/${constants.FUN_NAS_SERVICE_PREFIX}fun-nas-test/fun-nas-function/`;
assert.calledWith(upload, srcPath, mntDir, nasHttpTriggerPath, false);
});

it('src path undefined test', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/nas/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs-extra');
const path = require('path');
const sinon = require('sinon');
const proxyquire = require('proxyquire');
const constants = require('../../lib/nas/constants');
const sandbox = sinon.createSandbox();
const assert = sinon.assert;

Expand Down Expand Up @@ -71,7 +72,7 @@ describe('test fun nas init', () => {
}
};
const serviceName = 'fun-nas-test';
const nasServiceName = 'fun-nas-' + serviceName;
const nasServiceName = constants.FUN_NAS_SERVICE_PREFIX + serviceName;
const nasFunctionName = 'fun-nas-function';

const zipCodePath = path.resolve(__dirname, '../../lib/fc-utils/fc-fun-nas-server/dist/fun-nas-server.zip');
Expand Down

0 comments on commit 593ea03

Please sign in to comment.