Skip to content

Commit

Permalink
(node/hexrot) add conda install ts_m2gui
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarria committed Dec 15, 2023
1 parent e997b11 commit 81422d8
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hieradata/role/hexrot.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
classes:
- "mate"
- "profile::core::anaconda"
- "profile::core::common"
- "profile::core::debugutils"
- "profile::core::docker"
- "profile::core::docker::prune"
- "profile::core::ni_packages"
- "profile::core::x2go"
- "profile::ts::hexrot"
- "profile::ts::nexusctio"
files:
/rubin:
Expand All @@ -18,6 +20,8 @@ files:
subscribe:
- "Package[runHexEui]"
- "Package[runRotEui]"
- "Package[runM2Cntlr]"

# / on hexrot.cp was formated with xfs fstype=0 (long, long, long ago) and is
# not compatible with overlayfs[2]
profile::core::docker::storage_driver: "devicemapper"
Expand All @@ -27,3 +31,12 @@ accounts::group_list:
ensure: "present"
gid: 70014
forcelocal: true
profile::core::anaconda::python_env_name: "py311"
profile::core::anaconda::python_env_version: "3.11"
profile::core::anaconda::conda_packages:
-
name: "pyside2"
channel: "conda-forge"
-
name: "ts-m2gui"
channel: "lsstts"
78 changes: 78 additions & 0 deletions site/profile/manifests/core/anaconda.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# @summary
# Installs anaconda
#
# @param python_env_name
# if exist, sets the name of the virtual environment
#
# @param python_env_version
# if exist, sets the version of python for the virtual environment
#
# @param conda_packages
# if contains at least 1 tuple (name and channel), will install the package
#
class profile::core::anaconda (
String $python_env_name,
String $python_env_version,
Tuple $conda_packages,
) {
case $facts['os']['family'] {
'RedHat': {
ensure_packages('wget')
exec { 'install_anaconda':
command => '/bin/wget https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh -O /tmp/anaconda_installer.sh && /bin/bash /tmp/anaconda_installer.sh -b -p /opt/anaconda',
creates => '/opt/anaconda/bin/conda',
path => '/usr/bin:/bin:/opt/anaconda/bin',
require => Package['wget'],
}
}
default: {
notify { 'unsupported_os':
message => 'This Anaconda installation is only for RedHat family',
}
}
}
# Create a Conda environment with Python if parameters are set
if ($python_env_name and $python_env_version) {
exec { 'create_conda_env':
command => "/opt/anaconda/bin/conda create -y --name ${python_env_name} python=${python_env_version}",
creates => "/opt/anaconda/envs/${python_env_name}/",
require => Exec['install_anaconda'],
}
file { '/etc/profile.d/conda_source.sh':
ensure => file,
mode => '0644',
require => Exec['create_conda_env'],
# lint:ignore:strict_indent
content => @("SOURCE"),
#!/usr/bin/bash
source /opt/anaconda/bin/activate ${python_env_name}
| SOURCE
# lint:endignore
}
# Install libmamba inside the environment with conda
exec { 'install_libmamba_env':
command => "/opt/anaconda/bin/conda install -y -n ${python_env_name} conda-libmamba-solver",
creates => "/opt/anaconda/envs/${python_env_name}/lib/libmamba.so",
require => Exec['create_conda_env'],
path => ['/usr/bin', '/bin', '/opt/anaconda/bin'],
}
# Sets libmamba as dependencies solver
exec { 'set_libmamba':
command => 'conda config --set solver libmamba',
require => Exec['install_libmamba_env'],
unless => 'conda config --get solver | grep libmamba',
path => ['/usr/bin', '/bin', '/opt/anaconda/bin'],
}
}
#cycle and install conda stuff
if !empty($conda_packages) {
$conda_packages.each |$package_info| {
exec { "install_${package_info['name']}_via_conda":
command => "conda install -y -n ${python_env_name} -c ${package_info['channel']} ${package_info['name']}",
path => ['/usr/bin', '/bin', '/opt/anaconda/bin'],
require => Exec['set_libmamba'],
unless => "conda list -n ${python_env_name} | grep ${package_info['name']}",
}
}
}
}
42 changes: 42 additions & 0 deletions site/profile/manifests/ts/hexrot.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# @summary
# Sets up repos and symlinks for hexrot

