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

Rework extracting duplicated code from generating job settings #2959

Merged
merged 2 commits into from
Apr 23, 2020

Conversation

Amrysliu
Copy link
Contributor

@okurz
Copy link
Member

okurz commented Apr 20, 2020

Can you please explain what you changed vs. the last time and what additional tests you have executed?

@codecov
Copy link

codecov bot commented Apr 20, 2020

Codecov Report

Merging #2959 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2959   +/-   ##
=======================================
  Coverage   91.54%   91.54%           
=======================================
  Files         202      202           
  Lines       12707    12703    -4     
=======================================
- Hits        11632    11629    -3     
+ Misses       1075     1074    -1     
Impacted Files Coverage Δ
lib/OpenQA/JobSettings.pm 100.00% <100.00%> (ø)
lib/OpenQA/Schema/Result/ScheduledProducts.pm 97.18% <100.00%> (-0.12%) ⬇️
lib/OpenQA/WebAPI/Controller/API/V1/Job.pm 90.53% <100.00%> (+0.59%) ⬆️
lib/OpenQA/Worker/CommandHandler.pm 92.18% <0.00%> (-1.57%) ⬇️
lib/OpenQA/Resource/Jobs.pm 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d819309...fbba825. Read the comment docs.

@Amrysliu
Copy link
Contributor Author

In this pr, I move $settings->{MACHINE} = $machine->name; from ScheduledProducts.pm to JobSettings.pm. That make sure the MACHINE has been added to the setting before expanding variables, such as %MACHINE%.
I also added a test code in t/api/02-iso.t, Expand specified variables when scheduling iso. That is used to test if all specified variables are replaced correctly.

lib/OpenQA/JobSettings.pm Show resolved Hide resolved
t/api/02-iso.t Outdated
Comment on lines 984 to 987
is_deeply(
$result,
{
BUILD => '176.6',
BUILD_HA => '176.6',
BUILD_SDK => '176.6',
HDD_1 => 'opensuse-13.1-i586-176.6@64bit-minimal_with_sdk176.6_installed.qcow2',
ISO_MAXSIZE => '4700372992',
QEMUCPU => 'qemu64',
VERSION => '13.1',
BACKEND => 'qemu',
WORKER_CLASS => 'qemu_i586',
MACHINE => '64bit',
DVD => '1',
FLAVOR => 'DVD',
TEST_SUITE_NAME => 'test',
ISO => 'openSUSE-13.1-DVD-i586-Build0091-Media.iso',
DISTRI => 'opensuse',
SHUTDOWN_NEEDS_AUTH => '1',
TEST => 'test',
ARCH => 'i586'
},
'specified variables were expanded correctly'
);
Copy link
Member

Choose a reason for hiding this comment

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

To keep this shorter I recommend you only check for relevant entries, e.g. check MACHINE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you do not mind, I prefer to check all the settings. Because I also added some variables such as %BUILD_HA%. In my opinion, it is not only used to check MACHINE, but also other variables that need to be replaced.

Copy link
Member

Choose a reason for hiding this comment

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

The thing is: It should be clear in this test what settings we really care about. Being too specific is harmful because any next contributor that changes something so that the test fails does not understand easily which parts are relevant. Of course you can check for multiple values but not for all. I recommend to use the json_is test method here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified the code just checking few import variables. If I understand correctly, we cannot use json_is here, because schedule_iso returns return $t->tx->res.

@Amrysliu Amrysliu force-pushed the refactor_generate_job_settings branch from 9ff347e to e3d84d0 Compare April 21, 2020 10:49
@Amrysliu
Copy link
Contributor Author

@Martchus @kalikiana Would you mind double-checking this pull request?

lib/OpenQA/JobSettings.pm Outdated Show resolved Hide resolved
t/api/02-iso.t Show resolved Hide resolved
Both in the operation `isos post` and `jobs post`, there are some code
used to generate job settings, this pr used to reduce the duplicated
code.
When doing `isos post`, the machine name was added to the job settings
before expanding specified variables, so the %MACHINE% was not replaced
correctly.
@Amrysliu Amrysliu force-pushed the refactor_generate_job_settings branch from e3d84d0 to fbba825 Compare April 23, 2020 08:43
@okurz okurz merged commit 071caad into os-autoinst:master Apr 23, 2020
next if $key eq 'TEST' || $key eq 'MACHINE';
$settings{uc $key} = $args->{$key};
}

# make sure that the DISTRI is lowercase
$settings{DISTRI} = lc($settings{DISTRI});
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, this PR caused regression in many tests that use DISTRI in asset names or job dependency settings. The above line must be executed before generate_settings().

Copy link
Contributor

@mdoucha mdoucha May 6, 2020

Choose a reason for hiding this comment

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

Example: https://openqa.suse.de/tests/4186731#settings
START_AFTER_TEST was expanded to incorrect value, OpenQA failed to find the parent job and register ASSET_1 from it.

Amrysliu added a commit to Amrysliu/openQA that referenced this pull request May 7, 2020
PR os-autoinst#2959 caused a regression
issue that the `DISTRI` is not converted into lowercase.

Here is the comments and example: https://github.com/os-autoinst/openQA/pull/2959/files#r420928584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants