Skip to content

Commit

Permalink
NC | Online Upgrade | Add config_dir_upgrade unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <[email protected]>
  • Loading branch information
romayalon committed Jan 5, 2025
1 parent 5c4b49b commit a20a9a9
Showing 1 changed file with 154 additions and 6 deletions.
160 changes: 154 additions & 6 deletions src/test/unit_tests/jest_tests/test_nc_upgrade_manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
description: 'dummy upgrade script file 1'
};
`;

const old_expected_system_json = {
[hostname]: {
current_version: '5.17.0',
Expand All @@ -72,25 +73,77 @@ const old_expected_system_json = {

const old_expected_system_json_has_config_directory = {
[hostname]: {
current_version: '5.18.1',
current_version: pkg.version + '.1',
upgrade_history: {
successful_upgrades: [{
timestamp: 1724687496424,
from_version: '5.18.0',
to_version: '5.18.1'
from_version: pkg.version,
to_version: pkg.version + '.1'
}]
},
},
config_directory: {
config_dir_version: '1.0.0',
upgrade_package_version: '5.18.0',
config_dir_version: config_fs.config_dir_version,
upgrade_package_version: pkg.version,
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
upgrade_history: {
successful_upgrades: [{
timestamp: 1724687496424,
completed_scripts: [],
package_from_version: '5.17.0',
package_to_version: '5.18.0'
package_to_version: pkg.version
}]
}
}
};

const failed_expected_system_json_has_config_directory = {
[hostname]: {
current_version: pkg.version,
upgrade_history: {
successful_upgrades: [{
timestamp: 1724687496424,
from_version: pkg.version,
to_version: pkg.version
}]
},
},
config_directory: {
config_dir_version: '0.0.0',
upgrade_package_version: '5.17.0',
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
upgrade_history: {
successful_upgrades: [{ // mock successful upgrade
timestamp: 1724687496424,
completed_scripts: [],
package_from_version: '5.16.0',
package_to_version: '5.17.0'
}]
}
}
};

const newer_expected_system_json_has_config_directory = {
[hostname]: {
current_version: pkg.version + '.1',
upgrade_history: {
successful_upgrades: [{
timestamp: 1724687496424,
from_version: pkg.version,
to_version: pkg.version + '.1'
}]
},
},
config_directory: {
config_dir_version: config_fs.config_dir_version + '.1',
upgrade_package_version: pkg.version + '.1',
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
upgrade_history: {
successful_upgrades: [{
timestamp: 1724687496424,
completed_scripts: [],
package_from_version: '5.17.0',
package_to_version: pkg.version + '.1'
}]
}
}
Expand Down Expand Up @@ -673,6 +726,101 @@ describe('nc upgrade manager - upgrade config directory', () => {
assert_upgrade_finish_or_fail_data(system_json_data, expected_data);
});
});

describe('nc upgrade manager - upgrade_config_dir', () => {
beforeEach(async () => {
await create_config_dir(config.NSFS_NC_DEFAULT_CONF_DIR);
await create_config_dir(config_root);
await create_redirect_file(config_fs, config_root);
});

afterEach(async () => {
await clean_config_dir(config_fs, config_root);
}, TEST_TIMEOUT);

it('upgrade_config_dir - empty system_data', async () => {
const expected_version = pkg.version;
const hosts_list = [hostname];
const expected_err_msg = 'system does not exist';
await expect(nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list))
.rejects.toThrow(expected_err_msg);
});

it('upgrade_config_dir - config_directory property is missing in system.json', async () => {
const system_data = _.cloneDeep(current_expected_system_json);
const expected_version = pkg.version;
const hosts_list = [hostname];
await config_fs.create_system_config_file(JSON.stringify(system_data));
const res = await nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list);
const system_json_data = await config_fs.get_system_config_file();
const expected_data = {
...system_data,
config_directory: {
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
config_dir_version: config_fs.config_dir_version,
upgrade_package_version: expected_version,
upgrade_history: {
successful_upgrades: [res]
}
}
};
assert_upgrade_finish_or_fail_data(system_json_data, expected_data);
});

it('upgrade_config_dir - system.json and package.json have the same version', async () => {
const system_data = _.cloneDeep(old_expected_system_json_has_config_directory);
const expected_version = pkg.version;
const hosts_list = [hostname];
await config_fs.create_system_config_file(JSON.stringify(system_data));
const expected_msg = { "message": "config_dir_version on system.json and config_fs.config_dir_version match, nothing to upgrade" };
const res = await nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list);
expect(res).toStrictEqual(expected_msg);
});

it('upgrade_config_dir - config_dir_version in system.json is newer than the hosts current config_dir_version', async () => {
const system_data = _.cloneDeep(newer_expected_system_json_has_config_directory);
const expected_version = pkg.version;
const hosts_list = [hostname];
await config_fs.create_system_config_file(JSON.stringify(system_data));
const expected_err_msg = 'attempt to run old container version with newer server version';
await expect(nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list))
.rejects.toThrow(expected_err_msg);
});

it('upgrade_config_dir - host RPM is not upgraded to the expectced version', async () => {
const system_data = _.cloneDeep(old_expected_system_json);
const expected_version = pkg.version;
const hosts_list = [hostname];
await config_fs.create_system_config_file(JSON.stringify(system_data));
const expected_err_msg = `config dir upgrade can not be started until all expected hosts have the expected version=${pkg.version}, host=${hostname} host's current_version=${system_data[hostname].current_version}`;
await expect(nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list))
.rejects.toThrow(expected_err_msg);
});

it('upgrade_config_dir - old successful upgrades is not empty', async () => {
const system_data = _.cloneDeep(failed_expected_system_json_has_config_directory);
const expected_version = pkg.version;
const hosts_list = [hostname];
await config_fs.create_system_config_file(JSON.stringify(system_data));
const res = await nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list);
const system_json_data = await config_fs.get_system_config_file();
const expected_data = {
...system_data,
config_directory: {
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
config_dir_version: config_fs.config_dir_version,
upgrade_package_version: expected_version,
upgrade_history: {
successful_upgrades: [
res,
...failed_expected_system_json_has_config_directory.config_directory.upgrade_history.successful_upgrades,
]
}
}
};
assert_upgrade_finish_or_fail_data(system_json_data, expected_data);
});
});
});

/**
Expand Down

0 comments on commit a20a9a9

Please sign in to comment.