Skip to content

Commit c5ca0d0

Browse files
authored
Merge pull request #64 from yast/catch-scc-request-timeout-exception-master
Catch scc request timeout exception
2 parents 3694bf6 + d7149ff commit c5ca0d0

File tree

11 files changed

+306
-49
lines changed

11 files changed

+306
-49
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ jobs:
5353
- name: Git Checkout
5454
uses: actions/checkout@v2
5555

56-
- name: Add SCC Codestyle
57-
run: gem install --no-document scc-codestyle -v 0.1.4
56+
- name: Install project dependencies
57+
run: bundle install
5858

5959
- name: Proper Rubocop Version
6060
run: rm /etc/alternatives/rubocop && ln -s

.rubocop.yml

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,115 @@
1-
# Rubocop version is locked in the dependencies of scc-codestyle gem.
2-
# The version of scc-codestyle gem is specified in the Dockerfile.
3-
inherit_gem:
4-
scc-codestyle:
5-
- default.yml
1+
require:
2+
- rubocop-rspec
63

74
inherit_from: .rubocop_todo.yml
85

96
AllCops:
10-
Include:
11-
- Gemfile
12-
- config.ru
7+
NewCops: disable
138
Exclude:
149
- .bundle/**/*
1510
- vendor/**/*
1611
- package/*
1712
- Rakefile
1813

19-
Rails:
14+
Layout/EmptyLineAfterGuardClause:
2015
Enabled: false
2116

17+
Layout/EmptyLinesAroundMethodBody:
18+
Enabled: false
19+
20+
Layout/EmptyLines:
21+
Enabled: false
22+
23+
Layout/HashAlignment:
24+
Enabled: false
25+
26+
Layout/LineLength:
27+
Enabled: true
28+
Max: 160
29+
30+
Lint/ErbNewArguments:
31+
Enabled: false
32+
33+
Lint/MissingSuper:
34+
Enabled: false
35+
36+
Lint/MixedRegexpCaptureTypes:
37+
Enabled: false
38+
39+
Metrics/AbcSize:
40+
Enabled: true
41+
Max: 80
42+
43+
Metrics/BlockLength:
44+
Enabled: false
45+
46+
Metrics/ClassLength:
47+
Enabled: true
48+
Max: 160
49+
50+
Metrics/MethodLength:
51+
Enabled: true
52+
Max: 50
53+
54+
Metrics/PerceivedComplexity:
55+
Enabled: true
56+
Max: 12
57+
58+
Naming/MethodParameterName:
59+
Enabled: false
60+
61+
Naming/VariableNumber:
62+
Enabled: false
63+
64+
Style/ClassAndModuleChildren:
65+
Enabled: false
66+
67+
Style/ClassEqualityComparison:
68+
Enabled: false
69+
70+
Style/Documentation:
71+
Enabled: false
72+
73+
Style/ExpandPathArguments:
74+
Enabled: false
75+
76+
Style/FormatString:
77+
Enabled: false
78+
79+
Style/FrozenStringLiteralComment:
80+
Enabled: false
81+
82+
Style/HashTransformValues:
83+
Enabled: false
84+
85+
Style/NumericPredicate:
86+
Enabled: false
87+
88+
Style/ParenthesesAroundCondition:
89+
Enabled: false
90+
91+
Style/RedundantBegin:
92+
Enabled: false
93+
94+
Style/RedundantParentheses:
95+
Enabled: false
96+
97+
Style/StringConcatenation:
98+
Enabled: false
99+
100+
Style/TernaryParentheses:
101+
Enabled: false
102+
103+
Style/WordArray:
104+
Enabled: false
105+
106+
RSpec/AnyInstance:
107+
Enabled: false
108+
109+
RSpec/ExampleLength:
110+
Enabled: true
111+
Max: 16
112+
22113
# Impossible to satisfy these rules in specs
23114
RSpec/ExpectInHook:
24115
Enabled: false

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ gem 'yast-rake', '~> 0.2.20'
44

55
group :development do
66
gem 'gettext'
7-
gem 'scc-codestyle', '~> 0.1.4'
7+
gem 'rubocop', '~> 1.28.0'
8+
gem 'rubocop-rspec', '~> 1.19.0'
89
end

Gemfile.lock

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
ast (2.4.0)
4+
ast (2.4.2)
55
gettext (3.2.9)
66
locale (>= 2.0.5)
77
text (>= 1.3.0)
88
locale (2.1.2)
99
packaging_rake_tasks (1.4.4)
1010
rake
11-
parallel (1.12.1)
12-
parser (2.5.0.0)
13-
ast (~> 2.4.0)
14-
powerpack (0.1.1)
15-
rainbow (3.0.0)
11+
parallel (1.24.0)
12+
parser (3.3.0.5)
13+
ast (~> 2.4.1)
14+
racc
15+
racc (1.7.3)
16+
rainbow (3.1.1)
1617
rake (13.0.1)
17-
rubocop (0.52.1)
18+
regexp_parser (2.9.0)
19+
rexml (3.2.6)
20+
rubocop (1.28.2)
1821
parallel (~> 1.10)
19-
parser (>= 2.4.0.2, < 3.0)
20-
powerpack (~> 0.1)
22+
parser (>= 3.1.0.0)
2123
rainbow (>= 2.2.2, < 4.0)
24+
regexp_parser (>= 1.8, < 3.0)
25+
rexml
26+
rubocop-ast (>= 1.17.0, < 2.0)
2227
ruby-progressbar (~> 1.7)
23-
unicode-display_width (~> 1.0, >= 1.0.1)
28+
unicode-display_width (>= 1.4.0, < 3.0)
29+
rubocop-ast (1.31.2)
30+
parser (>= 3.3.0.4)
2431
rubocop-rspec (1.19.0)
2532
rubocop (>= 0.51.0)
26-
ruby-progressbar (1.9.0)
27-
scc-codestyle (0.1.4)
28-
rubocop (= 0.52.1)
29-
rubocop-rspec (= 1.19)
33+
ruby-progressbar (1.13.0)
3034
text (1.3.1)
31-
unicode-display_width (1.3.0)
35+
unicode-display_width (2.5.0)
3236
yast-rake (0.2.20)
3337
packaging_rake_tasks (>= 1.1.4)
3438
rake
@@ -38,8 +42,9 @@ PLATFORMS
3842

3943
DEPENDENCIES
4044
gettext
41-
scc-codestyle (~> 0.1.4)
45+
rubocop (~> 1.28.0)
46+
rubocop-rspec (~> 1.19.0)
4247
yast-rake (~> 0.2.20)
4348

4449
BUNDLED WITH
45-
1.16.1
50+
2.5.3

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,35 @@ There different ways to run the module:
2222
* `DISPLAY= rake run` — forces to run in ncurses mode;
2323
* `Y2DIR=src/ /usr/sbin/yast2 --ncurses rmt` — same as above.
2424

25+
#### Docker Setup
26+
27+
To run the module within a Docker container:
28+
29+
1. Select a proper Docker container image for YaST from https://registry.opensuse.org, according to the branch, e.g.:
30+
31+
* On branch `master`, use `yast/head/containers_tumbleweed/yast-ruby`.
32+
* On branch `SLE-15-SP6`, use `yast/sle-15/sp6/containers/yast-ruby`.
33+
34+
2. Run the Docker container with access to the localhost network with the chosen distribution and version:
35+
36+
```shell
37+
docker run --network host -v "$(pwd):/usr/src/app" -w "/usr/src/app" -it registry.opensuse.org/yast/sle-15/sp6/containers/yast-ruby sh
38+
```
39+
40+
3. On the container, install the `rmt-server` package:
41+
42+
```shell
43+
zypper --non-interactive install rmt-server
44+
```
45+
46+
4. Run the YaST RMT module with `rake run` or through the other ways previously described.
47+
2548
### Running tests
2649

2750
It is possible to run the specs in a Docker container:
2851

29-
```
30-
docker build -t yast-rmt-image .
31-
docker run -it yast-rmt-image rspec
52+
```shell
53+
docker run -v "$(pwd):/usr/src/app" -w "/usr/src/app" -it registry.opensuse.org/yast/sle-15/sp6/containers/yast-ruby rake test:unit
3254
```
3355

3456
### Resources

package/yast2-rmt.changes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
-------------------------------------------------------------------
2+
Thu Feb 8 16:10:29 UTC 2024 - Luis Caparroz <[email protected]>
3+
4+
- Adds UI dialog to allow the user to retry the SCC credential validation when
5+
the request times out (bsc#1218084).
6+
- Adds HTTP User-Agent to requests to the SCC API and changes the enpoint for
7+
credential validation.
8+
- Version 1.3.5
9+
110
-------------------------------------------------------------------
211
Thu Jun 9 10:47:13 UTC 2022 - Dominique Leuenberger <[email protected]>
312

package/yast2-rmt.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
Name: yast2-rmt
20-
Version: 1.3.4
20+
Version: 1.3.5
2121
Release: 0
2222

2323
BuildRoot: %{_tmppath}/%{name}-%{version}-build
@@ -60,6 +60,7 @@ rake install DESTDIR="%{buildroot}"
6060
%defattr(-,root,root)
6161
%{yast_dir}/clients/*.rb
6262
%{yast_dir}/lib/rmt
63+
%{yast_dir}/lib/rmt.rb
6364
%{yast_desktopdir}/rmt.desktop
6465
%{yast_dir}/data/rmt
6566

spec/rmt/wizard_scc_page_spec.rb

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,73 @@
127127
expect(Yast::UI).to receive(:CloseDialog)
128128

129129
expect_any_instance_of(Net::HTTP::Get).to receive(:basic_auth).with(config['scc']['username'], config['scc']['password'])
130-
131-
expect(Net::HTTP).to receive(:start).and_return(response_double)
132-
expect(response_double).to receive(:code).and_return(response_code)
133130
end
134131

135-
let(:response_double) { instance_double(Net::HTTPResponse) }
132+
context 'when the request completes without errors' do
133+
before do
134+
expect(Net::HTTP).to receive(:start).and_return(response_double)
135+
expect(response_double).to receive(:code).and_return(response_code)
136+
end
137+
138+
let(:response_double) { instance_double(Net::HTTPResponse) }
136139

137-
context 'when HTTP response code is 200' do
138-
let(:response_code) { '200' }
140+
context 'when HTTP response code is 200' do
141+
let(:response_code) { '200' }
139142

140-
it 'returns true' do
141-
expect(scc_page.scc_credentials_valid?).to be(true)
143+
it 'returns true' do
144+
expect(scc_page.scc_credentials_valid?).to be(true)
145+
end
146+
end
147+
148+
context 'when HTTP response code is not 200' do
149+
let(:response_code) { '401' }
150+
151+
it 'returns false' do
152+
expect(scc_page.scc_credentials_valid?).to be(false)
153+
end
142154
end
143155
end
144156

145-
context 'when HTTP response code is not 200' do
146-
let(:response_code) { '401' }
157+
context 'when SCC times out and the user chooses not to try again' do
158+
before do
159+
expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(false)
160+
expect(Net::HTTP).to receive(:start).and_raise(Net::ReadTimeout)
161+
end
162+
163+
context 'and the user chooses to not try again' do
164+
it 'returns false' do
165+
expect(scc_page.scc_credentials_valid?).to be(false)
166+
end
167+
end
168+
end
169+
170+
context 'when SCC times out and the user chooses to try again' do
171+
before do
172+
expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(true)
173+
expect(Net::HTTP).to receive(:start).and_raise(Net::ReadTimeout)
174+
expect(Net::HTTP).to receive(:start).and_return(response_double)
175+
end
176+
177+
let(:response_double) { instance_double(Net::HTTPResponse) }
178+
179+
context 'when SCC responds quickly and the HTTP response code is 200' do
180+
before do
181+
expect(response_double).to receive(:code).and_return(200)
182+
end
183+
184+
it 'returns true' do
185+
expect(scc_page.scc_credentials_valid?).to be(true)
186+
end
187+
end
188+
189+
context 'when SCC responds quickly and the HTTP response code is not 200' do
190+
before do
191+
expect(response_double).to receive(:code).and_return(401)
192+
end
147193

148-
it 'returns false' do
149-
expect(scc_page.scc_credentials_valid?).to be(false)
194+
it 'returns false' do
195+
expect(scc_page.scc_credentials_valid?).to be(false)
196+
end
150197
end
151198
end
152199
end

0 commit comments

Comments
 (0)