Skip to content

Commit 1f59118

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
Configure c states using grubby command
For other OSes, this commit keeps the old approach of changing grub files. This is done because the old approach does not take effect on RHEL9 and Rocky9. The `grubby` command does not take effect on some of the old OSes. Signed-off-by: Hanwen <[email protected]>
1 parent 1e5b655 commit 1f59118

File tree

7 files changed

+60
-19
lines changed

7 files changed

+60
-19
lines changed

cookbooks/aws-parallelcluster-platform/resources/c_states/c_states_redhat8.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and limitations under the License.
1414

1515
provides :c_states, platform: 'redhat' do |node|
16-
node['platform_version'].to_i >= 8
16+
node['platform_version'].to_i == 8
1717
end
1818

1919
use 'partial/_c_states_common'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://aws.amazon.com/apache2.0/
10+
#
11+
# or in the "LICENSE.txt" file accompanying this file.
12+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
13+
# See the License for the specific language governing permissions and limitations under the License.
14+
15+
provides :c_states, platform: 'redhat' do |node|
16+
node['platform_version'].to_i == 9
17+
end
18+
19+
use 'partial/_c_states_common'
20+
use 'partial/_c_states_redhat_9_based'

cookbooks/aws-parallelcluster-platform/resources/c_states/c_states_rocky8.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and limitations under the License.
1414

1515
provides :c_states, platform: 'rocky' do |node|
16-
node['platform_version'].to_i >= 8
16+
node['platform_version'].to_i == 8
1717
end
1818

1919
use 'partial/_c_states_common'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://aws.amazon.com/apache2.0/
10+
#
11+
# or in the "LICENSE.txt" file accompanying this file.
12+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
13+
# See the License for the specific language governing permissions and limitations under the License.
14+
15+
provides :c_states, platform: 'rocky' do |node|
16+
node['platform_version'].to_i == 9
17+
end
18+
19+
use 'partial/_c_states_common'
20+
use 'partial/_c_states_redhat_9_based'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
action :setup do
2+
return if !x86_instance? || on_docker?
3+
shell_out!('grubby --update-kernel=ALL --args="intel_idle.max_cstate=1 processor.max_cstate=1"')
4+
end

cookbooks/aws-parallelcluster-platform/spec/unit/resources/c_states_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def self.setup(chef_run)
1111
end
1212

1313
describe 'c_states:setup' do
14+
stubs_for_provider("c_states[setup]") do |provider|
15+
allow(provider).to receive_shell_out("grubby --update-kernel=ALL --args=\"intel_idle.max_cstate=1 processor.max_cstate=1\"")
16+
end
1417
before do
1518
stubs_for_resource('c_states') do |res|
1619
allow(res).to receive(:append_if_not_present_grub_cmdline)
@@ -40,16 +43,18 @@ def self.setup(chef_run)
4043
is_expected.to setup_c_states('setup')
4144
end
4245

43-
it 'edits /etc/default/grub' do
44-
stubs_for_resource('c_states[setup]') do |res|
45-
expect(res).to receive(:append_if_not_present_grub_cmdline).with(grub_cmdline_attributes, grub_variable)
46+
if version.to_i != 9
47+
it 'edits /etc/default/grub' do
48+
stubs_for_resource('c_states[setup]') do |res|
49+
expect(res).to receive(:append_if_not_present_grub_cmdline).with(grub_cmdline_attributes, grub_variable)
50+
end
51+
chef_run
4652
end
47-
chef_run
48-
end
4953

50-
it 'regenerate grub boot menus' do
51-
is_expected.to run_execute('Regenerate grub boot menu')
52-
.with(command: regenerate_grub_boot_menu_command)
54+
it 'regenerate grub boot menus' do
55+
is_expected.to run_execute('Regenerate grub boot menu')
56+
.with(command: regenerate_grub_boot_menu_command)
57+
end
5358
end
5459
end
5560

cookbooks/aws-parallelcluster-platform/test/controls/c_states_spec.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
its('content') { should match(/intel_idle.max_cstate=1/) }
1010
end
1111

12-
if os.redhat? # redhat includes amazon
12+
if os.redhat8? || os.alinux2? || os.centos7? || os.rocky8?
1313

1414
describe file('/boot/grub2/grub.cfg') do
1515
it { should exist }
@@ -24,14 +24,6 @@
2424
its('content') { should match(/processor.max_cstate=1/) }
2525
its('content') { should match(/intel_idle.max_cstate=1/) }
2626
end
27-
28-
else
29-
describe "unsupported OS" do
30-
# this produces a skipped control (ignore-like)
31-
# adding a new OS to kitchen platform list and running the tests,
32-
# it would surface the fact this recipe does not support this OS.
33-
pending "support for #{os.name}-#{os.release} needs to be implemented"
34-
end
3527
end
3628
end
3729

0 commit comments

Comments
 (0)