From ea024d4bdcf52eb70ef850803ed4078b140acd4d Mon Sep 17 00:00:00 2001 From: Carlos Barria Date: Wed, 6 Sep 2023 10:08:18 -0300 Subject: [PATCH] (node/hexrot) add conda install ts_m2gui --- hieradata/role/hexrot.yaml | 13 +++++ site/profile/manifests/core/anaconda.pp | 78 +++++++++++++++++++++++++ site/profile/manifests/ts/hexrot.pp | 42 +++++++++++++ spec/hosts/roles/hexrot_spec.rb | 11 ++++ 4 files changed, 144 insertions(+) create mode 100644 site/profile/manifests/core/anaconda.pp create mode 100644 site/profile/manifests/ts/hexrot.pp diff --git a/hieradata/role/hexrot.yaml b/hieradata/role/hexrot.yaml index 9c674f6a33..6464fb1b69 100644 --- a/hieradata/role/hexrot.yaml +++ b/hieradata/role/hexrot.yaml @@ -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: @@ -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" @@ -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" diff --git a/site/profile/manifests/core/anaconda.pp b/site/profile/manifests/core/anaconda.pp new file mode 100644 index 0000000000..50d259d6e4 --- /dev/null +++ b/site/profile/manifests/core/anaconda.pp @@ -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']}", + } + } + } +} diff --git a/site/profile/manifests/ts/hexrot.pp b/site/profile/manifests/ts/hexrot.pp new file mode 100644 index 0000000000..4bcda0824a --- /dev/null +++ b/site/profile/manifests/ts/hexrot.pp @@ -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, + } +} diff --git a/spec/hosts/roles/hexrot_spec.rb b/spec/hosts/roles/hexrot_spec.rb index 6d539beb6c..1201ef6fd3 100644 --- a/spec/hosts/roles/hexrot_spec.rb +++ b/spec/hosts/roles/hexrot_spec.rb @@ -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