Skip to content

Commit

Permalink
Merge pull request #64 from yast/catch-scc-request-timeout-exception-…
Browse files Browse the repository at this point in the history
…master

Catch scc request timeout exception
  • Loading branch information
lcaparroz committed Mar 26, 2024
2 parents 3694bf6 + d7149ff commit c5ca0d0
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
- name: Git Checkout
uses: actions/checkout@v2

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

- name: Proper Rubocop Version
run: rm /etc/alternatives/rubocop && ln -s
Expand Down
109 changes: 100 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,115 @@
# Rubocop version is locked in the dependencies of scc-codestyle gem.
# The version of scc-codestyle gem is specified in the Dockerfile.
inherit_gem:
scc-codestyle:
- default.yml
require:
- rubocop-rspec

inherit_from: .rubocop_todo.yml

AllCops:
Include:
- Gemfile
- config.ru
NewCops: disable
Exclude:
- .bundle/**/*
- vendor/**/*
- package/*
- Rakefile

Rails:
Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/EmptyLinesAroundMethodBody:
Enabled: false

Layout/EmptyLines:
Enabled: false

Layout/HashAlignment:
Enabled: false

Layout/LineLength:
Enabled: true
Max: 160

Lint/ErbNewArguments:
Enabled: false

Lint/MissingSuper:
Enabled: false

Lint/MixedRegexpCaptureTypes:
Enabled: false

Metrics/AbcSize:
Enabled: true
Max: 80

Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Enabled: true
Max: 160

Metrics/MethodLength:
Enabled: true
Max: 50

Metrics/PerceivedComplexity:
Enabled: true
Max: 12

Naming/MethodParameterName:
Enabled: false

Naming/VariableNumber:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ClassEqualityComparison:
Enabled: false

Style/Documentation:
Enabled: false

Style/ExpandPathArguments:
Enabled: false

Style/FormatString:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/HashTransformValues:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/ParenthesesAroundCondition:
Enabled: false

Style/RedundantBegin:
Enabled: false

Style/RedundantParentheses:
Enabled: false

Style/StringConcatenation:
Enabled: false

Style/TernaryParentheses:
Enabled: false

Style/WordArray:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/ExampleLength:
Enabled: true
Max: 16

# Impossible to satisfy these rules in specs
RSpec/ExpectInHook:
Enabled: false
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ gem 'yast-rake', '~> 0.2.20'

group :development do
gem 'gettext'
gem 'scc-codestyle', '~> 0.1.4'
gem 'rubocop', '~> 1.28.0'
gem 'rubocop-rspec', '~> 1.19.0'
end
39 changes: 22 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
ast (2.4.2)
gettext (3.2.9)
locale (>= 2.0.5)
text (>= 1.3.0)
locale (2.1.2)
packaging_rake_tasks (1.4.4)
rake
parallel (1.12.1)
parser (2.5.0.0)
ast (~> 2.4.0)
powerpack (0.1.1)
rainbow (3.0.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.0.1)
rubocop (0.52.1)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.28.2)
parallel (~> 1.10)
parser (>= 2.4.0.2, < 3.0)
powerpack (~> 0.1)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.17.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-rspec (1.19.0)
rubocop (>= 0.51.0)
ruby-progressbar (1.9.0)
scc-codestyle (0.1.4)
rubocop (= 0.52.1)
rubocop-rspec (= 1.19)
ruby-progressbar (1.13.0)
text (1.3.1)
unicode-display_width (1.3.0)
unicode-display_width (2.5.0)
yast-rake (0.2.20)
packaging_rake_tasks (>= 1.1.4)
rake
Expand All @@ -38,8 +42,9 @@ PLATFORMS

DEPENDENCIES
gettext
scc-codestyle (~> 0.1.4)
rubocop (~> 1.28.0)
rubocop-rspec (~> 1.19.0)
yast-rake (~> 0.2.20)

BUNDLED WITH
1.16.1
2.5.3
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,35 @@ There different ways to run the module:
* `DISPLAY= rake run` — forces to run in ncurses mode;
* `Y2DIR=src/ /usr/sbin/yast2 --ncurses rmt` — same as above.

#### Docker Setup

To run the module within a Docker container:

1. Select a proper Docker container image for YaST from https://registry.opensuse.org, according to the branch, e.g.:

* On branch `master`, use `yast/head/containers_tumbleweed/yast-ruby`.
* On branch `SLE-15-SP6`, use `yast/sle-15/sp6/containers/yast-ruby`.

2. Run the Docker container with access to the localhost network with the chosen distribution and version:

```shell
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
```

3. On the container, install the `rmt-server` package:

```shell
zypper --non-interactive install rmt-server
```

4. Run the YaST RMT module with `rake run` or through the other ways previously described.

### Running tests

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

```
docker build -t yast-rmt-image .
docker run -it yast-rmt-image rspec
```shell
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
```

### Resources
Expand Down
9 changes: 9 additions & 0 deletions package/yast2-rmt.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Feb 8 16:10:29 UTC 2024 - Luis Caparroz <luis.caparroz@suse.com>

- Adds UI dialog to allow the user to retry the SCC credential validation when
the request times out (bsc#1218084).
- Adds HTTP User-Agent to requests to the SCC API and changes the enpoint for
credential validation.
- Version 1.3.5

-------------------------------------------------------------------
Thu Jun 9 10:47:13 UTC 2022 - Dominique Leuenberger <dimstar@opensuse.org>

Expand Down
3 changes: 2 additions & 1 deletion package/yast2-rmt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-rmt
Version: 1.3.4
Version: 1.3.5
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down Expand Up @@ -60,6 +60,7 @@ rake install DESTDIR="%{buildroot}"
%defattr(-,root,root)
%{yast_dir}/clients/*.rb
%{yast_dir}/lib/rmt
%{yast_dir}/lib/rmt.rb
%{yast_desktopdir}/rmt.desktop
%{yast_dir}/data/rmt

Expand Down
71 changes: 59 additions & 12 deletions spec/rmt/wizard_scc_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,73 @@
expect(Yast::UI).to receive(:CloseDialog)

expect_any_instance_of(Net::HTTP::Get).to receive(:basic_auth).with(config['scc']['username'], config['scc']['password'])

expect(Net::HTTP).to receive(:start).and_return(response_double)
expect(response_double).to receive(:code).and_return(response_code)
end

let(:response_double) { instance_double(Net::HTTPResponse) }
context 'when the request completes without errors' do
before do
expect(Net::HTTP).to receive(:start).and_return(response_double)
expect(response_double).to receive(:code).and_return(response_code)
end

let(:response_double) { instance_double(Net::HTTPResponse) }

context 'when HTTP response code is 200' do
let(:response_code) { '200' }
context 'when HTTP response code is 200' do
let(:response_code) { '200' }

it 'returns true' do
expect(scc_page.scc_credentials_valid?).to be(true)
it 'returns true' do
expect(scc_page.scc_credentials_valid?).to be(true)
end
end

context 'when HTTP response code is not 200' do
let(:response_code) { '401' }

it 'returns false' do
expect(scc_page.scc_credentials_valid?).to be(false)
end
end
end

context 'when HTTP response code is not 200' do
let(:response_code) { '401' }
context 'when SCC times out and the user chooses not to try again' do
before do
expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(false)
expect(Net::HTTP).to receive(:start).and_raise(Net::ReadTimeout)
end

context 'and the user chooses to not try again' do
it 'returns false' do
expect(scc_page.scc_credentials_valid?).to be(false)
end
end
end

context 'when SCC times out and the user chooses to try again' do
before do
expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(true)
expect(Net::HTTP).to receive(:start).and_raise(Net::ReadTimeout)
expect(Net::HTTP).to receive(:start).and_return(response_double)
end

let(:response_double) { instance_double(Net::HTTPResponse) }

context 'when SCC responds quickly and the HTTP response code is 200' do
before do
expect(response_double).to receive(:code).and_return(200)
end

it 'returns true' do
expect(scc_page.scc_credentials_valid?).to be(true)
end
end

context 'when SCC responds quickly and the HTTP response code is not 200' do
before do
expect(response_double).to receive(:code).and_return(401)
end

it 'returns false' do
expect(scc_page.scc_credentials_valid?).to be(false)
it 'returns false' do
expect(scc_page.scc_credentials_valid?).to be(false)
end
end
end
end
Expand Down

0 comments on commit c5ca0d0

Please sign in to comment.