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

don't fail when the cli didn't return a correct task list #926

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion definitions/features/pulpcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def cli_available?
end

def cli(args)
parse_json(execute("pulp --format json #{args}"))
parse_json(execute!("pulp --format json #{args}"))
end

def running_tasks
cli('task list --state-in running --state-in canceling')
rescue ForemanMaintain::Error::ExecutionError
[]
end

def wait_for_tasks(spinner, timeout_for_tasks_status = TIMEOUT_FOR_TASKS_STATUS)
Expand Down
31 changes: 31 additions & 0 deletions test/definitions/features/pulpcore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@

subject { Features::Pulpcore.new }

describe '.cli' do
it 'returns hash result when getting JSON reply' do
subject.expects(:execute!).with('pulp --format json status').returns('{"versions": []}')
expected = { 'versions' => [] }
assert_equal expected, subject.cli('status')
end

it 'passes on ExecutionError' do
subject.expects(:execute!).with('pulp --format json status').
raises(ForemanMaintain::Error::ExecutionError.new('', 1, '', ''))
assert_raises(ForemanMaintain::Error::ExecutionError) do
subject.cli('status')
end
end
end

describe '.running_tasks' do
it 'returns an empty list when there are no tasks' do
subject.expects(:execute!).
with('pulp --format json task list --state-in running --state-in canceling').returns('[]')
assert_empty subject.running_tasks
end

it 'returns an empty list when pulp cli failed' do
subject.expects(:execute!).
with('pulp --format json task list --state-in running --state-in canceling').
raises(ForemanMaintain::Error::ExecutionError.new('', 1, '', ''))
assert_empty subject.running_tasks
end
end

describe '.cli_available?' do
it 'recognizes server with CLI' do
File.expects(:exist?).with('/etc/pulp/cli.toml').returns(true)
Expand Down
Loading