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

2820 test #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
142 changes: 0 additions & 142 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ jobs:
ruby: ["2.7.1"]
bundler: ["2.1.4"]
include:
# Test versions from Ubuntu 22.04
- os: ubuntu-latest
ruby: "3.0.2"
bundler: "2.3.5"
# Test versions from RHEL8 & RHEL9
- os: ubuntu-latest
ruby: "3.1.2"
bundler: "2.3.7"
# Test versions from Amazon Linux 2023
- os: ubuntu-latest
ruby: "3.2.2"
bundler: "2.4.10"
runs-on: ${{ matrix.os }}
name: Unit tests

Expand Down Expand Up @@ -80,137 +72,3 @@ jobs:
with:
name: system-test-failures
path: apps/dashboard/tmp/screenshots/*.png

k8s-tests:
runs-on: ubuntu-latest
name: Kubernetes tests
steps:
- name: Checkout ${{ github.sha }}
uses: actions/checkout@v3
- name: Create kind cluster
uses: container-tools/kind-action@v2
- name: Apply ondemand RBAC
run: kubectl apply -f hooks/k8s-bootstrap/ondemand.yaml
- name: Get ondemand token
id: token
run: |
TOKEN_NAME=$(kubectl describe serviceaccount ondemand -n ondemand | grep Tokens | awk '{ print $2 }')
TOKEN=$(kubectl describe secret $TOKEN_NAME -n ondemand | grep "token:" | awk '{ print $2 }')
echo "ondemand=${TOKEN}" >> $GITHUB_OUTPUT
- name: Setup kubectl
run: |
kubectl config set-credentials ondemand --token="${{ steps.token.outputs.ondemand }}"
kubectl config set-context kind-kind --user=ondemand
kubectl config use-context kind-kind
kubectl cluster-info
- name: Test k8s-bootstrap
run: /bin/bash hooks/k8s-bootstrap/k8s-bootstrap-ondemand.sh test hooks/hook.env.example

e2e-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
dist:
- el7
- el8
- el9
- amzn2023
- ubuntu-20.04
- ubuntu-22.04
arch:
- x86_64
- aarch64
- ppc64le
version: ["3.1"]
exclude:
# Amazon 2023 on aarch64 is very slow and will time out
- dist: amzn2023
arch: aarch64
# Amazon 2023 doesn't have ppc64le containers
- dist: amzn2023
arch: ppc64le
# Ubuntu doesn't have way to get NodeJS 14+ on ppc64le
- dist: ubuntu-20.04
arch: ppc64le
# Ubuntu doesn't have way to get NodeJS 14+ on ppc64le
- dist: ubuntu-22.04
arch: ppc64le
runs-on: ${{ matrix.os }}
name: E2E test ${{ matrix.dist }}-${{ matrix.arch }}

steps:
- name: Checkout ${{ github.sha }}
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Ruby using Bundler
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7.1"
bundler: "2.1.4"
bundler-cache: true

- name: Build package
if: matrix.arch == 'x86_64'
run: bundle exec rake package:build[${{ matrix.dist }},${{ matrix.arch }}]
env:
VERSION: "${{ matrix.version }}.0"
OOD_PACKAGING_DEBUG: 'true'

- name: Run package tests
if: matrix.arch == 'x86_64'
run: bundle exec rake test:e2e
env:
BEAKER_set: ${{ matrix.dist }}
OOD_BUILD_REPO: ${{ matrix.version }}

- name: arch distro
if: ${{ matrix.arch != 'x86_64' && github.event_name == 'schedule' }}
run: |
DISTRO=$(echo "${{ matrix.os }}" | sed 's|\-||g')
echo "DISTRO=${DISTRO}" >> $GITHUB_ENV
if [ "${{ matrix.arch }}" == "aarch64" ]; then
echo "PLATFORM=linux/arm64" >> $GITHUB_ENV
fi
if [ "${{ matrix.arch }}" == "ppc64le" ]; then
echo "PLATFORM=linux/ppc64le" >> $GITHUB_ENV
fi

- name: Test OnDemand
if: ${{ matrix.arch != 'x86_64' && github.event_name == 'schedule' }}
uses: uraimo/run-on-arch-action@v2
with:
arch: ${{ matrix.arch }}
distro: ${{ env.DISTRO }}
githubToken: ${{ github.token }}
install: |
apt update -y
apt install -y ruby-bundler ruby-dev build-essential git \
apt-transport-https ca-certificates curl software-properties-common
# Not available for ppc64le
# apt install -y chromium-chromedriver
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update -y
apt install -y docker-ce
dockerRunArgs: |
--platform ${{ env.PLATFORM }}
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
bundle install
bundle exec rake package:build[${{ matrix.dist }},${{ matrix.arch }}]
# e2e tests fail with issues accessing chorium
# bundle exec rake test:e2e
env: |
VERSION: "${{ matrix.version }}.0"
OOD_PACKAGING_DEBUG: 'true'
BEAKER_set: ${{ matrix.dist }}-${{ matrix.arch }}
OOD_BUILD_REPO: ${{ matrix.version }}
DOCKER_IN_DOCKER: 'true'

- name: Debug failure
if: failure()
run: |
find tmp/e2e_ctr/ -type f -name *.log -exec cat {} +
17 changes: 13 additions & 4 deletions apps/dashboard/app/controllers/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ScriptsController < ApplicationController

before_action :find_project
before_action :find_script, only: [:show, :edit, :submit, :save]
before_action :find_script, only: [:show, :edit, :destroy, :submit, :save]

SAVE_SCRIPT_KEYS = [
:cluster, :auto_accounts, :auto_accounts_exclude, :auto_scripts, :auto_scripts_exclude,
Expand All @@ -23,7 +23,7 @@ def create
@script = Script.new(opts)

if @script.save
redirect_to project_path(params[:project_id]), notice: 'sucess!'
redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_created')
else
redirect_to project_path(params[:project_id]), alert: @script.errors[:save].last
end
Expand All @@ -34,13 +34,22 @@ def create
def edit
end

# DELETE /projects/:project_id/scripts/:id
def destroy
if @script.destroy
redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_deleted')
else
redirect_to project_path(params[:project_id]), alert: @script.errors[:destroy].last
end
end

# POST /projects/:project_id/scripts/:id/save
# save the script after editing
def save
@script.update(save_script_params[:script])

if @script.save
redirect_to project_path(params[:project_id]), notice: 'sucess!'
redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_updated')
else
redirect_to project_path(params[:project_id]), alert: @script.errors[:save].last
end
Expand All @@ -52,7 +61,7 @@ def submit
opts = submit_script_params[:script].to_h.symbolize_keys

if (job_id = @script.submit(opts))
redirect_to(project_path(params[:project_id]), notice: "Successfully submited job #{job_id}.")
redirect_to(project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_submitted', job_id: job_id))
else
redirect_to(project_path(params[:project_id]), alert: @script.errors[:submit].last)
end
Expand Down
17 changes: 16 additions & 1 deletion apps/dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def []=(_id, value)

def save
@id = Script.next_id(project_dir) if @id.nil?
File.write("#{Script.scripts_dir(project_dir)}/#{id}.yml", to_yaml)
File.write(script_file, to_yaml)

true
rescue StandardError => e
Expand All @@ -137,6 +137,17 @@ def save
false
end

def destroy
FileUtils.remove_file(script_file)
FileUtils.remove_file(job_log_file)
FileUtils.remove_file(cache_file_path) if cache_file_exists?
true
rescue StandardError => e
errors.add(:destroy, e.message)
Rails.logger.warn("Cannot delete script #{id} due to error: #{e.class}:#{e.message}")
false
end

def update(params)
# reset smart attributes becuase the user could have removed some fields
@smart_attributes = []
Expand Down Expand Up @@ -176,6 +187,10 @@ def most_recent_job_cluster

private

def script_file
File.join(Script.scripts_dir(project_dir), "#{id}.yml")
end

# parameters you got from the controller that affect the attributes, not form.
# i.e., mins & maxes you set in the form but get serialized to the 'attributes' section.
def attribute_parameter?(name)
Expand Down
9 changes: 9 additions & 0 deletions apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
)
%>

<%= link_to(
t('dashboard.delete'),
project_script_path(@project.id, script.id),
class: 'btn btn-danger mx-1',
method: 'delete',
data: { confirm: I18n.t('dashboard.jobs_scripts_delete_script_confirmation') },
)
%>

<%-
params = script.smart_attributes.map { |attr| ["script[#{attr.id}]", attr.value] }.to_h
-%>
Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ en:
jobs_create_blank_project: "Create a new project"
jobs_create_template_project: "Create a new project from a template"

jobs_scripts_created: "Script successfully created!"
jobs_scripts_updated: "Script manifest updated!"
jobs_scripts_not_found: "Cannot find script %{script_id}"
jobs_scripts_deleted: "Script successfully deleted!"
jobs_scripts_submitted: "Successfully submited job %{job_id}."
jobs_scripts_delete_script_confirmation: "Delete all contents of script?"

settings_updated: "Settings updated"

breadcrumbs_support_ticket: "Support Ticket"
Expand Down Expand Up @@ -245,5 +252,6 @@ en:
save: "Save"
add: "Add"
remove: "Remove"
delete: "Delete"
edit: "Edit"
show: "Show"
45 changes: 36 additions & 9 deletions apps/dashboard/test/system/jobs_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ def add_bc_num_hours(project_id)
required: false
HEREDOC

assert_selector('.alert-success', text: "×\nClose\nsucess!")
success_message = I18n.t('dashboard.jobs_scripts_created')
assert_selector('.alert-success', text: "×\nClose\n#{success_message}")
assert_equal(expected_yml, File.read("#{dir}/projects/1/.ondemand/scripts/1.yml"))

find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click
assert_selector('h1', text: 'the script title', count: 1)
end
end
Expand All @@ -198,7 +199,7 @@ def add_bc_num_hours(project_id)
project_dir = "#{dir}/projects/1"
add_account(1)

find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click
assert_selector('h1', text: 'the script title', count: 1)

expected_accounts = ['pas1604', 'pas1754', 'pas1871', 'pas2051', 'pde0006', 'pzs0714', 'pzs0715', 'pzs1010',
Expand All @@ -213,6 +214,30 @@ def add_bc_num_hours(project_id)
end
end

test 'deleting a script that succeeds' do
Dir.mktmpdir do |dir|
setup_project(dir)
setup_script(1)
project_dir = "#{dir}/projects/1"
script_dir = "#{project_dir}/.ondemand/scripts"
expected_script_files = ["#{script_dir}/1.yml", "#{script_dir}/1_job_log"]
# ASSERT EXPECTED SCRIPT FILES
expected_script_files.each do |file_path|
assert_equal true, File.exist?(file_path)
end

accept_confirm do
click_on 'Delete'
end

assert_selector '.alert-success', text: 'Script successfully deleted!'
# EXPECTED FILES SHOULD BE DELETED
expected_script_files.each do |file_path|
assert_not File.exist? file_path
end
end
end

test 'submitting a script with auto attributes that succeeds' do
Dir.mktmpdir do |dir|
setup_project(dir)
Expand All @@ -221,7 +246,7 @@ def add_bc_num_hours(project_id)
script_dir = "#{project_dir}/.ondemand/scripts"
add_account(1)

find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click
assert_selector('h1', text: 'the script title', count: 1)

# assert defaults
Expand Down Expand Up @@ -264,7 +289,7 @@ def add_bc_num_hours(project_id)
script_dir = "#{project_dir}/.ondemand/scripts"
add_account(1)

find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click
assert_selector('h1', text: 'the script title', count: 1)

# assert defaults
Expand Down Expand Up @@ -342,7 +367,8 @@ def add_bc_num_hours(project_id)

# correctly saves
click_on(I18n.t('dashboard.save'))
assert_selector('.alert-success', text: "×\nClose\nsucess!")
success_message = I18n.t('dashboard.jobs_scripts_updated')
assert_selector('.alert-success', text: "×\nClose\n#{success_message}")
assert_current_path '/projects/1'

# note that bc_num_hours has default, min & max
Expand Down Expand Up @@ -419,7 +445,8 @@ def add_bc_num_hours(project_id)

# correctly saves
click_on(I18n.t('dashboard.save'))
assert_selector('.alert-success', text: "×\nClose\nsucess!")
success_message = I18n.t('dashboard.jobs_scripts_updated')
assert_selector('.alert-success', text: "×\nClose\n#{success_message}")
assert_current_path '/projects/1'

expected_yml = <<~HEREDOC
Expand Down Expand Up @@ -552,7 +579,7 @@ def add_bc_num_hours(project_id)

find("#save_script_edit").click
assert_current_path('/projects/1')
find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click

# now let's check scripts#show to see if they've actually been excluded.
show_account_options = page.all("#script_auto_accounts option").map(&:value)
Expand All @@ -579,7 +606,7 @@ def add_bc_num_hours(project_id)

find("#save_script_edit").click
assert_current_path('/projects/1')
find('[href="/projects/1/scripts/1"]').click
find('[href="/projects/1/scripts/1"].btn-success').click

# now let's check scripts#show and they should be back.
show_account_options = page.all("#script_auto_accounts option").map(&:value)
Expand Down