test cloudron migration

This commit is contained in:
Girish Ramakrishnan 2016-07-08 15:22:30 -07:00
parent 40d044c8fd
commit 9288937af3
2 changed files with 45 additions and 37 deletions

View File

@ -23,9 +23,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
function Cloudron(box) {
this._box = box;
this._isCustomDomain = box.domain === process.env.CUSTOM_DOMAIN || box.domain === process.env.SELFHOST_DOMAIN;
this._adminFqdn = this._isCustomDomain ? 'my.' + box.domain : 'my-' + box.domain;
this._origin = this._isCustomDomain ? 'https://my.' + box.domain : 'https://my-' + box.domain;
this.setDomain(box.domain);
this._credentials = {
password: null,
@ -33,6 +31,12 @@ function Cloudron(box) {
};
}
Cloudron.prototype._setDomain = function (domain) {
this._isCustomDomain = domain === process.env.CUSTOM_DOMAIN || domain === process.env.SELFHOST_DOMAIN;
this._adminFqdn = this._isCustomDomain ? 'my.' + domain : 'my-' + domain;
this._origin = this._isCustomDomain ? 'https://my.' + domain : 'https://my-' + domain;
};
Cloudron.prototype.fqdn = function () {
return this._box.domain;
};
@ -405,6 +409,15 @@ Cloudron.prototype.reboot = function () {
this.waitForBox();
};
Cloudron.prototype.migrate = function (options) {
var res = request.post(this._origin + '/api/v1/cloudron/migrate')
.query({ access_token: this._credentials.accessToken })
.send(options)
.end();
common.verifyResponse2xx(res, 'Box could not be migrated');
if (options.domain) this._setDomain(options.domain);
};
Cloudron.prototype.checkTimeZone = function (tz) {
var res = request.get(this._origin + '/api/v1/settings/time_zone').query({ access_token: this._credentials.accessToken }).end();
common.verifyResponse2xx(res, 'Could not query timezone');

View File

@ -10,7 +10,6 @@
var AppStore = require('../appstore.js'),
assert = require('assert'),
async = require('async'),
AWS = require('aws-sdk'),
Cloudron = require('../cloudron.js'),
common = require('../common.js'),
mailer = require('../mailer.js');
@ -25,7 +24,6 @@ describe('Custom domain test', function () {
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
var route53 = new AWS.Route53({ accessKeyId: process.env.AWS_STAGING_ACCESS_KEY, secretAccessKey: process.env.AWS_STAGING_SECRET_KEY });
var owner = common.getOwner();
var admin = common.getAdmin();
@ -50,43 +48,13 @@ describe('Custom domain test', function () {
it('can create a cloudron', function () {
box = appStore.createCloudron({
domain: CUSTOM_DOMAIN,
domain: common.cloudronDomain(__filename),
region: 'ams2',
size: '1gb',
version: BOX_VERSION
});
});
it('can setup my. domain after it got IP', function (done) {
var ip = appStore.waitForIP(box.id);
// update the route53 record for my subdomain
route53.listHostedZonesByName({ DNSName: CUSTOM_DOMAIN, MaxItems: '1'}, function (error, result) {
if (error) return done(error);
var params = {
ChangeBatch: {
Changes: [{
Action: 'UPSERT',
ResourceRecordSet: {
Type: 'A',
Name: 'my.' + CUSTOM_DOMAIN + '.',
ResourceRecords: [ { Value: ip } ],
TTL: 1
}
}]
},
HostedZoneId: result.HostedZones[0].Id
};
route53.changeResourceRecordSets(params, function(error) {
if (error) return done(error);
done();
});
});
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
@ -101,11 +69,25 @@ describe('Custom domain test', function () {
cloudron.setCredentials(owner.password, token);
});
it('can migrate cloudron to custom domain', function () {
cloudron.migrate({
domain: CUSTOM_DOMAIN,
provider: 'route53',
accessKeyId: process.env.AWS_STAGING_ACCESS_KEY,
secretAccessKey: process.env.AWS_STAGING_SECRET_KEY
});
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
});
it('send mail to cloudron user', function (done) {
mailer.sendMailToCloudronUser(owner.username + '@' + CUSTOM_DOMAIN, done);
});
it('can set dns credentials', function () {
it('can set dns credentials again', function () {
cloudron.setDnsConfig({ provider: 'route53', accessKeyId: process.env.AWS_STAGING_ACCESS_KEY, secretAccessKey: process.env.AWS_STAGING_SECRET_KEY });
});
var location = 'test' + (Math.random() * 10000).toFixed();
@ -153,6 +135,19 @@ describe('Custom domain test', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can migrate to bigger size', function () {
cloudron.migrate({ size: '2gb' });
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});