class profile::ts::hexrot {
vcsrepo { '/opt/ts_config_mttcs':
ensure => present,
provider => git,
source => 'https://github.com/lsst-ts/ts_config_mttcs.git',
keep_local_changes => true,
require => Class[profile::core::anaconda],
}
file { '/etc/profile.d/hexrot_path.sh':
ensure => file,
mode => '0644',
require => Vcsrepo['/opt/ts_config_mttcs'],
# lint:ignore:strict_indent
content => @(ENV),
#!/usr/bin/bash
export QT_API="PySide2"
export PYTEST_QT_API="PySide2"
export TS_CONFIG_MTTCS_DIR="/opt/ts_config_mttcs"
| ENV
# lint:endignore
}
file { '/rubin/mtm2/python':
ensure => directory,
owner => 73006,
group => 73006,
require => Class[profile::core::anaconda],
}
file { '/rubin/mtm2/python/run_m2gui':
ensure => link,
owner => 73006,
group => 73006,
target => '/opt/anaconda/envs/py311/bin/run_m2gui',
}
file { '/rubin/rotator':
ensure => directory,
owner => 73006,
group => 73006,
}
}
75 changes: 75 additions & 0 deletions spec/classes/core/anaconda_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'profile::core::anaconda' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'with params' do
let(:params) do
{
python_env_name: 'foo',
python_env_version: 'bar',
conda_packages: [
{
'name' => 'baz',
'channel' => 'qux',
},
],
}
end

it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_exec('create_conda_env').with(
'command' => '/opt/anaconda/bin/conda create -y --name foo python=bar',
)
}

it {
is_expected.to contain_exec('install_baz_via_conda').with(
'command' => 'conda install -y -n foo -c qux baz',
)
}

it {
is_expected.to contain_exec('install_anaconda').with(
'command' => '/bin/wget https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh -O /tmp/anaconda_installer.sh && /bin/bash /tmp/anaconda_installer.sh -b -p /opt/anaconda',
)
}

it {
is_expected.to contain_exec('install_libmamba_env').with(
'command' => '/opt/anaconda/bin/conda install -y -n foo conda-libmamba-solver',
)
}

it {
is_expected.to contain_exec('set_libmamba').with(
'command' => 'conda config --set solver libmamba',
)
}

it {
is_expected.to contain_file('/etc/profile.d/conda_source.sh').with(
'ensure' => 'file',
'mode' => '0644',
'content' => <<~CONTENT,
#!/usr/bin/bash
source /opt/anaconda/bin/activate foo
CONTENT
)
}

it {
is_expected.to contain_package('wget').with(
'ensure' => 'installed',
)
}
end
end
end
end
11 changes: 11 additions & 0 deletions spec/hosts/roles/hexrot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@
it { is_expected.to contain_class('docker') }

%w[
mate
profile::core::anaconda
profile::core::common
profile::core::debugutils
profile::core::docker
profile::core::docker::prune
profile::core::ni_packages
profile::core::x2go
profile::ts::hexrot
profile::ts::nexusctio
].each do |c|
it { is_expected.to contain_class(c) }
end

it { is_expected.to contain_class('profile::core::anaconda').with_python_env_name('py311') }

it { is_expected.to contain_class('profile::core::anaconda').with_python_env_version('3.11') }

it { is_expected.to contain_class('profile::core::anaconda').with_conda_packages('[{"name"=>"pyside2", "channel"=>"conda-forge"}, {"name"=>"ts-m2gui", "channel"=>"lsstts"}]') }

it { is_expected.to contain_package('docker-compose-plugin') }
end # host
end # lsst_sites
Expand Down

0 comments on commit 81422d8

Please sign in to comment.