Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NC | Online Upgrade | Tests | Config directory restructure upgrade script unit tests #8654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romayalon
Copy link
Contributor

@romayalon romayalon commented Jan 6, 2025

Explain the changes

  1. Added unit tests for every function in noobaa-core/src/upgrade/nc_upgrade_scripts/1.0.0/config_dir_restructure.js.
  2. config dir restructure -
  • did some small refactoring
  • added handling in removing name symlink in case the new symlink /etc/noobaa.conf.d/accounts_by_name/account1.symlink points to a wrong/non existing location and then re-creating the link correctly, added also the matching tests for this case - notice this is an artificial test and is not suppose to happen in the usual flow.
    The relevant tests for this case -
  1. create_account_name_index_if_missing() - new name index already exists and points to wrong location
  2. create_account_access_keys_index_if_missing() - new access key index already exists and points to a wrong location
  3. create_account_name_index_if_missing() - new name index already exists and points to a non existing location
  4. create_account_access_keys_index_if_missing() - new access key index already exists and points to a non existing location

Issues: Fixed #xxx / Gap #xxx

Testing Instructions:

  1. sudo jest --testRegex=jest_tests/test_config_dir_restructure_upgrade_script.test.js
  • Doc added/updated
  • Tests added

@romayalon romayalon force-pushed the romy-config-dir-restructure-tests branch 3 times, most recently from 513d2bd to f321d16 Compare January 7, 2025 09:00
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
@romayalon romayalon force-pushed the romy-config-dir-restructure-tests branch from f321d16 to 2ea7b60 Compare January 7, 2025 09:19
@romayalon romayalon requested a review from shirady January 7, 2025 09:20
async function folder_delete_skip_enoent(dir) {
if (!dir) return;
try {
return rimraf(dir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier for readability to reuse the function in this file:

Suggested change
return rimraf(dir);
return folder_delete(dir);

@@ -191,6 +191,15 @@ function folder_delete(dir) {
return rimraf(dir);
}

async function folder_delete_skip_enoent(dir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can JSDoc '9I understand that most of this file don't have it...).

* @returns {Promise<Void>}
*/
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '') {
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '', { symlink_name, symlink_access_key} = {symlink_name: true, symlink_access_key: true}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, in this approach you used default values for the whole object, so only if someone doesn't pass the options argument would it get those defaults.
Otherwise, if one passes one of them, it would get only the one that he passed.
Is that what you meant?

* @param {Object} config_data
* @returns {Promise<Void>}
*/
async function create_identity_dir_if_missing(config_fs, config_data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass only the ID as an argument (instead of the config_data object).

Comment on lines +509 to +510
if (type === CONFIG_TYPES.ACCOUNT && symlink_access_key && config_data.access_keys) {
await symlink_account_access_key(config_fs, config_data.access_keys[0].access_key, id_relative_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'm not sure it is enough && config_data.access_keys - anonymous account would have access_key as [] (defined, but empty array).
  2. If you can change it from the first item (config_data.access_keys[0]) to iterate on the array of access_keys, as this is a helper function and we might have more than 1 access key.


it('create_identity_if_missing() - only dir exists but file doesn’t', async () => {
const new_account_data = { _id: String(1), name: 'old_account' + 1, user: 'root', access_keys: [{ access_key: mock_access_key }] };
await write_manual_old_account_config_file(default_config_fs, new_account_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment in the line where we used to create the config file in the past but didn't so it will clear?

Comment on lines +640 to +645
// Jest has builtin function fail that based on Jasmine
// in case Jasmine would get removed from jest, created this one
// based on this: https://stackoverflow.com/a/55526098/16571658
function fail(reason) {
throw new Error(reason);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want we can move it to a new file "jest_utils" (not necessarily in this PR).

}
});

it('prepare_account_upgrade_params() - account name exists', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about the test title here? (in the previous test, we had the same title.

await assert_account_config_file_upgraded({[new_account_data.name]: new_account_data});
});

it('upgrade_account_config_file() - identity exists but indexes are not', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "identity exists but indexes are not"? (the term "indexes" is links?)
Could you write the title with what explicitly is missing (access key link, identity link, etc.).

await assert_account_config_file_upgraded({[new_account_data.name]: new_account_data});
});

it('upgrade_account_config_file() - identity exists, name index exist, access keys index does not', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why index?

Suggested change
it('upgrade_account_config_file() - identity exists, name index exist, access keys index does not', async () => {
it('upgrade_account_config_file() - identity exists, name symlink exist, access keys symlink does not', async () => {

@shirady
Copy link
Contributor

shirady commented Jan 9, 2025

@romayalon could you update the doc file of CI&Tests.md with the new tests files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants